list.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  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. $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->hasRight('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($search[$key])) {
  546. foreach ($search[$key] 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. $setupstring = '';
  673. foreach ($fieldstosearchall as $key => $val) {
  674. $fieldstosearchall[$key] = $langs->trans($val);
  675. $setupstring .= $key."=".$val.";";
  676. }
  677. print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  678. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  679. }
  680. $moreforfilter = '';
  681. /*$moreforfilter.='<div class="divsearchfield">';
  682. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  683. $moreforfilter.= '</div>';*/
  684. $parameters = array();
  685. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  686. if (empty($reshook)) {
  687. $moreforfilter .= $hookmanager->resPrint;
  688. } else {
  689. $moreforfilter = $hookmanager->resPrint;
  690. }
  691. if (!empty($moreforfilter)) {
  692. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  693. print $moreforfilter;
  694. print '</div>';
  695. }
  696. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  697. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  698. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  699. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  700. print '<div class="div-table-responsive-inside">';
  701. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  702. // Fields title search
  703. // --------------------------------------------------------------------
  704. print '<tr class="liste_titre">';
  705. foreach ($object->fields as $key => $val) {
  706. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  707. if ($key == 'fk_statut') {
  708. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  709. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  710. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  711. } elseif (in_array($val['type'], array('timestamp'))) {
  712. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  713. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  714. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  715. }
  716. if (!empty($arrayfields['t.'.$key]['checked'])) {
  717. if ($key == 'progress') {
  718. print '<td class="liste_titre right'.($cssforfield ? ' '.$cssforfield : '').'">';
  719. print '<input type="text" class="flat maxwidth50" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
  720. print '</td>';
  721. } elseif ($key == 'type_code') {
  722. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  723. $formTicket->selectTypesTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key.'', '', 2, 1, 1, 0, ($val['css'] ? $val['css'] : 'maxwidth150'));
  724. print '</td>';
  725. } elseif ($key == 'category_code') {
  726. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  727. $formTicket->selectGroupTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key.'', '', 2, 1, 1, 0, ($val['css'] ? $val['css'] : 'maxwidth150'));
  728. print '</td>';
  729. } elseif ($key == 'severity_code') {
  730. print '<td class="liste_titre center'.($cssforfield ? ' '.$cssforfield : '').'">';
  731. $formTicket->selectSeveritiesTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key.'', '', 2, 1, 1, 0, ($val['css'] ? $val['css'] : 'maxwidth150'));
  732. print '</td>';
  733. } elseif ($key == 'fk_user_assign' || $key == 'fk_user_create') {
  734. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  735. print $form->select_dolusers((empty($search[$key]) ? '' : $search[$key]), 'search_'.$key, 1, null, 0, '', '', '0', 0, 0, '', 0, '', ($val['css'] ? $val['css'] : 'maxwidth100'));
  736. print '</td>';
  737. } elseif ($key == 'fk_statut') {
  738. $arrayofstatus = array();
  739. $arrayofstatus['openall'] = '-- '.$langs->trans('OpenAll').' --';
  740. foreach ($object->statuts_short as $key2 => $val2) {
  741. if ($key2 == Ticket::STATUS_CLOSED) {
  742. $arrayofstatus['closeall'] = '-- '.$langs->trans('ClosedAll').' --';
  743. }
  744. $arrayofstatus[$key2] = $val2;
  745. }
  746. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  747. //var_dump($arrayofstatus);
  748. //var_dump($search['fk_statut']);
  749. //var_dump(array_values($search[$key]));
  750. $selectedarray = null;
  751. if (!empty($search[$key])) {
  752. $selectedarray = array_values($search[$key]);
  753. }
  754. print Form::multiselectarray('search_fk_statut', $arrayofstatus, $selectedarray, 0, 0, 'minwidth100imp maxwidth150', 1, 0, '', '', '');
  755. print '</td>';
  756. } elseif ($key == "fk_soc") {
  757. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'"><input type="text" class="flat maxwidth75" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
  758. } elseif ($key == "datec" || $key == 'date_read' || $key == 'date_close') {
  759. print '<td class="liste_titre center">';
  760. print '<div class="nowrap">';
  761. switch ($key) {
  762. case 'datec':
  763. print $form->selectDate($search_date_start ?: -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  764. break;
  765. case 'date_read':
  766. print $form->selectDate($search_dateread_start ?: -1, 'search_dateread_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  767. break;
  768. case 'date_close':
  769. print $form->selectDate($search_dateclose_start ?: -1, 'search_dateclose_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  770. }
  771. print '</div>';
  772. print '<div class="nowrap">';
  773. switch ($key) {
  774. case 'datec':
  775. print $form->selectDate($search_date_end ?: -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  776. break;
  777. case 'date_read':
  778. print $form->selectDate($search_dateread_end ?: -1, 'search_dateread_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  779. break;
  780. case 'date_close':
  781. print $form->selectDate($search_dateclose_end ?: -1, 'search_dateclose_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  782. }
  783. print '</div>';
  784. print '</td>';
  785. } else {
  786. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  787. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  788. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  789. } elseif (strpos($val['type'], 'integer:') === 0) {
  790. print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
  791. } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
  792. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
  793. }
  794. print '</td>';
  795. }
  796. }
  797. }
  798. // Extra fields
  799. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  800. // Fields from hook
  801. $parameters = array('arrayfields'=>$arrayfields);
  802. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  803. print $hookmanager->resPrint;
  804. // Action column
  805. print '<td class="liste_titre maxwidthsearch">';
  806. $searchpicto = $form->showFilterButtons();
  807. print $searchpicto;
  808. print '</td>';
  809. print '</tr>'."\n";
  810. // Fields title label
  811. // --------------------------------------------------------------------
  812. print '<tr class="liste_titre">';
  813. foreach ($object->fields as $key => $val) {
  814. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  815. if ($key == 'fk_statut' || $key == 'severity_code') {
  816. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  817. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  818. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  819. } elseif (in_array($val['type'], array('timestamp'))) {
  820. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  821. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  822. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  823. }
  824. if (!empty($arrayfields['t.'.$key]['checked'])) {
  825. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  826. }
  827. }
  828. $totalarray = array(
  829. 'nbfield' => 0,
  830. );
  831. // Extra fields
  832. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  833. // Hook fields
  834. $parameters = array(
  835. 'arrayfields' => $arrayfields,
  836. 'param' => $param,
  837. 'sortfield' => $sortfield,
  838. 'sortorder' => $sortorder,
  839. 'totalarray' => &$totalarray,
  840. );
  841. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  842. print $hookmanager->resPrint;
  843. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  844. print '</tr>'."\n";
  845. // Detect if we need a fetch on each output line
  846. $needToFetchEachLine = 0;
  847. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  848. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  849. if (preg_match('/\$object/', $val)) {
  850. $needToFetchEachLine++; // There is at least one compute field that use $object
  851. }
  852. }
  853. }
  854. // Loop on record
  855. // --------------------------------------------------------------------
  856. $i = 0;
  857. $totalarray = array();
  858. $totalarray['nbfield'] = 0;
  859. $now = dol_now();
  860. $cacheofoutputfield = array();
  861. while ($i < ($limit ? min($num, $limit) : $num)) {
  862. $obj = $db->fetch_object($resql);
  863. if (empty($obj)) {
  864. break; // Should not happen
  865. }
  866. // Store properties in $object
  867. $object->setVarsFromFetchObj($obj);
  868. $object->status = $object->fk_statut; // fk_statut is deprecated
  869. // Show here line of result
  870. print '<tr class="oddeven">';
  871. foreach ($object->fields as $key => $val) {
  872. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  873. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  874. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  875. }
  876. if (in_array($val['type'], array('timestamp'))) {
  877. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  878. }
  879. if (in_array($key, array('ref', 'fk_project'))) {
  880. $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
  881. }
  882. if ($key == 'fk_statut' || $key == 'severity_code') {
  883. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  884. }
  885. if (!empty($arrayfields['t.'.$key]['checked'])) {
  886. print '<td';
  887. if ($cssforfield || (array_key_exists('css', $val) && $val['css'])) {
  888. print ' class="';
  889. }
  890. print $cssforfield;
  891. if ($cssforfield && array_key_exists('css', $val) && $val['css']) {
  892. print ' ';
  893. }
  894. if (array_key_exists('css', $val)) {
  895. print $val['css'];
  896. }
  897. if ($cssforfield || (array_key_exists('css', $val) && $val['css'])) {
  898. print '"';
  899. }
  900. print '>';
  901. if ($key == 'fk_statut') {
  902. print $object->getLibStatut(5);
  903. } elseif ($key == 'subject') {
  904. $s = $obj->subject;
  905. print '<span title="'.dol_escape_htmltag($s).'">';
  906. print dol_escape_htmltag($s);
  907. print '</span>';
  908. } elseif ($key == 'type_code') {
  909. $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code);
  910. print '<span title="'.dol_escape_htmltag($s).'">';
  911. print $s;
  912. print '</span>';
  913. } elseif ($key == 'category_code') {
  914. $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code);
  915. print '<span title="'.dol_escape_htmltag($s).'">';
  916. print $s;
  917. print '</span>';
  918. } elseif ($key == 'severity_code') {
  919. $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code);
  920. print '<span title="'.dol_escape_htmltag($s).'">';
  921. print $s;
  922. print '</span>';
  923. } elseif ($key == 'tms') {
  924. print dol_print_date($db->jdate($obj->$key), 'dayhour', 'tzuser');
  925. } elseif ($key == 'fk_user_create') {
  926. if ($object->fk_user_create > 0) {
  927. if (isset($conf->cache['user'][$object->fk_user_create])) {
  928. $user_temp = $conf->cache['user'][$object->fk_user_create];
  929. } else {
  930. $user_temp = new User($db);
  931. $user_temp->fetch($object->fk_user_create);
  932. $conf->cache['user'][$object->fk_user_create] = $user_temp;
  933. }
  934. print $user_temp->getNomUrl(-1);
  935. }
  936. } elseif ($key == 'fk_user_assign') {
  937. if ($object->fk_user_assign > 0) {
  938. if (isset($conf->cache['user'][$object->fk_user_assign])) {
  939. $user_temp = $conf->cache['user'][$object->fk_user_assign];
  940. } else {
  941. $user_temp = new User($db);
  942. $user_temp->fetch($object->fk_user_assign);
  943. $conf->cache['user'][$object->fk_user_assign] = $user_temp;
  944. }
  945. print $user_temp->getNomUrl(-1);
  946. }
  947. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  948. print $object->showOutputField($val, $key, $db->jdate($obj->$key), '');
  949. } elseif ($key == 'ref') {
  950. print $object->showOutputField($val, $key, $obj->$key, '');
  951. // display a warning on untreated tickets
  952. $is_open = ($object->status != Ticket::STATUS_CLOSED && $object->status != Ticket::STATUS_CANCELED );
  953. $should_show_warning = (!empty($conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE) || !empty($conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE));
  954. if ($is_open && $should_show_warning) {
  955. $date_last_msg_sent = (int) $object->date_last_msg_sent;
  956. $hour_diff = ($now - $date_last_msg_sent) / 3600 ;
  957. if (!empty($conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE && $date_last_msg_sent == 0)) {
  958. $creation_date = $object->datec;
  959. $hour_diff_creation = ($now - $creation_date) / 3600 ;
  960. if ($hour_diff_creation > $conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE) {
  961. print " " . img_picto($langs->trans('Late') . ' : ' . $langs->trans('TicketsDelayForFirstResponseTooLong', $conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE), 'warning', 'style="color: red;"', false, 0, 0, '', '');
  962. }
  963. } elseif (!empty($conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE) && $hour_diff > $conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE) {
  964. print " " . img_picto($langs->trans('Late') . ' : ' . $langs->trans('TicketsDelayFromLastResponseTooLong', $conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE), 'warning');
  965. }
  966. }
  967. } else { // Example: key=fk_soc, obj->key=123 val=array('type'=>'integer', ...
  968. $tmp = explode(':', $val['type']);
  969. if ($tmp[0] == 'integer' && !empty($tmp[1]) && class_exists($tmp[1])) {
  970. // It is a type of an foreign field. We will try to reduce the number of fetch that the showOutputField is making.
  971. //var_dump('eeee-'.$key.'-'.$obj->$key.'-'.$val['type']);
  972. if ($key && $obj->$key && $val['type'] && array_key_exists($key.'-'.$obj->$key.'-'.$val['type'], $cacheofoutputfield)) {
  973. $result = $cacheofoutputfield[$key.'-'.$obj->$key.'-'.$val['type']];
  974. } else {
  975. $result = $object->showOutputField($val, $key, $obj->$key, '');
  976. $cacheofoutputfield[$key.'-'.$obj->$key.'-'.$val['type']] = $result;
  977. }
  978. } else {
  979. $result = $object->showOutputField($val, $key, $obj->$key, '');
  980. }
  981. print $result;
  982. }
  983. print '</td>';
  984. if (!$i) {
  985. $totalarray['nbfield']++;
  986. }
  987. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  988. if (!$i) {
  989. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  990. }
  991. if (!isset($totalarray['val'])) {
  992. $totalarray['val'] = array();
  993. }
  994. if (!isset($totalarray['val']['t.'.$key])) {
  995. $totalarray['val']['t.'.$key] = 0;
  996. }
  997. $totalarray['val']['t.'.$key] += $object->$key;
  998. }
  999. }
  1000. }
  1001. // Extra fields
  1002. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1003. // Fields from hook
  1004. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1005. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1006. print $hookmanager->resPrint;
  1007. // Action column
  1008. print '<td class="nowrap center">';
  1009. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1010. $selected = 0;
  1011. if (in_array($obj->rowid, $arrayofselected)) {
  1012. $selected = 1;
  1013. }
  1014. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1015. }
  1016. print '</td>';
  1017. if (!$i) {
  1018. $totalarray['nbfield']++;
  1019. }
  1020. print '</tr>'."\n";
  1021. $i++;
  1022. }
  1023. // Show total line
  1024. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1025. // If no record found
  1026. if ($num == 0) {
  1027. $colspan = 1;
  1028. foreach ($arrayfields as $key => $val) {
  1029. if (!empty($val['checked'])) {
  1030. $colspan++;
  1031. }
  1032. }
  1033. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1034. }
  1035. $db->free($resql);
  1036. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1037. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  1038. print $hookmanager->resPrint;
  1039. print '</table>'."\n";
  1040. print '</div>'."\n";
  1041. print '</div>'."\n"; // end div-responsive-inside
  1042. print '</form>'."\n";
  1043. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  1044. $hidegeneratedfilelistifempty = 1;
  1045. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1046. $hidegeneratedfilelistifempty = 0;
  1047. }
  1048. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  1049. $formfile = new FormFile($db);
  1050. // Show list of available documents
  1051. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1052. $urlsource .= str_replace('&amp;', '&', $param);
  1053. $filedir = $diroutputmassaction;
  1054. $genallowed = $permissiontoread;
  1055. $delallowed = $permissiontoadd;
  1056. print $formfile->showdocuments('massfilesarea_ticket', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1057. }
  1058. // End of page
  1059. llxFooter();
  1060. $db->close();