Clean code to have the filemanager beeing a reusable component

This commit is contained in:
Laurent Destailleur
2017-11-05 02:04:05 +01:00
parent 05ee3e3825
commit ef6fcbbc67
6 changed files with 237 additions and 61 deletions

View File

@@ -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.='<script type="text/javascript">'."\n";
$moreheadjs.='var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'\';'."\n";
@@ -330,24 +329,15 @@ $moreheadjs.='</script>'."\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
?>
<!-- Begin div id="containerlayout" -->
@@ -498,19 +488,15 @@ include_once DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirpreview.php';
</div>
</div> <!-- End div id="containerlayout" -->
<?php
// End of page
if ($module != 'medias')
{
dol_fiche_end();
}
if (! empty($conf->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();

View File

@@ -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.='<script type="text/javascript">'."\n";
$moreheadjs.='var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'\';'."\n";
@@ -334,13 +334,10 @@ if (! empty($conf->global->ECM_AUTO_TREE_ENABLED))
$rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'user', 'test'=>1, 'label'=>$langs->trans("Users"), 'desc'=>$langs->trans("ECMDocsByUsers"));
}
//print load_fiche_titre($langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"));
$head = ecm_prepare_dasboard_head('');
dol_fiche_head($head, 'index_auto', $langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"), -1, '');
$helptext1=''; $helptext2='';
$helptext1.=$langs->trans("ECMAreaDesc");
$helptext1.=$langs->trans("ECMAreaDesc2");
$helptext2.=$langs->trans("ECMAreaDesc");
$helptext2.=$langs->trans("ECMAreaDesc2");
// Confirm remove file (for non javascript users)
if ($action == 'delete' && empty($conf->use_javascript_ajax))
@@ -349,17 +346,6 @@ if ($action == 'delete' && empty($conf->use_javascript_ajax))
}
//if (! empty($conf->use_javascript_ajax)) $classviewhide='hidden';
//else $classviewhide='visible';
$classviewhide='inline-block';
$head = ecm_prepare_dasboard_head('');
dol_fiche_head($head, 'index_auto', $langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"), -1, '');
// Start container of all panels
?>
<!-- Begin div id="containerlayout" -->
@@ -381,7 +367,7 @@ print '</div>';
?>
</div>
<div id="ecm-layout-west" class="<?php echo $classviewhide; ?>">
<div id="ecm-layout-west" class="inline-block">
<?php
// Start left area
@@ -461,7 +447,7 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
// End left panel
?>
</div>
<div id="ecm-layout-center" class="<?php echo $classviewhide; ?>">
<div id="ecm-layout-center" class="inline-block">
<div class="pane-in ecm-in-layout-center">
<div id="ecmfileview" class="ecmfileview">
<?php
@@ -483,15 +469,12 @@ include_once DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirpreview.php';
<?php
// End of page
dol_fiche_end();
if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) {
include DOL_DOCUMENT_ROOT.'/ecm/tpl/enablefiletreeajax.tpl.php';
}
dol_fiche_end();
llxFooter();

View File

@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2008-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2008-2009 Regis Houssin <regis.houssin@capnetworks.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -19,8 +19,7 @@
/**
* \file htdocs/ecm/index.php
* \ingroup ecm
* \brief Main page for ECM section area
* \author Laurent Destailleur
* \brief Page to make advanced search into ECM
*/
require '../main.inc.php';

View File

@@ -93,4 +93,4 @@ function loadandshowpreview(filedirname,section)
}
</script>
<!-- END PHP TEMPLATE ecm/tpl/builddatabase.tpl.php -->
<!-- END PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->

View File

