document.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018 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 <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/asset/document.php
  20. * \ingroup asset
  21. * \brief Tab for documents linked to 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"));
  32. $action=GETPOST('action','aZ09');
  33. $confirm=GETPOST('confirm');
  34. $id=(GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
  35. $ref = GETPOST('ref', 'alpha');
  36. // Security check - Protection if external user
  37. //if ($user->societe_id > 0) access_forbidden();
  38. //if ($user->societe_id > 0) $socid = $user->societe_id;
  39. //$result = restrictedArea($user, 'asset', $id);
  40. // Get parameters
  41. $sortfield = GETPOST("sortfield",'alpha');
  42. $sortorder = GETPOST("sortorder",'alpha');
  43. $page = GETPOST("page",'int');
  44. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  45. $offset = $conf->liste_limit * $page;
  46. $pageprev = $page - 1;
  47. $pagenext = $page + 1;
  48. if (! $sortorder) $sortorder="ASC";
  49. if (! $sortfield) $sortfield="name";
  50. // Initialize technical objects
  51. $object=new Asset($db);
  52. $extrafields = new ExtraFields($db);
  53. $diroutputmassaction=$conf->assets->dir_output . '/temp/massgeneration/'.$user->id;
  54. $hookmanager->initHooks(array('assetdocument')); // Note that conf->hooks_modules contains array
  55. // Fetch optionals attributes and labels
  56. $extralabels = $extrafields->fetch_name_optionals_label('asset');
  57. // Load object
  58. 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
  59. //if ($id > 0 || ! empty($ref)) $upload_dir = $conf->sellyoursaas->multidir_output[$object->entity] . "/packages/" . dol_sanitizeFileName($object->id);
  60. if ($id > 0 || ! empty($ref)) $upload_dir = $conf->sellyoursaas->multidir_output[$object->entity] . "/packages/" . dol_sanitizeFileName($object->ref);
  61. /*
  62. * Actions
  63. */
  64. include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
  65. /*
  66. * View
  67. */
  68. $form = new Form($db);
  69. $title=$langs->trans("Assets").' - '.$langs->trans("Files");
  70. $help_url='';
  71. //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  72. llxHeader('', $title, $help_url);
  73. if ($object->id)
  74. {
  75. /*
  76. * Show tabs
  77. */
  78. if (! empty($conf->notification->enabled)) $langs->load("mails");
  79. $head = asset_prepare_head($object);
  80. dol_fiche_head($head, 'document', $langs->trans("Asset"), -1, 'generic');
  81. // Build file list
  82. $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  83. $totalsize=0;
  84. foreach($filearray as $key => $file)
  85. {
  86. $totalsize+=$file['size'];
  87. }
  88. // Object card
  89. // ------------------------------------------------------------
  90. $linkback = '<a href="' .dol_buildpath('/asset/list.php',1) . '?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  91. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  92. print '<div class="fichecenter">';
  93. print '<div class="underbanner clearboth"></div>';
  94. print '<table class="border centpercent">';
  95. // Number of files
  96. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  97. // Total size
  98. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  99. print '</table>';
  100. print '</div>';
  101. dol_fiche_end();
  102. $modulepart = 'asset';
  103. //$permission = $user->rights->asset->create;
  104. $permission = 1;
  105. //$permtoedit = $user->rights->asset->create;
  106. $permtoedit = 1;
  107. $param = '&id=' . $object->id;
  108. //$relativepathwithnofile='asset/' . dol_sanitizeFileName($object->id).'/';
  109. $relativepathwithnofile='asset/' . dol_sanitizeFileName($object->ref).'/';
  110. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  111. }
  112. else
  113. {
  114. accessforbidden('',0,0);
  115. }
  116. // End of page
  117. llxFooter();
  118. $db->close();