dolibarr 25.0.0-alpha
inventory_document.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Jose MARTINEZ <jose.martinez@pichinov.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24// Load Dolibarr environment
25require '../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
38require_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php';
39
40// Load translation files required by the page
41$langs->loadLangs(array("stocks", "other", "mails"));
42
43$action = GETPOST('action', 'aZ09');
44$confirm = GETPOST('confirm');
45$id = GETPOSTINT('id');
46$ref = GETPOST('ref', 'alpha');
47
48// Get parameters
49$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
50$sortfield = GETPOST('sortfield', 'aZ09comma');
51$sortorder = GETPOST('sortorder', 'aZ09comma');
52$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
53if (empty($page) || $page == -1) {
54 $page = 0;
55} // If $page is not defined, or '' or -1
56$offset = $limit * $page;
57$pageprev = $page - 1;
58$pagenext = $page + 1;
59if (!$sortorder) {
60 $sortorder = "ASC";
61}
62if (!$sortfield) {
63 $sortfield = "name";
64}
65
66// Initialize a technical objects
67$object = new Inventory($db);
68$hookmanager->initHooks(array('inventorydocument', 'globalcard')); // Note that conf->hooks_modules contains array
69
70// Fetch optionals attributes and labels
71$extrafields->fetch_name_optionals_label($object->table_element);
72
73// Load object
74include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
75
76$upload_dir = null;
77if ($id > 0 || !empty($ref)) {
78 $upload_dir = $conf->stock->multidir_output[$object->entity ? $object->entity : $conf->entity].'/inventory/'.dol_sanitizeFileName((string) $object->ref);
79}
80
81// Security check
82if ($user->socid > 0) {
84}
85$result = restrictedArea($user, 'stock', $object->id, 'inventory&stock');
86
87$permissiontoadd = $user->hasRight('stock', 'creer'); // Used by the include of actions_linkedfiles.inc.php
88
89
90/*
91 * Actions
92 */
93
94include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
95
96
97/*
98 * View
99 */
100
101$form = new Form($db);
102
103$title = $langs->trans("Inventory").' - '.$langs->trans("Files");
104$help_url = 'EN:Module_Stocks_En|FR:Module_Stock|DE:Modul_Lager';
105
106llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-product page-inventory_document');
107
108if ($object->id && $upload_dir !== null) {
109 /*
110 * Show tabs
111 */
112 $head = inventoryPrepareHead($object);
113
114 print dol_get_fiche_head($head, 'document', $langs->trans("Inventory"), -1, 'stock');
115
116 // Build file list
117 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
118 $totalsize = 0;
119 foreach ($filearray as $key => $file) {
120 $totalsize += $file['size'];
121 }
122
123 // Object card
124 // ------------------------------------------------------------
125 $linkback = '<a href="'.dol_buildpath('/product/inventory/list.php', 1).'?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
126
127 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
128
129 print '<div class="fichecenter">';
130
131 print '<div class="underbanner clearboth"></div>';
132 print '<table class="border centpercent tableforfield">';
133
134 // Number of files
135 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
136
137 // Total size
138 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
139
140 print '</table>';
141
142 print '</div>';
143
144 print dol_get_fiche_end();
145
146 $modulepart = 'inventory';
147 $permtoedit = $user->hasRight('stock', 'creer');
148 $param = '&id='.$object->id;
149
150 $relativepathwithnofile = dol_sanitizeFileName((string) $object->ref).'/';
151
152 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
153} else {
154 accessforbidden('', 0, 1);
155}
156
157// End of page
158llxFooter();
159$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
Class for Inventory.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:65
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:519
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:717
inventoryPrepareHead(&$inventory, $title='Inventory', $get='')
Define head array for tabs of inventory tools setup pages.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.