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