dolibarr/htdocs/asset/document.php

145 lines
4.5 KiB
PHP
Raw Normal View History

2018-04-01 21:26:52 +02:00
<?php
/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
2021-02-08 05:39:07 +01:00
* Copyright (C) 2018-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
2018-04-01 21:26:52 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-04-01 21:26:52 +02:00
*/
/**
2018-08-31 23:12:55 +02:00
* \file htdocs/asset/document.php
2018-04-29 19:52:14 +02:00
* \ingroup asset
2021-02-08 05:39:07 +01:00
* \brief Page for attached files on assets
2018-04-01 21:26:52 +02:00
*/
require '../main.inc.php';
2018-04-29 19:52:14 +02:00
require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php';
require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php';
2018-04-01 21:26:52 +02:00
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
2018-05-26 18:41:16 +02:00
// Load translation files required by the page
2021-02-08 05:39:07 +01:00
$langs->loadLangs(array('assets', 'companies', 'other'));
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
$id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
2018-04-01 21:26:52 +02:00
$ref = GETPOST('ref', 'alpha');
2021-02-08 05:39:07 +01:00
$socid = GETPOST('socid', 'int');
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
2018-04-01 21:26:52 +02:00
// Get parameters
2020-04-20 15:06:27 +02:00
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
2021-02-22 18:38:03 +01:00
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
2020-04-20 15:06:27 +02:00
$offset = $limit * $page;
2018-04-01 21:26:52 +02:00
$pageprev = $page - 1;
$pagenext = $page + 1;
2021-02-22 18:38:03 +01:00
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "name";
}
2018-04-01 21:26:52 +02:00
$object = new Asset($db);
2021-02-22 18:38:03 +01:00
if ($object->fetch($id)) {
2021-02-08 05:39:07 +01:00
$upload_dir = $conf->asset->dir_output."/".dol_sanitizeFileName($object->ref);
}
2018-04-01 21:26:52 +02:00
$permissiontoadd = $user->rights->asset->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
// Security check
if ($user->socid) {
$socid = $user->socid;
}
$result=restrictedArea($user, 'asset', $id, '');
2018-04-01 21:26:52 +02:00
/*
* Actions
*/
2021-02-19 16:04:46 +01:00
include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
2018-04-01 21:26:52 +02:00
/*
* View
*/
2021-02-08 05:39:07 +01:00
$title = $langs->trans('Assets')." - ".$langs->trans('Documents');
$help_url = '';
llxHeader('', $title, $help_url);
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
$form = new Form($db);
2018-04-01 21:26:52 +02:00
2021-02-22 18:38:03 +01:00
if ($id > 0 || !empty($ref)) {
if ($object->fetch($id, $ref) > 0) {
2021-02-08 05:39:07 +01:00
$upload_dir = $conf->asset->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
$head = asset_prepare_head($object);
print dol_get_fiche_head($head, 'documents', $langs->trans('Asset'), -1, 'accounting');
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
// Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0;
2021-02-22 18:38:03 +01:00
foreach ($filearray as $key => $file) {
2021-02-08 05:39:07 +01:00
$totalsize += $file['size'];
}
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
// Asset content
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
$linkback = '<a href="'.DOL_URL_ROOT.'/asset/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
$morehtmlref = '';
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0);
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
print '<table class="border tableforfield centpercent">';
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
print "</table>\n";
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
print "</div>\n";
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
print dol_get_fiche_end();
2018-04-01 21:26:52 +02:00
2021-02-08 05:39:07 +01:00
$modulepart = 'asset';
2021-06-08 16:19:21 +02:00
$permissiontoadd = $user->rights->asset->write;
2021-02-08 05:39:07 +01:00
$permtoedit = $user->rights->asset->write;
$param = '&id='.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
2021-02-08 05:39:07 +01:00
} else {
dol_print_error($db);
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-08 05:39:07 +01:00
print $langs->trans("ErrorUnknown");
2018-04-01 21:26:52 +02:00
}
2018-07-29 11:33:52 +02:00
// End of page
2018-04-01 21:26:52 +02:00
llxFooter();
$db->close();