dolibarr  16.0.5
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 
32 
37 {
41  public $db;
42 
46  public $dao;
47 
48  public $mesg;
49 
53  public $error;
54 
58  public $errors = array();
59 
61  public $errno = 0;
62 
63  public $template_dir;
64  public $template;
65 
69  public $label;
70 
74  public $description;
75 
79  public $fk_statut;
80 
84  public $fk_soc;
85 
91  public function __construct($db)
92  {
93  $this->db = $db;
94  }
95 
101  public function getInstanceDao()
102  {
103  if (!is_object($this->dao)) {
104  $this->dao = new Ticket($this->db);
105  }
106  }
107 
116  public function fetch($id = 0, $ref = '', $track_id = '')
117  {
118  $this->getInstanceDao();
119  return $this->dao->fetch($id, $ref, $track_id);
120  }
121 
128  public function getLibStatut($mode = 0)
129  {
130  $this->getInstanceDao();
131  $this->dao->fk_statut = $this->fk_statut;
132  return $this->dao->getLibStatut($mode);
133  }
134 
141  public function getInfo($id)
142  {
143  $this->getInstanceDao();
144  $this->dao->fetch($id, '', $track_id);
145 
146  $this->label = $this->dao->label;
147  $this->description = $this->dao->description;
148  }
149 
156  public function getTitle($action = '')
157  {
158  global $langs;
159 
160  if ($action == 'create') {
161  return $langs->trans("CreateTicket");
162  } elseif ($action == 'edit') {
163  return $langs->trans("EditTicket");
164  } elseif ($action == 'view') {
165  return $langs->trans("TicketCard");
166  } elseif ($action == 'add_message') {
167  return $langs->trans("AddMessage");
168  } else {
169  return $langs->trans("TicketsManagement");
170  }
171  }
172 
181  public function viewTicketOriginalMessage($user, $action, $object)
182  {
183  global $conf, $langs;
184 
185  print '<!-- initial message of ticket -->'."\n";
186  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
187  // MESSAGE
188 
189  print '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
190  print '<input type="hidden" name="token" value="'.newToken().'">';
191  print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
192  print '<input type="hidden" name="action" value="set_message">';
193  }
194 
195  // Initial message
196  print '<div class="underbanner clearboth"></div>';
197  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
198  print '<table class="noborder centpercent margintable margintablenotop">';
199  print '<tr class="liste_titre trforfield"><td class="nowrap titlefield">';
200  print $langs->trans("InitialMessage");
201  print '</td><td>';
202  if ($user->rights->ticket->manage) {
203  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>';
204  }
205  print '</td></tr>';
206 
207  print '<tr>';
208  print '<td colspan="2">';
209  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
210  // MESSAGE
211  $msg = GETPOST('message_initial', 'alpha') ? GETPOST('message_initial', 'alpha') : $object->message;
212  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
213  $uselocalbrowser = true;
214  $ckeditorenabledforticket = $conf->global->FCKEDITOR_ENABLE_TICKET;
215  $doleditor = new DolEditor('message_initial', $msg, '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser, $ckeditorenabledforticket, ROWS_9, '95%');
216  $doleditor->Create();
217  } else {
218  // Deal with format differences (text / HTML)
219  if (dol_textishtml($object->message)) {
220  print '<div class="longmessagecut">';
221  print $object->message;
222  print '</div>';
223  /*print '<div class="clear center">';
224  print $langs->trans("More").'...';
225  print '</div>';*/
226  } else {
227  print '<div class="longmessagecut">';
228  print dol_nl2br($object->message);
229  print '</div>';
230  /*print '<div class="clear center">';
231  print $langs->trans("More").'...';
232  print '</div>';*/
233  }
234 
235  //print '<div>' . $object->message . '</div>';
236  }
237  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
238  print '<div class="center">';
239  print ' <input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
240  print ' <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
241  print '</div>';
242  }
243  print '</td>';
244  print '</tr>';
245  print '</table>';
246  print '</div>';
247 
248  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
249  // MESSAGE
250  print '</form>';
251  }
252  }
253 
262  public function viewTicketMessages($show_private, $show_user, $object)
263  {
264  global $conf, $langs, $user;
265 
266  // Load logs in cache
267  $ret = $this->dao->loadCacheMsgsTicket();
268  if ($ret < 0) {
269  dol_print_error($this->dao->db);
270  }
271 
272  $action = GETPOST('action', 'aZ09');
273 
274  $this->viewTicketOriginalMessage($user, $action, $object);
275 
276  if (is_array($this->dao->cache_msgs_ticket) && count($this->dao->cache_msgs_ticket) > 0) {
277  print '<table class="border" style="width:100%;">';
278 
279  print '<tr class="liste_titre">';
280 
281  print '<td>';
282  print $langs->trans('TicketMessagesList');
283  print '</td>';
284 
285  if ($show_user) {
286  print '<td>';
287  print $langs->trans('User');
288  print '</td>';
289  }
290  print '</tr>';
291 
292  foreach ($this->dao->cache_msgs_ticket as $id => $arraymsgs) {
293  if (!$arraymsgs['private']
294  || ($arraymsgs['private'] == "1" && $show_private)
295  ) {
296  //print '<tr>';
297  print '<tr class="oddeven">';
298  print '<td><strong>';
299  print img_picto('', 'object_action', 'class="paddingright"').dol_print_date($arraymsgs['datep'], 'dayhour');
300  print '<strong></td>';
301  if ($show_user) {
302  print '<td>';
303  if ($arraymsgs['fk_user_author'] > 0) {
304  $userstat = new User($this->db);
305  $res = $userstat->fetch($arraymsgs['fk_user_author']);
306  if ($res) {
307  print $userstat->getNomUrl(0);
308  }
309  } else {
310  print $langs->trans('Customer');
311  }
312  print '</td>';
313  }
314  print '</td>';
315  print '<tr class="oddeven">';
316  print '<td colspan="2">';
317  print $arraymsgs['message'];
318  print '</td>';
319  print '</tr>';
320  }
321  }
322 
323  print '</table>';
324  } else {
325  print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
326  }
327  }
328 
337  public function viewTicketTimelineMessages($show_private, $show_user, Ticket $object)
338  {
339  global $conf, $langs, $user;
340 
341  // Load logs in cache
342  $ret = $object->loadCacheMsgsTicket();
343  $action = GETPOST('action');
344 
345  if (is_array($object->cache_msgs_ticket) && count($object->cache_msgs_ticket) > 0) {
346  print '<section id="cd-timeline">';
347 
348  foreach ($object->cache_msgs_ticket as $id => $arraymsgs) {
349  if (!$arraymsgs['private']
350  || ($arraymsgs['private'] == "1" && $show_private)
351  ) {
352  print '<div class="cd-timeline-block">';
353  print '<div class="cd-timeline-img">';
354  print '<img src="img/messages.png" alt="">';
355  print '</div> <!-- cd-timeline-img -->';
356 
357  print '<div class="cd-timeline-content">';
358  print $arraymsgs['message'];
359 
360  print '<span class="cd-date">';
361  print dol_print_date($arraymsgs['datec'], 'dayhour');
362 
363  if ($show_user) {
364  if ($arraymsgs['fk_user_action'] > 0) {
365  $userstat = new User($this->db);
366  $res = $userstat->fetch($arraymsgs['fk_user_action']);
367  if ($res) {
368  print '<br>';
369  print $userstat->getNomUrl(1);
370  }
371  } else {
372  print '<br>';
373  print $langs->trans('Customer');
374  }
375  }
376  print '</span>';
377  print '</div> <!-- cd-timeline-content -->';
378  print '</div> <!-- cd-timeline-block -->';
379  }
380  }
381  print '</section>';
382  } else {
383  print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
384  }
385  }
386 
393  public function viewStatusActions(Ticket $object)
394  {
395  global $langs;
396 
397  print '<div class="div-table-responsive-no-min margintoponly navBarForStatus">';
398  print '<div class="centpercent right">';
399  // Exclude status which requires specific method
400  $exclude_status = array(Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED);
401  // Exclude actual status
402  $exclude_status = array_merge($exclude_status, array(intval($object->fk_statut)));
403 
404  // Sort results to be similar to status object list
405  //sort($exclude_status);
406 
407  foreach ($object->statuts_short as $status => $status_label) {
408  if (!in_array($status, $exclude_status)) {
409  print '<div class="inline-block center marginbottomonly">';
410 
411  if ($status == 1) {
412  $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=mark_ticket_read'; // To set as read, we use a dedicated action
413  } else {
414  $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=confirm_set_status&token='.newToken().'&new_status='.$status;
415  }
416 
417  print '<a class="butAction butStatus marginbottomonly" href="'.$urlforbutton.'">';
418  print $object->LibStatut($status, 3, 1).' ';
419  //print img_picto($langs->trans($object->statuts_short[$status]), 'statut'.$status.'.png@ticket', '', false, 0, 0, '', 'valignmiddle').' ';
420  print $langs->trans($object->statuts_short[$status]);
421  print '</a>';
422  print '</div>';
423  }
424  }
425  print '</div>';
426  print '</div>';
427  print '<br>';
428  }
429 
439  public function emailElementlist($parameters, &$object, &$action, $hookmanager)
440  {
441  global $langs;
442 
443  $error = 0;
444 
445  if (in_array('admin', explode(':', $parameters['context']))) {
446  $this->results = array('ticket_send' => $langs->trans('MailToSendTicketMessage'));
447  }
448 
449  if (!$error) {
450  return 0; // or return 1 to replace standard code
451  } else {
452  $this->errors[] = 'Error message';
453  return -1;
454  }
455  }
456 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
ActionsTicket\viewTicketMessages
viewTicketMessages($show_private, $show_user, $object)
View html list of message for ticket.
Definition: actions_ticket.class.php:262
ActionsTicket\viewTicketTimelineMessages
viewTicketTimelineMessages($show_private, $show_user, Ticket $object)
View list of message for ticket with timeline display.
Definition: actions_ticket.class.php:337
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_nl2br
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
Definition: functions.lib.php:6963
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
ActionsTicket\getInfo
getInfo($id)
Get ticket info.
Definition: actions_ticket.class.php:141
ActionsTicket\getLibStatut
getLibStatut($mode=0)
Print statut.
Definition: actions_ticket.class.php:128
ActionsTicket
Class Actions of the module ticket.
Definition: actions_ticket.class.php:36
ActionsTicket\emailElementlist
emailElementlist($parameters, &$object, &$action, $hookmanager)
Hook to add email element template.
Definition: actions_ticket.class.php:439
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
ActionsTicket\viewTicketOriginalMessage
viewTicketOriginalMessage($user, $action, $object)
Show ticket original message.
Definition: actions_ticket.class.php:181
User
Class to manage Dolibarr users.
Definition: user.class.php:44
ActionsTicket\fetch
fetch($id=0, $ref='', $track_id='')
Fetch object.
Definition: actions_ticket.class.php:116
ActionsTicket\__construct
__construct($db)
Constructor.
Definition: actions_ticket.class.php:91
Ticket
Class to generate the form for creating a new ticket.
Definition: html.formticket.class.php:31
ActionsTicket\viewStatusActions
viewStatusActions(Ticket $object)
Print html navbar with link to set ticket status.
Definition: actions_ticket.class.php:393
dol_textishtml
dol_textishtml($msg, $option=0)
Return if a text is a html content.
Definition: functions.lib.php:7185
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30
ActionsTicket\$errno
$errno
Numero de l'erreur.
Definition: actions_ticket.class.php:61
ActionsTicket\getTitle
getTitle($action='')
Get action title.
Definition: actions_ticket.class.php:156
ActionsTicket\getInstanceDao
getInstanceDao()
Instantiation of DAO class.
Definition: actions_ticket.class.php:101