From 21df70032543f61fe0e8382d37d7347c967a5ecb Mon Sep 17 00:00:00 2001 From: All-3kcis Date: Thu, 12 Apr 2018 15:55:08 +0200 Subject: [PATCH] Add option to save file with product batch ref + use batch number like ref instead of id + debug access to shared link --- htdocs/core/lib/files.lib.php | 2 +- htdocs/core/lib/product.lib.php | 2 +- htdocs/core/tpl/document_actions_post_headers.tpl.php | 2 +- htdocs/product/stock/productlot_card.php | 8 +++++--- htdocs/product/stock/productlot_document.php | 10 +++------- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 844399caaf2..040cec8758a 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -2626,7 +2626,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, } // Wrapping pour les lots produits - else if ($modulepart == 'product_batch') + else if ($modulepart == 'product_batch' || $modulepart == 'produitlot') { if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); if (($fuser->rights->produit->{$lire} ) || preg_match('/^specimen/i',$original_file)) diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index e3c10eb9a89..eedb994baed 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -204,7 +204,7 @@ function productlot_prepare_head($object) // Attachments require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.$object->id; + $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); $nbLinks=Link::count($db, $object->element, $object->id); $head[$h][0] = DOL_URL_ROOT."/product/stock/productlot_document.php?id=".$object->id; diff --git a/htdocs/core/tpl/document_actions_post_headers.tpl.php b/htdocs/core/tpl/document_actions_post_headers.tpl.php index 6f20eb1759c..01d7b091a49 100644 --- a/htdocs/core/tpl/document_actions_post_headers.tpl.php +++ b/htdocs/core/tpl/document_actions_post_headers.tpl.php @@ -62,7 +62,7 @@ $savingdocmask=''; if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX)) { //var_dump($modulepart); - if (in_array($modulepart,array('facture_fournisseur','commande_fournisseur','facture','commande','propal','supplier_proposal','ficheinter','contract','expedition','project','project_task','expensereport','tax', 'produit'))) + if (in_array($modulepart,array('facture_fournisseur','commande_fournisseur','facture','commande','propal','supplier_proposal','ficheinter','contract','expedition','project','project_task','expensereport','tax', 'produit', 'product_batch'))) { $savingdocmask=dol_sanitizeFileName($object->ref).'-__file__'; } diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 56ab0ec39c0..757d01868b5 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -1,5 +1,6 @@ + * Copyright (C) 2018 All-3kcis * Copyright (C) ---Put here your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify @@ -86,7 +87,8 @@ if ($id || $ref) $productid=$tmp[0]; $batch=$tmp[1]; } - $object->fetch($id, $productid, $batch); + $object->fetch($id, $productid, $batch); + $object->ref = $object->batch; // For document management ( it use $object->ref) } // Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array @@ -411,14 +413,14 @@ if (empty($action)) print ''; // ancre // Documents - $filedir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product_batch').$object->id; + $filedir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product_batch').dol_sanitizeFileName($object->ref); $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed=$usercanread; $delallowed=$usercancreate; $var=true; - print $formfile->showdocuments('product_batch',$object->id,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang, '', $object); + print $formfile->showdocuments('product_batch',dol_sanitizeFileName($object->ref),$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang, '', $object); $somethingshown=$formfile->numoffiles; print ''; diff --git a/htdocs/product/stock/productlot_document.php b/htdocs/product/stock/productlot_document.php index e40f1a20ed0..be93256858f 100644 --- a/htdocs/product/stock/productlot_document.php +++ b/htdocs/product/stock/productlot_document.php @@ -71,7 +71,7 @@ $pagenext = $page + 1; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="position_name"; - +$modulepart='product_batch'; $object = new Productlot($db); if ($id || $ref) { @@ -82,13 +82,9 @@ if ($id || $ref) $batch=$tmp[1]; } $object->fetch($id, $productid, $batch); -} -$modulepart='product_batch'; -if ($id > 0 || ! empty($ref)) -{ - $result = $object->fetch($id, $ref); + $object->ref = $object->batch; // For document management ( it use $object->ref) - if (! empty($conf->productbatch->enabled)) $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, $modulepart).$object->id; + if (! empty($conf->productbatch->enabled)) $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, $modulepart).dol_sanitizeFileName($object->ref); }