list.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  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. if(strpos($search[$key], "á") !== false){
  377. $tmp = str_replace("á","á",$search[$key]);
  378. $sql .= natural_search($key, $search[$key]."|".$tmp, $mode_search);
  379. }
  380. elseif(strpos($search[$key], "á") !== false){
  381. $tmp = str_replace("á","á",$search[$key]);
  382. $sql .= natural_search($key, $search[$key]."|".$tmp, $mode_search);
  383. }
  384. else{
  385. $sql .= natural_search($key, $search[$key], $mode_search);
  386. }
  387. }
  388. }
  389. if ($search_all) {
  390. $tmp = (int)$search_all;
  391. unset($fieldstosearchall['t.fk_soc']);
  392. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  393. // if($search_all != ''.$tmp){}
  394. // else{$sql .= " OR t.fk_soc = ".$tmp." ";}
  395. $fieldstosearchall['t.fk_soc'] = $tmp;
  396. }
  397. if ($search_societe) {
  398. // $sql .= natural_search('s.nom', $search_societe);
  399. if($ids = getTpByNom(natural_search('s.nom', $search_societe),getEntity($object->element))){
  400. $sql .= " AND s.rowid IN (".implode(",",$ids).")";
  401. }
  402. }
  403. if ($search_fk_project > 0) {
  404. $sql .= natural_search('fk_project', $search_fk_project, 2);
  405. }
  406. if ($search_fk_contract > 0) {
  407. $sql .= natural_search('fk_contract', $search_fk_contract, 2);
  408. }
  409. if ($search_date_start) {
  410. $sql .= " AND t.datec >= '".$db->idate($search_date_start)."'";
  411. }
  412. if ($search_date_end) {
  413. $sql .= " AND t.datec <= '".$db->idate($search_date_end)."'";
  414. }
  415. if ($search_dateread_start) {
  416. $sql .= " AND t.date_read >= '".$db->idate($search_dateread_start)."'";
  417. }
  418. if ($search_dateread_end) {
  419. $sql .= " AND t.date_read <= '".$db->idate($search_dateread_end)."'";
  420. }
  421. if ($search_dateclose_start) {
  422. $sql .= " AND t.date_close >= '".$db->idate($search_dateclose_start)."'";
  423. }
  424. if ($search_dateclose_end) {
  425. $sql .= " AND t.date_close <= '".$db->idate($search_dateclose_end)."'";
  426. }
  427. if (!$user->socid && ($mode == "mine" || (!$user->admin && getDolGlobalInt('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')))) {
  428. $sql .= " AND (t.fk_user_assign = ".((int) $user->id);
  429. if (!getDolGlobalInt('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
  430. $sql .= " OR t.fk_user_create = ".((int) $user->id);
  431. }
  432. $sql .= ")";
  433. }
  434. // Add where from extra fields
  435. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  436. // Add where from hooks
  437. $parameters = array();
  438. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  439. $sql .= $hookmanager->resPrint;
  440. // Count total nb of records
  441. $nbtotalofrecords = '';
  442. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  443. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  444. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  445. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  446. $resql = $db->query($sqlforcount);
  447. if ($resql) {
  448. $objforcount = $db->fetch_object($resql);
  449. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  450. } else {
  451. dol_print_error($db);
  452. }
  453. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  454. $page = 0;
  455. $offset = 0;
  456. }
  457. $db->free($resql);
  458. }
  459. // Complete request and execute it with limit
  460. $sql .= $db->order($sortfield, $sortorder);
  461. if ($limit) {
  462. $sql .= $db->plimit($limit + 1, $offset);
  463. }
  464. $resql = $db->query($sql);
  465. if (!$resql) {
  466. dol_print_error($db);
  467. exit;
  468. }
  469. $num = $db->num_rows($resql);
  470. // Direct jump if only one record found
  471. if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  472. $obj = $db->fetch_object($resql);
  473. $id = $obj->rowid;
  474. header("Location: ".DOL_URL_ROOT.'/ticket/card.php?id='.$id);
  475. exit;
  476. }
  477. // Output page
  478. // --------------------------------------------------------------------
  479. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
  480. if ($socid && !$projectid && !$project_ref && $user->hasRight('societe', 'lire')) {
  481. $socstat = new Societe($db);
  482. $res = $socstat->fetch($socid);
  483. if ($res > 0) {
  484. $tmpobject = $object;
  485. $object = $socstat; // $object must be of type Societe when calling societe_prepare_head
  486. $head = societe_prepare_head($socstat);
  487. $object = $tmpobject;
  488. print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), -1, 'company');
  489. dol_banner_tab($socstat, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  490. print '<div class="fichecenter">';
  491. print '<div class="underbanner clearboth"></div>';
  492. print '<table class="border centpercent tableforfield">';
  493. // Type Prospect/Customer/Supplier
  494. print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
  495. print $socstat->getTypeUrl(1);
  496. print '</td></tr>';
  497. // Customer code
  498. if ($socstat->client && !empty($socstat->code_client)) {
  499. print '<tr><td class="titlefield">';
  500. print $langs->trans('CustomerCode').'</td><td>';
  501. print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_client));
  502. $tmpcheck = $socstat->check_codeclient();
  503. if ($tmpcheck != 0 && $tmpcheck != -5) {
  504. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  505. }
  506. print '</td>';
  507. print '</tr>';
  508. }
  509. // Supplier code
  510. if ($socstat->fournisseur && !empty($socstat->code_fournisseur)) {
  511. print '<tr><td class="titlefield">';
  512. print $langs->trans('SupplierCode').'</td><td>';
  513. print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_fournisseur));
  514. $tmpcheck = $socstat->check_codefournisseur();
  515. if ($tmpcheck != 0 && $tmpcheck != -5) {
  516. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  517. }
  518. print '</td>';
  519. print '</tr>';
  520. }
  521. print '</table>';
  522. print '</div>';
  523. print dol_get_fiche_end();
  524. }
  525. }
  526. if ($projectid > 0 || $project_ref) {
  527. $projectstat = new Project($db);
  528. if ($projectstat->fetch($projectid, $project_ref) > 0) {
  529. $projectid = $projectstat->id;
  530. $projectstat->fetch_thirdparty();
  531. $savobject = $object;
  532. $object = $projectstat;
  533. // To verify role of users
  534. //$userAccess = $object->restrictedProjectArea($user,'read');
  535. $userWrite = $projectstat->restrictedProjectArea($user, 'write');
  536. //$userDelete = $object->restrictedProjectArea($user,'delete');
  537. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  538. $head = project_prepare_head($projectstat);
  539. print dol_get_fiche_head($head, 'ticket', $langs->trans("Project"), -1, ($projectstat->public ? 'projectpub' : 'project'));
  540. // Project card
  541. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  542. $morehtmlref = '<div class="refidno">';
  543. // Title
  544. $morehtmlref .= $object->title;
  545. // Thirdparty
  546. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  547. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
  548. }
  549. $morehtmlref .= '</div>';
  550. // Define a complementary filter for search of next/prev ref.
  551. if (!$user->hasRight('projet', 'all', 'lire')) {
  552. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  553. $object->next_prev_filter = "rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  554. }
  555. dol_banner_tab($object, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  556. print '<div class="fichecenter">';
  557. print '<div class="underbanner clearboth"></div>';
  558. print '<table class="border tableforfield centpercent">';
  559. // Visibility
  560. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  561. if ($projectstat->public) {
  562. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  563. print $langs->trans('SharedProject');
  564. } else {
  565. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  566. print $langs->trans('PrivateProject');
  567. }
  568. print '</td></tr>';
  569. print "</table>";
  570. print '</div>';
  571. print dol_get_fiche_end();
  572. $object = $savobject;
  573. } else {
  574. print "ErrorRecordNotFound";
  575. }
  576. }
  577. $arrayofselected = is_array($toselect) ? $toselect : array();
  578. $param = '';
  579. if (!empty($mode)) {
  580. $param .= '&mode='.urlencode($mode);
  581. }
  582. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  583. $param .= '&contextpage='.urlencode($contextpage);
  584. }
  585. if ($limit > 0 && $limit != $conf->liste_limit) {
  586. $param .= '&limit='.((int) $limit);
  587. }
  588. foreach ($search as $key => $val) {
  589. if (is_array($search[$key])) {
  590. foreach ($search[$key] as $skey) {
  591. if ($skey != '') {
  592. $param .= '&search_'.$key.'[]='.urlencode($skey);
  593. }
  594. }
  595. } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
  596. $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
  597. $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
  598. $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
  599. } elseif ($search[$key] != '') {
  600. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  601. }
  602. }
  603. if ($optioncss != '') {
  604. $param .= '&optioncss='.urlencode($optioncss);
  605. }
  606. // Add $param from extra fields
  607. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  608. // Add $param from hooks
  609. $parameters = array();
  610. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  611. $param .= $hookmanager->resPrint;
  612. if ($socid > 0) {
  613. $param .= '&socid='.urlencode($socid);
  614. }
  615. if ($search_societe) {
  616. $param .= '&search_societe='.urlencode($search_societe);
  617. }
  618. if ($projectid > 0) {
  619. $param .= '&projectid='.urlencode($projectid);
  620. }
  621. if ($contractid > 0) {
  622. $param .= '&contractid='.urlencode($contractid);
  623. }
  624. if ($search_date_start) {
  625. $tmparray = dol_getdate($search_date_start);
  626. $param .= '&search_date_startday='.urlencode($tmparray['mday']);
  627. $param .= '&search_date_startmonth='.urlencode($tmparray['mon']);
  628. $param .= '&search_date_startyear='.urlencode($tmparray['year']);
  629. }
  630. if ($search_date_end) {
  631. $tmparray = dol_getdate($search_date_end);
  632. $param .= '&search_date_endday='.urlencode($tmparray['mday']);
  633. $param .= '&search_date_endmonth='.urlencode($tmparray['mon']);
  634. $param .= '&search_date_endyear='.urlencode($tmparray['year']);
  635. }
  636. if ($search_dateread_start) {
  637. $tmparray = dol_getdate($search_dateread_start);
  638. $param .= '&search_dateread_startday='.urlencode($tmparray['mday']);
  639. $param .= '&search_dateread_startmonth='.urlencode($tmparray['mon']);
  640. $param .= '&search_dateread_startyear='.urlencode($tmparray['year']);
  641. }
  642. if ($search_dateread_end) {
  643. $tmparray = dol_getdate($search_dateread_end);
  644. $param .= '&search_dateread_endday='.urlencode($tmparray['mday']);
  645. $param .= '&search_dateread_endmonth='.urlencode($tmparray['mon']);
  646. $param .= '&search_dateread_endyear='.urlencode($tmparray['year']);
  647. }
  648. if ($search_dateclose_start) {
  649. $tmparray = dol_getdate($search_dateclose_start);
  650. $param .= '&search_dateclose_startday='.urlencode($tmparray['mday']);
  651. $param .= '&search_dateclose_startmonth='.urlencode($tmparray['mon']);
  652. $param .= '&search_dateclose_startyear='.urlencode($tmparray['year']);
  653. }
  654. if ($search_dateclose_end) {
  655. $tmparray = dol_getdate($search_dateclose_end);
  656. $param .= '&search_date_endday='.urlencode($tmparray['mday']);
  657. $param .= '&search_date_endmonth='.urlencode($tmparray['mon']);
  658. $param .= '&search_date_endyear='.urlencode($tmparray['year']);
  659. }
  660. // List of mass actions available
  661. $arrayofmassactions = array(
  662. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  663. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  664. );
  665. if ($permissiontoadd) {
  666. $arrayofmassactions['presendonclose'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Close");
  667. $arrayofmassactions['reopen'] = img_picto('', 'folder-open', 'class="pictofixedwidth"').$langs->trans("ReOpen");
  668. }
  669. if ($permissiontodelete) {
  670. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  671. }
  672. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  673. $arrayofmassactions = array();
  674. }
  675. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  676. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  677. if ($optioncss != '') {
  678. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  679. }
  680. print '<input type="hidden" name="token" value="'.newToken().'">';
  681. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  682. print '<input type="hidden" name="action" value="list">';
  683. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  684. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  685. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  686. print '<input type="hidden" name="mode" value="'.$mode.'" >';
  687. if ($socid) {
  688. print '<input type="hidden" name="socid" value="'.$socid.'" >';
  689. }
  690. if ($projectid) {
  691. print '<input type="hidden" name="projectid" value="'.$projectid.'" >';
  692. }
  693. $url = DOL_URL_ROOT.'/ticket/card.php?action=create'.($socid ? '&socid='.$socid : '').($projectid ? '&origin=projet_project&originid='.$projectid : '');
  694. if (!empty($socid)) {
  695. $url .= '&socid='.$socid;
  696. }
  697. $newcardbutton = '';
  698. $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'));
  699. $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'));
  700. $newcardbutton .= dolGetButtonTitleSeparator();
  701. $newcardbutton .= dolGetButtonTitle($langs->trans('NewTicket'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('ticket', 'write'));
  702. $picto = 'ticket';
  703. if ($socid > 0) {
  704. $picto = '';
  705. }
  706. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  707. if ($mode == 'mine') {
  708. print '<div class="opacitymedium">'.$langs->trans('TicketAssignedToMeInfos').'</div><br>';
  709. }
  710. // Add code for pre mass action (confirmation or email presend form)
  711. $topicmail = "SendTicketRef";
  712. $modelmail = "ticket";
  713. $objecttmp = new Ticket($db);
  714. $trackid = 'tic'.$object->id;
  715. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  716. // confirm auto send on close
  717. if ($massaction == 'presendonclose') {
  718. $hidden_form = array([
  719. "type" => "hidden",
  720. "name" => "massaction",
  721. "value" => "close"
  722. ]);
  723. $selectedchoice = getDolGlobalInt('TICKET_NOTIFY_AT_CLOSING') ? "yes" : "no";
  724. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassTicketClosingSendEmail"), $langs->trans("ConfirmMassTicketClosingSendEmailQuestion"), 'confirm_send_close', $hidden_form, $selectedchoice, 0, 200, 500, 1);
  725. }
  726. if ($search_all) {
  727. $setupstring = '';
  728. foreach ($fieldstosearchall as $key => $val) {
  729. $fieldstosearchall[$key] = $langs->trans($val);
  730. $setupstring .= $key."=".$val.";";
  731. }
  732. print '<!-- Search done like if TICKET_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  733. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  734. }
  735. $moreforfilter = '';
  736. /*$moreforfilter.='<div class="divsearchfield">';
  737. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  738. $moreforfilter.= '</div>';*/
  739. $parameters = array();
  740. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  741. if (empty($reshook)) {
  742. $moreforfilter .= $hookmanager->resPrint;
  743. } else {
  744. $moreforfilter = $hookmanager->resPrint;
  745. }
  746. if (!empty($moreforfilter)) {
  747. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  748. print $moreforfilter;
  749. print '</div>';
  750. }
  751. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  752. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  753. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  754. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  755. print '<div class="div-table-responsive-inside">';
  756. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  757. // Fields title search
  758. // --------------------------------------------------------------------
  759. print '<tr class="liste_titre_filter">';
  760. // Action column
  761. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  762. print '<td class="liste_titre maxwidthsearch center">';
  763. $searchpicto = $form->showFilterButtons('left');
  764. print $searchpicto;
  765. print '</td>';
  766. }
  767. foreach ($object->fields as $key => $val) {
  768. $searchkey = empty($search[$key]) ? '' : $search[$key];
  769. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  770. if ($key == 'fk_statut') {
  771. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  772. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  773. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  774. } elseif (in_array($val['type'], array('timestamp'))) {
  775. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  776. } 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'])) {
  777. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  778. }
  779. if (!empty($arrayfields['t.'.$key]['checked'])) {
  780. if ($key == 'progress') {
  781. print '<td class="liste_titre right'.($cssforfield ? ' '.$cssforfield : '').'">';
  782. print '<input type="text" class="flat maxwidth50" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
  783. print '</td>';
  784. } elseif ($key == 'type_code') {
  785. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  786. $formTicket->selectTypesTickets(empty($search[$key]) ? '' : $search[$key], 'search_'.$key, '', 2, 1, 1, 0, (!empty($val['css']) ? $val['css'] : 'maxwidth150'), 1);
  787. print '</td>';
  788. } elseif ($key == 'category_code') {
  789. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  790. $formTicket->selectGroupTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key, '', 2, 1, 1, 0, (!empty($val['css']) ? $val['css'] : 'maxwidth150'));
  791. print '</td>';
  792. } elseif ($key == 'severity_code') {
  793. print '<td class="liste_titre center'.($cssforfield ? ' '.$cssforfield : '').'">';
  794. $formTicket->selectSeveritiesTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key, '', 2, 1, 1, 0, (!empty($val['css']) ? $val['css'] : 'maxwidth150'));
  795. print '</td>';
  796. } elseif ($key == 'fk_user_assign' || $key == 'fk_user_create') {
  797. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  798. print $form->select_dolusers((empty($search[$key]) ? '' : $search[$key]), 'search_'.$key, 1, null, 0, '', '', '0', 0, 0, '', 0, '', (!empty($val['css']) ? $val['css'] : 'maxwidth100'));
  799. print '</td>';
  800. } elseif ($key == 'fk_statut') {
  801. $arrayofstatus = array();
  802. $arrayofstatus['openall'] = '-- '.$langs->trans('OpenAll').' --';
  803. foreach ($object->labelStatusShort as $key2 => $val2) {
  804. if ($key2 == Ticket::STATUS_CLOSED) {
  805. $arrayofstatus['closeall'] = '-- '.$langs->trans('ClosedAll').' --';
  806. }
  807. $arrayofstatus[$key2] = $val2;
  808. }
  809. print '<td class="liste_titre center parentonrightofpage'.($cssforfield ? ' '.$cssforfield : '').'">';
  810. //var_dump($arrayofstatus);
  811. //var_dump($search['fk_statut']);
  812. //var_dump(array_values($search[$key]));
  813. $selectedarray = null;
  814. if (!empty($search[$key])) {
  815. $selectedarray = array_values($search[$key]);
  816. }
  817. print Form::multiselectarray('search_fk_statut', $arrayofstatus, $selectedarray, 0, 0, 'search_status width150 onrightofpage', 1, 0, '', '', '');
  818. print '</td>';
  819. } elseif ($key == "fk_soc") {
  820. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'"><input type="text" class="flat maxwidth75" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
  821. } elseif ($key == "datec" || $key == 'date_read' || $key == 'date_close') {
  822. print '<td class="liste_titre center">';
  823. print '<div class="nowrap">';
  824. switch ($key) {
  825. case 'datec':
  826. print $form->selectDate($search_date_start ?: -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Date_From"));
  827. break;
  828. case 'date_read':
  829. print $form->selectDate($search_dateread_start ?: -1, 'search_dateread_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Date_From"));
  830. break;
  831. case 'date_close':
  832. print $form->selectDate($search_dateclose_start ?: -1, 'search_dateclose_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Date_From"));
  833. }
  834. print '</div>';
  835. print '<div class="nowrap">';
  836. switch ($key) {
  837. case 'datec':
  838. print $form->selectDate($search_date_end ?: -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Date_To"));
  839. break;
  840. case 'date_read':
  841. print $form->selectDate($search_dateread_end ?: -1, 'search_dateread_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Date_To"));
  842. break;
  843. case 'date_close':
  844. print $form->selectDate($search_dateclose_end ?: -1, 'search_dateclose_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Date_To"));
  845. }
  846. print '</div>';
  847. print '</td>';
  848. } else {
  849. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  850. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  851. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  852. } elseif (strpos($val['type'], 'integer:') === 0) {
  853. print $object->showInputField($val, $key, !empty($search[$key]) ? $search[$key] : "", '', '', 'search_', 'maxwidth150', 1);
  854. } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
  855. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
  856. }
  857. print '</td>';
  858. }
  859. }
  860. }
  861. // Extra fields
  862. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  863. print '<td></td>';
  864. // Fields from hook
  865. $parameters = array('arrayfields'=>$arrayfields);
  866. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  867. print $hookmanager->resPrint;
  868. // Action column
  869. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  870. print '<td class="liste_titre center maxwidthsearch">';
  871. $searchpicto = $form->showFilterButtons();
  872. print $searchpicto;
  873. print '</td>';
  874. }
  875. print '</tr>'."\n";
  876. $totalarray = array();
  877. $totalarray['nbfield'] = 0;
  878. // Fields title label
  879. // --------------------------------------------------------------------
  880. print '<tr class="liste_titre">';
  881. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  882. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  883. $totalarray['nbfield']++;
  884. }
  885. foreach ($object->fields as $key => $val) {
  886. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  887. if ($key == 'fk_statut' || $key == 'severity_code') {
  888. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  889. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  890. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  891. } elseif (in_array($val['type'], array('timestamp'))) {
  892. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  893. } 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'])) {
  894. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  895. }
  896. $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
  897. if (!empty($arrayfields['t.'.$key]['checked'])) {
  898. 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";
  899. $totalarray['nbfield']++;
  900. }
  901. }
  902. // Extra fields
  903. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  904. print '<td>';
  905. print $langs->trans('Össz munkaidő (perc)');
  906. print '</td>';
  907. $totalarray['nbfield']++;
  908. // Hook fields
  909. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  910. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  911. print $hookmanager->resPrint;
  912. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  913. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  914. $totalarray['nbfield']++;
  915. }
  916. print '</tr>'."\n";
  917. // Detect if we need a fetch on each output line
  918. $needToFetchEachLine = 0;
  919. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  920. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  921. if (!is_null($val) && preg_match('/\$object/', $val)) {
  922. $needToFetchEachLine++; // There is at least one compute field that use $object
  923. }
  924. }
  925. }
  926. require_once DOL_DOCUMENT_ROOT.'/custom/ticketplus/class/actions_ticketplus.class.php';
  927. $at = new ActionsTicketPlus($db);
  928. $wt = [];
  929. $allIds = [];
  930. // Loop on record
  931. // --------------------------------------------------------------------
  932. $i = 0;
  933. $savnbfield = $totalarray['nbfield'];
  934. $totalarray = array();
  935. $totalarray['nbfield'] = 0;
  936. $imaxinloop = ($limit ? min($num, $limit) : $num);
  937. $cacheofoutputfield = array();
  938. while ($i < $imaxinloop) {
  939. $obj = $db->fetch_object($resql);
  940. if (empty($obj)) {
  941. break; // Should not happen
  942. }
  943. // Store properties in $object
  944. $object->setVarsFromFetchObj($obj);
  945. $object->type_code = $obj->type_code;
  946. $object->status = $object->fk_statut; // because field name is fk_statut
  947. if ($mode == 'kanban') {
  948. if ($i == 0) {
  949. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  950. print '<div class="box-flex-container kanban">';
  951. }
  952. // get infos needed from object
  953. // TODO Create a cache on users
  954. $arraydata = array();
  955. if ($obj->fk_user_assign > 0) {
  956. $user_temp->fetch($obj->fk_user_assign);
  957. $arraydata['user_assignment'] = $user_temp->getNomUrl(-3);
  958. }
  959. $arraydata['selected'] = in_array($object->id, $arrayofselected);
  960. // Output Kanban
  961. print $object->getKanbanView('', $arraydata);
  962. if ($i == ($imaxinloop - 1)) {
  963. print '</div>';
  964. print '</td></tr>';
  965. }
  966. }
  967. else {
  968. // Show here line of result
  969. $j = 0;
  970. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  971. // Action column
  972. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  973. print '<td class="nowrap center">';
  974. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  975. $selected = 0;
  976. if (in_array($object->id, $arrayofselected)) {
  977. $selected = 1;
  978. }
  979. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  980. }
  981. print '</td>';
  982. if (!$i) {
  983. $totalarray['nbfield']++;
  984. }
  985. }
  986. foreach ($object->fields as $key => $val) {
  987. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  988. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  989. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  990. }
  991. if (in_array($val['type'], array('timestamp'))) {
  992. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  993. }
  994. if (in_array($key, array('ref', 'fk_project'))) {
  995. $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
  996. }
  997. if ($key == 'fk_statut' || $key == 'severity_code') {
  998. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  999. }
  1000. if (!empty($arrayfields['t.'.$key]['checked'])) {
  1001. print '<td';
  1002. if ($cssforfield || (array_key_exists('css', $val) && $val['css'])) {
  1003. print ' class="';
  1004. }
  1005. print $cssforfield;
  1006. if ($cssforfield && array_key_exists('css', $val) && $val['css']) {
  1007. print ' ';
  1008. }
  1009. if (array_key_exists('css', $val)) {
  1010. print $val['css'];
  1011. }
  1012. if ($cssforfield || (array_key_exists('css', $val) && $val['css'])) {
  1013. print '"';
  1014. }
  1015. print '>';
  1016. if ($key == 'fk_statut') {
  1017. print $object->getLibStatut(5);
  1018. } elseif ($key == 'subject') {
  1019. $s = $obj->subject;
  1020. print '<span title="'.dol_escape_htmltag($s).'">';
  1021. print dol_escape_htmltag($s);
  1022. print '</span>';
  1023. } elseif ($key == 'type_code') {
  1024. $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code);
  1025. print '<span title="'.dol_escape_htmltag($s).'">';
  1026. print $s;
  1027. print '</span>';
  1028. } elseif ($key == 'category_code') {
  1029. $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code);
  1030. print '<span title="'.dol_escape_htmltag($s).'">';
  1031. print $s;
  1032. print '</span>';
  1033. } elseif ($key == 'severity_code') {
  1034. $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code);
  1035. print '<span title="'.dol_escape_htmltag($s).'">';
  1036. print $s;
  1037. print '</span>';
  1038. } elseif ($key == 'tms') {
  1039. print dol_print_date($db->jdate($obj->$key), 'dayhour', 'tzuser');
  1040. } elseif ($key == 'fk_user_create') {
  1041. if ($object->fk_user_create > 0) {
  1042. if (isset($conf->cache['user'][$object->fk_user_create])) {
  1043. $user_temp = $conf->cache['user'][$object->fk_user_create];
  1044. } else {
  1045. $user_temp = new User($db);
  1046. $user_temp->fetch($object->fk_user_create);
  1047. $conf->cache['user'][$object->fk_user_create] = $user_temp;
  1048. }
  1049. print $user_temp->getNomUrl(-1);
  1050. }
  1051. } elseif ($key == 'fk_user_assign') {
  1052. if ($object->fk_user_assign > 0) {
  1053. if (isset($conf->cache['user'][$object->fk_user_assign])) {
  1054. $user_temp = $conf->cache['user'][$object->fk_user_assign];
  1055. } else {
  1056. $user_temp = new User($db);
  1057. $user_temp->fetch($object->fk_user_assign);
  1058. $conf->cache['user'][$object->fk_user_assign] = $user_temp;
  1059. }
  1060. print $user_temp->getNomUrl(-1);
  1061. }
  1062. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  1063. print $object->showOutputField($val, $key, $db->jdate($obj->$key), '');
  1064. } elseif ($key == 'ref') {
  1065. print $object->showOutputField($val, $key, $obj->$key, '');
  1066. // display a warning on untreated tickets
  1067. $is_open = ($object->status != Ticket::STATUS_CLOSED && $object->status != Ticket::STATUS_CANCELED);
  1068. $should_show_warning = (getDolGlobalString('TICKET_DELAY_SINCE_LAST_RESPONSE') || getDolGlobalString('TICKET_DELAY_BEFORE_FIRST_RESPONSE'));
  1069. if ($is_open && $should_show_warning) {
  1070. $date_last_msg_sent = (int) $object->date_last_msg_sent;
  1071. $hour_diff = ($now - $date_last_msg_sent) / 3600 ;
  1072. if (!empty($conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE && $date_last_msg_sent == 0)) {
  1073. $creation_date = $object->datec;
  1074. $hour_diff_creation = ($now - $creation_date) / 3600 ;
  1075. if ($hour_diff_creation > $conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE) {
  1076. print " " . img_picto($langs->trans('Late') . ' : ' . $langs->trans('TicketsDelayForFirstResponseTooLong', $conf->global->TICKET_DELAY_BEFORE_FIRST_RESPONSE), 'warning', 'style="color: red;"', false, 0, 0, '', '');
  1077. }
  1078. } elseif (getDolGlobalString('TICKET_DELAY_SINCE_LAST_RESPONSE') && $hour_diff > $conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE) {
  1079. print " " . img_picto($langs->trans('Late') . ' : ' . $langs->trans('TicketsDelayFromLastResponseTooLong', $conf->global->TICKET_DELAY_SINCE_LAST_RESPONSE), 'warning');
  1080. }
  1081. }
  1082. } else { // Example: key=fk_soc, obj->key=123 val=array('type'=>'integer', ...
  1083. $tmp = explode(':', $val['type']);
  1084. if ($tmp[0] == 'integer' && !empty($tmp[1]) && class_exists($tmp[1])) {
  1085. // It is a type of an foreign field. We will try to reduce the number of fetch that the showOutputField is making.
  1086. //var_dump('eeee-'.$key.'-'.$obj->$key.'-'.$val['type']);
  1087. if ($key && $obj->$key && $val['type'] && array_key_exists($key.'-'.$obj->$key.'-'.$val['type'], $cacheofoutputfield)) {
  1088. $result = $cacheofoutputfield[$key.'-'.$obj->$key.'-'.$val['type']];
  1089. } else {
  1090. $result = $object->showOutputField($val, $key, $obj->$key, '');
  1091. $cacheofoutputfield[$key.'-'.$obj->$key.'-'.$val['type']] = $result;
  1092. }
  1093. } else {
  1094. $result = $object->showOutputField($val, $key, $obj->$key, '');
  1095. }
  1096. print $result;
  1097. }
  1098. print '</td>';
  1099. if (!$i) {
  1100. $totalarray['nbfield']++;
  1101. }
  1102. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  1103. if (!$i) {
  1104. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  1105. }
  1106. if (!isset($totalarray['val'])) {
  1107. $totalarray['val'] = array();
  1108. }
  1109. if (!isset($totalarray['val']['t.'.$key])) {
  1110. $totalarray['val']['t.'.$key] = 0;
  1111. }
  1112. $totalarray['val']['t.'.$key] += $object->$key;
  1113. }
  1114. }
  1115. }
  1116. // Extra fields
  1117. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1118. //Worktime
  1119. if(!isset($wt[$object->id])){
  1120. $ids = $at->getWorktimes($object->id);
  1121. array_shift($ids[3]);
  1122. $idArr = array_merge($ids[3],$ids[4]);
  1123. $tmp_wt = $at->sumActionWorktime($idArr);
  1124. foreach($idArr as $k=>$v){
  1125. $wt[$v] = [
  1126. 'wt'=>$tmp_wt,
  1127. 'lt'=>$ids[2]
  1128. ];
  1129. }
  1130. }
  1131. print '<td align="center" class="worktime" lastTicket="'.$wt[$object->id]['lt'].'">';
  1132. print $wt[$object->id]['wt'];
  1133. print '</td>';
  1134. if (!$i) {
  1135. $totalarray['nbfield']++;
  1136. }
  1137. // Fields from hook
  1138. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1139. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1140. print $hookmanager->resPrint;
  1141. // Action column
  1142. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1143. print '<td class="nowrap center">';
  1144. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1145. $selected = 0;
  1146. if (in_array($object->id, $arrayofselected)) {
  1147. $selected = 1;
  1148. }
  1149. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  1150. }
  1151. print '</td>';
  1152. }
  1153. if (!$i) {
  1154. $totalarray['nbfield']++;
  1155. }
  1156. print '</tr>'."\n";
  1157. }
  1158. $i++;
  1159. }
  1160. print '<script>$(function(){
  1161. $.each($(".worktime"),function(k,v){
  1162. idTicket = $(v).attr("lastticket");
  1163. if($(v).parent().attr("data-rowid") != idTicket){
  1164. $(v).parent().find("td[data-key=\'ticket.lastticket\']").eq(0).html(\'<a href="/ticket/card.php?id=\'+idTicket+\'"><i class="fas fa-solid fa-link"></i>\');
  1165. }
  1166. });
  1167. }); </script>';
  1168. // Show total line
  1169. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1170. // If no record found
  1171. if ($num == 0) {
  1172. $colspan = 1;
  1173. foreach ($arrayfields as $key => $val) {
  1174. if (!empty($val['checked'])) {
  1175. $colspan++;
  1176. }
  1177. }
  1178. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1179. }
  1180. $db->free($resql);
  1181. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1182. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  1183. print $hookmanager->resPrint;
  1184. print '</table>'."\n";
  1185. print '</div>'."\n";
  1186. print '</div>'."\n"; // end div-responsive-inside
  1187. print '</form>'."\n";
  1188. if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  1189. $hidegeneratedfilelistifempty = 1;
  1190. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1191. $hidegeneratedfilelistifempty = 0;
  1192. }
  1193. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  1194. $formfile = new FormFile($db);
  1195. // Show list of available documents
  1196. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1197. $urlsource .= str_replace('&amp;', '&', $param);
  1198. $filedir = $diroutputmassaction;
  1199. $genallowed = $permissiontoread;
  1200. $delallowed = $permissiontoadd;
  1201. print $formfile->showdocuments('massfilesarea_ticket', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1202. }
  1203. // End of page
  1204. llxFooter();
  1205. $db->close();
  1206. function getTpByNom($sqlNom,$getEntity){
  1207. global $db;
  1208. $ids = [];
  1209. $sql = "SELECT * FROM ".MAIN_DB_PREFIX."societe as s WHERE s.entity IN (".$getEntity.") ".$sqlNom;
  1210. $resql = $db->query($sql);
  1211. if ($resql) {
  1212. while($obj = $db->fetch_object($resql)){
  1213. if($obj->rowid){
  1214. $ids[] = $obj->rowid;
  1215. // print_r([$obj->rowid,$getEntity,$ids]);
  1216. getSubTp($obj->rowid,$getEntity,$ids);
  1217. }
  1218. }
  1219. }
  1220. return $ids;
  1221. }
  1222. function getSubTp($id,$getEntity,&$ids){
  1223. global $db;
  1224. $sql = "SELECT * FROM ".MAIN_DB_PREFIX."societe as s WHERE s.entity IN (".$getEntity.") AND s.parent = ".(int)$id;
  1225. $resql = $db->query($sql);
  1226. if ($resql) {
  1227. while($obj = $db->fetch_object($resql)){
  1228. if(!in_array($obj->rowid,$ids)){
  1229. $ids[] = $obj->rowid;
  1230. getSubTp($obj->rowid,$getEntity,$ids);
  1231. }
  1232. }
  1233. }
  1234. }