dolibarr 25.0.0-alpha
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, $db, $conf;
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
248 // Add layout and AI tools for message
249 $out = '';
250 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
251 $formmail = new FormMail($db);
252 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formai.class.php';
253 $formai = new FormAI($db);
254
255 $formmail->withfckeditor = $ckeditorenabledforticket ? 1 : 0;
256 $formmail->withlayout = ($ckeditorenabledforticket) ? 'email' : '';
257 $formmail->withaiprompt = (isModEnabled('ai')) ? 'text' : '';
258
259 $showlinktolayout = ($formmail->withfckeditor && getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout : '';
260 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
261 $showlinktoai = ($formmail->withaiprompt ? 'textgenerationemail' : '');
262 $showlinktoailabel = $langs->trans("AIEnhancements");
263 $htmlname = 'message_initial';
264
265 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
266 print $out;
267 print '<br>';
268
269 if (!$ckeditorenabledforticket) {
270 $msg = dol_string_nohtmltag($msg, 2);
271 }
272 $doleditor = new DolEditor('message_initial', $msg, '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser, $ckeditorenabledforticket, ROWS_9, '95%');
273 $doleditor->Create();
274 } else {
275 print '<div class="longmessagecut small">';
276 print dolPrintHTML($object->message);
277 print '</div>';
278 /*print '<div class="clear center">';
279 print $langs->trans("More").'...';
280 print '</div>';*/
281
282 //print '<div>' . $object->message . '</div>';
283 }
284 print '</td>';
285 print '</tr>';
286 print '</table>';
287 print '</div>';
288
289 if ($permissiontoadd && !in_array($object->status, $closeStatuses) && $action == 'edit_message_init') {
290 // MESSAGE
291 print '</form>';
292 }
293 }
294
303 public function viewTicketMessages($show_private, $show_author, $object)
304 {
305 global $langs, $user;
306
307 // Load logs in cache
308 $ret = $this->dao->loadCacheMsgsTicket();
309 if ($ret < 0) {
310 dol_print_error($this->dao->db);
311 }
312
313 $action = GETPOST('action', 'aZ09');
314
315 print '<div class="ticketpublicarea ticketlargemargin" style="padding-top: 0">';
316 $this->viewTicketOriginalMessage($user, $action, $object);
317 print '</div>';
318
319 if (is_array($this->dao->cache_msgs_ticket) && count($this->dao->cache_msgs_ticket) > 0) {
320 print '<div class="ticketpublicarea ticketlargemargin">';
321
322 print '<div class="div-table-responsive-no-min">';
323 print '<table class="border centpercent">';
324
325 print '<tr class="liste_titre">';
326
327 print '<td>';
328 print '<h4>';
329 print $langs->trans('TicketMessagesList');
330 print '</h4>';
331 print '</td>';
332
333 if ($show_author) {
334 print '<td>';
335 print '<h4>';
336 print $langs->trans('Author');
337 print '</h4>';
338 print '</td>';
339 }
340 print '</tr>';
341
342 $ticket_message_nr = 1;
343 foreach ($this->dao->cache_msgs_ticket as $id => $arraymsgs) {
344 if (!$arraymsgs['private']
345 || ($arraymsgs['private'] == "1" && $show_private)
346 ) {
347 //print '<tr>';
348 print '<tr id="ticket_message_header_'.$ticket_message_nr.'" class="oddeven nohover">';
349 print '<td><strong>';
350 print img_picto('', 'object_action', 'class="paddingright"').dol_print_date($arraymsgs['datep'], 'dayhour');
351 print '<strong></td>';
352 if ($show_author) {
353 print '<td>';
354 if ($arraymsgs['fk_user_author'] > 0) {
355 $userstat = new User($this->db);
356 $res = $userstat->fetch($arraymsgs['fk_user_author']);
357 if ($res) {
358 print img_picto('', 'user', 'class="pictofixedwidth"');
359 print $userstat->getNomUrl(0);
360 }
361 } elseif (isset($arraymsgs['fk_contact_author'])) {
362 $contactstat = new Contact($this->db);
363 $res = $contactstat->fetch(0, null, '', $arraymsgs['fk_contact_author']);
364 if ($res == 2) {
365 print img_picto('', 'email', 'class="pictofixedwidth"');
366 print $arraymsgs['fk_contact_author'];
367 } elseif ($res) {
368 print img_picto('', 'contact', 'class="pictofixedwidth"');
369 print $contactstat->getNomUrl(0, 'nolink');
370 } else {
371 print $arraymsgs['fk_contact_author'];
372 }
373 } else {
374 print '<span class="opacitymedium">'.$langs->trans('Unknown').'</span>';
375 }
376 print '</td>';
377 }
378 print '</tr>';
379
380 print '<tr id="ticket_message_body_'.$ticket_message_nr.'" class="oddeven nohover">';
381 print '<td'.($show_author ? ' colspan="2"' : '').'>';
382 print $arraymsgs['message'];
383
384 //attachment
385
386 $documents = array();
387
388 $sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.agenda_id';
389 $sql .= ', ecm.filepath, ecm.filename, ecm.share';
390 $sql .= ' FROM '.MAIN_DB_PREFIX.'ecm_files ecm';
391 $sql .= " WHERE ecm.filepath = 'agenda/".(int) $arraymsgs['id']."'";
392 $sql .= " OR (ecm.agenda_id = ".(int) $arraymsgs['id']." AND ecm.src_object_type = 'ticket' AND ecm.src_object_id = ".(int) $this->dao->id.")";
393 $sql .= ' ORDER BY ecm.position ASC';
394
395 $resql = $this->db->query($sql);
396 if ($resql) {
397 if ($this->db->num_rows($resql)) {
398 while ($obj = $this->db->fetch_object($resql)) {
399 $documents[$obj->id] = $obj;
400 }
401 }
402 }
403 if (!empty($documents)) {
404 $isshared = 0;
405 $footer = '<div class="timeline-documents-container">';
406 foreach ($documents as $doc) {
407 if (!empty($doc->share) || ($doc->src_object_type == 'ticket')) {
408 $isshared = 1;
409 $footer .= '<span id="document_'.$doc->id.'" class="timeline-documents" ';
410 $footer .= ' data-id="'.$doc->id.'" ';
411 $footer .= ' data-path="'.$doc->filepath.'"';
412 $footer .= ' data-filename="'.dol_escape_htmltag($doc->filename).'" ';
413 $footer .= '>';
414
415 if (empty($doc->agenda_id)) {
416 $dir_ref = $arraymsgs['id'];
417 $modulepart = 'actions';
418 } else {
419 $split_dir = explode('/', $doc->filepath);
420 $modulepart = array_shift($split_dir);
421 $dir_ref = implode('/', $split_dir);
422 }
423 $filePath = DOL_DATA_ROOT.'/'.$doc->filepath.'/'.$doc->filename;
424 $file_relative_path = $dir_ref.'/'.$doc->filename;
425 $mime = dol_mimetype($filePath);
426 $doclink = '';
427 if (!empty($doc->share)) {
428 $doclink = DOL_URL_ROOT.'/document.php?hashp='.urlencode($doc->share);
429 } elseif ($doc->src_object_type == 'ticket') {
430 $downloadwrapper = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') ? getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') . '/document.php' : dol_buildpath('/public/ticket/document.php', 2);
431
432 global $dolibarr_main_instance_unique_id;
433 $securekey = dol_hash('dolibarr-'.$file_relative_path.'-'.$dolibarr_main_instance_unique_id, 'sha256');
434 $doclink = $downloadwrapper.'?modulepart='.$modulepart.'&attachment=0&entity='.getEntity('ticket', 0).'&securekey='.urlencode($securekey).'&file='.urlencode($file_relative_path);
435 }
436
437 $mimeAttr = ' mime="'.$mime.'" ';
438 $class = '';
439 if (in_array($mime, array('image/png', 'image/jpeg', 'application/pdf'))) {
440 $class .= ' documentpreview';
441 }
442
443 $footer .= '<a href="'.$doclink.'" class="btn-link '.$class.'" target="_blank" '.$mimeAttr.' >';
444 $footer .= img_mime($filePath).' '.$doc->filename;
445 $footer .= '</a>';
446
447 $footer .= '</span>';
448 }
449 }
450 $footer .= '</div>';
451 if ($isshared == 1) {
452 print '<br>';
453 print '<br>';
454 print $footer;
455 }
456 }
457 print '</td>';
458 print '</tr>';
459 }
460 $ticket_message_nr++;
461 }
462
463 print '</table>';
464 print '</div>';
465 print '</div>';
466 } else {
467 print '<div class="ticketpublicarea ticketlargemargin">';
468 print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
469 print '</div>';
470 }
471 }
472
481 public function viewTicketTimelineMessages($show_private, $show_author, Ticket $object)
482 {
483 global $langs;
484
485 // Load logs in cache
486 $object->loadCacheMsgsTicket();
487
488 if (is_array($object->cache_msgs_ticket) && count($object->cache_msgs_ticket) > 0) {
489 print '<section id="cd-timeline">';
490
491 foreach ($object->cache_msgs_ticket as $id => $arraymsgs) {
492 if (!$arraymsgs['private']
493 || ($arraymsgs['private'] == "1" && $show_private)
494 ) {
495 print '<div class="cd-timeline-block">';
496 print '<div class="cd-timeline-img">';
497 print '<img src="img/messages.png" alt="">';
498 print '</div> <!-- cd-timeline-img -->';
499
500 print '<div class="cd-timeline-content">';
501 print $arraymsgs['message'];
502
503 print '<span class="cd-date">';
504 print dol_print_date($arraymsgs['datec'], 'dayhour');
505
506 if ($show_author) {
507 if ($arraymsgs['fk_user_action'] > 0) {
508 $userstat = new User($this->db);
509 $res = $userstat->fetch($arraymsgs['fk_user_action']);
510 if ($res) {
511 print '<br>';
512 print $userstat->getNomUrl(1);
513 }
514 } else {
515 print '<br>';
516 print $langs->trans('Customer');
517 }
518 }
519 print '</span>';
520 print '</div> <!-- cd-timeline-content -->';
521 print '</div> <!-- cd-timeline-block -->';
522 }
523 }
524 print '</section>';
525 } else {
526 print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
527 }
528 }
529
537 {
538 global $langs;
539
540 print '<div class="div-table-responsive-no-min margintoponly navBarForStatus">';
541 print '<div class="centpercent right">';
542 // Exclude status which requires specific method
543 $exclude_status = array(Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED);
544 // Exclude actual status
545 $exclude_status = array_merge($exclude_status, array((int) $object->status));
546 // Exclude also the Waiting/Pending/Suspended status
547 if (!getDolGlobalString('TICKET_INCLUDE_SUSPENDED_STATUS')) {
548 $exclude_status[] = $object::STATUS_WAITING;
549 }
550
551 // Sort results to be similar to status object list
552 //sort($exclude_status);
553
554 foreach ($object->labelStatusShort as $status => $status_label) {
555 if (!in_array($status, $exclude_status)) {
556 print '<div class="inline-block center margintoponly marginbottomonly">';
557
558 if ($status == 1) {
559 $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=set_read&token='.newToken(); // To set as read, we use a dedicated action
560 } else {
561 $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=confirm_set_status&token='.newToken().'&new_status='.((int) $status);
562 }
563
564 print '<a class="butAction butStatus marginbottomonly" href="'.$urlforbutton.'">';
565 print $object->LibStatut($status, 3, 1).' ';
566 //print img_picto($langs->trans($object->labelStatusShort[$status]), 'statut'.$status.'.png@ticket', '', 0, 0, 0, '', 'valignmiddle').' ';
567 print $langs->trans($object->labelStatusShort[$status]);
568 print '</a>';
569 print '</div>';
570 }
571 }
572 print '</div>';
573 print '</div>';
574 print '<br>';
575 }
576}
$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 generate HTML forms for single email Usage: $formai = new FormAI($db) $formai->proprietes=1 ...
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
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.