list.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <?php
  2. /* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
  3. * Copyright (C) 2013-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@inodbox.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/holiday/list.php
  21. * \ingroup holiday
  22. * \brief List of holiday
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('users', 'holidays', 'hrm'));
  35. // Protection if external user
  36. if ($user->societe_id > 0) accessforbidden();
  37. $action = GETPOST('action','alpha'); // The action 'add', 'create', 'edit', 'update', 'view', ...
  38. $massaction = GETPOST('massaction','alpha'); // The bulk action (combo box choice into lists)
  39. $show_files = GETPOST('show_files','int'); // Show files area generated by bulk actions ?
  40. $confirm = GETPOST('confirm','alpha'); // Result of a confirmation
  41. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  42. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  43. $contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'myobjectlist'; // To manage different context of search
  44. $backtopage = GETPOST('backtopage','alpha'); // Go back to a dedicated page
  45. $optioncss = GETPOST('optioncss','aZ'); // Option for the css output (always '' except when 'print')
  46. $childids = $user->getAllChildIds(1);
  47. // Security check
  48. $socid=0;
  49. if ($user->societe_id > 0) // Protection if external user
  50. {
  51. //$socid = $user->societe_id;
  52. accessforbidden();
  53. }
  54. $result = restrictedArea($user, 'holiday', $id, '');
  55. $id = GETPOST('id','int');
  56. // Load variable for pagination
  57. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  58. $sortfield = GETPOST('sortfield','alpha');
  59. $sortorder = GETPOST('sortorder','alpha');
  60. $page = GETPOST('page','int');
  61. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  62. $offset = $limit * $page;
  63. $pageprev = $page - 1;
  64. $pagenext = $page + 1;
  65. // Initialize technical objects
  66. $object=new Holiday($db);
  67. $extrafields = new ExtraFields($db);
  68. $diroutputmassaction=$conf->holiday->dir_output . '/temp/massgeneration/'.$user->id;
  69. $hookmanager->initHooks(array('holidaylist')); // Note that conf->hooks_modules contains array
  70. // Fetch optionals attributes and labels
  71. $extralabels = $extrafields->fetch_name_optionals_label('holiday');
  72. $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
  73. // Default sort order (if not yet defined by previous GETPOST)
  74. if (! $sortfield) $sortfield="cp.rowid";
  75. if (! $sortorder) $sortorder="DESC";
  76. $sall = trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
  77. $search_ref = GETPOST('search_ref','alphanohtml');
  78. $search_day_create = GETPOST('search_day_create','int');
  79. $search_month_create = GETPOST('search_month_create','int');
  80. $search_year_create = GETPOST('search_year_create','int');
  81. $search_day_start = GETPOST('search_day_start','int');
  82. $search_month_start = GETPOST('search_month_start','int');
  83. $search_year_start = GETPOST('search_year_start','int');
  84. $search_day_end = GETPOST('search_day_end','int');
  85. $search_month_end = GETPOST('search_month_end','int');
  86. $search_year_end = GETPOST('search_year_end','int');
  87. $search_employee = GETPOST('search_employee','int');
  88. $search_valideur = GETPOST('search_valideur','int');
  89. $search_statut = GETPOST('search_statut','int');
  90. $search_type = GETPOST('search_type','int');
  91. // List of fields to search into when doing a "search in all"
  92. $fieldstosearchall = array(
  93. 'cp.description'=>'Description',
  94. 'uu.lastname'=>'EmployeeLastname',
  95. 'uu.firstname'=>'EmployeeFirstname'
  96. );
  97. /*
  98. * Actions
  99. */
  100. if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
  101. if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  102. $parameters=array();
  103. $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  104. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  105. if (empty($reshook))
  106. {
  107. // Selection of new fields
  108. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  109. // Purge search criteria
  110. 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
  111. {
  112. $search_ref="";
  113. $search_month_create="";
  114. $search_year_create="";
  115. $search_month_start="";
  116. $search_year_start="";
  117. $search_month_end="";
  118. $search_year_end="";
  119. $search_employee="";
  120. $search_valideur="";
  121. $search_statut="";
  122. $search_type='';
  123. $toselect='';
  124. $search_array_options=array();
  125. }
  126. if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')
  127. || GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha'))
  128. {
  129. $massaction=''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  130. }
  131. // Mass actions
  132. $objectclass='Holiday';
  133. $objectlabel='Holiday';
  134. $permtoread = $user->rights->holiday->read;
  135. $permtodelete = $user->rights->holiday->delete;
  136. $uploaddir = $conf->holiday->dir_output;
  137. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  138. }
  139. /*
  140. * View
  141. */
  142. $form = new Form($db);
  143. $formother = new FormOther($db);
  144. $holiday = new Holiday($db);
  145. $holidaystatic=new Holiday($db);
  146. $fuser = new User($db);
  147. // Update sold
  148. $result = $holiday->updateBalance();
  149. $max_year = 5;
  150. $min_year = 10;
  151. $filter='';
  152. llxHeader('', $langs->trans('CPTitreMenu'));
  153. $order = $db->order($sortfield,$sortorder).$db->plimit($limit + 1, $offset);
  154. // Ref
  155. if(!empty($search_ref))
  156. {
  157. $filter.= " AND cp.rowid = ".(int) $db->escape($search_ref);
  158. }
  159. // Start date
  160. if($search_year_start > 0) {
  161. if($search_month_start > 0) {
  162. $filter .= " AND (cp.date_debut BETWEEN '".$db->idate(dol_get_first_day($search_year_start,$search_month_start,1))."' AND '".$db->idate(dol_get_last_day($search_year_start,$search_month_start,1))."')";
  163. //$filter.= " AND date_format(cp.date_debut, '%Y-%m') = '$search_year_start-$search_month_start'";
  164. } else {
  165. $filter .= " AND (cp.date_debut BETWEEN '".$db->idate(dol_get_first_day($search_year_start,1,1))."' AND '".$db->idate(dol_get_last_day($search_year_start,12,1))."')";
  166. //$filter.= " AND date_format(cp.date_debut, '%Y') = '$search_year_start'";
  167. }
  168. } else {
  169. if($search_month_start > 0) {
  170. $filter.= " AND date_format(cp.date_debut, '%m') = '".$db->escape($search_month_start)."'";
  171. }
  172. }
  173. // End date
  174. if($search_year_end > 0) {
  175. if($search_month_end > 0) {
  176. $filter .= " AND (cp.date_fin BETWEEN '".$db->idate(dol_get_first_day($search_year_end,$search_month_end,1))."' AND '".$db->idate(dol_get_last_day($search_year_end,$search_month_end,1))."')";
  177. //$filter.= " AND date_format(cp.date_fin, '%Y-%m') = '$search_year_end-$search_month_end'";
  178. } else {
  179. $filter .= " AND (cp.date_fin BETWEEN '".$db->idate(dol_get_first_day($search_year_end,1,1))."' AND '".$db->idate(dol_get_last_day($search_year_end,12,1))."')";
  180. //$filter.= " AND date_format(cp.date_fin, '%Y') = '$search_year_end'";
  181. }
  182. } else {
  183. if($search_month_end > 0) {
  184. $filter.= " AND date_format(cp.date_fin, '%m') = '".$db->escape($search_month_end)."'";
  185. }
  186. }
  187. // Create date
  188. if($search_year_create > 0) {
  189. if($search_month_create > 0) {
  190. $filter .= " AND (cp.date_create BETWEEN '".$db->idate(dol_get_first_day($search_year_create,$search_month_create,1))."' AND '".$db->idate(dol_get_last_day($search_year_create,$search_month_create,1))."')";
  191. //$filter.= " AND date_format(cp.date_create, '%Y-%m') = '$search_year_create-$search_month_create'";
  192. } else {
  193. $filter .= " AND (cp.date_create BETWEEN '".$db->idate(dol_get_first_day($search_year_create,1,1))."' AND '".$db->idate(dol_get_last_day($search_year_create,12,1))."')";
  194. //$filter.= " AND date_format(cp.date_create, '%Y') = '$search_year_create'";
  195. }
  196. } else {
  197. if($search_month_create > 0) {
  198. $filter.= " AND date_format(cp.date_create, '%m') = '".$db->escape($search_month_create)."'";
  199. }
  200. }
  201. // Employee
  202. if(!empty($search_employee) && $search_employee != -1) {
  203. $filter.= " AND cp.fk_user = '".$db->escape($search_employee)."'\n";
  204. }
  205. // Validator
  206. if(!empty($search_valideur) && $search_valideur != -1) {
  207. $filter.= " AND cp.fk_validator = '".$db->escape($search_valideur)."'\n";
  208. }
  209. // Type
  210. if (!empty($search_type) && $search_type != -1) {
  211. $filter.= ' AND cp.fk_type IN ('.$db->escape($search_type).')';
  212. }
  213. // Status
  214. if(!empty($search_statut) && $search_statut != -1) {
  215. $filter.= " AND cp.statut = '".$db->escape($search_statut)."'\n";
  216. }
  217. // Search all
  218. if (!empty($sall))
  219. {
  220. $filter.= natural_search(array_keys($fieldstosearchall), $sall);
  221. }
  222. if (empty($user->rights->holiday->read_all)) $filter.=' AND cp.fk_user IN ('.join(',',$childids).')';
  223. // Récupération de l'ID de l'utilisateur
  224. $user_id = $user->id;
  225. if ($id > 0)
  226. {
  227. // Charge utilisateur edite
  228. $fuser->fetch($id, '', '', 1);
  229. $fuser->getrights();
  230. $user_id = $fuser->id;
  231. $search_employee = $user_id;
  232. }
  233. // Récupération des congés payés de l'utilisateur ou de tous les users de sa hierarchy
  234. // Load array $holiday->holiday
  235. if (empty($user->rights->holiday->read_all) || $id > 0)
  236. {
  237. if ($id > 0) $result = $holiday->fetchByUser($id, $order, $filter);
  238. else $result = $holiday->fetchByUser(join(',',$childids), $order, $filter);
  239. }
  240. else
  241. {
  242. $result = $holiday->fetchAll($order, $filter);
  243. }
  244. // Si erreur SQL
  245. if ($result == '-1')
  246. {
  247. print load_fiche_titre($langs->trans('CPTitreMenu'), '', 'title_hrm.png');
  248. dol_print_error($db, $langs->trans('Error').' '.$holiday->error);
  249. exit();
  250. }
  251. // Show table of vacations
  252. $num = count($holiday->holiday);
  253. $arrayofselected=is_array($toselect)?$toselect:array();
  254. $param='';
  255. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  256. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
  257. if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
  258. if ($search_ref) $param.='&search_ref='.urlencode($search_ref);
  259. if ($search_day_create) $param.='&search_day_create='.urlencode($search_day_create);
  260. if ($search_month_create) $param.='&search_month_create='.urlencode($search_month_create);
  261. if ($search_year_create) $param.='&search_year_create='.urlencode($search_year_create);
  262. if ($search_search_day_start) $param.='&search_day_start='.urlencode($search_day_start);
  263. if ($search_month_start) $param.='&search_month_start='.urlencode($search_month_start);
  264. if ($search_year_start) $param.='&search_year_start='.urlencode($search_year_start);
  265. if ($search_day_end) $param.='&search_day_end='.urlencode($search_day_end);
  266. if ($search_month_end) $param.='&search_month_end='.urlencode($search_month_end);
  267. if ($search_year_end) $param.='&search_year_end='.urlencode($search_year_end);
  268. if ($search_employee > 0) $param.='&search_employee='.urlencode($search_employee);
  269. if ($search_valideur > 0) $param.='&search_valideur='.urlencode($search_valideur);
  270. if ($search_type > 0) $param.='&search_type='.urlencode($search_type);
  271. if ($search_statut > 0) $param.='&search_statut='.urlencode($search_statut);
  272. // List of mass actions available
  273. $arrayofmassactions = array(
  274. //'presend'=>$langs->trans("SendByMail"),
  275. //'builddoc'=>$langs->trans("PDFMerge"),
  276. );
  277. if ($user->rights->holiday->delete) $arrayofmassactions['predelete']=$langs->trans("Delete");
  278. if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
  279. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  280. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  281. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  282. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  283. print '<input type="hidden" name="action" value="list">';
  284. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  285. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  286. print '<input type="hidden" name="page" value="'.$page.'">';
  287. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  288. if ($id > 0) print '<input type="hidden" name="id" value="'.$id.'">';
  289. if ($id > 0) // For user tab
  290. {
  291. $title = $langs->trans("User");
  292. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  293. $head = user_prepare_head($fuser);
  294. dol_fiche_head($head, 'paidholidays', $title, -1, 'user');
  295. dol_banner_tab($fuser,'id',$linkback,$user->rights->user->user->lire || $user->admin);
  296. if (empty($conf->global->HOLIDAY_HIDE_BALANCE))
  297. {
  298. print '<div class="underbanner clearboth"></div>';
  299. print '<br>';
  300. showMyBalance($holiday, $user_id);
  301. }
  302. dol_fiche_end();
  303. print '<div class="tabsAction">';
  304. $canedit=(($user->id == $user_id && $user->rights->holiday->write) || ($user->id != $user_id && $user->rights->holiday->write_all));
  305. // Boutons d'actions
  306. if ($canedit)
  307. {
  308. print '<a href="'.DOL_URL_ROOT.'/holiday/card.php?action=request&fuserid='.$user_id.'" class="butAction">'.$langs->trans("AddCP").'</a>';
  309. }
  310. print '</div>';
  311. }
  312. else
  313. {
  314. $nbtotalofrecords = count($holiday->holiday);
  315. //print $num;
  316. //print count($holiday->holiday);
  317. $newcardbutton='';
  318. if ($user->rights->holiday->write)
  319. {
  320. $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/holiday/card.php?action=request"><span class="valignmiddle">'.$langs->trans('MenuAddCP').'</span>';
  321. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  322. $newcardbutton.= '</a>';
  323. }
  324. print_barre_liste($langs->trans("ListeCP"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_hrm.png', 0, $newcardbutton, '', $limit);
  325. $topicmail="Information";
  326. $modelmail="leaverequest";
  327. $objecttmp=new Holiday($db);
  328. $trackid='leav'.$object->id;
  329. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  330. }
  331. if ($sall)
  332. {
  333. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  334. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
  335. }
  336. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  337. $selectedfields=''; // $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  338. $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  339. print '<div class="div-table-responsive">';
  340. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  341. // Filters
  342. print '<tr class="liste_titre_filter">';
  343. print '<td class="liste_titre">';
  344. print '<input class="flat" size="4" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  345. print '</td>';
  346. // Create date
  347. print '<td class="liste_titre" align="center">';
  348. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month_create" value="'.dol_escape_htmltag($search_month_create).'">';
  349. $formother->select_year($search_year_create, 'search_year_create', 1, $min_year, 0);
  350. print '</td>';
  351. $morefilter = 'AND employee = 1';
  352. if (! empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = '';
  353. // User
  354. $disabled=0;
  355. // If into the tab holiday of a user ($id is set in such a case)
  356. if ($id && ! GETPOSTISSET('search_employee'))
  357. {
  358. $search_employee=$id;
  359. $disabled=1;
  360. }
  361. if (! empty($user->rights->holiday->read_all)) // Can see all
  362. {
  363. if (GETPOSTISSET('search_employee')) $search_employee=GETPOST('search_employee','int');
  364. print '<td class="liste_titre maxwidthonsmartphone" align="left">';
  365. print $form->select_dolusers($search_employee, "search_employee", 1, "", $disabled, '', '', 0, 0, 0, $morefilter, 0, '', 'maxwidth200');
  366. print '</td>';
  367. }
  368. else
  369. {
  370. if (GETPOSTISSET('search_employee')) $search_employee=GETPOST('search_employee','int');
  371. print '<td class="liste_titre maxwidthonsmartphone" align="left">';
  372. print $form->select_dolusers($search_employee, "search_employee", 1, "", $disabled, 'hierarchyme', '', 0, 0, 0, $morefilter, 0, '', 'maxwidth200');
  373. print '</td>';
  374. }
  375. // Approve
  376. if ($user->rights->holiday->read_all)
  377. {
  378. print '<td class="liste_titre maxwidthonsmartphone" align="left">';
  379. $validator = new UserGroup($db);
  380. $excludefilter=$user->admin?'':'u.rowid <> '.$user->id;
  381. $valideurobjects = $validator->listUsersForGroup($excludefilter);
  382. $valideurarray = array();
  383. foreach($valideurobjects as $val) $valideurarray[$val->id]=$val->id;
  384. print $form->select_dolusers($search_valideur, "search_valideur", 1, "", 0, $valideurarray, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth200');
  385. print '</td>';
  386. }
  387. else
  388. {
  389. print '<td class="liste_titre">&nbsp;</td>';
  390. }
  391. // Type
  392. print '<td class="liste_titre">';
  393. if (empty($mysoc->country_id)) {
  394. setEventMessages(null, array($langs->trans("ErrorSetACountryFirst"),$langs->trans("CompanyFoundation")),'errors');
  395. } else {
  396. $typeleaves=$holidaystatic->getTypes(1,-1);
  397. $arraytypeleaves=array();
  398. foreach($typeleaves as $key => $val)
  399. {
  400. $labeltoshow = ($langs->trans($val['code'])!=$val['code'] ? $langs->trans($val['code']) : $val['label']);
  401. //$labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':'');
  402. $arraytypeleaves[$val['rowid']]=$labeltoshow;
  403. }
  404. print $form->selectarray('search_type', $arraytypeleaves, $search_type, 1);
  405. }
  406. print '</td>';
  407. // Duration
  408. print '<td class="liste_titre">&nbsp;</td>';
  409. // Start date
  410. print '<td class="liste_titre" align="center">';
  411. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month_start" value="'.dol_escape_htmltag($search_month_start).'">';
  412. $formother->select_year($search_year_start,'search_year_start',1, $min_year, $max_year);
  413. print '</td>';
  414. // End date
  415. print '<td class="liste_titre" align="center">';
  416. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month_end" value="'.dol_escape_htmltag($search_month_end).'">';
  417. $formother->select_year($search_year_end,'search_year_end',1, $min_year, $max_year);
  418. print '</td>';
  419. // Status
  420. print '<td class="liste_titre maxwidthonsmartphone maxwidth200" align="right">';
  421. $holiday->selectStatutCP($search_statut, 'search_statut');
  422. print '</td>';
  423. // Actions
  424. print '<td class="liste_titre" align="right">';
  425. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  426. print $searchpicto;
  427. print '</td>';
  428. print "</tr>\n";
  429. print '<tr class="liste_titre">';
  430. print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"cp.ref","",$param,'',$sortfield,$sortorder);
  431. print_liste_field_titre("DateCreateCP",$_SERVER["PHP_SELF"],"cp.date_create","",$param,'align="center"',$sortfield,$sortorder);
  432. print_liste_field_titre("Employee",$_SERVER["PHP_SELF"],"cp.fk_user","",$param,'',$sortfield,$sortorder);
  433. print_liste_field_titre("ValidatorCP",$_SERVER["PHP_SELF"],"cp.fk_validator","",$param,'',$sortfield,$sortorder);
  434. print_liste_field_titre("Type",$_SERVER["PHP_SELF"],'','',$param,'',$sortfield,$sortorder);
  435. print_liste_field_titre("NbUseDaysCPShort",$_SERVER["PHP_SELF"],'','',$pram,'align="right"',$sortfield,$sortorder);
  436. print_liste_field_titre("DateDebCP",$_SERVER["PHP_SELF"],"cp.date_debut","",$param,'align="center"',$sortfield,$sortorder);
  437. print_liste_field_titre("DateFinCP",$_SERVER["PHP_SELF"],"cp.date_fin","",$param,'align="center"',$sortfield,$sortorder);
  438. print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"cp.statut","",$param,'align="right"',$sortfield,$sortorder);
  439. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n";
  440. print "</tr>\n";
  441. $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon"));
  442. // If we ask a dedicated card and not allow to see it, we forc on user.
  443. if ($id && empty($user->rights->holiday->read_all) && ! in_array($id, $childids))
  444. {
  445. $langs->load("errors");
  446. print '<tr class="oddeven opacitymediuem"><td colspan="10">'.$langs->trans("NotEnoughPermissions").'</td></tr>';
  447. $result = 0;
  448. }
  449. // Lines
  450. elseif (! empty($holiday->holiday) && !empty($mysoc->country_id))
  451. {
  452. $userstatic = new User($db);
  453. $approbatorstatic = new User($db);
  454. $typeleaves=$holiday->getTypes(1,-1);
  455. foreach($holiday->holiday as $infos_CP)
  456. {
  457. // Leave request
  458. $holidaystatic->id=$infos_CP['rowid'];
  459. $holidaystatic->ref=($infos_CP['ref']?$infos_CP['ref']:$infos_CP['rowid']);
  460. // User
  461. $userstatic->id=$infos_CP['fk_user'];
  462. $userstatic->lastname=$infos_CP['user_lastname'];
  463. $userstatic->firstname=$infos_CP['user_firstname'];
  464. $userstatic->login=$infos_CP['user_login'];
  465. $userstatic->statut=$infos_CP['user_statut'];
  466. $userstatic->photo=$infos_CP['user_photo'];
  467. // Validator
  468. $approbatorstatic->id=$infos_CP['fk_validator'];
  469. $approbatorstatic->lastname=$infos_CP['validator_lastname'];
  470. $approbatorstatic->firstname=$infos_CP['validator_firstname'];
  471. $approbatorstatic->login=$infos_CP['validator_login'];
  472. $approbatorstatic->statut=$infos_CP['validator_statut'];
  473. $approbatorstatic->photo=$infos_CP['validator_photo'];
  474. $date = $infos_CP['date_create'];
  475. $starthalfday=($infos_CP['halfday'] == -1 || $infos_CP['halfday'] == 2)?'afternoon':'morning';
  476. $endhalfday=($infos_CP['halfday'] == 1 || $infos_CP['halfday'] == 2)?'morning':'afternoon';
  477. print '<tr class="oddeven">';
  478. print '<td>';
  479. print $holidaystatic->getNomUrl(1, 1);
  480. print '</td>';
  481. print '<td style="text-align: center;">'.dol_print_date($date,'day').'</td>';
  482. print '<td>'.$userstatic->getNomUrl(-1, 'leave').'</td>';
  483. print '<td>'.$approbatorstatic->getNomUrl(-1).'</td>';
  484. print '<td>';
  485. $labeltypeleavetoshow = ($langs->trans($typeleaves[$infos_CP['fk_type']]['code'])!=$typeleaves[$infos_CP['fk_type']]['code'] ? $langs->trans($typeleaves[$infos_CP['fk_type']]['code']) : $typeleaves[$infos_CP['fk_type']]['label']);
  486. print empty($typeleaves[$infos_CP['fk_type']]['label']) ? $langs->trans("TypeWasDisabledOrRemoved",$infos_CP['fk_type']) : $labeltypeleavetoshow;
  487. print '</td>';
  488. print '<td align="right">';
  489. $nbopenedday=num_open_day($infos_CP['date_debut_gmt'], $infos_CP['date_fin_gmt'], 0, 1, $infos_CP['halfday']);
  490. print $nbopenedday.' '.$langs->trans('DurationDays');
  491. print '</td>';
  492. print '<td align="center">';
  493. print dol_print_date($infos_CP['date_debut'],'day');
  494. print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfday]).')</span>';
  495. print '</td>';
  496. print '<td align="center">';
  497. print dol_print_date($infos_CP['date_fin'],'day');
  498. print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfday]).')</span>';
  499. print '</td>';
  500. print '<td align="right">'.$holidaystatic->LibStatut($infos_CP['statut'],5).'</td>';
  501. // Action column
  502. print '<td class="nowrap" align="center">';
  503. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  504. {
  505. $selected=0;
  506. if (in_array($infos_CP['rowid'], $arrayofselected)) $selected=1;
  507. print '<input id="cb'.$infos_CP['rowid'].'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$infos_CP['rowid'].'"'.($selected?' checked="checked"':'').'>';
  508. }
  509. print '</td>';
  510. print '</tr>'."\n";
  511. }
  512. }
  513. // Si il n'y a pas d'enregistrement suite à une recherche
  514. if ($result == '2')
  515. {
  516. print '<tr>';
  517. print '<td colspan="10" class="opacitymedium">'.$langs->trans('NoRecordFound').'</td>';
  518. print '</tr>';
  519. }
  520. print '</table>';
  521. print '</div>';
  522. print '</form>';
  523. /*if ($user_id == $user->id)
  524. {
  525. print '<br>';
  526. print '<div style="float: right; margin-top: 8px;">';
  527. print '<a href="./card.php?action=request" class="butAction">'.$langs->trans('AddCP').'</a>';
  528. print '</div>';
  529. }*/
  530. // End of page
  531. llxFooter();
  532. $db->close();
  533. /**
  534. * Show balance of user
  535. *
  536. * @param Holiday $holiday Object $holiday
  537. * @param int $user_id User id
  538. * @return string Html code with balance
  539. */
  540. function showMyBalance($holiday, $user_id)
  541. {
  542. global $conf, $langs;
  543. $alltypeleaves=$holiday->getTypes(1,-1); // To have labels
  544. $out='';
  545. $nb_holiday=0;
  546. $typeleaves=$holiday->getTypes(1,1);
  547. foreach($typeleaves as $key => $val)
  548. {
  549. $nb_type = $holiday->getCPforUser($user_id, $val['rowid']);
  550. $nb_holiday += $nb_type;
  551. $out .= ' - '.$val['label'].': <strong>'.($nb_type?price2num($nb_type):0).'</strong><br>';
  552. }
  553. print $langs->trans('SoldeCPUser', round($nb_holiday,5)).'<br>';
  554. print $out;
  555. }