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