document.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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) 2016 Gilles Poirier <glgpoirier@gmail.com>
  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/resource/document.php
  26. * \ingroup resource
  27. * \brief Page des documents joints sur les resources
  28. */
  29. // Load Dolibarr environment
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.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', 'resource', 'companies'));
  38. $id = GETPOST('id', 'int');
  39. $ref = GETPOST('ref', 'alpha');
  40. $action = GETPOST('action', 'aZ09');
  41. $confirm = GETPOST('confirm', 'alpha');
  42. // Security check
  43. if ($user->socid) {
  44. $socid = $user->socid;
  45. }
  46. $result = restrictedArea($user, 'resource', $id, 'resource');
  47. // Get parameters
  48. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  49. $sortfield = GETPOST('sortfield', 'aZ09comma');
  50. $sortorder = GETPOST('sortorder', 'aZ09comma');
  51. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  52. if (empty($page) || $page == -1) {
  53. $page = 0;
  54. } // If $page is not defined, or '' or -1
  55. $offset = $limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (!$sortorder) {
  59. $sortorder = "ASC";
  60. }
  61. if (!$sortfield) {
  62. $sortfield = "name";
  63. }
  64. $object = new DolResource($db);
  65. // Load object
  66. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  67. $upload_dir = $conf->resource->dir_output.'/'.dol_sanitizeFileName($object->ref);
  68. $modulepart = 'resource';
  69. $result = restrictedArea($user, 'resource', $object->id, 'resource');
  70. $permissiontoadd = $user->rights->resource->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
  71. /*
  72. * Actions
  73. */
  74. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  75. /*
  76. * View
  77. */
  78. $form = new Form($db);
  79. llxHeader('', $langs->trans("Resource"));
  80. if ($object->id > 0) {
  81. $object->fetch_thirdparty();
  82. $head = resource_prepare_head($object);
  83. print dol_get_fiche_head($head, 'documents', $langs->trans("ResourceSingular"), -1, 'resource');
  84. // Build file list
  85. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  86. $totalsize = 0;
  87. foreach ($filearray as $key => $file) {
  88. $totalsize += $file['size'];
  89. }
  90. $linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php'.(!empty($socid) ? '?id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  91. $morehtmlref = '<div class="refidno">';
  92. $morehtmlref .= '</div>';
  93. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  94. print '<div class="fichecenter">';
  95. print '<div class="underbanner clearboth"></div>';
  96. print '<table class="border tableforfield centpercent">';
  97. // Resource type
  98. print '<tr>';
  99. print '<td class="titlefield">'.$langs->trans("ResourceType").'</td>';
  100. print '<td>';
  101. print $object->type_label;
  102. print '</td>';
  103. print '</tr>';
  104. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  105. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  106. print '</table>';
  107. print '</div>';
  108. print dol_get_fiche_end();
  109. $modulepart = 'dolresource';
  110. $permissiontoadd = $user->rights->resource->write;
  111. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  112. } else {
  113. print $langs->trans("ErrorUnknown");
  114. }
  115. // End of page
  116. llxFooter();
  117. $db->close();