list.php 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. <?php
  2. /* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
  3. * Copyright (C) 2013-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
  6. * Copyright (C) 2019-2022 Frédéric France <frederic.france@netlogic.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/holiday/list.php
  23. * \ingroup holiday
  24. * \brief List of holiday
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  37. // Load translation files required by the page
  38. $langs->loadLangs(array('users', 'other', 'holiday', 'hrm'));
  39. // Protection if external user
  40. if ($user->socid > 0) {
  41. accessforbidden();
  42. }
  43. $action = GETPOST('action', 'aZ09'); // The action 'add', 'create', 'edit', 'update', 'view', ...
  44. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  45. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  46. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  47. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  48. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  49. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'holidaylist'; // To manage different context of search
  50. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  51. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  52. $id = GETPOST('id', 'int');
  53. $childids = $user->getAllChildIds(1);
  54. $diroutputmassaction = $conf->holiday->dir_output.'/temp/massgeneration/'.$user->id;
  55. // Load variable for pagination
  56. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  57. $sortfield = GETPOST('sortfield', 'aZ09comma');
  58. $sortorder = GETPOST('sortorder', 'aZ09comma');
  59. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  60. if (empty($page) || $page == -1) {
  61. $page = 0;
  62. } // If $page is not defined, or '' or -1
  63. $offset = $limit * $page;
  64. $pageprev = $page - 1;
  65. $pagenext = $page + 1;
  66. if (!$sortorder) {
  67. $sortorder = "DESC";
  68. }
  69. if (!$sortfield) {
  70. $sortfield = "cp.ref";
  71. }
  72. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  73. $search_ref = GETPOST('search_ref', 'alphanohtml');
  74. $search_day_create = GETPOST('search_day_create', 'int');
  75. $search_month_create = GETPOST('search_month_create', 'int');
  76. $search_year_create = GETPOST('search_year_create', 'int');
  77. $search_day_start = GETPOST('search_day_start', 'int');
  78. $search_month_start = GETPOST('search_month_start', 'int');
  79. $search_year_start = GETPOST('search_year_start', 'int');
  80. $search_day_end = GETPOST('search_day_end', 'int');
  81. $search_month_end = GETPOST('search_month_end', 'int');
  82. $search_year_end = GETPOST('search_year_end', 'int');
  83. $search_employee = GETPOST('search_employee', 'int');
  84. $search_valideur = GETPOST('search_valideur', 'int');
  85. $search_status = GETPOSTISSET('search_status') ? GETPOST('search_status', 'int') : GETPOST('search_statut', 'int');
  86. $search_type = GETPOST('search_type', 'int');
  87. // Initialize technical objects
  88. $object = new Holiday($db);
  89. $extrafields = new ExtraFields($db);
  90. $hookmanager->initHooks(array('holidaylist')); // Note that conf->hooks_modules contains array
  91. // Fetch optionals attributes and labels
  92. $extrafields->fetch_name_optionals_label($object->table_element);
  93. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  94. // List of fields to search into when doing a "search in all"
  95. $fieldstosearchall = array(
  96. 'cp.ref'=>'Ref',
  97. 'cp.description'=>'Description',
  98. 'uu.lastname'=>'EmployeeLastname',
  99. 'uu.firstname'=>'EmployeeFirstname',
  100. 'uu.login'=>'Login'
  101. );
  102. $arrayfields = array(
  103. 'cp.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  104. 'cp.fk_user'=>array('label'=>$langs->trans("Employee"), 'checked'=>1, 'position'=>20),
  105. 'cp.fk_validator'=>array('label'=>$langs->trans("ValidatorCP"), 'checked'=>1, 'position'=>30),
  106. 'cp.fk_type'=>array('label'=>$langs->trans("Type"), 'checked'=>1, 'position'=>35),
  107. 'duration'=>array('label'=>$langs->trans("NbUseDaysCPShort"), 'checked'=>1, 'position'=>38),
  108. 'cp.date_debut'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1, 'position'=>40),
  109. 'cp.date_fin'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1, 'position'=>42),
  110. 'cp.date_valid'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1, 'position'=>60),
  111. 'cp.date_approval'=>array('label'=>$langs->trans("DateApprove"), 'checked'=>1, 'position'=>70),
  112. 'cp.date_create'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  113. 'cp.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>501),
  114. 'cp.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  115. );
  116. // Extra fields
  117. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  118. // Security check
  119. $socid = 0;
  120. if ($user->socid > 0) { // Protection if external user
  121. //$socid = $user->socid;
  122. accessforbidden();
  123. }
  124. if (empty($conf->holiday->enabled)) accessforbidden('Module not enabled');
  125. $result = restrictedArea($user, 'holiday', '', '');
  126. // If we are on the view of a specific user
  127. if ($id > 0) {
  128. $canread = 0;
  129. if ($id == $user->id) {
  130. $canread = 1;
  131. }
  132. if (!empty($user->rights->holiday->readall)) {
  133. $canread = 1;
  134. }
  135. if (!empty($user->rights->holiday->read) && in_array($id, $childids)) {
  136. $canread = 1;
  137. }
  138. if (!$canread) {
  139. accessforbidden();
  140. }
  141. }
  142. /*
  143. * Actions
  144. */
  145. if (GETPOST('cancel', 'alpha')) {
  146. $action = 'list'; $massaction = '';
  147. }
  148. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  149. $massaction = '';
  150. }
  151. $parameters = array('socid'=>$socid);
  152. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  153. if ($reshook < 0) {
  154. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  155. }
  156. if (empty($reshook)) {
  157. // Selection of new fields
  158. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  159. // Purge search criteria
  160. 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
  161. $search_ref = "";
  162. $search_month_create = "";
  163. $search_year_create = "";
  164. $search_month_start = "";
  165. $search_year_start = "";
  166. $search_month_end = "";
  167. $search_year_end = "";
  168. $search_employee = "";
  169. $search_valideur = "";
  170. $search_status = "";
  171. $search_type = '';
  172. $toselect = array();
  173. $search_array_options = array();
  174. }
  175. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  176. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  177. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  178. }
  179. // Mass actions
  180. $objectclass = 'Holiday';
  181. $objectlabel = 'Holiday';
  182. $permissiontoread = $user->hasRight('holiday', 'read');
  183. $permissiontodelete = $user->hasRight('holiday', 'delete');
  184. $permissiontoapprove = $user->hasRight('holiday', 'approve');
  185. $uploaddir = $conf->holiday->dir_output;
  186. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  187. }
  188. /*
  189. * View
  190. */
  191. $form = new Form($db);
  192. $formother = new FormOther($db);
  193. $formfile = new FormFile($db);
  194. $fuser = new User($db);
  195. $holidaystatic = new Holiday($db);
  196. // Update sold
  197. $result = $object->updateBalance();
  198. $title = $langs->trans('CPTitreMenu');
  199. llxHeader('', $title);
  200. $max_year = 5;
  201. $min_year = 10;
  202. // Get current user id
  203. $user_id = $user->id;
  204. if ($id > 0) {
  205. // Charge utilisateur edite
  206. $fuser->fetch($id, '', '', 1);
  207. $fuser->getrights();
  208. $user_id = $fuser->id;
  209. $search_employee = $user_id;
  210. }
  211. // Récupération des congés payés de l'utilisateur ou de tous les users de sa hierarchy
  212. // Load array $object->holiday
  213. $sql = "SELECT";
  214. $sql .= " cp.rowid,";
  215. $sql .= " cp.ref,";
  216. $sql .= " cp.fk_user,";
  217. $sql .= " cp.fk_type,";
  218. $sql .= " cp.date_create,";
  219. $sql .= " cp.tms as date_update,";
  220. $sql .= " cp.description,";
  221. $sql .= " cp.date_debut,";
  222. $sql .= " cp.date_fin,";
  223. $sql .= " cp.halfday,";
  224. $sql .= " cp.statut as status,";
  225. $sql .= " cp.fk_validator,";
  226. $sql .= " cp.date_valid,";
  227. $sql .= " cp.fk_user_valid,";
  228. $sql .= " cp.date_approval,";
  229. $sql .= " cp.fk_user_approve,";
  230. $sql .= " cp.date_refuse,";
  231. $sql .= " cp.fk_user_refuse,";
  232. $sql .= " cp.date_cancel,";
  233. $sql .= " cp.fk_user_cancel,";
  234. $sql .= " cp.detail_refuse,";
  235. $sql .= " uu.lastname as user_lastname,";
  236. $sql .= " uu.firstname as user_firstname,";
  237. $sql .= " uu.admin as user_admin,";
  238. $sql .= " uu.email as user_email,";
  239. $sql .= " uu.login as user_login,";
  240. $sql .= " uu.statut as user_status,";
  241. $sql .= " uu.photo as user_photo,";
  242. $sql .= " ua.lastname as validator_lastname,";
  243. $sql .= " ua.firstname as validator_firstname,";
  244. $sql .= " ua.admin as validator_admin,";
  245. $sql .= " ua.email as validator_email,";
  246. $sql .= " ua.login as validator_login,";
  247. $sql .= " ua.statut as validator_status,";
  248. $sql .= " ua.photo as validator_photo";
  249. // Add fields from extrafields
  250. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  251. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  252. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  253. }
  254. }
  255. // Add fields from hooks
  256. $parameters = array();
  257. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  258. $sql .= $hookmanager->resPrint;
  259. $sqlfields = $sql; // $sql fields to remove for count total
  260. $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
  261. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  262. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cp.rowid = ef.fk_object)";
  263. }
  264. $sql .= ", ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
  265. $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
  266. $sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
  267. // Search all
  268. if (!empty($sall)) {
  269. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  270. }
  271. // Ref
  272. if (!empty($search_ref)) {
  273. $sql .= natural_search("cp.ref", $search_ref);
  274. }
  275. // Start date
  276. $sql .= dolSqlDateFilter("cp.date_debut", $search_day_start, $search_month_start, $search_year_start);
  277. // End date
  278. $sql .= dolSqlDateFilter("cp.date_fin", $search_day_end, $search_month_end, $search_year_end);
  279. // Create date
  280. $sql .= dolSqlDateFilter("cp.date_create", $search_day_create, $search_month_create, $search_year_create);
  281. // Employee
  282. if (!empty($search_employee) && $search_employee != -1) {
  283. $sql .= " AND cp.fk_user = '".$db->escape($search_employee)."'\n";
  284. }
  285. // Validator
  286. if (!empty($search_valideur) && $search_valideur != -1) {
  287. $sql .= " AND cp.fk_validator = '".$db->escape($search_valideur)."'\n";
  288. }
  289. // Type
  290. if (!empty($search_type) && $search_type != -1) {
  291. $sql .= ' AND cp.fk_type IN ('.$db->sanitize($db->escape($search_type)).')';
  292. }
  293. // Status
  294. if (!empty($search_status) && $search_status != -1) {
  295. $sql .= " AND cp.statut = '".$db->escape($search_status)."'\n";
  296. }
  297. if (empty($user->rights->holiday->readall)) {
  298. $sql .= ' AND cp.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
  299. }
  300. if ($id > 0) {
  301. $sql .= " AND cp.fk_user IN (".$db->sanitize($id).")";
  302. }
  303. // Add where from extra fields
  304. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  305. // Add where from hooks
  306. $parameters = array();
  307. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  308. $sql .= $hookmanager->resPrint;
  309. // Count total nb of records
  310. $nbtotalofrecords = '';
  311. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  312. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  313. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  314. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  315. $resql = $db->query($sqlforcount);
  316. if ($resql) {
  317. $objforcount = $db->fetch_object($resql);
  318. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  319. } else {
  320. dol_print_error($db);
  321. }
  322. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  323. $page = 0;
  324. $offset = 0;
  325. }
  326. $db->free($resql);
  327. }
  328. // Complete request and execute it with limit
  329. $sql .= $db->order($sortfield, $sortorder);
  330. if ($limit) {
  331. $sql .= $db->plimit($limit + 1, $offset);
  332. }
  333. //print $sql;
  334. $resql = $db->query($sql);
  335. if ($resql) {
  336. $num = $db->num_rows($resql);
  337. $arrayofselected = is_array($toselect) ? $toselect : array();
  338. $param = '';
  339. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  340. $param .= '&contextpage='.urlencode($contextpage);
  341. }
  342. if ($limit > 0 && $limit != $conf->liste_limit) {
  343. $param .= '&limit='.urlencode($limit);
  344. }
  345. if ($optioncss != '') {
  346. $param .= '&optioncss='.urlencode($optioncss);
  347. }
  348. if ($search_ref) {
  349. $param .= '&search_ref='.urlencode($search_ref);
  350. }
  351. if ($search_day_create) {
  352. $param .= '&search_day_create='.urlencode($search_day_create);
  353. }
  354. if ($search_month_create) {
  355. $param .= '&search_month_create='.urlencode($search_month_create);
  356. }
  357. if ($search_year_create) {
  358. $param .= '&search_year_create='.urlencode($search_year_create);
  359. }
  360. if ($search_day_start) {
  361. $param .= '&search_day_start='.urlencode($search_day_start);
  362. }
  363. if ($search_month_start) {
  364. $param .= '&search_month_start='.urlencode($search_month_start);
  365. }
  366. if ($search_year_start) {
  367. $param .= '&search_year_start='.urlencode($search_year_start);
  368. }
  369. if ($search_day_end) {
  370. $param .= '&search_day_end='.urlencode($search_day_end);
  371. }
  372. if ($search_month_end) {
  373. $param .= '&search_month_end='.urlencode($search_month_end);
  374. }
  375. if ($search_year_end) {
  376. $param .= '&search_year_end='.urlencode($search_year_end);
  377. }
  378. if ($search_employee > 0) {
  379. $param .= '&search_employee='.urlencode($search_employee);
  380. }
  381. if ($search_valideur > 0) {
  382. $param .= '&search_valideur='.urlencode($search_valideur);
  383. }
  384. if ($search_type > 0) {
  385. $param .= '&search_type='.urlencode($search_type);
  386. }
  387. if ($search_status > 0) {
  388. $param .= '&search_status='.urlencode($search_status);
  389. }
  390. // Add $param from extra fields
  391. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  392. // List of mass actions available
  393. $arrayofmassactions = array(
  394. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  395. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  396. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  397. );
  398. if (!empty($user->rights->holiday->delete)) {
  399. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  400. }
  401. if (!empty($user->rights->holiday->approve)) {
  402. $arrayofmassactions['preapproveleave'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Approve");
  403. }
  404. if (in_array($massaction, array('presend', 'predelete'))) {
  405. $arrayofmassactions = array();
  406. }
  407. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  408. // Lines of title fields
  409. print '<form id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  410. if ($optioncss != '') {
  411. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  412. }
  413. print '<input type="hidden" name="token" value="'.newToken().'">';
  414. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  415. print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'list').'">';
  416. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  417. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  418. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  419. if ($id > 0) {
  420. print '<input type="hidden" name="id" value="'.$id.'">';
  421. }
  422. if ($id > 0) { // For user tab
  423. $title = $langs->trans("User");
  424. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  425. $head = user_prepare_head($fuser);
  426. print dol_get_fiche_head($head, 'paidholidays', $title, -1, 'user');
  427. dol_banner_tab($fuser, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
  428. if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) {
  429. print '<div class="underbanner clearboth"></div>';
  430. print '<br>';
  431. showMyBalance($object, $user_id);
  432. }
  433. print dol_get_fiche_end();
  434. // Buttons for actions
  435. print '<div class="tabsAction">';
  436. $cancreate = 0;
  437. if (!empty($user->rights->holiday->writeall)) {
  438. $cancreate = 1;
  439. }
  440. if (!empty($user->rights->holiday->write) && in_array($user_id, $childids)) {
  441. $cancreate = 1;
  442. }
  443. if ($cancreate) {
  444. print '<a href="'.DOL_URL_ROOT.'/holiday/card.php?action=create&fuserid='.$user_id.'" class="butAction">'.$langs->trans("AddCP").'</a>';
  445. }
  446. print '</div>';
  447. } else {
  448. $title = $langs->trans("ListeCP");
  449. $newcardbutton = dolGetButtonTitle($langs->trans('MenuAddCP'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/holiday/card.php?action=create', '', $user->rights->holiday->write);
  450. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_hrm', 0, $newcardbutton, '', $limit, 0, 0, 1);
  451. }
  452. $topicmail = "Information";
  453. $modelmail = "leaverequest";
  454. $objecttmp = new Holiday($db);
  455. $trackid = 'leav'.$object->id;
  456. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  457. if ($sall) {
  458. foreach ($fieldstosearchall as $key => $val) {
  459. $fieldstosearchall[$key] = $langs->trans($val);
  460. }
  461. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  462. }
  463. $moreforfilter = '';
  464. $parameters = array();
  465. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  466. if (empty($reshook)) {
  467. $moreforfilter .= $hookmanager->resPrint;
  468. } else {
  469. $moreforfilter = $hookmanager->resPrint;
  470. }
  471. if (!empty($moreforfilter)) {
  472. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  473. print $moreforfilter;
  474. print '</div>';
  475. }
  476. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  477. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  478. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  479. $include = '';
  480. if (empty($user->rights->holiday->readall)) {
  481. $include = 'hierarchyme'; // Can see only its hierarchyl
  482. }
  483. print '<div class="div-table-responsive">';
  484. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  485. // Filters
  486. print '<tr class="liste_titre_filter">';
  487. // Action column
  488. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  489. print '<td class="liste_titre maxwidthsearch">';
  490. $searchpicto = $form->showFilterButtons('left');
  491. print $searchpicto;
  492. print '</td>';
  493. }
  494. if (!empty($arrayfields['cp.ref']['checked'])) {
  495. print '<td class="liste_titre">';
  496. print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  497. print '</td>';
  498. }
  499. if (!empty($arrayfields['cp.fk_user']['checked'])) {
  500. $morefilter = '';
  501. if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) {
  502. $morefilter = 'AND employee = 1';
  503. }
  504. // User
  505. $disabled = 0;
  506. // If into the tab holiday of a user ($id is set in such a case)
  507. if ($id && !GETPOSTISSET('search_employee')) {
  508. $search_employee = $id;
  509. $disabled = 1;
  510. }
  511. print '<td class="liste_titre maxwidthonsmartphone left">';
  512. print $form->select_dolusers($search_employee, "search_employee", 1, "", $disabled, $include, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth125');
  513. print '</td>';
  514. }
  515. // Approver
  516. if (!empty($arrayfields['cp.fk_validator']['checked'])) {
  517. if ($user->hasRight('holiday', 'readall')) {
  518. print '<td class="liste_titre maxwidthonsmartphone left">';
  519. $validator = new UserGroup($db);
  520. $excludefilter = $user->admin ? '' : 'u.rowid <> '.$user->id;
  521. $valideurobjects = $validator->listUsersForGroup($excludefilter, 1);
  522. $valideurarray = array();
  523. foreach ($valideurobjects as $val) {
  524. $valideurarray[$val->id] = $val->id;
  525. }
  526. print $form->select_dolusers($search_valideur, "search_valideur", 1, "", 0, $valideurarray, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth125');
  527. print '</td>';
  528. } else {
  529. print '<td class="liste_titre">&nbsp;</td>';
  530. }
  531. }
  532. // Type
  533. if (!empty($arrayfields['cp.fk_type']['checked'])) {
  534. print '<td class="liste_titre">';
  535. if (empty($mysoc->country_id)) {
  536. setEventMessages(null, array($langs->trans("ErrorSetACountryFirst"), $langs->trans("CompanyFoundation")), 'errors');
  537. } else {
  538. $typeleaves = $holidaystatic->getTypes(1, -1);
  539. $arraytypeleaves = array();
  540. foreach ($typeleaves as $key => $val) {
  541. $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
  542. //$labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':'');
  543. $arraytypeleaves[$val['rowid']] = $labeltoshow;
  544. }
  545. print $form->selectarray('search_type', $arraytypeleaves, $search_type, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100', 1);
  546. }
  547. print '</td>';
  548. }
  549. // Duration
  550. if (!empty($arrayfields['duration']['checked'])) {
  551. print '<td class="liste_titre">&nbsp;</td>';
  552. }
  553. // Start date
  554. if (!empty($arrayfields['cp.date_debut']['checked'])) {
  555. print '<td class="liste_titre center nowraponall">';
  556. print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_start" value="'.dol_escape_htmltag($search_month_start).'">';
  557. print $formother->selectyear($search_year_start, 'search_year_start', 1, $min_year, $max_year);
  558. print '</td>';
  559. }
  560. // End date
  561. if (!empty($arrayfields['cp.date_fin']['checked'])) {
  562. print '<td class="liste_titre center nowraponall">';
  563. print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_end" value="'.dol_escape_htmltag($search_month_end).'">';
  564. print $formother->selectyear($search_year_end, 'search_year_end', 1, $min_year, $max_year);
  565. print '</td>';
  566. }
  567. // Date validation
  568. if (!empty($arrayfields['cp.date_valid']['checked'])) {
  569. print '<td class="liste_titre center nowraponall">';
  570. print '</td>';
  571. }
  572. // Date appoval
  573. if (!empty($arrayfields['cp.date_approval']['checked'])) {
  574. print '<td class="liste_titre center nowraponall">';
  575. print '</td>';
  576. }
  577. // Extra fields
  578. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  579. // Fields from hook
  580. $parameters = array('arrayfields'=>$arrayfields);
  581. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  582. print $hookmanager->resPrint;
  583. // Create date
  584. if (!empty($arrayfields['cp.date_create']['checked'])) {
  585. print '<td class="liste_titre center width200">';
  586. print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_create" value="'.dol_escape_htmltag($search_month_create).'">';
  587. print $formother->selectyear($search_year_create, 'search_year_create', 1, $min_year, 0);
  588. print '</td>';
  589. }
  590. // Create date
  591. if (!empty($arrayfields['cp.tms']['checked'])) {
  592. print '<td class="liste_titre center width200">';
  593. print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_update" value="'.dol_escape_htmltag($search_month_update).'">';
  594. print $formother->selectyear($search_year_update, 'search_year_update', 1, $min_year, 0);
  595. print '</td>';
  596. }
  597. // Status
  598. if (!empty($arrayfields['cp.statut']['checked'])) {
  599. print '<td class="liste_titre right">';
  600. $object->selectStatutCP($search_status, 'search_status', 'minwidth125');
  601. print '</td>';
  602. }
  603. // Action column
  604. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  605. print '<td class="liste_titre maxwidthsearch">';
  606. $searchpicto = $form->showFilterButtons();
  607. print $searchpicto;
  608. print '</td>';
  609. }
  610. print "</tr>\n";
  611. print '<tr class="liste_titre">';
  612. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  613. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
  614. }
  615. if (!empty($arrayfields['cp.ref']['checked'])) {
  616. print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], "cp.ref", "", $param, '', $sortfield, $sortorder);
  617. }
  618. if (!empty($arrayfields['cp.fk_user']['checked'])) {
  619. print_liste_field_titre($arrayfields['cp.fk_user']['label'], $_SERVER["PHP_SELF"], "cp.fk_user", "", $param, '', $sortfield, $sortorder);
  620. }
  621. if (!empty($arrayfields['cp.fk_validator']['checked'])) {
  622. print_liste_field_titre($arrayfields['cp.fk_validator']['label'], $_SERVER["PHP_SELF"], "cp.fk_validator", "", $param, '', $sortfield, $sortorder);
  623. }
  624. if (!empty($arrayfields['cp.fk_type']['checked'])) {
  625. print_liste_field_titre($arrayfields['cp.fk_type']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
  626. }
  627. if (!empty($arrayfields['duration']['checked'])) {
  628. print_liste_field_titre($arrayfields['duration']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right maxwidth100');
  629. }
  630. if (!empty($arrayfields['cp.date_debut']['checked'])) {
  631. print_liste_field_titre($arrayfields['cp.date_debut']['label'], $_SERVER["PHP_SELF"], "cp.date_debut", "", $param, '', $sortfield, $sortorder, 'center ');
  632. }
  633. if (!empty($arrayfields['cp.date_fin']['checked'])) {
  634. print_liste_field_titre($arrayfields['cp.date_fin']['label'], $_SERVER["PHP_SELF"], "cp.date_fin", "", $param, '', $sortfield, $sortorder, 'center ');
  635. }
  636. if (!empty($arrayfields['cp.date_valid']['checked'])) {
  637. print_liste_field_titre($arrayfields['cp.date_valid']['label'], $_SERVER["PHP_SELF"], "cp.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
  638. }
  639. if (!empty($arrayfields['cp.date_approval']['checked'])) {
  640. print_liste_field_titre($arrayfields['cp.date_approval']['label'], $_SERVER["PHP_SELF"], "cp.date_approval", "", $param, '', $sortfield, $sortorder, 'center ');
  641. }
  642. // Extra fields
  643. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  644. // Hook fields
  645. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  646. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  647. print $hookmanager->resPrint;
  648. if (!empty($arrayfields['cp.date_create']['checked'])) {
  649. print_liste_field_titre($arrayfields['cp.date_create']['label'], $_SERVER["PHP_SELF"], "cp.date_create", "", $param, '', $sortfield, $sortorder, 'center ');
  650. }
  651. if (!empty($arrayfields['cp.tms']['checked'])) {
  652. print_liste_field_titre($arrayfields['cp.tms']['label'], $_SERVER["PHP_SELF"], "cp.tms", "", $param, '', $sortfield, $sortorder, 'center ');
  653. }
  654. if (!empty($arrayfields['cp.statut']['checked'])) {
  655. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "cp.statut", "", $param, '', $sortfield, $sortorder, 'right ');
  656. }
  657. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  658. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
  659. }
  660. print "</tr>\n";
  661. $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
  662. // If we ask a dedicated card and not allow to see it, we force on user.
  663. if ($id && empty($user->rights->holiday->readall) && !in_array($id, $childids)) {
  664. $langs->load("errors");
  665. print '<tr class="oddeven opacitymediuem"><td colspan="10">'.$langs->trans("NotEnoughPermissions").'</td></tr>';
  666. $result = 0;
  667. } elseif ($num > 0 && !empty($mysoc->country_id)) {
  668. // Lines
  669. $userstatic = new User($db);
  670. $approbatorstatic = new User($db);
  671. $typeleaves = $object->getTypes(1, -1);
  672. $i = 0;
  673. $totalarray = array();
  674. $totalarray['nbfield'] = 0;
  675. $totalduration = 0;
  676. while ($i < min($num, $limit)) {
  677. $obj = $db->fetch_object($resql);
  678. // Leave request
  679. $holidaystatic->id = $obj->rowid;
  680. $holidaystatic->ref = ($obj->ref ? $obj->ref : $obj->rowid);
  681. $holidaystatic->statut = $obj->status;
  682. $holidaystatic->date_debut = $db->jdate($obj->date_debut);
  683. // User
  684. $userstatic->id = $obj->fk_user;
  685. $userstatic->lastname = $obj->user_lastname;
  686. $userstatic->firstname = $obj->user_firstname;
  687. $userstatic->admin = $obj->user_admin;
  688. $userstatic->email = $obj->user_email;
  689. $userstatic->login = $obj->user_login;
  690. $userstatic->statut = $obj->user_status;
  691. $userstatic->photo = $obj->user_photo;
  692. // Validator
  693. $approbatorstatic->id = $obj->fk_validator;
  694. $approbatorstatic->lastname = $obj->validator_lastname;
  695. $approbatorstatic->firstname = $obj->validator_firstname;
  696. $approbatorstatic->admin = $obj->validator_admin;
  697. $approbatorstatic->email = $obj->validator_email;
  698. $approbatorstatic->login = $obj->validator_login;
  699. $approbatorstatic->statut = $obj->validator_status;
  700. $approbatorstatic->photo = $obj->validator_photo;
  701. $date = $obj->date_create;
  702. $date_modif = $obj->date_update;
  703. $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning';
  704. $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon';
  705. print '<tr class="oddeven">';
  706. // Action column
  707. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  708. print '<td class="nowrap center">';
  709. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  710. $selected = 0;
  711. if (in_array($obj->rowid, $arrayofselected)) {
  712. $selected = 1;
  713. }
  714. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  715. }
  716. print '</td>';
  717. if (!$i) {
  718. $totalarray['nbfield']++;
  719. }
  720. }
  721. if (!empty($arrayfields['cp.ref']['checked'])) {
  722. print '<td class="nowraponall">';
  723. print $holidaystatic->getNomUrl(1, 1);
  724. print '</td>';
  725. if (!$i) {
  726. $totalarray['nbfield']++;
  727. }
  728. }
  729. if (!empty($arrayfields['cp.fk_user']['checked'])) {
  730. print '<td class="tdoverflowmax125">'.$userstatic->getNomUrl(-1, 'leave').'</td>';
  731. if (!$i) {
  732. $totalarray['nbfield']++;
  733. }
  734. }
  735. if (!empty($arrayfields['cp.fk_validator']['checked'])) {
  736. print '<td class="tdoverflowmax125">'.$approbatorstatic->getNomUrl(-1).'</td>';
  737. if (!$i) {
  738. $totalarray['nbfield']++;
  739. }
  740. }
  741. if (!empty($arrayfields['cp.fk_type']['checked'])) {
  742. if (empty($typeleaves[$obj->fk_type])) {
  743. $labeltypeleavetoshow = $langs->trans("TypeWasDisabledOrRemoved", $obj->fk_type);
  744. } else {
  745. $labeltypeleavetoshow = ($langs->trans($typeleaves[$obj->fk_type]['code']) != $typeleaves[$obj->fk_type]['code'] ? $langs->trans($typeleaves[$obj->fk_type]['code']) : $typeleaves[$obj->fk_type]['label']);
  746. }
  747. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labeltypeleavetoshow).'">';
  748. print $labeltypeleavetoshow;
  749. print '</td>';
  750. if (!$i) {
  751. $totalarray['nbfield']++;
  752. }
  753. }
  754. if (!empty($arrayfields['duration']['checked'])) {
  755. print '<td class="right">';
  756. $nbopenedday = num_open_day($db->jdate($obj->date_debut, 1), $db->jdate($obj->date_fin, 1), 0, 1, $obj->halfday); // user jdate(..., 1) because num_open_day need UTC dates
  757. $totalduration += $nbopenedday;
  758. print $nbopenedday;
  759. //print ' '.$langs->trans('DurationDays');
  760. print '</td>';
  761. if (!$i) {
  762. $totalarray['nbfield']++;
  763. }
  764. }
  765. if (!empty($arrayfields['cp.date_debut']['checked'])) {
  766. print '<td class="center">';
  767. print dol_print_date($db->jdate($obj->date_debut), 'day');
  768. print ' <span class="opacitymedium nowraponall">('.$langs->trans($listhalfday[$starthalfday]).')</span>';
  769. print '</td>';
  770. if (!$i) {
  771. $totalarray['nbfield']++;
  772. }
  773. }
  774. if (!empty($arrayfields['cp.date_fin']['checked'])) {
  775. print '<td class="center">';
  776. print dol_print_date($db->jdate($obj->date_fin), 'day');
  777. print ' <span class="opacitymedium nowraponall">('.$langs->trans($listhalfday[$endhalfday]).')</span>';
  778. print '</td>';
  779. if (!$i) {
  780. $totalarray['nbfield']++;
  781. }
  782. }
  783. // Date validation
  784. if (!empty($arrayfields['cp.date_valid']['checked'])) { // date_valid is both date_valid but also date_approval
  785. print '<td class="center" title="'.dol_print_date($db->jdate($obj->date_valid), 'dayhour').'">';
  786. print dol_print_date($db->jdate($obj->date_valid), 'day');
  787. print '</td>';
  788. if (!$i) $totalarray['nbfield']++;
  789. }
  790. // Date approval
  791. if (!empty($arrayfields['cp.date_approval']['checked'])) {
  792. print '<td class="center" title="'.dol_print_date($db->jdate($obj->date_approval), 'dayhour').'">';
  793. print dol_print_date($db->jdate($obj->date_approval), 'day');
  794. print '</td>';
  795. if (!$i) $totalarray['nbfield']++;
  796. }
  797. // Extra fields
  798. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  799. // Fields from hook
  800. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  801. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  802. print $hookmanager->resPrint;
  803. // Date creation
  804. if (!empty($arrayfields['cp.date_create']['checked'])) {
  805. print '<td style="text-align: center;">'.dol_print_date($date, 'dayhour').'</td>';
  806. if (!$i) {
  807. $totalarray['nbfield']++;
  808. }
  809. }
  810. if (!empty($arrayfields['cp.tms']['checked'])) {
  811. print '<td style="text-align: center;">'.dol_print_date($date_modif, 'dayhour').'</td>';
  812. if (!$i) {
  813. $totalarray['nbfield']++;
  814. }
  815. }
  816. if (!empty($arrayfields['cp.statut']['checked'])) {
  817. print '<td class="right nowrap">'.$holidaystatic->getLibStatut(5).'</td>';
  818. if (!$i) {
  819. $totalarray['nbfield']++;
  820. }
  821. }
  822. // Action column
  823. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  824. print '<td class="nowrap center">';
  825. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  826. $selected = 0;
  827. if (in_array($obj->rowid, $arrayofselected)) {
  828. $selected = 1;
  829. }
  830. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  831. }
  832. print '</td>';
  833. if (!$i) {
  834. $totalarray['nbfield']++;
  835. }
  836. }
  837. print '</tr>'."\n";
  838. $i++;
  839. }
  840. // Add a line for total if there is a total to show
  841. if (!empty($arrayfields['duration']['checked'])) {
  842. print '<tr class="total">';
  843. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  844. print '<td></td>';
  845. }
  846. foreach ($arrayfields as $key => $val) {
  847. if (!empty($val['checked'])) {
  848. if ($key == 'duration') {
  849. print '<td class="right">'.$totalduration.' '.$langs->trans('DurationDays').'</td>';
  850. } else {
  851. print '<td></td>';
  852. }
  853. }
  854. }
  855. // status
  856. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  857. print '<td></td>';
  858. }
  859. print '</tr>';
  860. }
  861. }
  862. // Si il n'y a pas d'enregistrement suite à une recherche
  863. if ($num == 0) {
  864. $colspan = 1;
  865. foreach ($arrayfields as $key => $val) {
  866. if (!empty($val['checked'])) {
  867. $colspan++;
  868. }
  869. }
  870. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  871. }
  872. print '</table>';
  873. print '</div>';
  874. print '</form>';
  875. } else {
  876. dol_print_error($db);
  877. }
  878. // End of page
  879. llxFooter();
  880. $db->close();
  881. /**
  882. * Show balance of user
  883. *
  884. * @param Holiday $holiday Object $holiday
  885. * @param int $user_id User id
  886. * @return string Html code with balance
  887. */
  888. function showMyBalance($holiday, $user_id)
  889. {
  890. global $conf, $langs;
  891. $alltypeleaves = $holiday->getTypes(1, -1); // To have labels
  892. $out = '';
  893. $nb_holiday = 0;
  894. $typeleaves = $holiday->getTypes(1, 1);
  895. foreach ($typeleaves as $key => $val) {
  896. $nb_type = $holiday->getCPforUser($user_id, $val['rowid']);
  897. $nb_holiday += $nb_type;
  898. $out .= ' - '.$val['label'].': <strong>'.($nb_type ?price2num($nb_type) : 0).'</strong><br>';
  899. }
  900. print $langs->trans('SoldeCPUser', round($nb_holiday, 5)).'<br>';
  901. print $out;
  902. }