dolibarr 23.0.3
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 global $langs;
204
205 print '<!-- initial message of ticket -->'."\n";
206 if ($user->hasRight('ticket', 'manage') && $action == 'edit_message_init') {
207 // MESSAGE
208 print '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
209 print '<input type="hidden" name="token" value="'.newToken().'">';
210 print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
211 print '<input type="hidden" name="action" value="set_message">';
212 }
213
214 // Initial message
215 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
216 print '<table class="border tableforfield centpercent margintable">';
217 print '<tr class="liste_titre trforfield"><td class="nowrap titlefield">';
218 print $langs->trans("InitialMessage");
219 print '</td><td>';
220 if ($user->hasRight("ticket", "manage")) {
221 if ($action != 'edit_message_init') {
222 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>';
223 } else {
224 print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';
225 print ' <input type="submit" class="button button-cancel smallpaddingimp" name="cancel" value="'.$langs->trans("Cancel").'">';
226 }
227 }
228 print '</td></tr>';
229
230 print '<tr>';
231 print '<td colspan="2">';
232 if ($user->hasRight('ticket', 'manage') && $action == 'edit_message_init') {
233 // Message
234 $msg = GETPOSTISSET('message_initial') ? GETPOST('message_initial', 'restricthtml') : $object->message;
235 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
236 $uselocalbrowser = true;
237 $ckeditorenabledforticket = getDolGlobalString('FCKEDITOR_ENABLE_TICKET');
238 if (!$ckeditorenabledforticket) {
239 $msg = dol_string_nohtmltag($msg, 2);
240 }
241 $doleditor = new DolEditor('message_initial', $msg, '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser, $ckeditorenabledforticket, ROWS_9, '95%');
242 $doleditor->Create();
243 } else {
244 print '<div class="longmessagecut small">';
245 print dolPrintHTML($object->message);
246 print '</div>';
247 /*print '<div class="clear center">';
248 print $langs->trans("More").'...';
249 print '</div>';*/
250
251 //print '<div>' . $object->message . '</div>';
252 }
253 print '</td>';
254 print '</tr>';
255 print '</table>';
256 print '</div>';
257
258 if ($user->hasRight('ticket', 'manage') && $action == 'edit_message_init') {
259 // MESSAGE
260 print '</form>';
261 }
262 }
263
272 public function viewTicketMessages($show_private, $show_user, $object)
273 {
274 global $langs, $user;
275
276 // Load logs in cache
277 $ret = $this->dao->loadCacheMsgsTicket();
278 if ($ret < 0) {
279 dol_print_error($this->dao->db);
280 }
281
282 $action = GETPOST('action', 'aZ09');
283
284 print '<div class="ticketpublicarea ticketlargemargin" style="padding-top: 0">';
285 $this->viewTicketOriginalMessage($user, $action, $object);
286 print '</div>';
287
288 if (is_array($this->dao->cache_msgs_ticket) && count($this->dao->cache_msgs_ticket) > 0) {
289 print '<div class="ticketpublicarea ticketlargemargin">';
290
291 print '<div class="div-table-responsive-no-min">';
292 print '<table class="border centpercent">';
293
294 print '<tr class="liste_titre">';
295
296 print '<td>';
297 print $langs->trans('TicketMessagesList');
298 print '</td>';
299
300 if ($show_user) {
301 print '<td>';
302 print $langs->trans('User');
303 print '</td>';
304 }
305 print '</tr>';
306
307 foreach ($this->dao->cache_msgs_ticket as $id => $arraymsgs) {
308 if (!$arraymsgs['private']
309 || ($arraymsgs['private'] == "1" && $show_private)
310 ) {
311 //print '<tr>';
312 print '<tr class="oddeven nohover">';
313 print '<td><strong>';
314 print img_picto('', 'object_action', 'class="paddingright"').dol_print_date($arraymsgs['datep'], 'dayhour');
315 print '<strong></td>';
316 if ($show_user) {
317 print '<td>';
318 if ($arraymsgs['fk_user_author'] > 0) {
319 $userstat = new User($this->db);
320 $res = $userstat->fetch($arraymsgs['fk_user_author']);
321 if ($res) {
322 print img_picto('', 'user', 'class="pictofixedwidth"');
323 print $userstat->getNomUrl(0);
324 }
325 } elseif (isset($arraymsgs['fk_contact_author'])) {
326 $contactstat = new Contact($this->db);
327 $res = $contactstat->fetch(0, null, '', $arraymsgs['fk_contact_author']);
328 if ($res) {
329 print img_picto('', 'contact', 'class="pictofixedwidth"');
330 print $contactstat->getNomUrl(0, 'nolink');
331 } else {
332 print $arraymsgs['fk_contact_author'];
333 }
334 } else {
335 print '<span class="opacitymedium">'.$langs->trans('Unknown').'</span>';
336 }
337 print '</td>';
338 }
339 print '</tr>';
340
341 print '<tr class="oddeven nohover borderbottom">';
342 print '<td'.($show_user ? ' colspan="2"' : '').'>';
343 print $arraymsgs['message'];
344
345 //attachment
346
347 $documents = array();
348
349 $sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.agenda_id';
350 $sql .= ', ecm.filepath, ecm.filename, ecm.share';
351 $sql .= ' FROM '.MAIN_DB_PREFIX.'ecm_files ecm';
352 $sql .= " WHERE ecm.filepath = 'agenda/".(int) $arraymsgs['id']."'";
353 $sql .= " OR (ecm.agenda_id = ".(int) $arraymsgs['id']." AND ecm.src_object_type = 'ticket' AND ecm.src_object_id = ".(int) $this->dao->id.")";
354 $sql .= ' ORDER BY ecm.position ASC';
355
356 $resql = $this->db->query($sql);
357 if ($resql) {
358 if ($this->db->num_rows($resql)) {
359 while ($obj = $this->db->fetch_object($resql)) {
360 $documents[$obj->id] = $obj;
361 }
362 }
363 }
364 if (!empty($documents)) {
365 $isshared = 0;
366 $footer = '<div class="timeline-documents-container">';
367 foreach ($documents as $doc) {
368 if (!empty($doc->share) || ($doc->src_object_type == 'ticket')) {
369 $isshared = 1;
370 $footer .= '<span id="document_'.$doc->id.'" class="timeline-documents" ';
371 $footer .= ' data-id="'.$doc->id.'" ';
372 $footer .= ' data-path="'.$doc->filepath.'"';
373 $footer .= ' data-filename="'.dol_escape_htmltag($doc->filename).'" ';
374 $footer .= '>';
375
376 if (empty($doc->agenda_id)) {
377 $dir_ref = $arraymsgs['id'];
378 $modulepart = 'actions';
379 } else {
380 $split_dir = explode('/', $doc->filepath);
381 $modulepart = array_shift($split_dir);
382 $dir_ref = implode('/', $split_dir);
383 }
384 $filePath = DOL_DATA_ROOT.'/'.$doc->filepath.'/'.$doc->filename;
385 $file_relative_path = $dir_ref.'/'.$doc->filename;
386 $mime = dol_mimetype($filePath);
387 $doclink = '';
388 if (!empty($doc->share)) {
389 $doclink = DOL_URL_ROOT.'/document.php?hashp='.urlencode($doc->share);
390 } elseif ($doc->src_object_type == 'ticket') {
391 $doclink = dol_buildpath('document.php', 1).'?modulepart='.$modulepart.'&attachment=0&file='.urlencode($file_relative_path).'&entity='.getEntity('ticket', 0);
392 }
393
394 $mimeAttr = ' mime="'.$mime.'" ';
395 $class = '';
396 if (in_array($mime, array('image/png', 'image/jpeg', 'application/pdf'))) {
397 $class .= ' documentpreview';
398 }
399
400 $footer .= '<a href="'.$doclink.'" class="btn-link '.$class.'" target="_blank" '.$mimeAttr.' >';
401 $footer .= img_mime($filePath).' '.$doc->filename;
402 $footer .= '</a>';
403
404 $footer .= '</span>';
405 }
406 }
407 $footer .= '</div>';
408 if ($isshared == 1) {
409 print '<br>';
410 print '<br>';
411 print $footer;
412 }
413 }
414 print '</td>';
415 print '</tr>';
416 }
417 }
418
419 print '</table>';
420 print '</div>';
421 print '</div>';
422 } else {
423 print '<div class="ticketpublicarea ticketlargemargin">';
424 print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
425 print '</div>';
426 }
427 }
428
437 public function viewTicketTimelineMessages($show_private, $show_user, Ticket $object)
438 {
439 global $conf, $langs, $user;
440
441 // Load logs in cache
442 $ret = $object->loadCacheMsgsTicket();
443 $action = GETPOST('action');
444
445 if (is_array($object->cache_msgs_ticket) && count($object->cache_msgs_ticket) > 0) {
446 print '<section id="cd-timeline">';
447
448 foreach ($object->cache_msgs_ticket as $id => $arraymsgs) {
449 if (!$arraymsgs['private']
450 || ($arraymsgs['private'] == "1" && $show_private)
451 ) {
452 print '<div class="cd-timeline-block">';
453 print '<div class="cd-timeline-img">';
454 print '<img src="img/messages.png" alt="">';
455 print '</div> <!-- cd-timeline-img -->';
456
457 print '<div class="cd-timeline-content">';
458 print $arraymsgs['message'];
459
460 print '<span class="cd-date">';
461 print dol_print_date($arraymsgs['datec'], 'dayhour');
462
463 if ($show_user) {
464 if ($arraymsgs['fk_user_action'] > 0) {
465 $userstat = new User($this->db);
466 $res = $userstat->fetch($arraymsgs['fk_user_action']);
467 if ($res) {
468 print '<br>';
469 print $userstat->getNomUrl(1);
470 }
471 } else {
472 print '<br>';
473 print $langs->trans('Customer');
474 }
475 }
476 print '</span>';
477 print '</div> <!-- cd-timeline-content -->';
478 print '</div> <!-- cd-timeline-block -->';
479 }
480 }
481 print '</section>';
482 } else {
483 print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
484 }
485 }
486
494 {
495 global $langs;
496
497 print '<div class="div-table-responsive-no-min margintoponly navBarForStatus">';
498 print '<div class="centpercent right">';
499 // Exclude status which requires specific method
500 $exclude_status = array(Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED);
501 // Exclude actual status
502 $exclude_status = array_merge($exclude_status, array((int) $object->status));
503 // Exclude also the Waiting/Pending/Suspended status
504 if (!getDolGlobalString('TICKET_INCLUDE_SUSPENDED_STATUS')) {
505 $exclude_status[] = $object::STATUS_WAITING;
506 }
507
508 // Sort results to be similar to status object list
509 //sort($exclude_status);
510
511 foreach ($object->labelStatusShort as $status => $status_label) {
512 if (!in_array($status, $exclude_status)) {
513 print '<div class="inline-block center margintoponly marginbottomonly">';
514
515 if ($status == 1) {
516 $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=set_read&token='.newToken(); // To set as read, we use a dedicated action
517 } else {
518 $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=confirm_set_status&token='.newToken().'&new_status='.((int) $status);
519 }
520
521 print '<a class="butAction butStatus marginbottomonly" href="'.$urlforbutton.'">';
522 print $object->LibStatut($status, 3, 1).' ';
523 //print img_picto($langs->trans($object->labelStatusShort[$status]), 'statut'.$status.'.png@ticket', '', 0, 0, 0, '', 'valignmiddle').' ';
524 print $langs->trans($object->labelStatusShort[$status]);
525 print '</a>';
526 print '</div>';
527 }
528 }
529 print '</div>';
530 print '</div>';
531 print '<br>';
532 }
533}
$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.
viewTicketMessages($show_private, $show_user, $object)
View html list of message for ticket.
__construct($db)
Constructor.
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.
getTitle($action='', $object=null)
Get action title.
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)
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dolPrintHTML($s, $allowiframe=0)
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.
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)
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Class to generate the form for creating a new ticket.