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