diff --git a/htdocs/actioncomm.class.php b/htdocs/actioncomm.class.php index e89c6341438..2e997c7341f 100644 --- a/htdocs/actioncomm.class.php +++ b/htdocs/actioncomm.class.php @@ -229,6 +229,7 @@ class ActionComm $obj = $this->db->fetch_object($resql); $this->id = $obj->id; + $this->ref = $obj->id; $this->type_id = $obj->type_id; $this->type_code = $obj->type_code; $transcode=$langs->trans("Action".$obj->code); diff --git a/htdocs/comm/action/document.php b/htdocs/comm/action/document.php index 2702b7a913e..9e578a0fe86 100755 --- a/htdocs/comm/action/document.php +++ b/htdocs/comm/action/document.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005 Regis Houssin * Copyright (C) 2005 Simon TOSSER @@ -18,22 +18,20 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ */ /** \file htdocs/product/document.php \ingroup product \brief Page des documents joints sur les produits - \version $Revision$ + \version $Id$ */ require_once("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/cactioncomm.class.php"); require_once(DOL_DOCUMENT_ROOT."/actioncomm.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); $langs->load("companies"); @@ -149,37 +147,14 @@ if ($_GET["id"] > 0) print ''; // Construit liste des fichiers - clearstatcache(); - + $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1); $totalsize=0; - $filearray=array(); - - if (is_dir($upload_dir)) + foreach($filearray as $key => $file) { - $errorlevel=error_reporting(); - error_reporting(0); - $handle=opendir($upload_dir); - error_reporting($errorlevel); - if ($handle) - { - $i=0; - while (($file = readdir($handle))!==false) - { - if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $filearray[$i]=$file; - $totalsize+=filesize($upload_dir."/".$file); - $i++; - } - } - closedir($handle); - } - else - { - print '
'.$langs->trans("ErrorCanNotReadDir",$upload_dir).'
'; - } + $totalsize+=$file['size']; } + print ''.$langs->trans("NbOfAttachedFiles").''.sizeof($filearray).''; print ''.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").''; print ''; @@ -188,52 +163,15 @@ if ($_GET["id"] > 0) if ($mesg) { print $mesg."
"; } + // Affiche formulaire upload $formfile=new FormFile($db); $formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/action/document.php?id='.$act->id); - // Affiche liste des documents existant - print_titre($langs->trans("AttachedFiles")); - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - if (is_dir($upload_dir)) - { - $errorlevel=error_reporting(); - $handle=opendir($upload_dir); - if ($handle) - { - $var=true; - while (($file = readdir($handle))!==false) - { - if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $var=!$var; - print ''; - print '\n"; - print ''; - print ''; - print '\n"; - } - } - closedir($handle); - } - else - { - print '
'.$langs->trans('ErrorCantOpenDir').' '.$upload_dir.'
'; - } - } - print '
'.$langs->trans('Document').''.$langs->trans('Size').''.$langs->trans('Date').' 
'; - echo ''.$file.''; - print "'.filesize($upload_dir.'/'.$file). ' bytes'.dolibarr_print_date(filemtime($upload_dir.'/'.$file),'dayhour').''; - print ''.img_delete($langs->trans('Delete')).''; - print "
'; + + // List of document + $formfile->list_of_documents($upload_dir,$act,'actions'); + } else { diff --git a/htdocs/comm/propal/document.php b/htdocs/comm/propal/document.php index b2671ebce86..40842022ff7 100644 --- a/htdocs/comm/propal/document.php +++ b/htdocs/comm/propal/document.php @@ -29,6 +29,7 @@ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/propal.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); $langs->load('compta'); @@ -111,35 +112,15 @@ if ($propalid > 0) $head = propal_prepare_head($propal); dolibarr_fiche_head($head, 'document', $langs->trans('Proposal')); - // Construit liste des fichiers - clearstatcache(); - - $totalsize=0; - $filearray=array(); - - $errorlevel=error_reporting(); - error_reporting(0); - $handle=opendir($upload_dir); - error_reporting($errorlevel); - if ($handle) - { - $i=0; - while (($file = readdir($handle))!==false) - { - if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $filearray[$i]=$file; - $totalsize+=filesize($upload_dir."/".$file); - $i++; - } - } - closedir($handle); - } - else - { -// print '
'.$langs->trans("ErrorCanNotReadDir",$upload_dir).'
'; - } - + + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + print ''; @@ -162,50 +143,9 @@ if ($propalid > 0) $formfile=new FormFile($db); $formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/propal/document.php?propalid='.$propal->id); - // Affiche liste des documents existant - print_titre($langs->trans("AttachedFiles")); - print '
'; - print ''; - - if (is_dir($upload_dir)) - { - $handle=opendir($upload_dir); - if ($handle) - { - $var=true; - while (($file = readdir($handle))!==false) - { - if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $var=!$var; - print ''; - print '\n"; - print ''; - print ''; - print '\n"; - } - } - closedir($handle); - } - else - { - print '
'.$langs->trans('ErrorCantOpenDir').' '.$upload_dir.'
'; - } - - } - print '
'.$langs->trans("Document").''.$langs->trans("Size").''.$langs->trans("Date").' 
'; - echo ''.$file.''; - print "'.filesize($upload_dir.'/'.$file). ' bytes'.dolibarr_print_date(filemtime($upload_dir.'/'.$file),'dayhour').''; - if ($file == $propref . '.pdf') - { - echo '-'; - } - else - { - echo ''.img_delete($langs->trans('Delete')).''; - } - print "
'; + // List of document + $formfile->list_of_documents($upload_dir,$propal,'propal'); } else diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php index f9edc272dea..3f9c2a3f86a 100644 --- a/htdocs/commande/document.php +++ b/htdocs/commande/document.php @@ -28,6 +28,7 @@ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT.'/lib/order.lib.php'); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); if (!$user->rights->commande->lire) @@ -105,38 +106,15 @@ if ($id > 0) $head = commande_prepare_head($commande); dolibarr_fiche_head($head, 'documents', $langs->trans('CustomerOrder')); - // Construit liste des fichiers - clearstatcache(); - $totalsize=0; - $filearray=array(); - - $errorlevel=error_reporting(); - error_reporting(0); - $handle=opendir($upload_dir); - error_reporting($errorlevel); - if ($handle) - { - $i=0; - while (($file = readdir($handle))!==false) + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1); + $totalsize=0; + foreach($filearray as $key => $file) { - if (! is_dir($dir.$file) - && ! eregi('^\.',$file) - && ! eregi('^CVS',$file) - && ! eregi('\.meta$',$file)) - { - $filearray[$i]=$file; - $totalsize+=filesize($upload_dir."/".$file); - $i++; - } + $totalsize+=$file['size']; } - closedir($handle); - } - else - { - // print '
'.$langs->trans("ErrorCanNotReadDir",$upload_dir).'
'; - } - + print ''; @@ -151,63 +129,15 @@ if ($id > 0) if ($mesg) { print $mesg."
"; } + // Affiche formulaire upload $formfile=new FormFile($db); $formfile->form_attach_new_file(DOL_URL_ROOT.'/commande/document.php?id='.$commande->id); - // Affiche liste des documents existant - print_titre($langs->trans("AttachedFiles")); - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - if (is_dir($upload_dir)) - { - $handle=opendir($upload_dir); - if ($handle) - { - $var=true; - while (($file = readdir($handle))!==false) - { - if (! is_dir($dir.$file) - && ! eregi('^\.',$file) - && ! eregi('^CVS',$file) - && ! eregi('\.meta$',$file)) - { - $var=!$var; - print ''; - print '\n"; - print ''; - print ''; - print '\n"; - } - } - closedir($handle); - } - else - { - print '
'.$langs->trans('ErrorCantOpenDir').' '.$upload_dir.'
'; - } - - } - print '
'.$langs->trans("Document").''.$langs->trans("Size").''.$langs->trans("Date").' 
'; - echo ''.$file.''; - print "'.filesize($upload_dir.'/'.$file). ' '.$langs->trans("bytes").''.dolibarr_print_date(filemtime($upload_dir.'/'.$file),'dayhour').''; - if ($file == $facref . '.pdf') - { - echo '-'; - } - else - { - echo ''.img_delete($langs->trans('Delete')).''; - } - print "
'; - + + // List of document + $formfile->list_of_documents($upload_dir,$commande,'commande'); + } else { diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php index 8fdfc55d010..6d032003543 100644 --- a/htdocs/compta/facture/document.php +++ b/htdocs/compta/facture/document.php @@ -17,20 +17,19 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** \file htdocs/compta/facture/document.php \ingroup facture \brief Page de gestion des documents attachées à une facture - \version $Revision$ + \version $Id$ */ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/invoice.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); $langs->load('propal'); @@ -78,9 +77,10 @@ if ($_POST["sendit"] && $conf->upload) // Delete if ($action=='delete') { - $facture = new Facture($db); + $facture = new Facture($db); - if ($facture->fetch($facid)) + $facid=$_GET["id"]; + if ($facture->fetch($facid)) { $upload_dir = $conf->facture->dir_output . "/" . $facture->ref; $file = $upload_dir . '/' . urldecode($_GET['urlfile']); @@ -111,37 +111,15 @@ if ($facid > 0) $head = facture_prepare_head($facture); dolibarr_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer')); - // Construit liste des fichiers - clearstatcache(); - - $totalsize=0; - $filearray=array(); - - $errorlevel=error_reporting(); - error_reporting(0); - $handle=opendir($upload_dir); - error_reporting($errorlevel); - if ($handle) - { - $i=0; - while (($file = readdir($handle))!==false) - { - if (! is_dir($dir.$file) - && ! eregi('^\.',$file) - && ! eregi('^CVS',$file) - && ! eregi('\.meta$',$file)) - { - $filearray[$i]=$file; - $totalsize+=filesize($upload_dir."/".$file); - $i++; - } - } - closedir($handle); - } - else - { - // print '
'.$langs->trans("ErrorCanNotReadDir",$upload_dir).'
'; - } + + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + print ''; @@ -159,60 +137,14 @@ if ($facid > 0) if ($mesg) { print $mesg."
"; } + // Affiche formulaire upload $formfile=new FormFile($db); $formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/facture/document.php?facid='.$facture->id); - - // Affiche liste des documents existant - print_titre($langs->trans("AttachedFiles")); - print '
'; - print ''; - print ''; - print ''; - print ''; - print "\n"; - if (is_dir($upload_dir)) - { - $handle=opendir($upload_dir); - if ($handle) - { - $var=true; - while (($file = readdir($handle))!==false) - { - if (! is_dir($dir.$file) - && ! eregi('^\.',$file) - && ! eregi('^CVS',$file) - && ! eregi('\.meta$',$file)) - { - $var=!$var; - print ''; - print '\n"; - print ''; - print ''; - print '\n"; - } - } - closedir($handle); - } - else - { - print '
'.$langs->trans('ErrorCantOpenDir').' '.$upload_dir.'
'; - } - } - print '
'.$langs->trans("Document").''.$langs->trans("Size").''.$langs->trans("Date").' 
'; - echo ''.$file.''; - print "'.filesize($upload_dir.'/'.$file). ' '.$langs->trans("bytes").''.dolibarr_print_date(filemtime($upload_dir.'/'.$file),'dayhour').''; - if ($file == $facref . '.pdf') - { - echo '-'; - } - else - { - echo ''.img_delete($langs->trans('Delete')).''; - } - print "
'; + // List of document + $formfile->list_of_documents($upload_dir,$facture,'facture'); } else diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php index 9b189bba14c..f7baed4f045 100644 --- a/htdocs/contrat/document.php +++ b/htdocs/contrat/document.php @@ -21,15 +21,16 @@ */ /** - \file htdocs/product/document.php - \ingroup product - \brief Page des documents joints sur les produits + \file htdocs/contrat/document.php + \ingroup contrat + \brief Page des documents joints sur les contrats \version $Id$ */ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT."/lib/contract.lib.php"); require_once(DOL_DOCUMENT_ROOT."/contrat/contrat.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); $langs->load("other"); @@ -105,34 +106,14 @@ if ($contrat->id) dolibarr_fiche_head($head, 'documents', $langs->trans("Contract")); - // Construit liste des fichiers - clearstatcache(); - - $totalsize=0; - $filearray=array(); - - $errorlevel=error_reporting(); - error_reporting(0); - $handle=opendir($upload_dir); - error_reporting($errorlevel); - if ($handle) - { - $i=0; - while (($file = readdir($handle))!==false) - { - if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $filearray[$i]=$file; - $totalsize+=filesize($upload_dir."/".$file); - $i++; - } - } - closedir($handle); - } - else - { -// print '
'.$langs->trans("ErrorCanNotReadDir",$upload_dir).'
'; - } + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + print ''; @@ -154,53 +135,9 @@ if ($contrat->id) $formfile=new FormFile($db); $formfile->form_attach_new_file(DOL_URL_ROOT.'/contrat/document.php?id='.$contrat->id); - - $errorlevel=error_reporting(); - error_reporting(0); - $handle=opendir($upload_dir); - error_reporting($errorlevel); - - print '
'; - // Affiche liste des documents existant - print_titre($langs->trans("AttachedFiles")); - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $var=true; - - if ($handle) - { - while (($file = readdir($handle))!==false) - { - if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $var=!$var; - print ''; - print '\n"; - print ''; - print ''; - print '\n"; - } - } - closedir($handle); - } - print '
'.$langs->trans('Document').''.$langs->trans('Size').''.$langs->trans('Date').' 
'; - echo ''.$file.''; - print "'.filesize($upload_dir.'/'.$file). ' bytes'.dolibarr_print_date(filemtime($upload_dir.'/'.$file),'dayhour').''; - if ($file == $propref . '.pdf') - { - echo '-'; - } - else - { - echo ''.img_delete($langs->trans('Delete')).''; - } - print "
'; + // List of document + $formfile->list_of_documents($upload_dir,$contrat,'contract'); } else diff --git a/htdocs/ecm/docmine.php b/htdocs/ecm/docmine.php index fcb46462831..f136b6142a4 100644 --- a/htdocs/ecm/docmine.php +++ b/htdocs/ecm/docmine.php @@ -160,6 +160,11 @@ $form=new Form($db); // Construit liste des fichiers $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1); +$totalsize=0; +foreach($filearray as $key => $file) +{ + $totalsize+=$file['size']; +} $head = ecm_prepare_head($ecmdir); @@ -191,7 +196,7 @@ while ($tmpecmdir && $result > 0) $tmpecmdir=0; } } -//print img_picto('','object_dir').' '.$langs->trans("ECMRoot").''; +print img_picto('','object_dir').' '.$langs->trans("ECMRoot").' -> '; print $s; print ''; print ''.$langs->trans("Description").''; @@ -219,11 +224,6 @@ print ''.$langs->trans("ECMNbOfDocs").''; print sizeof($filearray); print ''; print ''.$langs->trans("TotalSizeOfAttachedFiles").''; -$totalsize=0; -foreach($filearray as $key => $file) -{ - $totalsize+=$file['size']; -} print dol_print_size($totalsize); print ''; if ($_GET["action"] == 'edit') diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index a611e3e540f..d8cb74813b4 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -117,6 +117,18 @@ $form=new Form($db); $ecmdirstatic = new ECMDirectory($db); $userstatic = new User($db); + +// Ajout rubriques automatiques +$rowspan=0; +$sectionauto=array(); +if ($conf->societe->enabled) { $rowspan++; $sectionauto[]=array('test'=>$conf->societe->enabled, 'label'=>$langs->trans("ThirdParties"), 'desc'=>$langs->trans("ECMDocsByThirdParties")); } +if ($conf->propal->enabled) { $rowspan++; $sectionauto[]=array('test'=>$conf->propal->enabled, 'label'=>$langs->trans("Proposals"), 'desc'=>$langs->trans("ECMDocsByProposals")); } +if ($conf->commande->enabled) { $rowspan++; $sectionauto[]=array('test'=>$conf->commande->enabled,'label'=>$langs->trans("Orders"), 'desc'=>$langs->trans("ECMDocsByOrders")); } +if ($conf->contrat->enabled) { $rowspan++; $sectionauto[]=array('test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")); } +if ($conf->facture->enabled) { $rowspan++; $sectionauto[]=array('test'=>$conf->facture->enabled, 'label'=>$langs->trans("Invoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); } +if ($conf->produit->enabled) { $rowspan++; $sectionauto[]=array('test'=>$conf->produit->enabled, 'label'=>$langs->trans("ProductsAndServices"), 'desc'=>$langs->trans("ECMDocsByProducts")); } + + //*********************** // List //*********************** @@ -150,14 +162,16 @@ print ''; print ""; print ''; -$buthtml=''; -$butshown=0; -if ($conf->societe->enabled) { print "'.($butshown?'':$buthtml).''; $butshown=1; } -if ($conf->contrat->enabled) { print "'.($butshown?'':$buthtml).''; $butshown=1; } -if ($conf->propal->enabled) { print "'.($butshown?'':$buthtml).''; $butshown=1; } -if ($conf->commande->enabled) { print "'.($butshown?'':$buthtml).''; $butshown=1; } -if ($conf->facture->enabled) { print "'.($butshown?'':$buthtml).''; $butshown=1; } + +$buthtml=''; +$butshown=0; +if ($conf->societe->enabled) { print "'.($butshown?'':$buthtml).''; $butshown++; } +if ($conf->contrat->enabled) { print "'.($butshown?'':$buthtml).''; $butshown++; } +if ($conf->propal->enabled) { print "'.($butshown?'':$buthtml).''; $butshown++; } +if ($conf->commande->enabled) { print "'.($butshown?'':$buthtml).''; $butshown++; } +if ($conf->facture->enabled) { print "'.($butshown?'':$buthtml).''; $butshown++; } +if ($conf->produit->enabled) { print "'.($butshown?'':$buthtml).''; $butshown++; } print "
'.$langs->trans("ECMSearchByEntity").'
".$langs->trans("ThirdParty").':
".$langs->trans("Contrat").':
".$langs->trans("Proposal").':
".$langs->trans("Order").':
".$langs->trans("Invoice").':
".$langs->trans("ThirdParty").':
".$langs->trans("Contrat").':
".$langs->trans("Proposal").':
".$langs->trans("Order").':
".$langs->trans("Invoice").':
".$langs->trans("ProductsAndServices").':

