NEW Can filter on document name in ECM module for automatic tree

This commit is contained in:
Laurent Destailleur 2017-08-04 13:07:15 +02:00
parent f4a44ced80
commit c107a77722
3 changed files with 66 additions and 11 deletions

View File

@ -32,7 +32,6 @@ if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
if (! isset($mode) || $mode != 'noajax') // For ajax call
{
require_once '../../main.inc.php';
@ -45,6 +44,7 @@ if (! isset($mode) || $mode != 'noajax') // For ajax call
$section=GETPOST("section");
$module=GETPOST("module");
$urlsource=GETPOST("urlsource");
$search_doc_ref=GETPOST('search_doc_ref','alpha');
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
@ -188,12 +188,16 @@ if ($type == 'directory')
if (in_array($module, $automodules))
{
$param.='&module='.$module;
if (isset($search_doc_ref) && $search_doc_ref != '') $param.='&search_doc_ref='.$search_doc_ref;
$textifempty=($section?$langs->trans("NoFileFound"):($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("NoFileFound")));
if ($module == 'company') $excludefiles[]='^contact$'; // The subdir 'contact' contains files of contacts with no id of thirdparty.
$filearray=dol_dir_list($upload_dir,"files",1,'', $excludefiles, $sortfield, $sorting,1);
$formfile->list_of_autoecmfiles($upload_dir,$filearray,$module,$param,1,'',$user->rights->ecm->upload,1,$textifempty,$maxlengthname,$url);
$filter=preg_quote($search_doc_ref, '/');
$filearray=dol_dir_list($upload_dir, "files", 1, $filter, $excludefiles, $sortfield, $sorting,1);
$formfile->list_of_autoecmfiles($upload_dir,$filearray,$module,$param,1,'',$user->rights->ecm->upload,1,$textifempty,$maxlengthname,$url,1);
}
// Manual list
else
@ -211,6 +215,8 @@ if ($type == 'directory')
if ($section)
{
$param.='&section='.$section;
if (isset($search_doc_ref) && $search_doc_ref != '') $param.='&search_doc_ref='.$search_doc_ref;
$textifempty = $langs->trans('NoFileFound');
}
else if ($section === '0') $textifempty='<br><div align="center"><font class="warning">'.$langs->trans("DirNotSynchronizedSyncFirst").'</font></div><br>';

View File

@ -922,9 +922,10 @@ class FormFile
* @param string $sortfield Sort field ('name', 'size', 'position', ...)
* @param string $sortorder Sort order ('ASC' or 'DESC')
* @param int $disablemove 1=Disable move button, 0=Position move is possible.
* @param int $addfilterfields Add line with filters
* @return int <0 if KO, nb of files shown if OK
*/
function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permonobject=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0, $permtoeditline=-1,$upload_dir='',$sortfield='',$sortorder='ASC', $disablemove=1)
function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permonobject=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0, $permtoeditline=-1,$upload_dir='',$sortfield='',$sortorder='ASC', $disablemove=1, $addfilterfields=0)
{
global $user, $conf, $langs, $hookmanager;
global $bc,$bcdd;
@ -1006,6 +1007,18 @@ class FormFile
print '<div class="div-table-responsive-no-min">';
print '<table width="100%" id="tablelines" class="'.($useinecm?'liste noborder':'liste').'">'."\n";
if (! empty($addfilterfields))
{
print '<tr class="liste_titre nodrag nodrop">';
print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref','alpha')).'"></td>';
print '<td></td>';
print '<td></td>';
if (empty($useinecm)) print '<td></td>';
print '<td></td>';
if (! $disablemove) print '<td></td>';
print "</tr>\n";
}
print '<tr class="liste_titre nodrag nodrop">';
print_liste_field_titre('Documents2',$url,"name","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre('Size',$url,"size","",$param,'align="right"',$sortfield,$sortorder);
@ -1291,21 +1304,47 @@ class FormFile
* @param int $useinecm Change output for use in ecm module
* @param int $textifempty Text to show if filearray is empty
* @param int $maxlength Maximum length of file name shown
* @param string $url Full url to use for click links ('' = autodetect)
* @param string $url Full url to use for click links ('' = autodetect)
* @param int $addfilterfields Add line with filters
* @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,$url='')
function list_of_autoecmfiles($upload_dir,$filearray,$modulepart,$param,$forcedownload=0,$relativepath='',$permtodelete=1,$useinecm=0,$textifempty='',$maxlength=0,$url='',$addfilterfields=0)
{
global $user, $conf, $langs;
global $user, $conf, $langs, $form;
global $bc;
global $sortfield, $sortorder;
global $search_doc_ref;
dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
// Show list of documents
if (empty($useinecm)) print load_fiche_titre($langs->trans("AttachedFiles"));
if (empty($url)) $url=$_SERVER["PHP_SELF"];
if (! empty($addfilterfields))
{
print '<form action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="module" value="'.$modulepart.'">';
}
print '<div class="div-table-responsive-no-min">';
print '<table width="100%" class="noborder">'."\n";
if (! empty($addfilterfields))
{
print '<tr class="liste_titre nodrag nodrop">';
print '<td><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
print '<td></td>';
print '<td></td>';
print '<td></td>';
// Action column
print '<td class="liste_titre" align="middle">';
$searchpicto=$form->showFilterButtons();
print $searchpicto;
print '</td>';
print "</tr>\n";
}
print '<tr class="liste_titre">';
$sortref="fullname";
if ($modulepart == 'invoice_supplier') $sortref='level1name';
@ -1490,12 +1529,15 @@ class FormFile
if (count($filearray) == 0)
{
print '<tr '.$bc[false].'><td colspan="4">';
print '<tr '.$bc[false].'><td colspan="5">';
if (empty($textifempty)) print $langs->trans("NoFileFound");
else print $textifempty;
print '</td></tr>';
}
print "</table>";
print '</div>';
if (! empty($addfilterfields)) print '</form>';
// Fin de zone
}

View File

@ -50,10 +50,11 @@ $result = restrictedArea($user, 'ecm', 0);
// Get parameters
$socid=GETPOST('socid','int');
$action=GETPOST('action','aZ09');
$section=GETPOST("section")?GETPOST("section","int"):GETPOST("section_id","int");
$module=GETPOST("module");
$section=GETPOST('section','int')?GETPOST('section','int'):GETPOST('section_id','int');
$module=GETPOST('module','alpha');
if (! $section) $section=0;
$section_dir=GETPOST('section_dir');
$section_dir=GETPOST('section_dir','alpha');
$search_doc_ref=GETPOST('search_doc_ref','alpha');
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
@ -88,6 +89,12 @@ $error=0;
* Actions
*/
// Purge search criteria
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
{
$search_doc_ref='';
}
// Upload file
if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
{