skill_list.php 33 KB

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