position_list.php 32 KB

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