PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/holiday/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 323 lines | 206 code | 57 blank | 60 comment | 42 complexity | c7836d4db4ecd5123610922bc9c60d7c MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
  4. * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.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 index.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.'/user/class/user.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php';
  30. // Protection if external user
  31. if ($user->societe_id > 0) accessforbidden();
  32. $sortfield = GETPOST("sortfield",'alpha');
  33. $sortorder = GETPOST("sortorder",'alpha');
  34. $page = GETPOST("page",'int');
  35. $page = is_numeric($page) ? $page : 0;
  36. $page = $page == -1 ? 0 : $page;
  37. if (! $sortfield) $sortfield="cp.rowid";
  38. if (! $sortorder) $sortorder="DESC";
  39. $offset = $conf->liste_limit * $page ;
  40. $pageprev = $page - 1;
  41. $pagenext = $page + 1;
  42. $search_ref = GETPOST('search_ref');
  43. $month_create = GETPOST('month_create');
  44. $year_create = GETPOST('year_create');
  45. $month_start = GETPOST('month_start');
  46. $year_start = GETPOST('year_start');
  47. $month_end = GETPOST('month_end');
  48. $year_end = GETPOST('year_end');
  49. $search_employe = GETPOST('search_employe');
  50. $search_valideur = GETPOST('search_valideur');
  51. $search_statut = GETPOST('select_statut');
  52. /*
  53. * Actions
  54. */
  55. // None
  56. /*
  57. * View
  58. */
  59. $max_year = 5;
  60. $min_year = 10;
  61. llxHeader(array(),$langs->trans('CPTitreMenu'));
  62. $order = $db->order($sortfield,$sortorder).$db->plimit($conf->liste_limit + 1, $offset);
  63. // WHERE
  64. if(!empty($search_ref)){
  65. $filter.= " AND cp.rowid LIKE '%$search_ref%'\n";
  66. }
  67. // DATE START
  68. if($year_start > 0) {
  69. if($month_start > 0) {
  70. $filter.= " AND date_format(cp.date_debut, '%Y-%m') = '$year_start-$month_start'";
  71. } else {
  72. $filter.= " AND date_format(cp.date_debut, '%Y') = '$year_start'";
  73. }
  74. } else {
  75. if($month_start > 0) {
  76. $filter.= " AND date_format(cp.date_debut, '%m') = '$month_start'";
  77. }
  78. }
  79. // DATE FIN
  80. if($year_end > 0) {
  81. if($month_end > 0) {
  82. $filter.= " AND date_format(cp.date_fin, '%Y-%m') = '$year_end-$month_end'";
  83. } else {
  84. $filter.= " AND date_format(cp.date_fin, '%Y') = '$year_end'";
  85. }
  86. } else {
  87. if($month_end > 0) {
  88. $filter.= " AND date_format(cp.date_fin, '%m') = '$month_end'";
  89. }
  90. }
  91. // DATE CREATE
  92. if($year_create > 0) {
  93. if($month_create > 0) {
  94. $filter.= " AND date_format(cp.date_create, '%Y-%m') = '$year_create-$month_create'";
  95. } else {
  96. $filter.= " AND date_format(cp.date_create, '%Y') = '$year_create'";
  97. }
  98. } else {
  99. if($month_create > 0) {
  100. $filter.= " AND date_format(cp.date_create, '%m') = '$month_create'";
  101. }
  102. }
  103. // EMPLOYE
  104. if(!empty($search_employe) && $search_employe != -1) {
  105. $filter.= " AND cp.fk_user = '$search_employe'\n";
  106. }
  107. // VALIDEUR
  108. if(!empty($search_valideur) && $search_valideur != -1) {
  109. $filter.= " AND cp.fk_validator = '$search_valideur'\n";
  110. }
  111. // STATUT
  112. if(!empty($search_statut) && $search_statut != -1) {
  113. $filter.= " AND cp.statut = '$search_statut'\n";
  114. }
  115. /*************************************
  116. * Fin des filtres de recherche
  117. *************************************/
  118. // Récupération de l'ID de l'utilisateur
  119. $user_id = $user->id;
  120. // Récupération des congés payés de l'utilisateur ou de tous les users
  121. if(!$user->rights->holiday->lire_tous)
  122. {
  123. $holiday = new Holiday($db);
  124. $holiday_payes = $holiday->fetchByUser($user_id,$order,$filter);
  125. }
  126. else
  127. {
  128. $holiday = new Holiday($db);
  129. $holiday_payes = $holiday->fetchAll($order,$filter);
  130. }
  131. // Si pas de congés payés
  132. if($holiday_payes == 0)
  133. {
  134. print_fiche_titre($langs->trans('CPTitreMenu'));
  135. print '<div class="tabBar">';
  136. print '<span>'.$langs->trans('NoCPforUser').'<br /><br />';
  137. print '<a href="./fiche.php?mainmenu=agenda&action=request" class="butAction">'.$langs->trans('AddCP').'</a></span>';
  138. print '</div>';
  139. exit();
  140. }
  141. // Si erreur SQL
  142. if($holiday_payes == '-1')
  143. {
  144. print_fiche_titre($langs->trans('CPTitreMenu'));
  145. print '<div class="tabBar">';
  146. print '<span>'.$langs->trans('CPErrorSQL');
  147. print ' '.$holiday->error.'</span>';
  148. print '</div>';
  149. exit();
  150. }
  151. /*************************************
  152. * Affichage du tableau des congés payés
  153. *************************************/
  154. $var=true; $num = count($holiday->holiday);
  155. $html = new Form($db);
  156. $htmlother = new FormOther($db);
  157. print_barre_liste($langs->trans("ListeCP"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num,$nbtotalofrecords);
  158. print '<div class="tabBar">';
  159. $nbaquis=$holiday->getCPforUser($user->id);
  160. $nbdeduced=$holiday->getConfCP('nbHolidayDeducted');
  161. $nb_holiday = $nbaquis / $nbdeduced;
  162. print $langs->trans('SoldeCPUser',round($nb_holiday,2)).($nbdeduced != 1 ? ' ('.$nbaquis.' / '.$nbdeduced.')' : '');
  163. print '</div>';
  164. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  165. print '<table class="noborder" width="100%;">';
  166. print "<tr class=\"liste_titre\">";
  167. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"cp.rowid","",'','',$sortfield,$sortorder);
  168. print_liste_field_titre($langs->trans("DateCreateCP"),$_SERVER["PHP_SELF"],"cp.date_create","",'','align="center"',$sortfield,$sortorder);
  169. print_liste_field_titre($langs->trans("Employe"),$_SERVER["PHP_SELF"],"cp.fk_user","",'','',$sortfield,$sortorder);
  170. print_liste_field_titre($langs->trans("ValidatorCP"),$_SERVER["PHP_SELF"],"cp.fk_validator","",'','',$sortfield,$sortorder);
  171. print_liste_field_titre($langs->trans("DateDebCP"),$_SERVER["PHP_SELF"],"cp.date_debut","",'','align="center"',$sortfield,$sortorder);
  172. print_liste_field_titre($langs->trans("DateFinCP"),$_SERVER["PHP_SELF"],"cp.date_fin","",'','align="center"',$sortfield,$sortorder);
  173. print_liste_field_titre($langs->trans("Duration"));
  174. print_liste_field_titre($langs->trans("Statut"),$_SERVER["PHP_SELF"],"cp.statut","",'','align="center"',$sortfield,$sortorder);
  175. print "</tr>\n";
  176. // FILTRES
  177. print '<tr class="liste_titre">';
  178. print '<td class="liste_titre" align="left" width="50">';
  179. print '<input class="flat" size="4" type="text" name="search_ref" value="'.$search_ref.'">';
  180. // DATE CREATE
  181. print '<td class="liste_titre" colspan="1" align="center">';
  182. print '<input class="flat" type="text" size="1" maxlength="2" name="month_create" value="'.$month_create.'">';
  183. $htmlother->select_year($year_create,'year_create',1, $min_year, $max_year);
  184. print '</td>';
  185. // UTILISATEUR
  186. if($user->rights->holiday->lire_tous) {
  187. print '<td class="liste_titre" align="left">';
  188. $html->select_users($search_employe,"search_employe",1,"",0,'');
  189. print '</td>';
  190. } else {
  191. print '<td class="liste_titre">&nbsp;</td>';
  192. }
  193. // VALIDEUR
  194. if($user->rights->holiday->lire_tous){
  195. print '<td class="liste_titre" align="left">';
  196. // Liste des utiliseurs du groupes Comptabilité
  197. $idGroupValid = $holiday->getConfCP('userGroup');
  198. $validator = new UserGroup($db,$idGroupValid);
  199. $valideur = $validator->listUsersForGroup();
  200. $html->select_users($search_valideur,"search_valideur",1,"",0,$valideur,'');
  201. print '</td>';
  202. } else {
  203. print '<td class="liste_titre">&nbsp;</td>';
  204. }
  205. // DATE DEBUT
  206. print '<td class="liste_titre" colspan="1" align="center">';
  207. print '<input class="flat" type="text" size="1" maxlength="2" name="month_start" value="'.$month_start.'">';
  208. $htmlother->select_year($year_start,'year_start',1, $min_year, $max_year);
  209. print '</td>';
  210. // DATE FIN
  211. print '<td class="liste_titre" colspan="1" align="center">';
  212. print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
  213. $htmlother->select_year($year_end,'year_end',1, $min_year, $max_year);
  214. print '</td>';
  215. // DUREE
  216. print '<td>&nbsp;</td>';
  217. // STATUT
  218. print '<td class="liste_titre" width="70px;" align="center">';
  219. $holiday->selectStatutCP($search_statut);
  220. print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans('Search').'">';
  221. print "</td></tr>\n";
  222. if (! empty($holiday->holiday))
  223. {
  224. foreach($holiday->holiday as $infos_CP)
  225. {
  226. $var=!$var;
  227. // Utilisateur
  228. $user = new User($db);
  229. $user->fetch($infos_CP['fk_user']);
  230. // Valideur
  231. $validator = new User($db);
  232. $validator->fetch($infos_CP['fk_validator']);
  233. $date = date_create($infos_CP['date_create']);
  234. $date = date_format($date,'Y-m-d');
  235. $statut = $holiday->getStatutCP($infos_CP['statut']);
  236. print '<tr '.$bc[$var].'>';
  237. print '<td><a href="./fiche.php?id='.$infos_CP['rowid'].'">CP '.$infos_CP['rowid'].'</a></td>';
  238. print '<td style="text-align: center;">'.$date.'</td>';
  239. print '<td>'.$user->getNomUrl('1').'</td>';
  240. print '<td>'.$validator->getNomUrl('1').'</td>';
  241. print '<td style="text-align: center;">'.$infos_CP['date_debut'].'</td>';
  242. print '<td style="text-align: center;">'.$infos_CP['date_fin'].'</td>';
  243. print '<td>';
  244. $nbopenedday=num_open_day($infos_CP['date_debut'],$infos_CP['date_fin'],0,1);
  245. print $nbopenedday.' '.$langs->trans('Jours');
  246. print '<td align="center"><a href="./fiche.php?id='.$infos_CP['rowid'].'">'.$statut.'</a></td>';
  247. print '</tr>'."\n";
  248. }
  249. }
  250. // Si il n'y a pas d'enregistrement suite à une recherche
  251. if($holiday_payes == '2')
  252. {
  253. print '<tr>';
  254. print '<td colspan="8" class="pair" style="text-align: center; padding: 5px;">'.$langs->trans('None').'</td>';
  255. print '</tr>';
  256. }
  257. print '</table>';
  258. print '</form>';
  259. print '<br>';
  260. print '<div style="float: right; margin-top: 8px;">';
  261. print '<a href="./fiche.php?action=request" class="butAction">'.$langs->trans('AddCP').'</a>';
  262. print '</div>';
  263. // Fin de page
  264. $db->close();
  265. llxFooter();
  266. ?>