position.php 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  1. <?php
  2. /* Copyright (C) 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.php
  23. * \ingroup hrm
  24. * \brief Page to create/edit/view position
  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/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/hrm/class/position.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_position.lib.php';
  34. require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
  35. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  36. require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
  37. // Load translation files required by the page
  38. $langs->loadLangs(array("hrm", "other", 'products'));
  39. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  40. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  41. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  42. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  43. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  44. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  45. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'jobpositionlist'; // To manage different context of search
  46. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  47. $id = GETPOST('id', 'int');
  48. $fk_job = GETPOST('fk_job', 'int');
  49. // Load variable for pagination
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  55. // If $page is not defined, or '' or -1 or if we click on clear filters
  56. $page = 0;
  57. }
  58. $offset = $limit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. // Get parameters
  62. $id = GETPOST('fk_job', 'int');
  63. $ref = GETPOST('ref', 'alpha');
  64. $fk_job = GETPOST('fk_job', 'int');
  65. $fk_user = GETPOST('fk_user', 'int');
  66. //$start_date = date('Y-m-d', GETPOST('date_startyear', 'int').'-'.GETPOST('date_startmonth', 'int').'-'.GETPOST('date_startday', 'int'));
  67. $start_date = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
  68. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  69. $backtopage = GETPOST('backtopage', 'alpha');
  70. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  71. $fk_job = GETPOST('fk_job', 'int');
  72. // Initialize technical objects
  73. $object = new Job($db);
  74. $objectposition = new Position($db);
  75. $extrafields = new ExtraFields($db);
  76. $diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
  77. $hookmanager->initHooks(array('jobpositionlist', 'globalcard')); // Note that conf->hooks_modules contains array
  78. // Fetch optionals attributes and labels
  79. $extrafields->fetch_name_optionals_label($objectposition->table_element);
  80. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  81. $search_array_options = $extrafields->getOptionalsFromPost($objectposition->table_element, '', 'search_');
  82. // Default sort order (if not yet defined by previous GETPOST)
  83. if (!$sortfield) {
  84. reset($objectposition->fields); // Reset is required to avoid key() to return null.
  85. $sortfield = "t." . key($objectposition->fields); // Set here default search field. By default 1st field in definition.
  86. }
  87. if (!$sortorder) {
  88. $sortorder = "ASC";
  89. }
  90. // Initialize array of search criterias
  91. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  92. $search = array();
  93. foreach ($objectposition->fields as $key => $val) {
  94. if (GETPOST('search_' . $key, 'alpha') !== '') {
  95. $search[$key] = GETPOST('search_' . $key, 'alpha');
  96. }
  97. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  98. $search[$key . '_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_' . $key . '_dtstartmonth', 'int'), GETPOST('search_' . $key . '_dtstartday', 'int'), GETPOST('search_' . $key . '_dtstartyear', 'int'));
  99. $search[$key . '_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_' . $key . '_dtendmonth', 'int'), GETPOST('search_' . $key . '_dtendday', 'int'), GETPOST('search_' . $key . '_dtendyear', 'int'));
  100. }
  101. }
  102. // List of fields to search into when doing a "search in all"
  103. $fieldstosearchall = array();
  104. foreach ($objectposition->fields as $key => $val) {
  105. if (!empty($val['searchall'])) {
  106. $fieldstosearchall['t.' . $key] = $val['label'];
  107. }
  108. }
  109. // Definition of array of fields for columns
  110. $arrayfields = array();
  111. foreach ($objectposition->fields as $key => $val) {
  112. // If $val['visible']==0, then we never show the field
  113. if (!empty($val['visible'])) {
  114. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  115. $arrayfields['t.' . $key] = array(
  116. 'label' => $val['label'],
  117. 'checked' => (($visible < 0) ? 0 : 1),
  118. 'enabled' => ($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  119. 'position' => $val['position'],
  120. 'help' => isset($val['help']) ? $val['help'] : ''
  121. );
  122. }
  123. }
  124. // Extra fields
  125. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
  126. $objectposition->fields = dol_sort_array($objectposition->fields, 'position');
  127. $arrayfields = dol_sort_array($arrayfields, 'position');
  128. // Load object
  129. include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  130. // Permissions
  131. $permissiontoread = $user->rights->hrm->all->read;
  132. $permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  133. $permissiontodelete = $user->rights->hrm->all->delete;
  134. $upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/position';
  135. // Security check (enable the most restrictive one)
  136. //if ($user->socid > 0) accessforbidden();
  137. //if ($user->socid > 0) $socid = $user->socid;
  138. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  139. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  140. if (empty($conf->hrm->enabled)) accessforbidden();
  141. if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
  142. /*
  143. * Actions
  144. */
  145. $parameters = array();
  146. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  147. if ($reshook < 0) {
  148. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  149. }
  150. if (empty($reshook)) {
  151. $error = 0;
  152. $backurlforlist = dol_buildpath('/hrm/position_list.php', 1);
  153. //$backtopage = dol_buildpath('/hrm/position.php', 1) . '?fk_job=' . ($fk_job > 0 ? $fk_job : '__ID__');
  154. if (empty($backtopage) || ($cancel && $fk_job <= 0)) {
  155. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  156. if ($fk_job == -1 && (($action != 'add' && $action != 'create') || $cancel)) {
  157. $backtopage = $backurlforlist;
  158. } else {
  159. if ($fk_job > 0) {
  160. $backtopage = dol_buildpath('/hrm/position.php', 1) . '?fk_job=' . ($fk_job > 0 ? $fk_job : '__ID__');
  161. } else {
  162. $backtopage = dol_buildpath('/hrm/position_card.php', 1) . '?id=__ID__';
  163. }
  164. }
  165. }
  166. }
  167. $triggermodname = 'HRM_POSITION_MODIFY'; // Name of trigger action code to execute when we modify record
  168. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  169. $job = $object;
  170. $object = new Position($db);
  171. // Selection of new fields
  172. include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
  173. // Purge search criteria
  174. 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
  175. foreach ($object->fields as $key => $val) {
  176. $search[$key] = '';
  177. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  178. $search[$key . '_dtstart'] = '';
  179. $search[$key . '_dtend'] = '';
  180. }
  181. }
  182. $toselect = array();
  183. $search_array_options = array();
  184. }
  185. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  186. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  187. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  188. }
  189. // Mass actions
  190. $objectclass = 'Position';
  191. $objectlabel = 'Position';
  192. $uploaddir = $conf->hrm->dir_output;
  193. include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php';
  194. include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
  195. $object = $job;
  196. }
  197. /*
  198. * View
  199. */
  200. $title = $langs->trans("Position");
  201. $help_url = '';
  202. llxHeader('', $title, $help_url);
  203. $now = dol_now();
  204. // Part to create
  205. if ($action == 'create') {
  206. $object = new Position($db);
  207. // Fetch optionals attributes and labels
  208. $extrafields->fetch_name_optionals_label($object->table_element);
  209. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Position")), '', 'object_' . $object->picto);
  210. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  211. print '<input type="hidden" name="token" value="' . newToken() . '">';
  212. print '<input type="hidden" name="action" value="add">';
  213. if ($backtopage) {
  214. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  215. }
  216. if ($backtopageforcancel) {
  217. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  218. }
  219. print dol_get_fiche_head(array(), '');
  220. print '<table class="border centpercent tableforfieldcreate">' . "\n";
  221. // Common attributes
  222. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
  223. // Other attributes
  224. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
  225. print '</table>' . "\n";
  226. print dol_get_fiche_end();
  227. print '<div class="center">';
  228. print '<input type="submit" class="button" name="add" value="' . dol_escape_htmltag($langs->trans("Create")) . '">';
  229. print '&nbsp; ';
  230. print '<input type="' . ($backtopage ? "submit" : "button") . '" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag($langs->trans("Cancel")) . '"' . ($backtopage ? '' : ' onclick="history.go(-1)"') . '>'; // Cancel for create does not post form if we don't know the backtopage
  231. print '</div>';
  232. print '</form>';
  233. //dol_set_focus('input[name="ref"]');
  234. }
  235. if ($job->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  236. if ($backtopage) {
  237. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  238. }
  239. if ($backtopageforcancel) {
  240. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  241. }
  242. // Part to show record
  243. $res = $object->fetch_optionals();
  244. $head = jobPrepareHead($object);
  245. print dol_get_fiche_head($head, 'position', $langs->trans("Workstation"), -1, $object->picto);
  246. // Object card
  247. // ------------------------------------------------------------
  248. $linkback = '<a href="' . dol_buildpath('/hrm/position_list.php', 1) . '?restore_lastsearch_values=1' . (!empty($fk_job) ? '&fk_job=' . $fk_job : '') . '">' . $langs->trans("BackToList") . '</a>';
  249. $morehtmlref = '<div class="refid">';
  250. $morehtmlref.= $object->label;
  251. $morehtmlref .= '</div>';
  252. dol_banner_tab($object, 'fk_job', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  253. print '<div class="fichecenter">';
  254. print '<div class="fichehalfleft">';
  255. print '<div class="underbanner clearboth"></div>';
  256. print '<table class="border centpercent tableforfield">' . "\n";
  257. // Common attributes
  258. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
  259. //unset($object->fields['fk_project']); // Hide field already shown in banner
  260. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  261. $object->fields['label']['visible']=0; // Already in banner
  262. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
  263. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  264. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  265. print '</table>';
  266. print '</div>';
  267. print '</div>';
  268. print '<div class="clearboth"></div>';
  269. print dol_get_fiche_end();
  270. // List of positions
  271. $object = $objectposition;
  272. //$help_url="EN:Module_Position|FR:Module_Position_FR|ES:Módulo_Position";
  273. $help_url = '';
  274. $title = $langs->trans("Positions");
  275. $morejs = array();
  276. $morecss = array();
  277. // Build and execute select
  278. // --------------------------------------------------------------------
  279. $sql = 'SELECT ';
  280. $sql .= $object->getFieldList('t');
  281. // Add fields from extrafields
  282. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  283. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  284. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef." . $key . " as options_" . $key . ', ' : '');
  285. }
  286. }
  287. // Add fields from hooks
  288. $parameters = array();
  289. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  290. $sql .= $hookmanager->resPrint;
  291. $sql = preg_replace('/,\s*$/', '', $sql);
  292. $sql .= " FROM " . MAIN_DB_PREFIX . $object->table_element . " as t";
  293. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  294. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
  295. }
  296. // Add table from hooks
  297. $parameters = array();
  298. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  299. $sql .= $hookmanager->resPrint;
  300. if ($object->ismultientitymanaged == 1) {
  301. $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ")";
  302. } else {
  303. $sql .= " WHERE 1 = 1";
  304. }
  305. $sql .= " AND t.fk_job = " . ((int) $fk_job) . " ";
  306. foreach ($search as $key => $val) {
  307. if (array_key_exists($key, $object->fields)) {
  308. if ($key == 'status' && $search[$key] == -1) {
  309. continue;
  310. }
  311. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  312. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  313. if ($search[$key] == '-1' || $search[$key] === '0') {
  314. $search[$key] = '';
  315. }
  316. $mode_search = 2;
  317. }
  318. if ($search[$key] != '') {
  319. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  320. }
  321. } else {
  322. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  323. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  324. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  325. if (preg_match('/_dtstart$/', $key)) {
  326. $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
  327. }
  328. if (preg_match('/_dtend$/', $key)) {
  329. $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
  330. }
  331. }
  332. }
  333. }
  334. }
  335. if ($search_all) {
  336. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  337. }
  338. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  339. // Add where from extra fields
  340. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
  341. // Add where from hooks
  342. $parameters = array();
  343. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  344. $sql .= $hookmanager->resPrint;
  345. $sql .= $db->order($sortfield, $sortorder);
  346. // Count total nb of records
  347. $nbtotalofrecords = '';
  348. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  349. $resql = $db->query($sql);
  350. $nbtotalofrecords = $db->num_rows($resql);
  351. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  352. $page = 0;
  353. $offset = 0;
  354. }
  355. }
  356. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  357. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  358. $num = $nbtotalofrecords;
  359. } else {
  360. if ($limit) {
  361. $sql .= $db->plimit($limit + 1, $offset);
  362. }
  363. $resql = $db->query($sql);
  364. if (!$resql) {
  365. dol_print_error($db);
  366. exit;
  367. }
  368. $num = $db->num_rows($resql);
  369. }
  370. // Direct jump if only one record found
  371. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  372. $obj = $db->fetch_object($resql);
  373. $id = $obj->rowid;
  374. header("Location: " . dol_buildpath('/hrm/position.php', 1) . '?id=' . $id);
  375. exit;
  376. }
  377. $arrayofselected = is_array($toselect) ? $toselect : array();
  378. $param = 'fk_job=' . $fk_job;
  379. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  380. $param .= '&contextpage=' . urlencode($contextpage);
  381. }
  382. if ($limit > 0 && $limit != $conf->liste_limit) {
  383. $param .= '&limit='.((int) $limit);
  384. }
  385. foreach ($search as $key => $val) {
  386. if (is_array($search[$key]) && count($search[$key])) {
  387. foreach ($search[$key] as $skey) {
  388. $param .= '&search_' . $key . '[]=' . urlencode($skey);
  389. }
  390. } else {
  391. $param .= '&search_' . $key . '=' . urlencode($search[$key]);
  392. }
  393. }
  394. if ($optioncss != '') {
  395. $param .= '&optioncss=' . urlencode($optioncss);
  396. }
  397. // Add $param from extra fields
  398. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
  399. // Add $param from hooks
  400. $parameters = array();
  401. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  402. $param .= $hookmanager->resPrint;
  403. // List of mass actions available
  404. $arrayofmassactions = array(
  405. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  406. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  407. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  408. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  409. );
  410. if ($permissiontodelete) {
  411. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"') . $langs->trans("Delete");
  412. }
  413. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  414. $arrayofmassactions = array();
  415. }
  416. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  417. print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '?fk_job=' . $fk_job . '">' . "\n";
  418. if ($optioncss != '') {
  419. print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
  420. }
  421. print '<input type="hidden" name="token" value="' . newToken() . '">';
  422. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  423. print '<input type="hidden" name="action" value="list">';
  424. print '<input type="hidden" name="massaction" value="' . $massaction . '">';
  425. print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
  426. print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
  427. print '<input type="hidden" name="page" value="' . $page . '">';
  428. print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';
  429. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/hrm/position.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']).'&fk_job='.((int) $fk_job), '', $permissiontoadd);
  430. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_' . $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  431. // Add code for pre mass action (confirmation or email presend form)
  432. $topicmail = "SendPositionRef";
  433. $modelmail = "position";
  434. $objecttmp = new Position($db);
  435. $trackid = 'xxxx' . $object->id;
  436. include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php';
  437. if ($search_all) {
  438. foreach ($fieldstosearchall as $key => $val) {
  439. $fieldstosearchall[$key] = $langs->trans($val);
  440. }
  441. print '<div class="divsearchfieldfilter">' . $langs->trans("FilterOnInto", $search_all) . join(', ', $fieldstosearchall) . '</div>';
  442. }
  443. $moreforfilter = '';
  444. /*$moreforfilter.='<div class="divsearchfield">';
  445. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  446. $moreforfilter.= '</div>';*/
  447. $parameters = array();
  448. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  449. if (empty($reshook)) {
  450. $moreforfilter .= $hookmanager->resPrint;
  451. } else {
  452. $moreforfilter = $hookmanager->resPrint;
  453. }
  454. if (!empty($moreforfilter)) {
  455. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  456. print $moreforfilter;
  457. print '</div>';
  458. }
  459. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  460. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  461. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  462. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  463. print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
  464. // Fields title search
  465. // --------------------------------------------------------------------
  466. print '<tr class="liste_titre">';
  467. foreach ($object->fields as $key => $val) {
  468. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  469. if ($key == 'status') {
  470. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  471. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  472. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  473. } elseif (in_array($val['type'], array('timestamp'))) {
  474. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  475. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  476. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  477. }
  478. if (!empty($arrayfields['t.' . $key]['checked'])) {
  479. print '<td class="liste_titre' . ($cssforfield ? ' ' . $cssforfield : '') . '">';
  480. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  481. print $form->selectarray('search_' . $key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  482. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  483. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  484. } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  485. print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '') . '">';
  486. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  487. print '<div class="nowrap">';
  488. print $form->selectDate($search[$key . '_dtstart'] ? $search[$key . '_dtstart'] : '', "search_" . $key . "_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  489. print '</div>';
  490. print '<div class="nowrap">';
  491. print $form->selectDate($search[$key . '_dtend'] ? $search[$key . '_dtend'] : '', "search_" . $key . "_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  492. print '</div>';
  493. }
  494. print '</td>';
  495. }
  496. }
  497. // Extra fields
  498. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
  499. // Fields from hook
  500. $parameters = array('arrayfields' => $arrayfields);
  501. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  502. print $hookmanager->resPrint;
  503. // Action column
  504. print '<td class="liste_titre maxwidthsearch">';
  505. $searchpicto = $form->showFilterButtons();
  506. print $searchpicto;
  507. print '</td>';
  508. print '</tr>' . "\n";
  509. // Fields title label
  510. // --------------------------------------------------------------------
  511. print '<tr class="liste_titre">';
  512. foreach ($object->fields as $key => $val) {
  513. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  514. if ($key == 'status') {
  515. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  516. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  517. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  518. } elseif (in_array($val['type'], array('timestamp'))) {
  519. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  520. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  521. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  522. }
  523. if (!empty($arrayfields['t.' . $key]['checked'])) {
  524. print getTitleFieldOfList($arrayfields['t.' . $key]['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : '')) . "\n";
  525. }
  526. }
  527. // Extra fields
  528. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
  529. // Hook fields
  530. $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
  531. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  532. print $hookmanager->resPrint;
  533. // Action column
  534. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n";
  535. print '</tr>' . "\n";
  536. // Detect if we need a fetch on each output line
  537. $needToFetchEachLine = 0;
  538. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  539. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  540. if (preg_match('/\$object/', $val)) {
  541. $needToFetchEachLine++; // There is at least one compute field that use $object
  542. }
  543. }
  544. }
  545. // Loop on record
  546. // --------------------------------------------------------------------
  547. $i = 0;
  548. $totalarray = array();
  549. $totalarray['nbfield'] = 0;
  550. while ($i < ($limit ? min($num, $limit) : $num)) {
  551. $obj = $db->fetch_object($resql);
  552. if (empty($obj)) {
  553. break; // Should not happen
  554. }
  555. // Store properties in $object
  556. $object->setVarsFromFetchObj($obj);
  557. // Show here line of result
  558. print '<tr class="oddeven">';
  559. foreach ($object->fields as $key => $val) {
  560. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  561. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  562. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  563. } elseif ($key == 'status') {
  564. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  565. }
  566. if (in_array($val['type'], array('timestamp'))) {
  567. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  568. } elseif ($key == 'ref') {
  569. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  570. }
  571. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  572. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  573. }
  574. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  575. if (!empty($arrayfields['t.' . $key]['checked'])) {
  576. print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '') . '>';
  577. if ($key == 'status') {
  578. print $object->getLibStatut(5);
  579. } elseif ($key == 'rowid') {
  580. print $object->getNomUrl(1);
  581. } else {
  582. print $object->showOutputField($val, $key, $object->$key, '');
  583. }
  584. print '</td>';
  585. if (!$i) {
  586. $totalarray['nbfield']++;
  587. }
  588. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  589. if (!$i) {
  590. $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key;
  591. }
  592. if (!isset($totalarray['val'])) {
  593. $totalarray['val'] = array();
  594. }
  595. if (!isset($totalarray['val']['t.' . $key])) {
  596. $totalarray['val']['t.' . $key] = 0;
  597. }
  598. $totalarray['val']['t.' . $key] += $object->$key;
  599. }
  600. }
  601. }
  602. // Extra fields
  603. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php';
  604. // Fields from hook
  605. $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
  606. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  607. print $hookmanager->resPrint;
  608. // Action column
  609. print '<td class="nowrap center">';
  610. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  611. $selected = 0;
  612. if (in_array($object->id, $arrayofselected)) {
  613. $selected = 1;
  614. }
  615. print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  616. }
  617. print '</td>';
  618. if (!$i) {
  619. $totalarray['nbfield']++;
  620. }
  621. print '</tr>' . "\n";
  622. $i++;
  623. }
  624. // Show total line
  625. include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php';
  626. // If no record found
  627. if ($num == 0) {
  628. $colspan = 1;
  629. foreach ($arrayfields as $key => $val) {
  630. if (!empty($val['checked'])) {
  631. $colspan++;
  632. }
  633. }
  634. print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs->trans("NoRecordFound") . '</td></tr>';
  635. }
  636. $db->free($resql);
  637. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  638. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  639. print $hookmanager->resPrint;
  640. print '</table>' . "\n";
  641. print '</div>' . "\n";
  642. print '</form>' . "\n";
  643. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  644. $hidegeneratedfilelistifempty = 1;
  645. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  646. $hidegeneratedfilelistifempty = 0;
  647. }
  648. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  649. $formfile = new FormFile($db);
  650. // Show list of available documents
  651. $urlsource = $_SERVER['PHP_SELF'] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder;
  652. $urlsource .= str_replace('&amp;', '&', $param);
  653. $filedir = $diroutputmassaction;
  654. $genallowed = $permissiontoread;
  655. $delallowed = $permissiontoadd;
  656. print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  657. }
  658. }
  659. /**
  660. * Show a list of positions for the current job
  661. *
  662. * @return void
  663. */
  664. function DisplayPositionList()
  665. {
  666. global $user, $langs, $db, $conf, $extrafields, $hookmanager, $permissiontoadd, $permissiontodelete;
  667. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  668. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  669. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  670. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  671. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  672. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  673. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positionlist'; // To manage different context of search
  674. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  675. $id = GETPOST('id', 'int');
  676. $fk_job = GETPOST('fk_job', 'int');
  677. // Load variable for pagination
  678. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  679. $sortfield = GETPOST('sortfield', 'aZ09comma');
  680. $sortorder = GETPOST('sortorder', 'aZ09comma');
  681. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  682. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  683. // If $page is not defined, or '' or -1 or if we click on clear filters
  684. $page = 0;
  685. }
  686. $offset = $limit * $page;
  687. $pageprev = $page - 1;
  688. $pagenext = $page + 1;
  689. // Initialize technical objects
  690. $object = new Position($db);
  691. $extrafields = new ExtraFields($db);
  692. $diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
  693. $hookmanager->initHooks(array('positiontablist')); // Note that conf->hooks_modules contains array
  694. // Fetch optionals attributes and labels
  695. $extrafields->fetch_name_optionals_label($object->table_element);
  696. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  697. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  698. // Default sort order (if not yet defined by previous GETPOST)
  699. if (!$sortfield) {
  700. reset($object->fields); // Reset is required to avoid key() to return null.
  701. $sortfield = "t." . key($object->fields); // Set here default search field. By default 1st field in definition.
  702. }
  703. if (!$sortorder) {
  704. $sortorder = "ASC";
  705. }
  706. // Initialize array of search criterias
  707. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  708. $search = array();
  709. foreach ($object->fields as $key => $val) {
  710. if (GETPOST('search_' . $key, 'alpha') !== '') {
  711. $search[$key] = GETPOST('search_' . $key, 'alpha');
  712. }
  713. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  714. $search[$key . '_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_' . $key . '_dtstartmonth', 'int'), GETPOST('search_' . $key . '_dtstartday', 'int'), GETPOST('search_' . $key . '_dtstartyear', 'int'));
  715. $search[$key . '_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_' . $key . '_dtendmonth', 'int'), GETPOST('search_' . $key . '_dtendday', 'int'), GETPOST('search_' . $key . '_dtendyear', 'int'));
  716. }
  717. }
  718. // List of fields to search into when doing a "search in all"
  719. $fieldstosearchall = array();
  720. foreach ($object->fields as $key => $val) {
  721. if (!empty($val['searchall'])) {
  722. $fieldstosearchall['t.' . $key] = $val['label'];
  723. }
  724. }
  725. // Definition of array of fields for columns
  726. $arrayfields = array();
  727. foreach ($object->fields as $key => $val) {
  728. // If $val['visible']==0, then we never show the field
  729. if (!empty($val['visible'])) {
  730. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  731. $arrayfields['t.' . $key] = array(
  732. 'label' => $val['label'],
  733. 'checked' => (($visible < 0) ? 0 : 1),
  734. 'enabled' => ($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  735. 'position' => $val['position'],
  736. 'help' => isset($val['help']) ? $val['help'] : ''
  737. );
  738. }
  739. }
  740. // Extra fields
  741. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
  742. $object->fields = dol_sort_array($object->fields, 'position');
  743. $arrayfields = dol_sort_array($arrayfields, 'position');
  744. // Security check
  745. if (empty($conf->hrm->enabled)) {
  746. accessforbidden('Module not enabled');
  747. }
  748. // Security check (enable the most restrictive one)
  749. if ($user->socid > 0) accessforbidden();
  750. //if ($user->socid > 0) accessforbidden();
  751. //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
  752. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  753. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  754. //if (empty($conf->hrm->enabled)) accessforbidden();
  755. //if (!$permissiontoread) accessforbidden();
  756. // Build and execute select
  757. // --------------------------------------------------------------------
  758. $sql = 'SELECT ';
  759. $sql .= $object->getFieldList('t');
  760. // Add fields from extrafields
  761. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  762. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  763. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef." . $key . " as options_" . $key . ', ' : '');
  764. }
  765. }
  766. // Add fields from hooks
  767. $parameters = array();
  768. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  769. $sql .= $hookmanager->resPrint;
  770. $sql = preg_replace('/,\s*$/', '', $sql);
  771. $sql .= " FROM " . MAIN_DB_PREFIX . $object->table_element . " as t";
  772. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  773. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
  774. }
  775. // Add table from hooks
  776. $parameters = array();
  777. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  778. $sql .= $hookmanager->resPrint;
  779. if ($object->ismultientitymanaged == 1) {
  780. $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ")";
  781. } else {
  782. $sql .= " WHERE 1 = 1";
  783. }
  784. $sql .= " AND t.fk_job = " . ((int) $fk_job) . " ";
  785. foreach ($search as $key => $val) {
  786. if (array_key_exists($key, $object->fields)) {
  787. if ($key == 'status' && $search[$key] == -1) {
  788. continue;
  789. }
  790. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  791. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  792. if ($search[$key] == '-1' || $search[$key] === '0') {
  793. $search[$key] = '';
  794. }
  795. $mode_search = 2;
  796. }
  797. if ($search[$key] != '') {
  798. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  799. }
  800. } else {
  801. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  802. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  803. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  804. if (preg_match('/_dtstart$/', $key)) {
  805. $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
  806. }
  807. if (preg_match('/_dtend$/', $key)) {
  808. $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
  809. }
  810. }
  811. }
  812. }
  813. }
  814. if ($search_all) {
  815. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  816. }
  817. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  818. // Add where from extra fields
  819. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
  820. // Add where from hooks
  821. $parameters = array();
  822. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  823. $sql .= $hookmanager->resPrint;
  824. /* If a group by is required
  825. $sql .= " GROUP BY ";
  826. foreach($object->fields as $key => $val) {
  827. $sql .= "t.".$key.", ";
  828. }
  829. // Add fields from extrafields
  830. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  831. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  832. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  833. }
  834. }
  835. // Add where from hooks
  836. $parameters = array();
  837. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  838. $sql .= $hookmanager->resPrint;
  839. $sql = preg_replace('/,\s*$/', '', $sql);
  840. */
  841. $sql .= $db->order($sortfield, $sortorder);
  842. // Count total nb of records
  843. $nbtotalofrecords = '';
  844. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  845. $resql = $db->query($sql);
  846. $nbtotalofrecords = $db->num_rows($resql);
  847. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  848. $page = 0;
  849. $offset = 0;
  850. }
  851. }
  852. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  853. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  854. $num = $nbtotalofrecords;
  855. } else {
  856. if ($limit) {
  857. $sql .= $db->plimit($limit + 1, $offset);
  858. }
  859. $resql = $db->query($sql);
  860. if (!$resql) {
  861. dol_print_error($db);
  862. exit;
  863. }
  864. $num = $db->num_rows($resql);
  865. }
  866. // Direct jump if only one record found
  867. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  868. $obj = $db->fetch_object($resql);
  869. $id = $obj->rowid;
  870. header("Location: " . dol_buildpath('/hrm/position.php', 1) . '?id=' . $id);
  871. exit;
  872. }
  873. $arrayofselected = is_array($toselect) ? $toselect : array();
  874. $param = 'fk_job='.$fk_job;
  875. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  876. $param .= '&contextpage='.urlencode($contextpage);
  877. }
  878. if ($limit > 0 && $limit != $conf->liste_limit) {
  879. $param .= '&limit='.((int) $limit);
  880. }
  881. foreach ($search as $key => $val) {
  882. if (is_array($search[$key]) && count($search[$key])) {
  883. foreach ($search[$key] as $skey) {
  884. $param .= '&search_'.$key.'[]='.urlencode($skey);
  885. }
  886. } else {
  887. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  888. }
  889. }
  890. if ($optioncss != '') {
  891. $param .= '&optioncss='.urlencode($optioncss);
  892. }
  893. // Add $param from extra fields
  894. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
  895. // Add $param from hooks
  896. $parameters = array();
  897. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  898. $param .= $hookmanager->resPrint;
  899. // List of mass actions available
  900. $arrayofmassactions = array(
  901. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  902. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  903. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  904. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  905. );
  906. if ($permissiontodelete) {
  907. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"') . $langs->trans("Delete");
  908. }
  909. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  910. $arrayofmassactions = array();
  911. }
  912. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  913. print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '?fk_job=' . $fk_job . '">' . "\n";
  914. if ($optioncss != '') {
  915. print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
  916. }
  917. print '<input type="hidden" name="token" value="' . newToken() . '">';
  918. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  919. print '<input type="hidden" name="action" value="list">';
  920. print '<input type="hidden" name="massaction" value="' . $massaction . '">';
  921. print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
  922. print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
  923. print '<input type="hidden" name="page" value="' . $page . '">';
  924. print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';
  925. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/hrm/position.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']).'&fk_job='.((int) $fk_job), '', $permissiontoadd);
  926. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_' . $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  927. // Add code for pre mass action (confirmation or email presend form)
  928. $topicmail = "SendPositionRef";
  929. $modelmail = "position";
  930. $objecttmp = new Position($db);
  931. $trackid = 'xxxx' . $object->id;
  932. include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php';
  933. if ($search_all) {
  934. foreach ($fieldstosearchall as $key => $val) {
  935. $fieldstosearchall[$key] = $langs->trans($val);
  936. }
  937. print '<div class="divsearchfieldfilter">' . $langs->trans("FilterOnInto", $search_all) . join(', ', $fieldstosearchall) . '</div>';
  938. }
  939. $moreforfilter = '';
  940. /*$moreforfilter.='<div class="divsearchfield">';
  941. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  942. $moreforfilter.= '</div>';*/
  943. $parameters = array();
  944. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  945. if (empty($reshook)) {
  946. $moreforfilter .= $hookmanager->resPrint;
  947. } else {
  948. $moreforfilter = $hookmanager->resPrint;
  949. }
  950. if (!empty($moreforfilter)) {
  951. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  952. print $moreforfilter;
  953. print '</div>';
  954. }
  955. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  956. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  957. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  958. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  959. print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
  960. // Fields title search
  961. // --------------------------------------------------------------------
  962. print '<tr class="liste_titre">';
  963. foreach ($object->fields as $key => $val) {
  964. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  965. if ($key == 'status') {
  966. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  967. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  968. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  969. } elseif (in_array($val['type'], array('timestamp'))) {
  970. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  971. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  972. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  973. }
  974. if (!empty($arrayfields['t.' . $key]['checked'])) {
  975. print '<td class="liste_titre' . ($cssforfield ? ' ' . $cssforfield : '') . '">';
  976. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  977. print $form->selectarray('search_' . $key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  978. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  979. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  980. } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  981. print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '') . '">';
  982. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  983. print '<div class="nowrap">';
  984. print $form->selectDate($search[$key . '_dtstart'] ? $search[$key . '_dtstart'] : '', "search_" . $key . "_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  985. print '</div>';
  986. print '<div class="nowrap">';
  987. print $form->selectDate($search[$key . '_dtend'] ? $search[$key . '_dtend'] : '', "search_" . $key . "_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  988. print '</div>';
  989. }
  990. print '</td>';
  991. }
  992. }
  993. // Extra fields
  994. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
  995. // Fields from hook
  996. $parameters = array('arrayfields' => $arrayfields);
  997. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  998. print $hookmanager->resPrint;
  999. // Action column
  1000. print '<td class="liste_titre maxwidthsearch">';
  1001. $searchpicto = $form->showFilterButtons();
  1002. print $searchpicto;
  1003. print '</td>';
  1004. print '</tr>' . "\n";
  1005. // Fields title label
  1006. // --------------------------------------------------------------------
  1007. print '<tr class="liste_titre">';
  1008. foreach ($object->fields as $key => $val) {
  1009. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  1010. if ($key == 'status') {
  1011. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  1012. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  1013. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  1014. } elseif (in_array($val['type'], array('timestamp'))) {
  1015. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  1016. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  1017. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  1018. }
  1019. if (!empty($arrayfields['t.' . $key]['checked'])) {
  1020. print getTitleFieldOfList($arrayfields['t.' . $key]['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : '')) . "\n";
  1021. }
  1022. }
  1023. // Extra fields
  1024. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
  1025. // Hook fields
  1026. $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
  1027. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  1028. print $hookmanager->resPrint;
  1029. // Action column
  1030. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n";
  1031. print '</tr>' . "\n";
  1032. // Detect if we need a fetch on each output line
  1033. $needToFetchEachLine = 0;
  1034. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  1035. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  1036. if (preg_match('/\$object/', $val)) {
  1037. $needToFetchEachLine++; // There is at least one compute field that use $object
  1038. }
  1039. }
  1040. }
  1041. // Loop on record
  1042. // --------------------------------------------------------------------
  1043. $i = 0;
  1044. $totalarray = array();
  1045. $totalarray['nbfield'] = 0;
  1046. while ($i < ($limit ? min($num, $limit) : $num)) {
  1047. $obj = $db->fetch_object($resql);
  1048. if (empty($obj)) {
  1049. break; // Should not happen
  1050. }
  1051. // Store properties in $object
  1052. $object->setVarsFromFetchObj($obj);
  1053. // Show here line of result
  1054. print '<tr class="oddeven">';
  1055. foreach ($object->fields as $key => $val) {
  1056. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  1057. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  1058. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  1059. } elseif ($key == 'status') {
  1060. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  1061. }
  1062. if (in_array($val['type'], array('timestamp'))) {
  1063. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  1064. } elseif ($key == 'ref') {
  1065. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  1066. }
  1067. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  1068. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  1069. }
  1070. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  1071. if (!empty($arrayfields['t.' . $key]['checked'])) {
  1072. print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '') . '>';
  1073. if ($key == 'status') {
  1074. print $object->getLibStatut(5);
  1075. } elseif ($key == 'rowid') {
  1076. print $object->getNomUrl(1);
  1077. } else {
  1078. print $object->showOutputField($val, $key, $object->$key, '');
  1079. }
  1080. print '</td>';
  1081. if (!$i) {
  1082. $totalarray['nbfield']++;
  1083. }
  1084. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  1085. if (!$i) {
  1086. $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key;
  1087. }
  1088. if (!isset($totalarray['val'])) {
  1089. $totalarray['val'] = array();
  1090. }
  1091. if (!isset($totalarray['val']['t.' . $key])) {
  1092. $totalarray['val']['t.' . $key] = 0;
  1093. }
  1094. $totalarray['val']['t.' . $key] += $object->$key;
  1095. }
  1096. }
  1097. }
  1098. // Extra fields
  1099. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php';
  1100. // Fields from hook
  1101. $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
  1102. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1103. print $hookmanager->resPrint;
  1104. // Action column
  1105. print '<td class="nowrap center">';
  1106. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1107. $selected = 0;
  1108. if (in_array($object->id, $arrayofselected)) {
  1109. $selected = 1;
  1110. }
  1111. print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  1112. }
  1113. print '</td>';
  1114. if (!$i) {
  1115. $totalarray['nbfield']++;
  1116. }
  1117. print '</tr>' . "\n";
  1118. $i++;
  1119. }
  1120. // Show total line
  1121. include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php';
  1122. // If no record found
  1123. if ($num == 0) {
  1124. $colspan = 1;
  1125. foreach ($arrayfields as $key => $val) {
  1126. if (!empty($val['checked'])) {
  1127. $colspan++;
  1128. }
  1129. }
  1130. print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs->trans("NoRecordFound") . '</td></tr>';
  1131. }
  1132. $db->free($resql);
  1133. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  1134. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  1135. print $hookmanager->resPrint;
  1136. print '</table>' . "\n";
  1137. print '</div>' . "\n";
  1138. print '</form>' . "\n";
  1139. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  1140. $hidegeneratedfilelistifempty = 1;
  1141. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1142. $hidegeneratedfilelistifempty = 0;
  1143. }
  1144. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  1145. $formfile = new FormFile($db);
  1146. // Show list of available documents
  1147. $urlsource = $_SERVER['PHP_SELF'] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder;
  1148. $urlsource .= str_replace('&amp;', '&', $param);
  1149. $filedir = $diroutputmassaction;
  1150. $genallowed = $permissiontoread;
  1151. $delallowed = $permissiontoadd;
  1152. print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1153. }
  1154. }
  1155. // End of page
  1156. llxFooter();
  1157. $db->close();