document.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  7. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  9. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/holiday/document.php
  26. * \ingroup fichinter
  27. * \brief Page des documents joints sur les contrats
  28. */
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  36. // Load translation files required by the page
  37. $langs->loadLangs(array('other', 'holiday', 'companies'));
  38. $id = GETPOST('id', 'int');
  39. $ref = GETPOST('ref', 'alpha');
  40. $action = GETPOST('action', 'aZ09');
  41. $confirm = GETPOST('confirm', 'alpha');
  42. // Get parameters
  43. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  44. $sortfield = GETPOST('sortfield', 'aZ09comma');
  45. $sortorder = GETPOST('sortorder', 'aZ09comma');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. if (empty($page) || $page == -1) {
  48. $page = 0;
  49. } // If $page is not defined, or '' or -1
  50. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. if (!$sortorder) {
  54. $sortorder = "ASC";
  55. }
  56. if (!$sortfield) {
  57. $sortfield = "position_name";
  58. }
  59. $childids = $user->getAllChildIds(1);
  60. $morefilter = '';
  61. if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) {
  62. $morefilter = 'AND employee = 1';
  63. }
  64. $object = new Holiday($db);
  65. $extrafields = new ExtraFields($db);
  66. // fetch optionals attributes and labels
  67. $extrafields->fetch_name_optionals_label($object->table_element);
  68. if (($id > 0) || $ref) {
  69. $object->fetch($id, $ref);
  70. // Check current user can read this leave request
  71. $canread = 0;
  72. if (!empty($user->rights->holiday->readall)) {
  73. $canread = 1;
  74. }
  75. if (!empty($user->rights->holiday->read) && in_array($object->fk_user, $childids)) {
  76. $canread = 1;
  77. }
  78. if (!$canread) {
  79. accessforbidden();
  80. }
  81. }
  82. $upload_dir = $conf->holiday->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, '');
  83. $modulepart = 'holiday';
  84. // Protection if external user
  85. if ($user->socid) {
  86. $socid = $user->socid;
  87. }
  88. $result = restrictedArea($user, 'holiday', $object->id, 'holiday');
  89. /*
  90. * Actions
  91. */
  92. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  93. /*
  94. * View
  95. */
  96. $form = new Form($db);
  97. $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
  98. $title = $langs->trans('InterventionCard');
  99. llxHeader('', $title);
  100. if ($object->id) {
  101. $valideur = new User($db);
  102. $valideur->fetch($object->fk_validator);
  103. $userRequest = new User($db);
  104. $userRequest->fetch($object->fk_user);
  105. $head = holiday_prepare_head($object);
  106. print dol_get_fiche_head($head, 'documents', $langs->trans("CPTitreMenu"), -1, 'holiday');
  107. // Build file list
  108. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  109. $totalsize = 0;
  110. foreach ($filearray as $key => $file) {
  111. $totalsize += $file['size'];
  112. }
  113. $linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  114. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
  115. print '<div class="fichecenter">';
  116. //print '<div class="fichehalfleft">';
  117. print '<div class="underbanner clearboth"></div>';
  118. print '<table class="border tableforfield centpercent">';
  119. print '<tr>';
  120. print '<td class="titlefield">'.$langs->trans("User").'</td>';
  121. print '<td>';
  122. print $userRequest->getNomUrl(-1, 'leave');
  123. print '</td></tr>';
  124. // Type
  125. print '<tr>';
  126. print '<td>'.$langs->trans("Type").'</td>';
  127. print '<td>';
  128. $typeleaves = $object->getTypes(1, -1);
  129. $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']);
  130. print empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow;
  131. print '</td>';
  132. print '</tr>';
  133. $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
  134. $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
  135. if (!$edit) {
  136. print '<tr>';
  137. print '<td>';
  138. print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
  139. print '</td>';
  140. print '<td>'.dol_print_date($object->date_debut, 'day');
  141. print ' &nbsp; &nbsp; ';
  142. print '<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
  143. print '</td>';
  144. print '</tr>';
  145. } else {
  146. print '<tr>';
  147. print '<td>';
  148. print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
  149. print '</td>';
  150. print '<td>';
  151. print $form->selectDate($object->date_debut, 'date_debut_');
  152. print ' &nbsp; &nbsp; ';
  153. print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday') ?GETPOST('starthalfday') : $starthalfday));
  154. print '</td>';
  155. print '</tr>';
  156. }
  157. if (!$edit) {
  158. print '<tr>';
  159. print '<td>';
  160. print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
  161. print '</td>';
  162. print '<td>'.dol_print_date($object->date_fin, 'day');
  163. print ' &nbsp; &nbsp; ';
  164. print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
  165. print '</td>';
  166. print '</tr>';
  167. } else {
  168. print '<tr>';
  169. print '<td>';
  170. print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
  171. print '</td>';
  172. print '<td>';
  173. print $form->selectDate($object->date_fin, 'date_fin_');
  174. print ' &nbsp; &nbsp; ';
  175. print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ?GETPOST('endhalfday') : $endhalfday));
  176. print '</td>';
  177. print '</tr>';
  178. }
  179. // Nb days consumed
  180. print '<tr>';
  181. print '<td>';
  182. $htmlhelp = $langs->trans('NbUseDaysCPHelp');
  183. $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
  184. $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
  185. if ($includesaturday) {
  186. $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
  187. }
  188. if ($includesunday) {
  189. $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
  190. }
  191. print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
  192. print '</td>';
  193. print '<td>'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).'</td>';
  194. print '</tr>';
  195. if ($object->statut == 5) {
  196. print '<tr>';
  197. print '<td>'.$langs->trans('DetailRefusCP').'</td>';
  198. print '<td>'.$object->detail_refuse.'</td>';
  199. print '</tr>';
  200. }
  201. // Description
  202. if (!$edit) {
  203. print '<tr>';
  204. print '<td>'.$langs->trans('DescCP').'</td>';
  205. print '<td>'.nl2br($object->description).'</td>';
  206. print '</tr>';
  207. } else {
  208. print '<tr>';
  209. print '<td>'.$langs->trans('DescCP').'</td>';
  210. print '<td><textarea name="description" class="flat" rows="'.ROWS_3.'" cols="70">'.$object->description.'</textarea></td>';
  211. print '</tr>';
  212. }
  213. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  214. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  215. print '</tbody>';
  216. print '</table>'."\n";
  217. /*
  218. print '</div>';
  219. print '<div class="fichehalfright">';
  220. print '<div class="ficheaddleft">';
  221. print '<div class="underbanner clearboth"></div>';
  222. // Info workflow
  223. print '<table class="border tableforfield centpercent">'."\n";
  224. print '<tbody>';
  225. if (! empty($object->fk_user_create))
  226. {
  227. $userCreate=new User($db);
  228. $userCreate->fetch($object->fk_user_create);
  229. print '<tr>';
  230. print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
  231. print '<td>'.$userCreate->getNomUrl(-1).'</td>';
  232. print '</tr>';
  233. }
  234. if (!$edit) {
  235. print '<tr>';
  236. print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
  237. print '<td>'.$valideur->getNomUrl(-1).'</td>';
  238. print '</tr>';
  239. } else {
  240. print '<tr>';
  241. print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
  242. print '<td>';
  243. print $form->select_dolusers($object->fk_user, "valideur", 1, ($user->admin ? '' : array($user->id))); // By default, hierarchical parent
  244. print '</td>';
  245. print '</tr>';
  246. }
  247. print '<tr>';
  248. print '<td>'.$langs->trans('DateCreation').'</td>';
  249. print '<td>'.dol_print_date($object->date_create,'dayhour').'</td>';
  250. print '</tr>';
  251. if ($object->statut == 3) {
  252. print '<tr>';
  253. print '<td>'.$langs->trans('DateValidCP').'</td>';
  254. print '<td>'.dol_print_date($object->date_valid,'dayhour').'</td>';
  255. print '</tr>';
  256. }
  257. if ($object->statut == 4) {
  258. print '<tr>';
  259. print '<td>'.$langs->trans('DateCancelCP').'</td>';
  260. print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td>';
  261. print '</tr>';
  262. }
  263. if ($object->statut == 5) {
  264. print '<tr>';
  265. print '<td>'.$langs->trans('DateRefusCP').'</td>';
  266. print '<td>'.dol_print_date($object->date_refuse,'dayhour').'</td>';
  267. print '</tr>';
  268. }
  269. print '</tbody>';
  270. print '</table>';
  271. print '</div>';
  272. print '</div>'; */
  273. print '</div>';
  274. print '<div class="clearboth"></div>';
  275. print dol_get_fiche_end();
  276. $modulepart = 'holiday';
  277. $permissiontoadd = $user->rights->holiday->write;
  278. $permtoedit = $user->rights->holiday->write;
  279. $param = '&id='.$object->id;
  280. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  281. } else {
  282. print $langs->trans("ErrorUnknown");
  283. }
  284. // End of page
  285. llxFooter();
  286. $db->close();