list.php 42 KB

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