PageRenderTime 64ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/modules/modTicket.class.php

http://github.com/Dolibarr/dolibarr
PHP | 353 lines | 213 code | 34 blank | 106 comment | 5 complexity | 6d35da4a506b04beec68f11b43f6b251 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  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. $this->db = $db;
  41. // Id for module (must be unique).
  42. // Use a free id here
  43. // (See in Home -> System information -> Dolibarr for list of used modules id).
  44. $this->numero = 56000;
  45. // Key text used to identify module (for permissions, menus, etc...)
  46. $this->rights_class = 'ticket';
  47. // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
  48. // It is used to group modules in module setup page
  49. $this->family = "crm";
  50. // Module position in the family
  51. $this->module_position = '60';
  52. // Module label (no space allowed)
  53. // used if translation string 'ModuleXXXName' not found
  54. // (where XXX is value of numeric property 'numero' of module)
  55. $this->name = preg_replace('/^mod/i', '', get_class($this));
  56. // Module description
  57. // used if translation string 'ModuleXXXDesc' not found
  58. // (where XXX is value of numeric property 'numero' of module)
  59. $this->description = "Incident/support ticket management";
  60. // Possible values for version are: 'development', 'experimental' or version
  61. $this->version = 'dolibarr';
  62. // Key used in llx_const table to save module status enabled/disabled
  63. // (where MYMODULE is value of property name of module in uppercase)
  64. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  65. // Name of image file used for this module.
  66. // If file is in theme/yourtheme/img directory under name object_pictovalue.png
  67. // use this->picto='pictovalue'
  68. // If file is in module/img directory under name object_pictovalue.png
  69. // use this->picto='pictovalue@module'
  70. $this->picto = 'ticket'; // mypicto@ticket
  71. // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
  72. // for default path (eg: /ticket/core/xxxxx) (0=disable, 1=enable)
  73. // for specific path of parts (eg: /ticket/core/modules/barcode)
  74. // for specific css file (eg: /ticket/css/ticket.css.php)
  75. $this->module_parts = array(
  76. // Set this to 1 if module has its own trigger directory
  77. 'triggers' => 1,
  78. );
  79. // Data directories to create when module is enabled.
  80. // Example: this->dirs = array("/ticket/temp");
  81. $this->dirs = array();
  82. // Config pages. Put here list of php pages
  83. // stored into ticket/admin directory, used to setup module.
  84. $this->config_page_url = array("ticket.php");
  85. // Dependencies
  86. $this->hidden = false; // A condition to hide module
  87. $this->depends = array('modAgenda'); // List of module class names as string that must be enabled if this module is enabled
  88. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  89. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  90. $this->phpmin = array(5, 6); // Minimum version of PHP required by module
  91. $this->langfiles = array("ticket");
  92. // Constants
  93. // List of particular constants to add when module is enabled
  94. // (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
  95. // Example:
  96. $this->const = array(
  97. 1 => array('TICKET_ENABLE_PUBLIC_INTERFACE', 'chaine', '0', 'Enable ticket public interface', 0),
  98. 2 => array('TICKET_ADDON', 'chaine', 'mod_ticket_simple', 'Ticket ref module', 0),
  99. 3 => array('TICKET_ADDON_PDF_ODT_PATH', 'chaine', 'DOL_DATA_ROOT/doctemplates/tickets', 'Ticket templates ODT/ODS directory for templates', 0)
  100. );
  101. $this->tabs = array(
  102. 'thirdparty:+ticket:Tickets:@ticket:$user->rights->ticket->read:/ticket/list.php?socid=__ID__',
  103. 'project:+ticket:Tickets:@ticket:$user->rights->ticket->read:/ticket/list.php?projectid=__ID__',
  104. );
  105. // Dictionaries
  106. if (!isset($conf->ticket->enabled)) {
  107. $conf->ticket = new stdClass();
  108. $conf->ticket->enabled = 0;
  109. }
  110. $this->dictionaries = array(
  111. 'langs' => 'ticket',
  112. 'tabname' => array(
  113. MAIN_DB_PREFIX."c_ticket_type",
  114. MAIN_DB_PREFIX."c_ticket_severity",
  115. MAIN_DB_PREFIX."c_ticket_category",
  116. MAIN_DB_PREFIX."c_ticket_resolution"
  117. ),
  118. 'tablib' => array(
  119. "TicketDictType",
  120. "TicketDictSeverity",
  121. "TicketDictCategory",
  122. "TicketDictResolution"
  123. ),
  124. 'tabsql' => array(
  125. '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',
  126. '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',
  127. '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',
  128. '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'
  129. ),
  130. 'tabsqlsort' => array("pos ASC", "pos ASC", "pos ASC", "pos ASC"),
  131. '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"),
  132. '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"),
  133. '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"),
  134. 'tabrowid' => array("rowid", "rowid", "rowid", "rowid"),
  135. 'tabcond' => array($conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled, $conf->ticket->enabled && !empty($conf->global->TICKET_ENABLE_RESOLUTION)),
  136. 'tabhelp' => array(
  137. array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")),
  138. array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1")),
  139. array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1"), 'public'=>$langs->trans("Enter0or1").'<br>'.$langs->trans("TicketGroupIsPublicDesc"), 'fk_parent'=>$langs->trans("IfThisCategoryIsChildOfAnother")),
  140. array('code'=>$langs->trans("EnterAnyCode"), 'use_default'=>$langs->trans("Enter0or1"))
  141. ),
  142. );
  143. // Boxes
  144. // Add here list of php file(s) stored in core/boxes that contains class to show a box.
  145. $this->boxes = array(
  146. 0=>array('file'=>'box_last_ticket.php', 'enabledbydefaulton'=>'Home'),
  147. 1=>array('file'=>'box_last_modified_ticket.php', 'enabledbydefaulton'=>'Home'),
  148. 2=>array('file'=>'box_ticket_by_severity.php', 'enabledbydefaulton'=>'ticketindex'),
  149. 3=>array('file'=>'box_nb_ticket_last_x_days.php', 'enabledbydefaulton'=>'ticketindex'),
  150. 4=>array('file'=>'box_nb_tickets_type.php', 'enabledbydefaulton'=>'ticketindex'),
  151. 5=>array('file'=>'box_new_vs_close_ticket.php', 'enabledbydefaulton'=>'ticketindex')
  152. ); // Boxes list
  153. // Permissions
  154. $this->rights = array(); // Permission array used by this module
  155. $r = 0;
  156. $this->rights[$r][0] = 56001; // id de la permission
  157. $this->rights[$r][1] = "Read ticket"; // libelle de la permission
  158. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  159. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  160. $this->rights[$r][4] = 'read';
  161. $r++;
  162. $this->rights[$r][0] = 56002; // id de la permission
  163. $this->rights[$r][1] = "Create les tickets"; // libelle de la permission
  164. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  165. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  166. $this->rights[$r][4] = 'write';
  167. $r++;
  168. $this->rights[$r][0] = 56003; // id de la permission
  169. $this->rights[$r][1] = "Delete les tickets"; // libelle de la permission
  170. $this->rights[$r][2] = 'd'; // 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] = 'delete';
  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. /* Seems not used and in conflict with societe->client->voir (see all thirdparties)
  180. $r++;
  181. $this->rights[$r][0] = 56005; // id de la permission
  182. $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
  183. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  184. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  185. $this->rights[$r][4] = 'view';
  186. $this->rights[$r][5] = 'all';
  187. */
  188. // Main menu entries
  189. $this->menus = array(); // List of menus to add
  190. $r = 0;
  191. /*$this->menu[$r] = array('fk_menu' => 0, // Put 0 if this is a top menu
  192. 'type' => 'top', // This is a Top menu entry
  193. 'titre' => 'Ticket',
  194. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth em092"'),
  195. 'mainmenu' => 'ticket',
  196. 'leftmenu' => '1', // Use 1 if you also want to add left menu entries using this descriptor.
  197. 'url' => '/ticket/index.php',
  198. 'langs' => 'ticket', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  199. 'position' => 88,
  200. 'enabled' => '$conf->ticket->enabled',
  201. 'perms' => '$user->rights->ticket->read', // Use 'perms'=>'$user->rights->ticket->level1->level2' if you want your menu with a permission rules
  202. 'target' => '',
  203. 'user' => 2); // 0=Menu for internal users, 1=external users, 2=both
  204. $r++;*/
  205. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket',
  206. 'type' => 'left',
  207. 'titre' => 'Ticket',
  208. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth em092"'),
  209. 'mainmenu' => 'ticket',
  210. 'leftmenu' => 'ticket',
  211. 'url' => '/ticket/index.php',
  212. 'langs' => 'ticket',
  213. 'position' => 101,
  214. 'enabled' => '$conf->ticket->enabled',
  215. 'perms' => '$user->rights->ticket->read',
  216. 'target' => '',
  217. 'user' => 2);
  218. $r++;
  219. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
  220. 'type' => 'left',
  221. 'titre' => 'NewTicket',
  222. 'mainmenu' => 'ticket',
  223. 'url' => '/ticket/card.php?action=create',
  224. 'langs' => 'ticket',
  225. 'position' => 102,
  226. 'enabled' => '$conf->ticket->enabled',
  227. 'perms' => '$user->rights->ticket->write',
  228. 'target' => '',
  229. 'user' => 2);
  230. $r++;
  231. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
  232. 'type' => 'left',
  233. 'titre' => 'List',
  234. 'mainmenu' => 'ticket',
  235. 'leftmenu' => 'ticketlist',
  236. 'url' => '/ticket/list.php?search_fk_status=non_closed',
  237. 'langs' => 'ticket',
  238. 'position' => 103,
  239. 'enabled' => '$conf->ticket->enabled',
  240. 'perms' => '$user->rights->ticket->read',
  241. 'target' => '',
  242. 'user' => 2);
  243. $r++;
  244. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
  245. 'type' => 'left',
  246. 'titre' => 'MenuTicketMyAssign',
  247. 'mainmenu' => 'ticket',
  248. 'leftmenu' => 'ticketmy',
  249. 'url' => '/ticket/list.php?mode=mine&search_fk_status=non_closed',
  250. 'langs' => 'ticket',
  251. 'position' => 105,
  252. 'enabled' => '$conf->ticket->enabled',
  253. 'perms' => '$user->rights->ticket->read',
  254. 'target' => '',
  255. 'user' => 0);
  256. $r++;
  257. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
  258. 'type' => 'left',
  259. 'titre' => 'Statistics',
  260. 'mainmenu' => 'ticket',
  261. 'url' => '/ticket/stats/index.php',
  262. 'langs' => 'ticket',
  263. 'position' => 107,
  264. 'enabled' => '$conf->ticket->enabled',
  265. 'perms' => '$user->rights->ticket->read',
  266. 'target' => '',
  267. 'user' => 0);
  268. $r++;
  269. $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket',
  270. 'type' => 'left',
  271. 'titre' => 'Categories',
  272. 'mainmenu' => 'ticket',
  273. 'url' => '/categories/index.php?type=12',
  274. 'langs' => 'ticket',
  275. 'position' => 107,
  276. 'enabled' => '$conf->categorie->enabled',
  277. 'perms' => '$user->rights->ticket->read',
  278. 'target' => '',
  279. 'user' => 0);
  280. $r++;
  281. }
  282. /**
  283. * Function called when module is enabled.
  284. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  285. * It also creates data directories
  286. *
  287. * @param string $options Options when enabling module ('', 'noboxes')
  288. * @return int 1 if OK, 0 if KO
  289. */
  290. public function init($options = '')
  291. {
  292. global $conf, $langs;
  293. // Permissions
  294. $this->remove($options);
  295. //ODT template
  296. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/tickets/template_ticket.odt';
  297. $dirodt = DOL_DATA_ROOT.'/doctemplates/tickets';
  298. $dest = $dirodt.'/template_order.odt';
  299. if (file_exists($src) && !file_exists($dest)) {
  300. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  301. dol_mkdir($dirodt);
  302. $result = dol_copy($src, $dest, 0, 0);
  303. if ($result < 0) {
  304. $langs->load("errors");
  305. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  306. return 0;
  307. }
  308. }
  309. $sql = array(
  310. 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),
  311. array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110121, 'ticket', 'internal', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
  312. 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),
  313. array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110123, 'ticket', 'external', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
  314. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'TICKET_ADDON_PDF_ODT_PATH' AND type = 'ticket' AND entity = ".((int) $conf->entity),
  315. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('TICKET_ADDON_PDF_ODT_PATH','ticket',".((int) $conf->entity).")"
  316. );
  317. return $this->_init($sql, $options);
  318. }
  319. }