@@ -0,0 +1,193 @@
<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 <http://www.gnu.org/licenses/>.
*
* Output code for the filemanager
* $module must be defined ('ecm', 'medias', ...)
*/
?>
<!-- BEGIN PHP TEMPLATE ecm/tpl/filemanager.tpl.php -->
<!-- Doc of fileTree plugin at http://www.abeautifulsite.net/blog/2008/03/jquery-file-tree/ -->
<?php
require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
// Confirm remove file (for non javascript users)
if (($action == 'delete' || $action == 'file_manager_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);
}
// Start container of all panels
?>
<!-- Begin div id="containerlayout" -->
<div id="containerlayout">
<div id="ecm-layout-north" class="toolbar largebutton">
<?php
// Start top panel, toolbar
print '<div class="inline-block toolbarbutton centpercent">';
// Toolbar
if ($user->rights->ecm->setup)
{
print '<a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create" class="inline-block valignmiddle toolbarbutton" title="'.dol_escape_htmltag($langs->trans('ECMAddSection')).'">';
print '<img class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
print '</a>';
}
else
{
print '<a href="#" class="inline-block valignmiddle toolbarbutton" title="'.$langs->trans("NotAllowed").'">';
print '<img class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
print '</a>';
}
$url=((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))?'#':($_SERVER["PHP_SELF"].'?action=refreshmanual'.($module?'&amp;module='.$module:'').($section?'&amp;section='.$section:'')));
print '<a href="'.$url.'" class="inline-block valignmiddle toolbarbutton" title="'.dol_escape_htmltag($langs->trans('ReSyncListOfDir')).'">';
print '<img id="refreshbutton" class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/view-refresh.png">';
print '</a>';
// Start "Add new file" area
$nameforformuserfile = 'formuserfileecm';
print '<div class="inline-block valignmiddle floatright">';
// 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'))
{
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#<?php echo $nameforformuserfile ?>').hide();
});
</script>
<?php
}
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
$formfile=new FormFile($db);
$formfile->form_attach_new_file($_SERVER["PHP_SELF"], 'none', 0, ($section?$section:-1), $user->rights->ecm->upload, 48, null, '', 0, '', 0, $nameforformuserfile);
}
else print '&nbsp;';
print '</div>';
// End "Add new file" area
print '</div>';
// End top panel, toolbar
?>
</div>
<div id="ecm-layout-west" class="inline-block">
<?php
// Start left area
// Confirmation de la suppression d'une ligne categorie
if ($action == 'delete_section')
{
print $form->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 '<table width="100%" class="liste noborderbottom">'."\n";
print '<!-- Title for manual directories -->'."\n";
print '<tr class="liste_titre">'."\n";
print '<th class="liste_titre" align="left" colspan="6">';
print '&nbsp;'.$langs->trans("ECMSections");
print '</th></tr>';
$showonrightsize='';
// Manual section
$htmltooltip=$langs->trans("ECMAreaDesc2");
if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))
{
print '<tr><td colspan="6">';
// Show filemanager tree (will be filled by call of ajax enablefiletreeajax.tpl.php that execute ajaxdirtree.php)
print '<div id="filetree" class="ecmfiletree"></div>';
if ($action == 'deletefile') print $form->formconfirm('eeeee', $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', '', 'deletefile');
print '</td></tr>';
}
else
{
print '<tr><td colspan="6" style="padding-left: 20px">';
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 '<div id="filetree" class="ecmfiletree">';
$mode='noajax';
$url=DOL_URL_ROOT.'/ecm/index.php';
include DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirtree.php';
print '</div>';
print '</td></tr>';
}
print "</table>";
}
// End left panel
?>
</div>
<div id="ecm-layout-center" class="inline-block">
<div class="pane-in ecm-in-layout-center">
<div id="ecmfileview" class="ecmfileview">
<?php
// Start right panel
$mode='noajax';
$url=DOL_URL_ROOT.'/ecm/index.php';
include_once DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirpreview.php';
// End right panel
?>
</div>
</div>
</div>
</div> <!-- End div id="containerlayout" -->
<?php
if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) {
include DOL_DOCUMENT_ROOT.'/ecm/tpl/enablefiletreeajax.tpl.php';
}
?>
<!-- END PHP TEMPLATE ecm/tpl/filemanager.tpl.php -->

View File

@@ -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, '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
$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.='<script type="text/javascript">'."\n";
$moreheadjs.='var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'\';'."\n";
$moreheadjs.='</script>'."\n";
llxHeader($moreheadcss.$moreheadjs, $langs->trans("websiteetup"), $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST"><div>';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -1199,7 +1210,7 @@ if (count($object->records) > 0)
print ' &nbsp; ';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("MediaFiles")).'" name="editmedias">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("MediaFiles")).'" name="file_manager">';
}
print '</div>';
@@ -1227,10 +1238,10 @@ if (count($object->records) > 0)
print '</a>';
}
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 '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^edit/',$action) && $action != 'editmedias') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^create/',$action) && $action != 'file_manager') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^edit/',$action) && $action != 'file_manager') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
}
@@ -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 '</div>'; // 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 '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
if (preg_match('/^edit/',$action)) print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
@@ -1774,10 +1785,14 @@ if ($action == 'editmeta' || $action == 'create')
print '<br>';
}
if ($action == 'editmedias')
if ($action == 'file_manager')
{
print '<!-- Edit Media -->'."\n";
print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
print '<br><br>';
//print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
$module = 'medias';
include DOL_DOCUMENT_ROOT.'/ecm/tpl/filemanager.tpl.php';
}
if ($action == 'editmenu')