document.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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-2022 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. $permissiontoadd = $user->rights->holiday->write; // Used by the include of actions_setnotes.inc.php
  90. /*
  91. * Actions
  92. */
  93. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  94. /*
  95. * View
  96. */
  97. $form = new Form($db);
  98. $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
  99. $title = $langs->trans("Leave").' - '.$langs->trans("Files");
  100. llxHeader('', $title);
  101. if ($object->id) {
  102. $valideur = new User($db);
  103. $valideur->fetch($object->fk_validator);
  104. $userRequest = new User($db);
  105. $userRequest->fetch($object->fk_user);
  106. $head = holiday_prepare_head($object);
  107. print dol_get_fiche_head($head, 'documents', $langs->trans("CPTitreMenu"), -1, 'holiday');
  108. // Build file list
  109. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  110. $totalsize = 0;
  111. foreach ($filearray as $key => $file) {
  112. $totalsize += $file['size'];
  113. }
  114. $linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  115. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
  116. print '<div class="fichecenter">';
  117. //print '<div class="fichehalfleft">';
  118. print '<div class="underbanner clearboth"></div>';
  119. print '<table class="border tableforfield centpercent">';
  120. print '<tr>';
  121. print '<td class="titlefield">'.$langs->trans("User").'</td>';
  122. print '<td>';
  123. print $userRequest->getNomUrl(-1, 'leave');
  124. print '</td></tr>';
  125. // Type
  126. print '<tr>';
  127. print '<td>'.$langs->trans("Type").'</td>';
  128. print '<td>';
  129. $typeleaves = $object->getTypes(1, -1);
  130. $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']);
  131. print empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow;
  132. print '</td>';
  133. print '</tr>';
  134. $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
  135. $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
  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. print '<tr>';
  146. print '<td>';
  147. print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
  148. print '</td>';
  149. print '<td>'.dol_print_date($object->date_fin, 'day');
  150. print ' &nbsp; &nbsp; ';
  151. print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
  152. print '</td>';
  153. print '</tr>';
  154. // Nb days consumed
  155. print '<tr>';
  156. print '<td>';
  157. $htmlhelp = $langs->trans('NbUseDaysCPHelp');
  158. $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
  159. $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
  160. if ($includesaturday) {
  161. $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
  162. }
  163. if ($includesunday) {
  164. $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
  165. }
  166. print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
  167. print '</td>';
  168. print '<td>'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).'</td>';
  169. print '</tr>';
  170. if ($object->statut == 5) {
  171. print '<tr>';
  172. print '<td>'.$langs->trans('DetailRefusCP').'</td>';
  173. print '<td>'.$object->detail_refuse.'</td>';
  174. print '</tr>';
  175. }
  176. // Description
  177. print '<tr>';
  178. print '<td>'.$langs->trans('DescCP').'</td>';
  179. print '<td>'.nl2br($object->description).'</td>';
  180. print '</tr>';
  181. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  182. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  183. print '</tbody>';
  184. print '</table>'."\n";
  185. /*
  186. print '</div>';
  187. print '<div class="fichehalfright">';
  188. print '<div class="underbanner clearboth"></div>';
  189. // Info workflow
  190. print '<table class="border tableforfield centpercent">'."\n";
  191. print '<tbody>';
  192. if (! empty($object->fk_user_create)) {
  193. $userCreate=new User($db);
  194. $userCreate->fetch($object->fk_user_create);
  195. print '<tr>';
  196. print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
  197. print '<td>'.$userCreate->getNomUrl(-1).'</td>';
  198. print '</tr>';
  199. }
  200. print '<tr>';
  201. print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
  202. print '<td>'.$valideur->getNomUrl(-1).'</td>';
  203. print '</tr>';
  204. print '<tr>';
  205. print '<td>'.$langs->trans('DateCreation').'</td>';
  206. print '<td>'.dol_print_date($object->date_create,'dayhour').'</td>';
  207. print '</tr>';
  208. if ($object->statut == 3) {
  209. print '<tr>';
  210. print '<td>'.$langs->trans('DateValidCP').'</td>';
  211. print '<td>'.dol_print_date($object->date_valid,'dayhour').'</td>';
  212. print '</tr>';
  213. }
  214. if ($object->statut == 4) {
  215. print '<tr>';
  216. print '<td>'.$langs->trans('DateCancelCP').'</td>';
  217. print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td>';
  218. print '</tr>';
  219. }
  220. if ($object->statut == 5) {
  221. print '<tr>';
  222. print '<td>'.$langs->trans('DateRefusCP').'</td>';
  223. print '<td>'.dol_print_date($object->date_refuse,'dayhour').'</td>';
  224. print '</tr>';
  225. }
  226. print '</tbody>';
  227. print '</table>';
  228. print '</div>'; */
  229. print '</div>';
  230. print '<div class="clearboth"></div>';
  231. print dol_get_fiche_end();
  232. $permissiontoadd = $user->rights->holiday->write;
  233. $permtoedit = $user->rights->holiday->write;
  234. $param = '&id='.$object->id;
  235. $relativepathwithnofile = dol_sanitizeFileName($object->ref).'/';
  236. $savingdocmask = dol_sanitizeFileName($object->ref).'-__file__';
  237. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  238. } else {
  239. print $langs->trans("ErrorUnknown");
  240. }
  241. // End of page
  242. llxFooter();
  243. $db->close();