document.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. * or see https://www.gnu.org/
  23. */
  24. /**
  25. * \file htdocs/expensereport/document.php
  26. * \ingroup expensereport
  27. * \brief Page of linked files onto trip and expens reports
  28. */
  29. // Load Dolibarr environment
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("other", "trips", "companies", "interventions"));
  37. $id = GETPOST('id', 'int');
  38. $ref = GETPOST('ref', 'alpha');
  39. $action = GETPOST('action', 'aZ09');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. $childids = $user->getAllChildIds(1);
  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. $object = new ExpenseReport($db);
  60. if (!$object->fetch($id, $ref) > 0) {
  61. dol_print_error($db);
  62. }
  63. $upload_dir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($object->ref);
  64. $modulepart = 'trip';
  65. // Load object
  66. //include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  67. // Security check
  68. if ($user->socid) {
  69. $socid = $user->socid;
  70. }
  71. $result = restrictedArea($user, 'expensereport', $id, 'expensereport');
  72. if ($object->id > 0) {
  73. // Check current user can read this expense report
  74. $canread = 0;
  75. if ($user->hasRight('expensereport', 'readall')) {
  76. $canread = 1;
  77. }
  78. if ($user->hasRight('expensereport', 'lire') && in_array($object->fk_user_author, $childids)) {
  79. $canread = 1;
  80. }
  81. if (!$canread) {
  82. accessforbidden();
  83. }
  84. }
  85. $permissiontoadd = $user->rights->expensereport->creer; // Used by the include of actions_dellink.inc.php
  86. /*
  87. * Actions
  88. */
  89. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  90. /*
  91. * View
  92. */
  93. $form = new Form($db);
  94. $title = $langs->trans("ExpenseReport")." - ".$langs->trans("Documents");
  95. $help_url = "EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
  96. llxHeader("", $title, $help_url);
  97. if ($object->id) {
  98. $object->fetch_thirdparty();
  99. $head = expensereport_prepare_head($object);
  100. print dol_get_fiche_head($head, 'documents', $langs->trans("ExpenseReport"), -1, 'trip');
  101. $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  102. $morehtmlref = '<div class="refidno">';
  103. $morehtmlref .= '</div>';
  104. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  105. // Build file list
  106. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  107. $totalsize = 0;
  108. foreach ($filearray as $key => $file) {
  109. $totalsize += $file['size'];
  110. }
  111. print '<div class="fichecenter">';
  112. print '<div class="underbanner clearboth"></div>';
  113. print '<table class="border tableforfield centpercent">';
  114. $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  115. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  116. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  117. print '</table>';
  118. print '</div>';
  119. print dol_get_fiche_end();
  120. $modulepart = 'expensereport';
  121. $permissiontoadd = $user->rights->expensereport->creer;
  122. $permtoedit = $user->rights->expensereport->creer;
  123. $param = '&id='.$object->id;
  124. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  125. } else {
  126. print $langs->trans("ErrorUnknown");
  127. }
  128. // End of page
  129. llxFooter();
  130. $db->close();