dolibarr 24.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
29require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
32require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
33require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
34require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php';
36
37// TODO Only the last method emailElementlist is a hook method. Other must be moved into standard ticket.class.php
38
39
44{
48 public $db;
49
53 public $dao;
54
58 public $mesg;
59
63 public $error;
64
68 public $errors = array();
69
73 public $errno = 0;
74
78 public $template_dir;
82 public $template;
83
87 public $label;
88
92 public $description;
93
97 public $fk_statut;
98
102 public $fk_soc;
103
104
110 public function __construct($db)
111 {
112 $this->db = $db;
113 }
114
120 public function getInstanceDao()
121 {
122 if (!is_object($this->dao)) {
123 $this->dao = new Ticket($this->db);
124 }
125 }
126
135 public function fetch($id = 0, $ref = '', $track_id = '')
136 {
137 $this->getInstanceDao();
138 return $this->dao->fetch($id, $ref, $track_id);
139 }
140
147 public function getLibStatut($mode = 0)
148 {
149 $this->getInstanceDao();
150 $this->dao->fk_statut = $this->fk_statut;
151 return $this->dao->getLibStatut($mode);
152 }
153
160 public function getInfo($id)
161 {
162 $this->getInstanceDao();
163 $this->dao->fetch($id);
164
165 $this->label = $this->dao->label;
166 $this->description = $this->dao->description;
167 }
168
176 public function getTitle($action = '', $object = null)
177 {
178 global $langs;
179
180 if ($action == 'create') {
181 return $langs->trans("CreateTicket");
182 } elseif ($action == 'edit') {
183 return $langs->trans("EditTicket");
184 } elseif ($action == 'view') {
185 return $langs->trans("Ticket").(is_null($object) ? '' : ' '.$object->ref);
186 } elseif ($action == 'add_message') {
187 return $langs->trans("TicketAddMessage");
188 } else {
189 return $langs->trans("Ticket");
190 }
191 }
192
201 public function viewTicketOriginalMessage($user, $action, $object)
202 {
203 dol_syslog(__METHOD__, LOG_DEBUG);
204 global $langs;
205
206 $closeStatuses = [Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED];
207
208 $permissiontoadd = $user->hasRight('ticket', 'write');
209
210 print '<!-- initial message of ticket -->'."\n";
211 if ($permissiontoadd && !in_array($object->status, $closeStatuses) && $action == 'edit_message_init') {
212 // MESSAGE
213 print '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
214 print '<input type="hidden" name="token" value="'.newToken().'">';
215 print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
216 print '<input type="hidden" name="action" value="set_message">';
217 }
218
219 // Initial message
220 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
221 print '<table class="border tableforfield centpercent margintable">';
222 print '<tr class="liste_titre trforfield"><td class="nowrap titlefield">';
223
224 print '<table class="nobordernopadding centpercent "><tr><td class="noborder" style="border-bottom: none !important;">';
225 print $langs->trans('InitialMessage');
226 if ($action != 'edit_message_init' && $permissiontoadd && !in_array($object->status, $closeStatuses)) {
227 print '</td><td class="right noborder" style="border-bottom: none !important;">';
228 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>';
229 }
230 print '</td></tr></table>';
231
232 print '</td><td>';
233 if ($action == 'edit_message_init' && $permissiontoadd && !in_array($object->status, $closeStatuses)) {
234 print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';
235 print ' <input type="submit" class="button button-cancel smallpaddingimp" name="cancel" value="'.$langs->trans("Cancel").'">';
236 }
237 print '</td></tr>';
238
239 print '<tr>';
240 print '<td colspan="2">';
241 if ($permissiontoadd && !in_array($object->status, $closeStatuses) && $action == 'edit_message_init') {
242 // Message
243 $msg = GETPOSTISSET('message_initial') ? GETPOST('message_initial', 'restricthtml') : $object->message;
244 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
245 $uselocalbrowser = -1;
246 $ckeditorenabledforticket = (getDolGlobalString('FCKEDITOR_ENABLE_TICKET') >= 1); // 0=no, 1=from backoffice only, 2=from backoffice+public (very dangerous)
247 if (!$ckeditorenabledforticket) {
248 $msg = dol_string_nohtmltag($msg, 2);
249 }
250 $doleditor = new DolEditor('message_initial', $msg, '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser, $ckeditorenabledforticket, ROWS_9, '95%');
251 $doleditor->Create();
252 } else {
253 print '<div class="longmessagecut small">';
254 print dolPrintHTML($object->message);
255 print '</div>';
256 /*print '<div class="clear center">';
257 print $langs->trans("More").'...';
258 print '</div>';*/
259
260 //print '<div>' . $object->message . '</div>';
261 }
262 print '</td>';
263 print '</tr>';
264 print '</table>';
265 print '</div>';
266
267 if ($permissiontoadd && !in_array($object->status, $closeStatuses) && $action == 'edit_message_init') {
268 // MESSAGE
269 print '</form>';
270 }
271 }
272
281 public function viewTicketMessages($show_private, $show_author, $object)
282 {
283 global $langs, $user;
284
285 // Load logs in cache
286 $ret = $this->dao->loadCacheMsgsTicket();
287 if ($ret < 0) {
288 dol_print_error($this->dao->db);
289 }
290
291 $action = GETPOST('action', 'aZ09');
292
293 print '<div class="ticketpublicarea ticketlargemargin" style="padding-top: 0">';
294 $this->viewTicketOriginalMessage($user, $action, $object);
295 print '</div>';
296
297 if (is_array($this->dao->cache_msgs_ticket) && count($this->dao->cache_msgs_ticket) > 0) {
298 print '<div class="ticketpublicarea ticketlargemargin">';
299
300 print '<div class="div-table-responsive-no-min">';
301 print '<table class="border centpercent">';
302
303 print '<tr class="liste_titre">';
304
305 print '<td>';
306 print '<h4>';
307 print $langs->trans('TicketMessagesList');
308 print '</h4>';
309 print '</td>';
310
311 if ($show_author) {
312 print '<td>';
313 print '<h4>';
314 print $langs->trans('Author');
315 print '</h4>';
316 print '</td>';
317 }
318 print '</tr>';
319
320 $ticket_message_nr = 1;
321 foreach ($this->dao->cache_msgs_ticket as $id => $arraymsgs) {
322 if (!$arraymsgs['private']
323 || ($arraymsgs['private'] == "1" && $show_private)
324 ) {
325 //print '<tr>';
326 print '<tr id="ticket_message_header_'.$ticket_message_nr.'" class="oddeven nohover">';
327 print '<td><strong>';
328 print img_picto('', 'object_action', 'class="paddingright"').dol_print_date($arraymsgs['datep'], 'dayhour');
329 print '<strong></td>';
330 if ($show_author) {
331 print '<td>';
332 if ($arraymsgs['fk_user_author'] > 0) {
333 $userstat = new User($this->db);
334 $res = $userstat->fetch($arraymsgs['fk_user_author']);
335 if ($res) {
336 print img_picto('', 'user', 'class="pictofixedwidth"');
337 print $userstat->getNomUrl(0);
338 }
339 } elseif (isset($arraymsgs['fk_contact_author'])) {
340 $contactstat = new Contact($this->db);
341 $res = $contactstat->fetch(0, null, '', $arraymsgs['fk_contact_author']);
342 if ($res == 2) {
343 print img_picto('', 'email', 'class="pictofixedwidth"');
344 print $arraymsgs['fk_contact_author'];
345 } elseif ($res) {
346 print img_picto('', 'contact', 'class="pictofixedwidth"');
347 print $contactstat->getNomUrl(0, 'nolink');
348 } else {
349 print $arraymsgs['fk_contact_author'];
350 }
351 } else {
352 print '<span class="opacitymedium">'.$langs->trans('Unknown').'</span>';
353 }
354 print '</td>';
355 }
356 print '</tr>';
357
358 print '<tr id="ticket_message_body_'.$ticket_message_nr.'" class="oddeven nohover">';
359 print '<td'.($show_author ? ' colspan="2"' : '').'>';
360 print $arraymsgs['message'];
361
362 //attachment
363
364 $documents = array();
365
366 $sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.agenda_id';
367 $sql .= ', ecm.filepath, ecm.filename, ecm.share';
368 $sql .= ' FROM '.MAIN_DB_PREFIX.'ecm_files ecm';
369 $sql .= " WHERE ecm.filepath = 'agenda/".(int) $arraymsgs['id']."'";
370 $sql .= " OR (ecm.agenda_id = ".(int) $arraymsgs['id']." AND ecm.src_object_type = 'ticket' AND ecm.src_object_id = ".(int) $this->dao->id.")";
371 $sql .= ' ORDER BY ecm.position ASC';
372
373 $resql = $this->db->query($sql);
374 if ($resql) {
375 if ($this->db->num_rows($resql)) {
376 while ($obj = $this->db->fetch_object($resql)) {
377 $documents[$obj->id] = $obj;
378 }
379 }
380 }
381 if (!empty($documents)) {
382 $isshared = 0;
383 $footer = '<div class="timeline-documents-container">';
384 foreach ($documents as $doc) {
385 if (!empty($doc->share) || ($doc->src_object_type == 'ticket')) {
386 $isshared = 1;
387 $footer .= '<span id="document_'.$doc->id.'" class="timeline-documents" ';
388 $footer .= ' data-id="'.$doc->id.'" ';
389 $footer .= ' data-path="'.$doc->filepath.'"';
390 $footer .= ' data-filename="'.dol_escape_htmltag($doc->filename).'" ';
391 $footer .= '>';
392
393 if (empty($doc->agenda_id)) {
394 $dir_ref = $arraymsgs['id'];
395 $modulepart = 'actions';
396 } else {
397 $split_dir = explode('/', $doc->filepath);
398 $modulepart = array_shift($split_dir);
399 $dir_ref = implode('/', $split_dir);
400 }
401 $filePath = DOL_DATA_ROOT.'/'.$doc->filepath.'/'.$doc->filename;
402 $file_relative_path = $dir_ref.'/'.$doc->filename;
403 $mime = dol_mimetype($filePath);
404 $doclink = '';
405 if (!empty($doc->share)) {
406 $doclink = DOL_URL_ROOT.'/document.php?hashp='.urlencode($doc->share);
407 } elseif ($doc->src_object_type == 'ticket') {
408 $downloadwrapper = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') ? getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') . '/document.php' : dol_buildpath('/public/ticket/document.php', 2);
409
410 global $dolibarr_main_instance_unique_id;
411 $securekey = dol_hash('dolibarr-'.$file_relative_path.'-'.$dolibarr_main_instance_unique_id, 'sha256');
412 $doclink = $downloadwrapper.'?modulepart='.$modulepart.'&attachment=0&entity='.getEntity('ticket', 0).'&securekey='.urlencode($securekey).'&file='.urlencode($file_relative_path);
413 }
414
415 $mimeAttr = ' mime="'.$mime.'" ';
416 $class = '';
417 if (in_array($mime, array('image/png', 'image/jpeg', 'application/pdf'))) {
418 $class .= ' documentpreview';
419 }
420
421 $footer .= '<a href="'.$doclink.'" class="btn-link '.$class.'" target="_blank" '.$mimeAttr.' >';
422 $footer .= img_mime($filePath).' '.$doc->filename;
423 $footer .= '</a>';
424
425 $footer .= '</span>';
426 }
427 }
428 $footer .= '</div>';
429 if ($isshared == 1) {
430 print '<br>';
431 print '<br>';
432 print $footer;
433 }
434 }
435 print '</td>';
436 print '</tr>';
437 }
438 $ticket_message_nr++;
439 }
440
441 print '</table>';
442 print '</div>';
443 print '</div>';
444 } else {
445 print '<div class="ticketpublicarea ticketlargemargin">';
446 print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
447 print '</div>';
448 }
449 }
450
459 public function viewTicketTimelineMessages($show_private, $show_author, Ticket $object)
460 {
461 global $langs;
462
463 // Load logs in cache
464 $object->loadCacheMsgsTicket();
465
466 if (is_array($object->cache_msgs_ticket) && count($object->cache_msgs_ticket) > 0) {
467 print '<section id="cd-timeline">';
468
469 foreach ($object->cache_msgs_ticket as $id => $arraymsgs) {
470 if (!$arraymsgs['private']
471 || ($arraymsgs['private'] == "1" && $show_private)
472 ) {
473 print '<div class="cd-timeline-block">';
474 print '<div class="cd-timeline-img">';
475 print '<img src="img/messages.png" alt="">';
476 print '</div> <!-- cd-timeline-img -->';
477
478 print '<div class="cd-timeline-content">';
479 print $arraymsgs['message'];
480
481 print '<span class="cd-date">';
482 print dol_print_date($arraymsgs['datec'], 'dayhour');
483
484 if ($show_author) {
485 if ($arraymsgs['fk_user_action'] > 0) {
486 $userstat = new User($this->db);
487 $res = $userstat->fetch($arraymsgs['fk_user_action']);
488 if ($res) {
489 print '<br>';
490 print $userstat->getNomUrl(1);
491 }
492 } else {
493 print '<br>';
494 print $langs->trans('Customer');
495 }
496 }
497 print '</span>';
498 print '</div> <!-- cd-timeline-content -->';
499 print '</div> <!-- cd-timeline-block -->';
500 }
501 }
502 print '</section>';
503 } else {
504 print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
505 }
506 }
507
515 {
516 global $langs;
517
518 print '<div class="div-table-responsive-no-min margintoponly navBarForStatus">';
519 print '<div class="centpercent right">';
520 // Exclude status which requires specific method
521 $exclude_status = array(Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED);
522 // Exclude actual status
523 $exclude_status = array_merge($exclude_status, array((int) $object->status));
524 // Exclude also the Waiting/Pending/Suspended status
525 if (!getDolGlobalString('TICKET_INCLUDE_SUSPENDED_STATUS')) {
526 $exclude_status[] = $object::STATUS_WAITING;
527 }
528
529 // Sort results to be similar to status object list
530 //sort($exclude_status);
531
532 foreach ($object->labelStatusShort as $status => $status_label) {
533 if (!in_array($status, $exclude_status)) {
534 print '<div class="inline-block center margintoponly marginbottomonly">';
535
536 if ($status == 1) {
537 $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=set_read&token='.newToken(); // To set as read, we use a dedicated action
538 } else {
539 $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=confirm_set_status&token='.newToken().'&new_status='.((int) $status);
540 }
541
542 print '<a class="butAction butStatus marginbottomonly" href="'.$urlforbutton.'">';
543 print $object->LibStatut($status, 3, 1).' ';
544 //print img_picto($langs->trans($object->labelStatusShort[$status]), 'statut'.$status.'.png@ticket', '', 0, 0, 0, '', 'valignmiddle').' ';
545 print $langs->trans($object->labelStatusShort[$status]);
546 print '</a>';
547 print '</div>';
548 }
549 }
550 print '</div>';
551 print '</div>';
552 print '<br>';
553 }
554}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class Actions of the module ticket.
__construct($db)
Constructor.
fetch($id=0, $ref='', $track_id='')
Fetch object.
viewTicketOriginalMessage($user, $action, $object)
Show ticket original message.
getInstanceDao()
Instantiation of DAO class.
getLibStatut($mode=0)
Print statut.
getTitle($action='', $object=null)
Get action title.
viewTicketMessages($show_private, $show_author, $object)
View html list of message for ticket.
viewTicketTimelineMessages($show_private, $show_author, Ticket $object)
View list of message for ticket with timeline display.
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Class to generate the form for creating a new ticket.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.