position_list.php 33 KB

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