From f902fedbb840cd25aab7f3eaf1f0af3d75c049f2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 13 Sep 2012 17:43:24 +0200 Subject: [PATCH] Fix: split for more possibility --- htdocs/comm/propal/list.php | 6 +- htdocs/core/class/html.formfile.class.php | 126 +++++++++++++--------- 2 files changed, 81 insertions(+), 51 deletions(-) diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index 81f56e21366..7092e8dc180 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -35,7 +35,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; -if ($conf->projet->enabled) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +if (! empty($conf->projet->enabled)) + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; $langs->load('companies'); $langs->load('propal'); @@ -319,7 +320,8 @@ if ($result) $filename=dol_sanitizeFileName($objp->ref); $filedir=$conf->propal->dir_output . '/' . dol_sanitizeFileName($objp->ref); $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->propalid; - $formfile->show_documents('propal',$filename,$filedir,$urlsource,'','','',1,'',1); + //$formfile->show_documents('propal',$filename,$filedir,$urlsource,'','','',1,'',1); + print $formfile->getDocumentsLink('propal', $filename, $filedir); print ''; if ($objp->client == 1) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index db2cdb8cfcb..edef760ec00 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -182,7 +182,7 @@ class FormFile * @param string $modelselected Model to preselect by default * @param string $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning) * @param string $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) - * @param int $iconPDF Show only PDF icon with link (1/0) + * @param int $iconPDF Obsolete, see getDocumentsLink * @param int $maxfilenamelength Max length for filename shown * @param string $noform Do not output html form tags * @param string $param More param on http links @@ -199,18 +199,15 @@ class FormFile global $langs,$bc,$conf; + // For backward compatibility + if (! empty($iconPDF)) { + return $this->getDocumentsLink($modulepart, $filename, $filedir); + } + $forname='builddoc'; $out=''; $var=true; - // Clean paramaters - if ($iconPDF == 1) - { - $genallowed = ''; - $delallowed = 0; - $modelselected = ''; - $forcenomultilang=0; - } //$filename = dol_sanitizeFileName($filename); //Must be sanitized before calling show_documents $headershown=0; $showempty=0; @@ -440,29 +437,17 @@ class FormFile } // Get list of files - if ($filedir) + if (! empty($filedir)) { - $png = ''; - $filter = ''; - if ($iconPDF==1) - { - $png = '\.png$'; - $filter = $filename.'.pdf'; - } - $file_list=dol_dir_list($filedir,'files',0,$filter,'\.meta$'.($png?'|'.$png:''),'date',SORT_DESC); + $file_list=dol_dir_list($filedir,'files',0,'','\.meta$','date',SORT_DESC); // Affiche en-tete tableau si non deja affiche - if (! empty($file_list) && ! $headershown && ! $iconPDF) + if (! empty($file_list) && ! $headershown) { $headershown=1; $out.= '
'.$titletoshow.'
'; $out.= ''; } - else if (empty($file_list) && ! empty($iconPDF)) - { - // For ajax treatment - $out.= '
'.img_picto('', 'refresh').'
'."\n"; - } // Loop on each file found foreach($file_list as $file) @@ -476,44 +461,37 @@ class FormFile if ($modulepart == 'donation') { $relativepath = get_exdir($filename,2).$file["name"]; } if ($modulepart == 'export') { $relativepath = $file["name"]; } - if (! $iconPDF) $out.= ""; + $out.= ""; // Show file name with link to download - if (! $iconPDF) $out.= ''; - // Show file size - $out.= ''; - // Show file date - $out.= ''; - } + $out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]).' '.dol_trunc($file["name"],$maxfilenamelength); + $out.= ''."\n"; + $out.= ''; + + // Show file size + $size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"])); + $out.= ''; + + // Show file date + $date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"])); + $out.= ''; if ($delallowed) { $out.= ''; } - if (! $iconPDF) $out.= ''; + $out.= ''; $this->numoffiles++; } @@ -533,6 +511,56 @@ class FormFile return $out; } + /** + * Show only Document icon with link + * + * @param string $modulepart propal, facture, facture_fourn, ... + * @param string $filename Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if $filedir is already complete) + * @param string $filedir Directory to scan + * @return string Output string with HTML link of documents (might be empty string) + */ + function getDocumentsLink($modulepart, $filename, $filedir) + { + if (! function_exists('dol_dir_list')) { + include DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + } + + $out=''; + + $file_list=dol_dir_list($filedir, 'files', 0, $filename.'.pdf', '\.meta$|\.png$'); + + // For ajax treatment + $out.= '
'.img_picto('', 'refresh').'
'."\n"; + + if (! empty($file_list)) + { + // Loop on each file found + foreach($file_list as $file) + { + // Define relative path for download link (depends on module) + $relativepath=$file["name"]; // Cas general + if ($filename) $relativepath=$filename."/".$file["name"]; // Cas propal, facture... + // Autre cas + if ($modulepart == 'donation') { + $relativepath = get_exdir($filename,2).$file["name"]; + } + if ($modulepart == 'export') { + $relativepath = $file["name"]; + } + + // Show file name with link to download + $out.= 'hooks_modules contains array array require DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($db); + $hookmanager=new HookManager($this->db); } } $hookmanager->initHooks(array('formfile'));
'; + $out.= ''; $out.= 'trans("File").': '.$file["name"]).' '.dol_trunc($file["name"],$maxfilenamelength); - } - else - { - $out.= img_pdf($file["name"],2); - } - $out.= ''."\n"; - if (! $iconPDF) - { - $size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"])); - $date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"])); - $out.= ''.dol_print_size($size).''.dol_print_date($date, 'dayhour').''.dol_print_size($size).''.dol_print_date($date, 'dayhour').''; - $out.= '