card.php 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637
  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@open-dsi.fr>
  7. * Copyright (C) 2014-2017 Ferran Marcet <fmarcet@2byte.es>
  8. * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
  9. * Copyright (C) 2020-2021 Udo Tamm <dev@dolibit.de>
  10. * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, orwrite
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/holiday/card.php
  27. * \ingroup holiday
  28. * \brief Form and file creation of paid holiday.
  29. */
  30. // Load Dolibarr environment
  31. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  42. // Get parameters
  43. $action = GETPOST('action', 'aZ09');
  44. $cancel = GETPOST('cancel', 'alpha');
  45. $confirm = GETPOST('confirm', 'alpha');
  46. $backtopage = GETPOST('backtopage', 'alpha');
  47. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  48. $id = GETPOST('id', 'int');
  49. $ref = GETPOST('ref', 'alpha');
  50. $fuserid = (GETPOST('fuserid', 'int') ?GETPOST('fuserid', 'int') : $user->id);
  51. $socid = GETPOST('socid', 'int');
  52. // Load translation files required by the page
  53. $langs->loadLangs(array("other", "holiday", "mails", "trips"));
  54. $error = 0;
  55. $now = dol_now();
  56. $childids = $user->getAllChildIds(1);
  57. $morefilter = '';
  58. if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) {
  59. $morefilter = 'AND employee = 1';
  60. }
  61. $object = new Holiday($db);
  62. $extrafields = new ExtraFields($db);
  63. // fetch optionals attributes and labels
  64. $extrafields->fetch_name_optionals_label($object->table_element);
  65. if (($id > 0) || $ref) {
  66. $object->fetch($id, $ref);
  67. // Check current user can read this leave request
  68. $canread = 0;
  69. if (!empty($user->rights->holiday->readall)) {
  70. $canread = 1;
  71. }
  72. if (!empty($user->rights->holiday->read) && in_array($object->fk_user, $childids)) {
  73. $canread = 1;
  74. }
  75. if (!$canread) {
  76. accessforbidden();
  77. }
  78. }
  79. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  80. $hookmanager->initHooks(array('holidaycard', 'globalcard'));
  81. $cancreate = 0;
  82. $cancreateall = 0;
  83. if (!empty($user->rights->holiday->write) && in_array($fuserid, $childids)) {
  84. $cancreate = 1;
  85. }
  86. if (!empty($user->rights->holiday->writeall)) {
  87. $cancreate = 1;
  88. $cancreateall = 1;
  89. }
  90. $candelete = 0;
  91. if (!empty($user->rights->holiday->delete)) {
  92. $candelete = 1;
  93. }
  94. if ($object->statut == Holiday::STATUS_DRAFT && $user->rights->holiday->write && in_array($object->fk_user, $childids)) {
  95. $candelete = 1;
  96. }
  97. // Protection if external user
  98. if ($user->socid) {
  99. $socid = $user->socid;
  100. }
  101. $result = restrictedArea($user, 'holiday', $object->id, 'holiday', '', '', 'rowid', $object->statut);
  102. /*
  103. * Actions
  104. */
  105. $parameters = array('socid' => $socid);
  106. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  107. if ($reshook < 0) {
  108. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  109. }
  110. if (empty($reshook)) {
  111. $backurlforlist = DOL_URL_ROOT.'/holiday/list.php';
  112. if (empty($backtopage) || ($cancel && empty($id))) {
  113. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  114. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  115. $backtopage = $backurlforlist;
  116. } else {
  117. $backtopage = DOL_URL_ROOT.'/holiday/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  118. }
  119. }
  120. }
  121. if ($cancel) {
  122. if (!empty($backtopageforcancel)) {
  123. header("Location: ".$backtopageforcancel);
  124. exit;
  125. } elseif (!empty($backtopage)) {
  126. header("Location: ".$backtopage);
  127. exit;
  128. }
  129. $action = '';
  130. }
  131. // Add leave request
  132. if ($action == 'add') {
  133. // If no right to create a request
  134. if (!$cancreate) {
  135. $error++;
  136. setEventMessages($langs->trans('CantCreateCP'), null, 'errors');
  137. $action = 'create';
  138. }
  139. if (!$error) {
  140. $object = new Holiday($db);
  141. $db->begin();
  142. $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'));
  143. $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'));
  144. $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1);
  145. $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
  146. $starthalfday = GETPOST('starthalfday');
  147. $endhalfday = GETPOST('endhalfday');
  148. $type = GETPOST('type');
  149. $halfday = 0;
  150. if ($starthalfday == 'afternoon' && $endhalfday == 'morning') {
  151. $halfday = 2;
  152. } elseif ($starthalfday == 'afternoon') {
  153. $halfday = -1;
  154. } elseif ($endhalfday == 'morning') {
  155. $halfday = 1;
  156. }
  157. $approverid = GETPOST('valideur', 'int');
  158. $description = trim(GETPOST('description', 'restricthtml'));
  159. // Check that leave is for a user inside the hierarchy or advanced permission for all is set
  160. if (!$cancreateall) {
  161. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  162. if (empty($user->rights->holiday->write)) {
  163. $error++;
  164. setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
  165. } elseif (!in_array($fuserid, $childids)) {
  166. $error++;
  167. setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
  168. $action = 'create';
  169. }
  170. } else {
  171. if (empty($user->rights->holiday->write) && empty($user->rights->holiday->writeall_advance)) {
  172. $error++;
  173. setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
  174. } elseif (empty($user->rights->holiday->writeall_advance) && !in_array($fuserid, $childids)) {
  175. $error++;
  176. setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
  177. $action = 'create';
  178. }
  179. }
  180. }
  181. // If no type
  182. if ($type <= 0) {
  183. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
  184. $error++;
  185. $action = 'create';
  186. }
  187. // If no start date
  188. if (empty($date_debut)) {
  189. setEventMessages($langs->trans("NoDateDebut"), null, 'errors');
  190. $error++;
  191. $action = 'create';
  192. }
  193. // If no end date
  194. if (empty($date_fin)) {
  195. setEventMessages($langs->trans("NoDateFin"), null, 'errors');
  196. $error++;
  197. $action = 'create';
  198. }
  199. // If start date after end date
  200. if ($date_debut > $date_fin) {
  201. setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors');
  202. $error++;
  203. $action = 'create';
  204. }
  205. // Check if there is already holiday for this period
  206. $verifCP = $object->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday);
  207. if (!$verifCP) {
  208. setEventMessages($langs->trans("alreadyCPexist"), null, 'errors');
  209. $error++;
  210. $action = 'create';
  211. }
  212. // If there is no Business Days within request
  213. $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
  214. if ($nbopenedday < 0.5) {
  215. setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors'); // No working day
  216. $error++;
  217. $action = 'create';
  218. }
  219. // If no validator designated
  220. if ($approverid < 1) {
  221. setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors');
  222. $error++;
  223. }
  224. $approverslist = $object->fetch_users_approver_holiday();
  225. if (!in_array($approverid, $approverslist)) {
  226. setEventMessages($langs->transnoentitiesnoconv('InvalidValidator'), null, 'errors');
  227. $error++;
  228. }
  229. // Fill array 'array_options' with data from add form
  230. $ret = $extrafields->setOptionalsFromPost(null, $object);
  231. if ($ret < 0) {
  232. $error++;
  233. }
  234. $result = 0;
  235. if (!$error) {
  236. $object->fk_user = $fuserid;
  237. $object->description = $description;
  238. $object->fk_validator = $approverid;
  239. $object->fk_type = $type;
  240. $object->date_debut = $date_debut;
  241. $object->date_fin = $date_fin;
  242. $object->halfday = $halfday;
  243. $result = $object->create($user);
  244. if ($result <= 0) {
  245. setEventMessages($object->error, $object->errors, 'errors');
  246. $error++;
  247. }
  248. }
  249. // If no SQL error we redirect to the request card
  250. if (!$error) {
  251. $db->commit();
  252. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  253. exit;
  254. } else {
  255. $db->rollback();
  256. }
  257. }
  258. }
  259. // If this is an update and we are an approver, we can update to change the expected approver with another one (including himself)
  260. if ($action == 'update' && GETPOSTISSET('savevalidator') && !empty($user->rights->holiday->approve)) {
  261. $object->fetch($id);
  262. $object->oldcopy = dol_clone($object);
  263. $object->fk_validator = GETPOST('valideur', 'int');
  264. if ($object->fk_validator != $object->oldcopy->fk_validator) {
  265. $verif = $object->update($user);
  266. if ($verif <= 0) {
  267. setEventMessages($object->error, $object->errors, 'warnings');
  268. $action = 'editvalidator';
  269. } else {
  270. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  271. exit;
  272. }
  273. }
  274. $action = '';
  275. }
  276. if ($action == 'update' && !GETPOSTISSET('savevalidator')) {
  277. $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'));
  278. $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'));
  279. $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1);
  280. $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
  281. $starthalfday = GETPOST('starthalfday');
  282. $endhalfday = GETPOST('endhalfday');
  283. $halfday = 0;
  284. if ($starthalfday == 'afternoon' && $endhalfday == 'morning') {
  285. $halfday = 2;
  286. } elseif ($starthalfday == 'afternoon') {
  287. $halfday = -1;
  288. } elseif ($endhalfday == 'morning') {
  289. $halfday = 1;
  290. }
  291. // If no right to modify a request
  292. if (!$cancreateall) {
  293. if ($cancreate) {
  294. if (!in_array($fuserid, $childids)) {
  295. setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
  296. header('Location: '.$_SERVER["PHP_SELF"].'?action=create');
  297. exit;
  298. }
  299. } else {
  300. setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
  301. header('Location: '.$_SERVER["PHP_SELF"].'?action=create');
  302. exit;
  303. }
  304. }
  305. $object->fetch($id);
  306. // If under validation
  307. if ($object->statut == Holiday::STATUS_DRAFT) {
  308. // If this is the requestor or has read/write rights
  309. if ($cancreate) {
  310. $approverid = GETPOST('valideur', 'int');
  311. // TODO Check this approver user id has the permission for approval
  312. $description = trim(GETPOST('description', 'restricthtml'));
  313. // If no end date
  314. if (!GETPOST('date_fin_')) {
  315. setEventMessages($langs->trans('NoDateFin'), null, 'warnings');
  316. $error++;
  317. $action = 'edit';
  318. }
  319. // If start date after end date
  320. if ($date_debut > $date_fin) {
  321. setEventMessages($langs->trans('ErrorEndDateCP'), null, 'warnings');
  322. $error++;
  323. $action = 'edit';
  324. }
  325. // If no validator designated
  326. if ($approverid < 1) {
  327. setEventMessages($langs->trans('InvalidValidatorCP'), null, 'warnings');
  328. $error++;
  329. $action = 'edit';
  330. }
  331. // If there is no Business Days within request
  332. $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
  333. if ($nbopenedday < 0.5) {
  334. setEventMessages($langs->trans('ErrorDureeCP'), null, 'warnings');
  335. $error++;
  336. $action = 'edit';
  337. }
  338. $db->begin();
  339. if (!$error) {
  340. $object->description = $description;
  341. $object->date_debut = $date_debut;
  342. $object->date_fin = $date_fin;
  343. $object->fk_validator = $approverid;
  344. $object->halfday = $halfday;
  345. // Update
  346. $verif = $object->update($user);
  347. if ($verif <= 0) {
  348. setEventMessages($object->error, $object->errors, 'warnings');
  349. $error++;
  350. $action = 'edit';
  351. }
  352. }
  353. if (!$error) {
  354. $db->commit();
  355. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  356. exit;
  357. } else {
  358. $db->rollback();
  359. }
  360. } else {
  361. setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
  362. $action = '';
  363. }
  364. } else {
  365. setEventMessages($langs->trans("ErrorBadStatus"), null, 'errors');
  366. $action = '';
  367. }
  368. }
  369. // If delete of request
  370. if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $candelete) {
  371. $error = 0;
  372. $db->begin();
  373. $object->fetch($id);
  374. // If this is a rough draft, approved, canceled or refused
  375. if ($object->statut == Holiday::STATUS_DRAFT || $object->statut == Holiday::STATUS_CANCELED || $object->statut == Holiday::STATUS_REFUSED) {
  376. $result = $object->delete($user);
  377. } else {
  378. $error++;
  379. setEventMessages($langs->trans('BadStatusOfObject'), null, 'errors');
  380. $action = '';
  381. }
  382. if (!$error) {
  383. $db->commit();
  384. header('Location: list.php?restore_lastsearch_values=1');
  385. exit;
  386. } else {
  387. $db->rollback();
  388. }
  389. }
  390. // Action validate (+ send email for approval to the expected approver)
  391. if ($action == 'confirm_send') {
  392. $object->fetch($id);
  393. // If draft and owner of leave
  394. if ($object->statut == Holiday::STATUS_DRAFT && $cancreate) {
  395. $object->oldcopy = dol_clone($object);
  396. $object->statut = Holiday::STATUS_VALIDATED;
  397. $verif = $object->validate($user);
  398. // If no SQL error, we redirect to the request form
  399. if ($verif > 0) {
  400. // To
  401. $destinataire = new User($db);
  402. $destinataire->fetch($object->fk_validator);
  403. $emailTo = $destinataire->email;
  404. if (!$emailTo) {
  405. dol_syslog("Expected validator 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_user);
  412. //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
  413. $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
  414. // Subject
  415. $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
  416. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  417. $societeName = $conf->global->MAIN_APPLICATION_TITLE;
  418. }
  419. $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysToValidate");
  420. // Content
  421. $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
  422. $message .= "<p>".$langs->transnoentities("HolidaysToValidateBody")."</p>\n";
  423. // option to warn the validator in case of too short delay
  424. if (empty($conf->global->HOLIDAY_HIDE_APPROVER_ABOUT_TOO_LOW_DELAY)) {
  425. $delayForRequest = 0; // TODO Set delay depending of holiday leave type
  426. if ($delayForRequest) {
  427. $nowplusdelay = dol_time_plus_duree($now, $delayForRequest, 'd');
  428. if ($object->date_debut < $nowplusdelay) {
  429. $message = "<p>".$langs->transnoentities("HolidaysToValidateDelay", $delayForRequest)."</p>\n";
  430. }
  431. }
  432. }
  433. // option to notify the validator if the balance is less than the request
  434. if (empty($conf->global->HOLIDAY_HIDE_APPROVER_ABOUT_NEGATIVE_BALANCE)) {
  435. $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
  436. if ($nbopenedday > $object->getCPforUser($object->fk_user, $object->fk_type)) {
  437. $message .= "<p>".$langs->transnoentities("HolidaysToValidateAlertSolde")."</p>\n";
  438. }
  439. }
  440. $link = dol_buildpath("/holiday/card.php", 3) . '?id='.$object->id;
  441. $message .= "<ul>";
  442. $message .= "<li>".$langs->transnoentitiesnoconv("Name")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
  443. $message .= "<li>".$langs->transnoentitiesnoconv("Period")." : ".dol_print_date($object->date_debut, 'day')." ".$langs->transnoentitiesnoconv("To")." ".dol_print_date($object->date_fin, 'day')."</li>\n";
  444. $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
  445. $message .= "</ul>\n";
  446. $trackid = 'leav'.$object->id;
  447. $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid);
  448. // Sending the email
  449. $result = $mail->sendfile();
  450. if (!$result) {
  451. setEventMessages($mail->error, $mail->errors, 'warnings');
  452. $action = '';
  453. } else {
  454. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  455. exit;
  456. }
  457. } else {
  458. setEventMessages($object->error, $object->errors, 'errors');
  459. $action = '';
  460. }
  461. }
  462. }
  463. if ($action == 'update_extras') {
  464. $object->oldcopy = dol_clone($object);
  465. // Fill array 'array_options' with data from update form
  466. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  467. if ($ret < 0) {
  468. $error++;
  469. }
  470. if (!$error) {
  471. // Actions on extra fields
  472. $result = $object->insertExtraFields('HOLIDAY_MODIFY');
  473. if ($result < 0) {
  474. setEventMessages($object->error, $object->errors, 'errors');
  475. $error++;
  476. }
  477. }
  478. if ($error) {
  479. $action = 'edit_extras';
  480. }
  481. }
  482. // Approve leave request
  483. if ($action == 'confirm_valid') {
  484. $object->fetch($id);
  485. // If status is waiting approval and approver is also user
  486. if ($object->statut == Holiday::STATUS_VALIDATED && $user->id == $object->fk_validator) {
  487. $object->oldcopy = dol_clone($object);
  488. $object->date_approval = dol_now();
  489. $object->fk_user_approve = $user->id;
  490. $object->statut = Holiday::STATUS_APPROVED;
  491. $object->status = Holiday::STATUS_APPROVED;
  492. $db->begin();
  493. $verif = $object->approve($user);
  494. if ($verif <= 0) {
  495. setEventMessages($object->error, $object->errors, 'errors');
  496. $error++;
  497. }
  498. // If no SQL error, we redirect to the request form
  499. if (!$error) {
  500. // Calculcate number of days consumed
  501. $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
  502. $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
  503. $newSolde = ($soldeActuel - $nbopenedday);
  504. $label = $langs->transnoentitiesnoconv("Holidays").' - '.$object->ref;
  505. // The modification is added to the LOG
  506. $result = $object->addLogCP($user->id, $object->fk_user, $label, $newSolde, $object->fk_type);
  507. if ($result < 0) {
  508. $error++;
  509. setEventMessages(null, $object->errors, 'errors');
  510. }
  511. // Update balance
  512. $result = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
  513. if ($result < 0) {
  514. $error++;
  515. setEventMessages(null, $object->errors, 'errors');
  516. }
  517. }
  518. if (!$error) {
  519. // To
  520. $destinataire = new User($db);
  521. $destinataire->fetch($object->fk_user);
  522. $emailTo = $destinataire->email;
  523. if (!$emailTo) {
  524. dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
  525. } else {
  526. // From
  527. $expediteur = new User($db);
  528. $expediteur->fetch($object->fk_validator);
  529. //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
  530. $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
  531. // Subject
  532. $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
  533. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  534. $societeName = $conf->global->MAIN_APPLICATION_TITLE;
  535. }
  536. $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysValidated");
  537. // Content
  538. $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
  539. $message .= "<p>".$langs->transnoentities("HolidaysValidatedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."</p>\n";
  540. $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
  541. $message .= "<ul>\n";
  542. $message .= "<li>".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
  543. $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
  544. $message .= "</ul>\n";
  545. $trackid = 'leav'.$object->id;
  546. $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid);
  547. // Sending email
  548. $result = $mail->sendfile();
  549. if (!$result) {
  550. setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
  551. $action = '';
  552. }
  553. }
  554. }
  555. if (!$error) {
  556. $db->commit();
  557. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  558. exit;
  559. } else {
  560. $db->rollback();
  561. $action = '';
  562. }
  563. }
  564. }
  565. if ($action == 'confirm_refuse' && GETPOST('confirm', 'alpha') == 'yes') {
  566. if (GETPOST('detail_refuse')) {
  567. $object->fetch($id);
  568. // If status pending validation and validator = user
  569. if ($object->statut == Holiday::STATUS_VALIDATED && $user->id == $object->fk_validator) {
  570. $object->date_refuse = dol_now();
  571. $object->fk_user_refuse = $user->id;
  572. $object->statut = Holiday::STATUS_REFUSED;
  573. $object->status = Holiday::STATUS_REFUSED;
  574. $object->detail_refuse = GETPOST('detail_refuse', 'alphanohtml');
  575. $db->begin();
  576. $verif = $object->update($user);
  577. if ($verif <= 0) {
  578. $error++;
  579. setEventMessages($object->error, $object->errors, 'errors');
  580. }
  581. // If no SQL error, we redirect to the request form
  582. if (!$error) {
  583. // To
  584. $destinataire = new User($db);
  585. $destinataire->fetch($object->fk_user);
  586. $emailTo = $destinataire->email;
  587. if (!$emailTo) {
  588. dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
  589. } else {
  590. // From
  591. $expediteur = new User($db);
  592. $expediteur->fetch($object->fk_validator);
  593. //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
  594. $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
  595. // Subject
  596. $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
  597. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  598. $societeName = $conf->global->MAIN_APPLICATION_TITLE;
  599. }
  600. $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysRefused");
  601. // Content
  602. $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
  603. $message .= "<p>".$langs->transnoentities("HolidaysRefusedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."<p>\n";
  604. $message .= "<p>".GETPOST('detail_refuse', 'alpha')."</p>";
  605. $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
  606. $message .= "<ul>\n";
  607. $message .= "<li>".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
  608. $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
  609. $message .= "</ul>";
  610. $trackid = 'leav'.$object->id;
  611. $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid);
  612. // sending email
  613. $result = $mail->sendfile();
  614. if (!$result) {
  615. setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
  616. $action = '';
  617. }
  618. }
  619. } else {
  620. $action = '';
  621. }
  622. if (!$error) {
  623. $db->commit();
  624. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  625. exit;
  626. } else {
  627. $db->rollback();
  628. $action = '';
  629. }
  630. }
  631. } else {
  632. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DetailRefusCP")), null, 'errors');
  633. $action = 'refuse';
  634. }
  635. }
  636. // If the request is validated
  637. if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes') {
  638. $error = 0;
  639. $object->fetch($id);
  640. $oldstatus = $object->statut;
  641. $object->statut = Holiday::STATUS_DRAFT;
  642. $object->status = Holiday::STATUS_DRAFT;
  643. $result = $object->update($user);
  644. if ($result < 0) {
  645. $error++;
  646. setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors');
  647. }
  648. if (!$error) {
  649. $db->commit();
  650. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  651. exit;
  652. } else {
  653. $db->rollback();
  654. }
  655. }
  656. // If confirmation of cancellation
  657. if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') {
  658. $error = 0;
  659. $object->fetch($id);
  660. // If status pending validation and validator = validator or user, or rights to do for others
  661. if (($object->statut == Holiday::STATUS_VALIDATED || $object->statut == Holiday::STATUS_APPROVED) &&
  662. (!empty($user->admin) || $user->id == $object->fk_validator || $cancreate || $cancreateall)) {
  663. $db->begin();
  664. $oldstatus = $object->statut;
  665. $object->date_cancel = dol_now();
  666. $object->fk_user_cancel = $user->id;
  667. $object->statut = Holiday::STATUS_CANCELED;
  668. $object->status = Holiday::STATUS_CANCELED;
  669. $result = $object->update($user);
  670. if ($result >= 0 && $oldstatus == Holiday::STATUS_APPROVED) { // holiday was already validated, status 3, so we must increase back the balance
  671. // Call trigger
  672. $result = $object->call_trigger('HOLIDAY_CANCEL', $user);
  673. if ($result < 0) {
  674. $error++;
  675. }
  676. // Calculcate number of days consumed
  677. $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
  678. $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
  679. $newSolde = ($soldeActuel + $nbopenedday);
  680. // The modification is added to the LOG
  681. $result1 = $object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde, $object->fk_type);
  682. // Update of the balance
  683. $result2 = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
  684. if ($result1 < 0 || $result2 < 0) {
  685. $error++;
  686. setEventMessages($langs->trans('ErrorCantDeleteCP').' '.$object->error, $object->errors, 'errors');
  687. }
  688. }
  689. if (!$error) {
  690. $db->commit();
  691. } else {
  692. $db->rollback();
  693. }
  694. // If no SQL error, we redirect to the request form
  695. if (!$error && $result > 0) {
  696. // To
  697. $destinataire = new User($db);
  698. $destinataire->fetch($object->fk_user);
  699. $emailTo = $destinataire->email;
  700. if (!$emailTo) {
  701. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  702. exit;
  703. }
  704. // From
  705. $expediteur = new User($db);
  706. $expediteur->fetch($object->fk_user_cancel);
  707. //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
  708. $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
  709. // Subject
  710. $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
  711. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  712. $societeName = $conf->global->MAIN_APPLICATION_TITLE;
  713. }
  714. $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysCanceled");
  715. // Content
  716. $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
  717. $message .= "<p>".$langs->transnoentities("HolidaysCanceledBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."</p>\n";
  718. $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
  719. $message .= "<ul>\n";
  720. $message .= "<li>".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
  721. $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
  722. $message .= "</ul>\n";
  723. $trackid = 'leav'.$object->id;
  724. $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid);
  725. // sending email
  726. $result = $mail->sendfile();
  727. if (!$result) {
  728. setEventMessages($mail->error, $mail->errors, 'warnings');
  729. $action = '';
  730. } else {
  731. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  732. exit;
  733. }
  734. }
  735. }
  736. }
  737. /*
  738. // Actions when printing a doc from card
  739. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  740. // Actions to send emails
  741. $triggersendname = 'HOLIDAY_SENTBYMAIL';
  742. $autocopy='MAIN_MAIL_AUTOCOPY_HOLIDAY_TO';
  743. $trackid='leav'.$object->id;
  744. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  745. // Actions to build doc
  746. $upload_dir = $conf->holiday->dir_output;
  747. $permissiontoadd = $user->rights->holiday->creer;
  748. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  749. */
  750. }
  751. /*
  752. * View
  753. */
  754. $form = new Form($db);
  755. $object = new Holiday($db);
  756. $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
  757. $title = $langs->trans('Leave');
  758. $help_url = 'EN:Module_Holiday';
  759. llxHeader('', $title, $help_url);
  760. $edit = false;
  761. if ((empty($id) && empty($ref)) || $action == 'create' || $action == 'add') {
  762. // If user has no permission to create a leave
  763. if ((in_array($fuserid, $childids) && empty($user->rights->holiday->write)) || (!in_array($fuserid, $childids) && ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->holiday->writeall_advance) || empty($user->rights->holiday->writeall))))) {
  764. $errors[] = $langs->trans('CantCreateCP');
  765. } else {
  766. // Form to add a leave request
  767. print load_fiche_titre($langs->trans('MenuAddCP'), '', 'title_hrm.png');
  768. // Error management
  769. if (GETPOST('error')) {
  770. switch (GETPOST('error')) {
  771. case 'datefin':
  772. $errors[] = $langs->trans('ErrorEndDateCP');
  773. break;
  774. case 'SQL_Create':
  775. $errors[] = $langs->trans('ErrorSQLCreateCP');
  776. break;
  777. case 'CantCreate':
  778. $errors[] = $langs->trans('CantCreateCP');
  779. break;
  780. case 'Valideur':
  781. $errors[] = $langs->trans('InvalidValidatorCP');
  782. break;
  783. case 'nodatedebut':
  784. $errors[] = $langs->trans('NoDateDebut');
  785. break;
  786. case 'nodatefin':
  787. $errors[] = $langs->trans('NoDateFin');
  788. break;
  789. case 'DureeHoliday':
  790. $errors[] = $langs->trans('ErrorDureeCP');
  791. break;
  792. case 'alreadyCP':
  793. $errors[] = $langs->trans('alreadyCPexist');
  794. break;
  795. }
  796. setEventMessages($errors, null, 'errors');
  797. }
  798. print '<script type="text/javascript">
  799. $( document ).ready(function() {
  800. $("input.button-save").click("submit", function(e) {
  801. console.log("Call valider()");
  802. if (document.demandeCP.date_debut_.value != "")
  803. {
  804. if(document.demandeCP.date_fin_.value != "")
  805. {
  806. if(document.demandeCP.valideur.value != "-1") {
  807. return true;
  808. }
  809. else {
  810. alert("'.dol_escape_js($langs->transnoentities('InvalidValidatorCP')).'");
  811. return false;
  812. }
  813. }
  814. else
  815. {
  816. alert("'.dol_escape_js($langs->transnoentities('NoDateFin')).'");
  817. return false;
  818. }
  819. }
  820. else
  821. {
  822. alert("'.dol_escape_js($langs->transnoentities('NoDateDebut')).'");
  823. return false;
  824. }
  825. });
  826. });
  827. </script>'."\n";
  828. // Formulaire de demande
  829. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="demandeCP">'."\n";
  830. print '<input type="hidden" name="token" value="'.newToken().'" />'."\n";
  831. print '<input type="hidden" name="action" value="add" />'."\n";
  832. print dol_get_fiche_head();
  833. //print '<span>'.$langs->trans('DelayToRequestCP',$object->getConfCP('delayForRequest')).'</span><br><br>';
  834. print '<table class="border centpercent">';
  835. print '<tbody>';
  836. // User for leave request
  837. print '<tr>';
  838. print '<td class="titlefield fieldrequired tdtop">'.$langs->trans("User").'</td>';
  839. print '<td><div class="inline-block">';
  840. if ($cancreate && !$cancreateall) {
  841. print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(($fuserid ? $fuserid : $user->id), 'fuserid', 0, '', 0, 'hierarchyme', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'minwidth200 maxwidth500 inline-block');
  842. //print '<input type="hidden" name="fuserid" value="'.($fuserid?$fuserid:$user->id).'">';
  843. } else {
  844. print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($fuserid ? $fuserid : $user->id, 'fuserid', 0, '', 0, '', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'minwidth200 maxwidth500 inline-block');
  845. }
  846. print '</div>';
  847. if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) {
  848. print '<div class="leaveuserbalance paddingtop inline-block floatright badge badge-status0 badge-status margintoponsmartphone">';
  849. $out = '';
  850. $nb_holiday = 0;
  851. $typeleaves = $object->getTypes(1, 1);
  852. foreach ($typeleaves as $key => $val) {
  853. $nb_type = $object->getCPforUser(($fuserid ? $fuserid : $user->id), $val['rowid']);
  854. $nb_holiday += $nb_type;
  855. $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': <strong>'.($nb_type ? price2num($nb_type) : 0).'</strong><br>';
  856. //$out .= ' - '.$val['label'].': <strong>'.($nb_type ?price2num($nb_type) : 0).'</strong><br>';
  857. }
  858. print ' &nbsp; &nbsp; ';
  859. $htmltooltip = $langs->trans("Detail").'<br>';
  860. $htmltooltip .= $out;
  861. print $form->textwithtooltip($langs->trans('SoldeCPUser', round($nb_holiday, 5)).' '.img_picto('', 'help'), $htmltooltip);
  862. print '</div>';
  863. if (!empty($conf->use_javascript_ajax)) {
  864. print '<script>';
  865. print '$( document ).ready(function() {
  866. jQuery("#fuserid").change(function() {
  867. console.log("We change to user id "+jQuery("#fuserid").val());
  868. if (jQuery("#fuserid").val() == '.((int) $user->id).') {
  869. jQuery(".leaveuserbalance").show();
  870. } else {
  871. jQuery(".leaveuserbalance").hide();
  872. }
  873. });
  874. });';
  875. print '</script>';
  876. }
  877. } elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) {
  878. print '<div class="leaveuserbalance paddingtop">';
  879. print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE);
  880. print '</div>';
  881. }
  882. print '</td>';
  883. print '</tr>';
  884. // Type
  885. print '<tr>';
  886. print '<td class="fieldrequired">'.$langs->trans("Type").'</td>';
  887. print '<td>';
  888. $typeleaves = $object->getTypes(1, -1);
  889. $arraytypeleaves = array();
  890. foreach ($typeleaves as $key => $val) {
  891. $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
  892. $labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')' : '');
  893. $arraytypeleaves[$val['rowid']] = $labeltoshow;
  894. }
  895. print $form->selectarray('type', $arraytypeleaves, (GETPOST('type', 'alpha') ?GETPOST('type', 'alpha') : ''), 1, 0, 0, '', 0, 0, 0, '', '', true);
  896. if ($user->admin) {
  897. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  898. }
  899. print '</td>';
  900. print '</tr>';
  901. // Date start
  902. print '<tr>';
  903. print '<td class="fieldrequired">';
  904. print $form->textwithpicto($langs->trans("DateDebCP"), $langs->trans("FirstDayOfHoliday"));
  905. print '</td>';
  906. print '<td>'.img_picto('', 'action', 'class="pictofixedwidth"');
  907. if (!GETPOST('date_debut_')) { // If visitor does not come from agenda
  908. print $form->selectDate(-1, 'date_debut_', 0, 0, 0, '', 1, 1);
  909. } else {
  910. $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_debut_month', 'int'), GETPOST('date_debut_day', 'int'), GETPOST('date_debut_year', 'int'));
  911. print $form->selectDate($tmpdate, 'date_debut_', 0, 0, 0, '', 1, 1);
  912. }
  913. print ' &nbsp; &nbsp; ';
  914. print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday', 'alpha') ?GETPOST('starthalfday', 'alpha') : 'morning'));
  915. print '</td>';
  916. print '</tr>';
  917. // Date end
  918. print '<tr>';
  919. print '<td class="fieldrequired">';
  920. print $form->textwithpicto($langs->trans("DateFinCP"), $langs->trans("LastDayOfHoliday"));
  921. print '</td>';
  922. print '<td>'.img_picto('', 'action', 'class="pictofixedwidth"');
  923. if (!GETPOST('date_fin_')) {
  924. print $form->selectDate(-1, 'date_fin_', 0, 0, 0, '', 1, 1);
  925. } else {
  926. $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_fin_month', 'int'), GETPOST('date_fin_day', 'int'), GETPOST('date_fin_year', 'int'));
  927. print $form->selectDate($tmpdate, 'date_fin_', 0, 0, 0, '', 1, 1);
  928. }
  929. print ' &nbsp; &nbsp; ';
  930. print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday', 'alpha') ?GETPOST('endhalfday', 'alpha') : 'afternoon'));
  931. print '</td>';
  932. print '</tr>';
  933. // Approver
  934. print '<tr>';
  935. print '<td class="fieldrequired">'.$langs->trans("ReviewedByCP").'</td>';
  936. print '<td>';
  937. $object = new Holiday($db);
  938. $include_users = $object->fetch_users_approver_holiday();
  939. if (empty($include_users)) {
  940. print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
  941. } else {
  942. // Defined default approver (the forced approved of user or the supervisor if no forced value defined)
  943. // Note: This use will be set only if the deinfed approvr has permission to approve so is inside include_users
  944. $defaultselectuser = (empty($user->fk_user_holiday_validator) ? $user->fk_user : $user->fk_user_holiday_validator);
  945. if (!empty($conf->global->HOLIDAY_DEFAULT_VALIDATOR)) {
  946. $defaultselectuser = $conf->global->HOLIDAY_DEFAULT_VALIDATOR; // Can force default approver
  947. }
  948. if (GETPOST('valideur', 'int') > 0) {
  949. $defaultselectuser = GETPOST('valideur', 'int');
  950. }
  951. $s = $form->select_dolusers($defaultselectuser, "valideur", 1, '', 0, $include_users, '', '0,'.$conf->entity, 0, 0, '', 0, '', 'minwidth200 maxwidth500');
  952. print img_picto('', 'user', 'class="pictofixedwidth"').$form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
  953. }
  954. //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
  955. print '</td>';
  956. print '</tr>';
  957. // Description
  958. print '<tr>';
  959. print '<td>'.$langs->trans("DescCP").'</td>';
  960. print '<td class="tdtop">';
  961. $doleditor = new DolEditor('description', GETPOST('description', 'restricthtml'), '', 80, 'dolibarr_notes', 'In', 0, false, isModEnabled('fckeditor'), ROWS_3, '90%');
  962. print $doleditor->Create(1);
  963. print '</td></tr>';
  964. // Other attributes
  965. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  966. print '</tbody>';
  967. print '</table>';
  968. print dol_get_fiche_end();
  969. print $form->buttonsSaveCancel("SendRequestCP");
  970. print '</from>'."\n";
  971. }
  972. } else {
  973. if ($error && $action != 'edit') {
  974. print '<div class="tabBar">';
  975. print $error;
  976. print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
  977. print '</div>';
  978. } else {
  979. // Show page in view or edit mode
  980. if (($id > 0) || $ref) {
  981. $result = $object->fetch($id, $ref);
  982. $approverexpected = new User($db);
  983. $approverexpected->fetch($object->fk_validator); // Use that should be the approver
  984. $userRequest = new User($db);
  985. $userRequest->fetch($object->fk_user);
  986. //print load_fiche_titre($langs->trans('TitreRequestCP'));
  987. // Si il y a une erreur
  988. if (GETPOST('error')) {
  989. switch (GETPOST('error')) {
  990. case 'datefin':
  991. $errors[] = $langs->transnoentitiesnoconv('ErrorEndDateCP');
  992. break;
  993. case 'SQL_Create':
  994. $errors[] = $langs->transnoentitiesnoconv('ErrorSQLCreateCP');
  995. break;
  996. case 'CantCreate':
  997. $errors[] = $langs->transnoentitiesnoconv('CantCreateCP');
  998. break;
  999. case 'Valideur':
  1000. $errors[] = $langs->transnoentitiesnoconv('InvalidValidatorCP');
  1001. break;
  1002. case 'nodatedebut':
  1003. $errors[] = $langs->transnoentitiesnoconv('NoDateDebut');
  1004. break;
  1005. case 'nodatefin':
  1006. $errors[] = $langs->transnoentitiesnoconv('NoDateFin');
  1007. break;
  1008. case 'DureeHoliday':
  1009. $errors[] = $langs->transnoentitiesnoconv('ErrorDureeCP');
  1010. break;
  1011. case 'NoMotifRefuse':
  1012. $errors[] = $langs->transnoentitiesnoconv('NoMotifRefuseCP');
  1013. break;
  1014. case 'mail':
  1015. $errors[] = $langs->transnoentitiesnoconv('ErrorMailNotSend');
  1016. break;
  1017. }
  1018. setEventMessages($errors, null, 'errors');
  1019. }
  1020. // check if the user has the right to read this request
  1021. if ($canread) {
  1022. $head = holiday_prepare_head($object);
  1023. if (($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) {
  1024. if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) {
  1025. $edit = true;
  1026. }
  1027. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'."\n";
  1028. print '<input type="hidden" name="token" value="'.newToken().'" />'."\n";
  1029. print '<input type="hidden" name="action" value="update"/>'."\n";
  1030. print '<input type="hidden" name="id" value="'.$object->id.'" />'."\n";
  1031. }
  1032. print dol_get_fiche_head($head, 'card', $langs->trans("CPTitreMenu"), -1, 'holiday');
  1033. $linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1034. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
  1035. print '<div class="fichecenter">';
  1036. print '<div class="fichehalfleft">';
  1037. print '<div class="underbanner clearboth"></div>';
  1038. print '<table class="border tableforfield centpercent">';
  1039. print '<tbody>';
  1040. // User
  1041. print '<tr>';
  1042. print '<td class="titlefield">'.$langs->trans("User").'</td>';
  1043. print '<td>';
  1044. print $userRequest->getNomUrl(-1, 'leave');
  1045. print '</td></tr>';
  1046. // Type
  1047. print '<tr>';
  1048. print '<td>'.$langs->trans("Type").'</td>';
  1049. print '<td>';
  1050. $typeleaves = $object->getTypes(1, -1);
  1051. $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']);
  1052. print empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow;
  1053. print '</td>';
  1054. print '</tr>';
  1055. $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
  1056. $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
  1057. if (!$edit) {
  1058. print '<tr>';
  1059. print '<td class="nowrap">';
  1060. print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
  1061. print '</td>';
  1062. print '<td>'.dol_print_date($object->date_debut, 'day');
  1063. print ' &nbsp; &nbsp; ';
  1064. print '<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
  1065. print '</td>';
  1066. print '</tr>';
  1067. } else {
  1068. print '<tr>';
  1069. print '<td class="nowrap">';
  1070. print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
  1071. print '</td>';
  1072. print '<td>';
  1073. $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_debut_month', 'int'), GETPOST('date_debut_day', 'int'), GETPOST('date_debut_year', 'int'));
  1074. print $form->selectDate($tmpdate ? $tmpdate : $object->date_debut, 'date_debut_');
  1075. print ' &nbsp; &nbsp; ';
  1076. print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday') ?GETPOST('starthalfday') : $starthalfday));
  1077. print '</td>';
  1078. print '</tr>';
  1079. }
  1080. if (!$edit) {
  1081. print '<tr>';
  1082. print '<td class="nowrap">';
  1083. print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
  1084. print '</td>';
  1085. print '<td>'.dol_print_date($object->date_fin, 'day');
  1086. print ' &nbsp; &nbsp; ';
  1087. print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
  1088. print '</td>';
  1089. print '</tr>';
  1090. } else {
  1091. print '<tr>';
  1092. print '<td class="nowrap">';
  1093. print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
  1094. print '</td>';
  1095. print '<td>';
  1096. print $form->selectDate($object->date_fin, 'date_fin_');
  1097. print ' &nbsp; &nbsp; ';
  1098. print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ?GETPOST('endhalfday') : $endhalfday));
  1099. print '</td>';
  1100. print '</tr>';
  1101. }
  1102. // Nb of days
  1103. print '<tr>';
  1104. print '<td>';
  1105. $htmlhelp = $langs->trans('NbUseDaysCPHelp');
  1106. $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
  1107. $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
  1108. if ($includesaturday) {
  1109. $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
  1110. }
  1111. if ($includesunday) {
  1112. $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
  1113. }
  1114. print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
  1115. print '</td>';
  1116. print '<td>';
  1117. print num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
  1118. print '</td>';
  1119. print '</tr>';
  1120. if ($object->statut == Holiday::STATUS_REFUSED) {
  1121. print '<tr>';
  1122. print '<td>'.$langs->trans('DetailRefusCP').'</td>';
  1123. print '<td>'.$object->detail_refuse.'</td>';
  1124. print '</tr>';
  1125. }
  1126. // Description
  1127. if (!$edit) {
  1128. print '<tr>';
  1129. print '<td>'.$langs->trans('DescCP').'</td>';
  1130. print '<td>'.nl2br($object->description).'</td>';
  1131. print '</tr>';
  1132. } else {
  1133. print '<tr>';
  1134. print '<td>'.$langs->trans('DescCP').'</td>';
  1135. print '<td class="tdtop">';
  1136. $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_notes', 'In', 0, false, isModEnabled('fckeditor'), ROWS_3, '90%');
  1137. print $doleditor->Create(1);
  1138. print '</td></tr>';
  1139. }
  1140. // Other attributes
  1141. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1142. print '</tbody>';
  1143. print '</table>'."\n";
  1144. print '</div>';
  1145. print '<div class="fichehalfright">';
  1146. print '<div class="underbanner clearboth"></div>';
  1147. // Info workflow
  1148. print '<table class="border tableforfield centpercent">'."\n";
  1149. print '<tbody>';
  1150. if (!empty($object->fk_user_create)) {
  1151. $userCreate = new User($db);
  1152. $userCreate->fetch($object->fk_user_create);
  1153. print '<tr>';
  1154. print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
  1155. print '<td>'.$userCreate->getNomUrl(-1).'</td>';
  1156. print '</tr>';
  1157. }
  1158. // Approver
  1159. if (!$edit && $action != 'editvalidator') {
  1160. print '<tr>';
  1161. print '<td class="titlefield">';
  1162. if ($object->statut == Holiday::STATUS_APPROVED || $object->statut == Holiday::STATUS_CANCELED) {
  1163. print $langs->trans('ApprovedBy');
  1164. } else {
  1165. print $langs->trans('ReviewedByCP');
  1166. }
  1167. print '</td>';
  1168. print '<td>';
  1169. if ($object->statut == Holiday::STATUS_APPROVED || $object->statut == Holiday::STATUS_CANCELED) {
  1170. if ($object->fk_user_approve > 0) {
  1171. $approverdone = new User($db);
  1172. $approverdone->fetch($object->fk_user_approve);
  1173. print $approverdone->getNomUrl(-1);
  1174. }
  1175. } else {
  1176. print $approverexpected->getNomUrl(-1);
  1177. }
  1178. $include_users = $object->fetch_users_approver_holiday();
  1179. if (is_array($include_users) && in_array($user->id, $include_users) && $object->statut == Holiday::STATUS_VALIDATED) {
  1180. print '<a class="editfielda paddingleft" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editvalidator">'.img_edit($langs->trans("Edit")).'</a>';
  1181. }
  1182. print '</td>';
  1183. print '</tr>';
  1184. } else {
  1185. print '<tr>';
  1186. print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>'; // Will be approved by
  1187. print '<td>';
  1188. $include_users = $object->fetch_users_approver_holiday();
  1189. if (!in_array($object->fk_validator, $include_users)) { // Add the current validator to the list to not lose it when editing.
  1190. $include_users[] = $object->fk_validator;
  1191. }
  1192. if (empty($include_users)) {
  1193. print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
  1194. } else {
  1195. $arrayofvalidatorstoexclude = (($user->admin || ($user->id != $userRequest->id)) ? '' : array($user->id)); // Nobody if we are admin or if we are not the user of the leave.
  1196. $s = $form->select_dolusers($object->fk_validator, "valideur", (($action == 'editvalidator') ? 0 : 1), $arrayofvalidatorstoexclude, 0, $include_users);
  1197. print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
  1198. }
  1199. if ($action == 'editvalidator') {
  1200. print '<input type="submit" class="button button-save" name="savevalidator" value="'.$langs->trans("Save").'">';
  1201. print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1202. }
  1203. print '</td>';
  1204. print '</tr>';
  1205. }
  1206. print '<tr>';
  1207. print '<td>'.$langs->trans('DateCreation').'</td>';
  1208. print '<td>'.dol_print_date($object->date_create, 'dayhour', 'tzuser').'</td>';
  1209. print '</tr>';
  1210. if ($object->statut == Holiday::STATUS_APPROVED || $object->statut == Holiday::STATUS_CANCELED) {
  1211. print '<tr>';
  1212. print '<td>'.$langs->trans('DateValidCP').'</td>';
  1213. print '<td>'.dol_print_date($object->date_approval, 'dayhour', 'tzuser').'</td>'; // warning: date_valid is approval date on holiday module
  1214. print '</tr>';
  1215. }
  1216. if ($object->statut == Holiday::STATUS_CANCELED) {
  1217. print '<tr>';
  1218. print '<td>'.$langs->trans('DateCancelCP').'</td>';
  1219. print '<td>'.dol_print_date($object->date_cancel, 'dayhour', 'tzuser').'</td>';
  1220. print '</tr>';
  1221. }
  1222. if ($object->statut == Holiday::STATUS_REFUSED) {
  1223. print '<tr>';
  1224. print '<td>'.$langs->trans('DateRefusCP').'</td>';
  1225. print '<td>'.dol_print_date($object->date_refuse, 'dayhour', 'tzuser').'</td>';
  1226. print '</tr>';
  1227. }
  1228. print '</tbody>';
  1229. print '</table>';
  1230. print '</div>';
  1231. print '</div>';
  1232. print '<div class="clearboth"></div>';
  1233. print dol_get_fiche_end();
  1234. // Confirmation messages
  1235. if ($action == 'delete') {
  1236. if ($candelete) {
  1237. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleDeleteCP"), $langs->trans("ConfirmDeleteCP"), "confirm_delete", '', 0, 1);
  1238. }
  1239. }
  1240. // Si envoi en validation
  1241. if ($action == 'sendToValidate' && $object->statut == Holiday::STATUS_DRAFT) {
  1242. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleToValidCP"), $langs->trans("ConfirmToValidCP"), "confirm_send", '', 1, 1);
  1243. }
  1244. // Si validation de la demande
  1245. if ($action == 'valid') {
  1246. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleValidCP"), $langs->trans("ConfirmValidCP"), "confirm_valid", '', 1, 1);
  1247. }
  1248. // Si refus de la demande
  1249. if ($action == 'refuse') {
  1250. $array_input = array(array('type'=>"text", 'label'=> $langs->trans('DetailRefusCP'), 'name'=>"detail_refuse", 'size'=>"50", 'value'=>""));
  1251. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0);
  1252. }
  1253. // Si annulation de la demande
  1254. if ($action == 'cancel') {
  1255. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleCancelCP"), $langs->trans("ConfirmCancelCP"), "confirm_cancel", '', 1, 1);
  1256. }
  1257. // Si back to draft
  1258. if ($action == 'backtodraft') {
  1259. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleSetToDraft"), $langs->trans("ConfirmSetToDraft"), "confirm_draft", '', 1, 1);
  1260. }
  1261. if (($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) {
  1262. if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) {
  1263. if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) {
  1264. print $form->buttonsSaveCancel();
  1265. }
  1266. }
  1267. print '</form>';
  1268. }
  1269. if (!$edit) {
  1270. // Buttons for actions
  1271. print '<div class="tabsAction">';
  1272. if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) {
  1273. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'" class="butAction">'.$langs->trans("EditCP").'</a>';
  1274. }
  1275. if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) { // If draft
  1276. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=sendToValidate&token='.newToken().'" class="butAction">'.$langs->trans("Validate").'</a>';
  1277. }
  1278. if ($object->statut == Holiday::STATUS_VALIDATED) { // If validated
  1279. // Button Approve / Refuse
  1280. if ($user->id == $object->fk_validator) {
  1281. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken().'" class="butAction">'.$langs->trans("Approve").'</a>';
  1282. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=refuse&token='.newToken().'" class="butAction">'.$langs->trans("ActionRefuseCP").'</a>';
  1283. } else {
  1284. print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("Approve").'</a>';
  1285. print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("ActionRefuseCP").'</a>';
  1286. // Button Cancel (because we can't approve)
  1287. if ($cancreate || $cancreateall) {
  1288. if (($object->date_debut > dol_now()) || !empty($user->admin)) {
  1289. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
  1290. } else {
  1291. print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("HolidayStarted").'-'.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
  1292. }
  1293. }
  1294. }
  1295. }
  1296. if ($object->statut == Holiday::STATUS_APPROVED) { // If validated and approved
  1297. if ($user->id == $object->fk_validator || $user->id == $object->fk_user_approve || $cancreate || $cancreateall) {
  1298. if (($object->date_debut > dol_now()) || !empty($user->admin) || $user->id == $object->fk_user_approve) {
  1299. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
  1300. } else {
  1301. print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("HolidayStarted").'-'.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
  1302. }
  1303. } else { // I have no rights on the user of the holiday.
  1304. if (!empty($user->admin)) { // If current approver can't cancel an approved leave, we allow admin user
  1305. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
  1306. } else {
  1307. print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
  1308. }
  1309. }
  1310. }
  1311. if (($cancreate || $cancreateall) && $object->statut == Holiday::STATUS_CANCELED) {
  1312. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=backtodraft" class="butAction">'.$langs->trans("SetToDraft").'</a>';
  1313. }
  1314. if ($candelete && ($object->statut == Holiday::STATUS_DRAFT || $object->statut == Holiday::STATUS_CANCELED || $object->statut == Holiday::STATUS_REFUSED)) { // If draft or canceled or refused
  1315. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'" class="butActionDelete">'.$langs->trans("DeleteCP").'</a>';
  1316. }
  1317. print '</div>';
  1318. }
  1319. } else {
  1320. print '<div class="tabBar">';
  1321. print $langs->trans('ErrorUserViewCP');
  1322. print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
  1323. print '</div>';
  1324. }
  1325. } else {
  1326. print '<div class="tabBar">';
  1327. print $langs->trans('ErrorIDFicheCP');
  1328. print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
  1329. print '</div>';
  1330. }
  1331. // Select mail models is same action as presend
  1332. if (GETPOST('modelselected')) {
  1333. $action = 'presend';
  1334. }
  1335. if ($action != 'presend' && $action != 'edit') {
  1336. print '<div class="fichecenter"><div class="fichehalfleft">';
  1337. print '<a name="builddoc"></a>'; // ancre
  1338. $includedocgeneration = 0;
  1339. // Documents
  1340. if ($includedocgeneration) {
  1341. $objref = dol_sanitizeFileName($object->ref);
  1342. $relativepath = $objref.'/'.$objref.'.pdf';
  1343. $filedir = $conf->holiday->dir_output.'/'.$object->element.'/'.$objref;
  1344. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1345. $genallowed = ($user->rights->holiday->read && $object->fk_user == $user->id) || !empty($user->rights->holiday->readall); // If you can read, you can build the PDF to read content
  1346. $delallowed = ($user->rights->holiday->write && $object->fk_user == $user->id) || !empty($user->rights->holiday->writeall_advance); // If you can create/edit, you can remove a file on card
  1347. print $formfile->showdocuments('holiday:Holiday', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  1348. }
  1349. // Show links to link elements
  1350. //$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
  1351. //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  1352. print '</div><div class="fichehalfright">';
  1353. $MAXEVENT = 10;
  1354. $morehtmlright = '';
  1355. // List of actions on element
  1356. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1357. $formactions = new FormActions($db);
  1358. $somethingshown = $formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlright);
  1359. print '</div></div>';
  1360. }
  1361. }
  1362. }
  1363. // End of page
  1364. llxFooter();
  1365. if (is_object($db)) {
  1366. $db->close();
  1367. }