card.php 58 KB

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