document.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/asset/document.php
  20. * \ingroup asset
  21. * \brief Page for attached files on assets
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('assets', 'companies', 'other', 'mails'));
  32. $action = GETPOST('action', 'aZ09');
  33. $confirm = GETPOST('confirm', 'alpha');
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. // Get parameters
  37. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  38. $sortfield = GETPOST("sortfield", 'alpha');
  39. $sortorder = GETPOST("sortorder", 'alpha');
  40. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  41. if (empty($page) || $page == -1) {
  42. $page = 0;
  43. } // If $page is not defined, or '' or -1
  44. $offset = $limit * $page;
  45. $pageprev = $page - 1;
  46. $pagenext = $page + 1;
  47. if (!$sortorder) {
  48. $sortorder = "ASC";
  49. }
  50. if (!$sortfield) {
  51. $sortfield = "name";
  52. }
  53. // Initialize technical objects
  54. $object = new Asset($db);
  55. $extrafields = new ExtraFields($db);
  56. $diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
  57. $hookmanager->initHooks(array('assetdocument', 'globalcard')); // Note that conf->hooks_modules contains array
  58. // Fetch optionals attributes and labels
  59. $extrafields->fetch_name_optionals_label($object->table_element);
  60. // Load object
  61. 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
  62. if ($id > 0 || !empty($ref)) {
  63. $upload_dir = $conf->asset->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object);
  64. }
  65. $permissiontoadd = $user->rights->asset->asset->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
  66. // Security check (enable the most restrictive one)
  67. if ($user->socid > 0) accessforbidden();
  68. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  69. restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  70. if (empty($conf->asset->enabled)) accessforbidden();
  71. /*
  72. * Actions
  73. */
  74. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  75. /*
  76. * View
  77. */
  78. $form = new Form($db);
  79. $title = $langs->trans("Asset").' - '.$langs->trans("Files");
  80. $help_url = '';
  81. llxHeader('', $title, $help_url);
  82. if ($object->id) {
  83. /*
  84. * Show tabs
  85. */
  86. $head = assetPrepareHead($object);
  87. print dol_get_fiche_head($head, 'document', $langs->trans("Asset"), -1, $object->picto);
  88. // Build file list
  89. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  90. $totalsize = 0;
  91. foreach ($filearray as $key => $file) {
  92. $totalsize += $file['size'];
  93. }
  94. // Object card
  95. // ------------------------------------------------------------
  96. $linkback = '<a href="' . dol_buildpath('/asset/asset_list.php', 1) . '?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  97. $morehtmlref = '<div class="refidno">';
  98. $morehtmlref .= '</div>';
  99. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  100. print '<div class="fichecenter">';
  101. print '<div class="underbanner clearboth"></div>';
  102. print '<table class="border centpercent tableforfield">';
  103. // Number of files
  104. print '<tr><td class="titlefield">' . $langs->trans("NbOfAttachedFiles") . '</td><td colspan="3">' . count($filearray) . '</td></tr>';
  105. // Total size
  106. print '<tr><td>' . $langs->trans("TotalSizeOfAttachedFiles") . '</td><td colspan="3">' . $totalsize . ' ' . $langs->trans("bytes") . '</td></tr>';
  107. print '</table>';
  108. print '</div>';
  109. print dol_get_fiche_end();
  110. $modulepart = 'asset';
  111. $permissiontoadd = $user->rights->asset->write;
  112. // $permissiontoadd = 1;
  113. $permtoedit = $user->rights->asset->write;
  114. // $permtoedit = 1;
  115. $param = '&id=' . $object->id;
  116. //$relativepathwithnofile='asset/' . dol_sanitizeFileName($object->id).'/';
  117. $relativepathwithnofile = dol_sanitizeFileName($object->ref) . '/';
  118. include DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  119. } else {
  120. accessforbidden('', 0, 1);
  121. }
  122. // End of page
  123. llxFooter();
  124. $db->close();