skill_list.php 27 KB

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