recruitmentjobposition_list.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file recruitmentjobposition_list.php
  19. * \ingroup recruitment
  20. * \brief List page for recruitmentjobposition
  21. */
  22. // Load Dolibarr environment
  23. require_once '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/recruitment/lib/recruitment_recruitmentjobposition.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentjobposition.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("recruitment", "other"));
  31. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  32. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  33. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  34. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  35. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  36. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  37. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'recruitmentjobpositionlist'; // To manage different context of search
  38. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  39. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  40. $mode = GETPOST('mode', 'aZ');
  41. $id = GETPOST('id', 'int');
  42. // Load variable for pagination
  43. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  44. $sortfield = GETPOST('sortfield', 'aZ09comma');
  45. $sortorder = GETPOST('sortorder', 'aZ09comma');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  48. // If $page is not defined, or '' or -1 or if we click on clear filters
  49. $page = 0;
  50. }
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. // Initialize technical objects
  55. $object = new RecruitmentJobPosition($db);
  56. $extrafields = new ExtraFields($db);
  57. $diroutputmassaction = $conf->recruitment->dir_output.'/temp/massgeneration/'.$user->id;
  58. $hookmanager->initHooks(array('recruitmentjobpositionlist')); // Note that conf->hooks_modules contains array
  59. // Fetch optionals attributes and labels
  60. $extrafields->fetch_name_optionals_label($object->table_element);
  61. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  62. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  63. // Default sort order (if not yet defined by previous GETPOST)
  64. if (!$sortfield) {
  65. $sortfield = "t.ref";
  66. }
  67. if (!$sortorder) {
  68. $sortorder = "DESC";
  69. }
  70. // Initialize array of search criterias
  71. $search_all = GETPOST('search_all', 'alphanohtml');
  72. $search = array();
  73. foreach ($object->fields as $key => $val) {
  74. if (GETPOST('search_'.$key, 'alpha') !== '') {
  75. $search[$key] = GETPOST('search_'.$key, 'alpha');
  76. }
  77. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  78. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  79. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  80. }
  81. }
  82. // List of fields to search into when doing a "search in all"
  83. $fieldstosearchall = array();
  84. foreach ($object->fields as $key => $val) {
  85. if (!empty($val['searchall'])) {
  86. $fieldstosearchall['t.'.$key] = $val['label'];
  87. }
  88. }
  89. // Definition of array of fields for columns
  90. $arrayfields = array();
  91. foreach ($object->fields as $key => $val) {
  92. // If $val['visible']==0, then we never show the field
  93. if (!empty($val['visible'])) {
  94. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  95. $arrayfields['t.'.$key] = array(
  96. 'label'=>$val['label'],
  97. 'checked'=>(($visible < 0) ? 0 : 1),
  98. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  99. 'position'=>$val['position'],
  100. 'help'=> isset($val['help']) ? $val['help'] : ''
  101. );
  102. }
  103. }
  104. // Extra fields
  105. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  106. // Load object
  107. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  108. $object->fields = dol_sort_array($object->fields, 'position');
  109. $arrayfields['nbapplications'] = array('type'=>'integer', 'label'=>'Applications', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
  110. $arrayfields = dol_sort_array($arrayfields, 'position');
  111. $permissiontoread = $user->rights->recruitment->recruitmentjobposition->read;
  112. $permissiontoadd = $user->rights->recruitment->recruitmentjobposition->write;
  113. $permissiontodelete = $user->rights->recruitment->recruitmentjobposition->delete;
  114. // Security check - Protection if external user
  115. //if ($user->socid > 0) accessforbidden();
  116. //if ($user->socid > 0) $socid = $user->socid;
  117. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  118. restrictedArea($user, 'recruitment', 0, 'recruitment_recruitmentjobposition', 'recruitmentjobposition');
  119. /*
  120. * Actions
  121. */
  122. if (GETPOST('cancel', 'alpha')) {
  123. $action = 'list';
  124. $massaction = '';
  125. }
  126. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  127. $massaction = '';
  128. }
  129. $parameters = array();
  130. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  131. if ($reshook < 0) {
  132. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  133. }
  134. if (empty($reshook)) {
  135. // Selection of new fields
  136. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  137. // Purge search criteria
  138. 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
  139. foreach ($object->fields as $key => $val) {
  140. $search[$key] = '';
  141. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  142. $search[$key.'_dtstart'] = '';
  143. $search[$key.'_dtend'] = '';
  144. }
  145. }
  146. $toselect = array();
  147. $search_array_options = array();
  148. }
  149. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  150. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  151. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  152. }
  153. // Mass actions
  154. $objectclass = 'RecruitmentJobPosition';
  155. $objectlabel = 'RecruitmentJobPosition';
  156. $uploaddir = $conf->recruitment->dir_output;
  157. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  158. }
  159. /*
  160. * View
  161. */
  162. $form = new Form($db);
  163. $now = dol_now();
  164. //$help_url="EN:Module_RecruitmentJobPosition|FR:Module_RecruitmentJobPosition_FR|ES:Módulo_RecruitmentJobPosition";
  165. $help_url = '';
  166. $title = $langs->trans('PositionsToBeFilled');
  167. $morejs = array();
  168. $morecss = array();
  169. // Build and execute select
  170. // --------------------------------------------------------------------
  171. $sql = 'SELECT ';
  172. $sql .= $object->getFieldList('t');
  173. // Add fields from extrafields
  174. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  175. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  176. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  177. }
  178. }
  179. // Add fields from hooks
  180. $parameters = array();
  181. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  182. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  183. $sql = preg_replace('/,\s*$/', '', $sql);
  184. $sql .= ", COUNT(rc.rowid) as nbapplications";
  185. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  186. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."recruitment_recruitmentcandidature as rc ON rc.fk_recruitmentjobposition = t.rowid";
  187. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  188. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  189. }
  190. // Add table from hooks
  191. $parameters = array();
  192. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  193. $sql .= $hookmanager->resPrint;
  194. if ($object->ismultientitymanaged == 1) {
  195. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  196. } else {
  197. $sql .= " WHERE 1 = 1";
  198. }
  199. foreach ($search as $key => $val) {
  200. if (array_key_exists($key, $object->fields)) {
  201. if ($key == 'status' && $search[$key] == -1) {
  202. continue;
  203. }
  204. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  205. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  206. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  207. $search[$key] = '';
  208. }
  209. $mode_search = 2;
  210. }
  211. if ($search[$key] != '') {
  212. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  213. }
  214. } else {
  215. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  216. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  217. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  218. if (preg_match('/_dtstart$/', $key)) {
  219. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  220. }
  221. if (preg_match('/_dtend$/', $key)) {
  222. $sql .= " AND t.".$db->escape($columnName)." <= '" . $db->idate($search[$key])."'";
  223. }
  224. }
  225. }
  226. }
  227. }
  228. if ($search_all) {
  229. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  230. }
  231. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  232. // Add where from extra fields
  233. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  234. // Add where from hooks
  235. $parameters = array();
  236. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  237. $sql .= $hookmanager->resPrint;
  238. /* If a group by is required */
  239. $sql .= " GROUP BY ";
  240. foreach ($object->fields as $key => $val) {
  241. $sql .= "t.".$db->escape($key).", ";
  242. }
  243. // Add fields from extrafields
  244. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  245. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  246. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  247. }
  248. }
  249. // Add where from hooks
  250. $parameters = array();
  251. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  252. $sql .= $hookmanager->resPrint;
  253. $sql = preg_replace('/,\s*$/', '', $sql);
  254. // Count total nb of records
  255. $nbtotalofrecords = '';
  256. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  257. /* This old and fast method to get and count full list returns all record so use a high amount of memory. */
  258. $resql = $db->query($sql);
  259. $nbtotalofrecords = $db->num_rows($resql);
  260. /* The slow method does not consume memory on mysql (not tested on pgsql) */
  261. /*$resql = $db->query($sql, 0, 'auto', 1);
  262. while ($db->fetch_object($resql)) {
  263. $nbtotalofrecords++;
  264. }*/
  265. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  266. /*
  267. $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
  268. print $sqlforcount;
  269. $resql = $db->query($sqlforcount);
  270. $objforcount = $db->fetch_object($resql);
  271. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  272. */
  273. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  274. $page = 0;
  275. $offset = 0;
  276. }
  277. $db->free($resql);
  278. }
  279. // Complete request and execute it with limit
  280. $sql .= $db->order($sortfield, $sortorder);
  281. if ($limit) {
  282. $sql .= $db->plimit($limit + 1, $offset);
  283. }
  284. $resql = $db->query($sql);
  285. if (!$resql) {
  286. dol_print_error($db);
  287. exit;
  288. }
  289. $num = $db->num_rows($resql);
  290. // Direct jump if only one record found
  291. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  292. $obj = $db->fetch_object($resql);
  293. $id = $obj->rowid;
  294. header("Location: ".DOL_URL_ROOT.'/recruitment/recruitmentjobposition_card.php?id='.$id);
  295. exit;
  296. }
  297. // Output page
  298. // --------------------------------------------------------------------
  299. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
  300. $arrayofselected = is_array($toselect) ? $toselect : array();
  301. $param = '';
  302. if (!empty($mode)) {
  303. $param .= '&mode='.urlencode($mode);
  304. }
  305. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  306. $param .= '&contextpage='.urlencode($contextpage);
  307. }
  308. if ($limit > 0 && $limit != $conf->liste_limit) {
  309. $param .= '&limit='.urlencode($limit);
  310. }
  311. foreach ($search as $key => $val) {
  312. if (is_array($search[$key]) && count($search[$key])) {
  313. foreach ($search[$key] as $skey) {
  314. if ($skey != '') {
  315. $param .= '&search_'.$key.'[]='.urlencode($skey);
  316. }
  317. }
  318. } elseif ($search[$key] != '') {
  319. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  320. }
  321. }
  322. if ($optioncss != '') {
  323. $param .= '&optioncss='.urlencode($optioncss);
  324. }
  325. // Add $param from extra fields
  326. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  327. // Add $param from hooks
  328. $parameters = array();
  329. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  330. $param .= $hookmanager->resPrint;
  331. // List of mass actions available
  332. $arrayofmassactions = array(
  333. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  334. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  335. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  336. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  337. );
  338. if ($permissiontodelete) {
  339. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  340. }
  341. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  342. $arrayofmassactions = array();
  343. }
  344. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  345. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  346. if ($optioncss != '') {
  347. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  348. }
  349. print '<input type="hidden" name="token" value="'.newToken().'">';
  350. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  351. print '<input type="hidden" name="action" value="list">';
  352. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  353. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  354. //print '<input type="hidden" name="page" value="'.$page.'">';
  355. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  356. print '<input type="hidden" name="mode" value="'.$mode.'">';
  357. $newcardbutton = '';
  358. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/^&mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  359. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/^&mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  360. $newcardbutton .= dolGetButtonTitleSeparator();
  361. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/recruitment/recruitmentjobposition_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  362. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  363. // Add code for pre mass action (confirmation or email presend form)
  364. $topicmail = "SendRecruitmentJobPositionRef";
  365. $modelmail = "recruitmentjobposition";
  366. $objecttmp = new RecruitmentJobPosition($db);
  367. $trackid = 'recruitmentjobposition'.$object->id;
  368. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  369. if ($search_all) {
  370. foreach ($fieldstosearchall as $key => $val) {
  371. $fieldstosearchall[$key] = $langs->trans($val);
  372. }
  373. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  374. }
  375. $moreforfilter = '';
  376. /*$moreforfilter.='<div class="divsearchfield">';
  377. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  378. $moreforfilter.= '</div>';*/
  379. $parameters = array();
  380. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  381. if (empty($reshook)) {
  382. $moreforfilter .= $hookmanager->resPrint;
  383. } else {
  384. $moreforfilter = $hookmanager->resPrint;
  385. }
  386. if (!empty($moreforfilter)) {
  387. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  388. print $moreforfilter;
  389. print '</div>';
  390. }
  391. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  392. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  393. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  394. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  395. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  396. // Fields title search
  397. // --------------------------------------------------------------------
  398. print '<tr class="liste_titre">';
  399. foreach ($object->fields as $key => $val) {
  400. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  401. if ($key == 'status') {
  402. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  403. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  404. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  405. } elseif (in_array($val['type'], array('timestamp'))) {
  406. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  407. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  408. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  409. }
  410. if (!empty($arrayfields['t.'.$key]['checked'])) {
  411. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  412. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  413. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  414. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  415. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  416. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  417. print '<div class="nowrap">';
  418. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  419. print '</div>';
  420. print '<div class="nowrap">';
  421. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  422. print '</div>';
  423. } elseif ($key == 'lang') {
  424. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  425. $formadmin = new FormAdmin($db);
  426. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  427. } else {
  428. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  429. }
  430. print '</td>';
  431. }
  432. }
  433. // Extra fields
  434. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  435. // Fields from hook
  436. $parameters = array('arrayfields'=>$arrayfields);
  437. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  438. print $hookmanager->resPrint;
  439. if (!empty($arrayfields['nbapplications']['checked'])) {
  440. print '<td class="liste_titre"></td>';
  441. }
  442. // Action column
  443. print '<td class="liste_titre maxwidthsearch">';
  444. $searchpicto = $form->showFilterButtons();
  445. print $searchpicto;
  446. print '</td>';
  447. print '</tr>'."\n";
  448. $totalarray = array();
  449. $totalarray['nbfield'] = 0;
  450. // Fields title label
  451. // --------------------------------------------------------------------
  452. print '<tr class="liste_titre">';
  453. foreach ($object->fields as $key => $val) {
  454. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  455. if ($key == 'status') {
  456. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  457. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  458. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  459. } elseif (in_array($val['type'], array('timestamp'))) {
  460. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  461. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  462. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  463. }
  464. if (!empty($arrayfields['t.'.$key]['checked'])) {
  465. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  466. $totalarray['nbfield']++;
  467. }
  468. }
  469. // Extra fields
  470. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  471. // Hook fields
  472. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  473. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  474. print $hookmanager->resPrint;
  475. if (!empty($arrayfields['nbapplications']['checked'])) {
  476. print '<th class="liste_titre right">'.$langs->trans("RecruitmentCandidatures").'</th>';
  477. $totalarray['nbfield']++;
  478. }
  479. // Action column
  480. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  481. $totalarray['nbfield']++;
  482. print '</tr>'."\n";
  483. // Detect if we need a fetch on each output line
  484. $needToFetchEachLine = 0;
  485. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  486. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  487. if (preg_match('/\$object/', $val)) {
  488. $needToFetchEachLine++; // There is at least one compute field that use $object
  489. }
  490. }
  491. }
  492. // Loop on record
  493. // --------------------------------------------------------------------
  494. $i = 0;
  495. $savnbfield = $totalarray['nbfield'];
  496. $totalarray['nbfield'] = 0;
  497. $imaxinloop = ($limit ? min($num, $limit) : $num);
  498. while ($i < $imaxinloop) {
  499. $obj = $db->fetch_object($resql);
  500. if (empty($obj)) {
  501. break; // Should not happen
  502. }
  503. // Store properties in $object
  504. $object->setVarsFromFetchObj($obj);
  505. if ($mode == 'kanban') {
  506. if ($i == 0) {
  507. print '<tr><td colspan="'.$savnbfield.'">';
  508. print '<div class="box-flex-container">';
  509. }
  510. // Output Kanban
  511. print $object->getKanbanView('');
  512. if ($i == ($imaxinloop - 1)) {
  513. print '</div>';
  514. print '</td></tr>';
  515. }
  516. } else {
  517. // Show here line of result
  518. $j = 0;
  519. print '<tr class="oddeven">';
  520. foreach ($object->fields as $key => $val) {
  521. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  522. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  523. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  524. } elseif ($key == 'status') {
  525. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  526. }
  527. if (in_array($val['type'], array('timestamp'))) {
  528. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  529. } elseif ($key == 'ref') {
  530. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  531. }
  532. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  533. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  534. }
  535. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  536. if (!empty($arrayfields['t.'.$key]['checked'])) {
  537. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  538. if ($key == 'status') {
  539. print $object->getLibStatut(5);
  540. } elseif ($key == 'rowid') {
  541. print $object->showOutputField($val, $key, $object->id, '');
  542. } else {
  543. print $object->showOutputField($val, $key, $object->$key, '');
  544. }
  545. print '</td>';
  546. if (!$i) {
  547. $totalarray['nbfield']++;
  548. }
  549. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  550. if (!$i) {
  551. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  552. }
  553. if (!isset($totalarray['val'])) {
  554. $totalarray['val'] = array();
  555. }
  556. if (!isset($totalarray['val']['t.'.$key])) {
  557. $totalarray['val']['t.'.$key] = 0;
  558. }
  559. $totalarray['val']['t.'.$key] += $object->$key;
  560. }
  561. }
  562. }
  563. // Extra fields
  564. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  565. // Fields from hook
  566. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  567. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  568. print $hookmanager->resPrint;
  569. if (!empty($arrayfields['nbapplications']['checked'])) {
  570. print '<td class="right">'.$obj->nbapplications.'</td>';
  571. }
  572. // Action column
  573. print '<td class="nowrap center">';
  574. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  575. $selected = 0;
  576. if (in_array($object->id, $arrayofselected)) {
  577. $selected = 1;
  578. }
  579. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  580. }
  581. print '</td>';
  582. if (!$i) {
  583. $totalarray['nbfield']++;
  584. }
  585. print '</tr>'."\n";
  586. }
  587. $i++;
  588. }
  589. // Show total line
  590. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  591. // If no record found
  592. if ($num == 0) {
  593. $colspan = 1;
  594. foreach ($arrayfields as $key => $val) {
  595. if (!empty($val['checked'])) {
  596. $colspan++;
  597. }
  598. }
  599. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  600. }
  601. $db->free($resql);
  602. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  603. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  604. print $hookmanager->resPrint;
  605. print '</table>'."\n";
  606. print '</div>'."\n";
  607. print '</form>'."\n";
  608. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  609. $hidegeneratedfilelistifempty = 1;
  610. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  611. $hidegeneratedfilelistifempty = 0;
  612. }
  613. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  614. $formfile = new FormFile($db);
  615. // Show list of available documents
  616. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  617. $urlsource .= str_replace('&amp;', '&', $param);
  618. $filedir = $diroutputmassaction;
  619. $genallowed = $permissiontoread;
  620. $delallowed = $permissiontoadd;
  621. print $formfile->showdocuments('massfilesarea_recruitment', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  622. }
  623. // End of page
  624. llxFooter();
  625. $db->close();