list.php 30 KB

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