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