position.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  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 position.php
  23. * \ingroup hrm
  24. * \brief Page to create/edit/view position
  25. */
  26. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
  27. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
  28. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
  29. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
  30. //if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
  31. //if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
  32. //if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
  33. //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
  34. //if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
  35. //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
  36. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
  37. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
  38. //if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
  39. //if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  40. //if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
  41. //if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
  42. //if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
  43. //if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
  44. //if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
  45. // Load Dolibarr environment
  46. $res = 0;
  47. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  48. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  49. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  50. }
  51. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  52. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  53. $tmp2 = realpath(__FILE__);
  54. $i = strlen($tmp) - 1;
  55. $j = strlen($tmp2) - 1;
  56. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  57. $i--;
  58. $j--;
  59. }
  60. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  61. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  62. }
  63. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  64. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  65. }
  66. // Try main.inc.php using relative path
  67. if (!$res && file_exists("../main.inc.php")) {
  68. $res = @include "../main.inc.php";
  69. }
  70. if (!$res && file_exists("../../main.inc.php")) {
  71. $res = @include "../../main.inc.php";
  72. }
  73. if (!$res && file_exists("../../../main.inc.php")) {
  74. $res = @include "../../../main.inc.php";
  75. }
  76. if (!$res) {
  77. die("Include of main fails");
  78. }
  79. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  80. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  81. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  82. require_once DOL_DOCUMENT_ROOT . '/hrm/class/position.class.php';
  83. require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
  84. require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_position.lib.php';
  85. require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
  86. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  87. $backtopage = GETPOST('backtopage', 'alpha');
  88. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  89. $fk_job = GETPOST('fk_job', 'int');
  90. // Get parameters
  91. $id = GETPOST('fk_job', 'int');
  92. $fk_job = GETPOST('fk_job', 'int');
  93. $fk_user = GETPOST('fk_user', 'int');
  94. //$start_date = date('Y-m-d', GETPOST('date_startyear', 'int').'-'.GETPOST('date_startmonth', 'int').'-'.GETPOST('date_startday', 'int'));
  95. $start_date = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
  96. $ref = GETPOST('ref', 'alpha');
  97. $confirm = GETPOST('confirm', 'alpha');
  98. $cancel = GETPOST('cancel', 'aZ09');
  99. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positioncard'; // To manage different context of search
  100. // Initialize technical objects
  101. $object = new Job($db);
  102. $extrafields = new ExtraFields($db);
  103. $diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
  104. $hookmanager->initHooks(array('positiontab', 'globalcard')); // Note that conf->hooks_modules contains array
  105. // Fetch optionals attributes and labels
  106. $extrafields->fetch_name_optionals_label($object->table_element);
  107. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  108. // Initialize array of search criterias
  109. $search_all = GETPOST("search_all", 'alpha');
  110. $search = array();
  111. foreach ($object->fields as $key => $val) {
  112. if (GETPOST('search_' . $key, 'alpha')) {
  113. $search[$key] = GETPOST('search_' . $key, 'alpha');
  114. }
  115. }
  116. // Load object
  117. include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  118. $permissiontoread = $user->rights->hrm->all->read;
  119. $permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  120. $permissiontodelete = $user->rights->hrm->all->delete;
  121. $upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/position';
  122. // Security check (enable the most restrictive one)
  123. //if ($user->socid > 0) accessforbidden();
  124. //if ($user->socid > 0) $socid = $user->socid;
  125. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  126. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  127. if (empty($conf->hrm->enabled)) accessforbidden();
  128. if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
  129. /*
  130. * Actions
  131. */
  132. $parameters = array();
  133. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  134. if ($reshook < 0) {
  135. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  136. }
  137. if (empty($reshook)) {
  138. $error = 0;
  139. $backurlforlist = dol_buildpath('/hrm/position_list.php', 1);
  140. //$backtopage = dol_buildpath('/hrm/position.php', 1) . '?fk_job=' . ($fk_job > 0 ? $fk_job : '__ID__');
  141. if (empty($backtopage) || ($cancel && $fk_job <= 0)) {
  142. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  143. if ($fk_job == -1 && (($action != 'add' && $action != 'create') || $cancel)) {
  144. $backtopage = $backurlforlist;
  145. } else {
  146. if ($fk_job > 0) {
  147. $backtopage = dol_buildpath('/hrm/position.php', 1) . '?fk_job=' . ($fk_job > 0 ? $fk_job : '__ID__');
  148. } else {
  149. $backtopage = dol_buildpath('/hrm/position_card.php', 1) . '?id=__ID__';
  150. }
  151. }
  152. }
  153. }
  154. $triggermodname = 'hrm_POSITION_MODIFY'; // Name of trigger action code to execute when we modify record
  155. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  156. $job = $object;
  157. $object = new Position($db);
  158. include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
  159. }
  160. // Load translation files required by the page
  161. $langs->loadLangs(array("hrm", "other", 'products'));
  162. $title = $langs->trans("Position");
  163. $help_url = '';
  164. llxHeader('', $title, $help_url);
  165. if ($job->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  166. DisplayJob($job);
  167. DisplayPositionList();
  168. }
  169. /**
  170. * Show the top of the page including informations of a job
  171. *
  172. * @param Job $object Job object
  173. *
  174. * @return void
  175. */
  176. function DisplayJob($object)
  177. {
  178. global $conf, $langs, $db, $extrafields, $hookmanager, $action, $backtopage, $backtopageforcancel, $permissiontoadd;
  179. /*
  180. * View
  181. *
  182. * Put here all code to build page
  183. */
  184. $form = new Form($db);
  185. $formfile = new FormFile($db);
  186. $formproject = new FormProjets($db);
  187. if ($backtopage) {
  188. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  189. }
  190. if ($backtopageforcancel) {
  191. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  192. }
  193. // Part to show record
  194. $res = $object->fetch_optionals();
  195. $head = jobPrepareHead($object);
  196. print dol_get_fiche_head($head, 'position', $langs->trans("Workstation"), -1, $object->picto);
  197. // Object card
  198. // ------------------------------------------------------------
  199. $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>';
  200. $morehtmlref = '<div class="refid">';
  201. $morehtmlref.= $object->label;
  202. $morehtmlref .= '</div>';
  203. dol_banner_tab($object, 'fk_job', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  204. print '<div class="fichecenter">';
  205. print '<div class="fichehalfleft">';
  206. print '<div class="underbanner clearboth"></div>';
  207. print '<table class="border centpercent tableforfield">' . "\n";
  208. // Common attributes
  209. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
  210. //unset($object->fields['fk_project']); // Hide field already shown in banner
  211. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  212. $object->fields['label']['visible']=0; // Already in banner
  213. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
  214. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  215. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  216. print '</table>';
  217. print '</div>';
  218. print '</div>';
  219. print '<div class="clearboth"></div>';
  220. print dol_get_fiche_end();
  221. }
  222. /**
  223. * Show a list of positions for the current job
  224. *
  225. * @return void
  226. */
  227. function DisplayPositionList()
  228. {
  229. global $user, $langs, $db, $conf, $extrafields, $hookmanager, $permissiontoadd, $permissiontodelete;
  230. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  231. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  232. require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
  233. // load hrm libraries
  234. require_once __DIR__ . '/class/position.class.php';
  235. // for other modules
  236. //dol_include_once('/othermodule/class/otherobject.class.php');
  237. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  238. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  239. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  240. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  241. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  242. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  243. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positionlist'; // To manage different context of search
  244. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  245. $id = GETPOST('id', 'int');
  246. $fk_job = GETPOST('fk_job', 'int');
  247. // Load variable for pagination
  248. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  249. $sortfield = GETPOST('sortfield', 'aZ09comma');
  250. $sortorder = GETPOST('sortorder', 'aZ09comma');
  251. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  252. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  253. // If $page is not defined, or '' or -1 or if we click on clear filters
  254. $page = 0;
  255. }
  256. $offset = $limit * $page;
  257. $pageprev = $page - 1;
  258. $pagenext = $page + 1;
  259. // Initialize technical objects
  260. $object = new Position($db);
  261. $extrafields = new ExtraFields($db);
  262. $diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
  263. $hookmanager->initHooks(array('positiontablist')); // Note that conf->hooks_modules contains array
  264. // Fetch optionals attributes and labels
  265. $extrafields->fetch_name_optionals_label($object->table_element);
  266. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  267. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  268. // Default sort order (if not yet defined by previous GETPOST)
  269. if (!$sortfield) {
  270. reset($object->fields); // Reset is required to avoid key() to return null.
  271. $sortfield = "t." . key($object->fields); // Set here default search field. By default 1st field in definition.
  272. }
  273. if (!$sortorder) {
  274. $sortorder = "ASC";
  275. }
  276. // Initialize array of search criterias
  277. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  278. $search = array();
  279. foreach ($object->fields as $key => $val) {
  280. if (GETPOST('search_' . $key, 'alpha') !== '') {
  281. $search[$key] = GETPOST('search_' . $key, 'alpha');
  282. }
  283. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  284. $search[$key . '_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_' . $key . '_dtstartmonth', 'int'), GETPOST('search_' . $key . '_dtstartday', 'int'), GETPOST('search_' . $key . '_dtstartyear', 'int'));
  285. $search[$key . '_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_' . $key . '_dtendmonth', 'int'), GETPOST('search_' . $key . '_dtendday', 'int'), GETPOST('search_' . $key . '_dtendyear', 'int'));
  286. }
  287. }
  288. // List of fields to search into when doing a "search in all"
  289. $fieldstosearchall = array();
  290. foreach ($object->fields as $key => $val) {
  291. if (!empty($val['searchall'])) {
  292. $fieldstosearchall['t.' . $key] = $val['label'];
  293. }
  294. }
  295. // Definition of array of fields for columns
  296. $arrayfields = array();
  297. foreach ($object->fields as $key => $val) {
  298. // If $val['visible']==0, then we never show the field
  299. if (!empty($val['visible'])) {
  300. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  301. $arrayfields['t.' . $key] = array(
  302. 'label' => $val['label'],
  303. 'checked' => (($visible < 0) ? 0 : 1),
  304. 'enabled' => ($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  305. 'position' => $val['position'],
  306. 'help' => isset($val['help']) ? $val['help'] : ''
  307. );
  308. }
  309. }
  310. // Extra fields
  311. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
  312. $object->fields = dol_sort_array($object->fields, 'position');
  313. $arrayfields = dol_sort_array($arrayfields, 'position');
  314. // Security check
  315. if (empty($conf->hrm->enabled)) {
  316. accessforbidden('Module not enabled');
  317. }
  318. // Security check (enable the most restrictive one)
  319. if ($user->socid > 0) accessforbidden();
  320. //if ($user->socid > 0) accessforbidden();
  321. //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
  322. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  323. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  324. //if (empty($conf->hrm->enabled)) accessforbidden();
  325. //if (!$permissiontoread) accessforbidden();
  326. /*
  327. * Actions
  328. */
  329. if (GETPOST('cancel', 'alpha')) {
  330. $action = 'list';
  331. $massaction = '';
  332. }
  333. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  334. $massaction = '';
  335. }
  336. $parameters = array();
  337. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  338. if ($reshook < 0) {
  339. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  340. }
  341. if (empty($reshook)) {
  342. // Selection of new fields
  343. include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
  344. // Purge search criteria
  345. 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
  346. foreach ($object->fields as $key => $val) {
  347. $search[$key] = '';
  348. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  349. $search[$key . '_dtstart'] = '';
  350. $search[$key . '_dtend'] = '';
  351. }
  352. }
  353. $toselect = array();
  354. $search_array_options = array();
  355. }
  356. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  357. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  358. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  359. }
  360. // Mass actions
  361. $objectclass = 'Position';
  362. $objectlabel = 'Position';
  363. $uploaddir = $conf->hrm->dir_output;
  364. include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php';
  365. }
  366. /*
  367. * View
  368. */
  369. $form = new Form($db);
  370. $now = dol_now();
  371. //$help_url="EN:Module_Position|FR:Module_Position_FR|ES:Módulo_Position";
  372. $help_url = '';
  373. $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("Positions"));
  374. $morejs = array();
  375. $morecss = array();
  376. // Build and execute select
  377. // --------------------------------------------------------------------
  378. $sql = 'SELECT ';
  379. $sql .= $object->getFieldList('t');
  380. // Add fields from extrafields
  381. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  382. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  383. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef." . $key . " as options_" . $key . ', ' : '');
  384. }
  385. }
  386. // Add fields from hooks
  387. $parameters = array();
  388. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  389. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  390. $sql = preg_replace('/,\s*$/', '', $sql);
  391. $sql .= " FROM " . MAIN_DB_PREFIX . $object->table_element . " as t";
  392. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  393. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
  394. }
  395. // Add table from hooks
  396. $parameters = array();
  397. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  398. $sql .= $hookmanager->resPrint;
  399. if ($object->ismultientitymanaged == 1) {
  400. $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ")";
  401. } else {
  402. $sql .= " WHERE 1 = 1";
  403. }
  404. $sql .= " AND t.fk_job = " . ((int) $fk_job) . " ";
  405. foreach ($search as $key => $val) {
  406. if (array_key_exists($key, $object->fields)) {
  407. if ($key == 'status' && $search[$key] == -1) {
  408. continue;
  409. }
  410. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  411. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  412. if ($search[$key] == '-1' || $search[$key] === '0') {
  413. $search[$key] = '';
  414. }
  415. $mode_search = 2;
  416. }
  417. if ($search[$key] != '') {
  418. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  419. }
  420. } else {
  421. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  422. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  423. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  424. if (preg_match('/_dtstart$/', $key)) {
  425. $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
  426. }
  427. if (preg_match('/_dtend$/', $key)) {
  428. $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
  429. }
  430. }
  431. }
  432. }
  433. }
  434. if ($search_all) {
  435. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  436. }
  437. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  438. // Add where from extra fields
  439. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
  440. // Add where from hooks
  441. $parameters = array();
  442. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  443. $sql .= $hookmanager->resPrint;
  444. /* If a group by is required
  445. $sql .= " GROUP BY ";
  446. foreach($object->fields as $key => $val) {
  447. $sql .= "t.".$key.", ";
  448. }
  449. // Add fields from extrafields
  450. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  451. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  452. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  453. }
  454. }
  455. // Add where from hooks
  456. $parameters = array();
  457. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  458. $sql .= $hookmanager->resPrint;
  459. $sql = preg_replace('/,\s*$/', '', $sql);
  460. */
  461. $sql .= $db->order($sortfield, $sortorder);
  462. // Count total nb of records
  463. $nbtotalofrecords = '';
  464. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  465. $resql = $db->query($sql);
  466. $nbtotalofrecords = $db->num_rows($resql);
  467. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  468. $page = 0;
  469. $offset = 0;
  470. }
  471. }
  472. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  473. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  474. $num = $nbtotalofrecords;
  475. } else {
  476. if ($limit) {
  477. $sql .= $db->plimit($limit + 1, $offset);
  478. }
  479. $resql = $db->query($sql);
  480. if (!$resql) {
  481. dol_print_error($db);
  482. exit;
  483. }
  484. $num = $db->num_rows($resql);
  485. }
  486. // Direct jump if only one record found
  487. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  488. $obj = $db->fetch_object($resql);
  489. $id = $obj->rowid;
  490. header("Location: " . dol_buildpath('/hrm/position.php', 1) . '?id=' . $id);
  491. exit;
  492. }
  493. $arrayofselected = is_array($toselect) ? $toselect : array();
  494. $param = 'fk_job=' . $fk_job;
  495. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  496. $param .= '&contextpage=' . urlencode($contextpage);
  497. }
  498. if ($limit > 0 && $limit != $conf->liste_limit) {
  499. $param .= '&limit=' . urlencode($limit);
  500. }
  501. foreach ($search as $key => $val) {
  502. if (is_array($search[$key]) && count($search[$key])) {
  503. foreach ($search[$key] as $skey) {
  504. $param .= '&search_' . $key . '[]=' . urlencode($skey);
  505. }
  506. } else {
  507. $param .= '&search_' . $key . '=' . urlencode($search[$key]);
  508. }
  509. }
  510. if ($optioncss != '') {
  511. $param .= '&optioncss=' . urlencode($optioncss);
  512. }
  513. // Add $param from extra fields
  514. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
  515. // Add $param from hooks
  516. $parameters = array();
  517. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  518. $param .= $hookmanager->resPrint;
  519. // List of mass actions available
  520. $arrayofmassactions = array(
  521. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  522. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  523. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  524. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  525. );
  526. if ($permissiontodelete) {
  527. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"') . $langs->trans("Delete");
  528. }
  529. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  530. $arrayofmassactions = array();
  531. }
  532. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  533. print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '?fk_job=' . $fk_job . '">' . "\n";
  534. if ($optioncss != '') {
  535. print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
  536. }
  537. print '<input type="hidden" name="token" value="' . newToken() . '">';
  538. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  539. print '<input type="hidden" name="action" value="list">';
  540. print '<input type="hidden" name="massaction" value="' . $massaction . '">';
  541. print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
  542. print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
  543. print '<input type="hidden" name="page" value="' . $page . '">';
  544. print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';
  545. $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);
  546. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_' . $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  547. // Add code for pre mass action (confirmation or email presend form)
  548. $topicmail = "SendPositionRef";
  549. $modelmail = "position";
  550. $objecttmp = new Position($db);
  551. $trackid = 'xxxx' . $object->id;
  552. include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php';
  553. if ($search_all) {
  554. foreach ($fieldstosearchall as $key => $val) {
  555. $fieldstosearchall[$key] = $langs->trans($val);
  556. }
  557. print '<div class="divsearchfieldfilter">' . $langs->trans("FilterOnInto", $search_all) . join(', ', $fieldstosearchall) . '</div>';
  558. }
  559. $moreforfilter = '';
  560. /*$moreforfilter.='<div class="divsearchfield">';
  561. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  562. $moreforfilter.= '</div>';*/
  563. $parameters = array();
  564. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  565. if (empty($reshook)) {
  566. $moreforfilter .= $hookmanager->resPrint;
  567. } else {
  568. $moreforfilter = $hookmanager->resPrint;
  569. }
  570. if (!empty($moreforfilter)) {
  571. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  572. print $moreforfilter;
  573. print '</div>';
  574. }
  575. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  576. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  577. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  578. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  579. print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
  580. // Fields title search
  581. // --------------------------------------------------------------------
  582. print '<tr class="liste_titre">';
  583. foreach ($object->fields as $key => $val) {
  584. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  585. if ($key == 'status') {
  586. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  587. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  588. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  589. } elseif (in_array($val['type'], array('timestamp'))) {
  590. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  591. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  592. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  593. }
  594. if (!empty($arrayfields['t.' . $key]['checked'])) {
  595. print '<td class="liste_titre' . ($cssforfield ? ' ' . $cssforfield : '') . '">';
  596. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  597. print $form->selectarray('search_' . $key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  598. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  599. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  600. } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  601. print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '') . '">';
  602. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  603. print '<div class="nowrap">';
  604. print $form->selectDate($search[$key . '_dtstart'] ? $search[$key . '_dtstart'] : '', "search_" . $key . "_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  605. print '</div>';
  606. print '<div class="nowrap">';
  607. print $form->selectDate($search[$key . '_dtend'] ? $search[$key . '_dtend'] : '', "search_" . $key . "_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  608. print '</div>';
  609. }
  610. print '</td>';
  611. }
  612. }
  613. // Extra fields
  614. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
  615. // Fields from hook
  616. $parameters = array('arrayfields' => $arrayfields);
  617. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  618. print $hookmanager->resPrint;
  619. // Action column
  620. print '<td class="liste_titre maxwidthsearch">';
  621. $searchpicto = $form->showFilterButtons();
  622. print $searchpicto;
  623. print '</td>';
  624. print '</tr>' . "\n";
  625. // Fields title label
  626. // --------------------------------------------------------------------
  627. print '<tr class="liste_titre">';
  628. foreach ($object->fields as $key => $val) {
  629. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  630. if ($key == 'status') {
  631. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  632. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  633. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  634. } elseif (in_array($val['type'], array('timestamp'))) {
  635. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  636. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  637. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  638. }
  639. if (!empty($arrayfields['t.' . $key]['checked'])) {
  640. print getTitleFieldOfList($arrayfields['t.' . $key]['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : '')) . "\n";
  641. }
  642. }
  643. // Extra fields
  644. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
  645. // Hook fields
  646. $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
  647. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  648. print $hookmanager->resPrint;
  649. // Action column
  650. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n";
  651. print '</tr>' . "\n";
  652. // Detect if we need a fetch on each output line
  653. $needToFetchEachLine = 0;
  654. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  655. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  656. if (preg_match('/\$object/', $val)) {
  657. $needToFetchEachLine++; // There is at least one compute field that use $object
  658. }
  659. }
  660. }
  661. // Loop on record
  662. // --------------------------------------------------------------------
  663. $i = 0;
  664. $totalarray = array();
  665. $totalarray['nbfield'] = 0;
  666. while ($i < ($limit ? min($num, $limit) : $num)) {
  667. $obj = $db->fetch_object($resql);
  668. if (empty($obj)) {
  669. break; // Should not happen
  670. }
  671. // Store properties in $object
  672. $object->setVarsFromFetchObj($obj);
  673. // Show here line of result
  674. print '<tr class="oddeven">';
  675. foreach ($object->fields as $key => $val) {
  676. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  677. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  678. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  679. } elseif ($key == 'status') {
  680. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  681. }
  682. if (in_array($val['type'], array('timestamp'))) {
  683. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  684. } elseif ($key == 'ref') {
  685. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  686. }
  687. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  688. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  689. }
  690. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  691. if (!empty($arrayfields['t.' . $key]['checked'])) {
  692. print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '') . '>';
  693. if ($key == 'status') {
  694. print $object->getLibStatut(5);
  695. } elseif ($key == 'rowid') {
  696. print $object->getNomUrl(1);
  697. } else {
  698. print $object->showOutputField($val, $key, $object->$key, '');
  699. }
  700. print '</td>';
  701. if (!$i) {
  702. $totalarray['nbfield']++;
  703. }
  704. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  705. if (!$i) {
  706. $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key;
  707. }
  708. if (!isset($totalarray['val'])) {
  709. $totalarray['val'] = array();
  710. }
  711. if (!isset($totalarray['val']['t.' . $key])) {
  712. $totalarray['val']['t.' . $key] = 0;
  713. }
  714. $totalarray['val']['t.' . $key] += $object->$key;
  715. }
  716. }
  717. }
  718. // Extra fields
  719. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php';
  720. // Fields from hook
  721. $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
  722. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  723. print $hookmanager->resPrint;
  724. // Action column
  725. print '<td class="nowrap center">';
  726. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  727. $selected = 0;
  728. if (in_array($object->id, $arrayofselected)) {
  729. $selected = 1;
  730. }
  731. print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  732. }
  733. print '</td>';
  734. if (!$i) {
  735. $totalarray['nbfield']++;
  736. }
  737. print '</tr>' . "\n";
  738. $i++;
  739. }
  740. // Show total line
  741. include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php';
  742. // If no record found
  743. if ($num == 0) {
  744. $colspan = 1;
  745. foreach ($arrayfields as $key => $val) {
  746. if (!empty($val['checked'])) {
  747. $colspan++;
  748. }
  749. }
  750. print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs->trans("NoRecordFound") . '</td></tr>';
  751. }
  752. $db->free($resql);
  753. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  754. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  755. print $hookmanager->resPrint;
  756. print '</table>' . "\n";
  757. print '</div>' . "\n";
  758. print '</form>' . "\n";
  759. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  760. $hidegeneratedfilelistifempty = 1;
  761. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  762. $hidegeneratedfilelistifempty = 0;
  763. }
  764. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  765. $formfile = new FormFile($db);
  766. // Show list of available documents
  767. $urlsource = $_SERVER['PHP_SELF'] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder;
  768. $urlsource .= str_replace('&amp;', '&', $param);
  769. $filedir = $diroutputmassaction;
  770. $genallowed = $permissiontoread;
  771. $delallowed = $permissiontoadd;
  772. print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  773. }
  774. }
  775. // Part to create
  776. if ($action == 'create') {
  777. $object = new Position($db);
  778. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Position")), '', 'object_' . $object->picto);
  779. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  780. print '<input type="hidden" name="token" value="' . newToken() . '">';
  781. print '<input type="hidden" name="action" value="add">';
  782. if ($backtopage) {
  783. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  784. }
  785. if ($backtopageforcancel) {
  786. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  787. }
  788. print dol_get_fiche_head(array(), '');
  789. print '<table class="border centpercent tableforfieldcreate">' . "\n";
  790. // Common attributes
  791. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
  792. // Other attributes
  793. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
  794. print '</table>' . "\n";
  795. print dol_get_fiche_end();
  796. print '<div class="center">';
  797. print '<input type="submit" class="button" name="add" value="' . dol_escape_htmltag($langs->trans("Create")) . '">';
  798. print '&nbsp; ';
  799. print '<input type="' . ($backtopage ? "submit" : "button") . '" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag($langs->trans("Cancel")) . '"' . ($backtopage ? '' : ' onclick="javascript:history.go(-1)"') . '>'; // Cancel for create does not post form if we don't know the backtopage
  800. print '</div>';
  801. print '</form>';
  802. //dol_set_focus('input[name="ref"]');
  803. }
  804. // End of page
  805. llxFooter();
  806. $db->close();