diff --git a/htdocs/compta/facture/mergepdftool.php b/htdocs/compta/facture/mergepdftool.php index 146ee53736c..e8010229a8e 100644 --- a/htdocs/compta/facture/mergepdftool.php +++ b/htdocs/compta/facture/mergepdftool.php @@ -810,10 +810,8 @@ if ($resql) { // Checkbox to merge print ''; - if (! empty($formfile->numoffiles)) + if (! empty($formfile->infofiles['extensions']['pdf'])) print ''; - else - print ' '; print '' ; } else diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index aab33fa56d2..d273eef1462 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -37,6 +37,7 @@ class FormFile var $error; var $numoffiles; + var $infofiles; // Used to return informations by function getDocumentsLink /** @@ -680,16 +681,17 @@ class FormFile * @param string $modulepart propal, facture, facture_fourn, ... * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. * @param string $filedir Directory to scan - * @return string Output string with HTML link of documents (might be empty string) + * @param string $filter Filter filenames on this regex string (Example: '\.pdf$') + * @return string Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles */ - function getDocumentsLink($modulepart, $modulesubdir, $filedir) + function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='') { - if (! function_exists('dol_dir_list')) include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $out=''; - $this->numoffiles=0; + $this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array()); - $file_list=dol_dir_list($filedir, 'files', 0, preg_quote(basename($modulesubdir),'/').'[^\-]+', '\.meta$|\.png$'); + $file_list=dol_dir_list($filedir, 'files', 0, preg_quote(basename($modulesubdir),'/').'[^\-]+', '\.meta$|\.png$'); // Get list of files starting with name fo ref (but not followed by "-" to discard uploaded files) // For ajax treatment $out.= '
'.img_picto('', 'refresh').'
'."\n"; @@ -699,6 +701,8 @@ class FormFile // Loop on each file found foreach($file_list as $file) { + if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) continue; // Discard this. It does not match provided filter. + // Define relative path for download link (depends on module) $relativepath=$file["name"]; // Cas general if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture... @@ -721,7 +725,11 @@ class FormFile $out.= img_mime($relativepath, $file["name"]); $out.= ''."\n"; - $this->numoffiles++; + $this->infofiles['nboffiles']++; + $this->infofiles['files'][]=$file['fullname']; + $ext=pathinfo($file["name"], PATHINFO_EXTENSION); + if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1; + else $this->infofiles['extensions'][$ext]++; } }