dolibarr  19.0.0-dev
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  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 if (!defined('NOREQUIREMENU')) {
26  define('NOREQUIREMENU', '1');
27 }
28 // If there is no need to load and show top and left menu
29 if (!defined("NOLOGIN")) {
30  define("NOLOGIN", '1');
31 }
32 if (!defined('NOIPCHECK')) {
33  define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
34 }
35 if (!defined('NOBROWSERNOTIF')) {
36  define('NOBROWSERNOTIF', '1');
37 }
38 // If this page is public (can be called outside logged session)
39 
40 // For MultiCompany module.
41 // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
42 $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
43 if (is_numeric($entity)) {
44  define("DOLENTITY", $entity);
45 }
46 
47 // Load Dolibarr environment
48 require '../../main.inc.php';
49 require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
50 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
52 require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
53 require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
54 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
55 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
56 
57 // Load translation files required by the page
58 $langs->loadLangs(array("companies", "other", "ticket"));
59 
60 // Get parameters
61 $action = GETPOST('action', 'aZ09');
62 $cancel = GETPOST('cancel', 'aZ09');
63 
64 $track_id = GETPOST('track_id', 'alpha');
65 $email = GETPOST('email', 'email');
66 $suffix = "";
67 
68 if (GETPOST('btn_view_ticket')) {
69  unset($_SESSION['email_customer']);
70 }
71 if (isset($_SESSION['email_customer'])) {
72  $email = $_SESSION['email_customer'];
73 }
74 
75 $object = new ActionsTicket($db);
76 
77 if (!isModEnabled('ticket')) {
78  httponly_accessforbidden('Module Ticket not enabled');
79 }
80 
81 
82 /*
83  * Actions
84  */
85 
86 if ($cancel) {
87  $backtopage = DOL_URL_ROOT.'/public/ticket/index.php';
88 
89  if (!empty($backtopage)) {
90  header("Location: ".$backtopage);
91  exit;
92  }
93  $action = 'view_ticket';
94 }
95 
96 if ($action == "view_ticket" || $action == "presend" || $action == "close" || $action == "confirm_public_close" || $action == "add_message") {
97  $error = 0;
98  $display_ticket = false;
99  if (!strlen($track_id)) {
100  $error++;
101  array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketTrackId")));
102  $action = '';
103  }
104  if (!strlen($email)) {
105  $error++;
106  array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Email")));
107  $action = '';
108  } else {
109  if (!isValidEmail($email)) {
110  $error++;
111  array_push($object->errors, $langs->trans("ErrorEmailInvalid"));
112  $action = '';
113  }
114  }
115 
116  if (!$error) {
117  $ret = $object->fetch('', '', $track_id);
118  if ($ret && $object->dao->id > 0) {
119  // Check if emails provided is the one of author
120  $emailofticket = CMailFile::getValidAddress($object->dao->origin_email, 2);
121  if (strtolower($emailofticket) == strtolower($email)) {
122  $display_ticket = true;
123  $_SESSION['email_customer'] = $email;
124  } else {
125  // Check if emails provided is inside list of contacts
126  $contacts = $object->dao->liste_contact(-1, 'external');
127  foreach ($contacts as $contact) {
128  if (strtolower($contact['email']) == strtolower($email)) {
129  $display_ticket = true;
130  $_SESSION['email_customer'] = $email;
131  break;
132  } else {
133  $display_ticket = false;
134  }
135  }
136  }
137  // Check email of thirdparty of ticket
138  if ($object->dao->fk_soc > 0 || $object->dao->socid > 0) {
139  $object->dao->fetch_thirdparty();
140  if ($email == $object->dao->thirdparty->email) {
141  $display_ticket = true;
142  $_SESSION['email_customer'] = $email;
143  }
144  }
145  // Check if email is email of creator
146  if ($object->dao->fk_user_create > 0) {
147  $tmpuser = new User($db);
148  $tmpuser->fetch($object->dao->fk_user_create);
149  if (strtolower($email) == strtolower($tmpuser->email)) {
150  $display_ticket = true;
151  $_SESSION['email_customer'] = $email;
152  }
153  }
154  // Check if email is email of creator
155  if ($object->dao->fk_user_assign > 0 && $object->dao->fk_user_assign != $object->dao->fk_user_create) {
156  $tmpuser = new User($db);
157  $tmpuser->fetch($object->dao->fk_user_assign);
158  if (strtolower($email) == strtolower($tmpuser->email)) {
159  $display_ticket = true;
160  $_SESSION['email_customer'] = $email;
161  }
162  }
163  } else {
164  $error++;
165  array_push($object->errors, $langs->trans("ErrorTicketNotFound", $track_id));
166  $action = '';
167  }
168  }
169 
170  if (!$error && $action == 'confirm_public_close' && $display_ticket) {
171  if ($object->dao->close($user)) {
172  setEventMessages($langs->trans('TicketMarkedAsClosed'), null, 'mesgs');
173 
174  $url = 'view.php?action=view_ticket&track_id='.GETPOST('track_id', 'alpha').(!empty($entity) && isModEnabled('multicompany')?'&entity='.$entity:'').'&token='.newToken();
175  header("Location: ".$url);
176  exit;
177  } else {
178  $action = '';
179  setEventMessages($object->error, $object->errors, 'errors');
180  }
181  }
182 
183  if (!$error && $action == "add_message" && $display_ticket && GETPOSTISSET('btn_add_message')) {
184  // TODO Add message...
185  $ret = $object->dao->newMessage($user, $action, 0, 1);
186 
187 
188  if (!$error) {
189  $action = 'view_ticket';
190  }
191  }
192 
193  if ($error || $errors) {
194  setEventMessages($object->error, $object->errors, 'errors');
195  if ($action == "add_message") {
196  $action = 'presend';
197  } else {
198  $action = '';
199  }
200  }
201 }
202 //var_dump($action);
203 //$object->doActions($action);
204 
205 // Actions to send emails (for ticket, we need to manage the addfile and removefile only)
206 $triggersendname = 'TICKET_SENTBYMAIL';
207 $paramname = 'id';
208 $autocopy = 'MAIN_MAIL_AUTOCOPY_TICKET_TO'; // used to know the automatic BCC to add
209 if (!empty($object->dao->id)) $trackid = 'tic'.$object->dao->id;
210 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
211 
212 
213 
214 /*
215  * View
216  */
217 
218 $form = new Form($db);
219 $formticket = new FormTicket($db);
220 
221 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
222 $hookmanager->initHooks(array('ticketpublicview', 'globalcard'));
223 
224 if (!$conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) {
225  print '<div class="error">'.$langs->trans('TicketPublicInterfaceForbidden').'</div>';
226  $db->close();
227  exit();
228 }
229 
230 $arrayofjs = array();
231 $arrayofcss = array('/ticket/css/styles.css.php');
232 
233 llxHeaderTicket($langs->trans("Tickets"), "", 0, 0, $arrayofjs, $arrayofcss);
234 
235 print '<div class="ticketpublicarea ticketlargemargin centpercent">';
236 
237 if ($action == "view_ticket" || $action == "presend" || $action == "close" || $action == "confirm_public_close") {
238  if ($display_ticket) {
239  // Confirmation close
240  if ($action == 'close') {
241  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);
242  }
243 
244  print '<div id="form_view_ticket" class="margintoponly">';
245 
246  print '<table class="ticketpublictable centpercent tableforfield">';
247 
248  // Ref
249  print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
250  print img_picto('', 'ticket', 'class="pictofixedwidth"');
251  print dol_escape_htmltag($object->dao->ref);
252  print '</td></tr>';
253 
254  // Tracking ID
255  print '<tr><td>'.$langs->trans("TicketTrackId").'</td><td>';
256  print dol_escape_htmltag($object->dao->track_id);
257  print '</td></tr>';
258 
259  // Subject
260  print '<tr><td>'.$langs->trans("Subject").'</td><td>';
261  print '<span class="bold">';
262  print dol_escape_htmltag($object->dao->subject);
263  print '</span>';
264  print '</td></tr>';
265 
266  // Statut
267  print '<tr><td>'.$langs->trans("Status").'</td><td>';
268  print $object->dao->getLibStatut(2);
269  print '</td></tr>';
270 
271  // Type
272  print '<tr><td>'.$langs->trans("Type").'</td><td>';
273  print dol_escape_htmltag($object->dao->type_label);
274  print '</td></tr>';
275 
276  // Category
277  print '<tr><td>'.$langs->trans("Category").'</td><td>';
278  if ($object->dao->category_label) {
279  print img_picto('', 'category', 'class="pictofixedwidth"');
280  print dol_escape_htmltag($object->dao->category_label);
281  }
282  print '</td></tr>';
283 
284  // Severity
285  print '<tr><td>'.$langs->trans("Severity").'</td><td>';
286  print dol_escape_htmltag($object->dao->severity_label);
287  print '</td></tr>';
288 
289  // Creation date
290  print '<tr><td>'.$langs->trans("DateCreation").'</td><td>';
291  print dol_print_date($object->dao->datec, 'dayhour');
292  print '</td></tr>';
293 
294  // Author
295  print '<tr><td>'.$langs->trans("Author").'</td><td>';
296  if ($object->dao->fk_user_create > 0) {
297  $langs->load("users");
298  $fuser = new User($db);
299  $fuser->fetch($object->dao->fk_user_create);
300  print img_picto('', 'user', 'class="pictofixedwidth"');
301  print $fuser->getFullName($langs);
302  } else {
303  print img_picto('', 'email', 'class="pictofixedwidth"');
304  print dol_escape_htmltag($object->dao->origin_email);
305  }
306 
307  print '</td></tr>';
308 
309  // Read date
310  if (!empty($object->dao->date_read)) {
311  print '<tr><td>'.$langs->trans("TicketReadOn").'</td><td>';
312  print dol_print_date($object->dao->date_read, 'dayhour');
313  print '</td></tr>';
314  }
315 
316  // Close date
317  if (!empty($object->dao->date_close)) {
318  print '<tr><td>'.$langs->trans("TicketCloseOn").'</td><td>';
319  print dol_print_date($object->dao->date_close, 'dayhour');
320  print '</td></tr>';
321  }
322 
323  // User assigned
324  print '<tr><td>'.$langs->trans("AssignedTo").'</td><td>';
325  if ($object->dao->fk_user_assign > 0) {
326  $fuser = new User($db);
327  $fuser->fetch($object->dao->fk_user_assign);
328  print img_picto('', 'user', 'class="pictofixedwidth"');
329  print $fuser->getFullName($langs, 1);
330  }
331  print '</td></tr>';
332 
333  // Progression
334  if (!empty($conf->global->TICKET_SHOW_PROGRESSION)) {
335  print '<tr><td>'.$langs->trans("Progression").'</td><td>';
336  print ($object->dao->progress > 0 ? dol_escape_htmltag($object->dao->progress) : '0').'%';
337  print '</td></tr>';
338  }
339 
340  // Other attributes
341  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
342 
343  print '</table>';
344 
345  print '</div>';
346 
347  print '<div style="clear: both; margin-top: 1.5em;"></div>';
348 
349  if ($action == 'presend') {
350  print load_fiche_titre($langs->trans('TicketAddMessage'), '', 'conversation');
351 
352  $formticket = new FormTicket($db);
353 
354  $formticket->action = "add_message";
355  $formticket->track_id = $object->dao->track_id;
356  $formticket->trackid = 'tic'.$object->dao->id;
357 
358  $formticket->param = array('track_id' => $object->dao->track_id, 'fk_user_create' => '-1',
359  'returnurl' => DOL_URL_ROOT.'/public/ticket/view.php'.(!empty($entity) && isModEnabled('multicompany')?'?entity='.$entity:''));
360 
361  $formticket->withfile = 2;
362  $formticket->withcancel = 1;
363 
364  $formticket->showMessageForm('100%');
365  }
366 
367  if ($action != 'presend') {
368  print '<form method="post" id="form_view_ticket_list" name="form_view_ticket_list" action="'.DOL_URL_ROOT.'/public/ticket/list.php'.(!empty($entity) && isModEnabled('multicompany')?'?entity='.$entity:'').'">';
369  print '<input type="hidden" name="token" value="'.newToken().'">';
370  print '<input type="hidden" name="action" value="view_ticketlist">';
371  print '<input type="hidden" name="track_id" value="'.$object->dao->track_id.'">';
372  print '<input type="hidden" name="email" value="'.$_SESSION['email_customer'].'">';
373  //print '<input type="hidden" name="search_fk_status" value="non_closed">';
374  print "</form>\n";
375 
376  print '<div class="tabsAction">';
377 
378  // List ticket
379  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>';
380 
381  if ($object->dao->fk_statut < Ticket::STATUS_CLOSED) {
382  // New message
383  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>';
384 
385  // Close ticket
386  if ($object->dao->fk_statut >= Ticket::STATUS_NOT_READ && $object->dao->fk_statut < Ticket::STATUS_CLOSED) {
387  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>';
388  }
389  }
390 
391  print '</div>';
392  }
393 
394  // Message list
395  print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'conversation');
396  $object->viewTicketMessages(false, true, $object->dao);
397  } else {
398  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>';
399  }
400 } else {
401  print '<div class="center opacitymedium margintoponly marginbottomonly ticketlargemargin">'.$langs->trans("TicketPublicMsgViewLogIn").'</div>';
402 
403  print '<div id="form_view_ticket">';
404  print '<form method="post" name="form_view_ticket" action="'.$_SERVER['PHP_SELF'].(!empty($entity) && isModEnabled('multicompany')?'?entity='.$entity:'').'">';
405 
406  print '<input type="hidden" name="token" value="'.newToken().'">';
407  print '<input type="hidden" name="action" value="view_ticket">';
408 
409  print '<p><label for="track_id" style="display: inline-block; width: 30%; "><span class="fieldrequired">'.$langs->trans("TicketTrackId").'</span></label>';
410  print '<input size="30" id="track_id" name="track_id" value="'.(GETPOST('track_id', 'alpha') ? GETPOST('track_id', 'alpha') : '').'" />';
411  print '</p>';
412 
413  print '<p><label for="email" style="display: inline-block; width: 30%; "><span class="fieldrequired">'.$langs->trans('Email').'</span></label>';
414  print '<input size="30" id="email" name="email" value="'.(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : (!empty($_SESSION['customer_email']) ? $_SESSION['customer_email'] : "")).'" />';
415  print '</p>';
416 
417  print '<p style="text-align: center; margin-top: 1.5em;">';
418  print '<input type="submit" class="button" name="btn_view_ticket" value="'.$langs->trans('ViewTicket').'" />';
419  print ' &nbsp; ';
420  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
421  print "</p>\n";
422 
423  print "</form>\n";
424  print "</div>\n";
425 }
426 
427 print "</div>";
428 
429 if (getDolGlobalInt('TICKET_SHOW_COMPANY_FOOTER')) {
430  // End of page
431  htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix, $object);
432 }
433 
434 llxFooter('', 'public');
435 
436 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:70
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.
const STATUS_NOT_READ
Status.
Class to manage Dolibarr users.
Definition: user.class.php:48
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML pages.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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 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)
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
isModEnabled($module)
Is Dolibarr module enabled.
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.
Definition: ticket.lib.php:216