dolibarr  16.0.5
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  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
32 require '../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
39 
40 // Load translation files required by the page
41 $langs->loadLangs(array('other', 'products'));
42 
43 $id = GETPOST('id', 'int');
44 $ref = GETPOST('ref', 'alpha');
45 $action = GETPOST('action', 'aZ09');
46 $confirm = GETPOST('confirm', 'alpha');
47 
48 // Security check
49 $fieldvalue = (!empty($id) ? $id : '');
50 $fieldtype = 'rowid';
51 if ($user->socid) {
52  $socid = $user->socid;
53 }
54 $result = restrictedArea($user, 'produit|service');
55 
56 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
57 $hookmanager->initHooks(array('productlotdocuments'));
58 
59 // Get parameters
60 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
61 $sortfield = GETPOST('sortfield', 'aZ09comma');
62 $sortorder = GETPOST('sortorder', 'aZ09comma');
63 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
64 if (empty($page) || $page == -1) {
65  $page = 0;
66 } // If $page is not defined, or '' or -1
67 $offset = $limit * $page;
68 $pageprev = $page - 1;
69 $pagenext = $page + 1;
70 if (!$sortorder) {
71  $sortorder = "ASC";
72 }
73 if (!$sortfield) {
74  $sortfield = "position_name";
75 }
76 
77 $modulepart = 'product_batch';
78 $object = new Productlot($db);
79 if ($id || $ref) {
80  if ($ref) {
81  $tmp = explode('_', $ref);
82  $productid = $tmp[0];
83  $batch = $tmp[1];
84  }
85  $object->fetch($id, $productid, $batch);
86  $object->ref = $object->batch; // Old system for document management ( it uses $object->ref)
87 
88  if (!empty($conf->productbatch->enabled)) {
89  $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
90  $filearray = dol_dir_list($upload_dir, "files");
91  if (empty($filearray)) {
92  // If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product)
93  $object->fetch($id, $productid, $batch);
94  $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
95  }
96  }
97 }
98 
99 $usercanread = $user->rights->produit->lire;
100 $usercancreate = $user->rights->produit->creer;
101 $usercandelete = $user->rights->produit->supprimer;
102 
103 if (empty($upload_dir)) {
104  $upload_dir = $conf->productbatch->multidir_output[$conf->entity];
105 }
106 
107 $permissiontoread = $usercanread;
108 $permissiontoadd = $usercancreate;
109 $permtoedit = $user->rights->produit->creer;
110 //$permissiontodelete = $usercandelete;
111 
112 // Security check
113 if (empty($conf->productbatch->enabled)) {
114  accessforbidden('Module not enabled');
115 }
116 $socid = 0;
117 if ($user->socid > 0) { // Protection if external user
118  //$socid = $user->socid;
119  accessforbidden();
120 }
121 //$result = restrictedArea($user, 'productbatch');
122 if (!$permissiontoread) {
123  accessforbidden();
124 }
125 
126 
127 /*
128  * Actions
129  */
130 
131 $parameters = array('id'=>$id);
132 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
133 if ($reshook < 0) {
134  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
135 }
136 
137 if (empty($reshook)) {
138  // Action submit/delete file/link
139  include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
140 }
141 
142 
143 /*
144  * View
145  */
146 
147 $form = new Form($db);
148 
149 llxHeader('', $langs->trans('ProductLot'), '');
150 
151 
152 if ($object->id) {
153  $head = productlot_prepare_head($object);
154  print dol_get_fiche_head($head, 'documents', $langs->trans("Batch"), -1, 'barcode');
155 
156 
157  $parameters = array();
158  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
159  print $hookmanager->resPrint;
160  if ($reshook < 0) {
161  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
162  }
163 
164  // Build file list
165  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
166 
167  $totalsize = 0;
168  foreach ($filearray as $key => $file) {
169  $totalsize += $file['size'];
170  }
171 
172 
173  $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
174 
175  $shownav = 1;
176  if ($user->socid && !in_array('batch', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
177  $shownav = 0;
178  }
179 
180  dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch');
181 
182  print '<div class="fichecenter">';
183 
184  print '<div class="underbanner clearboth"></div>';
185  print '<table class="border tableforfield" width="100%">';
186 
187  // Product
188  print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
189  $producttmp = new Product($db);
190  $producttmp->fetch($object->fk_product);
191  print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
192  print '</td></tr>';
193 
194  print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
195  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
196  print '</table>';
197 
198  print '</div>';
199  print '<div style="clear:both"></div>';
200 
201  print dol_get_fiche_end();
202 
203  $param = '&id='.$object->id;
204  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
205 } else {
206  print $langs->trans("ErrorUnknown");
207 }
208 
209 
210 llxFooter();
211 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
productlot_prepare_head
productlot_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:220
Productlot
Class with list of lots and properties.
Definition: productlot.class.php:36
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6549
dol_print_size
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
Definition: functions.lib.php:2884
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59