diff --git a/htdocs/core/ajax/ajaxdirtree.php b/htdocs/core/ajax/ajaxdirtree.php index ea4bf830e21..2390e163239 100644 --- a/htdocs/core/ajax/ajaxdirtree.php +++ b/htdocs/core/ajax/ajaxdirtree.php @@ -23,25 +23,35 @@ // This script is called with a POST method. -// Directory to scan (full path) is inside POST['dir']. +// Directory to scan (full path) is inside POST['dir'] and encode by js escape() if ajax is used or encoded by urlencode if mode=noajax 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'; +if (! isset($mode) || $mode != 'noajax') // For ajax call +{ + $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 '/' + $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 '/' +} +else // For no ajax call +{ + $openeddir = GETPOST('openeddir'); + $modulepart= GETPOST('modulepart'); + $selecteddir = GETPOST('dir'); + if ($selecteddir != '/') $selecteddir = preg_replace('/\/$/','',$selecteddir); // We removed last '/' except if it is '/' + if (empty($url)) $url=DOL_URL_ROOT.'/ecm/index.php'; +} $langs->load("ecm"); @@ -76,7 +86,10 @@ if ($modulepart == 'medias') * View */ -top_httphead(); +if (! isset($mode) || $mode != 'noajax') +{ + top_httphead(); +} //print ''."\n"; $userstatic=new User($db); @@ -97,151 +110,320 @@ foreach($sqltree as $keycursor => $val) } } - -if (file_exists($fullpathselecteddir)) +if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) { - $files = @scandir($fullpathselecteddir); + if (file_exists($fullpathselecteddir)) + { + $files = @scandir($fullpathselecteddir); - if ($files) - { - natcasesort($files); - if ( count($files) > 2 ) /* The 2 accounts for . and .. */ - { - echo "\n"; - } - } - else print "PermissionDenied"; + } + } + else print "PermissionDenied"; + } + + // This ajax service is called only when a directory $selecteddir is opened but not when closed. + //print ''; } -// This ajax service is called only when a directory $selecteddir is opened but not when closed. -//print ''; -if (is_object($db)) $db->close(); +if (empty($conf->use_javascript_ajax) || ! empty($conf->global->MAIN_ECM_DISABLE_JS)) +{ + print ''; +} + + +// Close db if mode is not noajax +if ((! isset($mode) || $mode != 'noajax') && is_object($db)) $db->close(); diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index 77fb16f5afd..e9f3af7c255 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -14,13 +14,14 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * You can call this page with param module=medias to get a filemanager for medias. */ /** * \file htdocs/ecm/index.php * \ingroup ecm * \brief Main page for ECM section area - * \author Laurent Destailleur */ require '../main.inc.php'; @@ -31,14 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php'; require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; // Load traductions files -$langs->load("ecm"); -$langs->load("companies"); -$langs->load("other"); -$langs->load("users"); -$langs->load("orders"); -$langs->load("propal"); -$langs->load("bills"); -$langs->load("contracts"); +$langs->loadLangs(array("ecm","companies","other","users","orders","propal","bills","contracts")); // Security check if ($user->societe_id) $socid=$user->societe_id; @@ -145,7 +139,6 @@ if ($action == 'confirm_deletefile') { // GETPOST('urlfile','alpha') is full relative URL from ecm root dir. Contains path of all sections. //var_dump(GETPOST('urlfile'));exit; - $langs->load("other"); $upload_dir = $conf->ecm->dir_output.($relativepath?'/'.$relativepath:''); $file = $upload_dir . "/" . GETPOST('urlfile','alpha'); // Do not use urldecode here ($_GET and $_POST are already decoded by PHP). @@ -443,7 +436,7 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti { print ''; - // Show filemanager tree + // Show filemanager tree (will be filled by call of ajax enablefiletreeajax.tpl.php that execute ajaxdirtree.php) print '
'; if ($action == 'deletefile') print $form->formconfirm('eeeee', $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', '', 'deletefile'); @@ -453,164 +446,20 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti else { print ''; + + if (empty($module)) $module='ecm'; + + $_POST['modulepart'] = $module; + $_POST['openeddir'] = GETPOST('openeddir'); + $_POST['dir'] = empty($_POST['dir'])?'/':$_POST['dir']; + + // Show filemanager tree (will be filled by direct include of ajaxdirtree.php in mode noajax, this will return all dir - all levels - to show) print '
'; - print ''; print '
'; print ''; } diff --git a/htdocs/ecm/index_auto.php b/htdocs/ecm/index_auto.php index 3fa2bc1dc7a..a0ceefd5014 100644 --- a/htdocs/ecm/index_auto.php +++ b/htdocs/ecm/index_auto.php @@ -31,14 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php'; require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; // Load traductions files -$langs->load("ecm"); -$langs->load("companies"); -$langs->load("other"); -$langs->load("users"); -$langs->load("orders"); -$langs->load("propal"); -$langs->load("bills"); -$langs->load("contracts"); +$langs->loadLangs(array("ecm","companies","other","users","orders","propal","bills","contracts")); // Security check if ($user->societe_id) $socid=$user->societe_id; diff --git a/htdocs/ecm/tpl/enablefiletreeajax.tpl.php b/htdocs/ecm/tpl/enablefiletreeajax.tpl.php index 3f19e1d666f..7969ee6a458 100644 --- a/htdocs/ecm/tpl/enablefiletreeajax.tpl.php +++ b/htdocs/ecm/tpl/enablefiletreeajax.tpl.php @@ -33,7 +33,7 @@ $(document).ready(function() { $('#filetree').fileTree({ root: '', - // Ajax called if we click to expand a dir (not a file). Parameter of dir is provided as a POST parameter. + // Ajax called if we click to expand a dir (not a file). Parameter 'dir' is provided as a POST parameter by fileTree code. script: '', folderEvent: 'click', // 'dblclick' multiFolder: false },