list.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  32. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  33. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  34. include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("ticket", "companies", "other", "projects"));
  37. // Get parameters
  38. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  39. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  40. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  41. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  42. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  43. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  44. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'ticketlist'; // To manage different context of search
  45. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  46. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  47. $id = GETPOST('id', 'int');
  48. $msg_id = GETPOST('msg_id', 'int');
  49. $socid = GETPOST('socid', 'int');
  50. $projectid = GETPOST('projectid', 'int');
  51. $project_ref = GETPOST('project_ref', 'alpha');
  52. $search_societe = GETPOST('search_societe', 'alpha');
  53. $search_fk_project = GETPOST('search_fk_project', 'int') ?GETPOST('search_fk_project', 'int') : GETPOST('projectid', 'int');
  54. $search_fk_status = GETPOST('search_fk_statut', 'array');
  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, 1, '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('TicketList');
  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. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  315. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  316. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  317. }
  318. // Add table from hooks
  319. $parameters = array();
  320. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  321. $sql .= $hookmanager->resPrint;
  322. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (t.fk_soc = s.rowid)";
  323. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  324. if ($socid > 0) {
  325. $sql .= " AND t.fk_soc = ".((int) $socid);
  326. }
  327. foreach ($search as $key => $val) {
  328. if ($key == 'fk_statut' && !empty($search['fk_statut'])) {
  329. $newarrayofstatus = array();
  330. foreach ($search['fk_statut'] as $key2 => $val2) {
  331. if (in_array($val2, array('openall', 'closeall'))) {
  332. continue;
  333. }
  334. $newarrayofstatus[] = $val2;
  335. }
  336. if ($search['fk_statut'] == 'openall' || in_array('openall', $search['fk_statut'])) {
  337. $newarrayofstatus[] = Ticket::STATUS_NOT_READ;
  338. $newarrayofstatus[] = Ticket::STATUS_READ;
  339. $newarrayofstatus[] = Ticket::STATUS_ASSIGNED;
  340. $newarrayofstatus[] = Ticket::STATUS_IN_PROGRESS;
  341. $newarrayofstatus[] = Ticket::STATUS_NEED_MORE_INFO;
  342. $newarrayofstatus[] = Ticket::STATUS_WAITING;
  343. }
  344. if ($search['fk_statut'] == 'closeall' || in_array('closeall', $search['fk_statut'])) {
  345. $newarrayofstatus[] = Ticket::STATUS_CLOSED;
  346. $newarrayofstatus[] = Ticket::STATUS_CANCELED;
  347. }
  348. if (count($newarrayofstatus)) {
  349. $sql .= natural_search($key, join(',', $newarrayofstatus), 2);
  350. }
  351. continue;
  352. } elseif ($key == 'fk_user_assign' || $key == 'fk_user_create' || $key == 'fk_project') {
  353. if ($search[$key] > 0) {
  354. $sql .= natural_search($key, $search[$key], 2);
  355. }
  356. continue;
  357. }
  358. $mode_search = ((!empty($object->fields[$key]) && ($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))) ? 1 : 0);
  359. // $search[$key] can be an array of values, or a string. We add filter if array not empty or if it is a string.
  360. if ((is_array($search[$key]) && !empty($search[$key])) || (!is_array($search[$key]) && $search[$key] != '')) {
  361. $sql .= natural_search($key, $search[$key], $mode_search);
  362. }
  363. }
  364. if ($search_all) {
  365. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  366. }
  367. if ($search_societe) {
  368. $sql .= natural_search('s.nom', $search_societe);
  369. }
  370. if ($search_fk_project > 0) {
  371. $sql .= natural_search('fk_project', $search_fk_project, 2);
  372. }
  373. if ($search_date_start) {
  374. $sql .= " AND t.datec >= '".$db->idate($search_date_start)."'";
  375. }
  376. if ($search_date_end) {
  377. $sql .= " AND t.datec <= '".$db->idate($search_date_end)."'";
  378. }
  379. if ($search_dateread_start) {
  380. $sql .= " AND t.date_read >= '".$db->idate($search_dateread_start)."'";
  381. }
  382. if ($search_dateread_end) {
  383. $sql .= " AND t.date_read <= '".$db->idate($search_dateread_end)."'";
  384. }
  385. if ($search_dateclose_start) {
  386. $sql .= " AND t.date_close >= '".$db->idate($search_dateclose_start)."'";
  387. }
  388. if ($search_dateclose_end) {
  389. $sql .= " AND t.date_close <= '".$db->idate($search_dateclose_end)."'";
  390. }
  391. if (!$user->socid && ($mode == "mine" || (!$user->admin && $conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY))) {
  392. $sql .= " AND (t.fk_user_assign = ".((int) $user->id);
  393. if (empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY)) {
  394. $sql .= " OR t.fk_user_create = ".((int) $user->id);
  395. }
  396. $sql .= ")";
  397. }
  398. // Add where from extra fields
  399. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  400. // Add where from hooks
  401. $parameters = array();
  402. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  403. $sql .= $hookmanager->resPrint;
  404. // Count total nb of records
  405. $nbtotalofrecords = '';
  406. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  407. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  408. $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
  409. $resql = $db->query($sqlforcount);
  410. $objforcount = $db->fetch_object($resql);
  411. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  412. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  413. $page = 0;
  414. $offset = 0;
  415. }
  416. $db->free($resql);
  417. }
  418. // Complete request and execute it with limit
  419. $sql .= $db->order($sortfield, $sortorder);
  420. if ($limit) {
  421. $sql .= $db->plimit($limit + 1, $offset);
  422. }
  423. $resql = $db->query($sql);
  424. if (!$resql) {
  425. dol_print_error($db);
  426. exit;
  427. }
  428. $num = $db->num_rows($resql);
  429. // Direct jump if only one record found
  430. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  431. $obj = $db->fetch_object($resql);
  432. $id = $obj->rowid;
  433. header("Location: ".DOL_URL_ROOT.'/ticket/card.php?id='.$id);
  434. exit;
  435. }
  436. // Output page
  437. // --------------------------------------------------------------------
  438. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
  439. if ($socid && !$projectid && !$project_ref && $user->rights->societe->lire) {
  440. $socstat = new Societe($db);
  441. $res = $socstat->fetch($socid);
  442. if ($res > 0) {
  443. $tmpobject = $object;
  444. $object = $socstat; // $object must be of type Societe when calling societe_prepare_head
  445. $head = societe_prepare_head($socstat);
  446. $object = $tmpobject;
  447. print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), -1, 'company');
  448. dol_banner_tab($socstat, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  449. print '<div class="fichecenter">';
  450. print '<div class="underbanner clearboth"></div>';
  451. print '<table class="border centpercent tableforfield">';
  452. // Type Prospect/Customer/Supplier
  453. print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
  454. print $socstat->getTypeUrl(1);
  455. print '</td></tr>';
  456. // Customer code
  457. if ($socstat->client && !empty($socstat->code_client)) {
  458. print '<tr><td class="titlefield">';
  459. print $langs->trans('CustomerCode').'</td><td>';
  460. print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_client));
  461. $tmpcheck = $socstat->check_codeclient();
  462. if ($tmpcheck != 0 && $tmpcheck != -5) {
  463. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  464. }
  465. print '</td>';
  466. print '</tr>';
  467. }
  468. // Supplier code
  469. if ($socstat->fournisseur && !empty($socstat->code_fournisseur)) {
  470. print '<tr><td class="titlefield">';
  471. print $langs->trans('SupplierCode').'</td><td>';
  472. print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_fournisseur));
  473. $tmpcheck = $socstat->check_codefournisseur();
  474. if ($tmpcheck != 0 && $tmpcheck != -5) {
  475. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  476. }
  477. print '</td>';
  478. print '</tr>';
  479. }
  480. print '</table>';
  481. print '</div>';
  482. print dol_get_fiche_end();
  483. }
  484. }
  485. if ($projectid > 0 || $project_ref) {
  486. $projectstat = new Project($db);
  487. if ($projectstat->fetch($projectid, $project_ref) > 0) {
  488. $projectid = $projectstat->id;
  489. $projectstat->fetch_thirdparty();
  490. $savobject = $object;
  491. $object = $projectstat;
  492. // To verify role of users
  493. //$userAccess = $object->restrictedProjectArea($user,'read');
  494. $userWrite = $projectstat->restrictedProjectArea($user, 'write');
  495. //$userDelete = $object->restrictedProjectArea($user,'delete');
  496. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  497. $head = project_prepare_head($projectstat);
  498. print dol_get_fiche_head($head, 'ticket', $langs->trans("Project"), -1, ($projectstat->public ? 'projectpub' : 'project'));
  499. // Project card
  500. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  501. $morehtmlref = '<div class="refidno">';
  502. // Title
  503. $morehtmlref .= $object->title;
  504. // Thirdparty
  505. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  506. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'project');
  507. }
  508. $morehtmlref .= '</div>';
  509. // Define a complementary filter for search of next/prev ref.
  510. if (empty($user->rights->projet->all->lire)) {
  511. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  512. $object->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  513. }
  514. dol_banner_tab($object, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  515. print '<div class="fichecenter">';
  516. print '<div class="underbanner clearboth"></div>';
  517. print '<table class="border tableforfield" width="100%">';
  518. // Visibility
  519. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  520. if ($projectstat->public) {
  521. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  522. print $langs->trans('SharedProject');
  523. } else {
  524. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  525. print $langs->trans('PrivateProject');
  526. }
  527. print '</td></tr>';
  528. print "</table>";
  529. print '</div>';
  530. print dol_get_fiche_end();
  531. $object = $savobject;
  532. } else {
  533. print "ErrorRecordNotFound";
  534. }
  535. }
  536. $arrayofselected = is_array($toselect) ? $toselect : array();
  537. $param = '';
  538. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  539. $param .= '&contextpage='.urlencode($contextpage);
  540. }
  541. if ($limit > 0 && $limit != $conf->liste_limit) {
  542. $param .= '&limit='.urlencode($limit);
  543. }
  544. foreach ($search as $key => $val) {
  545. if (is_array($val) && count($val)) {
  546. foreach ($val as $skey) {
  547. if ($skey != '') {
  548. $param .= (!empty($val)) ? '&search_'.$key.'[]='.urlencode($skey) : "";
  549. }
  550. }
  551. } elseif ($search[$key] != '') {
  552. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  553. }
  554. }
  555. if ($optioncss != '') {
  556. $param .= '&optioncss='.urlencode($optioncss);
  557. }
  558. // Add $param from extra fields
  559. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  560. // Add $param from hooks
  561. $parameters = array();
  562. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  563. $param .= $hookmanager->resPrint;
  564. if ($socid > 0) {
  565. $param .= '&socid='.urlencode($socid);
  566. }
  567. if ($search_societe) {
  568. $param .= '&search_societe='.urlencode($search_societe);
  569. }
  570. if ($projectid > 0) {
  571. $param .= '&projectid='.urlencode($projectid);
  572. }
  573. if ($search_date_start) {
  574. $tmparray = dol_getdate($search_date_start);
  575. $param .= '&search_date_startday='.urlencode($tmparray['mday']);
  576. $param .= '&search_date_startmonth='.urlencode($tmparray['mon']);
  577. $param .= '&search_date_startyear='.urlencode($tmparray['year']);
  578. }
  579. if ($search_date_end) {
  580. $tmparray = dol_getdate($search_date_end);
  581. $param .= '&search_date_endday='.urlencode($tmparray['mday']);
  582. $param .= '&search_date_endmonth='.urlencode($tmparray['mon']);
  583. $param .= '&search_date_endyear='.urlencode($tmparray['year']);
  584. }
  585. if ($search_dateread_start) {
  586. $tmparray = dol_getdate($search_dateread_start);
  587. $param .= '&search_dateread_startday='.urlencode($tmparray['mday']);
  588. $param .= '&search_dateread_startmonth='.urlencode($tmparray['mon']);
  589. $param .= '&search_dateread_startyear='.urlencode($tmparray['year']);
  590. }
  591. if ($search_dateread_end) {
  592. $tmparray = dol_getdate($search_dateread_end);
  593. $param .= '&search_dateread_endday='.urlencode($tmparray['mday']);
  594. $param .= '&search_dateread_endmonth='.urlencode($tmparray['mon']);
  595. $param .= '&search_dateread_endyear='.urlencode($tmparray['year']);
  596. }
  597. if ($search_dateclose_start) {
  598. $tmparray = dol_getdate($search_dateclose_start);
  599. $param .= '&search_dateclose_startday='.urlencode($tmparray['mday']);
  600. $param .= '&search_dateclose_startmonth='.urlencode($tmparray['mon']);
  601. $param .= '&search_dateclose_startyear='.urlencode($tmparray['year']);
  602. }
  603. if ($search_dateclose_end) {
  604. $tmparray = dol_getdate($search_dateclose_end);
  605. $param .= '&search_date_endday='.urlencode($tmparray['mday']);
  606. $param .= '&search_date_endmonth='.urlencode($tmparray['mon']);
  607. $param .= '&search_date_endyear='.urlencode($tmparray['year']);
  608. }
  609. // List of mass actions available
  610. $arrayofmassactions = array(
  611. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  612. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  613. );
  614. if ($permissiontoadd) {
  615. $arrayofmassactions['presendonclose'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Close");
  616. $arrayofmassactions['reopen'] = img_picto('', 'folder-open', 'class="pictofixedwidth"').$langs->trans("ReOpen");
  617. }
  618. if ($permissiontodelete) {
  619. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  620. }
  621. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  622. $arrayofmassactions = array();
  623. }
  624. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  625. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  626. if ($optioncss != '') {
  627. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  628. }
  629. print '<input type="hidden" name="token" value="'.newToken().'">';
  630. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  631. print '<input type="hidden" name="action" value="list">';
  632. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  633. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  634. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  635. print '<input type="hidden" name="mode" value="'.$mode.'" >';
  636. if ($socid) {
  637. print '<input type="hidden" name="socid" value="'.$socid.'" >';
  638. }
  639. if ($projectid) {
  640. print '<input type="hidden" name="projectid" value="'.$projectid.'" >';
  641. }
  642. $url = DOL_URL_ROOT.'/ticket/card.php?action=create'.($socid ? '&socid='.$socid : '').($projectid ? '&origin=projet_project&originid='.$projectid : '');
  643. if (!empty($socid)) {
  644. $url .= '&socid='.$socid;
  645. }
  646. $newcardbutton = dolGetButtonTitle($langs->trans('NewTicket'), '', 'fa fa-plus-circle', $url, '', $user->rights->ticket->write);
  647. $picto = 'ticket';
  648. if ($socid > 0) {
  649. $picto = '';
  650. }
  651. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  652. if ($mode == 'mine') {
  653. print '<div class="opacitymedium">'.$langs->trans('TicketAssignedToMeInfos').'</div><br>';
  654. }
  655. // Add code for pre mass action (confirmation or email presend form)
  656. $topicmail = "SendTicketRef";
  657. $modelmail = "ticket";
  658. $objecttmp = new Ticket($db);
  659. $trackid = 'tic'.$object->id;
  660. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  661. // confirm auto send on close
  662. if ($massaction == 'presendonclose') {
  663. $hidden_form = array([
  664. "type" => "hidden",
  665. "name" => "massaction",
  666. "value" => "close"
  667. ]);
  668. $selectedchoice = (!empty($conf->global->TICKET_NOTIFY_AT_CLOSING)) ? "yes" : "no";
  669. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassTicketClosingSendEmail"), $langs->trans("ConfirmMassTicketClosingSendEmailQuestion"), 'confirm_send_close', $hidden_form, $selectedchoice, 0, 200, 500, 1);
  670. }
  671. if ($search_all) {
  672. foreach ($fieldstosearchall as $key => $val) {
  673. $fieldstosearchall[$key] = $langs->trans($val);
  674. }
  675. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  676. }
  677. $moreforfilter = '';
  678. /*$moreforfilter.='<div class="divsearchfield">';
  679. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  680. $moreforfilter.= '</div>';*/
  681. $parameters = array();
  682. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  683. if (empty($reshook)) {
  684. $moreforfilter .= $hookmanager->resPrint;
  685. } else {
  686. $moreforfilter = $hookmanager->resPrint;
  687. }
  688. if (!empty($moreforfilter)) {
  689. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  690. print $moreforfilter;
  691. print '</div>';
  692. }
  693. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  694. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  695. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  696. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  697. print '<div class="div-table-responsive-inside">';
  698. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  699. // Fields title search
  700. // --------------------------------------------------------------------
  701. print '<tr class="liste_titre">';
  702. foreach ($object->fields as $key => $val) {
  703. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  704. if ($key == 'fk_statut') {
  705. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  706. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  707. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  708. } elseif (in_array($val['type'], array('timestamp'))) {
  709. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  710. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  711. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  712. }
  713. if (!empty($arrayfields['t.'.$key]['checked'])) {
  714. if ($key == 'progress') {
  715. print '<td class="liste_titre right'.($cssforfield ? ' '.$cssforfield : '').'">';
  716. print '<input type="text" class="flat maxwidth50" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
  717. print '</td>';
  718. } elseif ($key == 'type_code') {
  719. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  720. $formTicket->selectTypesTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key.'', '', 2, 1, 1, 0, ($val['css'] ? $val['css'] : 'maxwidth150'));
  721. print '</td>';
  722. } elseif ($key == 'category_code') {
  723. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  724. $formTicket->selectGroupTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key.'', '', 2, 1, 1, 0, ($val['css'] ? $val['css'] : 'maxwidth150'));
  725. print '</td>';
  726. } elseif ($key == 'severity_code') {
  727. print '<td class="liste_titre center'.($cssforfield ? ' '.$cssforfield : '').'">';
  728. $formTicket->selectSeveritiesTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key.'', '', 2, 1, 1, 0, ($val['css'] ? $val['css'] : 'maxwidth150'));
  729. print '</td>';
  730. } elseif ($key == 'fk_user_assign' || $key == 'fk_user_create') {
  731. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  732. print $form->select_dolusers((empty($search[$key]) ? '' : $search[$key]), 'search_'.$key, 1, null, 0, '', '', '0', 0, 0, '', 0, '', ($val['css'] ? $val['css'] : 'maxwidth125'));
  733. print '</td>';
  734. } elseif ($key == 'fk_statut') {
  735. $arrayofstatus = array();
  736. $arrayofstatus['openall'] = '-- '.$langs->trans('OpenAll').' --';
  737. foreach ($object->statuts_short as $key2 => $val2) {
  738. if ($key2 == Ticket::STATUS_CLOSED) {
  739. $arrayofstatus['closeall'] = '-- '.$langs->trans('ClosedAll').' --';
  740. }
  741. $arrayofstatus[$key2] = $val2;
  742. }
  743. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  744. //var_dump($arrayofstatus);
  745. //var_dump($search['fk_statut']);
  746. //var_dump(array_values($search[$key]));
  747. $selectedarray = null;
  748. if (!empty($search[$key])) {
  749. $selectedarray = array_values($search[$key]);
  750. }
  751. print Form::multiselectarray('search_fk_statut', $arrayofstatus, $selectedarray, 0, 0, 'minwidth100imp maxwidth150', 1, 0, '', '', '');
  752. print '</td>';
  753. } elseif ($key == "fk_soc") {
  754. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'"><input type="text" class="flat maxwidth75" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
  755. } elseif ($key == "datec" || $key == 'date_read' || $key == 'date_close') {
  756. print '<td class="liste_titre center">';
  757. print '<div class="nowrap">';
  758. switch ($key) {
  759. case 'datec':
  760. print $form->selectDate($search_date_start ?: -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  761. break;
  762. case 'date_read':
  763. print $form->selectDate($search_dateread_start ?: -1, 'search_dateread_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  764. break;
  765. case 'date_close':
  766. print $form->selectDate($search_dateclose_start ?: -1, 'search_dateclose_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  767. }
  768. print '</div>';
  769. print '<div class="nowrap">';
  770. switch ($key) {
  771. case 'datec':
  772. print $form->selectDate($search_date_end ?: -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  773. break;
  774. case 'date_read':
  775. print $form->selectDate($search_dateread_end ?: -1, 'search_dateread_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  776. break;
  777. case 'date_close':
  778. print $form->selectDate($search_dateclose_end ?: -1, 'search_dateclose_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  779. }
  780. print '</div>';
  781. print '</td>';
  782. } else {
  783. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  784. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  785. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  786. } elseif (strpos($val['type'], 'integer:') === 0) {
  787. print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
  788. } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
  789. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
  790. }
  791. print '</td>';
  792. }
  793. }
  794. }
  795. // Extra fields
  796. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  797. // Fields from hook
  798. $parameters = array('arrayfields'=>$arrayfields);
  799. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  800. print $hookmanager->resPrint;
  801. // Action column
  802. print '<td class="liste_titre maxwidthsearch">';
  803. $searchpicto = $form->showFilterButtons();
  804. print $searchpicto;
  805. print '</td>';
  806. print '</tr>'."\n";
  807. // Fields title label
  808. // --------------------------------------------------------------------
  809. print '<tr class="liste_titre">';
  810. foreach ($object->fields as $key => $val) {
  811. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  812. if ($key == 'fk_statut' || $key == 'severity_code') {
  813. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  814. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  815. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  816. } elseif (in_array($val['type'], array('timestamp'))) {
  817. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  818. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  819. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  820. }
  821. if (!empty($arrayfields['t.'.$key]['checked'])) {
  822. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  823. }
  824. }
  825. $totalarray = array(
  826. 'nbfield' => 0,
  827. );
  828. // Extra fields
  829. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  830. // Hook fields
  831. $parameters = array(
  832. 'arrayfields' => $arrayfields,
  833. 'param' => $param,
  834. 'sortfield' => $sortfield,
  835. 'sortorder' => $sortorder,
  836. 'totalarray' => &$totalarray,
  837. );
  838. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  839. print $hookmanager->resPrint;
  840. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  841. print '</tr>'."\n";
  842. // Detect if we need a fetch on each output line
  843. $needToFetchEachLine = 0;
  844. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  845. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  846. if (preg_match('/\$object/', $val)) {
  847. $needToFetchEachLine++; // There is at least one compute field that use $object
  848. }
  849. }
  850. }
  851. // Loop on record
  852. // --------------------------------------------------------------------
  853. $i = 0;
  854. $totalarray = array();
  855. $totalarray['nbfield'] = 0;
  856. $now = dol_now();
  857. $cacheofoutputfield = array();
  858. while ($i < ($limit ? min($num, $limit) : $num)) {
  859. $obj = $db->fetch_object($resql);
  860. if (empty($obj)) {
  861. break; // Should not happen
  862. }
  863. // Store properties in $object
  864. $object->setVarsFromFetchObj($obj);
  865. $object->status = $object->fk_statut; // fk_statut is deprecated
  866. // Show here line of result
  867. print '<tr class="oddeven">';
  868. foreach ($object->fields as $key => $val) {
  869. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  870. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  871. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  872. }
  873. if (in_array($val['type'], array('timestamp'))) {
  874. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  875. }
  876. if (in_array($key, array('ref', 'fk_project'))) {
  877. $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
  878. }
  879. if ($key == 'fk_statut' || $key == 'severity_code') {
  880. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  881. }
  882. if (!empty($arrayfields['t.'.$key]['checked'])) {
  883. print '<td';
  884. if ($cssforfield || (array_key_exists('css', $val) && $val['css'])) {
  885. print ' class="';
  886. }
  887. print $cssforfield;
  888. if ($cssforfield && array_key_exists('css', $val) && $val['css']) {
  889. print ' ';
  890. }
  891. if (array_key_exists('css', $val)) {
  892. print $val['css'];
  893. }
  894. if ($cssforfield || (array_key_exists('css', $val) && $val['css'])) {
  895. print '"';
  896. }
  897. print '>';
  898. if ($key == 'fk_statut') {
  899. print $object->getLibStatut(5);
  900. } elseif ($key == 'subject') {
  901. $s = $obj->subject;
  902. print '<span title="'.dol_escape_htmltag($s).'">';
  903. print $s;
  904. print '</span>';
  905. } elseif ($key == 'type_code') {
  906. $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code);
  907. print '<span title="'.dol_escape_htmltag($s).'">';
  908. print $s;
  909. print '</span>';
  910. } elseif ($key == 'category_code') {
  911. $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code);
  912. print '<span title="'.dol_escape_htmltag($s).'">';
  913. print $s;
  914. print '</span>';
  915. } elseif ($key == 'severity_code') {
  916. $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code);
  917. print '<span title="'.dol_escape_htmltag($s).'">';
  918. print $s;
  919. print '</span>';
  920. } elseif ($key == 'tms') {
  921. print dol_print_date($db->jdate($obj->$key), 'dayhour', 'tzuser');
  922. } elseif ($key == 'fk_user_create') {
  923. if ($object->fk_user_create > 0) {
  924. if (isset($conf->cache['user'][$object->fk_user_create])) {
  925. $user_temp = $conf->cache['user'][$object->fk_user_create];
  926. } else {
  927. $user_temp = new User($db);
  928. $user_temp->fetch($object->fk_user_create);
  929. $conf->cache['user'][$object->fk_user_create] = $user_temp;
  930. }
  931. print $user_temp->getNomUrl(-1);
  932. }
  933. } elseif ($key == 'fk_user_assign') {
  934. if ($object->fk_user_assign > 0) {
  935. if (isset($conf->cache['user'][$object->fk_user_assign])) {
  936. $user_temp = $conf->cache['user'][$object->fk_user_assign];
  937. } else {
  938. $user_temp = new User($db);
  939. $user_temp->fetch($object->fk_user_assign);
  940. $conf->cache['user'][$object->fk_user_assign] = $user_temp;
  941. }
  942. print $user_temp->getNomUrl(-1);
  943. }
  944. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  945. print $object->showOutputField($val, $key, $db->jdate($obj->$key), '');
  946. } elseif ($key == 'ref') {
  947. print $object->showOutputField($val, $key, $obj->$key, '');
  948. // display a warning on untreated tickets
  949. $is_open = ($object->status != Ticket::STATUS_CLOSED && $object->status != Ticket::STATUS_CANCELED );
  950. $should_show_warning = (!empty($conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE) || !empty($conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE));
  951. if ($is_open && $should_show_warning) {
  952. $date_last_msg_sent = (int) $object->date_last_msg_sent;
  953. $hour_diff = ($now - $date_last_msg_sent) / 3600 ;
  954. if (!empty($conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE && $date_last_msg_sent == 0)) {
  955. $creation_date = $object->datec;
  956. $hour_diff_creation = ($now - $creation_date) / 3600 ;
  957. if ($hour_diff_creation > $conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE) {
  958. print " " . img_picto($langs->trans('Late') . ' : ' . $langs->trans('TicketsDelayForFirstResponseTooLong', $conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE), 'warning', 'style="color: red;"', false, 0, 0, '', '');
  959. }
  960. } elseif (!empty($conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE) && $hour_diff > $conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE) {
  961. print " " . img_picto($langs->trans('Late') . ' : ' . $langs->trans('TicketsDelayFromLastResponseTooLong', $conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE), 'warning');
  962. }
  963. }
  964. } else { // Example: key=fk_soc, obj->key=123 val=array('type'=>'integer', ...
  965. $tmp = explode(':', $val['type']);
  966. if ($tmp[0] == 'integer' && !empty($tmp[1]) && class_exists($tmp[1])) {
  967. // It is a type of an foreign field. We will try to reduce the number of fetch that the showOutputField is making.
  968. //var_dump('eeee-'.$key.'-'.$obj->$key.'-'.$val['type']);
  969. if ($key && $obj->$key && $val['type'] && array_key_exists($key.'-'.$obj->$key.'-'.$val['type'], $cacheofoutputfield)) {
  970. $result = $cacheofoutputfield[$key.'-'.$obj->$key.'-'.$val['type']];
  971. } else {
  972. $result = $object->showOutputField($val, $key, $obj->$key, '');
  973. $cacheofoutputfield[$key.'-'.$obj->$key.'-'.$val['type']] = $result;
  974. }
  975. } else {
  976. $result = $object->showOutputField($val, $key, $obj->$key, '');
  977. }
  978. print $result;
  979. }
  980. print '</td>';
  981. if (!$i) {
  982. $totalarray['nbfield']++;
  983. }
  984. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  985. if (!$i) {
  986. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  987. }
  988. if (!isset($totalarray['val'])) {
  989. $totalarray['val'] = array();
  990. }
  991. if (!isset($totalarray['val']['t.'.$key])) {
  992. $totalarray['val']['t.'.$key] = 0;
  993. }
  994. $totalarray['val']['t.'.$key] += $object->$key;
  995. }
  996. }
  997. }
  998. // Extra fields
  999. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1000. // Fields from hook
  1001. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1002. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1003. print $hookmanager->resPrint;
  1004. // Action column
  1005. print '<td class="nowrap center">';
  1006. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1007. $selected = 0;
  1008. if (in_array($obj->rowid, $arrayofselected)) {
  1009. $selected = 1;
  1010. }
  1011. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1012. }
  1013. print '</td>';
  1014. if (!$i) {
  1015. $totalarray['nbfield']++;
  1016. }
  1017. print '</tr>'."\n";
  1018. $i++;
  1019. }
  1020. // Show total line
  1021. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1022. // If no record found
  1023. if ($num == 0) {
  1024. $colspan = 1;
  1025. foreach ($arrayfields as $key => $val) {
  1026. if (!empty($val['checked'])) {
  1027. $colspan++;
  1028. }
  1029. }
  1030. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1031. }
  1032. $db->free($resql);
  1033. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1034. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  1035. print $hookmanager->resPrint;
  1036. print '</table>'."\n";
  1037. print '</div>'."\n";
  1038. print '</div>'."\n"; // end div-responsive-inside
  1039. print '</form>'."\n";
  1040. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  1041. $hidegeneratedfilelistifempty = 1;
  1042. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1043. $hidegeneratedfilelistifempty = 0;
  1044. }
  1045. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  1046. $formfile = new FormFile($db);
  1047. // Show list of available documents
  1048. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1049. $urlsource .= str_replace('&amp;', '&', $param);
  1050. $filedir = $diroutputmassaction;
  1051. $genallowed = $permissiontoread;
  1052. $delallowed = $permissiontoadd;
  1053. print $formfile->showdocuments('massfilesarea_ticket', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1054. }
  1055. // End of page
  1056. llxFooter();
  1057. $db->close();