list.php 51 KB

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