dolibarr 20.0.0
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
27require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
30require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
32require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php';
34
35// TODO Only the last method emailElementlist is a hook method. Other must be moved into standard ticket.class.php
36
37
42{
46 public $db;
47
51 public $dao;
52
53 public $mesg;
54
58 public $error;
59
63 public $errors = array();
64
66 public $errno = 0;
67
68 public $template_dir;
69 public $template;
70
74 public $label;
75
79 public $description;
80
84 public $fk_statut;
85
89 public $fk_soc;
90
91
97 public function __construct($db)
98 {
99 $this->db = $db;
100 }
101
107 public function getInstanceDao()
108 {
109 if (!is_object($this->dao)) {
110 $this->dao = new Ticket($this->db);
111 }
112 }
113
122 public function fetch($id = 0, $ref = '', $track_id = '')
123 {
124 $this->getInstanceDao();
125 return $this->dao->fetch($id, $ref, $track_id);
126 }
127
134 public function getLibStatut($mode = 0)
135 {
136 $this->getInstanceDao();
137 $this->dao->fk_statut = $this->fk_statut;
138 return $this->dao->getLibStatut($mode);
139 }
140
147 public function getInfo($id)
148 {
149 $this->getInstanceDao();
150 $this->dao->fetch($id);
151
152 $this->label = $this->dao->label;
153 $this->description = $this->dao->description;
154 }
155
162 public function getTitle($action = '')
163 {
164 global $langs;
165
166 if ($action == 'create') {
167 return $langs->trans("CreateTicket");
168 } elseif ($action == 'edit') {
169 return $langs->trans("EditTicket");
170 } elseif ($action == 'view') {
171 return $langs->trans("TicketCard");
172 } elseif ($action == 'add_message') {
173 return $langs->trans("TicketAddMessage");
174 } else {
175 return $langs->trans("TicketsManagement");
176 }
177 }
178
187 public function viewTicketOriginalMessage($user, $action, $object)
188 {
189 global $langs;
190
191 print '<!-- initial message of ticket -->'."\n";
192 if ($user->hasRight('ticket', 'manage') && $action == 'edit_message_init') {
193 // MESSAGE
194 print '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
195 print '<input type="hidden" name="token" value="'.newToken().'">';
196 print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
197 print '<input type="hidden" name="action" value="set_message">';
198 }
199
200 // Initial message
201 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
202 print '<table class="border centpercent margintable">';
203 print '<tr class="liste_titre trforfield"><td class="nowrap titlefield">';
204 print $langs->trans("InitialMessage");
205 print '</td><td>';
206 if ($user->hasRight("ticket", "manage")) {
207 if ($action != 'edit_message_init') {
208 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>';
209 } else {
210 print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';
211 print ' <input type="submit" class="button button-cancel smallpaddingimp" name="cancel" value="'.$langs->trans("Cancel").'">';
212 }
213 }
214 print '</td></tr>';
215
216 print '<tr>';
217 print '<td colspan="2">';
218 if ($user->hasRight('ticket', 'manage') && $action == 'edit_message_init') {
219 // Message
220 $msg = GETPOSTISSET('message_initial') ? GETPOST('message_initial', 'restricthtml') : $object->message;
221 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
222 $uselocalbrowser = true;
223 $ckeditorenabledforticket = getDolGlobalString('FCKEDITOR_ENABLE_TICKET');
224 if (!$ckeditorenabledforticket) {
225 $msg = dol_string_nohtmltag($msg, 2);
226 }
227 $doleditor = new DolEditor('message_initial', $msg, '100%', 250, 'dolibarr_details', 'In', true, $uselocalbrowser, $ckeditorenabledforticket, ROWS_9, '95%');
228 $doleditor->Create();
229 } else {
230 print '<div class="longmessagecut small">';
231 print dolPrintHTML($object->message);
232 print '</div>';
233 /*print '<div class="clear center">';
234 print $langs->trans("More").'...';
235 print '</div>';*/
236
237 //print '<div>' . $object->message . '</div>';
238 }
239 print '</td>';
240 print '</tr>';
241 print '</table>';
242 print '</div>';
243
244 if ($user->hasRight('ticket', 'manage') && $action == 'edit_message_init') {
245 // MESSAGE
246 print '</form>';
247 }
248 }
249
258 public function viewTicketMessages($show_private, $show_user, $object)
259 {
260 global $langs, $user;
261
262 // Load logs in cache
263 $ret = $this->dao->loadCacheMsgsTicket();
264 if ($ret < 0) {
265 dol_print_error($this->dao->db);
266 }
267
268 $action = GETPOST('action', 'aZ09');
269
270 print '<div class="ticketpublicarea ticketlargemargin centpercent" style="padding-top: 0">';
271 $this->viewTicketOriginalMessage($user, $action, $object);
272 print '</div>';
273
274 if (is_array($this->dao->cache_msgs_ticket) && count($this->dao->cache_msgs_ticket) > 0) {
275 print '<div class="ticketpublicarea ticketlargemargin centpercent">';
276
277 print '<div class="div-table-responsive-no-min">';
278 print '<table class="border centpercent">';
279
280 print '<tr class="liste_titre">';
281
282 print '<td>';
283 print $langs->trans('TicketMessagesList');
284 print '</td>';
285
286 if ($show_user) {
287 print '<td>';
288 print $langs->trans('User');
289 print '</td>';
290 }
291 print '</tr>';
292
293 foreach ($this->dao->cache_msgs_ticket as $id => $arraymsgs) {
294 if (!$arraymsgs['private']
295 || ($arraymsgs['private'] == "1" && $show_private)
296 ) {
297 //print '<tr>';
298 print '<tr class="oddeven nohover">';
299 print '<td><strong>';
300 print img_picto('', 'object_action', 'class="paddingright"').dol_print_date($arraymsgs['datep'], 'dayhour');
301 print '<strong></td>';
302 if ($show_user) {
303 print '<td>';
304 if ($arraymsgs['fk_user_author'] > 0) {
305 $userstat = new User($this->db);
306 $res = $userstat->fetch($arraymsgs['fk_user_author']);
307 if ($res) {
308 print $userstat->getNomUrl(0);
309 }
310 } elseif (isset($arraymsgs['fk_contact_author'])) {
311 $contactstat = new Contact($this->db);
312 $res = $contactstat->fetch(0, null, '', $arraymsgs['fk_contact_author']);
313 if ($res) {
314 print $contactstat->getNomUrl(0, 'nolink');
315 } else {
316 print $arraymsgs['fk_contact_author'];
317 }
318 } else {
319 print '<span class="opacitymedium">'.$langs->trans('Unknown').'</span>';
320 }
321 print '</td>';
322 }
323 print '</tr>';
324
325 print '<tr class="oddeven nohover">';
326 print '<td'.($show_user ? ' colspan="2"' : '').'>';
327 print $arraymsgs['message'];
328
329 //attachment
330
331 $documents = array();
332
333 $sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id';
334 $sql .= ', ecm.filepath, ecm.filename, ecm.share';
335 $sql .= ' FROM '.MAIN_DB_PREFIX.'ecm_files ecm';
336 $sql .= " WHERE ecm.filepath = 'agenda/".$arraymsgs['id']."'";
337 $sql .= ' ORDER BY ecm.position ASC';
338
339 $resql = $this->db->query($sql);
340 if ($resql) {
341 if ($this->db->num_rows($resql)) {
342 while ($obj = $this->db->fetch_object($resql)) {
343 $documents[$obj->id] = $obj;
344 }
345 }
346 }
347 if (!empty($documents)) {
348 $isshared = 0;
349 $footer = '<div class="timeline-documents-container">';
350 foreach ($documents as $doc) {
351 if (!empty($doc->share)) {
352 $isshared = 1;
353 $footer .= '<span id="document_'.$doc->id.'" class="timeline-documents" ';
354 $footer .= ' data-id="'.$doc->id.'" ';
355 $footer .= ' data-path="'.$doc->filepath.'"';
356 $footer .= ' data-filename="'.dol_escape_htmltag($doc->filename).'" ';
357 $footer .= '>';
358
359 $filePath = DOL_DATA_ROOT.'/'.$doc->filepath.'/'.$doc->filename;
360 $mime = dol_mimetype($filePath);
361 $thumb = $arraymsgs['id'].'/thumbs/'.substr($doc->filename, 0, strrpos($doc->filename, '.')).'_mini'.substr($doc->filename, strrpos($doc->filename, '.'));
362 $doclink = DOL_URL_ROOT.'/document.php?hashp='.urlencode($doc->share);
363
364 $mimeAttr = ' mime="'.$mime.'" ';
365 $class = '';
366 if (in_array($mime, array('image/png', 'image/jpeg', 'application/pdf'))) {
367 $class .= ' documentpreview';
368 }
369
370 $footer .= '<a href="'.$doclink.'" class="btn-link '.$class.'" target="_blank" '.$mimeAttr.' >';
371 $footer .= img_mime($filePath).' '.$doc->filename;
372 $footer .= '</a>';
373
374 $footer .= '</span>';
375 }
376 }
377 $footer .= '</div>';
378 if ($isshared == 1) {
379 print '<br>';
380 print '<br>';
381 print $footer;
382 }
383 }
384 print '</td>';
385 print '</tr>';
386 }
387 }
388
389 print '</table>';
390 print '</div>';
391 print '</div>';
392 } else {
393 print '<div class="ticketpublicarea ticketlargemargin centpercent">';
394 print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
395 print '</div>';
396 }
397 }
398
407 public function viewTicketTimelineMessages($show_private, $show_user, Ticket $object)
408 {
409 global $conf, $langs, $user;
410
411 // Load logs in cache
412 $ret = $object->loadCacheMsgsTicket();
413 $action = GETPOST('action');
414
415 if (is_array($object->cache_msgs_ticket) && count($object->cache_msgs_ticket) > 0) {
416 print '<section id="cd-timeline">';
417
418 foreach ($object->cache_msgs_ticket as $id => $arraymsgs) {
419 if (!$arraymsgs['private']
420 || ($arraymsgs['private'] == "1" && $show_private)
421 ) {
422 print '<div class="cd-timeline-block">';
423 print '<div class="cd-timeline-img">';
424 print '<img src="img/messages.png" alt="">';
425 print '</div> <!-- cd-timeline-img -->';
426
427 print '<div class="cd-timeline-content">';
428 print $arraymsgs['message'];
429
430 print '<span class="cd-date">';
431 print dol_print_date($arraymsgs['datec'], 'dayhour');
432
433 if ($show_user) {
434 if ($arraymsgs['fk_user_action'] > 0) {
435 $userstat = new User($this->db);
436 $res = $userstat->fetch($arraymsgs['fk_user_action']);
437 if ($res) {
438 print '<br>';
439 print $userstat->getNomUrl(1);
440 }
441 } else {
442 print '<br>';
443 print $langs->trans('Customer');
444 }
445 }
446 print '</span>';
447 print '</div> <!-- cd-timeline-content -->';
448 print '</div> <!-- cd-timeline-block -->';
449 }
450 }
451 print '</section>';
452 } else {
453 print '<div class="info">'.$langs->trans('NoMsgForThisTicket').'</div>';
454 }
455 }
456
464 {
465 global $langs;
466
467 print '<div class="div-table-responsive-no-min margintoponly navBarForStatus">';
468 print '<div class="centpercent right">';
469 // Exclude status which requires specific method
470 $exclude_status = array(Ticket::STATUS_CLOSED, Ticket::STATUS_CANCELED);
471 // Exclude actual status
472 $exclude_status = array_merge($exclude_status, array((int) $object->status));
473 // Exclude also the Waiting/Pending/Suspended status
474 if (!getDolGlobalString('TICKET_INCLUDE_SUSPENDED_STATUS')) {
475 $exclude_status[] = $object::STATUS_WAITING;
476 }
477
478 // Sort results to be similar to status object list
479 //sort($exclude_status);
480
481 foreach ($object->labelStatusShort as $status => $status_label) {
482 if (!in_array($status, $exclude_status)) {
483 print '<div class="inline-block center margintoponly marginbottomonly">';
484
485 if ($status == 1) {
486 $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=set_read&token='.newToken(); // To set as read, we use a dedicated action
487 } else {
488 $urlforbutton = $_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'&action=confirm_set_status&token='.newToken().'&new_status='.((int) $status);
489 }
490
491 print '<a class="butAction butStatus marginbottomonly" href="'.$urlforbutton.'">';
492 print $object->LibStatut($status, 3, 1).' ';
493 //print img_picto($langs->trans($object->labelStatusShort[$status]), 'statut'.$status.'.png@ticket', '', false, 0, 0, '', 'valignmiddle').' ';
494 print $langs->trans($object->labelStatusShort[$status]);
495 print '</a>';
496 print '</div>';
497 }
498 }
499 print '</div>';
500 print '</div>';
501 print '<br>';
502 }
503
513 public function emailElementlist($parameters, &$object, &$action, $hookmanager)
514 {
515 global $langs;
516
517 $error = 0;
518
519 if (in_array('admin', explode(':', $parameters['context']))) {
520 $this->results = array('ticket_send' => $langs->trans('MailToSendTicketMessage'));
521 }
522
523 if (!$error) {
524 return 0; // or return 1 to replace standard code
525 } else {
526 $this->errors[] = 'Error message';
527 return -1;
528 }
529 }
530}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class Actions of the module ticket.
viewTicketMessages($show_private, $show_user, $object)
View html list of message for ticket.
getTitle($action='')
Get action title.
__construct($db)
Constructor.
emailElementlist($parameters, &$object, &$action, $hookmanager)
Hook to add email element template.
$errno
Numero de l'erreur.
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.
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.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_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 dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
Class to generate the form for creating a new ticket.