position.php 32 KB

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