dolibarr  16.0.5
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  $langs->load("ticket");
44 
45  $this->db = $db;
46 
47  // Id for module (must be unique).
48  // Use a free id here
49  // (See in Home -> System information -> Dolibarr for list of used modules id).
50  $this->numero = 56000;
51  // Key text used to identify module (for permissions, menus, etc...)
52  $this->rights_class = 'ticket';
53 
54  // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
55  // It is used to group modules in module setup page
56  $this->family = "crm";
57  // Module position in the family
58  $this->module_position = '60';
59  // Module label (no space allowed)
60  // used if translation string 'ModuleXXXName' not found
61  // (where XXX is value of numeric property 'numero' of module)
62  $this->name = preg_replace('/^mod/i', '', get_class($this));
63  // Module description
64  // used if translation string 'ModuleXXXDesc' not found
65  // (where XXX is value of numeric property 'numero' of module)
66  $this->description = "Incident/support ticket management";
67  // Possible values for version are: 'development', 'experimental' or version
68  $this->version = 'dolibarr';
69  // Key used in llx_const table to save module status enabled/disabled
70  // (where MYMODULE is value of property name of module in uppercase)
71  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
72  // Name of image file used for this module.
73  // If file is in theme/yourtheme/img directory under name object_pictovalue.png
74  // use this->picto='pictovalue'
75  // If file is in module/img directory under name object_pictovalue.png
76  // use this->picto='pictovalue@module'
77  $this->picto = 'ticket'; // mypicto@ticket
78  // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
79  // for default path (eg: /ticket/core/xxxxx) (0=disable, 1=enable)
80  // for specific path of parts (eg: /ticket/core/modules/barcode)
81  // for specific css file (eg: /ticket/css/ticket.css.php)
82  $this->module_parts = array(
83  // Set this to 1 if module has its own trigger directory
84  'triggers' => 1,
85  );
86 
87  // Data directories to create when module is enabled.
88  // Example: this->dirs = array("/ticket/temp");
89  $this->dirs = array();
90 
91  // Config pages. Put here list of php pages
92  // stored into ticket/admin directory, used to setup module.
93  $this->config_page_url = array("ticket.php");
94 
95  // Dependencies
96  $this->hidden = false; // A condition to hide module
97  $this->depends = array('modAgenda'); // List of module class names as string that must be enabled if this module is enabled
98  $this->requiredby = array(); // List of module ids to disable if this one is disabled
99  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
100  $this->phpmin = array(5, 6); // Minimum version of PHP required by module
101  $this->langfiles = array("ticket");
102 
103  // Constants
104  // List of particular constants to add when module is enabled
105  // (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
106  // Example:
107  $default_signature = $langs->trans('TicketMessageMailSignatureText', getDolGlobalString('MAIN_INFO_SOCIETE_NOM'));
108  $this->const = array(
109  1 => array('TICKET_ENABLE_PUBLIC_INTERFACE', 'chaine', '0', 'Enable ticket public interface', 0),
110  2 => array('TICKET_ADDON', 'chaine', 'mod_ticket_simple', 'Ticket ref module', 0),
111  3 => array('TICKET_ADDON_PDF_ODT_PATH', 'chaine', 'DOL_DATA_ROOT/doctemplates/tickets', 'Ticket templates ODT/ODS directory for templates', 0),
112  4 => array('TICKET_AUTO_READ_WHEN_CREATED_FROM_BACKEND', 'chaine', 0, 'Automatically mark ticket as read when created from backend', 0),
113  5 => array('TICKET_DELAY_BEFORE_FIRST_RESPONSE', 'chaine', '0', 'Maximum wanted elapsed time before a first answer to a ticket (in hours). Display a warning in tickets list if not respected.', 0),
114  6 => array('TICKET_DELAY_SINCE_LAST_RESPONSE', 'chaine', '0', 'Maximum wanted elapsed time between two answers on the same ticket (in hours). Display a warning in tickets list if not respected.', 0),
115  7 => array('TICKET_NOTIFY_AT_CLOSING', 'chaine', '0', 'Default notify contacts when closing a module', 0),
116  8 => array('TICKET_PRODUCT_CATEGORY', 'chaine', 0, 'The category of product that is being used for ticket accounting', 0),
117  9 => array('TICKET_NOTIFICATION_EMAIL_FROM', 'chaine', getDolGlobalString('MAIN_MAIL_EMAIL_FROM'), 'Email to use by default as sender for messages sent from Dolibarr', 0),
118  10 => array('TICKET_MESSAGE_MAIL_INTRO', 'chaine', $langs->trans('TicketMessageMailIntroText'), 'Introduction text of ticket replies sent from Dolibarr', 0),
119  11 => array('TICKET_MESSAGE_MAIL_SIGNATURE', 'chaine', $default_signature, 'Signature to use by default for messages sent from Dolibarr', 0),
120  12 => array('MAIN_EMAILCOLLECTOR_MAIL_WITHOUT_HEADER', 'chaine', "1", 'Disable the rendering of headers in tickets', 0),
121  13 => array('MAIN_SECURITY_ENABLECAPTCHA_TICKET', 'chaine', getDolGlobalInt('MAIN_SECURITY_ENABLECAPTCHA_TICKET'), 'Enable captcha code by default', 0)
122  );
123 
124 
125  $this->tabs = array(
126  'thirdparty:+ticket:Tickets:@ticket:$user->rights->ticket->read:/ticket/list.php?socid=__ID__',
127  'project:+ticket:Tickets:@ticket:$user->rights->ticket->read:/ticket/list.php?projectid=__ID__',
128  );
129 
130  // Dictionaries
131  if (!isset($conf->ticket->enabled)) {
132  $conf->ticket = new stdClass();
133  $conf->ticket->enabled = 0;
134  }
135  $this->dictionaries = array(
136  'langs' => 'ticket',
137  'tabname' => array(
138  "c_ticket_type",
139  "c_ticket_severity",
140  "c_ticket_category",
141  "c_ticket_resolution"
142  ),
143  'tablib' => array(
144  "TicketDictType",
145  "TicketDictSeverity",
146  "TicketDictCategory",
147  "TicketDictResolution"
148  ),
149  'tabsql' => array(
150  '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',
151  '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',
152  'SELECT f.rowid as rowid, f.code, f.pos, f.label, f.active, f.use_default, f.public, f.fk_parent FROM '.MAIN_DB_PREFIX.'c_ticket_category as f',
153  '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'
154  ),
155  'tabsqlsort' => array("pos ASC", "pos ASC", "pos ASC", "pos ASC"),
156  'tabfield' => array("code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default,public,fk_parent", "code,label,pos,use_default"),
157  'tabfieldvalue' => array("code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default,public,fk_parent", "code,label,pos,use_default"),
158  'tabfieldinsert' => array("code,label,pos,use_default", "code,label,pos,use_default", "code,label,pos,use_default,public,fk_parent", "code,label,pos,use_default"),
159  'tabrowid' => array("rowid", "rowid", "rowid", "rowid"),
160  'tabcond' => array($conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled && !empty($conf->global->TICKET_ENABLE_RESOLUTION)),
161  'tabhelp' => array(
162  array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")),
163  array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")),
164  array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1"), 'public'=>$langs->trans("Enter0or1").'<br>'.$langs->trans("TicketGroupIsPublicDesc"), 'fk_parent'=>$langs->trans("IfThisCategoryIsChildOfAnother")),
165  array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1"))
166  ),
167  );
168 
169  // Boxes
170  // Add here list of php file(s) stored in core/boxes that contains class to show a box.
171  $this->boxes = array(
172  0=>array('file'=>'box_last_ticket.php', 'enabledbydefaulton'=>'Home'),
173  1=>array('file'=>'box_last_modified_ticket.php', 'enabledbydefaulton'=>'Home'),
174  2=>array('file'=>'box_ticket_by_severity.php', 'enabledbydefaulton'=>'ticketindex'),
175  3=>array('file'=>'box_graph_nb_ticket_last_x_days.php', 'enabledbydefaulton'=>'ticketindex'),
176  4=>array('file'=>'box_graph_nb_tickets_type.php', 'enabledbydefaulton'=>'ticketindex'),
177  5=>array('file'=>'box_new_vs_close_ticket.php', 'enabledbydefaulton'=>'ticketindex')
178  ); // Boxes list
179 
180  // Permissions
181  $this->rights = array(); // Permission array used by this module
182 
183  $r = 0;
184  $this->rights[$r][0] = 56001; // id de la permission
185  $this->rights[$r][1] = "Read ticket"; // libelle de la permission
186  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
187  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
188  $this->rights[$r][4] = 'read';
189 
190  $r++;
191  $this->rights[$r][0] = 56002; // id de la permission
192  $this->rights[$r][1] = "Create les tickets"; // libelle de la permission
193  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
194  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
195  $this->rights[$r][4] = 'write';
196 
197  $r++;
198  $this->rights[$r][0] = 56003; // id de la permission
199  $this->rights[$r][1] = "Delete les tickets"; // libelle de la permission
200  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
201  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
202  $this->rights[$r][4] = 'delete';
203 
204  $r++;
205  $this->rights[$r][0] = 56004; // id de la permission
206  $this->rights[$r][1] = "Manage tickets"; // libelle de la permission
207  //$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
208  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
209  $this->rights[$r][4] = 'manage';
210 
211  /* Seems not used and in conflict with societe->client->voir (see all thirdparties)
212  $r++;
213  $this->rights[$r][0] = 56005; // id de la permission
214  $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
215  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
216  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
217  $this->rights[$r][4] = 'view';
218  $this->rights[$r][5] = 'all';
219  */
220 
221  // Main menu entries
222  $this->menus = array(); // List of menus to add
223  $r = 0;
224 
225  /*$this->menu[$r] = array('fk_menu' => 0, // Put 0 if this is a top menu
226  'type' => 'top', // This is a Top menu entry
227  'titre' => 'Ticket',
228  'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth em092"'),
229  'mainmenu' => 'ticket',
230  'leftmenu' => '1', // Use 1 if you also want to add left menu entries using this descriptor.
231  'url' => '/ticket/index.php',
232  'langs' => 'ticket', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
233  'position' => 88,
234  'enabled' => '$conf->ticket->enabled',
235  'perms' => '$user->rights->ticket->read', // Use 'perms'=>'$user->rights->ticket->level1->level2' if you want your menu with a permission rules
236  'target' => '',
237  'user' => 2); // 0=Menu for internal users, 1=external users, 2=both
238  $r++;*/
239 
240  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket',
241  'type' => 'left',
242  'titre' => 'Ticket',
243  'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth em092"'),
244  'mainmenu' => 'ticket',
245  'leftmenu' => 'ticket',
246  'url' => '/ticket/index.php',
247  'langs' => 'ticket',
248  'position' => 101,
249  'enabled' => '$conf->ticket->enabled',
250  'perms' => '$user->rights->ticket->read',
251  'target' => '',
252  'user' => 2);
253  $r++;
254 
255  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
256  'type' => 'left',
257  'titre' => 'NewTicket',
258  'mainmenu' => 'ticket',
259  'url' => '/ticket/card.php?action=create',
260  'langs' => 'ticket',
261  'position' => 102,
262  'enabled' => '$conf->ticket->enabled',
263  'perms' => '$user->rights->ticket->write',
264  'target' => '',
265  'user' => 2);
266  $r++;
267 
268  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
269  'type' => 'left',
270  'titre' => 'List',
271  'mainmenu' => 'ticket',
272  'leftmenu' => 'ticketlist',
273  'url' => '/ticket/list.php?search_fk_status=non_closed',
274  'langs' => 'ticket',
275  'position' => 103,
276  'enabled' => '$conf->ticket->enabled',
277  'perms' => '$user->rights->ticket->read',
278  'target' => '',
279  'user' => 2);
280  $r++;
281 
282  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
283  'type' => 'left',
284  'titre' => 'MenuTicketMyAssign',
285  'mainmenu' => 'ticket',
286  'leftmenu' => 'ticketmy',
287  'url' => '/ticket/list.php?mode=mine&search_fk_status=non_closed',
288  'langs' => 'ticket',
289  'position' => 105,
290  'enabled' => '$conf->ticket->enabled',
291  'perms' => '$user->rights->ticket->read',
292  'target' => '',
293  'user' => 0);
294  $r++;
295 
296  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
297  'type' => 'left',
298  'titre' => 'Statistics',
299  'mainmenu' => 'ticket',
300  'url' => '/ticket/stats/index.php',
301  'langs' => 'ticket',
302  'position' => 107,
303  'enabled' => '$conf->ticket->enabled',
304  'perms' => '$user->rights->ticket->read',
305  'target' => '',
306  'user' => 0);
307  $r++;
308 
309  $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
310  'type' => 'left',
311  'titre' => 'Categories',
312  'mainmenu' => 'ticket',
313  'url' => '/categories/index.php?type=12',
314  'langs' => 'ticket',
315  'position' => 107,
316  'enabled' => '$conf->categorie->enabled',
317  'perms' => '$user->rights->ticket->read',
318  'target' => '',
319  'user' => 0);
320  $r++;
321  }
322 
331  public function init($options = '')
332  {
333  global $conf, $langs;
334 
335  $result = $this->_load_tables('/install/mysql/', 'ticket');
336  if ($result < 0) {
337  return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
338  }
339 
340  // Permissions
341  $this->remove($options);
342 
343  //ODT template
344  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/tickets/template_ticket.odt';
345  $dirodt = DOL_DATA_ROOT.'/doctemplates/tickets';
346  $dest = $dirodt.'/template_order.odt';
347 
348  if (file_exists($src) && !file_exists($dest)) {
349  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
350  dol_mkdir($dirodt);
351  $result = dol_copy($src, $dest, 0, 0);
352  if ($result < 0) {
353  $langs->load("errors");
354  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
355  return 0;
356  }
357  }
358 
359  $sql = array(
360  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),
361  array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110121, 'ticket', 'internal', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
362  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),
363  array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110123, 'ticket', 'external', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
364  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'TICKET_ADDON_PDF_ODT_PATH' AND type = 'ticket' AND entity = ".((int) $conf->entity),
365  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('TICKET_ADDON_PDF_ODT_PATH','ticket',".((int) $conf->entity).")"
366  );
367 
368  return $this->_init($sql, $options);
369  }
370 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
modTicket\__construct
__construct($db)
Constructor.
Definition: modTicket.class.php:40
DolibarrModules\_load_tables
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Definition: DolibarrModules.class.php:1070
name
$conf db name
Definition: repair.php:122
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_copy
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:703
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:383
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
modTicket
Description and activation class for module Ticket.
Definition: modTicket.class.php:33
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
modTicket\init
init($options='')
Function called when module is enabled.
Definition: modTicket.class.php:331
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37