actions_ticket.class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <?php
  2. /* Copyright (C) 2013-2015 Jean-François FERRY <hello@librethic.io>
  3. * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. /**
  20. * \file ticket/class/actions_ticket.class.php
  21. * \ingroup ticket
  22. * \brief File Class ticket
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  29. /**
  30. * Class Actions of the module ticket
  31. */
  32. class ActionsTicket
  33. {
  34. /**
  35. * @var DoliDB Database handler.
  36. */
  37. public $db;
  38. public $dao;
  39. public $mesg;
  40. /**
  41. * @var string Error code (or message)
  42. */
  43. public $error;
  44. /**
  45. * @var string[] Error codes (or messages)
  46. */
  47. public $errors = array();
  48. //! Numero de l'erreur
  49. public $errno = 0;
  50. public $template_dir;
  51. public $template;
  52. /**
  53. * @var string ticket action label
  54. */
  55. public $label;
  56. /**
  57. * @var string description
  58. */
  59. public $description;
  60. /**
  61. * @var int ID
  62. */
  63. public $fk_statut;
  64. /**
  65. * @var int Thirdparty ID
  66. */
  67. public $fk_soc;
  68. /**
  69. * Constructor
  70. *
  71. * @param DoliDB $db Database handler
  72. */
  73. public function __construct($db)
  74. {
  75. $this->db = $db;
  76. }
  77. /**
  78. * Instantiation of DAO class
  79. *
  80. * @return void
  81. */
  82. public function getInstanceDao()
  83. {
  84. if (!is_object($this->dao)) {
  85. $this->dao = new Ticket($this->db);
  86. }
  87. }
  88. /**
  89. * Fetch object
  90. *
  91. * @param int $id ID of ticket
  92. * @param string $ref Reference of ticket
  93. * @param string $track_id Track ID of ticket (for public area)
  94. * @return void
  95. */
  96. public function fetch($id = 0, $ref = '', $track_id = '')
  97. {
  98. $this->getInstanceDao();
  99. return $this->dao->fetch($id, $ref, $track_id);
  100. }
  101. /**
  102. * Print statut
  103. *
  104. * @param int $mode Display mode
  105. * @return string Label of status
  106. */
  107. public function getLibStatut($mode = 0)
  108. {
  109. $this->getInstanceDao();
  110. $this->dao->fk_statut = $this->fk_statut;
  111. return $this->dao->getLibStatut($mode);
  112. }
  113. /**
  114. * Get ticket info
  115. *
  116. * @param int $id Object id
  117. * @return void
  118. */
  119. public function getInfo($id)
  120. {
  121. $this->getInstanceDao();
  122. $this->dao->fetch($id, '', $track_id);
  123. $this->label = $this->dao->label;
  124. $this->description = $this->dao->description;
  125. }
  126. /**
  127. * Get action title
  128. *
  129. * @param string $action Type of action
  130. * @return string Title of action
  131. */
  132. public function getTitle($action = '')
  133. {
  134. global $langs;
  135. if ($action == 'create') {
  136. return $langs->trans("CreateTicket");
  137. } elseif ($action == 'edit') {
  138. return $langs->trans("EditTicket");
  139. } elseif ($action == 'view') {
  140. return $langs->trans("TicketCard");
  141. } elseif ($action == 'add_message') {
  142. return $langs->trans("AddMessage");
  143. } else {
  144. return $langs->trans("TicketsManagement");
  145. }
  146. }
  147. /**
  148. * Show ticket original message
  149. *
  150. * @param User $user User wich display
  151. * @param string $action Action mode
  152. * @param Ticket $object Object ticket
  153. * @return void
  154. */
  155. public function viewTicketOriginalMessage($user, $action, $object)
  156. {
  157. global $conf, $langs;
  158. print '<!-- initial message of ticket -->'."\n";
  159. if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
  160. // MESSAGE
  161. print '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
  162. print '<input type="hidden" name="token" value="'.newToken().'">';
  163. print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
  164. print '<input type="hidden" name="action" value="set_message">';
  165. }
  166. // Initial message
  167. print '<div class="underbanner clearboth"></div>';
  168. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  169. print '<table class="noborder centpercent margintable margintablenotop">';
  170. print '<tr class="liste_titre trforfield"><td class="nowrap titlefield">';
  171. print $langs->trans("InitialMessage");
  172. print '</td><td>';
  173. if ($user->rights->ticket->manage) {
  174. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=edit_message_init&amp;track_id='.$object->track_id.'">'.img_edit($langs->trans('Modify')).'</a>';
  175. }
  176. print '</td></tr>';
  177. print '<tr>';
  178. print '<td colspan="2">';
  179. if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
  180. // MESSAGE
  181. $msg = GETPOST('message_initial', 'alpha') ? GETPOST('message_initial', 'alpha') : $object->message;
  182. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  183. $uselocalbrowser = true;
  184. $ckeditorenabledforticket = $conf->global->FCKEDITOR_ENABLE_TICKET;
  185. $doleditor = new DolEditor('message_initial', $msg, '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser, $ckeditorenabledforticket, ROWS_9, '95%');
  186. $doleditor->Create();
  187. } else {
  188. // Deal with format differences (text / HTML)
  189. if (dol_textishtml($object->message)) {
  190. print '<div class="longmessagecut">';
  191. print $object->message;
  192. print '</div>';
  193. /*print '<div class="clear center">';
  194. print $langs->trans("More").'...';
  195. print '</div>';*/
  196. } else {
  197. print '<div class="longmessagecut">';
  198. print dol_nl2br($object->message);
  199. print '</div>';
  200. /*print '<div class="clear center">';
  201. print $langs->trans("More").'...';
  202. print '</div>';*/
  203. }
  204. //print '<div>' . $object->message . '</div>';
  205. }
  206. if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
  207. print '<div class="center">';
  208. print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  209. print ' <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  210. print '</div>';
  211. }
  212. print '</td>';
  213. print '</tr>';
  214. print '</table>';
  215. print '</div>';
  216. if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
  217. // MESSAGE
  218. print '</form>';
  219. }
  220. }
  221. /**
  222. * View html list of message for ticket
  223. *
  224. * @param boolean $show_private Show private messages
  225. * @param boolean $show_user Show user who make action
  226. * @param Ticket $object Object ticket
  227. * @return void
  228. */
  229. public function viewTicketMessages($show_private, $show_user, $object)
  230. {
  231. global $conf, $langs, $user;
  232. // Load logs in cache
  233. $ret = $this->dao->loadCacheMsgsTicket();
  234. if ($ret < 0) {
  235. dol_print_error($this->dao->db);
  236. }
  237. $action = GETPOST('action', 'aZ09');
  238. $this->viewTicketOriginalMessage($user, $action, $object);
  239. if (is_array($this->dao->cache_msgs_ticket) && count($this->dao->cache_msgs_ticket) > 0) {
  240. print '<table class="border" style="width:100%;">';
  241. print '<tr class="liste_titre">';
  242. print '<td>';
  243. print $langs->trans('TicketMessagesList');
  244. print '</td>';
  245. if ($show_user) {
  246. print '<td>';
  247. print $langs->trans('User');
  248. print '</td>';
  249. }
  250. print '</tr>';
  251. foreach ($this->dao->cache_msgs_ticket as $id => $arraymsgs) {
  252. if (!$arraymsgs['private']
  253. || ($arraymsgs['private'] == "1" && $show_private)
  254. ) {
  255. //print '<tr>';
  256. print '<tr class="oddeven">';
  257. print '<td><strong>';
  258. print img_picto('', 'object_action', 'class="paddingright"').dol_print_date($arraymsgs['datec'], 'dayhour');
  259. print '<strong></td>';
  260. if ($show_user) {
  261. print '<td>';
  262. if ($arraymsgs['fk_user_author'] > 0) {
  263. $userstat = new User($this->db);
  264. $res = $userstat->fetch($arraymsgs['fk_user_author']);
  265. if ($res) {
  266. print $userstat->getNomUrl(0);
  267. }
  268. } else {
  269. print $langs->trans('Customer');
  270. }
  271. print '</td>';
  272. }
  273. print '</td>';
  274. print '<tr class="oddeven">';
  275. print '<td colspan="2">';
  276. print $arraymsgs['message'];
  277. print '</td>';
  278. print '</tr>';
  279. }
  280. }
  281. print '</table>';
  282. } else {
  283. print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
  284. }
  285. }
  286. /**
  287. * View list of message for ticket with timeline display
  288. *
  289. * @param boolean $show_private Show private messages
  290. * @param boolean $show_user Show user who make action
  291. * @param Ticket $object Object ticket
  292. * @return void
  293. */
  294. public function viewTicketTimelineMessages($show_private, $show_user, Ticket $object)
  295. {
  296. global $conf, $langs, $user;
  297. // Load logs in cache
  298. $ret = $object->loadCacheMsgsTicket();
  299. $action = GETPOST('action');
  300. if (is_array($object->cache_msgs_ticket) && count($object->cache_msgs_ticket) > 0) {
  301. print '<section id="cd-timeline">';
  302. foreach ($object->cache_msgs_ticket as $id => $arraymsgs) {
  303. if (!$arraymsgs['private']
  304. || ($arraymsgs['private'] == "1" && $show_private)
  305. ) {
  306. print '<div class="cd-timeline-block">';
  307. print '<div class="cd-timeline-img">';
  308. print '<img src="img/messages.png" alt="">';
  309. print '</div> <!-- cd-timeline-img -->';
  310. print '<div class="cd-timeline-content">';
  311. print $arraymsgs['message'];
  312. print '<span class="cd-date">';
  313. print dol_print_date($arraymsgs['datec'], 'dayhour');
  314. if ($show_user) {
  315. if ($arraymsgs['fk_user_action'] > 0) {
  316. $userstat = new User($this->db);
  317. $res = $userstat->fetch($arraymsgs['fk_user_action']);
  318. if ($res) {
  319. print '<br>';
  320. print $userstat->getNomUrl(1);
  321. }
  322. } else {
  323. print '<br>';
  324. print $langs->trans('Customer');
  325. }
  326. }
  327. print '</span>';
  328. print '</div> <!-- cd-timeline-content -->';
  329. print '</div> <!-- cd-timeline-block -->';
  330. }
  331. }
  332. print '</section>';
  333. } else {
  334. print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
  335. }
  336. }
  337. /**
  338. * Print html navbar with link to set ticket status
  339. *
  340. * @param Ticket $object Ticket sup
  341. * @return void
  342. */
  343. public function viewStatusActions(Ticket $object)
  344. {
  345. global $langs;
  346. print '<div class="div-table-responsive-no-min margintoponly navBarForStatus">';
  347. print '<div class="centpercent right">';
  348. // Exclude status which requires specific method
  349. $exclude_status = array(Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED);
  350. // Exclude actual status
  351. $exclude_status = array_merge($exclude_status, array(intval($object->fk_statut)));
  352. // Sort results to be similar to status object list
  353. //sort($exclude_status);
  354. foreach ($object->statuts_short as $status => $status_label) {
  355. if (!in_array($status, $exclude_status)) {
  356. print '<div class="inline-block center marginbottomonly">';
  357. if ($status == 1) {
  358. $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=mark_ticket_read'; // To set as read, we use a dedicated action
  359. } else {
  360. $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=confirm_set_status&token='.newToken().'&new_status='.$status;
  361. }
  362. print '<a class="butAction butStatus marginbottomonly" href="'.$urlforbutton.'">';
  363. print $object->LibStatut($status, 3, 1).' ';
  364. //print img_picto($langs->trans($object->statuts_short[$status]), 'statut'.$status.'.png@ticket', '', false, 0, 0, '', 'valignmiddle').' ';
  365. print $langs->trans($object->statuts_short[$status]);
  366. print '</a>';
  367. print '</div>';
  368. }
  369. }
  370. print '</div>';
  371. print '</div>';
  372. print '<br>';
  373. }
  374. /**
  375. * Hook to add email element template
  376. *
  377. * @param array $parameters Parameters
  378. * @param Ticket $object Object for action
  379. * @param string $action Action string
  380. * @param HookManager $hookmanager Hookmanager object
  381. * @return int
  382. */
  383. public function emailElementlist($parameters, &$object, &$action, $hookmanager)
  384. {
  385. global $langs;
  386. $error = 0;
  387. if (in_array('admin', explode(':', $parameters['context']))) {
  388. $this->results = array('ticket_send' => $langs->trans('MailToSendTicketMessage'));
  389. }
  390. if (!$error) {
  391. return 0; // or return 1 to replace standard code
  392. } else {
  393. $this->errors[] = 'Error message';
  394. return -1;
  395. }
  396. }
  397. }