evaluation_list.php 33 KB

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