dolibarr  18.0.6
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  *
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 
26 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32 
33 
38 {
42  public $db;
43 
47  public $dao;
48 
49  public $mesg;
50 
54  public $error;
55 
59  public $errors = array();
60 
62  public $errno = 0;
63 
64  public $template_dir;
65  public $template;
66 
70  public $label;
71 
75  public $description;
76 
80  public $fk_statut;
81 
85  public $fk_soc;
86 
92  public function __construct($db)
93  {
94  $this->db = $db;
95  }
96 
102  public function getInstanceDao()
103  {
104  if (!is_object($this->dao)) {
105  $this->dao = new Ticket($this->db);
106  }
107  }
108 
117  public function fetch($id = 0, $ref = '', $track_id = '')
118  {
119  $this->getInstanceDao();
120  return $this->dao->fetch($id, $ref, $track_id);
121  }
122 
129  public function getLibStatut($mode = 0)
130  {
131  $this->getInstanceDao();
132  $this->dao->fk_statut = $this->fk_statut;
133  return $this->dao->getLibStatut($mode);
134  }
135 
142  public function getInfo($id)
143  {
144  $this->getInstanceDao();
145  $this->dao->fetch($id, '', $track_id);
146 
147  $this->label = $this->dao->label;
148  $this->description = $this->dao->description;
149  }
150 
157  public function getTitle($action = '')
158  {
159  global $langs;
160 
161  if ($action == 'create') {
162  return $langs->trans("CreateTicket");
163  } elseif ($action == 'edit') {
164  return $langs->trans("EditTicket");
165  } elseif ($action == 'view') {
166  return $langs->trans("TicketCard");
167  } elseif ($action == 'add_message') {
168  return $langs->trans("TicketAddMessage");
169  } else {
170  return $langs->trans("TicketsManagement");
171  }
172  }
173 
182  public function viewTicketOriginalMessage($user, $action, $object)
183  {
184  global $conf, $langs;
185 
186  print '<!-- initial message of ticket -->'."\n";
187  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
188  // MESSAGE
189 
190  print '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
191  print '<input type="hidden" name="token" value="'.newToken().'">';
192  print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
193  print '<input type="hidden" name="action" value="set_message">';
194  }
195 
196  // Initial message
197  print '<div class="underbanner clearboth"></div>';
198  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
199  print '<table class="noborder centpercent margintable margintablenotop">';
200  print '<tr class="liste_titre trforfield"><td class="nowrap titlefield">';
201  print $langs->trans("InitialMessage");
202  print '</td><td>';
203  if ($user->hasRight("ticket", "manage")) {
204  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>';
205  }
206  print '</td></tr>';
207 
208  print '<tr>';
209  print '<td colspan="2">';
210  if ($user->hasRight('ticket', 'manage') && $action == 'edit_message_init') {
211  // MESSAGE
212  $msg = GETPOSTISSET('message_initial') ? GETPOST('message_initial', 'restricthtml') : $object->message;
213  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
214  $uselocalbrowser = true;
215  $ckeditorenabledforticket = getDolGlobalString('FCKEDITOR_ENABLE_TICKET');
216  $doleditor = new DolEditor('message_initial', $msg, '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser, $ckeditorenabledforticket, ROWS_9, '95%');
217  $doleditor->Create();
218  } else {
219  // Deal with format differences (text / HTML)
220  if (dol_textishtml($object->message)) {
221  print '<div class="longmessagecut">';
222  print dol_htmlwithnojs($object->message);
223  print '</div>';
224  /*print '<div class="clear center">';
225  print $langs->trans("More").'...';
226  print '</div>';*/
227  } else {
228  print '<div class="longmessagecut">';
229  print dol_nl2br($object->message);
230  print '</div>';
231  /*print '<div class="clear center">';
232  print $langs->trans("More").'...';
233  print '</div>';*/
234  }
235 
236  //print '<div>' . $object->message . '</div>';
237  }
238  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
239  print '<div class="center">';
240  print ' <input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
241  print ' <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
242  print '</div>';
243  }
244  print '</td>';
245  print '</tr>';
246  print '</table>';
247  print '</div>';
248 
249  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
250  // MESSAGE
251  print '</form>';
252  }
253  }
254 
263  public function viewTicketMessages($show_private, $show_user, $object)
264  {
265  global $conf, $langs, $user;
266 
267  // Load logs in cache
268  $ret = $this->dao->loadCacheMsgsTicket();
269  if ($ret < 0) {
270  dol_print_error($this->dao->db);
271  }
272 
273  $action = GETPOST('action', 'aZ09');
274 
275  $this->viewTicketOriginalMessage($user, $action, $object);
276 
277  if (is_array($this->dao->cache_msgs_ticket) && count($this->dao->cache_msgs_ticket) > 0) {
278  print '<table class="border" style="width:100%;">';
279 
280  print '<tr class="liste_titre">';
281 
282  print '<td>';
283  print $langs->trans('TicketMessagesList');
284  print '</td>';
285 
286  if ($show_user) {
287  print '<td>';
288  print $langs->trans('User');
289  print '</td>';
290  }
291  print '</tr>';
292 
293  foreach ($this->dao->cache_msgs_ticket as $id => $arraymsgs) {
294  if (!$arraymsgs['private']
295  || ($arraymsgs['private'] == "1" && $show_private)
296  ) {
297  //print '<tr>';
298  print '<tr class="oddeven">';
299  print '<td><strong>';
300  print img_picto('', 'object_action', 'class="paddingright"').dol_print_date($arraymsgs['datep'], 'dayhour');
301  print '<strong></td>';
302  if ($show_user) {
303  print '<td>';
304  if ($arraymsgs['fk_user_author'] > 0) {
305  $userstat = new User($this->db);
306  $res = $userstat->fetch($arraymsgs['fk_user_author']);
307  if ($res) {
308  print $userstat->getNomUrl(0);
309  }
310  } elseif (isset($arraymsgs['fk_contact_author'])) {
311  $contactstat = new Contact($this->db);
312  $res = $contactstat->fetch(0, null, '', $arraymsgs['fk_contact_author']);
313  if ($res) {
314  print $contactstat->getNomUrl(0, 'nolink');
315  } else {
316  print $arraymsgs['fk_contact_author'];
317  }
318  } else {
319  print $langs->trans('Customer');
320  }
321  print '</td>';
322  }
323  print '</td>';
324  print '<tr class="oddeven">';
325  print '<td colspan="2">';
326  print $arraymsgs['message'];
327  print '</td>';
328  print '</tr>';
329  }
330  }
331 
332  print '</table>';
333  } else {
334  print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
335  }
336  }
337 
346  public function viewTicketTimelineMessages($show_private, $show_user, Ticket $object)
347  {
348  global $conf, $langs, $user;
349 
350  // Load logs in cache
351  $ret = $object->loadCacheMsgsTicket();
352  $action = GETPOST('action');
353 
354  if (is_array($object->cache_msgs_ticket) && count($object->cache_msgs_ticket) > 0) {
355  print '<section id="cd-timeline">';
356 
357  foreach ($object->cache_msgs_ticket as $id => $arraymsgs) {
358  if (!$arraymsgs['private']
359  || ($arraymsgs['private'] == "1" && $show_private)
360  ) {
361  print '<div class="cd-timeline-block">';
362  print '<div class="cd-timeline-img">';
363  print '<img src="img/messages.png" alt="">';
364  print '</div> <!-- cd-timeline-img -->';
365 
366  print '<div class="cd-timeline-content">';
367  print $arraymsgs['message'];
368 
369  print '<span class="cd-date">';
370  print dol_print_date($arraymsgs['datec'], 'dayhour');
371 
372  if ($show_user) {
373  if ($arraymsgs['fk_user_action'] > 0) {
374  $userstat = new User($this->db);
375  $res = $userstat->fetch($arraymsgs['fk_user_action']);
376  if ($res) {
377  print '<br>';
378  print $userstat->getNomUrl(1);
379  }
380  } else {
381  print '<br>';
382  print $langs->trans('Customer');
383  }
384  }
385  print '</span>';
386  print '</div> <!-- cd-timeline-content -->';
387  print '</div> <!-- cd-timeline-block -->';
388  }
389  }
390  print '</section>';
391  } else {
392  print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
393  }
394  }
395 
402  public function viewStatusActions(Ticket $object)
403  {
404  global $langs;
405 
406  print '<div class="div-table-responsive-no-min margintoponly navBarForStatus">';
407  print '<div class="centpercent right">';
408  // Exclude status which requires specific method
409  $exclude_status = array(Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED);
410  // Exclude actual status
411  $exclude_status = array_merge($exclude_status, array(intval($object->fk_statut)));
412 
413  // Sort results to be similar to status object list
414  //sort($exclude_status);
415 
416  foreach ($object->statuts_short as $status => $status_label) {
417  if (!in_array($status, $exclude_status)) {
418  print '<div class="inline-block center marginbottomonly">';
419 
420  if ($status == 1) {
421  $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=set_read&token='.newToken(); // To set as read, we use a dedicated action
422  } else {
423  $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=confirm_set_status&token='.newToken().'&new_status='.((int) $status);
424  }
425 
426  print '<a class="butAction butStatus marginbottomonly" href="'.$urlforbutton.'">';
427  print $object->LibStatut($status, 3, 1).' ';
428  //print img_picto($langs->trans($object->statuts_short[$status]), 'statut'.$status.'.png@ticket', '', false, 0, 0, '', 'valignmiddle').' ';
429  print $langs->trans($object->statuts_short[$status]);
430  print '</a>';
431  print '</div>';
432  }
433  }
434  print '</div>';
435  print '</div>';
436  print '<br>';
437  }
438 
448  public function emailElementlist($parameters, &$object, &$action, $hookmanager)
449  {
450  global $langs;
451 
452  $error = 0;
453 
454  if (in_array('admin', explode(':', $parameters['context']))) {
455  $this->results = array('ticket_send' => $langs->trans('MailToSendTicketMessage'));
456  }
457 
458  if (!$error) {
459  return 0; // or return 1 to replace standard code
460  } else {
461  $this->errors[] = 'Error message';
462  return -1;
463  }
464  }
465 }
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.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Class to generate the form for creating a new ticket.