card.php 57 KB

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