position_list.php 31 KB

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