"; //print $langs->trans("ECMAutoOrgDesc"); @@ -184,14 +198,6 @@ if ($mesg) { print $mesg."
"; } // Construit liste des répertoires print ''; -// Ajout rubriques automatiques -$sectionauto=array(); -if ($conf->societe->enabled) $sectionauto[]=array('test'=>$conf->societe->enabled, 'label'=>$langs->trans("ThirdParties"), 'desc'=>$langs->trans("ECMDocsByThirdParties")); -if ($conf->propal->enabled) $sectionauto[]=array('test'=>$conf->propal->enabled, 'label'=>$langs->trans("Proposals"), 'desc'=>$langs->trans("ECMDocsByProposals")); -if ($conf->commande->enabled) $sectionauto[]=array('test'=>$conf->commande->enabled,'label'=>$langs->trans("Orders"), 'desc'=>$langs->trans("ECMDocsByOrders")); -if ($conf->contrat->enabled) $sectionauto[]=array('test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")); -if ($conf->facture->enabled) $sectionauto[]=array('test'=>$conf->facture->enabled, 'label'=>$langs->trans("Invoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); - if (sizeof($sectionauto)) { // Automatic sections diff --git a/htdocs/fourn/facture/document.php b/htdocs/fourn/facture/document.php index c6d7beff3eb..e47b0e9c995 100644 --- a/htdocs/fourn/facture/document.php +++ b/htdocs/fourn/facture/document.php @@ -29,6 +29,7 @@ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT.'/fourn/fournisseur.facture.class.php'); require_once(DOL_DOCUMENT_ROOT.'/lib/fourn.lib.php'); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); $langs->load('bills'); @@ -81,6 +82,7 @@ if ($action=='delete') { $facture = new FactureFournisseur($db); + $facid=$_GET["id"]; if ($facture->fetch($facid)) { $ref = sanitize_string($facture->ref); @@ -111,35 +113,15 @@ if ($facid > 0) $head = facturefourn_prepare_head($facture); dolibarr_fiche_head($head, 'documents', $langs->trans('SupplierInvoice')); - // Construit liste des fichiers - clearstatcache(); - - $totalsize=0; - $filearray=array(); - - $errorlevel=error_reporting(); - error_reporting(0); - $handle=opendir($upload_dir); - error_reporting($errorlevel); - if ($handle) - { - $i=0; - while (($file = readdir($handle))!==false) - { - if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $filearray[$i]=$file; - $totalsize+=filesize($upload_dir.'/'.$file); - $i++; - } - } - closedir($handle); - } - else - { -// print '
'.$langs->trans("ErrorCanNotReadDir",$upload_dir).'
'; - } + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + print '
'; @@ -163,58 +145,15 @@ if ($facid > 0) if ($mesg) { print $mesg.'
'; } + // Affiche formulaire upload $formfile=new FormFile($db); $formfile->form_attach_new_file(DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$facture->id); - // Affiche liste des documents existant - print_titre($langs->trans('AttachedFiles')); - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - if (is_dir($upload_dir)) - { - $handle=opendir($upload_dir); - if ($handle) - { - $var=true; - while (($file = readdir($handle))!==false) - { - if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $var=!$var; - print ''; - print '\n"; - print ''; - print ''; - print '\n"; - } - } - closedir($handle); - } - else - { - print '
'.$langs->trans('ErrorCantOpenDir').' '.$upload_dir.'
'; - } - } - print '
'.$langs->trans('Document').''.$langs->trans('Size').''.$langs->trans('Date').' 
'; - echo ''.$file.''; - print "'.filesize($upload_dir.'/'.$file). ' bytes'.dolibarr_print_date(filemtime($upload_dir.'/'.$file),'dayhour').''; - if ($file == $facref . '.pdf') - { - echo '-'; - } - else - { - echo ''.img_delete($langs->trans('Delete')).''; - } - print "
'; + // List of document + $formfile->list_of_documents($upload_dir,$facture,'facture_fournisseur'); + } else { diff --git a/htdocs/html.formfile.class.php b/htdocs/html.formfile.class.php index 4aafc32d536..6a24a2f8dd0 100644 --- a/htdocs/html.formfile.class.php +++ b/htdocs/html.formfile.class.php @@ -91,8 +91,9 @@ class FormFile print ''; } - print ' ('.$langs->trans("MaxSize").': '.$max.' '.$langs->trans("Kb").')'; - + print ' ('.$langs->trans("MaxSize").': '.$max.' '.$langs->trans("Kb"); + print ' '.info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1); + print ')'; print ""; print ""; @@ -363,6 +364,70 @@ class FormFile return ($i?$i:$headershown); } + + /** + * \brief Show list of documents in a directory + * \param upload_dir Dir to scan + * \param object Object on which document is linked to + * \param modulepart Value for modulepart used by download wrapper + * \return int <0 if KO, nb of files shown if OK + */ + function list_of_documents($upload_dir,$object,$modulepart) + { + global $user, $conf, $langs; + global $bc; + + // List of documents + $errorlevel=error_reporting(); + error_reporting(0); + $handle=opendir($upload_dir); + error_reporting($errorlevel); + + // Affiche liste des documents existant + print_titre($langs->trans("AttachedFiles")); + + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $var=true; + + if ($handle) + { + while (($file = readdir($handle))!==false) + { + if (!is_dir($dir.$file) + && $file != '.' + && $file != '..' + && $file != 'CVS' + && ! eregi('\.meta$',$file) + ) + { + // Define relative path used to store the file + $morepath=$object->ref.'/'; + if ($modulepart == 'facture_fournisseur') $morepath=get_exdir($object->id,2).$morepath; + + $var=!$var; + print ''; + print '\n"; + print ''; + print ''; + print '\n"; + } + } + closedir($handle); + } + print '
'.$langs->trans('Document').''.$langs->trans('Size').''.$langs->trans('Date').' 
'; + print img_mime($file).' '; + print ''.$file.''; + print "'.filesize($upload_dir.'/'.$file). ' '.$langs->trans('bytes').''.dolibarr_print_date(filemtime($upload_dir.'/'.$file),'dayhour').''; + print ''.img_delete($langs->trans('Delete')).''; + print "
'; + } } ?> diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 46d60ba62cf..325ea3bb2e3 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -422,6 +422,7 @@ MenuECM=Documents MenuAWStats=AWStats MenuMembers=Members MenuAgendaGoogle=Google agenda +ThisLimitIsDefinedInSetup=Dolibarr limit (Menu home-setup-security): %s Kb, PHP limit: %s Kb # Week day Monday=Monday Tuesday=Tuesday diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 30c67153615..95acc68f342 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -424,6 +424,7 @@ MenuECM=Documents MenuAWStats=AWStats MenuMembers=Adhérents MenuAgendaGoogle=Agenda Google +ThisLimitIsDefinedInSetup=Limite Dolibarr (Menu accueil-configuration-sécurité): %s Ko, Limite PHP: %s Ko # Week day Monday=Lundi Tuesday=Mardi diff --git a/htdocs/product/document.php b/htdocs/product/document.php index ef5c6b98f40..fa395098bcf 100755 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -30,6 +30,7 @@ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); $langs->load("other"); @@ -107,34 +108,14 @@ if ($product->id) dolibarr_fiche_head($head, 'documents', $titre); - // Construit liste des fichiers - clearstatcache(); - - $totalsize=0; - $filearray=array(); - - $errorlevel=error_reporting(); - error_reporting(0); - $handle=opendir($upload_dir); - error_reporting($errorlevel); - if ($handle) - { - $i=0; - while (($file = readdir($handle))!==false) - { - if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $filearray[$i]=$file; - $totalsize+=filesize($upload_dir."/".$file); - $i++; - } - } - closedir($handle); - } - else - { -// print '
'.$langs->trans("ErrorCanNotReadDir",$upload_dir).'
'; - } + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + print ''; @@ -177,53 +158,9 @@ if ($product->id) $formfile->form_attach_new_file(DOL_URL_ROOT.'/product/document.php?id='.$product->id); - $errorlevel=error_reporting(); - error_reporting(0); - $handle=opendir($upload_dir); - error_reporting($errorlevel); - - print '
'; + // List of document + $formfile->list_of_documents($upload_dir,$product,'produit'); - // Affiche liste des documents existant - print_titre($langs->trans("AttachedFiles")); - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $var=true; - - if ($handle) - { - while (($file = readdir($handle))!==false) - { - if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $var=!$var; - print ''; - print '\n"; - print ''; - print ''; - print '\n"; - } - } - closedir($handle); - } - print '
'.$langs->trans('Document').''.$langs->trans('Size').''.$langs->trans('Date').' 
'; - echo ''.$file.''; - print "'.filesize($upload_dir.'/'.$file). ' bytes'.dolibarr_print_date(filemtime($upload_dir.'/'.$file),'dayhour').''; - if ($file == $propref . '.pdf') - { - echo '-'; - } - else - { - echo ''.img_delete($langs->trans('Delete')).''; - } - print "
'; - } else {