recruitmentjobposition_list.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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->hasRight('recruitment', 'recruitmentjobposition', 'read');
  112. $permissiontoadd = $user->hasRight('recruitment', 'recruitmentjobposition', 'write');
  113. $permissiontodelete = $user->hasRight('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 .= $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 (!getDolGlobalInt('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-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', '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='.((int) $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, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // 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. // Action column
  400. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  401. print '<td class="liste_titre maxwidthsearch">';
  402. $searchpicto = $form->showFilterButtons('left');
  403. print $searchpicto;
  404. print '</td>';
  405. }
  406. foreach ($object->fields as $key => $val) {
  407. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  408. if ($key == 'status') {
  409. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  410. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  411. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  412. } elseif (in_array($val['type'], array('timestamp'))) {
  413. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  414. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  415. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  416. }
  417. if (!empty($arrayfields['t.'.$key]['checked'])) {
  418. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  419. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  420. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  421. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  422. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  423. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  424. print '<div class="nowrap">';
  425. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  426. print '</div>';
  427. print '<div class="nowrap">';
  428. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  429. print '</div>';
  430. } elseif ($key == 'lang') {
  431. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  432. $formadmin = new FormAdmin($db);
  433. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  434. } else {
  435. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  436. }
  437. print '</td>';
  438. }
  439. }
  440. // Extra fields
  441. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  442. // Fields from hook
  443. $parameters = array('arrayfields'=>$arrayfields);
  444. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  445. print $hookmanager->resPrint;
  446. if (!empty($arrayfields['nbapplications']['checked'])) {
  447. print '<td class="liste_titre"></td>';
  448. }
  449. // Action column
  450. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  451. print '<td class="liste_titre maxwidthsearch">';
  452. $searchpicto = $form->showFilterButtons();
  453. print $searchpicto;
  454. print '</td>';
  455. }
  456. print '</tr>'."\n";
  457. $totalarray = array();
  458. $totalarray['nbfield'] = 0;
  459. // Fields title label
  460. // --------------------------------------------------------------------
  461. print '<tr class="liste_titre">';
  462. // Action column
  463. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  464. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  465. }
  466. foreach ($object->fields as $key => $val) {
  467. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  468. if ($key == 'status') {
  469. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  470. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  471. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  472. } elseif (in_array($val['type'], array('timestamp'))) {
  473. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  474. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  475. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  476. }
  477. if (!empty($arrayfields['t.'.$key]['checked'])) {
  478. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  479. $totalarray['nbfield']++;
  480. }
  481. }
  482. // Extra fields
  483. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  484. // Hook fields
  485. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  486. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  487. print $hookmanager->resPrint;
  488. if (!empty($arrayfields['nbapplications']['checked'])) {
  489. print '<th class="liste_titre right">'.$langs->trans("RecruitmentCandidatures").'</th>';
  490. $totalarray['nbfield']++;
  491. }
  492. // Action column
  493. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  494. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  495. }
  496. $totalarray['nbfield']++;
  497. print '</tr>'."\n";
  498. // Detect if we need a fetch on each output line
  499. $needToFetchEachLine = 0;
  500. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  501. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  502. if (preg_match('/\$object/', $val)) {
  503. $needToFetchEachLine++; // There is at least one compute field that use $object
  504. }
  505. }
  506. }
  507. // Loop on record
  508. // --------------------------------------------------------------------
  509. $i = 0;
  510. $savnbfield = $totalarray['nbfield'];
  511. $totalarray['nbfield'] = 0;
  512. $imaxinloop = ($limit ? min($num, $limit) : $num);
  513. while ($i < $imaxinloop) {
  514. $obj = $db->fetch_object($resql);
  515. if (empty($obj)) {
  516. break; // Should not happen
  517. }
  518. // Store properties in $object
  519. $object->setVarsFromFetchObj($obj);
  520. $object->date_planned = $obj->date_planned;
  521. if ($mode == 'kanban') {
  522. if ($i == 0) {
  523. print '<tr><td colspan="'.$savnbfield.'">';
  524. print '<div class="box-flex-container kanban">';
  525. }
  526. if ($massactionbutton || $massaction) {
  527. $selected = 0;
  528. }
  529. // Output Kanban
  530. print $object->getKanbanView('', array('nbapplications'=>$obj->nbapplications, 'selected' => in_array($object->id, $arrayofselected)));
  531. if ($i == ($imaxinloop - 1)) {
  532. print '</div>';
  533. print '</td></tr>';
  534. }
  535. } else {
  536. // Show here line of result
  537. $j = 0;
  538. print '<tr class="oddeven">';
  539. // Action column
  540. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  541. print '<td class="nowrap center">';
  542. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  543. $selected = 0;
  544. if (in_array($object->id, $arrayofselected)) {
  545. $selected = 1;
  546. }
  547. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  548. }
  549. print '</td>';
  550. }
  551. foreach ($object->fields as $key => $val) {
  552. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  553. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  554. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  555. } elseif ($key == 'status') {
  556. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  557. }
  558. if (in_array($val['type'], array('timestamp'))) {
  559. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  560. } elseif ($key == 'ref') {
  561. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  562. }
  563. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  564. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  565. }
  566. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  567. if (!empty($arrayfields['t.'.$key]['checked'])) {
  568. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  569. if ($key == 'status') {
  570. print $object->getLibStatut(5);
  571. } elseif ($key == 'rowid') {
  572. print $object->showOutputField($val, $key, $object->id, '');
  573. } else {
  574. print $object->showOutputField($val, $key, $object->$key, '');
  575. }
  576. print '</td>';
  577. if (!$i) {
  578. $totalarray['nbfield']++;
  579. }
  580. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  581. if (!$i) {
  582. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  583. }
  584. if (!isset($totalarray['val'])) {
  585. $totalarray['val'] = array();
  586. }
  587. if (!isset($totalarray['val']['t.'.$key])) {
  588. $totalarray['val']['t.'.$key] = 0;
  589. }
  590. $totalarray['val']['t.'.$key] += $object->$key;
  591. }
  592. }
  593. }
  594. // Extra fields
  595. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  596. // Fields from hook
  597. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  598. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  599. print $hookmanager->resPrint;
  600. if (!empty($arrayfields['nbapplications']['checked'])) {
  601. print '<td class="right">'.$obj->nbapplications.'</td>';
  602. }
  603. // Action column
  604. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  605. print '<td class="nowrap center">';
  606. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  607. $selected = 0;
  608. if (in_array($object->id, $arrayofselected)) {
  609. $selected = 1;
  610. }
  611. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  612. }
  613. print '</td>';
  614. }
  615. if (!$i) {
  616. $totalarray['nbfield']++;
  617. }
  618. print '</tr>'."\n";
  619. }
  620. $i++;
  621. }
  622. // Show total line
  623. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  624. // If no record found
  625. if ($num == 0) {
  626. $colspan = 1;
  627. foreach ($arrayfields as $key => $val) {
  628. if (!empty($val['checked'])) {
  629. $colspan++;
  630. }
  631. }
  632. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  633. }
  634. $db->free($resql);
  635. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  636. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  637. print $hookmanager->resPrint;
  638. print '</table>'."\n";
  639. print '</div>'."\n";
  640. print '</form>'."\n";
  641. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  642. $hidegeneratedfilelistifempty = 1;
  643. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  644. $hidegeneratedfilelistifempty = 0;
  645. }
  646. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  647. $formfile = new FormFile($db);
  648. // Show list of available documents
  649. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  650. $urlsource .= str_replace('&amp;', '&', $param);
  651. $filedir = $diroutputmassaction;
  652. $genallowed = $permissiontoread;
  653. $delallowed = $permissiontoadd;
  654. print $formfile->showdocuments('massfilesarea_recruitment', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  655. }
  656. // End of page
  657. llxFooter();
  658. $db->close();