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