dolibarr  16.0.1
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 require '../../main.inc.php';
48 require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
49 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
50 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
52 require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
53 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
54 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
55 
56 // Load translation files required by the page
57 $langs->loadLangs(array("companies", "other", "ticket"));
58 
59 // Get parameters
60 $action = GETPOST('action', 'aZ09');
61 $cancel = GETPOST('cancel', 'aZ09');
62 
63 $track_id = GETPOST('track_id', 'alpha');
64 $email = GETPOST('email', 'email');
65 
66 if (GETPOST('btn_view_ticket')) {
67  unset($_SESSION['email_customer']);
68 }
69 if (isset($_SESSION['email_customer'])) {
70  $email = $_SESSION['email_customer'];
71 }
72 
73 $object = new ActionsTicket($db);
74 
75 if (empty($conf->ticket->enabled)) {
76  accessforbidden('', 0, 0, 1);
77 }
78 
79 
80 /*
81  * Actions
82  */
83 
84 if ($cancel) {
85  $backtopage = DOL_URL_ROOT.'/public/ticket/index.php';
86 
87  if (!empty($backtopage)) {
88  header("Location: ".$backtopage);
89  exit;
90  }
91  $action = 'view_ticket';
92 }
93 
94 if ($action == "view_ticket" || $action == "presend" || $action == "close" || $action == "confirm_public_close" || $action == "add_message") {
95  $error = 0;
96  $display_ticket = false;
97  if (!strlen($track_id)) {
98  $error++;
99  array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketTrackId")));
100  $action = '';
101  }
102  if (!strlen($email)) {
103  $error++;
104  array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Email")));
105  $action = '';
106  } else {
107  if (!isValidEmail($email)) {
108  $error++;
109  array_push($object->errors, $langs->trans("ErrorEmailInvalid"));
110  $action = '';
111  }
112  }
113 
114  if (!$error) {
115  $ret = $object->fetch('', '', $track_id);
116  if ($ret && $object->dao->id > 0) {
117  // Check if emails provided is the one of author
118  $emailofticket = CMailFile::getValidAddress($object->dao->origin_email, 2);
119  if (strtolower($emailofticket) == strtolower($email)) {
120  $display_ticket = true;
121  $_SESSION['email_customer'] = $email;
122  } else {
123  // Check if emails provided is inside list of contacts
124  $contacts = $object->dao->liste_contact(-1, 'external');
125  foreach ($contacts as $contact) {
126  if (strtolower($contact['email']) == strtolower($email)) {
127  $display_ticket = true;
128  $_SESSION['email_customer'] = $email;
129  break;
130  } else {
131  $display_ticket = false;
132  }
133  }
134  }
135  // Check email of thirdparty of ticket
136  if ($object->dao->fk_soc > 0 || $object->dao->socid > 0) {
137  $object->dao->fetch_thirdparty();
138  if ($email == $object->dao->thirdparty->email) {
139  $display_ticket = true;
140  $_SESSION['email_customer'] = $email;
141  }
142  }
143  // Check if email is email of creator
144  if ($object->dao->fk_user_create > 0) {
145  $tmpuser = new User($db);
146  $tmpuser->fetch($object->dao->fk_user_create);
147  if (strtolower($email) == strtolower($tmpuser->email)) {
148  $display_ticket = true;
149  $_SESSION['email_customer'] = $email;
150  }
151  }
152  // Check if email is email of creator
153  if ($object->dao->fk_user_assign > 0 && $object->dao->fk_user_assign != $object->dao->fk_user_create) {
154  $tmpuser = new User($db);
155  $tmpuser->fetch($object->dao->fk_user_assign);
156  if (strtolower($email) == strtolower($tmpuser->email)) {
157  $display_ticket = true;
158  $_SESSION['email_customer'] = $email;
159  }
160  }
161  } else {
162  $error++;
163  array_push($object->errors, $langs->trans("ErrorTicketNotFound", $track_id));
164  $action = '';
165  }
166  }
167 
168  if (!$error && $action == 'confirm_public_close' && $display_ticket) {
169  if ($object->dao->close($user)) {
170  setEventMessages($langs->trans('TicketMarkedAsClosed'), null, 'mesgs');
171 
172  $url = 'view.php?action=view_ticket&track_id='.GETPOST('track_id', 'alpha').(!empty($entity) && !empty($conf->multicompany->enabled)?'&entity='.$entity:'');
173  header("Location: ".$url);
174  exit;
175  } else {
176  $action = '';
177  setEventMessages($object->error, $object->errors, 'errors');
178  }
179  }
180 
181  if (!$error && $action == "add_message" && $display_ticket && GETPOSTISSET('btn_add_message')) {
182  // TODO Add message...
183  $ret = $object->dao->newMessage($user, $action, 0, 1);
184 
185 
186  if (!$error) {
187  $action = 'view_ticket';
188  }
189  }
190 
191  if ($error || $errors) {
192  setEventMessages($object->error, $object->errors, 'errors');
193  if ($action == "add_message") {
194  $action = 'presend';
195  } else {
196  $action = '';
197  }
198  }
199 }
200 //var_dump($action);
201 //$object->doActions($action);
202 
203 // Actions to send emails (for ticket, we need to manage the addfile and removefile only)
204 $triggersendname = 'TICKET_SENTBYMAIL';
205 $paramname = 'id';
206 $autocopy = 'MAIN_MAIL_AUTOCOPY_TICKET_TO'; // used to know the automatic BCC to add
207 $trackid = 'tic'.$object->id;
208 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
209 
210 
211 
212 /*
213  * View
214  */
215 
216 $form = new Form($db);
217 $formticket = new FormTicket($db);
218 
219 if (!$conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) {
220  print '<div class="error">'.$langs->trans('TicketPublicInterfaceForbidden').'</div>';
221  $db->close();
222  exit();
223 }
224 
225 $arrayofjs = array();
226 $arrayofcss = array('/ticket/css/styles.css.php');
227 
228 llxHeaderTicket($langs->trans("Tickets"), "", 0, 0, $arrayofjs, $arrayofcss);
229 
230 print '<div class="ticketpublicarea">';
231 
232 if ($action == "view_ticket" || $action == "presend" || $action == "close" || $action == "confirm_public_close") {
233  if ($display_ticket) {
234  // Confirmation close
235  if ($action == 'close') {
236  print $form->formconfirm($_SERVER["PHP_SELF"]."?track_id=".$track_id.(!empty($entity) && !empty($conf->multicompany->enabled)?'&entity='.$entity:''), $langs->trans("CloseATicket"), $langs->trans("ConfirmCloseAticket"), "confirm_public_close", '', '', 1);
237  }
238 
239  print '<div id="form_view_ticket" class="margintoponly">';
240 
241  print '<table class="ticketpublictable centpercent tableforfield">';
242 
243  // Ref
244  print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
245  print img_picto('', 'ticket', 'class="pictofixedwidth"');
246  print dol_escape_htmltag($object->dao->ref);
247  print '</td></tr>';
248 
249  // Tracking ID
250  print '<tr><td>'.$langs->trans("TicketTrackId").'</td><td>';
251  print dol_escape_htmltag($object->dao->track_id);
252  print '</td></tr>';
253 
254  // Subject
255  print '<tr><td>'.$langs->trans("Subject").'</td><td>';
256  print '<span class="bold">';
257  print dol_escape_htmltag($object->dao->subject);
258  print '</span>';
259  print '</td></tr>';
260 
261  // Statut
262  print '<tr><td>'.$langs->trans("Status").'</td><td>';
263  print $object->dao->getLibStatut(2);
264  print '</td></tr>';
265 
266  // Type
267  print '<tr><td>'.$langs->trans("Type").'</td><td>';
268  print dol_escape_htmltag($object->dao->type_label);
269  print '</td></tr>';
270 
271  // Category
272  print '<tr><td>'.$langs->trans("Category").'</td><td>';
273  if ($object->dao->category_label) {
274  print img_picto('', 'category', 'class="pictofixedwidth"');
275  print dol_escape_htmltag($object->dao->category_label);
276  }
277  print '</td></tr>';
278 
279  // Severity
280  print '<tr><td>'.$langs->trans("Severity").'</td><td>';
281  print dol_escape_htmltag($object->dao->severity_label);
282  print '</td></tr>';
283 
284  // Creation date
285  print '<tr><td>'.$langs->trans("DateCreation").'</td><td>';
286  print dol_print_date($object->dao->datec, 'dayhour');
287  print '</td></tr>';
288 
289  // Author
290  print '<tr><td>'.$langs->trans("Author").'</td><td>';
291  if ($object->dao->fk_user_create > 0) {
292  $langs->load("users");
293  $fuser = new User($db);
294  $fuser->fetch($object->dao->fk_user_create);
295  print img_picto('', 'user', 'class="pictofixedwidth"');
296  print $fuser->getFullName($langs);
297  } else {
298  print img_picto('', 'email', 'class="pictofixedwidth"');
299  print dol_escape_htmltag($object->dao->origin_email);
300  }
301 
302  print '</td></tr>';
303 
304  // Read date
305  if (!empty($object->dao->date_read)) {
306  print '<tr><td>'.$langs->trans("TicketReadOn").'</td><td>';
307  print dol_print_date($object->dao->date_read, 'dayhour');
308  print '</td></tr>';
309  }
310 
311  // Close date
312  if (!empty($object->dao->date_close)) {
313  print '<tr><td>'.$langs->trans("TicketCloseOn").'</td><td>';
314  print dol_print_date($object->dao->date_close, 'dayhour');
315  print '</td></tr>';
316  }
317 
318  // User assigned
319  print '<tr><td>'.$langs->trans("AssignedTo").'</td><td>';
320  if ($object->dao->fk_user_assign > 0) {
321  $fuser = new User($db);
322  $fuser->fetch($object->dao->fk_user_assign);
323  print img_picto('', 'user', 'class="pictofixedwidth"');
324  print $fuser->getFullName($langs, 1);
325  }
326  print '</td></tr>';
327 
328  // Progression
329  print '<tr><td>'.$langs->trans("Progression").'</td><td>';
330  print ($object->dao->progress > 0 ? dol_escape_htmltag($object->dao->progress) : '0').'%';
331  print '</td></tr>';
332 
333  print '</table>';
334 
335  print '</div>';
336 
337  print '<div style="clear: both; margin-top: 1.5em;"></div>';
338 
339  if ($action == 'presend') {
340  print load_fiche_titre($langs->trans('TicketAddMessage'), '', 'conversation');
341 
342  $formticket = new FormTicket($db);
343 
344  $formticket->action = "add_message";
345  $formticket->track_id = $object->dao->track_id;
346  $formticket->id = $object->dao->id;
347 
348  $formticket->param = array('track_id' => $object->dao->track_id, 'fk_user_create' => '-1',
349  'returnurl' => DOL_URL_ROOT.'/public/ticket/view.php'.(!empty($entity) && !empty($conf->multicompany->enabled)?'?entity='.$entity:''));
350 
351  $formticket->withfile = 2;
352  $formticket->withcancel = 1;
353 
354  $formticket->showMessageForm('100%');
355  }
356 
357  if ($action != 'presend') {
358  print '<form method="post" id="form_view_ticket_list" name="form_view_ticket_list" action="'.DOL_URL_ROOT.'/public/ticket/list.php'.(!empty($entity) && !empty($conf->multicompany->enabled)?'?entity='.$entity:'').'">';
359  print '<input type="hidden" name="token" value="'.newToken().'">';
360  print '<input type="hidden" name="action" value="view_ticketlist">';
361  print '<input type="hidden" name="track_id" value="'.$object->dao->track_id.'">';
362  print '<input type="hidden" name="email" value="'.$_SESSION['email_customer'].'">';
363  //print '<input type="hidden" name="search_fk_status" value="non_closed">';
364  print "</form>\n";
365 
366  print '<div class="tabsAction">';
367 
368  // List ticket
369  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>';
370 
371  if ($object->dao->fk_statut < Ticket::STATUS_CLOSED) {
372  // New message
373  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) && !empty($conf->multicompany->enabled)?'&entity='.$entity:'').'">'.$langs->trans('AddMessage').'</a></div>';
374 
375  // Close ticket
376  if ($object->dao->fk_statut >= Ticket::STATUS_NOT_READ && $object->dao->fk_statut < Ticket::STATUS_CLOSED) {
377  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=close&track_id='.$object->dao->track_id.(!empty($entity) && !empty($conf->multicompany->enabled)?'&entity='.$entity:'').'">'.$langs->trans('CloseTicket').'</a></div>';
378  }
379  }
380 
381  print '</div>';
382  }
383 
384  // Message list
385  print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'conversation');
386  $object->viewTicketMessages(false, true, $object->dao);
387  } else {
388  print '<div class="error">Not Allowed<br><a href="'.$_SERVER['PHP_SELF'].'?track_id='.$object->dao->track_id.(!empty($entity) && !empty($conf->multicompany->enabled)?'?entity='.$entity:'').'" rel="nofollow noopener">'.$langs->trans('Back').'</a></div>';
389  }
390 } else {
391  print '<div class="center opacitymedium margintoponly marginbottomonly">'.$langs->trans("TicketPublicMsgViewLogIn").'</div>';
392 
393  print '<div id="form_view_ticket">';
394  print '<form method="post" name="form_view_ticket" action="'.$_SERVER['PHP_SELF'].(!empty($entity) && !empty($conf->multicompany->enabled)?'?entity='.$entity:'').'">';
395  print '<input type="hidden" name="token" value="'.newToken().'">';
396  print '<input type="hidden" name="action" value="view_ticket">';
397 
398  print '<p><label for="track_id" style="display: inline-block; width: 30%; "><span class="fieldrequired">'.$langs->trans("TicketTrackId").'</span></label>';
399  print '<input size="30" id="track_id" name="track_id" value="'.(GETPOST('track_id', 'alpha') ? GETPOST('track_id', 'alpha') : '').'" />';
400  print '</p>';
401 
402  print '<p><label for="email" style="display: inline-block; width: 30%; "><span class="fieldrequired">'.$langs->trans('Email').'</span></label>';
403  print '<input size="30" id="email" name="email" value="'.(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $_SESSION['customer_email']).'" />';
404  print '</p>';
405 
406  print '<p style="text-align: center; margin-top: 1.5em;">';
407  print '<input type="submit" class="button" name="btn_view_ticket" value="'.$langs->trans('ViewTicket').'" />';
408  print ' &nbsp; ';
409  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
410  print "</p>\n";
411 
412  print "</form>\n";
413  print "</div>\n";
414 }
415 
416 print "</div>";
417 
418 // End of page
419 htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix, $object);
420 
421 llxFooter('', 'public');
422 
423 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
llxHeaderTicket($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs= '', $arrayofcss= '')
Show header for public pages.
Definition: ticket.lib.php:206
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class Actions of the module ticket.
const STATUS_NOT_READ
Status.
llxFooter()
Empty footer.
Definition: wrapper.php:73