From 880f77b7e1cd5f799be3086fb81700655d859b10 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 30 Apr 2014 13:50:25 +0200 Subject: [PATCH] Fix: Preview feature --- htdocs/comm/propal/apercu.php | 12 +++++++----- htdocs/commande/apercu.php | 14 ++++++++------ htdocs/commande/fiche.php | 11 ++++++----- htdocs/compta/facture/apercu.php | 10 +++++----- htdocs/compta/prelevement/bon.php | 6 +++--- htdocs/core/class/html.formfile.class.php | 2 +- htdocs/core/lib/company.lib.php | 2 +- htdocs/core/lib/contract.lib.php | 2 +- htdocs/core/lib/fichinter.lib.php | 2 +- htdocs/core/lib/files.lib.php | 19 +++++++++++-------- htdocs/core/lib/fourn.lib.php | 4 ++-- htdocs/core/lib/invoice.lib.php | 2 +- htdocs/core/lib/order.lib.php | 2 +- htdocs/core/lib/product.lib.php | 2 +- htdocs/core/lib/project.lib.php | 2 +- htdocs/core/lib/propal.lib.php | 2 +- htdocs/core/lib/tax.lib.php | 2 +- htdocs/fichinter/apercu.php | 9 +++++---- 18 files changed, 57 insertions(+), 48 deletions(-) diff --git a/htdocs/comm/propal/apercu.php b/htdocs/comm/propal/apercu.php index 0e14848d1e8..77a5fcf2697 100644 --- a/htdocs/comm/propal/apercu.php +++ b/htdocs/comm/propal/apercu.php @@ -126,10 +126,10 @@ if ($id > 0 || ! empty($ref)) $relativepath = $objectref.'/'.$objectref.'.pdf'; $relativepathdetail = $objectref.'/'.$objectref.'-detail.pdf'; - // Chemin vers png apercus - $fileimage = $file.".png"; // Si PDF d'1 page - $fileimagebis = $file."-0.png"; // Si PDF de plus d'1 page - $relativepathimage = $relativepath.'.png'; + // Define path to preview pdf file (preview precompiled "file.ext" are "file.ext_preview.png") + $fileimage = $file.'_preview.png'; // If PDF has 1 page + $fileimagebis = $file.'_preview-0.pdf.png'; // If PDF has more than one page + $relativepathimage = $relativepath.'_preview.png'; $var=true; @@ -155,7 +155,7 @@ if ($id > 0 || ! empty($ref)) { if (class_exists("Imagick")) { - $ret = dol_convert_file($file); + $ret = dol_convert_file($file,'png',$fileimage); if ($ret < 0) $error++; } else @@ -173,6 +173,8 @@ if ($id > 0 || ! empty($ref)) print ''.price($object->price).''; print ''.$langs->trans("Currency".$conf->currency).''; print ''; + + dol_fiche_end(); } else { diff --git a/htdocs/commande/apercu.php b/htdocs/commande/apercu.php index 10bc0b500f4..9eb04e940bc 100644 --- a/htdocs/commande/apercu.php +++ b/htdocs/commande/apercu.php @@ -4,7 +4,7 @@ * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2011 Juanjo Menent - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or @@ -112,10 +112,10 @@ if ($id > 0 || ! empty($ref)) $relativepath = $objectref.'/'.$objectref.'.pdf'; $relativepathdetail = $objectref.'/'.$objectref.'-detail.pdf'; - // Chemin vers png apercus - $fileimage = $file.".png"; // Si PDF d'1 page - $fileimagebis = $file."-0.png"; // Si PDF de plus d'1 page - $relativepathimage = $relativepath.'.png'; + // Define path to preview pdf file (preview precompiled "file.ext" are "file.ext_preview.png") + $fileimage = $file.'_preview.png'; // If PDF has 1 page + $fileimagebis = $file.'_preview-0.pdf.png'; // If PDF has more than one page + $relativepathimage = $relativepath.'_preview.png'; $var=true; @@ -151,7 +151,7 @@ if ($id > 0 || ! empty($ref)) { if (class_exists("Imagick")) { - $ret = dol_convert_file($file); + $ret = dol_convert_file($file,'png',$fileimage); if ($ret < 0) $error++; } else @@ -193,6 +193,8 @@ if ($id > 0 || ! empty($ref)) print ''.price($object->total_ht).''; print ''.$langs->trans("Currency".$conf->currency).''; print ''; + + dol_fiche_end(); } else { diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index a14ba58e19e..f4cf312b045 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -2248,7 +2248,8 @@ if ($action == 'create' && $user->rights->commande->creer) { } print '
'; - if ($action != 'presend') { + if ($action != 'presend') + { print '
'; // print '
'; // print ''; // ancre @@ -2267,7 +2268,7 @@ if ($action == 'create' && $user->rights->commande->creer) { /* * Linked object block - */ + */ $somethingshown = $object->showLinkedObjectBlock(); print '
'; @@ -2284,9 +2285,9 @@ if ($action == 'create' && $user->rights->commande->creer) { /* * Action presend - * - */ - if ($action == 'presend') { + */ + if ($action == 'presend') + { $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/')); diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php index 36802709c0a..e1662708489 100644 --- a/htdocs/compta/facture/apercu.php +++ b/htdocs/compta/facture/apercu.php @@ -302,10 +302,10 @@ if ($id > 0 || ! empty($ref)) $relativepath = $objectref.'/'.$objectref.'.pdf'; $relativepathdetail = $objectref.'/'.$objectref.'-detail.pdf'; - // Chemin vers png apercus - $fileimage = $file.".png"; // Si PDF d'1 page - $fileimagebis = $file."-0.png"; // Si PDF de plus d'1 page - $relativepathimage = $relativepath.'.png'; + // Define path to preview pdf file (preview precompiled "file.ext" are "file.ext_preview.png") + $fileimage = $file.'_preview.png'; // If PDF has 1 page + $fileimagebis = $file.'_preview-0.pdf.png'; // If PDF has more than one page + $relativepathimage = $relativepath.'_preview.png'; $var=true; @@ -341,7 +341,7 @@ if ($id > 0 || ! empty($ref)) { if (class_exists("Imagick")) { - $ret = dol_convert_file($file); + $ret = dol_convert_file($file,'png',$fileimage); if ($ret < 0) $error++; } else diff --git a/htdocs/compta/prelevement/bon.php b/htdocs/compta/prelevement/bon.php index b1bcbb3d04b..6853a946c13 100644 --- a/htdocs/compta/prelevement/bon.php +++ b/htdocs/compta/prelevement/bon.php @@ -76,7 +76,7 @@ if ($id > 0 || ! empty($ref)) { if (class_exists("Imagick")) { - $ret = dol_convert_file($file); + $ret = dol_convert_file($file,'png',$fileimage); if ($ret < 0) $error++; } else @@ -91,6 +91,8 @@ if ($id > 0 || ! empty($ref)) print ''; } + + dol_fiche_end(); } else { @@ -98,7 +100,5 @@ if ($id > 0 || ! empty($ref)) } } -print "
"; - llxFooter(); ?> diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index cb993f9418e..6788174bc97 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -527,7 +527,7 @@ class FormFile // Get list of files if (! empty($filedir)) { - $file_list=dol_dir_list($filedir,'files',0,'','\.meta$','date',SORT_DESC); + $file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview\.png)$','date',SORT_DESC); // Affiche en-tete tableau si non deja affiche if (! empty($file_list) && ! $headershown) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 6aaa8a7e2f6..09e66330791 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -128,7 +128,7 @@ function societe_prepare_head($object) // Attached files require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->societe->dir_output . "/" . $object->id; - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id; $head[$h][1] = $langs->trans("Documents"); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; diff --git a/htdocs/core/lib/contract.lib.php b/htdocs/core/lib/contract.lib.php index 591d5746992..37ab1f7881f 100644 --- a/htdocs/core/lib/contract.lib.php +++ b/htdocs/core/lib/contract.lib.php @@ -67,7 +67,7 @@ function contract_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->contrat->dir_output . "/" . dol_sanitizeFileName($object->ref); - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$object->id; $head[$h][1] = $langs->trans("Documents"); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; diff --git a/htdocs/core/lib/fichinter.lib.php b/htdocs/core/lib/fichinter.lib.php index dc5668fd7d3..b25bfe808f2 100644 --- a/htdocs/core/lib/fichinter.lib.php +++ b/htdocs/core/lib/fichinter.lib.php @@ -79,7 +79,7 @@ function fichinter_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->ficheinter->dir_output . "/" . dol_sanitizeFileName($object->ref); - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id; $head[$h][1] = $langs->trans("Documents"); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index b8a2991ffb5..fabe7303e63 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -513,9 +513,9 @@ function dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1) if (empty($newmask)) // This should no happen { dol_syslog("Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING); - $newmask='0664'; + $newmask='0664'; } - + @chmod($newpathofdestfile, octdec($newmask)); return 1; @@ -1148,26 +1148,29 @@ function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile= } /** - * Convert an image file into antoher format. + * Convert an image file into anoher format. * This need Imagick php extension. * - * @param string $file Input file name - * @param string $ext Extension of target file + * @param string $fileinput Input file name + * @param string $ext Format of target file (It is also extension added to file if fileoutput is not provided). + * @param string $fileoutput Output filename * @return int <0 if KO, >0 if OK */ -function dol_convert_file($file,$ext='png') +function dol_convert_file($fileinput,$ext='png',$fileoutput='') { global $langs; $image=new Imagick(); - $ret = $image->readImage($file); + $ret = $image->readImage($fileinput); if ($ret) { $ret = $image->setImageFormat($ext); if ($ret) { + if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext; + $count = $image->getNumberImages(); - $ret = $image->writeImages($file . "." . $ext, true); + $ret = $image->writeImages($fileoutput, true); if ($ret) return $count; else return -3; } diff --git a/htdocs/core/lib/fourn.lib.php b/htdocs/core/lib/fourn.lib.php index d318ceed8ad..a6981be8355 100644 --- a/htdocs/core/lib/fourn.lib.php +++ b/htdocs/core/lib/fourn.lib.php @@ -70,7 +70,7 @@ function facturefourn_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$object->ref; - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$object->id; $head[$h][1] = $langs->trans('Documents'); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; @@ -142,7 +142,7 @@ function ordersupplier_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->fournisseur->dir_output . "/commande/" . dol_sanitizeFileName($object->ref); - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/document.php?id='.$object->id; $head[$h][1] = $langs->trans('Documents'); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php index 0142bfae113..caf82ca03f0 100644 --- a/htdocs/core/lib/invoice.lib.php +++ b/htdocs/core/lib/invoice.lib.php @@ -86,7 +86,7 @@ function facture_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref); - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/compta/facture/document.php?facid='.$object->id; $head[$h][1] = $langs->trans('Documents'); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; diff --git a/htdocs/core/lib/order.lib.php b/htdocs/core/lib/order.lib.php index 216887139d4..fa5be241aa6 100644 --- a/htdocs/core/lib/order.lib.php +++ b/htdocs/core/lib/order.lib.php @@ -96,7 +96,7 @@ function commande_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref); - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/commande/document.php?id='.$object->id; $head[$h][1] = $langs->trans('Documents'); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 3eb364e7eb6..e8c86b37db9 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -120,7 +120,7 @@ function product_prepare_head($object, $user) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$object->id; $head[$h][1] = $langs->trans('Documents'); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 007cb4a8184..87113d92301 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -78,7 +78,7 @@ function project_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref); - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id; $head[$h][1] = $langs->trans('Documents'); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; diff --git a/htdocs/core/lib/propal.lib.php b/htdocs/core/lib/propal.lib.php index d43885adf95..1a513d5fcec 100644 --- a/htdocs/core/lib/propal.lib.php +++ b/htdocs/core/lib/propal.lib.php @@ -90,7 +90,7 @@ function propal_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref); - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/comm/propal/document.php?id='.$object->id; $head[$h][1] = $langs->trans('Documents'); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php index 083f3a74548..35165597cff 100644 --- a/htdocs/core/lib/tax.lib.php +++ b/htdocs/core/lib/tax.lib.php @@ -51,7 +51,7 @@ function tax_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->tax->dir_output . "/" . dol_sanitizeFileName($object->ref); - $nbFiles = count(dol_dir_list($upload_dir,'files')); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $head[$h][0] = DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id; $head[$h][1] = $langs->trans("Documents"); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; diff --git a/htdocs/fichinter/apercu.php b/htdocs/fichinter/apercu.php index 2ba31d41df4..fbf7569ce4a 100644 --- a/htdocs/fichinter/apercu.php +++ b/htdocs/fichinter/apercu.php @@ -85,9 +85,10 @@ if ($id > 0 || ! empty($ref)) $relativepath = "${objectref}/${objectref}.pdf"; $relativepathdetail = "${objectref}/${objectref}-detail.pdf"; - // Chemin vers png apercus - $fileimage = $file.".png"; // Si PDF d'1 page - $fileimagebis = $file."-0.png"; // Si PDF de plus d'1 page + // Define path to preview pdf file (preview precompiled "file.ext" are "file.ext_preview.png") + $fileimage = $file.'_preview.png'; // If PDF has 1 page + $fileimagebis = $file.'_preview-0.pdf.png'; // If PDF has more than one page + $relativepathimage = $relativepath.'_preview.png'; $var=true; @@ -122,7 +123,7 @@ if ($id > 0 || ! empty($ref)) { if (class_exists("Imagick")) { - $ret = dol_convert_file($file); + $ret = dol_convert_file($file,'png',$fileimage); if ($ret < 0) $error++; } else