list.php 35 KB

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