card.php 52 KB

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