dolibarr 22.0.5
view.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
3 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
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, see <https://www.gnu.org/licenses/>.
19 */
20
27if (!defined('NOREQUIREMENU')) {
28 define('NOREQUIREMENU', '1');
29}
30// If there is no need to load and show top and left menu
31if (!defined("NOLOGIN")) {
32 define("NOLOGIN", '1');
33}
34if (!defined('NOIPCHECK')) {
35 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
36}
37if (!defined('NOBROWSERNOTIF')) {
38 define('NOBROWSERNOTIF', '1');
39}
40// If this page is public (can be called outside logged session)
41
42// For MultiCompany module.
43// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
44// Because 2 entities can have the same ref.
45$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
46if (is_numeric($entity)) {
47 define("DOLENTITY", $entity);
48}
49
50// Load Dolibarr environment
51require '../../main.inc.php';
52require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
53require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
54require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
55require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
56require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
57require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
58require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
59
68// Load translation files required by the page
69$langs->loadLangs(array("companies", "other", "ticket"));
70
71// Get parameters
72$action = GETPOST('action', 'aZ09');
73$cancel = GETPOST('cancel');
74
75$track_id = GETPOST('track_id', 'alpha');
76$email = GETPOST('email', 'email');
77$suffix = "";
78
79if (GETPOST('btn_view_ticket')) {
80 unset($_SESSION['email_customer']);
81}
82if (isset($_SESSION['email_customer'])) {
83 $email = $_SESSION['email_customer'];
84}
85
86$object = new ActionsTicket($db);
87
88if (!isModEnabled('ticket')) {
89 httponly_accessforbidden('Module Ticket not enabled');
90}
91
92
93/*
94 * Actions
95 */
96
97if ($cancel) {
98 $backtopage = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.'/public/ticket/');
99
100 if (!empty($backtopage)) {
101 header("Location: ".$backtopage);
102 exit;
103 }
104 $action = 'view_ticket';
105}
106
107$display_ticket = false;
108if (in_array($action, array("view_ticket", "presend", "close", "confirm_public_close", "add_message", "add_contact"))) { // Test on permission not required here. Done later by using the $track_id + check email in session
109 $error = 0;
110 if (!strlen($track_id)) {
111 $error++;
112 array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketTrackId")));
113 $action = '';
114 }
115 if (!strlen($email)) {
116 $error++;
117 array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Email")));
118 $action = '';
119 } else {
120 if (!isValidEmail($email)) {
121 $error++;
122 array_push($object->errors, $langs->trans("ErrorEmailInvalid"));
123 $action = '';
124 }
125 }
126
127 if (!$error) {
128 $ret = $object->fetch(0, '', $track_id);
129 if ($ret && $object->dao->id > 0) {
130 // Check if emails provided is the one of author
131 $emailofticket = CMailFile::getValidAddress($object->dao->origin_email, 2);
132 if (strtolower($emailofticket) == strtolower($email)) {
133 $display_ticket = true;
134 $_SESSION['email_customer'] = $email;
135 } else {
136 // Check if emails provided is inside list of contacts
137 $contacts = $object->dao->liste_contact(-1, 'external');
138 foreach ($contacts as $contact) {
139 if (strtolower($contact['email']) == strtolower($email)) {
140 $display_ticket = true;
141 $_SESSION['email_customer'] = $email;
142 break;
143 } else {
144 $display_ticket = false;
145 }
146 }
147 }
148 // Check email of thirdparty of ticket
149 if ($object->dao->fk_soc > 0 || $object->dao->socid > 0) {
150 $object->dao->fetch_thirdparty();
151 if ($email == $object->dao->thirdparty->email) {
152 $display_ticket = true;
153 $_SESSION['email_customer'] = $email;
154 }
155 }
156 // Check if email is email of creator
157 if ($object->dao->fk_user_create > 0) {
158 $tmpuser = new User($db);
159 $tmpuser->fetch($object->dao->fk_user_create);
160 if (strtolower($email) == strtolower($tmpuser->email)) {
161 $display_ticket = true;
162 $_SESSION['email_customer'] = $email;
163 }
164 }
165 // Check if email is email of creator
166 if ($object->dao->fk_user_assign > 0 && $object->dao->fk_user_assign != $object->dao->fk_user_create) {
167 $tmpuser = new User($db);
168 $tmpuser->fetch($object->dao->fk_user_assign);
169 if (strtolower($email) == strtolower($tmpuser->email)) {
170 $display_ticket = true;
171 $_SESSION['email_customer'] = $email;
172 }
173 }
174 } else {
175 $error++;
176 array_push($object->errors, $langs->trans("ErrorTicketNotFound", $track_id));
177 $action = '';
178 }
179 }
180
181 if (!$error && $action == 'confirm_public_close' && $display_ticket) { // Test on permission already done
182 if ($object->dao->close($user)) {
183 setEventMessages($langs->trans('TicketMarkedAsClosed'), null, 'mesgs');
184
185 $url = 'view.php?action=view_ticket&track_id='.GETPOST('track_id', 'alpha').(!empty($entity) && isModEnabled('multicompany') ? '&entity='.$entity : '').'&token='.newToken();
186 header("Location: ".$url);
187 exit;
188 } else {
189 $action = '';
190 setEventMessages($object->error, $object->errors, 'errors');
191 }
192 }
193
194 if (!$error && $action == "add_message" && $display_ticket && GETPOSTISSET('btn_add_message')) { // Test on permission already done
195 $ret = $object->dao->newMessage($user, $action, 0, 1);
196
197 if (!$error) {
198 $action = 'view_ticket';
199 }
200 }
201
202 // Add a new external contributor to a ticket
203 if (!$error && $action == "add_contact" && $display_ticket && GETPOSTISSET('btn_add_contact')) { // Test on permission already done
204 $ret = $object->dao->add_contact(GETPOSTINT('contactid'), 'CONTRIBUTOR');
205
206 if (!$error) {
207 $action = 'view_ticket';
208 }
209 }
210
211 if ($error || !empty($object->errors)) {
212 setEventMessages($object->error, $object->errors, 'errors');
213 if ($action == "add_message") { // Test on permission not required here
214 $action = 'presend';
215 } else {
216 $action = '';
217 }
218 }
219}
220
221// Actions to send emails (for ticket, we need to manage the addfile and removefile only)
222$triggersendname = 'TICKET_SENTBYMAIL';
223$paramname = 'id';
224$autocopy = 'MAIN_MAIL_AUTOCOPY_TICKET_TO'; // used to know the automatic BCC to add
225if (!empty($object->dao->id)) {
226 $trackid = 'tic'.$object->dao->id;
227}
228include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
229
230
231
232/*
233 * View
234 */
235
236$form = new Form($db);
237$formticket = new FormTicket($db);
238
239// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
240$hookmanager->initHooks(array('ticketpublicview', 'globalcard'));
241
242if (!getDolGlobalString('TICKET_ENABLE_PUBLIC_INTERFACE')) {
243 print '<div class="error">'.$langs->trans('TicketPublicInterfaceForbidden').'</div>';
244 $db->close();
245 exit();
246}
247
248$arrayofjs = array();
249$arrayofcss = array(getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', '/public/ticket/').'css/styles.css.php');
250
251llxHeaderTicket($langs->trans("Tickets"), "", 0, 0, $arrayofjs, $arrayofcss);
252
253
254if ($action == "view_ticket" || $action == "presend" || $action == "close" || $action == "confirm_public_close") {
255 if ($display_ticket) {
256 print '<!-- public view ticket -->';
257 print '<div class="ticketpublicarea ticketlargemargin">';
258
259 // Confirmation close
260 if ($action == 'close') {
261 print $form->formconfirm($_SERVER["PHP_SELF"]."?track_id=".$track_id.(!empty($entity) && isModEnabled('multicompany') ? '&entity='.$entity : ''), $langs->trans("CloseATicket"), $langs->trans("ConfirmCloseAticket"), "confirm_public_close", '', '', 1);
262 }
263
264 print '<div id="form_view_ticket" class="margintoponly">';
265
266 print '<table class="ticketpublictable centpercent tableforfield">';
267
268 // Ref
269 print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
270 print img_picto('', 'ticket', 'class="pictofixedwidth"');
271 print dol_escape_htmltag($object->dao->ref);
272 print '</td></tr>';
273
274 // Tracking ID
275 print '<tr><td>'.$langs->trans("TicketTrackId").'</td><td>';
276 print dol_escape_htmltag($object->dao->track_id);
277 print '</td></tr>';
278
279 // Subject
280 print '<tr><td>'.$langs->trans("Subject").'</td><td>';
281 print '<span class="bold">';
282 print dol_escape_htmltag($object->dao->subject);
283 print '</span>';
284 print '</td></tr>';
285
286 // Statut
287 print '<tr><td>'.$langs->trans("Status").'</td><td>';
288 print $object->dao->getLibStatut(2);
289 print '</td></tr>';
290
291 // Type
292 print '<tr><td>'.$langs->trans("Type").'</td><td>';
293 print dol_escape_htmltag($object->dao->type_label);
294 print '</td></tr>';
295
296 // Category
297 print '<tr><td>'.$langs->trans("Category").'</td><td>';
298 if ($object->dao->category_label) {
299 print img_picto('', 'category', 'class="pictofixedwidth"');
300 print dol_escape_htmltag($object->dao->category_label);
301 }
302 print '</td></tr>';
303
304 // Severity
305 print '<tr><td>'.$langs->trans("Severity").'</td><td>';
306 print dol_escape_htmltag($object->dao->severity_label);
307 print '</td></tr>';
308
309 // Creation date
310 print '<tr><td>'.$langs->trans("DateCreation").'</td><td>';
311 print dol_print_date($object->dao->datec, 'dayhour');
312 print '</td></tr>';
313
314 // Author
315 print '<tr><td>'.$langs->trans("Author").'</td><td>';
316 if ($object->dao->fk_user_create > 0) {
317 $langs->load("users");
318 $fuser = new User($db);
319 $fuser->fetch($object->dao->fk_user_create);
320 print img_picto('', 'user', 'class="pictofixedwidth"');
321 print $fuser->getFullName($langs);
322 } else {
323 print img_picto('', 'email', 'class="pictofixedwidth"');
324 print dol_escape_htmltag($object->dao->origin_email);
325 }
326
327 print '</td></tr>';
328
329 // Read date
330 if (!empty($object->dao->date_read)) {
331 print '<tr><td>'.$langs->trans("TicketReadOn").'</td><td>';
332 print dol_print_date($object->dao->date_read, 'dayhour');
333 print '</td></tr>';
334 }
335
336 // Close date
337 if (!empty($object->dao->date_close)) {
338 print '<tr><td>'.$langs->trans("TicketCloseOn").'</td><td>';
339 print dol_print_date($object->dao->date_close, 'dayhour');
340 print '</td></tr>';
341 }
342
343 // User assigned
344 print '<tr><td>'.$langs->trans("AssignedTo").'</td><td>';
345 if ($object->dao->fk_user_assign > 0) {
346 $fuser = new User($db);
347 $fuser->fetch($object->dao->fk_user_assign);
348 print img_picto('', 'user', 'class="pictofixedwidth"');
349 print $fuser->getFullName($langs, 0);
350 }
351 print '</td></tr>';
352
353 // External contributors
354 if (getDolGlobalInt('TICKET_PUBLIC_DISPLAY_EXTERNAL_CONTRIBUTORS')) {
355 print '<tr><td>'.$langs->trans("ExternalContributors").'</td><td>';
356 if ($object->dao->id > 0) {
357 $contactlist = $object->dao->liste_contact(-1, 'external');
358 foreach ($contactlist as $externalContributor) {
359 print img_picto('', 'contact', 'class="pictofixedwidth"');
360 print $externalContributor["lastname"]." ".$externalContributor["firstname"]."<br>";
361 }
362 }
363 print '</td></tr>';
364 }
365
366 // Add new external contributor
367 if (getDolGlobalInt('TICKET_PUBLIC_SELECT_EXTERNAL_CONTRIBUTORS') && !empty($object->dao->fk_soc)) {
368 print '<form method="post" id="form_view_add_contact" name="form_view_add_contact" action="'.$_SERVER['PHP_SELF'].'?track_id='.$object->dao->track_id.'">';
369 print '<input type="hidden" name="token" value="'.newToken().'">';
370 print '<input type="hidden" name="action" value="add_contact">';
371 print '<input type="hidden" name="email" value="'.$_SESSION['email_customer'].'">';
372 print '<tr><td>'.$langs->trans("AddContributor").'</td><td>';
373 //print $form->selectcontacts($object->dao->fk_soc, '', 'contactid', 3, '', '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400');
374 print $form->select_contact($object->dao->fk_soc, '', 'contactid', 3, '', '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400', true);
375 print '<input type="submit" class="button smallpaddingimp reposition" name="btn_add_contact" value="'.$langs->trans('Add').'" />';
376 print '</td></tr></form>';
377 }
378
379 // Progression
380 if (getDolGlobalString('TICKET_SHOW_PROGRESSION')) {
381 print '<tr><td>'.$langs->trans("Progression").'</td><td>';
382 print($object->dao->progress > 0 ? dol_escape_htmltag((string) $object->dao->progress) : '0').'%';
383 print '</td></tr>';
384 }
385
386 // Other attributes
387 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
388
389 print '</table>';
390
391 print '</div>';
392
393 print '<div style="clear: both; margin-top: 1.5em;"></div>';
394
395 if ($action == 'presend') {
396 print '<br>';
397 print load_fiche_titre($langs->trans('TicketAddMessage'), '', 'conversation');
398
399 $formticket = new FormTicket($db);
400
401 $formticket->action = "add_message";
402 $formticket->track_id = $object->dao->track_id;
403 $formticket->trackid = 'tic'.$object->dao->id;
404
405 $baseurl = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.'/public/ticket/');
406
407 $formticket->param = array('track_id' => $object->dao->track_id, 'fk_user_create' => '-1',
408 'returnurl' => $baseurl.'view.php'.(!empty($entity) && isModEnabled('multicompany') ? '?entity='.$entity : ''));
409
410 $formticket->withfile = 2;
411 $formticket->withcancel = 1;
412
413 $formticket->showMessageForm('100%');
414 }
415
416 if ($action != 'presend') {
417 $baseurl = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.'/public/ticket/');
418
419 print '<form method="POST" id="form_view_ticket_list" name="form_view_ticket_list" action="'.$baseurl.'list.php'.(!empty($entity) && isModEnabled('multicompany') ? '?entity='.$entity : '').'">';
420 print '<input type="hidden" name="token" value="'.newToken().'">';
421 print '<input type="hidden" name="action" value="view_ticketlist">';
422 print '<input type="hidden" name="track_id" value="'.$object->dao->track_id.'">';
423 print '<input type="hidden" name="email" value="'.$_SESSION['email_customer'].'">';
424 //print '<input type="hidden" name="search_fk_status" value="non_closed">';
425 print "</form>\n";
426
427 print '<div class="tabsAction">';
428
429 // List ticket
430 print '<div class="inline-block divButAction"><a class="left" style="padding-right: 50px" href="javascript:$(\'#form_view_ticket_list\').submit();">'.$langs->trans('ViewMyTicketList').'</a></div>';
431
432 if ($object->dao->fk_statut < Ticket::STATUS_CLOSED) {
433 // New message
434 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=presend&mode=init&track_id='.$object->dao->track_id.(!empty($entity) && isModEnabled('multicompany') ? '&entity='.$entity : '').'&token='.newToken().'">'.$langs->trans('TicketAddMessage').'</a></div>';
435
436 // Close ticket
437 if ($object->dao->fk_statut >= Ticket::STATUS_NOT_READ && $object->dao->fk_statut < Ticket::STATUS_CLOSED) {
438 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=close&track_id='.$object->dao->track_id.(!empty($entity) && isModEnabled('multicompany') ? '&entity='.$entity : '').'&token='.newToken().'">'.$langs->trans('CloseTicket').'</a></div>';
439 }
440 }
441
442 print '</div>';
443 }
444
445 print '</div>';
446
447 // Message list
448 print '<div class="ticketpublicarea ticketlargemargin centpercent">';
449 print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'conversation');
450 print '</div>';
451
452 $object->viewTicketMessages(false, true, $object->dao);
453
454 print '<br>';
455 } else {
456 print '<!-- public view ticket -->';
457 print '<div class="ticketpublicarea ticketlargemargin">';
458
459 print '<div class="error">Not Allowed<br><a href="'.$_SERVER['PHP_SELF'].'?track_id='.$object->dao->track_id.(!empty($entity) && isModEnabled('multicompany') ? '?entity='.$entity : '').'" rel="nofollow noopener">'.$langs->trans('Back').'</a></div>';
460
461 print '</div>';
462 }
463} else {
464 print '<!-- public view ticket -->';
465 print '<div class="ticketpublicarea ticketlargemargin">';
466
467 print '<div class="center opacitymedium margintoponly marginbottomonly ticketlargemargin">'.$langs->trans("TicketPublicMsgViewLogIn").'</div>';
468
469 print '<div id="form_view_ticket">';
470 print '<form method="POST" class="maxwidth1000 center" name="form_view_ticket" action="'.$_SERVER['PHP_SELF'].(!empty($entity) && isModEnabled('multicompany') ? '?entity='.$entity : '').'">';
471
472 print '<input type="hidden" name="token" value="'.newToken().'">';
473 print '<input type="hidden" name="action" value="view_ticket">';
474
475 print '<p><label for="track_id" style="display: inline-block;" class="titlefieldcreate left"><span class="fieldrequired">';
476 print img_picto($langs->trans("TicketTrackId"), 'generic', 'class="pictofixedwidth"');
477 print $langs->trans("TicketTrackId").'</span></label>';
478 print '<br class="showonsmartphone hidden">';
479 print '<input class="minwidth100" id="track_id" name="track_id" value="'.(GETPOST('track_id', 'alpha') ? GETPOST('track_id', 'alpha') : '').'" />';
480 print '</p>';
481
482 print '<p><label for="email" style="display: inline-block;" class="titlefieldcreate left"><span class="fieldrequired">';
483 print img_picto($langs->trans("Email"), 'email', 'class="pictofixedwidth"');
484 print $langs->trans('Email').'</span></label>';
485 print '<br class="showonsmartphone hidden">';
486 print '<input class="minwidth100" id="email" name="email" value="'.(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : (!empty($_SESSION['customer_email']) ? $_SESSION['customer_email'] : "")).'" />';
487 print '</p>';
488
489 print '<p style="text-align: center; margin-top: 1.5em;">';
490 print '<input type="submit" class="button" name="btn_view_ticket" value="'.$langs->trans('ViewTicket').'" />';
491 print ' &nbsp; ';
492 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
493 print "</p>\n";
494
495 print "</form>\n";
496 print "</div>\n";
497
498 print '</div>';
499}
500
501if (getDolGlobalInt('TICKET_SHOW_COMPANY_FOOTER')) {
502 // End of page
503 htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix, $object);
504}
505
506llxFooter('', 'public');
507
508$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
Class Actions of the module ticket.
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML public pages.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
llxHeaderTicket($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[])
Show http header, open body tag and show HTML header banner for public pages for tickets.