card.php 60 KB

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