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