card.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. <?php
  2. /* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
  3. * Copyright (C) 2012-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
  7. * Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, orwrite
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/holiday/card.php
  24. * \ingroup holiday
  25. * \brief Form and file creation of paid holiday.
  26. */
  27. require('../main.inc.php');
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php';
  37. // Get parameters
  38. $myparam = GETPOST("myparam");
  39. $action=GETPOST('action', 'alpha');
  40. $id=GETPOST('id', 'int');
  41. $userid = GETPOST('userid')?GETPOST('userid'):$user->id;
  42. // Protection if external user
  43. if ($user->societe_id > 0) accessforbidden();
  44. $now=dol_now();
  45. $langs->load("holiday");
  46. /*
  47. * Actions
  48. */
  49. // If create a request
  50. if ($action == 'create')
  51. {
  52. $object = new Holiday($db);
  53. // If no right to create a request
  54. if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all)))
  55. {
  56. $error++;
  57. setEventMessages($langs->trans('CantCreateCP'), null, 'errors');
  58. $action='request';
  59. }
  60. if (! $error)
  61. {
  62. $db->begin();
  63. $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'));
  64. $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'));
  65. $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1);
  66. $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
  67. $starthalfday=GETPOST('starthalfday');
  68. $endhalfday=GETPOST('endhalfday');
  69. $type=GETPOST('type');
  70. $halfday=0;
  71. if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2;
  72. else if ($starthalfday == 'afternoon') $halfday=-1;
  73. else if ($endhalfday == 'morning') $halfday=1;
  74. $valideur = GETPOST('valideur');
  75. $description = trim(GETPOST('description'));
  76. $userID = GETPOST('userID');
  77. // If no type
  78. if ($type <= 0)
  79. {
  80. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
  81. $error++;
  82. $action='create';
  83. }
  84. // If no start date
  85. if (empty($date_debut))
  86. {
  87. setEventMessages($langs->trans("NoDateDebut"), null, 'errors');
  88. $error++;
  89. $action='create';
  90. }
  91. // If no end date
  92. if (empty($date_fin))
  93. {
  94. setEventMessages($langs->trans("NoDateFin"), null, 'errors');
  95. $error++;
  96. $action='create';
  97. }
  98. // If start date after end date
  99. if ($date_debut > $date_fin)
  100. {
  101. setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors');
  102. $error++;
  103. $action='create';
  104. }
  105. // Check if there is already holiday for this period
  106. $verifCP = $object->verifDateHolidayCP($userID, $date_debut, $date_fin, $halfday);
  107. if (! $verifCP)
  108. {
  109. setEventMessages($langs->trans("alreadyCPexist"), null, 'errors');
  110. $error++;
  111. $action='create';
  112. }
  113. // If there is no Business Days within request
  114. $nbopenedday=num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
  115. if($nbopenedday < 0.5)
  116. {
  117. setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors');
  118. $error++;
  119. $action='create';
  120. }
  121. // If no validator designated
  122. if ($valideur < 1)
  123. {
  124. setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors');
  125. $error++;
  126. }
  127. $result = 0;
  128. $result = 0;
  129. if (! $error)
  130. {
  131. $object->fk_user = $userid;
  132. $object->description = $description;
  133. $object->date_debut = $date_debut;
  134. $object->date_fin = $date_fin;
  135. $object->fk_validator = $valideur;
  136. $object->halfday = $halfday;
  137. $object->fk_type = $type;
  138. $result = $object->create($user);
  139. }
  140. // If no SQL error we redirect to the request card
  141. if (! $error && $result > 0)
  142. {
  143. $db->commit();
  144. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  145. exit;
  146. }
  147. else
  148. {
  149. $db->rollback();
  150. }
  151. }
  152. }
  153. if ($action == 'update')
  154. {
  155. $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'));
  156. $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'));
  157. $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1);
  158. $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
  159. $starthalfday=GETPOST('starthalfday');
  160. $endhalfday=GETPOST('endhalfday');
  161. $halfday=0;
  162. if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2;
  163. else if ($starthalfday == 'afternoon') $halfday=-1;
  164. else if ($endhalfday == 'morning') $halfday=1;
  165. // If no right to modify a request
  166. if (! $user->rights->holiday->write)
  167. {
  168. header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=CantUpdate');
  169. exit;
  170. }
  171. $object = new Holiday($db);
  172. $object->fetch($id);
  173. $canedit=(($user->id == $object->fk_user && $user->rights->holiday->write) || ($user->id != $object->fk_user && $user->rights->holiday->write_all));
  174. // If under validation
  175. if ($object->statut == 1)
  176. {
  177. // If this is the requestor or has read/write rights
  178. if ($canedit)
  179. {
  180. $valideur = $_POST['valideur'];
  181. $description = trim($_POST['description']);
  182. // If no start date
  183. if (empty($_POST['date_debut_'])) {
  184. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=nodatedebut');
  185. exit;
  186. }
  187. // If no end date
  188. if (empty($_POST['date_fin_'])) {
  189. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=nodatefin');
  190. exit;
  191. }
  192. // If start date after end date
  193. if ($date_debut > $date_fin) {
  194. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=datefin');
  195. exit;
  196. }
  197. // If no validator designated
  198. if ($valideur < 1) {
  199. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=Valideur');
  200. exit;
  201. }
  202. // If there is no Business Days within request
  203. $nbopenedday=num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
  204. if ($nbopenedday < 0.5)
  205. {
  206. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=DureeHoliday');
  207. exit;
  208. }
  209. $object->description = $description;
  210. $object->date_debut = $date_debut;
  211. $object->date_fin = $date_fin;
  212. $object->fk_validator = $valideur;
  213. $object->halfday = $halfday;
  214. // Update
  215. $verif = $object->update($user);
  216. if ($verif > 0)
  217. {
  218. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  219. exit;
  220. }
  221. else
  222. {
  223. // Otherwise we display the request form with the SQL error message
  224. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=SQL_Create&msg='.$object->error);
  225. exit;
  226. }
  227. }
  228. } else {
  229. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  230. exit;
  231. }
  232. }
  233. // If delete of request
  234. if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights->holiday->delete)
  235. {
  236. $error=0;
  237. $db->begin();
  238. $object = new Holiday($db);
  239. $object->fetch($id);
  240. $canedit=(($user->id == $object->fk_user && $user->rights->holiday->write) || ($user->id != $object->fk_user && $user->rights->holiday->write_all));
  241. // If this is a rough draft
  242. if ($object->statut == 1 || $object->statut == 3)
  243. {
  244. // Si l'utilisateur à le droit de lire cette demande, il peut la supprimer
  245. if ($canedit)
  246. {
  247. $result=$object->delete($user);
  248. }
  249. else
  250. {
  251. $error = $langs->trans('ErrorCantDeleteCP');
  252. }
  253. }
  254. if (! $error)
  255. {
  256. $db->commit();
  257. header('Location: list.php');
  258. exit;
  259. }
  260. else
  261. {
  262. $db->rollback();
  263. }
  264. }
  265. // Si envoi de la demande
  266. if ($action == 'confirm_send')
  267. {
  268. $object = new Holiday($db);
  269. $object->fetch($id);
  270. $canedit=(($user->id == $object->fk_user && $user->rights->holiday->write) || ($user->id != $object->fk_user && $user->rights->holiday->write_all));
  271. // Si brouillon et créateur
  272. if($object->statut == 1 && $canedit)
  273. {
  274. $object->statut = 2;
  275. $verif = $object->update($user);
  276. // Si pas d'erreur SQL on redirige vers la fiche de la demande
  277. if ($verif > 0)
  278. {
  279. // To
  280. $destinataire = new User($db);
  281. $destinataire->fetch($object->fk_validator);
  282. $emailTo = $destinataire->email;
  283. if (!$emailTo)
  284. {
  285. dol_syslog("Expected validator has no email, so we redirect directly to finished page without sending email");
  286. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  287. exit;
  288. }
  289. // From
  290. $expediteur = new User($db);
  291. $expediteur->fetch($object->fk_user);
  292. $emailFrom = $expediteur->email;
  293. // Subject
  294. $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
  295. if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
  296. $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysToValidate");
  297. // Content
  298. $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
  299. $message.= "\n";
  300. $message.= $langs->transnoentities("HolidaysToValidateBody")."\n";
  301. $delayForRequest = $object->getConfCP('delayForRequest');
  302. //$delayForRequest = $delayForRequest * (60*60*24);
  303. $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd');
  304. // Si l'option pour avertir le valideur en cas de délai trop court
  305. if($object->getConfCP('AlertValidatorDelay'))
  306. {
  307. if($object->date_debut < $nextMonth)
  308. {
  309. $message.= "\n";
  310. $message.= $langs->transnoentities("HolidaysToValidateDelay",$object->getConfCP('delayForRequest'))."\n";
  311. }
  312. }
  313. // Si l'option pour avertir le valideur en cas de solde inférieur à la demande
  314. if ($object->getConfCP('AlertValidatorSolde'))
  315. {
  316. $nbopenedday=num_open_day($object->date_debut_gmt,$object->date_fin_gmt,0,1,$object->halfday);
  317. if ($nbopenedday > $object->getCPforUser($object->fk_user, $object->fk_type))
  318. {
  319. $message.= "\n";
  320. $message.= $langs->transnoentities("HolidaysToValidateAlertSolde")."\n";
  321. }
  322. }
  323. $message.= "\n";
  324. $message.= "- ".$langs->transnoentitiesnoconv("Name")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
  325. $message.= "- ".$langs->transnoentitiesnoconv("Period")." : ".dol_print_date($object->date_debut,'day')." ".$langs->transnoentitiesnoconv("To")." ".dol_print_date($object->date_fin,'day')."\n";
  326. $message.= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n";
  327. $message.= "\n";
  328. $mail = new CMailFile($subject,$emailTo,$emailFrom,$message);
  329. // Envoi du mail
  330. $result=$mail->sendfile();
  331. if (!$result)
  332. {
  333. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error);
  334. exit;
  335. }
  336. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  337. exit;
  338. }
  339. else
  340. {
  341. // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
  342. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error);
  343. exit;
  344. }
  345. }
  346. }
  347. // Si Validation de la demande
  348. if ($action == 'confirm_valid')
  349. {
  350. $object = new Holiday($db);
  351. $object->fetch($id);
  352. // Si statut en attente de validation et valideur = utilisateur
  353. if ($object->statut == 2 && $user->id == $object->fk_validator)
  354. {
  355. $object->date_valid = dol_now();
  356. $object->fk_user_valid = $user->id;
  357. $object->statut = 3;
  358. $verif = $object->update($user);
  359. // Si pas d'erreur SQL on redirige vers la fiche de la demande
  360. if ($verif > 0)
  361. {
  362. // Calculcate number of days consummed
  363. $nbopenedday=num_open_day($object->date_debut_gmt,$object->date_fin_gmt,0,1,$object->halfday);
  364. $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
  365. $newSolde = $soldeActuel - ($nbopenedday * $object->getConfCP('nbHolidayDeducted'));
  366. // On ajoute la modification dans le LOG
  367. $object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("Holidays"), $newSolde, $object->fk_type);
  368. // Mise à jour du solde
  369. $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
  370. // To
  371. $destinataire = new User($db);
  372. $destinataire->fetch($object->fk_user);
  373. $emailTo = $destinataire->email;
  374. if (!$emailTo)
  375. {
  376. dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
  377. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  378. exit;
  379. }
  380. // From
  381. $expediteur = new User($db);
  382. $expediteur->fetch($object->fk_validator);
  383. $emailFrom = $expediteur->email;
  384. // Subject
  385. $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
  386. if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
  387. $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysValidated");
  388. // Content
  389. $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
  390. $message.= "\n";
  391. $message.= $langs->transnoentities("HolidaysValidatedBody", dol_print_date($object->date_debut,'day'),dol_print_date($object->date_fin,'day'))."\n";
  392. $message.= "- ".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
  393. $message.= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n";
  394. $message.= "\n";
  395. $mail = new CMailFile($subject,$emailTo,$emailFrom,$message);
  396. // Envoi du mail
  397. $result=$mail->sendfile();
  398. if(!$result) {
  399. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error);
  400. exit;
  401. }
  402. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  403. exit;
  404. } else {
  405. // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
  406. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error);
  407. exit;
  408. }
  409. }
  410. }
  411. if ($action == 'confirm_refuse')
  412. {
  413. if (! empty($_POST['detail_refuse']))
  414. {
  415. $object = new Holiday($db);
  416. $object->fetch($id);
  417. // Si statut en attente de validation et valideur = utilisateur
  418. if ($object->statut == 2 && $user->id == $object->fk_validator)
  419. {
  420. $object->date_refuse = date('Y-m-d H:i:s', time());
  421. $object->fk_user_refuse = $user->id;
  422. $object->statut = 5;
  423. $object->detail_refuse = $_POST['detail_refuse'];
  424. $verif = $object->update($user);
  425. // Si pas d'erreur SQL on redirige vers la fiche de la demande
  426. if ($verif > 0)
  427. {
  428. // To
  429. $destinataire = new User($db);
  430. $destinataire->fetch($object->fk_user);
  431. $emailTo = $destinataire->email;
  432. if (!$emailTo)
  433. {
  434. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  435. exit;
  436. }
  437. // From
  438. $expediteur = new User($db);
  439. $expediteur->fetch($object->fk_validator);
  440. $emailFrom = $expediteur->email;
  441. // Subject
  442. $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
  443. if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
  444. $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysRefused");
  445. // Content
  446. $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
  447. $message.= "\n";
  448. $message.= $langs->transnoentities("HolidaysRefusedBody", dol_print_date($object->date_debut,'day'), dol_print_date($object->date_fin,'day'))."\n";
  449. $message.= GETPOST('detail_refuse','alpha')."\n\n";
  450. $message.= "- ".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
  451. $message.= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n";
  452. $message.= "\n";
  453. $mail = new CMailFile($subject,$emailTo,$emailFrom,$message);
  454. // Envoi du mail
  455. $result=$mail->sendfile();
  456. if(!$result) {
  457. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error);
  458. exit;
  459. }
  460. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  461. exit;
  462. } else {
  463. // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
  464. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error);
  465. exit;
  466. }
  467. }
  468. } else {
  469. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=NoMotifRefuse');
  470. exit;
  471. }
  472. }
  473. // Si Validation de la demande
  474. if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
  475. {
  476. $object = new Holiday($db);
  477. $object->fetch($id);
  478. // Si statut en attente de validation et valideur = utilisateur
  479. if (($object->statut == 2 || $object->statut == 3) && ($user->id == $object->fk_validator || $user->id == $object->fk_user))
  480. {
  481. $db->begin();
  482. $oldstatus = $object->statut;
  483. $object->date_cancel = dol_now();
  484. $object->fk_user_cancel = $user->id;
  485. $object->statut = 4;
  486. $result = $object->update($user);
  487. if ($result >= 0 && $oldstatus == 3) // holiday was already validated, status 3, so we must increase back sold
  488. {
  489. // Calculcate number of days consummed
  490. $nbopenedday=num_open_day($object->date_debut_gmt,$object->date_fin_gmt,0,1,$object->halfday);
  491. $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
  492. $newSolde = $soldeActuel + ($nbopenedday * $object->getConfCP('nbHolidayDeducted'));
  493. // On ajoute la modification dans le LOG
  494. $result1=$object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde, $object->fk_type);
  495. // Mise à jour du solde
  496. $result2=$object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
  497. if ($result1 < 0 || $result2 < 0)
  498. {
  499. $error = $langs->trans('ErrorCantDeleteCP');
  500. }
  501. }
  502. if (! $error)
  503. {
  504. $db->commit();
  505. }
  506. else
  507. {
  508. $db->rollback();
  509. }
  510. // Si pas d'erreur SQL on redirige vers la fiche de la demande
  511. if (! $error && $result > 0)
  512. {
  513. // To
  514. $destinataire = new User($db);
  515. $destinataire->fetch($object->fk_user);
  516. $emailTo = $destinataire->email;
  517. if (!$emailTo)
  518. {
  519. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  520. exit;
  521. }
  522. // From
  523. $expediteur = new User($db);
  524. $expediteur->fetch($object->fk_user_cancel);
  525. $emailFrom = $expediteur->email;
  526. // Subject
  527. $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
  528. if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
  529. $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysCanceled");
  530. // Content
  531. $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
  532. $message.= "\n";
  533. $message.= $langs->transnoentities("HolidaysCanceledBody", dol_print_date($object->date_debut,'day'), dol_print_date($object->date_fin,'day'))."\n";
  534. $message.= "- ".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
  535. $message.= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n";
  536. $message.= "\n";
  537. $mail = new CMailFile($subject,$emailTo,$emailFrom,$message);
  538. // Envoi du mail
  539. $result=$mail->sendfile();
  540. if(!$result)
  541. {
  542. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error);
  543. exit;
  544. }
  545. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  546. exit;
  547. }
  548. else
  549. {
  550. // Sinon on affiche le formulaire de demande avec le message d'erreur SQL
  551. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error);
  552. exit;
  553. }
  554. }
  555. }
  556. /*
  557. * View
  558. */
  559. $form = new Form($db);
  560. $object = new Holiday($db);
  561. $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon"));
  562. llxHeader('', $langs->trans('CPTitreMenu'));
  563. if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create')
  564. {
  565. // Si l'utilisateur n'a pas le droit de faire une demande
  566. if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all)))
  567. {
  568. $errors[]=$langs->trans('CantCreateCP');
  569. }
  570. else
  571. {
  572. // Formulaire de demande de congés payés
  573. print load_fiche_titre($langs->trans('MenuAddCP'), '', 'title_hrm.png');
  574. // Si il y a une erreur
  575. if (GETPOST('error')) {
  576. switch(GETPOST('error')) {
  577. case 'datefin' :
  578. $errors[] = $langs->trans('ErrorEndDateCP');
  579. break;
  580. case 'SQL_Create' :
  581. $errors[] = $langs->trans('ErrorSQLCreateCP').' <b>'.htmlentities($_GET['msg']).'</b>';
  582. break;
  583. case 'CantCreate' :
  584. $errors[] = $langs->trans('CantCreateCP');
  585. break;
  586. case 'Valideur' :
  587. $errors[] = $langs->trans('InvalidValidatorCP');
  588. break;
  589. case 'nodatedebut' :
  590. $errors[] = $langs->trans('NoDateDebut');
  591. break;
  592. case 'nodatefin' :
  593. $errors[] = $langs->trans('NoDateFin');
  594. break;
  595. case 'DureeHoliday' :
  596. $errors[] = $langs->trans('ErrorDureeCP');
  597. break;
  598. case 'alreadyCP' :
  599. $errors[] = $langs->trans('alreadyCPexist');
  600. break;
  601. }
  602. setEventMessages($errors, null, 'errors');
  603. }
  604. $delayForRequest = $object->getConfCP('delayForRequest');
  605. //$delayForRequest = $delayForRequest * (60*60*24);
  606. $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd');
  607. print '<script type="text/javascript">
  608. function valider()
  609. {
  610. if(document.demandeCP.date_debut_.value != "")
  611. {
  612. if(document.demandeCP.date_fin_.value != "")
  613. {
  614. if(document.demandeCP.valideur.value != "-1") {
  615. return true;
  616. }
  617. else {
  618. alert("'.dol_escape_js($langs->transnoentities('InvalidValidatorCP')).'");
  619. return false;
  620. }
  621. }
  622. else
  623. {
  624. alert("'.dol_escape_js($langs->transnoentities('NoDateFin')).'");
  625. return false;
  626. }
  627. }
  628. else
  629. {
  630. alert("'.dol_escape_js($langs->transnoentities('NoDateDebut')).'");
  631. return false;
  632. }
  633. }
  634. </script>'."\n";
  635. // Formulaire de demande
  636. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" onsubmit="return valider()" name="demandeCP">'."\n";
  637. print '<input type="hidden" name="action" value="create" />'."\n";
  638. print '<input type="hidden" name="userID" value="'.$userid.'" />'."\n";
  639. dol_fiche_head();
  640. $out='';
  641. $typeleaves=$object->getTypes(1,1);
  642. foreach($typeleaves as $key => $val)
  643. {
  644. $nb_type = $object->getCPforUser($user->id, $val['rowid']);
  645. $nb_holiday += $nb_type;
  646. $out .= ' - '.$val['label'].': <strong>'.($nb_type?price2num($nb_type):0).'</strong><br>';
  647. }
  648. print $langs->trans('SoldeCPUser', round($nb_holiday,5)).'<br>';
  649. print $out;
  650. dol_fiche_end();
  651. dol_fiche_head();
  652. //print '<span>'.$langs->trans('DelayToRequestCP',$object->getConfCP('delayForRequest')).'</span><br /><br />';
  653. print '<table class="border" width="100%">';
  654. print '<tbody>';
  655. // User
  656. print '<tr>';
  657. print '<td class="titlefield fieldrequired">'.$langs->trans("User").'</td>';
  658. print '<td>';
  659. if (empty($user->rights->holiday->write_all))
  660. {
  661. print $form->select_dolusers($userid, 'useridbis', 0, '', 1, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  662. print '<input type="hidden" name="userid" value="'.$userid.'">';
  663. }
  664. else print $form->select_dolusers(GETPOST('userid')?GETPOST('userid'):$user->id,'userid',0,'',0);
  665. print '</td>';
  666. print '</tr>';
  667. // Type
  668. print '<tr>';
  669. print '<td class="fieldrequired">'.$langs->trans("Type").'</td>';
  670. print '<td>';
  671. $typeleaves=$object->getTypes(1,-1);
  672. $arraytypeleaves=array();
  673. foreach($typeleaves as $key => $val)
  674. {
  675. $labeltoshow = $val['label'];
  676. $labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':'');
  677. $arraytypeleaves[$val['rowid']]=$labeltoshow;
  678. }
  679. print $form->selectarray('type', $arraytypeleaves, (GETPOST('type')?GETPOST('type'):''), 1);
  680. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  681. print '</td>';
  682. print '</tr>';
  683. // Date start
  684. print '<tr>';
  685. print '<td class="fieldrequired">';
  686. print $langs->trans("DateDebCP");
  687. print ' ('.$langs->trans("FirstDayOfHoliday").')';
  688. print '</td>';
  689. print '<td>';
  690. // Si la demande ne vient pas de l'agenda
  691. if (! GETPOST('date_debut_')) {
  692. $form->select_date(-1, 'date_debut_', 0, 0, 0, '', 1, 1);
  693. } else {
  694. $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'));
  695. $form->select_date($tmpdate, 'date_debut_', 0, 0, 0, '', 1, 1);
  696. }
  697. print ' &nbsp; &nbsp; ';
  698. print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday')?GETPOST('starthalfday'):'morning'));
  699. print '</td>';
  700. print '</tr>';
  701. // Date end
  702. print '<tr>';
  703. print '<td class="fieldrequired">';
  704. print $langs->trans("DateFinCP");
  705. print ' ('.$langs->trans("LastDayOfHoliday").')';
  706. print '</td>';
  707. print '<td>';
  708. // Si la demande ne vient pas de l'agenda
  709. if (! GETPOST('date_fin_')) {
  710. $form->select_date(-1,'date_fin_', 0, 0, 0, '', 1, 1);
  711. } else {
  712. $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'));
  713. $form->select_date($tmpdate,'date_fin_', 0, 0, 0, '', 1, 1);
  714. }
  715. print ' &nbsp; &nbsp; ';
  716. print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday')?GETPOST('endhalfday'):'afternoon'));
  717. print '</td>';
  718. print '</tr>';
  719. // Approved by
  720. print '<tr>';
  721. print '<td class="fieldrequired">'.$langs->trans("ReviewedByCP").'</td>';
  722. print '<td>';
  723. print $form->select_dolusers((GETPOST('valideur')>0?GETPOST('valideur'):$user->fk_user), "valideur", 1, ($user->admin ? '' : array($user->id)), 0, '', 0, 0, 0, 0, '', 0, '', '', 1); // By default, hierarchical parent
  724. print '</td>';
  725. print '</tr>';
  726. // Description
  727. print '<tr>';
  728. print '<td>'.$langs->trans("DescCP").'</td>';
  729. print '<td class="tdtop">';
  730. $doleditor = new DolEditor('description', GETPOST('description'), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
  731. print $doleditor->Create(1);
  732. print '</td></tr>';
  733. print '</tbody>';
  734. print '</table>';
  735. dol_fiche_end();
  736. print '<div class="center">';
  737. print '<input type="submit" value="'.$langs->trans("SendRequestCP").'" name="bouton" class="button">';
  738. print '&nbsp; &nbsp; ';
  739. print '<input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)">';
  740. print '</div>';
  741. print '</from>'."\n";
  742. }
  743. }
  744. else
  745. {
  746. if ($error)
  747. {
  748. print '<div class="tabBar">';
  749. print $error;
  750. print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
  751. print '</div>';
  752. }
  753. else
  754. {
  755. // Affichage de la fiche d'une demande de congés payés
  756. if ($id > 0)
  757. {
  758. $object->fetch($id);
  759. $canedit=(($user->id == $object->fk_user && $user->rights->holiday->write) || ($user->id != $object->fk_user && $user->rights->holiday->write_all));
  760. $valideur = new User($db);
  761. $valideur->fetch($object->fk_validator);
  762. $userRequest = new User($db);
  763. $userRequest->fetch($object->fk_user);
  764. //print load_fiche_titre($langs->trans('TitreRequestCP'));
  765. // Si il y a une erreur
  766. if (GETPOST('error'))
  767. {
  768. switch(GETPOST('error'))
  769. {
  770. case 'datefin' :
  771. $errors[] = $langs->transnoentitiesnoconv('ErrorEndDateCP');
  772. break;
  773. case 'SQL_Create' :
  774. $errors[] = $langs->transnoentitiesnoconv('ErrorSQLCreateCP').' '.$_GET['msg'];
  775. break;
  776. case 'CantCreate' :
  777. $errors[] = $langs->transnoentitiesnoconv('CantCreateCP');
  778. break;
  779. case 'Valideur' :
  780. $errors[] = $langs->transnoentitiesnoconv('InvalidValidatorCP');
  781. break;
  782. case 'nodatedebut' :
  783. $errors[] = $langs->transnoentitiesnoconv('NoDateDebut');
  784. break;
  785. case 'nodatefin' :
  786. $errors[] = $langs->transnoentitiesnoconv('NoDateFin');
  787. break;
  788. case 'DureeHoliday' :
  789. $errors[] = $langs->transnoentitiesnoconv('ErrorDureeCP');
  790. break;
  791. case 'NoMotifRefuse' :
  792. $errors[] = $langs->transnoentitiesnoconv('NoMotifRefuseCP');
  793. break;
  794. case 'mail' :
  795. $errors[] = $langs->transnoentitiesnoconv('ErrorMailNotSend')."\n".$_GET['error_content'];
  796. break;
  797. }
  798. setEventMessages($errors, null, 'errors');
  799. }
  800. // On vérifie si l'utilisateur à le droit de lire cette demande
  801. if ($canedit)
  802. {
  803. if ($action == 'delete')
  804. {
  805. if ($user->rights->holiday->delete)
  806. {
  807. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleDeleteCP"),$langs->trans("ConfirmDeleteCP"),"confirm_delete", '', 0, 1);
  808. }
  809. }
  810. // Si envoi en validation
  811. if ($action == 'sendToValidate' && $object->statut == 1)
  812. {
  813. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleToValidCP"),$langs->trans("ConfirmToValidCP"),"confirm_send", '', 1, 1);
  814. }
  815. // Si validation de la demande
  816. if ($action == 'valid')
  817. {
  818. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleValidCP"),$langs->trans("ConfirmValidCP"),"confirm_valid", '', 1, 1);
  819. }
  820. // Si refus de la demande
  821. if ($action == 'refuse')
  822. {
  823. $array_input = array(array('type'=>"text",'label'=> $langs->trans('DetailRefusCP'),'name'=>"detail_refuse",'size'=>"50",'value'=>""));
  824. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0);
  825. }
  826. // Si annulation de la demande
  827. if ($action == 'cancel')
  828. {
  829. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleCancelCP"),$langs->trans("ConfirmCancelCP"),"confirm_cancel", '', 1, 1);
  830. }
  831. $head=holiday_prepare_head($object);
  832. if ($action == 'edit' && $object->statut == 1)
  833. {
  834. $edit = true;
  835. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'."\n";
  836. print '<input type="hidden" name="action" value="update"/>'."\n";
  837. print '<input type="hidden" name="id" value="'.$object->id.'" />'."\n";
  838. }
  839. dol_fiche_head($head,'card',$langs->trans("CPTitreMenu"),0,'holiday');
  840. $linkback='<a href="'.DOL_URL_ROOT.'/holiday/list.php">'.$langs->trans("BackToList").'</a>';
  841. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref');
  842. print '<div class="fichecenter">';
  843. print '<div class="fichehalfleft">';
  844. print '<div class="underbanner clearboth"></div>';
  845. print '<table class="border centpercent">';
  846. print '<tbody>';
  847. print '<tr>';
  848. print '<td class="titlefield">'.$langs->trans("User").'</td>';
  849. print '<td>';
  850. print $userRequest->getNomUrl(-1, 'leave');
  851. print '</td></tr>';
  852. // Type
  853. print '<tr>';
  854. print '<td>'.$langs->trans("Type").'</td>';
  855. print '<td>';
  856. $typeleaves=$object->getTypes(1,-1);
  857. print empty($typeleaves[$object->fk_type]['label']) ? $langs->trans("TypeWasDisabledOrRemoved",$object->fk_type) : $typeleaves[$object->fk_type]['label'];
  858. print '</td>';
  859. print '</tr>';
  860. $starthalfday=($object->halfday == -1 || $object->halfday == 2)?'afternoon':'morning';
  861. $endhalfday=($object->halfday == 1 || $object->halfday == 2)?'morning':'afternoon';
  862. if(!$edit)
  863. {
  864. print '<tr>';
  865. print '<td>'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')</td>';
  866. print '<td>'.dol_print_date($object->date_debut,'day');
  867. print ' &nbsp; &nbsp; ';
  868. print $langs->trans($listhalfday[$starthalfday]);
  869. print '</td>';
  870. print '</tr>';
  871. }
  872. else
  873. {
  874. print '<tr>';
  875. print '<td>'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')</td>';
  876. print '<td>';
  877. $form->select_date($object->date_debut,'date_debut_');
  878. print ' &nbsp; &nbsp; ';
  879. print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday')?GETPOST('starthalfday'):$starthalfday));
  880. print '</td>';
  881. print '</tr>';
  882. }
  883. if (!$edit)
  884. {
  885. print '<tr>';
  886. print '<td>'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')</td>';
  887. print '<td>'.dol_print_date($object->date_fin,'day');
  888. print ' &nbsp; &nbsp; ';
  889. print $langs->trans($listhalfday[$endhalfday]);
  890. print '</td>';
  891. print '</tr>';
  892. }
  893. else
  894. {
  895. print '<tr>';
  896. print '<td>'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')</td>';
  897. print '<td>';
  898. $form->select_date($object->date_fin,'date_fin_');
  899. print ' &nbsp; &nbsp; ';
  900. print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday')?GETPOST('endhalfday'):$endhalfday));
  901. print '</td>';
  902. print '</tr>';
  903. }
  904. print '<tr>';
  905. print '<td>'.$langs->trans('NbUseDaysCP').'</td>';
  906. print '<td>'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).'</td>';
  907. print '</tr>';
  908. if ($object->statut == 5)
  909. {
  910. print '<tr>';
  911. print '<td>'.$langs->trans('DetailRefusCP').'</td>';
  912. print '<td>'.$object->detail_refuse.'</td>';
  913. print '</tr>';
  914. }
  915. // Description
  916. if (!$edit)
  917. {
  918. print '<tr>';
  919. print '<td>'.$langs->trans('DescCP').'</td>';
  920. print '<td>'.nl2br($object->description).'</td>';
  921. print '</tr>';
  922. }
  923. else
  924. {
  925. print '<tr>';
  926. print '<td>'.$langs->trans('DescCP').'</td>';
  927. print '<td class="tdtop">';
  928. $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
  929. print $doleditor->Create(1);
  930. print '</td></tr>';
  931. }
  932. print '</tbody>';
  933. print '</table>'."\n";
  934. print '</div>';
  935. print '<div class="fichehalfright">';
  936. print '<div class="ficheaddleft">';
  937. print '<div class="underbanner clearboth"></div>';
  938. // Info workflow
  939. print '<table class="border centpercent">'."\n";
  940. print '<tbody>';
  941. if (! empty($object->fk_user_create))
  942. {
  943. $userCreate=new User($db);
  944. $userCreate->fetch($object->fk_user_create);
  945. print '<tr>';
  946. print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
  947. print '<td>'.$userCreate->getNomUrl(-1).'</td>';
  948. print '</tr>';
  949. }
  950. if (!$edit) {
  951. print '<tr>';
  952. print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
  953. print '<td>'.$valideur->getNomUrl(-1).'</td>';
  954. print '</tr>';
  955. } else {
  956. print '<tr>';
  957. print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
  958. print '<td>';
  959. print $form->select_dolusers($object->fk_user, "valideur", 1, ($user->admin ? '' : array($user->id))); // By default, hierarchical parent
  960. print '</td>';
  961. print '</tr>';
  962. }
  963. print '<tr>';
  964. print '<td>'.$langs->trans('DateCreateCP').'</td>';
  965. print '<td>'.dol_print_date($object->date_create,'dayhour').'</td>';
  966. print '</tr>';
  967. if ($object->statut == 3) {
  968. print '<tr>';
  969. print '<td>'.$langs->trans('DateValidCP').'</td>';
  970. print '<td>'.dol_print_date($object->date_valid,'dayhour').'</td>';
  971. print '</tr>';
  972. }
  973. if ($object->statut == 4) {
  974. print '<tr>';
  975. print '<td>'.$langs->trans('DateCancelCP').'</td>';
  976. print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td>';
  977. print '</tr>';
  978. }
  979. if ($object->statut == 5) {
  980. print '<tr>';
  981. print '<td>'.$langs->trans('DateRefusCP').'</td>';
  982. print '<td>'.dol_print_date($object->date_refuse,'dayhour').'</td>';
  983. print '</tr>';
  984. }
  985. print '</tbody>';
  986. print '</table>';
  987. print '</div>';
  988. print '</div>';
  989. print '</div>';
  990. print '<div class="clearboth"></div>';
  991. dol_fiche_end();
  992. if ($action == 'edit' && $object->statut == 1)
  993. {
  994. print '<div align="center">';
  995. if ($canedit && $object->statut == 1)
  996. {
  997. print '<input type="submit" value="'.$langs->trans("Save").'" class="button">';
  998. }
  999. print '</div>';
  1000. print '</form>';
  1001. }
  1002. if (! $edit)
  1003. {
  1004. print '<div class="tabsAction">';
  1005. // Boutons d'actions
  1006. if ($canedit && $object->statut == 1)
  1007. {
  1008. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit" class="butAction">'.$langs->trans("EditCP").'</a>';
  1009. }
  1010. if ($canedit && $object->statut == 1)
  1011. {
  1012. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=sendToValidate" class="butAction">'.$langs->trans("Validate").'</a>';
  1013. }
  1014. if ($user->rights->holiday->delete && $object->statut == 1) // If draft
  1015. {
  1016. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete" class="butActionDelete">'.$langs->trans("DeleteCP").'</a>';
  1017. }
  1018. if ($user->id == $object->fk_validator && $object->statut == 2)
  1019. {
  1020. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid" class="butAction">'.$langs->trans("Approve").'</a>';
  1021. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=refuse" class="butAction">'.$langs->trans("ActionRefuseCP").'</a>';
  1022. }
  1023. if (($user->id == $object->fk_validator || $user->id == $object->fk_user) && ($object->statut == 2 || $object->statut == 3)) // Status validated or approved
  1024. {
  1025. if (($object->date_debut > dol_now()) || $user->admin) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
  1026. else print '<a href="#" class="butActionRefused" title="'.$langs->trans("HolidayStarted").'">'.$langs->trans("ActionCancelCP").'</a>';
  1027. }
  1028. print '</div>';
  1029. }
  1030. } else {
  1031. print '<div class="tabBar">';
  1032. print $langs->trans('ErrorUserViewCP');
  1033. print '<br /><br /><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
  1034. print '</div>';
  1035. }
  1036. } else {
  1037. print '<div class="tabBar">';
  1038. print $langs->trans('ErrorIDFicheCP');
  1039. print '<br /><br /><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
  1040. print '</div>';
  1041. }
  1042. }
  1043. }
  1044. // End of page
  1045. llxFooter();
  1046. if (is_object($db)) $db->close();