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