modTicket.class.php 18 KB

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