job_list.php 28 KB

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