dolibarr  13.0.2
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 
43  public $dao;
44 
45  public $mesg;
46 
50  public $error;
51 
55  public $errors = array();
56 
58  public $errno = 0;
59 
60  public $template_dir;
61  public $template;
62 
66  public $label;
67 
71  public $description;
72 
76  public $fk_statut;
77 
81  public $fk_soc;
82 
88  public function __construct($db)
89  {
90  $this->db = $db;
91  }
92 
98  public function getInstanceDao()
99  {
100  if (!is_object($this->dao)) {
101  $this->dao = new Ticket($this->db);
102  }
103  }
104 
113  public function fetch($id = 0, $ref = '', $track_id = '')
114  {
115  $this->getInstanceDao();
116  return $this->dao->fetch($id, $ref, $track_id);
117  }
118 
125  public function getLibStatut($mode = 0)
126  {
127  $this->getInstanceDao();
128  $this->dao->fk_statut = $this->fk_statut;
129  return $this->dao->getLibStatut($mode);
130  }
131 
138  public function getInfo($id)
139  {
140  $this->getInstanceDao();
141  $this->dao->fetch($id, '', $track_id);
142 
143  $this->label = $this->dao->label;
144  $this->description = $this->dao->description;
145  }
146 
153  public function getTitle($action = '')
154  {
155  global $langs;
156 
157  if ($action == 'create') {
158  return $langs->trans("CreateTicket");
159  } elseif ($action == 'edit') {
160  return $langs->trans("EditTicket");
161  } elseif ($action == 'view') {
162  return $langs->trans("TicketCard");
163  } elseif ($action == 'add_message') {
164  return $langs->trans("AddMessage");
165  } else {
166  return $langs->trans("TicketsManagement");
167  }
168  }
169 
178  public function viewTicketOriginalMessage($user, $action, $object)
179  {
180  global $conf, $langs;
181 
182  print '<!-- initial message of ticket -->'."\n";
183  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
184  // MESSAGE
185 
186  print '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
187  print '<input type="hidden" name="token" value="'.newToken().'">';
188  print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
189  print '<input type="hidden" name="action" value="set_message">';
190  }
191 
192  // Initial message
193  print '<div class="underbanner clearboth"></div>';
194  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
195  print '<table class="noborder centpercent margintable">';
196  print '<tr class="liste_titre trforfield"><td class="nowrap titlefield">';
197  print $langs->trans("InitialMessage");
198  print '</td><td>';
199  if ($user->rights->ticket->manage) {
200  print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=edit_message_init&amp;track_id='.$object->track_id.'">'.img_edit($langs->trans('Modify')).'</a>';
201  }
202  print '</td></tr>';
203 
204  print '<tr>';
205  print '<td colspan="2">';
206  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
207  // MESSAGE
208  $msg = GETPOST('message_initial', 'alpha') ? GETPOST('message_initial', 'alpha') : $object->message;
209  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
210  $uselocalbrowser = true;
211  $ckeditorenabledforticket = $conf->global->FCKEDITOR_ENABLE_TICKET;
212  $doleditor = new DolEditor('message_initial', $msg, '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser, $ckeditorenabledforticket, ROWS_9, '95%');
213  $doleditor->Create();
214  } else {
215  // Deal with format differences (text / HTML)
216  if (dol_textishtml($object->message)) {
217  print '<div class="longmessagecut">';
218  print $object->message;
219  print '</div>';
220  /*print '<div class="clear center">';
221  print $langs->trans("More").'...';
222  print '</div>';*/
223  } else {
224  print '<div class="longmessagecut">';
225  print dol_nl2br($object->message);
226  print '</div>';
227  /*print '<div class="clear center">';
228  print $langs->trans("More").'...';
229  print '</div>';*/
230  }
231 
232  //print '<div>' . $object->message . '</div>';
233  }
234  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
235  print '<div class="center">';
236  print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
237  print ' <input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
238  print '</div>';
239  }
240  print '</td>';
241  print '</tr>';
242  print '</table>';
243  print '</div>';
244 
245  if (!empty($user->rights->ticket->manage) && $action == 'edit_message_init') {
246  // MESSAGE
247  print '</form>';
248  }
249  }
250 
259  public function viewTicketMessages($show_private, $show_user, $object)
260  {
261  global $conf, $langs, $user;
262 
263  // Load logs in cache
264  $ret = $this->dao->loadCacheMsgsTicket();
265  if ($ret < 0) dol_print_error($this->dao->db);
266 
267  $action = GETPOST('action', 'aZ09');
268 
269  $this->viewTicketOriginalMessage($user, $action, $object);
270 
271  if (is_array($this->dao->cache_msgs_ticket) && count($this->dao->cache_msgs_ticket) > 0)
272  {
273  print '<table class="border" style="width:100%;">';
274 
275  print '<tr class="liste_titre">';
276 
277  print '<td>';
278  print $langs->trans('TicketMessagesList');
279  print '</td>';
280 
281  if ($show_user) {
282  print '<td>';
283  print $langs->trans('User');
284  print '</td>';
285  }
286  print '</tr>';
287 
288  foreach ($this->dao->cache_msgs_ticket as $id => $arraymsgs) {
289  if (!$arraymsgs['private']
290  || ($arraymsgs['private'] == "1" && $show_private)
291  ) {
292  //print '<tr>';
293  print '<tr class="oddeven">';
294  print '<td><strong>';
295  print img_picto('', 'object_action', 'class="paddingright"').dol_print_date($arraymsgs['datec'], 'dayhour');
296  print '<strong></td>';
297  if ($show_user) {
298  print '<td>';
299  if ($arraymsgs['fk_user_author'] > 0) {
300  $userstat = new User($this->db);
301  $res = $userstat->fetch($arraymsgs['fk_user_author']);
302  if ($res) {
303  print $userstat->getNomUrl(0);
304  }
305  } else {
306  print $langs->trans('Customer');
307  }
308  print '</td>';
309  }
310  print '</td>';
311  print '<tr class="oddeven">';
312  print '<td colspan="2">';
313  print $arraymsgs['message'];
314  print '</td>';
315  print '</tr>';
316  }
317  }
318 
319  print '</table>';
320  } else {
321  print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
322  }
323  }
324 
333  public function viewTicketTimelineMessages($show_private, $show_user, Ticket $object)
334  {
335  global $conf, $langs, $user;
336 
337  // Load logs in cache
338  $ret = $object->loadCacheMsgsTicket();
339  $action = GETPOST('action');
340 
341  if (is_array($object->cache_msgs_ticket) && count($object->cache_msgs_ticket) > 0) {
342  print '<section id="cd-timeline">';
343 
344  foreach ($object->cache_msgs_ticket as $id => $arraymsgs) {
345  if (!$arraymsgs['private']
346  || ($arraymsgs['private'] == "1" && $show_private)
347  ) {
348  print '<div class="cd-timeline-block">';
349  print '<div class="cd-timeline-img">';
350  print '<img src="img/messages.png" alt="">';
351  print '</div> <!-- cd-timeline-img -->';
352 
353  print '<div class="cd-timeline-content">';
354  print $arraymsgs['message'];
355 
356  print '<span class="cd-date">';
357  print dol_print_date($arraymsgs['datec'], 'dayhour');
358 
359  if ($show_user) {
360  if ($arraymsgs['fk_user_action'] > 0) {
361  $userstat = new User($this->db);
362  $res = $userstat->fetch($arraymsgs['fk_user_action']);
363  if ($res) {
364  print '<br>';
365  print $userstat->getNomUrl(1);
366  }
367  } else {
368  print '<br>';
369  print $langs->trans('Customer');
370  }
371  }
372  print '</span>';
373  print '</div> <!-- cd-timeline-content -->';
374  print '</div> <!-- cd-timeline-block -->';
375  }
376  }
377  print '</section>';
378  } else {
379  print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
380  }
381  }
382 
389  public function viewStatusActions(Ticket $object)
390  {
391  global $langs;
392 
393  print '<div class="div-table-responsive-no-min margintoponly">';
394  print '<div class="centpercent right">';
395  // Exclude status which requires specific method
396  $exclude_status = array(Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED);
397  // Exclude actual status
398  $exclude_status = array_merge($exclude_status, array(intval($object->fk_statut)));
399 
400  // Sort results to be similar to status object list
401  //sort($exclude_status);
402 
403  foreach ($object->statuts_short as $status => $status_label) {
404  if (!in_array($status, $exclude_status)) {
405  print '<div class="inline-block center marginbottomonly">';
406 
407  if ($status == 1) {
408  $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=mark_ticket_read'; // To set as read, we use a dedicated action
409  } else {
410  $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=set_status&token='.newToken().'&new_status='.$status;
411  }
412 
413  print '<a class="butAction butStatus marginbottomonly" href="'.$urlforbutton.'">';
414  print $object->LibStatut($status, 3, 1).' ';
415  //print img_picto($langs->trans($object->statuts_short[$status]), 'statut'.$status.'.png@ticket', '', false, 0, 0, '', 'valignmiddle').' ';
416  print $langs->trans($object->statuts_short[$status]);
417  print '</a>';
418  print '</div>';
419  }
420  }
421  print '</div></div><br>';
422  }
423 
433  public function emailElementlist($parameters, &$object, &$action, $hookmanager)
434  {
435  global $langs;
436 
437  $error = 0;
438 
439  if (in_array('admin', explode(':', $parameters['context']))) {
440  $this->results = array('ticket_send' => $langs->trans('MailToSendTicketMessage'));
441  }
442 
443  if (!$error) {
444  return 0; // or return 1 to replace standard code
445  } else {
446  $this->errors[] = 'Error message';
447  return -1;
448  }
449  }
450 }
viewTicketMessages($show_private, $show_user, $object)
View html list of message for ticket.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
LibStatut($status, $mode=0, $notooltip=0)
Return status label of object.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage ticket.
viewTicketTimelineMessages($show_private, $show_user, Ticket $object)
View list of message for ticket with timeline display.
getLibStatut($mode=0)
Print statut.
emailElementlist($parameters, &$object, &$action, $hookmanager)
Hook to add email element template.
viewStatusActions(Ticket $object)
Print html navbar with link to set ticket status.
getTitle($action= '')
Get action title.
__construct($db)
Constructor.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
viewTicketOriginalMessage($user, $action, $object)
Show ticket original message.
getInstanceDao()
Instantiation of DAO class.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class Actions of the module ticket.
fetch($id=0, $ref= '', $track_id= '')
Fetch object.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
Class to manage a WYSIWYG editor.
$errno
Numero de l&#39;erreur.
loadCacheMsgsTicket()
Load the list of event on ticket into -&gt;cache_msgs_ticket.
getInfo($id)
Get ticket info.
dol_textishtml($msg, $option=0)
Return if a text is a html content.