dolibarr  19.0.0-dev
actions_ticket.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2015 Jean-François FERRY <hello@librethic.io>
3  * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
4  * Copyright (C) 2024 Destailleur Laurent <eldy@users.sourceforge.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 
27 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
32 
33 // TODO Only the last method emailElementlist is a hook method. Other must be moved into standard ticket.class.php
34 
35 
40 {
44  public $db;
45 
49  public $dao;
50 
51  public $mesg;
52 
56  public $error;
57 
61  public $errors = array();
62 
64  public $errno = 0;
65 
66  public $template_dir;
67  public $template;
68 
72  public $label;
73 
77  public $description;
78 
82  public $fk_statut;
83 
87  public $fk_soc;
88 
89 
95  public function __construct($db)
96  {
97  $this->db = $db;
98  }
99 
105  public function getInstanceDao()
106  {
107  if (!is_object($this->dao)) {
108  $this->dao = new Ticket($this->db);
109  }
110  }
111 
120  public function fetch($id = 0, $ref = '', $track_id = '')
121  {
122  $this->getInstanceDao();
123  return $this->dao->fetch($id, $ref, $track_id);
124  }
125 
132  public function getLibStatut($mode = 0)
133  {
134  $this->getInstanceDao();
135  $this->dao->fk_statut = $this->fk_statut;
136  return $this->dao->getLibStatut($mode);
137  }
138 
145  public function getInfo($id)
146  {
147  $this->getInstanceDao();
148  $this->dao->fetch($id);
149 
150  $this->label = $this->dao->label;
151  $this->description = $this->dao->description;
152  }
153 
160  public function getTitle($action = '')
161  {
162  global $langs;
163 
164  if ($action == 'create') {
165  return $langs->trans("CreateTicket");
166  } elseif ($action == 'edit') {
167  return $langs->trans("EditTicket");
168  } elseif ($action == 'view') {
169  return $langs->trans("TicketCard");
170  } elseif ($action == 'add_message') {
171  return $langs->trans("TicketAddMessage");
172  } else {
173  return $langs->trans("TicketsManagement");
174  }
175  }
176 
185  public function viewTicketOriginalMessage($user, $action, $object)
186  {
187  global $conf, $langs;
188 
189  print '<!-- initial message of ticket -->'."\n";
190  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
191  // MESSAGE
192 
193  print '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
194  print '<input type="hidden" name="token" value="'.newToken().'">';
195  print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
196  print '<input type="hidden" name="action" value="set_message">';
197  }
198 
199  // Initial message
200  print '<div class="underbanner clearboth"></div>';
201  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
202  print '<table class="noborder centpercent margintable margintablenotop">';
203  print '<tr class="liste_titre trforfield"><td class="nowrap titlefield">';
204  print $langs->trans("InitialMessage");
205  print '</td><td>';
206  if ($user->hasRight("ticket", "manage")) {
207  print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=edit_message_init&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->trans('Modify')).'</a>';
208  }
209  print '</td></tr>';
210 
211  print '<tr>';
212  print '<td colspan="2">';
213  if ($user->hasRight('ticket', 'manage') && $action == 'edit_message_init') {
214  // MESSAGE
215  $msg = GETPOSTISSET('message_initial') ? GETPOST('message_initial', 'restricthtml') : $object->message;
216  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
217  $uselocalbrowser = true;
218  $ckeditorenabledforticket = $conf->global->FCKEDITOR_ENABLE_TICKET;
219  $doleditor = new DolEditor('message_initial', $msg, '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser, $ckeditorenabledforticket, ROWS_9, '95%');
220  $doleditor->Create();
221  } else {
222  // Deal with format differences (text / HTML)
223  if (dol_textishtml($object->message)) {
224  print '<div class="longmessagecut">';
225  print dol_htmlwithnojs($object->message);
226  print '</div>';
227  /*print '<div class="clear center">';
228  print $langs->trans("More").'...';
229  print '</div>';*/
230  } else {
231  print '<div class="longmessagecut">';
232  print dol_nl2br($object->message);
233  print '</div>';
234  /*print '<div class="clear center">';
235  print $langs->trans("More").'...';
236  print '</div>';*/
237  }
238 
239  //print '<div>' . $object->message . '</div>';
240  }
241  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
242  print '<div class="center">';
243  print ' <input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
244  print ' <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
245  print '</div>';
246  }
247  print '</td>';
248  print '</tr>';
249  print '</table>';
250  print '</div>';
251 
252  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
253  // MESSAGE
254  print '</form>';
255  }
256  }
257 
266  public function viewTicketMessages($show_private, $show_user, $object)
267  {
268  global $conf, $langs, $user;
269 
270  // Load logs in cache
271  $ret = $this->dao->loadCacheMsgsTicket();
272  if ($ret < 0) {
273  dol_print_error($this->dao->db);
274  }
275 
276  $action = GETPOST('action', 'aZ09');
277 
278  $this->viewTicketOriginalMessage($user, $action, $object);
279 
280  if (is_array($this->dao->cache_msgs_ticket) && count($this->dao->cache_msgs_ticket) > 0) {
281  print '<table class="border" style="width:100%;">';
282 
283  print '<tr class="liste_titre">';
284 
285  print '<td>';
286  print $langs->trans('TicketMessagesList');
287  print '</td>';
288 
289  if ($show_user) {
290  print '<td>';
291  print $langs->trans('User');
292  print '</td>';
293  }
294  print '</tr>';
295 
296  foreach ($this->dao->cache_msgs_ticket as $id => $arraymsgs) {
297  if (!$arraymsgs['private']
298  || ($arraymsgs['private'] == "1" && $show_private)
299  ) {
300  //print '<tr>';
301  print '<tr class="oddeven">';
302  print '<td><strong>';
303  print img_picto('', 'object_action', 'class="paddingright"').dol_print_date($arraymsgs['datec'], 'dayhour');
304  print '<strong></td>';
305  if ($show_user) {
306  print '<td>';
307  if ($arraymsgs['fk_user_author'] > 0) {
308  $userstat = new User($this->db);
309  $res = $userstat->fetch($arraymsgs['fk_user_author']);
310  if ($res) {
311  print $userstat->getNomUrl(0);
312  }
313  } elseif (isset($arraymsgs['fk_contact_author'])) {
314  $contactstat = new Contact($this->db);
315  $res = $contactstat->fetch(0, null, '', $arraymsgs['fk_contact_author']);
316  if ($res) {
317  print $contactstat->getNomUrl(0, 'nolink');
318  } else {
319  print $arraymsgs['fk_contact_author'];
320  }
321  } else {
322  print $langs->trans('Customer');
323  }
324  print '</td>';
325  }
326  print '</td>';
327  print '<tr class="oddeven">';
328  print '<td colspan="2">';
329  print $arraymsgs['message'];
330  print '</td>';
331  print '</tr>';
332  }
333  }
334 
335  print '</table>';
336  } else {
337  print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
338  }
339  }
340 
349  public function viewTicketTimelineMessages($show_private, $show_user, Ticket $object)
350  {
351  global $conf, $langs, $user;
352 
353  // Load logs in cache
354  $ret = $object->loadCacheMsgsTicket();
355  $action = GETPOST('action');
356 
357  if (is_array($object->cache_msgs_ticket) && count($object->cache_msgs_ticket) > 0) {
358  print '<section id="cd-timeline">';
359 
360  foreach ($object->cache_msgs_ticket as $id => $arraymsgs) {
361  if (!$arraymsgs['private']
362  || ($arraymsgs['private'] == "1" && $show_private)
363  ) {
364  print '<div class="cd-timeline-block">';
365  print '<div class="cd-timeline-img">';
366  print '<img src="img/messages.png" alt="">';
367  print '</div> <!-- cd-timeline-img -->';
368 
369  print '<div class="cd-timeline-content">';
370  print $arraymsgs['message'];
371 
372  print '<span class="cd-date">';
373  print dol_print_date($arraymsgs['datec'], 'dayhour');
374 
375  if ($show_user) {
376  if ($arraymsgs['fk_user_action'] > 0) {
377  $userstat = new User($this->db);
378  $res = $userstat->fetch($arraymsgs['fk_user_action']);
379  if ($res) {
380  print '<br>';
381  print $userstat->getNomUrl(1);
382  }
383  } else {
384  print '<br>';
385  print $langs->trans('Customer');
386  }
387  }
388  print '</span>';
389  print '</div> <!-- cd-timeline-content -->';
390  print '</div> <!-- cd-timeline-block -->';
391  }
392  }
393  print '</section>';
394  } else {
395  print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
396  }
397  }
398 
405  public function viewStatusActions(Ticket $object)
406  {
407  global $langs;
408 
409  print '<div class="div-table-responsive-no-min margintoponly navBarForStatus">';
410  print '<div class="centpercent right">';
411  // Exclude status which requires specific method
412  $exclude_status = array(Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED);
413  // Exclude actual status
414  $exclude_status = array_merge($exclude_status, array(intval($object->fk_statut)));
415 
416  // Sort results to be similar to status object list
417  //sort($exclude_status);
418 
419  foreach ($object->statuts_short as $status => $status_label) {
420  if (!in_array($status, $exclude_status)) {
421  print '<div class="inline-block center marginbottomonly">';
422 
423  if ($status == 1) {
424  $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=set_read&token='.newToken(); // To set as read, we use a dedicated action
425  } else {
426  $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=confirm_set_status&token='.newToken().'&new_status='.((int) $status);
427  }
428 
429  print '<a class="butAction butStatus marginbottomonly" href="'.$urlforbutton.'">';
430  print $object->LibStatut($status, 3, 1).' ';
431  //print img_picto($langs->trans($object->statuts_short[$status]), 'statut'.$status.'.png@ticket', '', false, 0, 0, '', 'valignmiddle').' ';
432  print $langs->trans($object->statuts_short[$status]);
433  print '</a>';
434  print '</div>';
435  }
436  }
437  print '</div>';
438  print '</div>';
439  print '<br>';
440  }
441 
451  public function emailElementlist($parameters, &$object, &$action, $hookmanager)
452  {
453  global $langs;
454 
455  $error = 0;
456 
457  if (in_array('admin', explode(':', $parameters['context']))) {
458  $this->results = array('ticket_send' => $langs->trans('MailToSendTicketMessage'));
459  }
460 
461  if (!$error) {
462  return 0; // or return 1 to replace standard code
463  } else {
464  $this->errors[] = 'Error message';
465  return -1;
466  }
467  }
468 }
Class Actions of the module ticket.
viewTicketMessages($show_private, $show_user, $object)
View html list of message for ticket.
getTitle($action='')
Get action title.
__construct($db)
Constructor.
emailElementlist($parameters, &$object, &$action, $hookmanager)
Hook to add email element template.
$errno
Numero de l'erreur.
fetch($id=0, $ref='', $track_id='')
Fetch object.
viewTicketOriginalMessage($user, $action, $object)
Show ticket original message.
viewTicketTimelineMessages($show_private, $show_user, Ticket $object)
View list of message for ticket with timeline display.
getInstanceDao()
Instantiation of DAO class.
getLibStatut($mode=0)
Print statut.
viewStatusActions(Ticket $object)
Print html navbar with link to set ticket status.
getInfo($id)
Get ticket info.
Parent class of all other hook actions classes.
Class to manage contact/addresses.
Class to manage a WYSIWYG editor.
Class to manage Dolibarr users.
Definition: user.class.php:48
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js and dangerous content.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Class to generate the form for creating a new ticket.