From a8e2b49c5ba454f8ae9d6d07abca0febcce9d05e Mon Sep 17 00:00:00 2001 From: Florian HENRY <florian.henry@open-concept.pro> Date: Tue, 8 Mar 2016 10:22:31 +0100 Subject: [PATCH] FIX : #4768 --- .../modules/propale/doc/pdf_azur.modules.php | 40 +++++++++++++------ htdocs/product/document.php | 15 ++++--- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 7c7fa2273d5..818f6fdb560 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -685,21 +685,39 @@ class pdf_azur extends ModelePDFPropales if (count($filetomerge->lines) > 0) { foreach ( $filetomerge->lines as $linefile ) { if (! empty($linefile->id) && ! empty($linefile->file_name)) { - if (! empty($conf->product->enabled)) - $filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . dol_sanitizeFileName($line->product_ref); - elseif (! empty($conf->service->enabled)) - $filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . dol_sanitizeFileName($line->product_ref); + + + if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) + { + if (! empty($conf->product->enabled)) { + $filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos"; + } elseif (! empty($conf->service->enabled)) { + $filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos"; + } + } + else + { + if (! empty($conf->product->enabled)) { + $filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref); + } elseif (! empty($conf->service->enabled)) { + $filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . get_exdir(0,0,0,0,$product,'product') . dol_sanitizeFileName($product->ref); + } + } dol_syslog(get_class($this) . ':: upload_dir=' . $filetomerge_dir, LOG_DEBUG); $infile = $filetomerge_dir . '/' . $linefile->file_name; - if (is_file($infile)) { + if (file_exists($infile) && is_readable($infile)) { $pagecount = $pdf->setSourceFile($infile); for($i = 1; $i <= $pagecount; $i ++) { - $tplidx = $pdf->ImportPage($i); - $s = $pdf->getTemplatesize($tplidx); - $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); - $pdf->useTemplate($tplidx); + $tplIdx = $pdf->importPage(1); + if ($tplIdx!==false) { + $s = $pdf->getTemplatesize($tplIdx); + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $pdf->useTemplate($tplIdx); + } else { + setEventMessages(null, array($infile.' cannot be added, probably protected PDF'),'warnings'); + } } } } @@ -709,10 +727,6 @@ class pdf_azur extends ModelePDFPropales } } - //exit; - - - $pdf->Close(); $pdf->Output($file,'F'); diff --git a/htdocs/product/document.php b/htdocs/product/document.php index ea16a13582c..eb8530259da 100644 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -72,7 +72,7 @@ if ($id > 0 || ! empty($ref)) if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'product').dol_sanitizeFileName($object->ref); elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'product').dol_sanitizeFileName($object->ref); - + if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs { if (! empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; @@ -187,13 +187,13 @@ if ($object->id) $filearrayold=dol_dir_list($upload_dirold,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); $filearray=array_merge($filearray, $filearrayold); } - + $totalsize=0; foreach($filearray as $key => $file) { $totalsize+=$file['size']; } - + print '<table class="border" width="100%">'; @@ -228,7 +228,6 @@ if ($object->id) $param = '&id=' . $object->id; include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; - // Merge propal PDF docuemnt PDF files if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL)) { @@ -243,10 +242,16 @@ if ($object->id) $form = new Form($db); + $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', 'name', SORT_ASC, 1); + if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs + { + $filearray = dol_dir_list($upload_dirold, "files", 0, '', '\.meta$', 'name', SORT_ASC, 1); + } + // For each file build select list with PDF extention - if (count($filearray) > 0) + if (count($filearray) > 0) { print '<br>'; // Actual file to merge is : -- GitLab