modTicket.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. );
  113. $this->tabs = array(
  114. 'thirdparty:+ticket:Tickets:ticket:$user->rights->ticket->read:/ticket/list.php?socid=__ID__',
  115. );
  116. // Dictionaries
  117. if (!isset($conf->ticket->enabled)) {
  118. $conf->ticket = new stdClass();
  119. $conf->ticket->enabled = 0;
  120. }
  121. $this->dictionaries = array(
  122. 'langs' => 'ticket',
  123. 'tabname' => array(
  124. "c_ticket_type",
  125. "c_ticket_severity",
  126. "c_ticket_category",
  127. "c_ticket_resolution"
  128. ),
  129. 'tablib' => array(
  130. "TicketDictType",
  131. "TicketDictSeverity",
  132. "TicketDictCategory",
  133. "TicketDictResolution"
  134. ),
  135. 'tabsql' => array(
  136. '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',
  137. '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',
  138. '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',
  139. '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'
  140. ),
  141. 'tabsqlsort' => array("pos ASC", "pos ASC", "pos ASC", "pos ASC"),
  142. '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"),
  143. '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"),
  144. '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"),
  145. 'tabrowid' => array("rowid", "rowid", "rowid", "rowid"),
  146. 'tabcond' => array($conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled && getDolGlobalString('TICKET_ENABLE_RESOLUTION')),
  147. 'tabhelp' => array(
  148. array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")),
  149. array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")),
  150. array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1"), 'public'=>$langs->trans("Enter0or1").'<br>'.$langs->trans("TicketGroupIsPublicDesc"), 'fk_parent'=>$langs->trans("IfThisCategoryIsChildOfAnother")),
  151. array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1"))
  152. ),
  153. );
  154. // Boxes
  155. // Add here list of php file(s) stored in core/boxes that contains class to show a box.
  156. $this->boxes = array(
  157. 0=>array('file'=>'box_last_ticket.php', 'enabledbydefaulton'=>'Home'),
  158. 1=>array('file'=>'box_last_modified_ticket.php', 'enabledbydefaulton'=>'Home'),
  159. 2=>array('file'=>'box_ticket_by_severity.php', 'enabledbydefaulton'=>'ticketindex'),
  160. 3=>array('file'=>'box_graph_nb_ticket_last_x_days.php', 'enabledbydefaulton'=>'ticketindex'),
  161. 4=>array('file'=>'box_graph_nb_tickets_type.php', 'enabledbydefaulton'=>'ticketindex'),
  162. 5=>array('file'=>'box_new_vs_close_ticket.php', 'enabledbydefaulton'=>'ticketindex')
  163. ); // Boxes list
  164. // Permissions
  165. $this->rights = array(); // Permission array used by this module
  166. $r = 0;
  167. $this->rights[$r][0] = 56001; // id de la permission
  168. $this->rights[$r][1] = "Read ticket"; // libelle de la permission
  169. $this->rights[$r][2] = 'r'; // 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] = 'read';
  172. $r++;
  173. $this->rights[$r][0] = 56002; // id de la permission
  174. $this->rights[$r][1] = "Create les tickets"; // libelle de la permission
  175. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  176. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  177. $this->rights[$r][4] = 'write';
  178. $r++;
  179. $this->rights[$r][0] = 56003; // id de la permission
  180. $this->rights[$r][1] = "Delete les tickets"; // libelle de la permission
  181. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  182. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  183. $this->rights[$r][4] = 'delete';
  184. $r++;
  185. $this->rights[$r][0] = 56004; // id de la permission
  186. $this->rights[$r][1] = "Manage tickets"; // libelle de la permission
  187. //$this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  188. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  189. $this->rights[$r][4] = 'manage';
  190. /* Seems not used and in conflict with societe->client->voir (see all thirdparties)
  191. $r++;
  192. $this->rights[$r][0] = 56005; // id de la permission
  193. $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
  194. $this->rights[$r][2] = 'r'; // 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] = 'view';
  197. $this->rights[$r][5] = 'all';
  198. */
  199. // Main menu entries
  200. $this->menus = array(); // List of menus to add
  201. $r = 0;
  202. /*$this->menu[$r] = array('fk_menu' => 0, // Put 0 if this is a top menu
  203. 'type' => 'top', // This is a Top menu entry
  204. 'titre' => 'Ticket',
  205. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth em092"'),
  206. 'mainmenu' => 'ticket',
  207. 'leftmenu' => '1', // Use 1 if you also want to add left menu entries using this descriptor.
  208. 'url' => '/ticket/index.php',
  209. 'langs' => 'ticket', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  210. 'position' => 88,
  211. 'enabled' => '$conf->ticket->enabled',
  212. 'perms' => '$user->rights->ticket->read', // Use 'perms'=>'$user->rights->ticket->level1->level2' if you want your menu with a permission rules
  213. 'target' => '',
  214. 'user' => 2); // 0=Menu for internal users, 1=external users, 2=both
  215. $r++;*/
  216. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket',
  217. 'type' => 'left',
  218. 'titre' => 'Tickethu',
  219. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth em092"'),
  220. 'mainmenu' => 'ticket',
  221. 'leftmenu' => 'ticket',
  222. 'url' => '/ticket/index.php',
  223. 'langs' => 'ticket',
  224. 'position' => 101,
  225. 'enabled' => '$conf->ticket->enabled',
  226. 'perms' => '$user->rights->ticket->read',
  227. 'target' => '',
  228. 'user' => 2);
  229. $r++;
  230. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
  231. 'type' => 'left',
  232. 'titre' => 'NewTickethu',
  233. 'mainmenu' => 'ticket',
  234. 'url' => '/ticket/card.php?action=create',
  235. 'langs' => 'ticket',
  236. 'position' => 102,
  237. 'enabled' => '$conf->ticket->enabled',
  238. 'perms' => '$user->rights->ticket->write',
  239. 'target' => '',
  240. 'user' => 2);
  241. $r++;
  242. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
  243. 'type' => 'left',
  244. 'titre' => 'List',
  245. 'mainmenu' => 'ticket',
  246. 'leftmenu' => 'ticketlist',
  247. 'url' => '/ticket/list.php?search_fk_status=non_closed',
  248. 'langs' => 'ticket',
  249. 'position' => 103,
  250. 'enabled' => '$conf->ticket->enabled',
  251. 'perms' => '$user->rights->ticket->read',
  252. 'target' => '',
  253. 'user' => 2);
  254. $r++;
  255. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
  256. 'type' => 'left',
  257. 'titre' => 'MenuTicketMyAssign',
  258. 'mainmenu' => 'ticket',
  259. 'leftmenu' => 'ticketmy',
  260. 'url' => '/ticket/list.php?mode=mine&search_fk_status=non_closed',
  261. 'langs' => 'ticket',
  262. 'position' => 105,
  263. 'enabled' => '$conf->ticket->enabled',
  264. 'perms' => '$user->rights->ticket->read',
  265. 'target' => '',
  266. 'user' => 0);
  267. $r++;
  268. /* $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
  269. 'type' => 'left',
  270. 'titre' => 'Statistics',
  271. 'mainmenu' => 'ticket',
  272. 'url' => '/ticket/stats/index.php',
  273. 'langs' => 'ticket',
  274. 'position' => 107,
  275. 'enabled' => '$conf->ticket->enabled',
  276. 'perms' => '$user->rights->ticket->read',
  277. 'target' => '',
  278. 'user' => 0);
  279. $r++; */
  280. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
  281. 'type' => 'left',
  282. 'titre' => 'Categories',
  283. 'mainmenu' => 'ticket',
  284. 'url' => '/categories/index.php?type=12',
  285. 'langs' => 'ticket',
  286. 'position' => 107,
  287. 'enabled' => '$conf->categorie->enabled',
  288. 'perms' => '$user->rights->ticket->read',
  289. 'target' => '',
  290. 'user' => 0);
  291. $r++;
  292. }
  293. /**
  294. * Function called when module is enabled.
  295. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  296. * It also creates data directories
  297. *
  298. * @param string $options Options when enabling module ('', 'noboxes')
  299. * @return int 1 if OK, 0 if KO
  300. */
  301. public function init($options = '')
  302. {
  303. global $conf, $langs;
  304. $result = $this->_load_tables('/install/mysql/', 'ticket');
  305. if ($result < 0) {
  306. 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')
  307. }
  308. // Permissions
  309. $this->remove($options);
  310. //ODT template
  311. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/tickets/template_ticket.odt';
  312. $dirodt = DOL_DATA_ROOT.'/doctemplates/tickets';
  313. $dest = $dirodt.'/template_order.odt';
  314. if (file_exists($src) && !file_exists($dest)) {
  315. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  316. dol_mkdir($dirodt);
  317. $result = dol_copy($src, $dest, 0, 0);
  318. if ($result < 0) {
  319. $langs->load("errors");
  320. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  321. return 0;
  322. }
  323. }
  324. $sql = array(
  325. 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),
  326. array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110121, 'ticket', 'internal', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
  327. 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),
  328. array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110123, 'ticket', 'external', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
  329. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'TICKET_ADDON_PDF_ODT_PATH' AND type = 'ticket' AND entity = ".((int) $conf->entity),
  330. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('TICKET_ADDON_PDF_ODT_PATH','ticket',".((int) $conf->entity).")"
  331. );
  332. return $this->_init($sql, $options);
  333. }
  334. }