job_list.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  4. * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
  5. * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
  6. * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/hrm/job_list.php
  23. * \ingroup hrm
  24. * \brief List page of jobs
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  31. // load hrm libraries
  32. require_once __DIR__.'/class/job.class.php';
  33. // for other modules
  34. //dol_include_once('/othermodule/class/otherobject.class.php');
  35. // Load translation files required by the page
  36. $langs->loadLangs(array('hrm', 'other'));
  37. // Get Parameters
  38. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  39. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  40. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  41. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  42. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  43. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  44. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'joblist'; // To manage different context of search
  45. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  46. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  47. $mode = GETPOST('mode', 'alpha'); // for view result with other mode
  48. $id = GETPOST('id', 'int');
  49. // Load variable for pagination
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  55. // If $page is not defined, or '' or -1 or if we click on clear filters
  56. $page = 0;
  57. }
  58. $offset = $limit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. // Initialize technical objects
  62. $object = new Job($db);
  63. $extrafields = new ExtraFields($db);
  64. $diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
  65. $hookmanager->initHooks(array('joblist')); // Note that conf->hooks_modules contains array
  66. // Fetch optionals attributes and labels
  67. $extrafields->fetch_name_optionals_label($object->table_element);
  68. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  69. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  70. // Default sort order (if not yet defined by previous GETPOST)
  71. if (!$sortfield) {
  72. reset($object->fields); // Reset is required to avoid key() to return null.
  73. $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  74. }
  75. if (!$sortorder) {
  76. $sortorder = "ASC";
  77. }
  78. // Initialize array of search criterias
  79. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  80. $search = array();
  81. foreach ($object->fields as $key => $val) {
  82. if (GETPOST('search_'.$key, 'alpha') !== '') {
  83. $search[$key] = GETPOST('search_'.$key, 'alpha');
  84. }
  85. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  86. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  87. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  88. }
  89. }
  90. // List of fields to search into when doing a "search in all"
  91. $fieldstosearchall = array();
  92. foreach ($object->fields as $key => $val) {
  93. if (!empty($val['searchall'])) {
  94. $fieldstosearchall['t.'.$key] = $val['label'];
  95. }
  96. }
  97. // Definition of array of fields for columns
  98. $arrayfields = array();
  99. foreach ($object->fields as $key => $val) {
  100. // If $val['visible']==0, then we never show the field
  101. if (!empty($val['visible'])) {
  102. $visible = (int) dol_eval($val['visible'], 1);
  103. $arrayfields['t.'.$key] = array(
  104. 'label'=>$val['label'],
  105. 'checked'=>(($visible < 0) ? 0 : 1),
  106. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  107. 'position'=>$val['position'],
  108. 'help'=> isset($val['help']) ? $val['help'] : ''
  109. );
  110. }
  111. }
  112. // Extra fields
  113. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  114. $object->fields = dol_sort_array($object->fields, 'position');
  115. $arrayfields = dol_sort_array($arrayfields, 'position');
  116. // Permissions
  117. $permissiontoread = $user->rights->hrm->all->read;
  118. $permissiontoadd = $user->rights->hrm->all->write;
  119. $permissiontodelete = $user->rights->hrm->all->delete;
  120. // Security check (enable the most restrictive one)
  121. if ($user->socid > 0) accessforbidden();
  122. //if ($user->socid > 0) accessforbidden();
  123. //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
  124. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  125. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  126. if (!isModEnabled('hrm')) {
  127. accessforbidden('Module hrm not enabled');
  128. }
  129. if (!$permissiontoread) accessforbidden();
  130. /*
  131. * Actions
  132. */
  133. if (GETPOST('cancel', 'alpha')) {
  134. $action = 'list';
  135. $massaction = '';
  136. }
  137. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  138. $massaction = '';
  139. }
  140. $parameters = array();
  141. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  142. if ($reshook < 0) {
  143. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  144. }
  145. if (empty($reshook)) {
  146. // Selection of new fields
  147. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  148. // Purge search criteria
  149. 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
  150. foreach ($object->fields as $key => $val) {
  151. $search[$key] = '';
  152. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  153. $search[$key.'_dtstart'] = '';
  154. $search[$key.'_dtend'] = '';
  155. }
  156. }
  157. $toselect = array();
  158. $search_array_options = array();
  159. }
  160. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  161. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  162. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  163. }
  164. // Mass actions
  165. $objectclass = 'Job';
  166. $objectlabel = 'Job';
  167. $uploaddir = $conf->hrm->dir_output;
  168. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  169. }
  170. /*
  171. * View
  172. */
  173. $form = new Form($db);
  174. $now = dol_now();
  175. //$help_url="EN:Module_Job|FR:Module_Job_FR|ES:Módulo_Job";
  176. $help_url = '';
  177. $title = $langs->trans("JobsProfiles");
  178. $morejs = array();
  179. $morecss = array();
  180. // Build and execute select
  181. // --------------------------------------------------------------------
  182. $sql = 'SELECT ';
  183. $sql .= $object->getFieldList('t');
  184. // Add fields from extrafields
  185. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  186. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  187. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  188. }
  189. }
  190. // Add fields from hooks
  191. $parameters = array();
  192. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  193. $sql .= $hookmanager->resPrint;
  194. $sql = preg_replace('/,\s*$/', '', $sql);
  195. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  196. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  197. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  198. }
  199. // Add table from hooks
  200. $parameters = array();
  201. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  202. $sql .= $hookmanager->resPrint;
  203. if ($object->ismultientitymanaged == 1) {
  204. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  205. } else {
  206. $sql .= " WHERE 1 = 1";
  207. }
  208. foreach ($search as $key => $val) {
  209. if (array_key_exists($key, $object->fields)) {
  210. if ($key == 'status' && $search[$key] == -1) {
  211. continue;
  212. }
  213. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  214. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  215. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  216. $search[$key] = '';
  217. }
  218. $mode_search = 2;
  219. }
  220. if ($search[$key] != '') {
  221. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  222. }
  223. } else {
  224. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  225. $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
  226. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  227. if (preg_match('/_dtstart$/', $key)) {
  228. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  229. }
  230. if (preg_match('/_dtend$/', $key)) {
  231. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  232. }
  233. }
  234. }
  235. }
  236. }
  237. if ($search_all) {
  238. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  239. }
  240. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  241. // Add where from extra fields
  242. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  243. // Add where from hooks
  244. $parameters = array();
  245. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  246. $sql .= $hookmanager->resPrint;
  247. /* If a group by is required
  248. $sql .= " GROUP BY ";
  249. foreach($object->fields as $key => $val) {
  250. $sql .= "t.".$db->escape($key).", ";
  251. }
  252. // Add fields from extrafields
  253. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  254. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  255. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  256. }
  257. }
  258. // Add where from hooks
  259. $parameters = array();
  260. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  261. $sql .= $hookmanager->resPrint;
  262. $sql = preg_replace('/,\s*$/', '', $sql);
  263. */
  264. // Count total nb of records
  265. $nbtotalofrecords = '';
  266. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  267. $resql = $db->query($sql);
  268. $nbtotalofrecords = $db->num_rows($resql);
  269. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  270. $page = 0;
  271. $offset = 0;
  272. }
  273. $db->free($resql);
  274. }
  275. // Complete request and execute it with limit
  276. $sql .= $db->order($sortfield, $sortorder);
  277. if ($limit) {
  278. $sql .= $db->plimit($limit + 1, $offset);
  279. }
  280. $resql = $db->query($sql);
  281. if (!$resql) {
  282. dol_print_error($db);
  283. exit;
  284. }
  285. $num = $db->num_rows($resql);
  286. // Direct jump if only one record found
  287. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  288. $obj = $db->fetch_object($resql);
  289. $id = $obj->rowid;
  290. header("Location: ".dol_buildpath('/hrm/job_card.php', 1).'?id='.$id);
  291. exit;
  292. }
  293. // Output page
  294. // --------------------------------------------------------------------
  295. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
  296. // Example : Adding jquery code
  297. // print '<script type="text/javascript" language="javascript">
  298. // jQuery(document).ready(function() {
  299. // function init_myfunc()
  300. // {
  301. // jQuery("#myid").removeAttr(\'disabled\');
  302. // jQuery("#myid").attr(\'disabled\',\'disabled\');
  303. // }
  304. // init_myfunc();
  305. // jQuery("#mybutton").click(function() {
  306. // init_myfunc();
  307. // });
  308. // });
  309. // </script>';
  310. $arrayofselected = is_array($toselect) ? $toselect : array();
  311. $param = '';
  312. if (!empty($mode)) {
  313. $param .= '&mode='.urlencode($mode);
  314. }
  315. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  316. $param .= '&contextpage='.urlencode($contextpage);
  317. }
  318. if ($limit > 0 && $limit != $conf->liste_limit) {
  319. $param .= '&limit='.((int) $limit);
  320. }
  321. foreach ($search as $key => $val) {
  322. if (is_array($search[$key])) {
  323. foreach ($search[$key] as $skey) {
  324. if ($skey != '') {
  325. $param .= '&search_'.$key.'[]='.urlencode($skey);
  326. }
  327. }
  328. } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
  329. $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
  330. $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
  331. $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
  332. } elseif ($search[$key] != '') {
  333. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  334. }
  335. }
  336. if ($optioncss != '') {
  337. $param .= '&optioncss='.urlencode($optioncss);
  338. }
  339. // Add $param from extra fields
  340. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  341. // Add $param from hooks
  342. $parameters = array();
  343. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  344. $param .= $hookmanager->resPrint;
  345. // List of mass actions available
  346. $arrayofmassactions = array(
  347. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  348. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  349. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  350. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  351. );
  352. if (!empty($permissiontodelete)) {
  353. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  354. }
  355. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  356. $arrayofmassactions = array();
  357. }
  358. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  359. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  360. if ($optioncss != '') {
  361. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  362. }
  363. print '<input type="hidden" name="token" value="'.newToken().'">';
  364. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  365. print '<input type="hidden" name="action" value="list">';
  366. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  367. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  368. print '<input type="hidden" name="page" value="'.$page.'">';
  369. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  370. print '<input type="hidden" name="mode" value="'.$mode.'">';
  371. $newcardbutton = '';
  372. $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'));
  373. $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'));
  374. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/hrm/job_card.php', 1).'?action=create', '', $permissiontoadd);
  375. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  376. // Add code for pre mass action (confirmation or email presend form)
  377. $topicmail = "SendJobRef";
  378. $modelmail = "job";
  379. $objecttmp = new Job($db);
  380. $trackid = 'xxxx'.$object->id;
  381. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  382. if ($search_all) {
  383. $setupstring = '';
  384. foreach ($fieldstosearchall as $key => $val) {
  385. $fieldstosearchall[$key] = $langs->trans($val);
  386. $setupstring .= $key."=".$val.";";
  387. }
  388. print '<!-- Search done like if JOBPOSITION_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  389. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  390. }
  391. $moreforfilter = '';
  392. /*$moreforfilter.='<div class="divsearchfield">';
  393. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  394. $moreforfilter.= '</div>';*/
  395. $parameters = array();
  396. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  397. if (empty($reshook)) {
  398. $moreforfilter .= $hookmanager->resPrint;
  399. } else {
  400. $moreforfilter = $hookmanager->resPrint;
  401. }
  402. if (!empty($moreforfilter)) {
  403. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  404. print $moreforfilter;
  405. print '</div>';
  406. }
  407. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  408. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  409. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  410. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  411. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  412. // Fields title search
  413. // --------------------------------------------------------------------
  414. print '<tr class="liste_titre">';
  415. // Action column
  416. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  417. print '<td class="liste_titre maxwidthsearch">';
  418. $searchpicto = $form->showFilterButtons('left');
  419. print $searchpicto;
  420. print '</td>';
  421. }
  422. foreach ($object->fields as $key => $val) {
  423. $searchkey = empty($search[$key]) ? '' : $search[$key];
  424. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  425. if ($key == 'status') {
  426. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  427. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  428. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  429. } elseif (in_array($val['type'], array('timestamp'))) {
  430. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  431. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  432. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  433. }
  434. if (!empty($arrayfields['t.'.$key]['checked'])) {
  435. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  436. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  437. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  438. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  439. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth125', 1);
  440. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  441. print '<div class="nowrap">';
  442. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  443. print '</div>';
  444. print '<div class="nowrap">';
  445. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  446. print '</div>';
  447. } elseif ($key == 'lang') {
  448. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  449. $formadmin = new FormAdmin($db);
  450. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  451. } else {
  452. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  453. }
  454. print '</td>';
  455. }
  456. }
  457. // Extra fields
  458. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  459. // Fields from hook
  460. $parameters = array('arrayfields'=>$arrayfields);
  461. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  462. print $hookmanager->resPrint;
  463. // Action column
  464. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  465. print '<td class="liste_titre maxwidthsearch">';
  466. $searchpicto = $form->showFilterButtons();
  467. print $searchpicto;
  468. print '</td>';
  469. }
  470. print '</tr>'."\n";
  471. $totalarray = array();
  472. $totalarray['nbfield'] = 0;
  473. // Fields title label
  474. // --------------------------------------------------------------------
  475. print '<tr class="liste_titre">';
  476. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  477. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  478. }
  479. foreach ($object->fields as $key => $val) {
  480. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  481. if ($key == 'status') {
  482. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  483. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  484. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  485. } elseif (in_array($val['type'], array('timestamp'))) {
  486. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  487. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  488. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  489. }
  490. $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
  491. if (!empty($arrayfields['t.'.$key]['checked'])) {
  492. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  493. $totalarray['nbfield']++;
  494. }
  495. }
  496. // Extra fields
  497. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  498. // Hook fields
  499. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  500. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  501. print $hookmanager->resPrint;
  502. // Action column
  503. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  504. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  505. }
  506. $totalarray['nbfield']++;
  507. print '</tr>'."\n";
  508. // Detect if we need a fetch on each output line
  509. $needToFetchEachLine = 0;
  510. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  511. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  512. if (preg_match('/\$object/', $val)) {
  513. $needToFetchEachLine++; // There is at least one compute field that use $object
  514. }
  515. }
  516. }
  517. // Loop on record
  518. // --------------------------------------------------------------------
  519. $i = 0;
  520. $savnbfield = $totalarray['nbfield'];
  521. $totalarray = array();
  522. $totalarray['nbfield'] = 0;
  523. $imaxinloop = ($limit ? min($num, $limit) : $num);
  524. while ($i < $imaxinloop) {
  525. $obj = $db->fetch_object($resql);
  526. if (empty($obj)) {
  527. break; // Should not happen
  528. }
  529. // Store properties in $object
  530. $object->setVarsFromFetchObj($obj);
  531. if ($mode == 'kanban') {
  532. $object->deplacement = $obj->deplacement;
  533. $object->description = $obj->description;
  534. if ($i == 0) {
  535. print '<tr><td colspan="'.$savnbfield.'">';
  536. print '<div class="box-flex-container kanban">';
  537. }
  538. // Output Kanban
  539. print $object->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected)));
  540. if ($i == ($imaxinloop - 1)) {
  541. print '</div>';
  542. print '</td></tr>';
  543. }
  544. } else {
  545. // Show here line of result
  546. $j = 0;
  547. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  548. // Action column
  549. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  550. print '<td class="nowrap center">';
  551. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  552. $selected = 0;
  553. if (in_array($object->id, $arrayofselected)) {
  554. $selected = 1;
  555. }
  556. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  557. }
  558. print '</td>';
  559. }
  560. foreach ($object->fields as $key => $val) {
  561. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  562. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  563. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  564. } elseif ($key == 'status') {
  565. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  566. }
  567. if (in_array($val['type'], array('timestamp'))) {
  568. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  569. } elseif ($key == 'ref') {
  570. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  571. }
  572. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  573. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  574. }
  575. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  576. if (!empty($arrayfields['t.'.$key]['checked'])) {
  577. print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
  578. if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($object->$key)) {
  579. print ' title="'.dol_escape_htmltag($object->$key).'"';
  580. }
  581. print '>';
  582. if ($key == 'status') {
  583. print $object->getLibStatut(5);
  584. } elseif ($key == 'rowid') {
  585. print $object->showOutputField($val, $key, $object->id, '');
  586. } elseif ($key == 'label') {
  587. print $object->getNomUrl(1);
  588. } else {
  589. print $object->showOutputField($val, $key, $object->$key, '');
  590. }
  591. print '</td>';
  592. if (!$i) {
  593. $totalarray['nbfield']++;
  594. }
  595. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  596. if (!$i) {
  597. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  598. }
  599. if (!isset($totalarray['val'])) {
  600. $totalarray['val'] = array();
  601. }
  602. if (!isset($totalarray['val']['t.'.$key])) {
  603. $totalarray['val']['t.'.$key] = 0;
  604. }
  605. $totalarray['val']['t.'.$key] += $object->$key;
  606. }
  607. }
  608. }
  609. // Extra fields
  610. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  611. // Fields from hook
  612. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  613. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  614. print $hookmanager->resPrint;
  615. // Action column
  616. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  617. print '<td class="nowrap center">';
  618. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  619. $selected = 0;
  620. if (in_array($object->id, $arrayofselected)) {
  621. $selected = 1;
  622. }
  623. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  624. }
  625. print '</td>';
  626. }
  627. if (!$i) {
  628. $totalarray['nbfield']++;
  629. }
  630. print '</tr>'."\n";
  631. }
  632. $i++;
  633. }
  634. // Show total line
  635. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  636. // If no record found
  637. if ($num == 0) {
  638. $colspan = 1;
  639. foreach ($arrayfields as $key => $val) {
  640. if (!empty($val['checked'])) {
  641. $colspan++;
  642. }
  643. }
  644. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  645. }
  646. $db->free($resql);
  647. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  648. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  649. print $hookmanager->resPrint;
  650. print '</table>'."\n";
  651. print '</div>'."\n";
  652. print '</form>'."\n";
  653. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  654. $hidegeneratedfilelistifempty = 1;
  655. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  656. $hidegeneratedfilelistifempty = 0;
  657. }
  658. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  659. $formfile = new FormFile($db);
  660. // Show list of available documents
  661. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  662. $urlsource .= str_replace('&amp;', '&', $param);
  663. $filedir = $diroutputmassaction;
  664. $genallowed = $permissiontoread;
  665. $delallowed = $permissiontoadd;
  666. print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  667. }
  668. // End of page
  669. llxFooter();
  670. $db->close();