New: Work on automatic ecm.

This commit is contained in:
Laurent Destailleur 2011-04-17 18:41:26 +00:00
parent 19f173ec90
commit 22271d7a40
3 changed files with 131 additions and 15 deletions

View File

@ -480,6 +480,7 @@ class FormFile
* @param permtodelete Permission to delete
* @param useinecm Change output for use in ecm module
* @param textifempty Text to show if filearray is empty
* @param maxlength Maximum length of file name shown
* @return int <0 if KO, nb of files shown if OK
*/
function list_of_documents($filearray,$object,$modulepart,$param,$forcedownload=0,$relativepath='',$permtodelete=1,$useinecm=0,$textifempty='',$maxlength=0)
@ -513,7 +514,8 @@ class FormFile
if (! $relativepath) $relativepath=dol_sanitizeFileName($object->ref).'/';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<tr '.$bc[$var].'>';
print '<td>';
//print "XX".$file['name']; //$file['name'] must be utf8
print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
if ($forcedownload) print '&attachment=1';
@ -540,9 +542,106 @@ class FormFile
}
print "</table>";
// Fin de zone
}
/**
* Show list of documents in a directory
* @param filearray Array of files loaded by dol_dir_list function
* @param modulepart Value for modulepart used by download wrapper
* @param param Parameters on sort links
* @param forcedownload Force to open dialog box "Save As" when clicking on file
* @param relativepath Relative path of docs (autodefined if not provided)
* @param permtodelete Permission to delete
* @param useinecm Change output for use in ecm module
* @param textifempty Text to show if filearray is empty
* @param maxlength Maximum length of file name shown
* @return int <0 if KO, nb of files shown if OK
*/
function list_of_autoecmfiles($upload_dir,$filearray,$modulepart,$param,$forcedownload=0,$relativepath='',$permtodelete=1,$useinecm=0,$textifempty='',$maxlength=0)
{
global $user, $conf, $langs;
global $bc;
global $sortfield, $sortorder;
// Affiche liste des documents existant
if (empty($useinecm)) print_titre($langs->trans("AttachedFiles"));
//else { $bc[true]=''; $bc[false]=''; };
$url=$_SERVER["PHP_SELF"];
print '<table width="100%" class="nobordernopadding">';
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Documents2"),$_SERVER["PHP_SELF"],"name","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Size"),$_SERVER["PHP_SELF"],"size","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"date","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre('','','');
print '</tr>';
if ($modulepart == 'invoice_supplier')
{
include_once(DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php');
$object_static=new FactureFournisseur($this->db);
}
$var=true;
foreach($filearray as $key => $file)
{
if (!is_dir($dir.$file['name'])
&& $file['name'] != '.'
&& $file['name'] != '..'
&& $file['name'] != 'CVS'
&& ! preg_match('/\.meta$/i',$file['name']))
{
// Define relative path used to store the file
$relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
//print 'eeee'.$relativefile;
//var_dump($file);
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>';
$id='';$ref='';
if ($modulepart == 'invoice_supplier')
{
preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg);
$id=$reg[1];
$object_static->fetch($id);
//print $relativefile.'rr'.$id;
print $object_static->getNomUrl(1);
}
print '</td>';
print '<td>';
//print "XX".$file['name']; //$file['name'] must be utf8
print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
if ($forcedownload) print '&attachment=1';
print '&file='.urlencode($relativefile).'">';
print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')').' ';
print dol_trunc($file['name'],$maxlength,'middle');
print '</a>';
print "</td>\n";
print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>';
print '<td align="right">';
if (! empty($useinecm)) print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
if ($forcedownload) print '&attachment=1';
print '&file='.urlencode($relativefile).'">';
print img_view().'</a> &nbsp; ';
//if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
//else print '&nbsp;';
print "</td></tr>\n";
}
}
if (sizeof($filearray) == 0)
{
print '<tr '.$bc[$var].'><td colspan="4">';
if (empty($textifempty)) print $langs->trans("NoFileFound");
else print $textifempty;
print '</td></tr>';
}
print "</table>";
// Fin de zone
}
}
?>

View File

@ -423,9 +423,9 @@ class EcmDirectory // extends CommonObject
}
/**
* \brief Return relative path of a directory on disk
* \param force Force reload of full arbo even if already loaded
* \return string Relative physical path
* Return relative path of a directory on disk
* @param force Force reload of full arbo even if already loaded
* @return string Relative physical path
*/
function getRelativePath($force=0)
{

View File

@ -55,6 +55,7 @@ $user->getrights('ecm');
$socid=GETPOST('socid');
$action=GETPOST("action");
$section=GETPOST("section");
$module=GETPOST("module");
if (! $section) $section=0;
$upload_dir = $conf->ecm->dir_output.'/'.$section;
@ -357,9 +358,9 @@ if ($conf->societe->enabled) { $rowspan++; $sectionauto[]=array('level'=>1,
if ($conf->propal->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'propal', 'test'=>$conf->propal->enabled, 'label'=>$langs->trans("Prop"), 'desc'=>$langs->trans("ECMDocsByProposals")); }
if ($conf->contrat->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'contract','test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")); }
if ($conf->commande->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'order', 'test'=>$conf->commande->enabled,'label'=>$langs->trans("CustomersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); }
if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'order_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersInvoices"), 'desc'=>$langs->trans("ECMDocsByOrders")); }
if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'order_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); }
if ($conf->facture->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice', 'test'=>$conf->facture->enabled, 'label'=>$langs->trans("CustomersInvoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); }
if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); }
if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersInvoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); }
//***********************
@ -804,15 +805,31 @@ else
print '</td><td valign="top" style="background: #FFFFFF">';
}
// Right area
$relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1);
$formfile=new FormFile($db);
$param='&amp;section='.$section;
$textifempty=($section?$langs->trans("NoFileFound"):($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("ECMSelectASection")));
$formfile->list_of_documents($filearray,'','ecm',$param,1,$relativepath,$user->rights->ecm->upload,1,$textifempty,40);
// Right area
if ($module == 'invoice_supplier') // Auto area for suppliers invoices
{
$relativepath='facture';
$upload_dir = $conf->fournisseur->dir_output.'/'.$relativepath;
$filearray=dol_dir_list($upload_dir,"files",1,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1);
$param='&amp;module='.$module;
$textifempty=($section?$langs->trans("NoFileFound"):($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("ECMSelectASection")));
$formfile->list_of_autoecmfiles($upload_dir,$filearray,$module,$param,1,'',$user->rights->ecm->upload,1,$textifempty,40);
}
else // Manual area
{
$relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1);
$param='&amp;section='.$section;
$textifempty=($section?$langs->trans("NoFileFound"):($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("ECMSelectASection")));
$formfile->list_of_documents($filearray,'','ecm',$param,1,$relativepath,$user->rights->ecm->upload,1,$textifempty,40);
}
// print '<table width="100%" class="border">';