list.php 51 KB

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