PageRenderTime 65ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/holiday/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1051 lines | 766 code | 172 blank | 113 comment | 191 complexity | 2c8ad099e8a6b7879000374676041a94 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file fiche.php
  20. * \ingroup holiday
  21. * \brief Form and file creation of paid holiday.
  22. */
  23. require('../main.inc.php');
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php';
  31. // Get parameters
  32. $myparam = GETPOST("myparam");
  33. $action=GETPOST('action');
  34. $id=GETPOST('id');
  35. // Protection if external user
  36. if ($user->societe_id > 0) accessforbidden();
  37. $user_id = $user->id;
  38. /*******************************************************************
  39. * Actions
  40. ********************************************************************/
  41. // Si création de la demande
  42. if ($action == 'create')
  43. {
  44. // Si pas le droit de créer une demande
  45. if(!$user->rights->holiday->write)
  46. {
  47. header('Location: fiche.php?action=request&error=CantCreate');
  48. exit;
  49. }
  50. $date_debut = dol_mktime(0, 0, 0, $_POST['date_debut_month'], $_POST['date_debut_day'], $_POST['date_debut_year']);
  51. $date_fin = dol_mktime(0, 0, 0, $_POST['date_fin_month'], $_POST['date_fin_day'], $_POST['date_fin_year']);
  52. $valideur = GETPOST('valideur');
  53. $description = trim(GETPOST('description'));
  54. $userID = GETPOST('userID');
  55. // Si pas de date de début
  56. if (empty($date_debut))
  57. {
  58. header('Location: fiche.php?action=request&error=nodatedebut');
  59. exit;
  60. }
  61. // Si pas de date de fin
  62. if (empty($date_fin))
  63. {
  64. header('Location: fiche.php?action=request&error=nodatefin');
  65. exit;
  66. }
  67. $testDateDebut = $date_debut;
  68. $testDateFin = $date_fin;
  69. // Si date de début après la date de fin
  70. if($testDateDebut > $testDateFin)
  71. {
  72. header('Location: fiche.php?action=request&error=datefin');
  73. exit;
  74. }
  75. $cp = new Holiday($db);
  76. $verifCP = $cp->verifDateHolidayCP($userID,$date_debut,$date_fin);
  77. // On vérifie si il n'y a pas déjà des congés payés sur cette période
  78. if (! $verifCP)
  79. {
  80. header('Location: fiche.php?action=request&error=alreadyCP');
  81. exit;
  82. }
  83. // Si aucun jours ouvrés dans la demande
  84. $nbopenedday=num_open_day($testDateDebut,$testDateFin,0,1);
  85. if($nbopenedday < 1)
  86. {
  87. header('Location: fiche.php?action=request&error=DureeHoliday');
  88. exit;
  89. }
  90. // Si pas de validateur choisi
  91. if ($valideur < 1)
  92. {
  93. header('Location: fiche.php?action=request&error=Valideur');
  94. exit;
  95. }
  96. $cp->fk_user = $user_id;
  97. $cp->description = $description;
  98. $cp->date_debut = $date_debut;
  99. $cp->date_fin = $date_fin;
  100. $cp->fk_validator = $valideur;
  101. $verif = $cp->create($user_id);
  102. // Si pas d'erreur SQL on redirige vers la fiche de la demande
  103. if ($verif > 0)
  104. {
  105. header('Location: fiche.php?id='.$verif);
  106. exit;
  107. }
  108. else
  109. {
  110. // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
  111. header('Location: fiche.php?action=request&error=SQL_Create&msg='.$cp->error);
  112. exit;
  113. }
  114. }
  115. if ($action == 'update')
  116. {
  117. $date_debut = dol_mktime(0, 0, 0, $_POST['date_debut_month'], $_POST['date_debut_day'], $_POST['date_debut_year']);
  118. $date_fin = dol_mktime(0, 0, 0, $_POST['date_fin_month'], $_POST['date_fin_day'], $_POST['date_fin_year']);
  119. // Si pas le droit de modifier une demande
  120. if(!$user->rights->holiday->write)
  121. {
  122. header('Location: fiche.php?action=request&error=CantUpdate');
  123. exit;
  124. }
  125. $cp = new Holiday($db);
  126. $cp->fetch($_POST['holiday_id']);
  127. // Si en attente de validation
  128. if ($cp->statut == 1)
  129. {
  130. // Si c'est le créateur ou qu'il a le droit de tout lire / modifier
  131. if ($user->id == $cp->fk_user || $user->rights->holiday->lire_tous)
  132. {
  133. $valideur = $_POST['valideur'];
  134. $description = trim($_POST['description']);
  135. // Si pas de date de début
  136. if (empty($_POST['date_debut_'])) {
  137. header('Location: fiche.php?id='.$_POST['holiday_id'].'&action=edit&error=nodatedebut');
  138. exit;
  139. }
  140. // Si pas de date de fin
  141. if (empty($_POST['date_fin_'])) {
  142. header('Location: fiche.php?id='.$_POST['holiday_id'].'&action=edit&error=nodatefin');
  143. exit;
  144. }
  145. $testDateDebut = $date_debut;
  146. $testDateFin = $date_fin;
  147. // Si date de début après la date de fin
  148. if ($testDateDebut > $testDateFin) {
  149. header('Location: fiche.php?id='.$_POST['holiday_id'].'&action=edit&error=datefin');
  150. exit;
  151. }
  152. // Si pas de valideur choisi
  153. if ($valideur < 1) {
  154. header('Location: fiche.php?id='.$_POST['holiday_id'].'&action=edit&error=Valideur');
  155. exit;
  156. }
  157. // Si pas de jours ouvrés dans la demande
  158. $nbopenedday=num_open_day($testDateDebut,$testDateFin,0,1);
  159. if ($nbopenedday < 1)
  160. {
  161. header('Location: fiche.php?id='.$_POST['holiday_id'].'&action=edit&error=DureeHoliday');
  162. exit;
  163. }
  164. $cp->description = $description;
  165. $cp->date_debut = $date_debut;
  166. $cp->date_fin = $date_fin;
  167. $cp->fk_validator = $valideur;
  168. $verif = $cp->update($user->id);
  169. // Si pas d'erreur SQL on redirige vers la fiche de la demande
  170. if ($verif > 0)
  171. {
  172. header('Location: fiche.php?id='.$_POST['holiday_id']);
  173. exit;
  174. }
  175. else
  176. {
  177. // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
  178. header('Location: fiche.php?id='.$_POST['holiday_id'].'&action=edit&error=SQL_Create&msg='.$cp->error);
  179. exit;
  180. }
  181. }
  182. } else {
  183. header('Location: fiche.php?id='.$_POST['holiday_id']);
  184. exit;
  185. }
  186. }
  187. // Si suppression de la demande
  188. if ($action == 'confirm_delete' && $_GET['confirm'] == 'yes')
  189. {
  190. if($user->rights->holiday->delete)
  191. {
  192. $cp = new Holiday($db);
  193. $cp->fetch($_GET['id']);
  194. // Si c'est bien un brouillon
  195. if($cp->statut == 1) {
  196. // Si l'utilisateur à le droit de lire cette demande, il peut la supprimer
  197. if($user->id == $cp->fk_user || $user->rights->holiday->lire_tous) {
  198. $cp->delete($_GET['id']);
  199. header('Location: index.php');
  200. exit;
  201. }
  202. else {
  203. $error = $langs->trans('ErrorCantDeleteCP');
  204. }
  205. }
  206. }
  207. }
  208. // Si envoi de la demande
  209. if ($action == 'confirm_send')
  210. {
  211. $cp = new Holiday($db);
  212. $cp->fetch($_GET['id']);
  213. $userID = $user->id;
  214. // Si brouillon et créateur
  215. if($cp->statut == 1 && $userID == $cp->fk_user)
  216. {
  217. $cp->statut = 2;
  218. $verif = $cp->update($user->id);
  219. // Si pas d'erreur SQL on redirige vers la fiche de la demande
  220. if($verif > 0) {
  221. // A
  222. $destinataire = new User($db);
  223. $destinataire->fetch($cp->fk_validator);
  224. $emailTo = $destinataire->email;
  225. // De
  226. $expediteur = new User($db);
  227. $expediteur->fetch($cp->fk_user);
  228. $emailFrom = $expediteur->email;
  229. // Sujet
  230. if($conf->global->MAIN_APPLICATION_TITLE != NULL) {
  231. $societeName = addslashes($conf->global->MAIN_APPLICATION_TITLE);
  232. } else {
  233. $societeName = addslashes($conf->global->MAIN_INFO_SOCIETE_NOM);
  234. }
  235. $subject = stripslashes($societeName)." - Demande de congés payés à valider";
  236. // Contenu
  237. $message = "Bonjour {$destinataire->prenom},\n\n";
  238. $message.= "Veuillez trouver ci-dessous une demande de congés payés à valider.\n";
  239. $delayForRequest = $cp->getConfCP('delayForRequest');
  240. //$delayForRequest = $delayForRequest * (60*60*24);
  241. $now=dol_now();
  242. $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd');
  243. // Si l'option pour avertir le valideur en cas de délai trop court
  244. if($cp->getConfCP('AlertValidatorDelay')) {
  245. if($cp->date_debut < $nextMonth) {
  246. $message.= "\n";
  247. $message.= "Cette demande de congés payés à été effectué dans un";
  248. $message.= " délai de moins de ".$cp->getConfCP('delayForRequest')." jours avant ceux-ci.\n";
  249. }
  250. }
  251. // Si l'option pour avertir le valideur en cas de solde inférieur à la demande
  252. if($cp->getConfCP('AlertValidatorSolde')) {
  253. $nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1);
  254. if ($nbopenedday > $cp->getCPforUser($cp->fk_user))
  255. {
  256. $message.= "\n";
  257. $message.= "L'utilisateur ayant fait cette demande de congés payés n'a pas le solde requis.\n";
  258. }
  259. }
  260. $message.= "\n";
  261. $message.= "- Demandeur : {$expediteur->prenom} {$expediteur->nom}\n";
  262. $message.= "- Période : du ".date('d/m/Y',strtotime($cp->date_debut))." au ".date('d/m/Y',strtotime($cp->date_fin))."\n";
  263. $message.= "- Lien : {$dolibarr_main_url_root}/holiday/fiche.php?id={$cp->rowid}\n\n";
  264. $message.= "Bien cordialement,\n".$societeName;
  265. $mail = new CMailFile($subject,$emailTo,$emailFrom,$message);
  266. // Envoi du mail
  267. $result=$mail->sendfile();
  268. if(!$result) {
  269. header('Location: fiche.php?id='.$_GET['id'].'&error=mail&error_content='.$mail->error);
  270. exit;
  271. }
  272. header('Location: fiche.php?id='.$_GET['id']);
  273. exit;
  274. } else {
  275. // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
  276. header('Location: fiche.php?id='.$_GET['id'].'&error=SQL_Create&msg='.$cp->error);
  277. exit;
  278. }
  279. }
  280. }
  281. // Si Validation de la demande
  282. if($action == 'confirm_valid')
  283. {
  284. $cp = new Holiday($db);
  285. $cp->fetch($_GET['id']);
  286. $userID = $user->id;
  287. // Si statut en attente de validation et valideur = utilisateur
  288. if($cp->statut == 2 && $userID == $cp->fk_validator)
  289. {
  290. $cp->date_valid = dol_now();
  291. $cp->fk_user_valid = $user->id;
  292. $cp->statut = 3;
  293. $verif = $cp->update($user->id);
  294. // Si pas d'erreur SQL on redirige vers la fiche de la demande
  295. if($verif > 0) {
  296. // Retrait du nombre de jours prit
  297. $nbJour = $nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1);
  298. $soldeActuel = $cp->getCpforUser($cp->fk_user);
  299. $newSolde = $soldeActuel - ($nbJour*$cp->getConfCP('nbHolidayDeducted'));
  300. // On ajoute la modification dans le LOG
  301. $cp->addLogCP($userID,$cp->fk_user,'Event : Prise de congés payés',$newSolde);
  302. // Mise à jour du solde
  303. $cp->updateSoldeCP($cp->fk_user,$newSolde);
  304. // A
  305. $destinataire = new User($db);
  306. $destinataire->fetch($cp->fk_user);
  307. $emailTo = $destinataire->email;
  308. // De
  309. $expediteur = new User($db);
  310. $expediteur->fetch($cp->fk_validator);
  311. $emailFrom = $expediteur->email;
  312. // Sujet
  313. if($conf->global->MAIN_APPLICATION_TITLE != NULL) {
  314. $societeName = addslashes($conf->global->MAIN_APPLICATION_TITLE);
  315. } else {
  316. $societeName = addslashes($conf->global->MAIN_INFO_SOCIETE_NOM);
  317. }
  318. $subject = stripslashes($societeName)." - Demande de congés payés validée";
  319. // Contenu
  320. $message = "Bonjour {$destinataire->prenom},\n\n";
  321. $message.= "Votre demande de congés payés du ".$cp->date_debut." au ".$cp->date_fin." vient d'être validée!\n";
  322. $message.= "- Valideur : {$expediteur->prenom} {$expediteur->nom}\n";
  323. $message.= "- Lien : {$dolibarr_main_url_root}/holiday/fiche.php?id={$cp->rowid}\n\n";
  324. $message.= "Bien cordialement,\n".$societeName;
  325. $mail = new CMailFile($subject,$emailTo,$emailFrom,$message);
  326. // Envoi du mail
  327. $result=$mail->sendfile();
  328. if(!$result) {
  329. header('Location: fiche.php?id='.$_GET['id'].'&error=mail&error_content='.$mail->error);
  330. exit;
  331. }
  332. header('Location: fiche.php?id='.$_GET['id']);
  333. exit;
  334. } else {
  335. // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
  336. header('Location: fiche.php?id='.$_GET['id'].'&error=SQL_Create&msg='.$cp->error);
  337. exit;
  338. }
  339. }
  340. }
  341. if ($action == 'confirm_refuse')
  342. {
  343. if(!empty($_POST['detail_refuse']))
  344. {
  345. $cp = new Holiday($db);
  346. $cp->fetch($_GET['id']);
  347. $userID = $user->id;
  348. // Si statut en attente de validation et valideur = utilisateur
  349. if($cp->statut == 2 && $userID == $cp->fk_validator) {
  350. $cp->date_refuse = date('Y-m-d H:i:s', time());
  351. $cp->fk_user_refuse = $user->id;
  352. $cp->statut = 5;
  353. $cp->detail_refuse = $_POST['detail_refuse'];
  354. $verif = $cp->update($user->id);
  355. // Si pas d'erreur SQL on redirige vers la fiche de la demande
  356. if($verif > 0) {
  357. // A
  358. $destinataire = new User($db);
  359. $destinataire->fetch($cp->fk_user);
  360. $emailTo = $destinataire->email;
  361. // De
  362. $expediteur = new User($db);
  363. $expediteur->fetch($cp->fk_validator);
  364. $emailFrom = $expediteur->email;
  365. // Sujet
  366. if($conf->global->MAIN_APPLICATION_TITLE != NULL) {
  367. $societeName = addslashes($conf->global->MAIN_APPLICATION_TITLE);
  368. } else {
  369. $societeName = addslashes($conf->global->MAIN_INFO_SOCIETE_NOM);
  370. }
  371. $subject = stripslashes($societeName)." - Demande de congés payés refusée";
  372. // Contenu
  373. $message = "Bonjour {$destinataire->prenom},\n\n";
  374. $message.= "Votre demande de congés payés ".$cp->date_debut." au ".$cp->date_fin." vient d'être refusée pour le motif suivant :\n";
  375. $message.= $_POST['detail_refuse']."\n\n";
  376. $message.= "- Valideur : {$expediteur->prenom} {$expediteur->nom}\n";
  377. $message.= "- Lien : {$dolibarr_main_url_root}/holiday/fiche.php?id={$cp->rowid}\n\n";
  378. $message.= "Bien cordialement,\n".$societeName;
  379. $mail = new CMailFile($subject,$emailTo,$emailFrom,$message);
  380. // Envoi du mail
  381. $result=$mail->sendfile();
  382. if(!$result) {
  383. header('Location: fiche.php?id='.$_GET['id'].'&error=mail&error_content='.$mail->error);
  384. exit;
  385. }
  386. header('Location: fiche.php?id='.$_GET['id']);
  387. exit;
  388. } else {
  389. // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
  390. header('Location: fiche.php?id='.$_GET['id'].'&error=SQL_Create&msg='.$cp->error);
  391. exit;
  392. }
  393. }
  394. } else {
  395. header('Location: fiche.php?id='.$_GET['id'].'&error=NoMotifRefuse');
  396. exit;
  397. }
  398. }
  399. // Si Validation de la demande
  400. if ($action == 'confirm_cancel' && $_GET['confirm'] == 'yes')
  401. {
  402. $cp = new Holiday($db);
  403. $cp->fetch($_GET['id']);
  404. $userID = $user->id;
  405. // Si statut en attente de validation et valideur = utilisateur
  406. if($cp->statut == 2 && $userID == $cp->fk_validator)
  407. {
  408. $cp->date_cancel = date('Y-m-d H:i:s', time());
  409. $cp->fk_user_cancel = $user->id;
  410. $cp->statut = 4;
  411. $verif = $cp->update($user->id);
  412. // Si pas d'erreur SQL on redirige vers la fiche de la demande
  413. if($verif > 0)
  414. {
  415. // A
  416. $destinataire = new User($db);
  417. $destinataire->fetch($cp->fk_user);
  418. $emailTo = $destinataire->email;
  419. // De
  420. $expediteur = new User($db);
  421. $expediteur->fetch($cp->fk_validator);
  422. $emailFrom = $expediteur->email;
  423. // Sujet
  424. if($conf->global->MAIN_APPLICATION_TITLE != NULL) {
  425. $societeName = addslashes($conf->global->MAIN_APPLICATION_TITLE);
  426. } else {
  427. $societeName = addslashes($conf->global->MAIN_INFO_SOCIETE_NOM);
  428. }
  429. $subject = stripslashes($societeName)."- Demande de congés payés annulée";
  430. // Contenu
  431. $message = "Bonjour {$destinataire->prenom},\n\n";
  432. $message.= "Votre demande de congés payés ".$cp->date_debut." au ".$cp->date_fin." vient d'être annulée !\n";
  433. $message.= "- Valideur : {$expediteur->prenom} {$expediteur->nom}\n";
  434. $message.= "- Lien : {$dolibarr_main_url_root}/holiday/fiche.php?id={$cp->rowid}\n\n";
  435. $message.= "Bien cordialement,\n".$societeName;
  436. $mail = new CMailFile($subject,$emailTo,$emailFrom,$message);
  437. // Envoi du mail
  438. $result=$mail->sendfile();
  439. if(!$result)
  440. {
  441. header('Location: fiche.php?id='.$_GET['id'].'&error=mail&error_content='.$mail->error);
  442. exit;
  443. }
  444. header('Location: fiche.php?id='.$_GET['id']);
  445. exit;
  446. }
  447. else
  448. {
  449. // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
  450. header('Location: fiche.php?id='.$_GET['id'].'&error=SQL_Create&msg='.$cp->error);
  451. exit;
  452. }
  453. }
  454. }
  455. /***************************************************
  456. * View
  457. ****************************************************/
  458. llxHeader(array(),$langs->trans('CPTitreMenu'));
  459. if (empty($id) || $action == 'add' || $action == 'request')
  460. {
  461. // Si l'utilisateur n'a pas le droit de faire une demande
  462. if(!$user->rights->holiday->write)
  463. {
  464. $errors[]=$langs->trans('CantCreateCP');
  465. }
  466. else
  467. {
  468. // Formulaire de demande de congés payés
  469. print_fiche_titre($langs->trans('MenuAddCP'));
  470. // Si il y a une erreur
  471. if (GETPOST('error')) {
  472. switch(GETPOST('error')) {
  473. case 'datefin' :
  474. $errors[] = $langs->trans('ErrorEndDateCP');
  475. break;
  476. case 'SQL_Create' :
  477. $errors[] = $langs->trans('ErrorSQLCreateCP').' <b>'.htmlentities($_GET['msg']).'</b>';
  478. break;
  479. case 'CantCreate' :
  480. $errors[] = $langs->trans('CantCreateCP');
  481. break;
  482. case 'Valideur' :
  483. $errors[] = $langs->trans('InvalidValidatorCP');
  484. break;
  485. case 'nodatedebut' :
  486. $errors[] = $langs->trans('NoDateDebut');
  487. break;
  488. case 'nodatedebut' :
  489. $errors[] = $langs->trans('NoDateFin');
  490. break;
  491. case 'DureeHoliday' :
  492. $errors[] = $langs->trans('ErrorDureeCP');
  493. break;
  494. case 'alreadyCP' :
  495. $errors[] = $langs->trans('alreadyCPexist');
  496. break;
  497. }
  498. dol_htmloutput_mesg('',$errors,'error');
  499. }
  500. $html = new Form($db);
  501. $cp = new Holiday($db);
  502. $delayForRequest = $cp->getConfCP('delayForRequest');
  503. //$delayForRequest = $delayForRequest * (60*60*24);
  504. $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd');
  505. print '<script type="text/javascript">
  506. //<![CDATA[
  507. function valider(){
  508. if(document.demandeCP.date_debut_.value != "") {
  509. if(document.demandeCP.date_fin_.value != "") {
  510. if(document.demandeCP.valideur.value != "-1") {
  511. return true;
  512. }
  513. else {
  514. alert("'.dol_escape_js($langs->transnoentities('InvalidValidatorCP')).'");
  515. return false;
  516. }
  517. }
  518. else {
  519. alert("'.dol_escape_js($langs->transnoentities('NoDateFin')).'");
  520. return false;
  521. }
  522. }
  523. else {
  524. alert("'.dol_escape_js($langs->transnoentities('NoDateDebut')).'");
  525. return false;
  526. }
  527. }
  528. //]]>
  529. </script>'."\n";
  530. // Formulaire de demande
  531. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" onsubmit="return valider()" name="demandeCP">'."\n";
  532. print '<input type="hidden" name="action" value="create" />'."\n";
  533. print '<input type="hidden" name="userID" value="'.$user_id.'" />'."\n";
  534. print '<div class="tabBar">';
  535. print '<span>'.$langs->trans('DelayToRequestCP',$cp->getConfCP('delayForRequest')).'</span><br /><br />';
  536. $nb_holiday = $cp->getCPforUser($user->id) / $cp->getConfCP('nbHolidayDeducted');
  537. print '<span>'.$langs->trans('SoldeCPUser', round($nb_holiday,0)).'</span><br /><br />';
  538. print '<table class="border" width="100%">';
  539. print '<tbody>';
  540. print '<tr>';
  541. print '<td class="fieldrequired">'.$langs->trans("DateDebCP").' ('.$langs->trans("FirstDayOfHoliday").')</td>';
  542. print '<td>';
  543. // Si la demande ne vient pas de l'agenda
  544. if(!isset($_GET['datep'])) {
  545. $html->select_date(-1,'date_debut_');
  546. } else {
  547. $tmpdate = dol_mktime(0, 0, 0, GETPOST('datepmonth'), GETPOST('datepday'), GETPOST('datepyear'));
  548. $html->select_date($tmpdate,'date_debut_');
  549. }
  550. print '</td>';
  551. print '</tr>';
  552. print '<tr>';
  553. print '<td class="fieldrequired">'.$langs->trans("DateFinCP").' ('.$langs->trans("LastDayOfHoliday").')</td>';
  554. print '<td>';
  555. // Si la demande ne vient pas de l'agenda
  556. if(!isset($_GET['datep'])) {
  557. $html->select_date(-1,'date_fin_');
  558. } else {
  559. $tmpdate = dol_mktime(0, 0, 0, GETPOST('datefmonth'), GETPOST('datefday'), GETPOST('datefyear'));
  560. $html->select_date($tmpdate,'date_fin_');
  561. }
  562. print '</td>';
  563. print '</tr>';
  564. print '<tr>';
  565. print '<td class="fieldrequired">'.$langs->trans("ValidateByCP").'</td>';
  566. // Liste des utiliseurs du groupes choisi dans la config
  567. $idGroupValid = $cp->getConfCP('userGroup');
  568. $validator = new UserGroup($db,$idGroupValid);
  569. $valideurarray = $validator->listUsersForGroup();
  570. print '<td>';
  571. print $html->select_dolusers($valideur,"valideur",1,"",0,$valideurarray,'');
  572. print '</td>';
  573. print '</tr>';
  574. print '<tr>';
  575. print '<td>'.$langs->trans("DescCP").'</td>';
  576. print '<td>';
  577. print '<textarea name="description" class="flat" rows="'.ROWS_3.'" cols="70"></textarea>';
  578. print '</td>';
  579. print '</tr>';
  580. print '</tbody>';
  581. print '</table>';
  582. print '<div style="clear: both;"></div>';
  583. print '</div>';
  584. print '</from>'."\n";
  585. print '<center>';
  586. print '<input type="submit" value="'.$langs->trans("SendRequestCP").'" name="bouton" class="button">';
  587. print '&nbsp; &nbsp; ';
  588. print '<input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)">';
  589. print '</center>';
  590. }
  591. }
  592. else
  593. {
  594. if ($error)
  595. {
  596. print '<div class="tabBar">';
  597. print $error;
  598. print '<br /><br /><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
  599. print '</div>';
  600. }
  601. else
  602. {
  603. // Affichage de la fiche d'une demande de congés payés
  604. if ($id > 0)
  605. {
  606. $cp = new Holiday($db);
  607. $cp->fetch($id);
  608. $valideur = new User($db);
  609. $valideur->fetch($cp->fk_validator);
  610. $userRequest = new User($db);
  611. $userRequest->fetch($cp->fk_user);
  612. // Utilisateur connecté
  613. $userID = $user->id;
  614. //print_fiche_titre($langs->trans('TitreRequestCP'));
  615. // Si il y a une erreur
  616. if (GETPOST('error')) {
  617. switch(GETPOST('error')) {
  618. case 'datefin' :
  619. $errors[] = $langs->trans('ErrorEndDateCP');
  620. break;
  621. case 'SQL_Create' :
  622. $errors[] = $langs->trans('ErrorSQLCreateCP').' <b>'.htmlentities($_GET['msg']).'</b>';
  623. break;
  624. case 'CantCreate' :
  625. $errors[] = $langs->trans('CantCreateCP');
  626. break;
  627. case 'Valideur' :
  628. $errors[] = $langs->trans('InvalidValidatorCP');
  629. break;
  630. case 'nodatedebut' :
  631. $errors[] = $langs->trans('NoDateDebut');
  632. break;
  633. case 'nodatedebut' :
  634. $errors[] = $langs->trans('NoDateFin');
  635. break;
  636. case 'DureeHoliday' :
  637. $errors[] = $langs->trans('ErrorDureeCP');
  638. break;
  639. case 'NoMotifRefuse' :
  640. $errors[] = $langs->trans('NoMotifRefuseCP');
  641. break;
  642. case 'mail' :
  643. $errors[] = $langs->trans('ErrorMailNotSend').'<br /><b>'.$_GET['error_content'].'</b>';
  644. break;
  645. }
  646. dol_htmloutput_mesg('',$errors,'error');
  647. }
  648. // On vérifie si l'utilisateur à le droit de lire cette demande
  649. if($user->id == $cp->fk_user || $user->rights->holiday->lire_tous)
  650. {
  651. if ($action == 'delete' && $cp->statut == 1) {
  652. if($user->rights->holiday->delete) {
  653. $html = new Form($db);
  654. $ret=$html->form_confirm("fiche.php?id=".$_GET['id'],$langs->trans("TitleDeleteCP"),$langs->trans("ConfirmDeleteCP"),"confirm_delete", '', 0, 1);
  655. if ($ret == 'html') print '<br />';
  656. }
  657. }
  658. // Si envoi en validation
  659. if ($action == 'sendToValidate' && $cp->statut == 1 && $userID == $cp->fk_user) {
  660. $html = new Form($db);
  661. $ret=$html->form_confirm("fiche.php?id=".$_GET['id'],$langs->trans("TitleToValidCP"),$langs->trans("ConfirmToValidCP"),"confirm_send", '', 0, 1);
  662. if ($ret == 'html') print '<br />';
  663. }
  664. // Si validation de la demande
  665. if ($action == 'valid' && $cp->statut == 2 && $userID == $cp->fk_validator) {
  666. $html = new Form($db);
  667. $ret=$html->form_confirm("fiche.php?id=".$_GET['id'],$langs->trans("TitleValidCP"),$langs->trans("ConfirmValidCP"),"confirm_valid", '', 0, 1);
  668. if ($ret == 'html') print '<br />';
  669. }
  670. // Si refus de la demande
  671. if ($action == 'refuse' && $cp->statut == 2 && $userID == $cp->fk_validator) {
  672. $html = new Form($db);
  673. $array_input = array(array('type'=>"text",'label'=>"Entrez ci-dessous un motif de refus :",'name'=>"detail_refuse",'size'=>"50",'value'=>""));
  674. $ret=$html->form_confirm("fiche.php?id=".$_GET['id']."&action=confirm_refuse",$langs->trans("TitleRefuseCP"),"","confirm_refuse",$array_input,"",0);
  675. if ($ret == 'html') print '<br />';
  676. }
  677. // Si annulation de la demande
  678. if ($action == 'cancel' && $cp->statut == 2 && $userID == $cp->fk_validator) {
  679. $html = new Form($db);
  680. $ret=$html->form_confirm("fiche.php?id=".$_GET['id'],$langs->trans("TitleCancelCP"),$langs->trans("ConfirmCancelCP"),"confirm_cancel", '', 0, 1);
  681. if ($ret == 'html') print '<br />';
  682. }
  683. dol_fiche_head(array(),'card',$langs->trans("CPTitreMenu"),0,'holiday');
  684. if ($action == 'edit' && $user->id == $cp->fk_user && $cp->statut == 1)
  685. {
  686. $edit = true;
  687. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$_GET['id'].'">'."\n";
  688. print '<input type="hidden" name="action" value="update"/>'."\n";
  689. print '<input type="hidden" name="holiday_id" value="'.$_GET['id'].'" />'."\n";
  690. $html = new Form($db);
  691. }
  692. print '<table class="border" width="100%">';
  693. print '<tbody>';
  694. /*print '<tr class="liste_titre">';
  695. print '<td colspan="2">'.$langs->trans("InfosCP").'</td>';
  696. print '</tr>';*/
  697. print '<tr>';
  698. print '<td width="25%">'.$langs->trans("Ref").'</td>';
  699. print '<td>'.$cp->rowid.'</td>';
  700. print '</tr>';
  701. if(!$edit) {
  702. print '<tr>';
  703. print '<td>'.$langs->trans('DateDebCP').'</td>';
  704. print '<td>'.dol_print_date($cp->date_debut,'day').'</td>';
  705. print '</tr>';
  706. } else {
  707. print '<tr>';
  708. print '<td>'.$langs->trans('DateDebCP').'</td>';
  709. print '<td>';
  710. $html->select_date($cp->date_debut,'date_debut_');
  711. print '</td>';
  712. print '</tr>';
  713. }
  714. if(!$edit) {
  715. print '<tr>';
  716. print '<td>'.$langs->trans('DateFinCP').'</td>';
  717. print '<td>'.dol_print_date($cp->date_fin,'day').'</td>';
  718. print '</tr>';
  719. } else {
  720. print '<tr>';
  721. print '<td>'.$langs->trans('DateFinCP').'</td>';
  722. print '<td>';
  723. $html->select_date($cp->date_fin,'date_fin_');
  724. print '</td>';
  725. print '</tr>';
  726. }
  727. print '<tr>';
  728. print '<td>'.$langs->trans('NbUseDaysCP').'</td>';
  729. print '<td>'.num_open_day($cp->date_debut,$cp->date_fin,0,1).'</td>';
  730. print '</tr>';
  731. // Status
  732. print '<tr>';
  733. print '<td>'.$langs->trans('StatutCP').'</td>';
  734. print '<td><b>'.$cp->getStatutCP($cp->statut).'</b></td>';
  735. print '</tr>';
  736. if($cp->statut == 5) {
  737. print '<tr>';
  738. print '<td>'.$langs->trans('DetailRefusCP').'</td>';
  739. print '<td>'.$cp->detail_refuse.'</td>';
  740. print '</tr>';
  741. }
  742. // Description
  743. if(!$edit) {
  744. print '<tr>';
  745. print '<td>'.$langs->trans('DescCP').'</td>';
  746. print '<td>'.nl2br($cp->description).'</td>';
  747. print '</tr>';
  748. } else {
  749. print '<tr>';
  750. print '<td>'.$langs->trans('DescCP').'</td>';
  751. print '<td><textarea name="description" class="flat" rows="'.ROWS_3.'" cols="70">'.$cp->description.'</textarea></td>';
  752. print '</tr>';
  753. }
  754. print '</tbody>';
  755. print '</table>'."\n";
  756. print '<br><br>';
  757. print '<table class="border" width="50%">'."\n";
  758. print '<tbody>';
  759. print '<tr class="liste_titre">';
  760. print '<td colspan="2">'.$langs->trans("InfosWorkflowCP").'</td>';
  761. print '</tr>';
  762. print '<tr>';
  763. print '<td>'.$langs->trans('RequestByCP').'</td>';
  764. print '<td>'.$userRequest->getNomUrl(1).'</td>';
  765. print '</tr>';
  766. if(!$edit) {
  767. print '<tr>';
  768. print '<td width="50%">'.$langs->trans('ValidateByCP').'</td>';
  769. print '<td>'.$valideur->getNomUrl(1).'</td>';
  770. print '</tr>';
  771. } else {
  772. print '<tr>';
  773. print '<td width="50%">'.$langs->trans('ValidateByCP').'</td>';
  774. // Liste des utiliseurs du groupes choisi dans la config
  775. $idGroupValid = $cp->getConfCP('userGroup');
  776. $validator = new UserGroup($db,$idGroupValid);
  777. $valideur = $validator->listUsersForGroup();
  778. print '<td>';
  779. $html->select_users($cp->fk_validator,"valideur",1,"",0,$valideur,'');
  780. print '</td>';
  781. print '</tr>';
  782. }
  783. print '<tr>';
  784. print '<td>'.$langs->trans('DateCreateCP').'</td>';
  785. print '<td>'.dol_print_date($cp->date_create,'dayhour').'</td>';
  786. print '</tr>';
  787. if($cp->statut == 3) {
  788. print '<tr>';
  789. print '<td>'.$langs->trans('DateValidCP').'</td>';
  790. print '<td>'.dol_print_date($cp->date_valid,'dayhour').'</td>';
  791. print '</tr>';
  792. }
  793. if($cp->statut == 4) {
  794. print '<tr>';
  795. print '<td>'.$langs->trans('DateCancelCP').'</td>';
  796. print '<td>'.dol_print_date($cp->date_cancel,'dayhour').'</td>';
  797. print '</tr>';
  798. }
  799. if($cp->statut == 5) {
  800. print '<tr>';
  801. print '<td>'.$langs->trans('DateRefusCP').'</td>';
  802. print '<td>'.dol_print_date($cp->date_refuse,'dayhour').'</td>';
  803. print '</tr>';
  804. }
  805. print '</tbody>';
  806. print '</table>';
  807. dol_fiche_end();
  808. print '<div style="clear: both;"></div>'."\n";
  809. if ($edit)
  810. {
  811. print '<center>';
  812. if($user->rights->holiday->write && $_GET['action'] == 'edit' && $cp->statut == 1)
  813. {
  814. print '<input type="submit" value="'.$langs->trans("UpdateButtonCP").'" class="button">';
  815. }
  816. print '</center>';
  817. print '</form>';
  818. }
  819. if (! $edit)
  820. {
  821. print '<br />';
  822. print '<div style="float: right;">'."\n";
  823. // Boutons d'actions
  824. if($user->rights->holiday->write && $_GET['action'] != 'edit' && $cp->statut == 1) {
  825. print '<a href="fiche.php?id='.$_GET['id'].'&action=edit" class="butAction" style="float: left;">'.$langs->trans("EditCP").'</a>';
  826. }
  827. if($user->rights->holiday->delete && $cp->statut == 1) {
  828. print '<a href="fiche.php?id='.$_GET['id'].'&action=delete" class="butAction" style="float: left;">'.$langs->trans("DeleteCP").'</a>';
  829. }
  830. if($user->id == $cp->fk_user && $cp->statut == 1) {
  831. print '<a href="fiche.php?id='.$_GET['id'].'&action=sendToValidate" class="butAction" style="float: left;">'.$langs->trans("SendToValidationCP").'</a>';
  832. }
  833. // Si le statut est en attente de validation et que le valideur est connecté
  834. if($userID == $cp->fk_validator && $cp->statut == 2) {
  835. print '<a href="fiche.php?id='.$_GET['id'].'&action=valid" class="butAction" style="float: left;">'.$langs->trans("ActionValidCP").'</a>';
  836. print '<a href="fiche.php?id='.$_GET['id'].'&action=refuse" class="butAction" style="float: left;">'.$langs->trans("ActionRefuseCP").'</a>';
  837. print '<a href="fiche.php?id='.$_GET['id'].'&action=cancel" class="butAction" style="float: left;">'.$langs->trans("ActionCancelCP").'</a>';
  838. }
  839. print '</div>';
  840. }
  841. } else {
  842. print '<div class="tabBar">';
  843. print $langs->trans('ErrorUserViewCP');
  844. print '<br /><br /><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
  845. print '</div>';
  846. }
  847. } else {
  848. print '<div class="tabBar">';
  849. print $langs->trans('ErrorIDFicheCP');
  850. print '<br /><br /><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
  851. print '</div>';
  852. }
  853. }
  854. }
  855. // End of page
  856. llxFooter();
  857. if (is_object($db)) $db->close();
  858. ?>