list.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. <?php
  2. /* Copyright (C) 2013-2018 Jean-François FERRY <hello@librethic.io>
  3. * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
  4. * Copyright (C) 2018 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2019-2021 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2019-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/ticket/list.php
  23. * \ingroup ticket
  24. * \brief List page for tickets
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  33. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  34. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  35. include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  36. // Load translation files required by the page
  37. $langs->loadLangs(array("ticket", "companies", "other", "projects"));
  38. // Get parameters
  39. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  40. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  41. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  42. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  43. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  44. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  45. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'ticketlist'; // To manage different context of search
  46. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  47. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  48. $id = GETPOST('id', 'int');
  49. $msg_id = GETPOST('msg_id', 'int');
  50. $socid = GETPOST('socid', 'int');
  51. $projectid = GETPOST('projectid', 'int');
  52. $project_ref = GETPOST('project_ref', 'alpha');
  53. $search_societe = GETPOST('search_societe', 'alpha');
  54. $search_fk_project = GETPOST('search_fk_project', 'int') ?GETPOST('search_fk_project', 'int') : GETPOST('projectid', 'int');
  55. $search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int'));
  56. $search_date_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int'));
  57. $search_dateread_start = dol_mktime(0, 0, 0, GETPOST('search_dateread_startmonth', 'int'), GETPOST('search_dateread_startday', 'int'), GETPOST('search_dateread_startyear', 'int'));
  58. $search_dateread_end = dol_mktime(23, 59, 59, GETPOST('search_dateread_endmonth', 'int'), GETPOST('search_dateread_endday', 'int'), GETPOST('search_dateread_endyear', 'int'));
  59. $search_dateclose_start = dol_mktime(0, 0, 0, GETPOST('search_dateclose_startmonth', 'int'), GETPOST('search_dateclose_startday', 'int'), GETPOST('search_dateclose_startyear', 'int'));
  60. $search_dateclose_end = dol_mktime(23, 59, 59, GETPOST('search_dateclose_endmonth', 'int'), GETPOST('search_dateclose_endday', 'int'), GETPOST('search_dateclose_endyear', 'int'));
  61. $mode = GETPOST('mode', 'alpha');
  62. // Load variable for pagination
  63. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  64. $sortfield = GETPOST('sortfield', 'aZ09comma');
  65. $sortorder = GETPOST('sortorder', 'aZ09comma');
  66. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  67. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  68. // If $page is not defined, or '' or -1 or if we click on clear filters
  69. $page = 0;
  70. }
  71. $offset = $limit * $page;
  72. $pageprev = $page - 1;
  73. $pagenext = $page + 1;
  74. // Initialize technical objects
  75. $object = new Ticket($db);
  76. $extrafields = new ExtraFields($db);
  77. $diroutputmassaction = $conf->ticket->dir_output.'/temp/massgeneration/'.$user->id;
  78. if ($socid > 0) {
  79. $hookmanager->initHooks(array('thirdpartyticket'));
  80. } elseif ($projectid > 0) {
  81. $hookmanager->initHooks(array('projectticket'));
  82. } else {
  83. $hookmanager->initHooks(array('ticketlist'));
  84. }
  85. // Fetch optionals attributes and labels
  86. $extrafields->fetch_name_optionals_label($object->table_element);
  87. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  88. // Default sort order (if not yet defined by previous GETPOST)
  89. if (!$sortfield) {
  90. $sortfield = "t.datec";
  91. }
  92. if (!$sortorder) {
  93. $sortorder = "DESC";
  94. }
  95. if (GETPOST('search_fk_status', 'alpha') == 'non_closed') {
  96. $_GET['search_fk_statut'][] = 'openall'; // For backward compatibility
  97. }
  98. // Initialize array of search criterias
  99. $search_all = (GETPOSTISSET("search_all") ? GETPOST("search_all", 'alpha') : GETPOST('sall'));
  100. $search = array();
  101. foreach ($object->fields as $key => $val) {
  102. if (GETPOST('search_'.$key, 'alpha') !== '') {
  103. $search[$key] = GETPOST('search_'.$key, 'alpha');
  104. }
  105. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  106. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  107. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  108. }
  109. }
  110. // List of fields to search into when doing a "search in all"
  111. $fieldstosearchall = array();
  112. foreach ($object->fields as $key => $val) {
  113. if (!empty($val['searchall'])) {
  114. $fieldstosearchall['t.'.$key] = $val['label'];
  115. }
  116. }
  117. $fieldstosearchall['s.name_alias'] = "AliasNameShort";
  118. $fieldstosearchall['s.zip'] = "Zip";
  119. $fieldstosearchall['s.town'] = "Town";
  120. // Definition of array of fields for columns
  121. $arrayfields = array();
  122. foreach ($object->fields as $key => $val) {
  123. // If $val['visible']==0, then we never show the field
  124. if (!empty($val['visible'])) {
  125. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  126. $arrayfields['t.'.$key] = array(
  127. 'label'=>$val['label'],
  128. 'checked'=>(($visible < 0) ? 0 : 1),
  129. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
  130. 'position'=>$val['position'],
  131. 'help'=> isset($val['help']) ? $val['help'] : ''
  132. );
  133. }
  134. }
  135. // Extra fields
  136. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  137. $object->fields = dol_sort_array($object->fields, 'position');
  138. $arrayfields = dol_sort_array($arrayfields, 'position');
  139. // Security check
  140. if (!$user->rights->ticket->read) {
  141. accessforbidden();
  142. }
  143. // restrict view to current user's company
  144. if ($user->socid > 0) $socid = $user->socid;
  145. // Store current page url
  146. $url_page_current = DOL_URL_ROOT.'/ticket/list.php';
  147. if ($project_ref) {
  148. $tmpproject = new Project($db);
  149. $tmpproject->fetch(0, $project_ref);
  150. $projectid = $tmpproject->id;
  151. $search_fk_project = $projectid;
  152. }
  153. $permissiontoread = $user->rights->ticket->read;
  154. $permissiontoadd = $user->rights->ticket->write;
  155. $permissiontodelete = $user->rights->ticket->delete;
  156. $error = 0;
  157. /*
  158. * Actions
  159. */
  160. if (GETPOST('cancel', 'alpha')) {
  161. $action = 'list';
  162. $massaction = '';
  163. }
  164. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'presendonclose' && $massaction != 'close') {
  165. $massaction = '';
  166. }
  167. $parameters = array();
  168. if ($socid > 0) {
  169. $parameters['socid'] = $socid;
  170. }
  171. if ($projectid > 0) {
  172. $parameters['projectid'] = $projectid;
  173. }
  174. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  175. if ($reshook < 0) {
  176. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  177. }
  178. if (empty($reshook)) {
  179. // Selection of new fields
  180. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  181. // Purge search criteria
  182. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  183. foreach ($object->fields as $key => $val) {
  184. $search[$key] = '';
  185. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  186. $search[$key.'_dtstart'] = '';
  187. $search[$key.'_dtend'] = '';
  188. }
  189. }
  190. $toselect = array();
  191. $search_array_options = array();
  192. $search_date_start = '';
  193. $search_date_end = '';
  194. $search_dateread_start = '';
  195. $search_dateread_end = '';
  196. $search_dateclose_start = '';
  197. $search_dateclose_end = '';
  198. }
  199. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  200. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  201. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  202. }
  203. // Mass actions
  204. $objectclass = 'Ticket';
  205. $objectlabel = 'Ticket';
  206. $uploaddir = $conf->ticket->dir_output;
  207. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  208. // Close records
  209. if (!$error && $massaction == 'close' && $permissiontoadd) {
  210. $objecttmp = new $objectclass($db);
  211. if (!$error) {
  212. $db->begin();
  213. $nbok = 0;
  214. foreach ($toselect as $toselectid) {
  215. $result = $objecttmp->fetch($toselectid);
  216. if ($result > 0) {
  217. $result = $objecttmp->close($user);
  218. if ($result < 0) {
  219. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  220. $error++;
  221. break;
  222. } else {
  223. $nbok++;
  224. }
  225. } else {
  226. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  227. $error++;
  228. break;
  229. }
  230. }
  231. if (!$error) {
  232. if ($nbok > 1) {
  233. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  234. } else {
  235. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  236. }
  237. $db->commit();
  238. } else {
  239. $db->rollback();
  240. }
  241. //var_dump($listofobjectthirdparties);exit;
  242. }
  243. }
  244. // Reopen records
  245. if (!$error && $massaction == 'reopen' && $permissiontoadd) {
  246. $objecttmp = new $objectclass($db);
  247. if (!$error) {
  248. $db->begin();
  249. $nbok = 0;
  250. foreach ($toselect as $toselectid) {
  251. $result = $objecttmp->fetch($toselectid);
  252. if ($result > 0) {
  253. if ($objecttmp->status == Ticket::STATUS_CLOSED || $objecttmp->status == Ticket::STATUS_CANCELED) {
  254. $result = $objecttmp->setStatut(Ticket::STATUS_ASSIGNED);
  255. if ($result < 0) {
  256. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  257. $error++;
  258. break;
  259. } else {
  260. $nbok++;
  261. }
  262. } else {
  263. $langs->load("errors");
  264. setEventMessages($langs->trans("ErrorObjectMustHaveStatusClosedToBeReOpened", $objecttmp->ref), null, 'errors');
  265. $error++;
  266. break;
  267. }
  268. } else {
  269. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  270. $error++;
  271. break;
  272. }
  273. }
  274. if (!$error) {
  275. if ($nbok > 1) {
  276. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  277. } else {
  278. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  279. }
  280. $db->commit();
  281. } else {
  282. $db->rollback();
  283. }
  284. //var_dump($listofobjectthirdparties);exit;
  285. }
  286. }
  287. }
  288. /*
  289. * View
  290. */
  291. $form = new Form($db);
  292. $formTicket = new FormTicket($db);
  293. $user_temp = new User($db);
  294. $socstatic = new Societe($db);
  295. $help_url = '';
  296. $title = $langs->trans('Tickets');
  297. $morejs = array();
  298. $morecss = array();
  299. // Build and execute select
  300. // --------------------------------------------------------------------
  301. $sql = 'SELECT ';
  302. $sql .= $object->getFieldList('t');
  303. // Add fields from extrafields
  304. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  305. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  306. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  307. }
  308. }
  309. // Add fields from hooks
  310. $parameters = array();
  311. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  312. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  313. $sql = preg_replace('/,\s*$/', '', $sql);
  314. $sqlfields = $sql; // $sql fields to remove for count total
  315. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  316. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  317. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  318. }
  319. // Add table from hooks
  320. $parameters = array();
  321. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  322. $sql .= $hookmanager->resPrint;
  323. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (t.fk_soc = s.rowid)";
  324. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  325. if ($socid > 0) {
  326. $sql .= " AND t.fk_soc = ".((int) $socid);
  327. }
  328. foreach ($search as $key => $val) {
  329. if ($key == 'fk_statut' && !empty($search['fk_statut'])) {
  330. $newarrayofstatus = array();
  331. foreach ($search['fk_statut'] as $key2 => $val2) {
  332. if (in_array($val2, array('openall', 'closeall'))) {
  333. continue;
  334. }
  335. $newarrayofstatus[] = $val2;
  336. }
  337. if ($search['fk_statut'] == 'openall' || in_array('openall', $search['fk_statut'])) {
  338. $newarrayofstatus[] = Ticket::STATUS_NOT_READ;
  339. $newarrayofstatus[] = Ticket::STATUS_READ;
  340. $newarrayofstatus[] = Ticket::STATUS_ASSIGNED;
  341. $newarrayofstatus[] = Ticket::STATUS_IN_PROGRESS;
  342. $newarrayofstatus[] = Ticket::STATUS_NEED_MORE_INFO;
  343. $newarrayofstatus[] = Ticket::STATUS_WAITING;
  344. }
  345. if ($search['fk_statut'] == 'closeall' || in_array('closeall', $search['fk_statut'])) {
  346. $newarrayofstatus[] = Ticket::STATUS_CLOSED;
  347. $newarrayofstatus[] = Ticket::STATUS_CANCELED;
  348. }
  349. if (count($newarrayofstatus)) {
  350. $sql .= natural_search($key, join(',', $newarrayofstatus), 2);
  351. }
  352. continue;
  353. } elseif ($key == 'fk_user_assign' || $key == 'fk_user_create' || $key == 'fk_project') {
  354. if ($search[$key] > 0) {
  355. $sql .= natural_search($key, $search[$key], 2);
  356. }
  357. continue;
  358. } elseif ($key == 'type_code') {
  359. $newarrayoftypecodes = is_array($search[$key]) ? $search[$key] : (!empty($search[$key]) ? explode(',', $search[$key]) : array());
  360. if (count($newarrayoftypecodes)) {
  361. $sql .= natural_search($key, join(',', $newarrayoftypecodes), 3);
  362. }
  363. continue;
  364. }
  365. $mode_search = ((!empty($object->fields[$key]) && ($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))) ? 1 : 0);
  366. // $search[$key] can be an array of values, or a string. We add filter if array not empty or if it is a string.
  367. if ((is_array($search[$key]) && !empty($search[$key])) || (!is_array($search[$key]) && $search[$key] != '')) {
  368. $sql .= natural_search($key, $search[$key], $mode_search);
  369. }
  370. }
  371. if ($search_all) {
  372. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  373. }
  374. if ($search_societe) {
  375. $sql .= natural_search('s.nom', $search_societe);
  376. }
  377. if ($search_fk_project > 0) {
  378. $sql .= natural_search('fk_project', $search_fk_project, 2);
  379. }
  380. if ($search_date_start) {
  381. $sql .= " AND t.datec >= '".$db->idate($search_date_start)."'";
  382. }
  383. if ($search_date_end) {
  384. $sql .= " AND t.datec <= '".$db->idate($search_date_end)."'";
  385. }
  386. if ($search_dateread_start) {
  387. $sql .= " AND t.date_read >= '".$db->idate($search_dateread_start)."'";
  388. }
  389. if ($search_dateread_end) {
  390. $sql .= " AND t.date_read <= '".$db->idate($search_dateread_end)."'";
  391. }
  392. if ($search_dateclose_start) {
  393. $sql .= " AND t.date_close >= '".$db->idate($search_dateclose_start)."'";
  394. }
  395. if ($search_dateclose_end) {
  396. $sql .= " AND t.date_close <= '".$db->idate($search_dateclose_end)."'";
  397. }
  398. if (!$user->socid && ($mode == "mine" || (!$user->admin && $conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY))) {
  399. $sql .= " AND (t.fk_user_assign = ".((int) $user->id);
  400. if (empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY)) {
  401. $sql .= " OR t.fk_user_create = ".((int) $user->id);
  402. }
  403. $sql .= ")";
  404. }
  405. // Add where from extra fields
  406. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  407. // Add where from hooks
  408. $parameters = array();
  409. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  410. $sql .= $hookmanager->resPrint;
  411. // Count total nb of records
  412. $nbtotalofrecords = '';
  413. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  414. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  415. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  416. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  417. $resql = $db->query($sqlforcount);
  418. if ($resql) {
  419. $objforcount = $db->fetch_object($resql);
  420. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  421. } else {
  422. dol_print_error($db);
  423. }
  424. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  425. $page = 0;
  426. $offset = 0;
  427. }
  428. $db->free($resql);
  429. }
  430. // Complete request and execute it with limit
  431. $sql .= $db->order($sortfield, $sortorder);
  432. if ($limit) {
  433. $sql .= $db->plimit($limit + 1, $offset);
  434. }
  435. $resql = $db->query($sql);
  436. if (!$resql) {
  437. dol_print_error($db);
  438. exit;
  439. }
  440. $num = $db->num_rows($resql);
  441. // Direct jump if only one record found
  442. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  443. $obj = $db->fetch_object($resql);
  444. $id = $obj->rowid;
  445. header("Location: ".DOL_URL_ROOT.'/ticket/card.php?id='.$id);
  446. exit;
  447. }
  448. // Output page
  449. // --------------------------------------------------------------------
  450. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
  451. if ($socid && !$projectid && !$project_ref && $user->hasRight('societe', 'lire')) {
  452. $socstat = new Societe($db);
  453. $res = $socstat->fetch($socid);
  454. if ($res > 0) {
  455. $tmpobject = $object;
  456. $object = $socstat; // $object must be of type Societe when calling societe_prepare_head
  457. $head = societe_prepare_head($socstat);
  458. $object = $tmpobject;
  459. print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), -1, 'company');
  460. dol_banner_tab($socstat, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  461. print '<div class="fichecenter">';
  462. print '<div class="underbanner clearboth"></div>';
  463. print '<table class="border centpercent tableforfield">';
  464. // Type Prospect/Customer/Supplier
  465. print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
  466. print $socstat->getTypeUrl(1);
  467. print '</td></tr>';
  468. // Customer code
  469. if ($socstat->client && !empty($socstat->code_client)) {
  470. print '<tr><td class="titlefield">';
  471. print $langs->trans('CustomerCode').'</td><td>';
  472. print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_client));
  473. $tmpcheck = $socstat->check_codeclient();
  474. if ($tmpcheck != 0 && $tmpcheck != -5) {
  475. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  476. }
  477. print '</td>';
  478. print '</tr>';
  479. }
  480. // Supplier code
  481. if ($socstat->fournisseur && !empty($socstat->code_fournisseur)) {
  482. print '<tr><td class="titlefield">';
  483. print $langs->trans('SupplierCode').'</td><td>';
  484. print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_fournisseur));
  485. $tmpcheck = $socstat->check_codefournisseur();
  486. if ($tmpcheck != 0 && $tmpcheck != -5) {
  487. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  488. }
  489. print '</td>';
  490. print '</tr>';
  491. }
  492. print '</table>';
  493. print '</div>';
  494. print dol_get_fiche_end();
  495. }
  496. }
  497. if ($projectid > 0 || $project_ref) {
  498. $projectstat = new Project($db);
  499. if ($projectstat->fetch($projectid, $project_ref) > 0) {
  500. $projectid = $projectstat->id;
  501. $projectstat->fetch_thirdparty();
  502. $savobject = $object;
  503. $object = $projectstat;
  504. // To verify role of users
  505. //$userAccess = $object->restrictedProjectArea($user,'read');
  506. $userWrite = $projectstat->restrictedProjectArea($user, 'write');
  507. //$userDelete = $object->restrictedProjectArea($user,'delete');
  508. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  509. $head = project_prepare_head($projectstat);
  510. print dol_get_fiche_head($head, 'ticket', $langs->trans("Project"), -1, ($projectstat->public ? 'projectpub' : 'project'));
  511. // Project card
  512. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  513. $morehtmlref = '<div class="refidno">';
  514. // Title
  515. $morehtmlref .= $object->title;
  516. // Thirdparty
  517. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  518. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
  519. }
  520. $morehtmlref .= '</div>';
  521. // Define a complementary filter for search of next/prev ref.
  522. if (empty($user->rights->projet->all->lire)) {
  523. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  524. $object->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  525. }
  526. dol_banner_tab($object, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  527. print '<div class="fichecenter">';
  528. print '<div class="underbanner clearboth"></div>';
  529. print '<table class="border tableforfield centpercent">';
  530. // Visibility
  531. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  532. if ($projectstat->public) {
  533. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  534. print $langs->trans('SharedProject');
  535. } else {
  536. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  537. print $langs->trans('PrivateProject');
  538. }
  539. print '</td></tr>';
  540. print "</table>";
  541. print '</div>';
  542. print dol_get_fiche_end();
  543. $object = $savobject;
  544. } else {
  545. print "ErrorRecordNotFound";
  546. }
  547. }
  548. $arrayofselected = is_array($toselect) ? $toselect : array();
  549. $param = '';
  550. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  551. $param .= '&contextpage='.urlencode($contextpage);
  552. }
  553. if ($limit > 0 && $limit != $conf->liste_limit) {
  554. $param .= '&limit='.urlencode($limit);
  555. }
  556. foreach ($search as $key => $val) {
  557. if (is_array($search[$key])) {
  558. foreach ($search[$key] as $skey) {
  559. if ($skey != '') {
  560. $param .= (!empty($val)) ? '&search_'.$key.'[]='.urlencode($skey) : "";
  561. }
  562. }
  563. } elseif ($search[$key] != '') {
  564. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  565. }
  566. }
  567. if ($optioncss != '') {
  568. $param .= '&optioncss='.urlencode($optioncss);
  569. }
  570. // Add $param from extra fields
  571. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  572. // Add $param from hooks
  573. $parameters = array();
  574. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  575. $param .= $hookmanager->resPrint;
  576. if ($socid > 0) {
  577. $param .= '&socid='.urlencode($socid);
  578. }
  579. if ($search_societe) {
  580. $param .= '&search_societe='.urlencode($search_societe);
  581. }
  582. if ($projectid > 0) {
  583. $param .= '&projectid='.urlencode($projectid);
  584. }
  585. if ($search_date_start) {
  586. $tmparray = dol_getdate($search_date_start);
  587. $param .= '&search_date_startday='.urlencode($tmparray['mday']);
  588. $param .= '&search_date_startmonth='.urlencode($tmparray['mon']);
  589. $param .= '&search_date_startyear='.urlencode($tmparray['year']);
  590. }
  591. if ($search_date_end) {
  592. $tmparray = dol_getdate($search_date_end);
  593. $param .= '&search_date_endday='.urlencode($tmparray['mday']);
  594. $param .= '&search_date_endmonth='.urlencode($tmparray['mon']);
  595. $param .= '&search_date_endyear='.urlencode($tmparray['year']);
  596. }
  597. if ($search_dateread_start) {
  598. $tmparray = dol_getdate($search_dateread_start);
  599. $param .= '&search_dateread_startday='.urlencode($tmparray['mday']);
  600. $param .= '&search_dateread_startmonth='.urlencode($tmparray['mon']);
  601. $param .= '&search_dateread_startyear='.urlencode($tmparray['year']);
  602. }
  603. if ($search_dateread_end) {
  604. $tmparray = dol_getdate($search_dateread_end);
  605. $param .= '&search_dateread_endday='.urlencode($tmparray['mday']);
  606. $param .= '&search_dateread_endmonth='.urlencode($tmparray['mon']);
  607. $param .= '&search_dateread_endyear='.urlencode($tmparray['year']);
  608. }
  609. if ($search_dateclose_start) {
  610. $tmparray = dol_getdate($search_dateclose_start);
  611. $param .= '&search_dateclose_startday='.urlencode($tmparray['mday']);
  612. $param .= '&search_dateclose_startmonth='.urlencode($tmparray['mon']);
  613. $param .= '&search_dateclose_startyear='.urlencode($tmparray['year']);
  614. }
  615. if ($search_dateclose_end) {
  616. $tmparray = dol_getdate($search_dateclose_end);
  617. $param .= '&search_date_endday='.urlencode($tmparray['mday']);
  618. $param .= '&search_date_endmonth='.urlencode($tmparray['mon']);
  619. $param .= '&search_date_endyear='.urlencode($tmparray['year']);
  620. }
  621. // List of mass actions available
  622. $arrayofmassactions = array(
  623. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  624. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  625. );
  626. if ($permissiontoadd) {
  627. $arrayofmassactions['presendonclose'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Close");
  628. $arrayofmassactions['reopen'] = img_picto('', 'folder-open', 'class="pictofixedwidth"').$langs->trans("ReOpen");
  629. }
  630. if ($permissiontodelete) {
  631. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  632. }
  633. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  634. $arrayofmassactions = array();
  635. }
  636. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  637. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  638. if ($optioncss != '') {
  639. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  640. }
  641. print '<input type="hidden" name="token" value="'.newToken().'">';
  642. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  643. print '<input type="hidden" name="action" value="list">';
  644. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  645. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  646. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  647. print '<input type="hidden" name="mode" value="'.$mode.'" >';
  648. if ($socid) {
  649. print '<input type="hidden" name="socid" value="'.$socid.'" >';
  650. }
  651. if ($projectid) {
  652. print '<input type="hidden" name="projectid" value="'.$projectid.'" >';
  653. }
  654. $url = DOL_URL_ROOT.'/ticket/card.php?action=create'.($socid ? '&socid='.$socid : '').($projectid ? '&origin=projet_project&originid='.$projectid : '');
  655. if (!empty($socid)) {
  656. $url .= '&socid='.$socid;
  657. }
  658. $newcardbutton = dolGetButtonTitle($langs->trans('NewTicket'), '', 'fa fa-plus-circle', $url, '', $user->rights->ticket->write);
  659. $picto = 'ticket';
  660. if ($socid > 0) {
  661. $picto = '';
  662. }
  663. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  664. if ($mode == 'mine') {
  665. print '<div class="opacitymedium">'.$langs->trans('TicketAssignedToMeInfos').'</div><br>';
  666. }
  667. // Add code for pre mass action (confirmation or email presend form)
  668. $topicmail = "SendTicketRef";
  669. $modelmail = "ticket";
  670. $objecttmp = new Ticket($db);
  671. $trackid = 'tic'.$object->id;
  672. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  673. // confirm auto send on close
  674. if ($massaction == 'presendonclose') {
  675. $hidden_form = array([
  676. "type" => "hidden",
  677. "name" => "massaction",
  678. "value" => "close"
  679. ]);
  680. $selectedchoice = (!empty($conf->global->TICKET_NOTIFY_AT_CLOSING)) ? "yes" : "no";
  681. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassTicketClosingSendEmail"), $langs->trans("ConfirmMassTicketClosingSendEmailQuestion"), 'confirm_send_close', $hidden_form, $selectedchoice, 0, 200, 500, 1);
  682. }
  683. if ($search_all) {
  684. $setupstring = '';
  685. foreach ($fieldstosearchall as $key => $val) {
  686. $fieldstosearchall[$key] = $langs->trans($val);
  687. $setupstring .= $key."=".$val.";";
  688. }
  689. print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  690. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  691. }
  692. $moreforfilter = '';
  693. /*$moreforfilter.='<div class="divsearchfield">';
  694. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  695. $moreforfilter.= '</div>';*/
  696. $parameters = array();
  697. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  698. if (empty($reshook)) {
  699. $moreforfilter .= $hookmanager->resPrint;
  700. } else {
  701. $moreforfilter = $hookmanager->resPrint;
  702. }
  703. if (!empty($moreforfilter)) {
  704. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  705. print $moreforfilter;
  706. print '</div>';
  707. }
  708. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  709. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  710. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  711. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  712. print '<div class="div-table-responsive-inside">';
  713. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  714. // Fields title search
  715. // --------------------------------------------------------------------
  716. print '<tr class="liste_titre">';
  717. // Action column
  718. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  719. print '<td class="liste_titre maxwidthsearch">';
  720. $searchpicto = $form->showFilterButtons('left');
  721. print $searchpicto;
  722. print '</td>';
  723. }
  724. foreach ($object->fields as $key => $val) {
  725. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  726. if ($key == 'fk_statut') {
  727. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  728. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  729. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  730. } elseif (in_array($val['type'], array('timestamp'))) {
  731. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  732. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  733. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  734. }
  735. if (!empty($arrayfields['t.'.$key]['checked'])) {
  736. if ($key == 'progress') {
  737. print '<td class="liste_titre right'.($cssforfield ? ' '.$cssforfield : '').'">';
  738. print '<input type="text" class="flat maxwidth50" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
  739. print '</td>';
  740. } elseif ($key == 'type_code') {
  741. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  742. $formTicket->selectTypesTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key.'', '', 2, 1, 1, 0, (!empty($val['css']) ? $val['css'] : 'maxwidth150'), 1);
  743. print '</td>';
  744. } elseif ($key == 'category_code') {
  745. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  746. $formTicket->selectGroupTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key.'', '', 2, 1, 1, 0, (!empty($val['css']) ? $val['css'] : 'maxwidth150'));
  747. print '</td>';
  748. } elseif ($key == 'severity_code') {
  749. print '<td class="liste_titre center'.($cssforfield ? ' '.$cssforfield : '').'">';
  750. $formTicket->selectSeveritiesTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key.'', '', 2, 1, 1, 0, (!empty($val['css']) ? $val['css'] : 'maxwidth150'));
  751. print '</td>';
  752. } elseif ($key == 'fk_user_assign' || $key == 'fk_user_create') {
  753. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  754. print $form->select_dolusers((empty($search[$key]) ? '' : $search[$key]), 'search_'.$key, 1, null, 0, '', '', '0', 0, 0, '', 0, '', (!empty($val['css']) ? $val['css'] : 'maxwidth100'));
  755. print '</td>';
  756. } elseif ($key == 'fk_statut') {
  757. $arrayofstatus = array();
  758. $arrayofstatus['openall'] = '-- '.$langs->trans('OpenAll').' --';
  759. foreach ($object->statuts_short as $key2 => $val2) {
  760. if ($key2 == Ticket::STATUS_CLOSED) {
  761. $arrayofstatus['closeall'] = '-- '.$langs->trans('ClosedAll').' --';
  762. }
  763. $arrayofstatus[$key2] = $val2;
  764. }
  765. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  766. //var_dump($arrayofstatus);
  767. //var_dump($search['fk_statut']);
  768. //var_dump(array_values($search[$key]));
  769. $selectedarray = null;
  770. if (!empty($search[$key])) {
  771. $selectedarray = array_values($search[$key]);
  772. }
  773. print Form::multiselectarray('search_fk_statut', $arrayofstatus, $selectedarray, 0, 0, 'minwidth100imp maxwidth150', 1, 0, '', '', '');
  774. print '</td>';
  775. } elseif ($key == "fk_soc") {
  776. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'"><input type="text" class="flat maxwidth75" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
  777. } elseif ($key == "datec" || $key == 'date_read' || $key == 'date_close') {
  778. print '<td class="liste_titre center">';
  779. print '<div class="nowrap">';
  780. switch ($key) {
  781. case 'datec':
  782. print $form->selectDate($search_date_start ?: -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  783. break;
  784. case 'date_read':
  785. print $form->selectDate($search_dateread_start ?: -1, 'search_dateread_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  786. break;
  787. case 'date_close':
  788. print $form->selectDate($search_dateclose_start ?: -1, 'search_dateclose_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  789. }
  790. print '</div>';
  791. print '<div class="nowrap">';
  792. switch ($key) {
  793. case 'datec':
  794. print $form->selectDate($search_date_end ?: -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  795. break;
  796. case 'date_read':
  797. print $form->selectDate($search_dateread_end ?: -1, 'search_dateread_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  798. break;
  799. case 'date_close':
  800. print $form->selectDate($search_dateclose_end ?: -1, 'search_dateclose_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  801. }
  802. print '</div>';
  803. print '</td>';
  804. } else {
  805. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  806. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  807. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  808. } elseif (strpos($val['type'], 'integer:') === 0) {
  809. print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
  810. } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
  811. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
  812. }
  813. print '</td>';
  814. }
  815. }
  816. }
  817. // Extra fields
  818. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  819. // Fields from hook
  820. $parameters = array('arrayfields'=>$arrayfields);
  821. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  822. print $hookmanager->resPrint;
  823. // Action column
  824. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  825. print '<td class="liste_titre maxwidthsearch">';
  826. $searchpicto = $form->showFilterButtons();
  827. print $searchpicto;
  828. print '</td>';
  829. }
  830. print '</tr>'."\n";
  831. // Fields title label
  832. // --------------------------------------------------------------------
  833. print '<tr class="liste_titre">';
  834. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  835. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  836. }
  837. foreach ($object->fields as $key => $val) {
  838. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  839. if ($key == 'fk_statut' || $key == 'severity_code') {
  840. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  841. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  842. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  843. } elseif (in_array($val['type'], array('timestamp'))) {
  844. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  845. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  846. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  847. }
  848. if (!empty($arrayfields['t.'.$key]['checked'])) {
  849. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  850. }
  851. }
  852. $totalarray = array(
  853. 'nbfield' => 0,
  854. );
  855. // Extra fields
  856. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  857. // Hook fields
  858. $parameters = array(
  859. 'arrayfields' => $arrayfields,
  860. 'param' => $param,
  861. 'sortfield' => $sortfield,
  862. 'sortorder' => $sortorder,
  863. 'totalarray' => &$totalarray,
  864. );
  865. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  866. print $hookmanager->resPrint;
  867. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  868. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  869. }
  870. print '</tr>'."\n";
  871. // Detect if we need a fetch on each output line
  872. $needToFetchEachLine = 0;
  873. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  874. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  875. if (preg_match('/\$object/', $val)) {
  876. $needToFetchEachLine++; // There is at least one compute field that use $object
  877. }
  878. }
  879. }
  880. // Loop on record
  881. // --------------------------------------------------------------------
  882. $i = 0;
  883. $totalarray = array();
  884. $totalarray['nbfield'] = 0;
  885. $now = dol_now();
  886. $cacheofoutputfield = array();
  887. while ($i < ($limit ? min($num, $limit) : $num)) {
  888. $obj = $db->fetch_object($resql);
  889. if (empty($obj)) {
  890. break; // Should not happen
  891. }
  892. // Store properties in $object
  893. $object->setVarsFromFetchObj($obj);
  894. $object->status = $object->fk_statut; // fk_statut is deprecated
  895. // Show here line of result
  896. print '<tr class="oddeven">';
  897. // Action column
  898. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  899. print '<td class="nowrap center">';
  900. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  901. $selected = 0;
  902. if (in_array($obj->rowid, $arrayofselected)) {
  903. $selected = 1;
  904. }
  905. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  906. }
  907. print '</td>';
  908. }
  909. foreach ($object->fields as $key => $val) {
  910. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  911. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  912. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  913. }
  914. if (in_array($val['type'], array('timestamp'))) {
  915. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  916. }
  917. if (in_array($key, array('ref', 'fk_project'))) {
  918. $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
  919. }
  920. if ($key == 'fk_statut' || $key == 'severity_code') {
  921. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  922. }
  923. if (!empty($arrayfields['t.'.$key]['checked'])) {
  924. print '<td';
  925. if ($cssforfield || (array_key_exists('css', $val) && $val['css'])) {
  926. print ' class="';
  927. }
  928. print $cssforfield;
  929. if ($cssforfield && array_key_exists('css', $val) && $val['css']) {
  930. print ' ';
  931. }
  932. if (array_key_exists('css', $val)) {
  933. print $val['css'];
  934. }
  935. if ($cssforfield || (array_key_exists('css', $val) && $val['css'])) {
  936. print '"';
  937. }
  938. print '>';
  939. if ($key == 'fk_statut') {
  940. print $object->getLibStatut(5);
  941. } elseif ($key == 'subject') {
  942. $s = $obj->subject;
  943. print '<span title="'.dol_escape_htmltag($s).'">';
  944. print dol_escape_htmltag($s);
  945. print '</span>';
  946. } elseif ($key == 'type_code') {
  947. $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code);
  948. print '<span title="'.dol_escape_htmltag($s).'">';
  949. print $s;
  950. print '</span>';
  951. } elseif ($key == 'category_code') {
  952. $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code);
  953. print '<span title="'.dol_escape_htmltag($s).'">';
  954. print $s;
  955. print '</span>';
  956. } elseif ($key == 'severity_code') {
  957. $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code);
  958. print '<span title="'.dol_escape_htmltag($s).'">';
  959. print $s;
  960. print '</span>';
  961. } elseif ($key == 'tms') {
  962. print dol_print_date($db->jdate($obj->$key), 'dayhour', 'tzuser');
  963. } elseif ($key == 'fk_user_create') {
  964. if ($object->fk_user_create > 0) {
  965. if (isset($conf->cache['user'][$object->fk_user_create])) {
  966. $user_temp = $conf->cache['user'][$object->fk_user_create];
  967. } else {
  968. $user_temp = new User($db);
  969. $user_temp->fetch($object->fk_user_create);
  970. $conf->cache['user'][$object->fk_user_create] = $user_temp;
  971. }
  972. print $user_temp->getNomUrl(-1);
  973. }
  974. } elseif ($key == 'fk_user_assign') {
  975. if ($object->fk_user_assign > 0) {
  976. if (isset($conf->cache['user'][$object->fk_user_assign])) {
  977. $user_temp = $conf->cache['user'][$object->fk_user_assign];
  978. } else {
  979. $user_temp = new User($db);
  980. $user_temp->fetch($object->fk_user_assign);
  981. $conf->cache['user'][$object->fk_user_assign] = $user_temp;
  982. }
  983. print $user_temp->getNomUrl(-1);
  984. }
  985. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  986. print $object->showOutputField($val, $key, $db->jdate($obj->$key), '');
  987. } elseif ($key == 'ref') {
  988. print $object->showOutputField($val, $key, $obj->$key, '');
  989. // display a warning on untreated tickets
  990. $is_open = ($object->status != Ticket::STATUS_CLOSED && $object->status != Ticket::STATUS_CANCELED );
  991. $should_show_warning = (!empty($conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE) || !empty($conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE));
  992. if ($is_open && $should_show_warning) {
  993. $date_last_msg_sent = (int) $object->date_last_msg_sent;
  994. $hour_diff = ($now - $date_last_msg_sent) / 3600 ;
  995. if (!empty($conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE && $date_last_msg_sent == 0)) {
  996. $creation_date = $object->datec;
  997. $hour_diff_creation = ($now - $creation_date) / 3600 ;
  998. if ($hour_diff_creation > $conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE) {
  999. print " " . img_picto($langs->trans('Late') . ' : ' . $langs->trans('TicketsDelayForFirstResponseTooLong', $conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE), 'warning', 'style="color: red;"', false, 0, 0, '', '');
  1000. }
  1001. } elseif (!empty($conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE) && $hour_diff > $conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE) {
  1002. print " " . img_picto($langs->trans('Late') . ' : ' . $langs->trans('TicketsDelayFromLastResponseTooLong', $conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE), 'warning');
  1003. }
  1004. }
  1005. } else { // Example: key=fk_soc, obj->key=123 val=array('type'=>'integer', ...
  1006. $tmp = explode(':', $val['type']);
  1007. if ($tmp[0] == 'integer' && !empty($tmp[1]) && class_exists($tmp[1])) {
  1008. // It is a type of an foreign field. We will try to reduce the number of fetch that the showOutputField is making.
  1009. //var_dump('eeee-'.$key.'-'.$obj->$key.'-'.$val['type']);
  1010. if ($key && $obj->$key && $val['type'] && array_key_exists($key.'-'.$obj->$key.'-'.$val['type'], $cacheofoutputfield)) {
  1011. $result = $cacheofoutputfield[$key.'-'.$obj->$key.'-'.$val['type']];
  1012. } else {
  1013. $result = $object->showOutputField($val, $key, $obj->$key, '');
  1014. $cacheofoutputfield[$key.'-'.$obj->$key.'-'.$val['type']] = $result;
  1015. }
  1016. } else {
  1017. $result = $object->showOutputField($val, $key, $obj->$key, '');
  1018. }
  1019. print $result;
  1020. }
  1021. print '</td>';
  1022. if (!$i) {
  1023. $totalarray['nbfield']++;
  1024. }
  1025. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  1026. if (!$i) {
  1027. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  1028. }
  1029. if (!isset($totalarray['val'])) {
  1030. $totalarray['val'] = array();
  1031. }
  1032. if (!isset($totalarray['val']['t.'.$key])) {
  1033. $totalarray['val']['t.'.$key] = 0;
  1034. }
  1035. $totalarray['val']['t.'.$key] += $object->$key;
  1036. }
  1037. }
  1038. }
  1039. // Extra fields
  1040. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1041. // Fields from hook
  1042. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1043. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1044. print $hookmanager->resPrint;
  1045. // Action column
  1046. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1047. print '<td class="nowrap center">';
  1048. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1049. $selected = 0;
  1050. if (in_array($obj->rowid, $arrayofselected)) {
  1051. $selected = 1;
  1052. }
  1053. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1054. }
  1055. print '</td>';
  1056. }
  1057. if (!$i) {
  1058. $totalarray['nbfield']++;
  1059. }
  1060. print '</tr>'."\n";
  1061. $i++;
  1062. }
  1063. // Show total line
  1064. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1065. // If no record found
  1066. if ($num == 0) {
  1067. $colspan = 1;
  1068. foreach ($arrayfields as $key => $val) {
  1069. if (!empty($val['checked'])) {
  1070. $colspan++;
  1071. }
  1072. }
  1073. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1074. }
  1075. $db->free($resql);
  1076. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1077. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  1078. print $hookmanager->resPrint;
  1079. print '</table>'."\n";
  1080. print '</div>'."\n";
  1081. print '</div>'."\n"; // end div-responsive-inside
  1082. print '</form>'."\n";
  1083. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  1084. $hidegeneratedfilelistifempty = 1;
  1085. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1086. $hidegeneratedfilelistifempty = 0;
  1087. }
  1088. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  1089. $formfile = new FormFile($db);
  1090. // Show list of available documents
  1091. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1092. $urlsource .= str_replace('&amp;', '&', $param);
  1093. $filedir = $diroutputmassaction;
  1094. $genallowed = $permissiontoread;
  1095. $delallowed = $permissiontoadd;
  1096. print $formfile->showdocuments('massfilesarea_ticket', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1097. }
  1098. // End of page
  1099. llxFooter();
  1100. $db->close();