*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* \file htdocs/core/ajax/ajaxdirtree.php
* \ingroup ecm
* \brief This script returns content of a directory for filetree
*/
// This script is called with a POST method.
// Directory to scan (full path) is inside POST['dir'].
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
$res=@include '../../main.inc.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
$openeddir = GETPOST('openeddir');
$modulepart= GETPOST('modulepart');
$selecteddir = jsUnEscape(GETPOST('dir')); // relative path. We must decode using same encoding function used by javascript: escape()
if ($selecteddir != '/') $selecteddir = preg_replace('/\/$/','',$selecteddir); // We removed last '/' except if it is '/'
$langs->load("ecm");
// Define selecteddir (fullpath).
if ($modulepart == 'ecm') $fullpathselecteddir=$conf->ecm->dir_output.'/'.($selecteddir != '/' ? $selecteddir : '');
// Security:
// On interdit les remontees de repertoire ainsi que les pipe dans
// les noms de fichiers.
if (preg_match('/\.\./',$fullpathselecteddir) || preg_match('/[<>|]/',$fullpathselecteddir))
{
dol_syslog("Refused to deliver file ".$original_file);
// Do no show plain path in shown error message
dol_print_error(0,$langs->trans("ErrorFileNameInvalid",GETPOST("file")));
exit;
}
// Check permissions
if ($modulepart == 'ecm')
{
if (! $user->rights->ecm->read) accessforbidden();
}
/*
* View
*/
top_httphead();
//print ''."\n";
$userstatic=new User($db);
$form=new Form($db);
$ecmdirstatic = new EcmDirectory($db);
// Load full tree from database. We will use it to define nbofsubdir and nboffilesinsubdir
if (empty($sqltree)) $sqltree=$ecmdirstatic->get_full_arbo(0);
// Try to find key into $sqltree
$current_ecmdir_id=-1;
foreach($sqltree as $keycursor => $val)
{
//print $val['fullrelativename']." == ".$selecteddir;
if ($val['fullrelativename'] == $selecteddir)
{
$current_ecmdir_id = $keycursor;
}
}
if (file_exists($fullpathselecteddir))
{
$files = @scandir($fullpathselecteddir);
if ($files)
{
natcasesort($files);
if ( count($files) > 2 ) /* The 2 accounts for . and .. */
{
echo "
\n";
// All dirs
foreach( $files as $file ) // $file can be '.', '..', or 'My dir' or 'My file'
{
if ($file == 'temp') continue;
$nbofsubdir=0;
$nboffilesinsubdir=0;
$val=array();
// Loop on all database entries (sqltree) to find the one matching the subdir found into dir to scan
foreach($sqltree as $key => $tmpval)
{
//print "-- key=".$key." - ".$val['fullrelativename']." vs ".(($selecteddir != '/'?$selecteddir.'/':'').$file).'
';
if ($tmpval['fullrelativename'] == (($selecteddir != '/'?$selecteddir.'/':'').$file)) // We found equivalent record into database
{
$val=$tmpval;
$resarray=tree_showpad($sqltree,$key,1);
// Refresh cache for this subdir
if (isset($val['cachenbofdoc']) && $val['cachenbofdoc'] < 0) // Cache is not up to date, so we update it for this directory t
{
$result=$ecmdirstatic->fetch($val['id']);
$ecmdirstatic->ref=$ecmdirstatic->label;
$result=$ecmdirstatic->refreshcachenboffile(0);
$val['cachenbofdoc']=$result;
}
$a=$resarray[0];
$nbofsubdir=$resarray[1];
$nboffilesinsubdir=$resarray[2];
break;
}
}
//print 'modulepart='.$modulepart.' fullpathselecteddir='.$fullpathselecteddir.' - val[fullrelativename] (in database)='.$val['fullrelativename'].' - val[id]='.$val['id'].' - is_dir='.dol_is_dir($fullpathselecteddir . $file).' - file='.$file."\n";
if ($file != '.' && $file != '..' && ((! empty($val['fullrelativename']) && $val['id'] >= 0) || dol_is_dir($fullpathselecteddir . (preg_match('/\/$/',$fullpathselecteddir)?'':'/') . $file)))
{
if (empty($val['fullrelativename'])) // If we did not find entry into database, but found a directory (dol_is_dir was ok at previous test)
{
$val['fullrelativename']=$file; $val['id']=0;
$val['label']=$file;
$val['description']='';
$nboffilesinsubdir=$langs->trans("Unknown");
}
print '- ';
print "";
print dol_escape_htmltag($file);
print "";
print '
';
print '
';
/*print '| ';
print dol_escape_htmltag($file);
print ' | ';*/
// Nb of docs
print '';
print (isset($val['cachenbofdoc']) && $val['cachenbofdoc'] >= 0)?$val['cachenbofdoc']:' ';
print ' | ';
print '';
if ($nbofsubdir > 0 && $nboffilesinsubdir > 0) print '+'.$nboffilesinsubdir.' ';
print ' | ';
// Edit link
print ''.img_view($langs->trans("Edit").' - '.$langs->trans("View")).' | ';
// Add link
//print ''.img_edit_add().' | ';
//print ' | ';
// Info
print '';
$userstatic->id=isset($val['fk_user_c'])?$val['fk_user_c']:0;
$userstatic->lastname=isset($val['login_c'])?$val['login_c']:0;
$htmltooltip=''.$langs->trans("ECMSection").': '.$val['label'].' ';
$htmltooltip=''.$langs->trans("Type").': '.$langs->trans("ECMSectionManual").' ';
$htmltooltip.=''.$langs->trans("ECMCreationUser").': '.$userstatic->getNomUrl(1).' ';
$htmltooltip.=''.$langs->trans("ECMCreationDate").': '.(isset($val['date_c'])?dol_print_date($val['date_c'],"dayhour"):$langs->trans("NeedRefresh")).' ';
$htmltooltip.=''.$langs->trans("Description").': '.$val['description'].' ';
$htmltooltip.=''.$langs->trans("ECMNbOfFilesInDir").': '.((isset($val['cachenbofdoc']) && $val['cachenbofdoc'] >= 0)?$val['cachenbofdoc']:$langs->trans("NeedRefresh")).' ';
if ($nboffilesinsubdir > 0) $htmltooltip.=''.$langs->trans("ECMNbOfFilesInSubDir").': '.$nboffilesinsubdir;
else $htmltooltip.=''.$langs->trans("ECMNbOfSubDir").': '.($nbofsubdir >= 0 ? $nbofsubdir : $langs->trans("NeedRefresh")).' ';
print $form->textwithpicto('',$htmltooltip,1,"info");
print " | ";
print "
\n";
print '
';
//print '
';
print " \n";
}
}
// Enable jquery handlers on new generated HTML objects
print '';
echo "
\n";
}
}
else print "PermissionDenied";
}
// This ajax service is called only when a directory $selecteddir is opened but not closed.
//print '';
if (is_object($db)) $db->close();
?>