dolibarr 21.0.3
productlot_document.php
Go to the documentation of this file.
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-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
9 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
10 * Copyright (C) 2018 All-3kcis <contact@all-3kcis.fr>
11 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
34// Load Dolibarr environment
35require '../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
41require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
42
51// Load translation files required by the page
52$langs->loadLangs(array('other', 'products', 'productbatch'));
53
54$id = GETPOSTINT('id');
55$ref = GETPOST('ref', 'alpha');
56$action = GETPOST('action', 'aZ09');
57$confirm = GETPOST('confirm', 'alpha');
58
59// Security check
60$fieldvalue = (!empty($id) ? $id : '');
61$fieldtype = 'rowid';
62if ($user->socid) {
63 $socid = $user->socid;
64}
65
66// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
67$hookmanager->initHooks(array('productlotdocuments'));
68
69$result = restrictedArea($user, 'produit|service');
70
71// Get parameters
72$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
73$sortfield = GETPOST('sortfield', 'aZ09comma');
74$sortorder = GETPOST('sortorder', 'aZ09comma');
75$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
76if (empty($page) || $page == -1) {
77 $page = 0;
78} // If $page is not defined, or '' or -1
79$offset = $limit * $page;
80$pageprev = $page - 1;
81$pagenext = $page + 1;
82if (!$sortorder) {
83 $sortorder = "ASC";
84}
85if (!$sortfield) {
86 $sortfield = "position_name";
87}
88
89$modulepart = 'product_batch';
90$object = new Productlot($db);
91if ($id || $ref) {
92 $productid = 0;
93 $batch = '';
94 if ($ref) {
95 $tmp = explode('_', $ref);
96 $productid = $tmp[0];
97 $batch = $tmp[1];
98 }
99 $object->fetch($id, $productid, $batch);
100
101 if (isModEnabled('productbatch')) {
102 $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
103 $filearray = dol_dir_list($upload_dir, "files");
104 }
105}
106
107$usercanread = $user->hasRight('produit', 'lire');
108$usercancreate = $user->hasRight('produit', 'creer');
109$usercandelete = $user->hasRight('produit', 'supprimer');
110
111if (empty($upload_dir)) {
112 $upload_dir = $conf->productbatch->multidir_output[$conf->entity];
113}
114
115$permissiontoread = $usercanread;
116$permissiontoadd = $usercancreate;
117$permtoedit = $user->hasRight('produit', 'creer');
118//$permissiontodelete = $usercandelete;
119
120// Security check
121if (!isModEnabled('productbatch')) {
122 accessforbidden('Module not enabled');
123}
124$socid = 0;
125if ($user->socid > 0) { // Protection if external user
126 //$socid = $user->socid;
128}
129//$result = restrictedArea($user, 'productbatch');
130if (!$permissiontoread) {
132}
133
134
135/*
136 * Actions
137 */
138
139$parameters = array('id'=>$id);
140$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
141if ($reshook < 0) {
142 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
143}
144
145if (empty($reshook)) {
146 // Action submit/delete file/link
147 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
148}
149
150
151/*
152 * View
153 */
154
155$form = new Form($db);
156
157$help_url = '';
158$shortlabel = dol_trunc($object->batch, 16);
159$title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Documents');
160$help_url = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
161
162llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-product page-stock_productlot_document');
163
164if ($object->id) {
165 $head = productlot_prepare_head($object);
166 print dol_get_fiche_head($head, 'documents', $langs->trans("Batch"), -1, $object->picto);
167
168
169 $parameters = array();
170 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
171 print $hookmanager->resPrint;
172 if ($reshook < 0) {
173 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
174 }
175
176 // Build file list
177 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
178
179 $totalsize = 0;
180 foreach ($filearray as $key => $file) {
181 $totalsize += $file['size'];
182 }
183
184
185 $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
186
187 $shownav = 1;
188 if ($user->socid && !in_array('batch', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
189 $shownav = 0;
190 }
191
192 dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch');
193
194 print '<div class="fichecenter">';
195
196 print '<div class="underbanner clearboth"></div>';
197 print '<table class="border tableforfield" width="100%">';
198
199 // Product
200 print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
201 $producttmp = new Product($db);
202 $producttmp->fetch($object->fk_product);
203 print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
204 print '</td></tr>';
205
206 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
207 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
208 print '</table>';
209
210 print '</div>';
211 print '<div class="clearboth"></div>';
212
213 print dol_get_fiche_end();
214
215 $param = '&id='.$object->id;
216 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
217} else {
218 print $langs->trans("ErrorUnknown");
219}
220
221
222llxFooter();
223$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
Class to manage generation of HTML components Only common components must be here.
Class to manage products or services.
Class with list of lots and properties.
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:63
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
productlot_prepare_head($object)
Prepare array with list of tabs.
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.