dolibarr  13.0.2
modTicket.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) - 2013-2018 Jean-François FERRY <hello@librethic.io>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  *
17  * Module descriptor for ticket system
18  */
19 
27 require_once DOL_DOCUMENT_ROOT."/core/modules/DolibarrModules.class.php";
28 
29 
34 {
40  public function __construct($db)
41  {
42  global $langs, $conf;
43 
44  $this->db = $db;
45 
46  // Id for module (must be unique).
47  // Use a free id here
48  // (See in Home -> System information -> Dolibarr for list of used modules id).
49  $this->numero = 56000;
50  // Key text used to identify module (for permissions, menus, etc...)
51  $this->rights_class = 'ticket';
52 
53  // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
54  // It is used to group modules in module setup page
55  $this->family = "crm";
56  // Module position in the family
57  $this->module_position = '60';
58  // Module label (no space allowed)
59  // used if translation string 'ModuleXXXName' not found
60  // (where XXX is value of numeric property 'numero' of module)
61  $this->name = preg_replace('/^mod/i', '', get_class($this));
62  // Module description
63  // used if translation string 'ModuleXXXDesc' not found
64  // (where XXX is value of numeric property 'numero' of module)
65  $this->description = "Incident/support ticket management";
66  // Possible values for version are: 'development', 'experimental' or version
67  $this->version = 'dolibarr';
68  // Key used in llx_const table to save module status enabled/disabled
69  // (where MYMODULE is value of property name of module in uppercase)
70  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
71  // Name of image file used for this module.
72  // If file is in theme/yourtheme/img directory under name object_pictovalue.png
73  // use this->picto='pictovalue'
74  // If file is in module/img directory under name object_pictovalue.png
75  // use this->picto='pictovalue@module'
76  $this->picto = 'ticket'; // mypicto@ticket
77  // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
78  // for default path (eg: /ticket/core/xxxxx) (0=disable, 1=enable)
79  // for specific path of parts (eg: /ticket/core/modules/barcode)
80  // for specific css file (eg: /ticket/css/ticket.css.php)
81  $this->module_parts = array(
82  // Set this to 1 if module has its own trigger directory
83  'triggers' => 1,
84  );
85 
86  // Data directories to create when module is enabled.
87  // Example: this->dirs = array("/ticket/temp");
88  $this->dirs = array();
89 
90  // Config pages. Put here list of php pages
91  // stored into ticket/admin directory, used to setup module.
92  $this->config_page_url = array("ticket.php");
93 
94  // Dependencies
95  $this->hidden = false; // A condition to hide module
96  $this->depends = array('modAgenda'); // List of module class names as string that must be enabled if this module is enabled
97  $this->requiredby = array(); // List of module ids to disable if this one is disabled
98  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
99  $this->phpmin = array(5, 4); // Minimum version of PHP required by module
100  $this->langfiles = array("ticket");
101 
102  // Constants
103  // List of particular constants to add when module is enabled
104  // (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
105  // Example:
106  $this->const = array(
107  1 => array('TICKET_ENABLE_PUBLIC_INTERFACE', 'chaine', '0', 'Enable ticket public interface', 0),
108  2 => array('TICKET_ADDON', 'chaine', 'mod_ticket_simple', 'Ticket ref module', 0),
109  3 => array('TICKET_ADDON_PDF_ODT_PATH', 'chaine', 'DOL_DATA_ROOT/doctemplates/tickets', 'Ticket templates ODT/ODS directory for templates', 0)
110  );
111 
112 
113  $this->tabs = array(
114  'thirdparty:+ticket:Tickets:@ticket:$user->rights->ticket->read:/ticket/list.php?socid=__ID__',
115  'project:+ticket:Tickets:@ticket:$user->rights->ticket->read:/ticket/list.php?projectid=__ID__',
116  );
117 
118  // Dictionaries
119  if (!isset($conf->ticket->enabled)) {
120  $conf->ticket = new stdClass();
121  $conf->ticket->enabled = 0;
122  }
123  $this->dictionaries = array(
124  'langs' => 'ticket',
125  'tabname' => array(MAIN_DB_PREFIX."c_ticket_type", MAIN_DB_PREFIX."c_ticket_severity", MAIN_DB_PREFIX."c_ticket_category", MAIN_DB_PREFIX."c_ticket_resolution"),
126  'tablib' => array("TicketDictType", "TicketDictSeverity", "TicketDictCategory", "TicketDictResolution"),
127  'tabsql' => array(
128  'SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM '.MAIN_DB_PREFIX.'c_ticket_type as f',
129  'SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM '.MAIN_DB_PREFIX.'c_ticket_severity as f',
130  'SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM '.MAIN_DB_PREFIX.'c_ticket_category as f',
131  'SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default FROM '.MAIN_DB_PREFIX.'c_ticket_resolution as f'
132  ),
133  'tabsqlsort' => array("pos ASC", "pos ASC", "pos ASC", "pos ASC"),
134  'tabfield' => array("code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default"),
135  'tabfieldvalue' => array("code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default"),
136  'tabfieldinsert' => array("code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default"),
137  'tabrowid' => array("rowid", "rowid", "rowid", "rowid"),
138  'tabcond' => array($conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled),
139  'tabhelp' => array(array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")), array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")), array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")), array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1"))),
140  );
141 
142  // Boxes
143  // Add here list of php file(s) stored in core/boxes that contains class to show a box.
144  $this->boxes = array(
145  0=>array('file'=>'box_last_ticket.php', 'enabledbydefaulton'=>'Home'),
146  1=>array('file'=>'box_last_modified_ticket.php', 'enabledbydefaulton'=>'Home')
147  ); // Boxes list
148 
149  // Permissions
150  $this->rights = array(); // Permission array used by this module
151 
152  $r = 0;
153  $this->rights[$r][0] = 56001; // id de la permission
154  $this->rights[$r][1] = "Read ticket"; // libelle de la permission
155  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
156  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
157  $this->rights[$r][4] = 'read';
158 
159  $r++;
160  $this->rights[$r][0] = 56002; // id de la permission
161  $this->rights[$r][1] = "Create les tickets"; // libelle de la permission
162  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
163  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
164  $this->rights[$r][4] = 'write';
165 
166  $r++;
167  $this->rights[$r][0] = 56003; // id de la permission
168  $this->rights[$r][1] = "Delete les tickets"; // libelle de la permission
169  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
170  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
171  $this->rights[$r][4] = 'delete';
172 
173  $r++;
174  $this->rights[$r][0] = 56004; // id de la permission
175  $this->rights[$r][1] = "Manage tickets"; // libelle de la permission
176  //$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
177  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
178  $this->rights[$r][4] = 'manage';
179 
180  /* Seems not used and in conflict with societe->client->voir (see all thirdparties)
181  $r++;
182  $this->rights[$r][0] = 56005; // id de la permission
183  $this->rights[$r][1] = 'See all tickets, even if not assigned to (not effective for external users, always restricted to the thirdpardy they depends on)'; // libelle de la permission
184  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
185  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
186  $this->rights[$r][4] = 'view';
187  $this->rights[$r][5] = 'all';
188  */
189 
190  // Main menu entries
191  $this->menus = array(); // List of menus to add
192  $r = 0;
193 
194  $this->menu[$r] = array('fk_menu' => 0, // Put 0 if this is a top menu
195  'type' => 'top', // This is a Top menu entry
196  'titre' => 'Ticket',
197  'mainmenu' => 'ticket',
198  'leftmenu' => '1', // Use 1 if you also want to add left menu entries using this descriptor.
199  'url' => '/ticket/index.php',
200  'langs' => 'ticket', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
201  'position' => 88,
202  'enabled' => '$conf->ticket->enabled', // Define condition to show or hide menu entry. Use '$conf->ticket->enabled' if entry must be visible if module is enabled.
203  'perms' => '$user->rights->ticket->read', // Use 'perms'=>'$user->rights->ticket->level1->level2' if you want your menu with a permission rules
204  'target' => '',
205  'user' => 2); // 0=Menu for internal users, 1=external users, 2=both
206  $r++;
207 
208  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket',
209  'type' => 'left',
210  'titre' => 'Ticket',
211  'mainmenu' => 'ticket',
212  'leftmenu' => 'ticket',
213  'url' => '/ticket/index.php',
214  'langs' => 'ticket',
215  'position' => 101,
216  'enabled' => '$conf->ticket->enabled',
217  'perms' => '$user->rights->ticket->read',
218  'target' => '',
219  'user' => 2);
220  $r++;
221 
222  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
223  'type' => 'left',
224  'titre' => 'NewTicket',
225  'mainmenu' => 'ticket',
226  'url' => '/ticket/card.php?action=create',
227  'langs' => 'ticket',
228  'position' => 102,
229  'enabled' => '$conf->ticket->enabled',
230  'perms' => '$user->rights->ticket->write',
231  'target' => '',
232  'user' => 2);
233  $r++;
234 
235  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
236  'type' => 'left',
237  'titre' => 'List',
238  'mainmenu' => 'ticket',
239  'leftmenu' => 'ticketlist',
240  'url' => '/ticket/list.php?search_fk_status=non_closed',
241  'langs' => 'ticket',
242  'position' => 103,
243  'enabled' => '$conf->ticket->enabled',
244  'perms' => '$user->rights->ticket->read',
245  'target' => '',
246  'user' => 2);
247  $r++;
248 
249  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
250  'type' => 'left',
251  'titre' => 'MenuTicketMyAssign',
252  'mainmenu' => 'ticket',
253  'leftmenu' => 'ticketmy',
254  'url' => '/ticket/list.php?mode=mine&search_fk_status=non_closed',
255  'langs' => 'ticket',
256  'position' => 105,
257  'enabled' => '$conf->ticket->enabled',
258  'perms' => '$user->rights->ticket->read',
259  'target' => '',
260  'user' => 0);
261  $r++;
262 
263  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
264  'type' => 'left',
265  'titre' => 'Statistics',
266  'mainmenu' => 'ticket',
267  'url' => '/ticket/stats/index.php',
268  'langs' => 'ticket',
269  'position' => 107,
270  'enabled' => '$conf->ticket->enabled',
271  'perms' => '$user->rights->ticket->read',
272  'target' => '',
273  'user' => 0);
274  $r++;
275  }
276 
285  public function init($options = '')
286  {
287  global $conf, $langs;
288 
289  // Permissions
290  $this->remove($options);
291 
292  //ODT template
293  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/tickets/template_ticket.odt';
294  $dirodt = DOL_DATA_ROOT.'/doctemplates/tickets';
295  $dest = $dirodt.'/template_order.odt';
296 
297  if (file_exists($src) && !file_exists($dest))
298  {
299  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
300  dol_mkdir($dirodt);
301  $result = dol_copy($src, $dest, 0, 0);
302  if ($result < 0)
303  {
304  $langs->load("errors");
305  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
306  return 0;
307  }
308  }
309 
310  $sql = array(
311  array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110120, 'ticket', 'internal', 'SUPPORTTEC', 'Utilisateur assigné au ticket', 1);", "ignoreerror" => 1),
312  array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110121, 'ticket', 'internal', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
313  array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110122, 'ticket', 'external', 'SUPPORTCLI', 'Contact client suivi incident', 1);", "ignoreerror" => 1),
314  array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110123, 'ticket', 'external', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
315  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'TICKET_ADDON_PDF_ODT_PATH' AND type = 'ticket' AND entity = ".$conf->entity,
316  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('TICKET_ADDON_PDF_ODT_PATH','ticket',".$conf->entity.")"
317  );
318 
319  return $this->_init($sql, $options);
320  }
321 }
Description and activation class for module Ticket.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:663
Class DolibarrModules.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
__construct($db)
Constructor.
_init($array_sql, $options= '')
Enables a module.
init($options= '')
Function called when module is enabled.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)