1<?php
2/*  Copyright (C) 2013-2016    Jean-François FERRY    <jfefe@aternatik.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18/**
19 *       \file       htdocs/public/ticket/list.php
20 *       \ingroup    ticket
21 *       \brief      Public file to list tickets
22 */
23
24if (!defined('NOCSRFCHECK')) {
25	define('NOCSRFCHECK', '1');
26}
27// Do not check anti CSRF attack test
28if (!defined('NOREQUIREMENU')) {
29	define('NOREQUIREMENU', '1');
30}
31// If there is no need to load and show top and left menu
32if (!defined("NOLOGIN")) {
33	define("NOLOGIN", '1');
34}
35if (!defined('NOIPCHECK'))		define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
36if (!defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1');
37// If this page is public (can be called outside logged session)
38
39require '../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
47
48// Load translation files required by the page
49$langs->loadLangs(array("companies", "other", "ticket"));
50
51// Get parameters
52$track_id = GETPOST('track_id', 'alpha');
53$action = GETPOST('action', 'aZ09');
54$email = strtolower(GETPOST('email', 'alpha'));
55
56if (GETPOST('btn_view_ticket_list')) {
57	unset($_SESSION['track_id_customer']);
58	unset($_SESSION['email_customer']);
59}
60if (isset($_SESSION['track_id_customer'])) {
61	$track_id = $_SESSION['track_id_customer'];
62}
63if (isset($_SESSION['email_customer'])) {
64	$email = strtolower($_SESSION['email_customer']);
65}
66
67$object = new Ticket($db);
68
69
70
71
72/*
73 * Actions
74 */
75
76if ($action == "view_ticketlist") {
77	$error = 0;
78	$display_ticket_list = false;
79	if (!strlen($track_id)) {
80		$error++;
81		array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketTrackId")));
82		$action = '';
83	}
84
85	if (!strlen($email)) {
86		$error++;
87		array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Email")));
88		$action = '';
89	} else {
90		if (!isValidEmail($email)) {
91			$error++;
92			array_push($object->errors, $langs->trans("ErrorEmailOrTrackingInvalid"));
93			$action = '';
94		}
95	}
96
97	if (!$error) {
98		$ret = $object->fetch('', '', $track_id);
99
100		if ($ret && $object->id > 0) {
101			// vérifie si l'adresse email est bien dans les contacts du ticket
102			$contacts = $object->liste_contact(-1, 'external');
103			foreach ($contacts as $contact) {
104				if (strtolower($contact['email']) == $email) {
105					$display_ticket_list = true;
106					$_SESSION['email_customer'] = $email;
107					$_SESSION['track_id_customer'] = $track_id;
108					break;
109				} else {
110					$display_ticket_list = false;
111				}
112			}
113			if ($object->fk_soc > 0) {
114				$object->fetch_thirdparty();
115				if ($email == strtolower($object->thirdparty->email)) {
116					$display_ticket_list = true;
117					$_SESSION['email_customer'] = $email;
118					$_SESSION['track_id_customer'] = $track_id;
119				}
120			}
121			if ($object->fk_user_create > 0) {
122				$tmpuser = new User($db);
123				$tmpuser->fetch($object->fk_user_create);
124				if ($email == strtolower($tmpuser->email)) {
125					$display_ticket_list = true;
126					$_SESSION['email_customer'] = $email;
127					$_SESSION['track_id_customer'] = $track_id;
128				}
129			}
130
131			$emailorigin = strtolower(CMailFile::getValidAddress($object->origin_email, 2));
132			if ($email == $emailorigin) {
133				$display_ticket_list = true;
134				$_SESSION['email_customer'] = $email;
135				$_SESSION['track_id_customer'] = $track_id;
136			}
137		} else {
138			$error++;
139			array_push($object->errors, $langs->trans("ErrorTicketNotFound", $track_id));
140			$action = '';
141		}
142	}
143
144	if ($error || $errors) {
145		setEventMessages($object->error, $object->errors, 'errors');
146		$action = '';
147	}
148}
149
150//$object->doActions($action);
151
152
153
154/*
155 * View
156 */
157
158$form = new Form($db);
159$user_assign = new User($db);
160$user_create = new User($db);
161$formTicket = new FormTicket($db);
162
163if (!$conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) {
164	print '<div class="error">'.$langs->trans('TicketPublicInterfaceForbidden').'</div>';
165	$db->close();
166	exit();
167}
168
169$arrayofjs = array();
170$arrayofcss = array('/ticket/css/styles.css.php');
171
172llxHeaderTicket($langs->trans("Tickets"), "", 0, 0, $arrayofjs, $arrayofcss);
173
174
175print '<div class="ticketpublicarealist">';
176
177if ($action == "view_ticketlist")
178{
179	print '<br>';
180	if ($display_ticket_list) {
181		// Filters
182		$search_fk_status = GETPOST("search_fk_status", 'alpha');
183		$search_subject = GETPOST("search_subject", 'alpha');
184		$search_type = GETPOST("search_type", 'alpha');
185		$search_category = GETPOST("search_category", 'alpha');
186		$search_severity = GETPOST("search_severity", 'alpha');
187		$search_fk_user_create = GETPOST("search_fk_user_create", 'int');
188		$search_fk_user_assign = GETPOST("search_fk_user_assign", 'int');
189
190		// Store current page url
191		$url_page_current = dol_buildpath('/public/ticket/list.php', 1);
192
193		// Do we click on purge search criteria ?
194		if (GETPOST("button_removefilter_x")) {
195			$search_fk_status = '';
196			$search_subject = '';
197			$search_type = '';
198			$search_category = '';
199			$search_severity = '';
200			$search_fk_user_create = '';
201			$search_fk_user_assign = '';
202		}
203
204		// fetch optionals attributes and labels
205		$extrafields = new ExtraFields($db);
206		$extrafields->fetch_name_optionals_label($object->table_element);
207
208		$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
209
210		$filter = array();
211		$param = 'action=view_ticketlist';
212
213		// Definition of fields for list
214		$arrayfields = array(
215			't.datec' => array('label' => $langs->trans("Date"), 'checked' => 1),
216			't.date_read' => array('label' => $langs->trans("TicketReadOn"), 'checked' => 0),
217			't.date_close' => array('label' => $langs->trans("TicketCloseOn"), 'checked' => 0),
218			't.ref' => array('label' => $langs->trans("Ref"), 'checked' => 1),
219			//'t.track_id' => array('label' => $langs->trans("IDTracking"), 'checked' => 0),
220			't.fk_statut' => array('label' => $langs->trans("Status"), 'checked' => 1),
221			't.subject' => array('label' => $langs->trans("Subject"), 'checked' => 1),
222			'type.code' => array('label' => $langs->trans("Type"), 'checked' => 1),
223			'category.code' => array('label' => $langs->trans("Category"), 'checked' => 1),
224			'severity.code' => array('label' => $langs->trans("Severity"), 'checked' => 1),
225			't.progress' => array('label' => $langs->trans("Progression"), 'checked' => 0),
226			//'t.fk_contract' => array('label' => $langs->trans("Contract"), 'checked' => 0),
227			't.fk_user_create' => array('label' => $langs->trans("Author"), 'checked' => 1),
228			't.fk_user_assign' => array('label' => $langs->trans("AssignedTo"), 'checked' => 0),
229
230			//'t.entity'=>array('label'=>$langs->trans("Entity"), 'checked'=>1, 'enabled'=>(! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode))),
231			//'t.datec' => array('label' => $langs->trans("DateCreation"), 'checked' => 0, 'position' => 500),
232			//'t.tms' => array('label' => $langs->trans("DateModificationShort"), 'checked' => 0, 'position' => 2)
233			//'t.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
234		);
235
236		// Extra fields
237		if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
238			foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
239				if ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate') {
240					$arrayfields["ef.".$key] = array('label' => $extrafields->attributes[$object->table_element]['label'][$key], 'checked' => ($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1, 'position' => $extrafields->attributes[$object->table_element]['pos'][$key], 'enabled' =>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3) && $extrafields->attributes[$object->table_element]['perms'][$key]);
241				}
242			}
243		}
244		if (!empty($search_subject)) {
245			$filter['t.subject'] = $search_subject;
246			$param .= '&search_subject='.urlencode($search_subject);
247		}
248		if (!empty($search_type)) {
249			$filter['t.type_code'] = $search_type;
250			$param .= '&search_type='.urlencode($search_type);
251		}
252		if (!empty($search_category)) {
253			$filter['t.category_code'] = $search_category;
254			$param .= '&search_category='.urlencode($search_category);
255		}
256		if (!empty($search_severity)) {
257			$filter['t.severity_code'] = $search_severity;
258			$param .= '&search_severity='.urlencode($search_severity);
259		}
260		if (!empty($search_fk_user_assign)) {
261			// -1 value = all so no filter
262			if ($search_fk_user_assign > 0) {
263				$filter['t.fk_user_assign'] = $search_fk_user_assign;
264				$param .= '&search_fk_user_assign='.urlencode($search_fk_user_assign);
265			}
266		}
267		if (!empty($search_fk_user_create)) {
268			// -1 value = all so no filter
269			if ($search_fk_user_create > 0) {
270				$filter['t.fk_user_create'] = $search_fk_user_create;
271				$param .= '&search_fk_user_create='.urlencode($search_fk_user_create);
272			}
273		}
274		if ((isset($search_fk_status) && $search_fk_status != '') && $search_fk_status != '-1' && $search_fk_status != 'non_closed') {
275			$filter['t.fk_statut'] = $search_fk_status;
276			$param .= '&search_fk_status='.urlencode($search_fk_status);
277		}
278		if (isset($search_fk_status) && $search_fk_status == 'non_closed') {
279			$filter['t.fk_statut'] = array(0, 1, 3, 4, 5, 6);
280			$param .= '&search_fk_status=non_closed';
281		}
282
283		require DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
284
285		$sortfield = GETPOST("sortfield", 'alpha');
286		$sortorder = GETPOST("sortorder", 'alpha');
287
288		if (!$sortfield) {
289			$sortfield = 't.datec';
290		}
291		if (!$sortorder) {
292			$sortorder = 'DESC';
293		}
294
295		$limit = $conf->liste_limit;
296
297		$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
298		if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
299		$offset = $limit * $page;
300		$pageprev = $page - 1;
301		$pagenext = $page + 1;
302
303		// Request SQL
304		$sql = "SELECT DISTINCT";
305		$sql .= " t.rowid,";
306		$sql .= " t.ref,";
307		$sql .= " t.track_id,";
308		$sql .= " t.fk_soc,";
309		$sql .= " t.fk_project,";
310		$sql .= " t.origin_email,";
311		$sql .= " t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
312		$sql .= " t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
313		$sql .= " t.subject,";
314		$sql .= " t.message,";
315		$sql .= " t.fk_statut,";
316		$sql .= " t.resolution,";
317		$sql .= " t.progress,";
318		$sql .= " t.timing,";
319		$sql .= " t.type_code,";
320		$sql .= " t.category_code,";
321		$sql .= " t.severity_code,";
322		$sql .= " t.datec,";
323		$sql .= " t.date_read,";
324		$sql .= " t.date_close,";
325		$sql .= " t.tms,";
326		$sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label";
327		// Add fields for extrafields
328		if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
329			foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val)
330				$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
331		}
332		$sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
333		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
334		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code";
335		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code";
336		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc";
337		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as uc ON uc.rowid=t.fk_user_create";
338		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as ua ON ua.rowid=t.fk_user_assign";
339		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact as ec ON ec.element_id=t.rowid";
340		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_contact as tc ON ec.fk_c_type_contact=tc.rowid";
341		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople sp ON ec.fk_socpeople=sp.rowid";
342		if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
343			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."ticket_extrafields as ef on (t.rowid = ef.fk_object)";
344		}
345		$sql .= " WHERE t.entity IN (".getEntity('ticket').")";
346		$sql .= " AND ((tc.source = 'external'";
347		$sql .= " AND tc.element='".$db->escape($object->dao->element)."'";
348		$sql .= " AND tc.active=1)";
349		$sql .= " OR (sp.email='".$db->escape($_SESSION['email_customer'])."'";
350		$sql .= " OR s.email='".$db->escape($_SESSION['email_customer'])."'";
351		$sql .= " OR t.origin_email='".$db->escape($_SESSION['email_customer'])."'))";
352		// Manage filter
353		if (!empty($filter)) {
354			foreach ($filter as $key => $value) {
355				if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year
356					$sql .= ' AND '.$key.' = \''.$value.'\'';
357				} elseif (($key == 't.fk_user_assign') || ($key == 't.type_code') || ($key == 't.category_code') || ($key == 't.severity_code')) {
358					$sql .= " AND ".$key." = '".$db->escape($value)."'";
359				} elseif ($key == 't.fk_statut') {
360					if (is_array($value) && count($value) > 0) {
361						$sql .= 'AND '.$key.' IN ('.implode(',', $value).')';
362					} else {
363						$sql .= ' AND '.$key.' = '.$db->escape($value);
364					}
365				} else {
366					$sql .= ' AND '.$key.' LIKE \'%'.$value.'%\'';
367				}
368			}
369		}
370		//$sql .= " GROUP BY t.track_id";
371		$sql .= " ORDER BY ".$sortfield.' '.$sortorder;
372
373		$resql = $db->query($sql);
374		if ($resql) {
375			$num_total = $db->num_rows($resql);
376			if (!empty($limit)) {
377				$sql .= ' '.$db->plimit($limit + 1, $offset);
378			}
379
380			$resql = $db->query($sql);
381			if ($resql) {
382				$num = $db->num_rows($resql);
383				print_barre_liste($langs->trans('TicketList'), $page, 'public/list.php', $param, $sortfield, $sortorder, '', $num, $num_total, 'ticket');
384
385				// Search bar
386				print '<form method="get" action="'.$url_form.'" id="searchFormList" >'."\n";
387				print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
388				print '<input type="hidden" name="action" value="view_ticketlist">';
389				print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
390				print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
391
392				$varpage = empty($contextpage) ? $url_page_current : $contextpage;
393				$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
394
395				print '<table class="liste '.($moreforfilter ? "listwithfilterbefore" : "").'">';
396
397				// Filter bar
398				print '<tr class="liste_titre">';
399
400				if (!empty($arrayfields['t.datec']['checked'])) {
401					print '<td class="liste_titre"></td>';
402				}
403
404				if (!empty($arrayfields['t.date_read']['checked'])) {
405					print '<td class="liste_titre"></td>';
406				}
407				if (!empty($arrayfields['t.date_close']['checked'])) {
408					print '<td class="liste_titre"></td>';
409				}
410
411				if (!empty($arrayfields['t.ref']['checked'])) {
412					print '<td class="liste_titre"></td>';
413				}
414
415				if (!empty($arrayfields['t.subject']['checked'])) {
416					print '<td class="liste_titre">';
417					print '<input type="text" class="flat maxwidth100" name="search_subject" value="'.$search_subject.'">';
418					print '</td>';
419				}
420
421				if (!empty($arrayfields['type.code']['checked'])) {
422					print '<td class="liste_titre">';
423					$formTicket->selectTypesTickets($search_type, 'search_type', '', 2, 1, 1, 0, 'maxwidth150');
424					print '</td>';
425				}
426
427				if (!empty($arrayfields['category.code']['checked'])) {
428					print '<td class="liste_titre">';
429					$formTicket->selectGroupTickets($search_category, 'search_category', '', 2, 1, 1);
430					print '</td>';
431				}
432
433				if (!empty($arrayfields['severity.code']['checked'])) {
434					print '<td class="liste_titre">';
435					$formTicket->selectSeveritiesTickets($search_severity, 'search_severity', '', 2, 1, 1);
436					print '</td>';
437				}
438
439				if (!empty($arrayfields['t.progress']['checked'])) {
440					print '<td class="liste_titre"></td>';
441				}
442
443				if (!empty($arrayfields['t.fk_user_create']['checked'])) {
444					print '<td class="liste_titre"></td>';
445				}
446
447				if (!empty($arrayfields['t.fk_user_assign']['checked'])) {
448					print '<td class="liste_titre"></td>';
449				}
450
451				if (!empty($arrayfields['t.tms']['checked'])) {
452					print '<td class="liste_titre"></td>';
453				}
454
455				// Extra fields
456				include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
457
458				// Fields from hook
459				$parameters = array('arrayfields'=>$arrayfields);
460				$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
461				print $hookmanager->resPrint;
462
463				// Status
464				if (!empty($arrayfields['t.fk_statut']['checked'])) {
465					print '<td class="liste_titre">';
466					$selected = ($search_fk_status != "non_closed" ? $search_fk_status : '');
467					//$object->printSelectStatus($selected);
468					print '</td>';
469				}
470
471				// Action column
472				print '<td class="liste_titre maxwidthsearch">';
473				$searchpicto = $form->showFilterButtons();
474				print $searchpicto;
475				print '</td>';
476				print '</tr>';
477
478				// Field title
479				print '<tr class="liste_titre">';
480				if (!empty($arrayfields['t.datec']['checked'])) {
481					print_liste_field_titre($arrayfields['t.datec']['label'], $url_page_current, 't.datec', '', $param, '', $sortfield, $sortorder);
482				}
483				if (!empty($arrayfields['t.date_read']['checked'])) {
484					print_liste_field_titre($arrayfields['t.date_read']['label'], $url_page_current, 't.date_read', '', $param, '', $sortfield, $sortorder);
485				}
486				if (!empty($arrayfields['t.date_close']['checked'])) {
487					print_liste_field_titre($arrayfields['t.date_close']['label'], $url_page_current, 't.date_close', '', $param, '', $sortfield, $sortorder);
488				}
489				if (!empty($arrayfields['t.ref']['checked'])) {
490					print_liste_field_titre($arrayfields['t.ref']['label'], $url_page_current, 't.ref', '', $param, '', $sortfield, $sortorder);
491				}
492				if (!empty($arrayfields['t.subject']['checked'])) {
493					print_liste_field_titre($arrayfields['t.subject']['label']);
494				}
495				if (!empty($arrayfields['type.code']['checked'])) {
496					print_liste_field_titre($arrayfields['type.code']['label'], $url_page_current, 'type.code', '', $param, '', $sortfield, $sortorder);
497				}
498				if (!empty($arrayfields['category.code']['checked'])) {
499					print_liste_field_titre($arrayfields['category.code']['label'], $url_page_current, 'category.code', '', $param, '', $sortfield, $sortorder);
500				}
501				if (!empty($arrayfields['severity.code']['checked'])) {
502					print_liste_field_titre($arrayfields['severity.code']['label'], $url_page_current, 'severity.code', '', $param, '', $sortfield, $sortorder);
503				}
504				if (!empty($arrayfields['t.progress']['checked'])) {
505					print_liste_field_titre($arrayfields['t.progress']['label'], $url_page_current, 't.progress', '', $param, '', $sortfield, $sortorder);
506				}
507				if (!empty($arrayfields['t.fk_user_create']['checked'])) {
508					print_liste_field_titre($arrayfields['t.fk_user_create']['label'], $url_page_current, 't.fk_user_create', '', $param, '', $sortfield, $sortorder);
509				}
510				if (!empty($arrayfields['t.fk_user_assign']['checked'])) {
511					print_liste_field_titre($arrayfields['t.fk_user_assign']['label'], $url_page_current, 't.fk_user_assign', '', $param, '', $sortfield, $sortorder);
512				}
513				if (!empty($arrayfields['t.tms']['checked'])) {
514					print_liste_field_titre($arrayfields['t.tms']['label'], $url_page_current, 't.tms', '', $param, '', $sortfield, $sortorder);
515				}
516
517				// Extra fields
518				include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
519
520				// Hook fields
521				$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
522				$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
523				print $hookmanager->resPrint;
524
525				if (!empty($arrayfields['t.fk_statut']['checked'])) {
526					print_liste_field_titre($arrayfields['t.fk_statut']['label'], $url_page_current, 't.fk_statut', '', $param, '', $sortfield, $sortorder);
527				}
528				print_liste_field_titre($selectedfields, $url_page_current, "", '', '', 'align="right"', $sortfield, $sortorder, 'center maxwidthsearch ');
529				print '</tr>';
530
531				while ($obj = $db->fetch_object($resql))
532				{
533					print '<tr class="oddeven">';
534
535					// Date ticket
536					if (!empty($arrayfields['t.datec']['checked'])) {
537						print '<td>';
538						print dol_print_date($db->jdate($obj->datec), 'dayhour');
539						print '</td>';
540					}
541
542					// Date read
543					if (!empty($arrayfields['t.date_read']['checked'])) {
544						print '<td>';
545						print dol_print_date($db->jdate($obj->date_read), 'dayhour');
546						print '</td>';
547					}
548
549					// Date close
550					if (!empty($arrayfields['t.date_close']['checked'])) {
551						print '<td>';
552						print dol_print_date($db->jdate($obj->date_close), 'dayhour');
553						print '</td>';
554					}
555
556					// Ref
557					if (!empty($arrayfields['t.ref']['checked'])) {
558						print '<td class="nowraponall">';
559						print $obj->ref;
560						print '</td>';
561					}
562
563					// Subject
564					if (!empty($arrayfields['t.subject']['checked'])) {
565						print '<td>';
566						print '<a rel="nofollow" href="javascript:viewticket(\''.$obj->track_id.'\',\''.$_SESSION['email_customer'].'\');">'.$obj->subject.'</a>';
567						print '</td>';
568					}
569
570					// Type
571					if (!empty($arrayfields['type.code']['checked'])) {
572						print '<td>';
573						print $obj->type_label;
574						print '</td>';
575					}
576
577					// Category
578					if (!empty($arrayfields['category.code']['checked'])) {
579						print '<td>';
580						print $obj->category_label;
581						print '</td>';
582					}
583
584					// Severity
585					if (!empty($arrayfields['severity.code']['checked'])) {
586						print '<td>';
587						print $obj->severity_label;
588						print '</td>';
589					}
590
591					// Progression
592					if (!empty($arrayfields['t.progress']['checked'])) {
593						print '<td>';
594						print $obj->progress;
595						print '</td>';
596					}
597
598					// Message author
599					if (!empty($arrayfields['t.fk_user_create']['checked'])) {
600						print '<td>';
601						if ($obj->fk_user_create > 0) {
602							$user_create->firstname = (!empty($obj->user_create_firstname) ? $obj->user_create_firstname : '');
603							$user_create->name = (!empty($obj->user_create_lastname) ? $obj->user_create_lastname : '');
604							$user_create->id = (!empty($obj->fk_user_create) ? $obj->fk_user_create : '');
605							print $user_create->getFullName($langs);
606						} else {
607							print $langs->trans('Email');
608						}
609						print '</td>';
610					}
611
612					// Assigned author
613					if (!empty($arrayfields['t.fk_user_assign']['checked'])) {
614						print '<td>';
615						if ($obj->fk_user_assig > 0) {
616							$user_assign->firstname = (!empty($obj->user_assign_firstname) ? $obj->user_assign_firstname : '');
617							$user_assign->lastname = (!empty($obj->user_assign_lastname) ? $obj->user_assign_lastname : '');
618							$user_assign->id = (!empty($obj->fk_user_assign) ? $obj->fk_user_assign : '');
619							print $user_assign->getFullName($langs);
620						}
621						print '</td>';
622					}
623
624					if (!empty($arrayfields['t.tms']['checked'])) {
625						print '<td>'.dol_print_date($db->jdate($obj->tms), 'dayhour').'</td>';
626					}
627
628					// Extra fields
629					if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
630						foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
631							if (!empty($arrayfields["ef.".$key]['checked'])) {
632								print '<td';
633								$align = $extrafields->getAlignFlag($key);
634								if ($align) {
635									print ' align="'.$align.'"';
636								}
637								print '>';
638								$tmpkey = 'options_'.$key;
639								print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
640								print '</td>';
641							}
642						}
643					}
644
645					// Statut
646					if (!empty($arrayfields['t.fk_statut']['checked'])) {
647						print '<td class="nowraponall">';
648						$object->fk_statut = $obj->fk_statut;
649						print $object->getLibStatut(2);
650						print '</td>';
651					}
652
653					print '<td></td>';
654
655					$i++;
656					print '</tr>';
657				}
658
659				print '</table>';
660				print '</form>';
661
662				print '<form method="post" id="form_view_ticket" name="form_view_ticket" enctype="multipart/form-data" action="'.dol_buildpath('/public/ticket/view.php', 1).'" style="display:none;">';
663				print '<input type="hidden" name="token" value="'.newToken().'">';
664				print '<input type="hidden" name="action" value="view_ticket">';
665				print '<input type="hidden" name="btn_view_ticket_list" value="1">';
666				print '<input type="hidden" name="track_id" value="">';
667				print '<input type="hidden" name="email" value="">';
668				print "</form>";
669				print '<script type="text/javascript">
670                    function viewticket(ticket_id, email) {
671                        var form = $("#form_view_ticket");
672                        form.find("input[name=\\"track_id\\"]").val(ticket_id);
673                        form.find("input[name=\\"email\\"]").val(email);
674                        form.submit();
675                    }
676                </script>';
677			}
678		}
679	} else {
680		print '<div class="error">Not Allowed<br><a href="'.$_SERVER['PHP_SELF'].'?track_id='.$object->dao->track_id.'">'.$langs->trans('Back').'</a></div>';
681	}
682} else {
683	print '<p class="center">'.$langs->trans("TicketPublicMsgViewLogIn").'</p>';
684	print '<br>';
685
686	print '<div id="form_view_ticket">';
687	print '<form method="post" name="form_view_ticketlist"  enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">';
688	print '<input type="hidden" name="token" value="'.newToken().'">';
689	print '<input type="hidden" name="action" value="view_ticketlist">';
690	//print '<input type="hidden" name="search_fk_status" value="non_closed">';
691
692	print '<p><label for="track_id" style="display: inline-block; width: 30%; "><span class="fieldrequired">'.$langs->trans("OneOfTicketTrackId").'</span></label>';
693	print '<input size="30" id="track_id" name="track_id" value="'.(GETPOST('track_id', 'alpha') ? GETPOST('track_id', 'alpha') : '').'" />';
694	print '</p>';
695
696	print '<p><label for="email" style="display: inline-block; width: 30%; "><span class="fieldrequired">'.$langs->trans('Email').'</span></label>';
697	print '<input size="30" id="email" name="email" value="'.(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $_SESSION['customer_email']).'" />';
698	print '</p>';
699
700	print '<p style="text-align: center; margin-top: 1.5em;">';
701	print '<input class="button" type="submit" name="btn_view_ticket_list" value="'.$langs->trans('ViewMyTicketList').'" />';
702	print "</p>\n";
703
704	print "</form>\n";
705	print "</div>\n";
706}
707
708print "</div>";
709
710// End of page
711htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix, $object);
712
713llxFooter('', 'public');
714
715$db->close();
716