From ef6fcbbc67c74cad9cc7e981f00f0fc5de14eadc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 5 Nov 2017 02:04:05 +0100 Subject: [PATCH] Clean code to have the filemanager beeing a reusable component --- htdocs/ecm/index.php | 32 +--- htdocs/ecm/index_auto.php | 31 +--- htdocs/ecm/search.php | 5 +- htdocs/ecm/tpl/enablefiletreeajax.tpl.php | 2 +- htdocs/ecm/tpl/filemanager.tpl.php | 193 ++++++++++++++++++++++ htdocs/website/index.php | 35 ++-- 6 files changed, 237 insertions(+), 61 deletions(-) create mode 100644 htdocs/ecm/tpl/filemanager.tpl.php diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index 1acf33c6343..135f7061adb 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -42,7 +42,6 @@ $result = restrictedArea($user, 'ecm', 0); $socid=GETPOST('socid','int'); $action=GETPOST('action','aZ09'); $section=GETPOST('section','int')?GETPOST('section','int'):GETPOST('section_id','int'); -$module=GETPOST('module','alpha'); if (! $section) $section=0; $section_dir=GETPOST('section_dir','alpha'); @@ -322,7 +321,7 @@ $moreheadjs=''; //$morejs=array(); $morejs=array('includes/jquery/plugins/blockUI/jquery.blockUI.js','core/js/blockUI.js'); // Used by ecm/tpl/enabledfiletreeajax.tpl.pgp -if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $morejs[]="/includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js"; +if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $morejs[]="includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js"; $moreheadjs.=''."\n"; llxHeader($moreheadcss.$moreheadjs,$langs->trans("ECMArea"),'','','','',$morejs,'',0,0); +$head = ecm_prepare_dasboard_head(''); +dol_fiche_head($head, 'index', $langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"), -1, ''); -// Add sections to manage -$rowspan=0; -$sectionauto=array(); -// Confirm remove file (for non javascript users) -if ($action == 'delete' && empty($conf->use_javascript_ajax)) -{ - print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1); +// Add filemanager component +include DOL_DOCUMENT_ROOT.'/ecm/tpl/filemanager.tpl.php'; -} - -if ($module != 'medias') -{ - $head = ecm_prepare_dasboard_head(''); - dol_fiche_head($head, 'index', $langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"), -1, ''); -} +/* // Start container of all panels ?> @@ -498,19 +488,15 @@ include_once DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirpreview.php'; use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) { include DOL_DOCUMENT_ROOT.'/ecm/tpl/enablefiletreeajax.tpl.php'; } +*/ - +// End of page +dol_fiche_end(); llxFooter(); diff --git a/htdocs/ecm/index_auto.php b/htdocs/ecm/index_auto.php index 8a015055478..5a394188c18 100644 --- a/htdocs/ecm/index_auto.php +++ b/htdocs/ecm/index_auto.php @@ -304,7 +304,7 @@ $moreheadjs=''; //$morejs=array(); $morejs=array('includes/jquery/plugins/blockUI/jquery.blockUI.js','core/js/blockUI.js'); // Used by ecm/tpl/enabledfiletreeajax.tpl.pgp -if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $morejs[]="/includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js"; +if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $morejs[]="includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js"; $moreheadjs.=' - + diff --git a/htdocs/ecm/tpl/filemanager.tpl.php b/htdocs/ecm/tpl/filemanager.tpl.php new file mode 100644 index 00000000000..84d73a42540 --- /dev/null +++ b/htdocs/ecm/tpl/filemanager.tpl.php @@ -0,0 +1,193 @@ + + * + * 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 . + * + * Output code for the filemanager + * $module must be defined ('ecm', 'medias', ...) + */ +?> + + + + +use_javascript_ajax)) +{ + print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1); +} + +// Start container of all panels +?> + +
+
+'; + +// Toolbar +if ($user->rights->ecm->setup) +{ + print ''; + print ''; + print ''; +} +else +{ + print ''; + print ''; + print ''; +} +$url=((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))?'#':($_SERVER["PHP_SELF"].'?action=refreshmanual'.($module?'&module='.$module:'').($section?'&section='.$section:''))); +print ''; +print ''; +print ''; + + +// Start "Add new file" area +$nameforformuserfile = 'formuserfileecm'; + +print '
'; + +// To attach new file +if ((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) || ! empty($section)) +{ + if ((empty($section) || $section == -1) && ($module != 'medias')) + { + ?> + + form_attach_new_file($_SERVER["PHP_SELF"], 'none', 0, ($section?$section:-1), $user->rights->ecm->upload, 48, null, '', 0, '', 0, $nameforformuserfile); +} +else print ' '; + +print '
'; +// End "Add new file" area + + +print '
'; +// End top panel, toolbar + +?> +
+
+formconfirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1); +} +// End confirm + + +if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action) || $action == 'delete') +{ + print ''."\n"; + + print ''."\n"; + print ''."\n"; + print ''; + + $showonrightsize=''; + + // Manual section + $htmltooltip=$langs->trans("ECMAreaDesc2"); + + if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) + { + print ''; + } + else + { + print ''; + } + + + print "
'; + print ' '.$langs->trans("ECMSections"); + print '
'; + + // 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'); + + 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 '
'; + + $mode='noajax'; + $url=DOL_URL_ROOT.'/ecm/index.php'; + include DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirtree.php'; + + print '
'; + print '
"; +} + + +// End left panel +?> +
+
+
+
+ +
+
+ +
+ +use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) { + include DOL_DOCUMENT_ROOT.'/ecm/tpl/enablefiletreeajax.tpl.php'; +} + +?> + diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 1065a811047..45867093722 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -57,7 +57,7 @@ if (GETPOST('delete')) { $action='delete'; } if (GETPOST('preview')) $action='preview'; if (GETPOST('createsite')) { $action='createsite'; } if (GETPOST('create')) { $action='create'; } -if (GETPOST('editmedias')) { $action='editmedias'; } +if (GETPOST('file_manager')) { $action='file_manager'; } if (GETPOST('editcss')) { $action='editcss'; } if (GETPOST('editmenu')) { $action='editmenu'; } if (GETPOST('setashome')) { $action='setashome'; } @@ -1094,7 +1094,18 @@ $arrayofjs = array( ); $arrayofcss = array(); -llxHeader('', $langs->trans("websiteetup"), $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', '', ''."\n".'
'); +$moreheadcss=''; +$moreheadjs=''; + +$arrayofjs[]='includes/jquery/plugins/blockUI/jquery.blockUI.js'; +$arrayofjs[]='core/js/blockUI.js'; // Used by ecm/tpl/enabledfiletreeajax.tpl.pgp +if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $arrayofjs[]="includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js"; + +$moreheadjs.=''."\n"; + +llxHeader($moreheadcss.$moreheadjs, $langs->trans("websiteetup"), $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', '', ''."\n".'
'); print "\n".'
'; print ''; @@ -1199,7 +1210,7 @@ if (count($object->records) > 0) print '   '; - print ''; + print ''; } print '
'; @@ -1227,10 +1238,10 @@ if (count($object->records) > 0) print ''; } - if (in_array($action, array('editcss','editmenu','editmedias'))) + if (in_array($action, array('editcss','editmenu','file_manager'))) { - if (preg_match('/^create/',$action) && $action != 'editmedias') print ''; - if (preg_match('/^edit/',$action) && $action != 'editmedias') print ''; + if (preg_match('/^create/',$action) && $action != 'file_manager') print ''; + if (preg_match('/^edit/',$action) && $action != 'file_manager') print ''; if ($action != 'preview') print ''; } @@ -1239,7 +1250,7 @@ if (count($object->records) > 0) // ***** Part for pages - if ($website && ! in_array($action, array('editcss','editmenu','editmedias'))) + if ($website && ! in_array($action, array('editcss','editmenu','file_manager'))) { print '
'; // Close current websitebar to open a new one @@ -1377,7 +1388,7 @@ if (count($object->records) > 0) // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext } - if (! in_array($action, array('editcss','editmenu','editmedias','createsite','create','createpagefromclone'))) + if (! in_array($action, array('editcss','editmenu','file_manager','createsite','create','createpagefromclone'))) { if (preg_match('/^create/',$action)) print ''; if (preg_match('/^edit/',$action)) print ''; @@ -1774,10 +1785,14 @@ if ($action == 'editmeta' || $action == 'create') print '
'; } -if ($action == 'editmedias') +if ($action == 'file_manager') { print ''."\n"; - print '
'.$langs->trans("FeatureNotYetAvailable").''; + print '

'; + //print '
'.$langs->trans("FeatureNotYetAvailable").''; + + $module = 'medias'; + include DOL_DOCUMENT_ROOT.'/ecm/tpl/filemanager.tpl.php'; } if ($action == 'editmenu')