Clean ecm code

This commit is contained in:
Laurent Destailleur 2017-08-20 23:16:20 +02:00
parent 11be4c8632
commit 083cb33a6c
7 changed files with 88 additions and 83 deletions

View File

@ -39,11 +39,11 @@ if (! isset($mode) || $mode != 'noajax') // For ajax call
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
$action=GETPOST('action','aZ09');
$file=urldecode(GETPOST('file'));
$section=GETPOST("section");
$module=GETPOST("module");
$urlsource=GETPOST("urlsource");
$action=GETPOST('action','aZ09');
$file=urldecode(GETPOST('file','alpha'));
$section=GETPOST("section",'alpha');
$module=GETPOST("module",'alpha');
$urlsource=GETPOST("urlsource",'alpha');
$search_doc_ref=GETPOST('search_doc_ref','alpha');
$sortfield = GETPOST("sortfield",'alpha');
@ -56,7 +56,9 @@ if (! isset($mode) || $mode != 'noajax') // For ajax call
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="name";
$upload_dir = dirname(str_replace("../","/", $conf->ecm->dir_output.'/'.$file));
$rootdirfordoc = $conf->ecm->dir_output;
$upload_dir = dirname(str_replace("../", "/", $rootdirfordoc.'/'.$file));
$ecmdir = new EcmDirectory($db);
$result=$ecmdir->fetch($section);
@ -68,7 +70,9 @@ if (! isset($mode) || $mode != 'noajax') // For ajax call
}
else // For no ajax call
{
$ecmdir = new EcmDirectory($db);
$rootdirfordoc = $conf->ecm->dir_output;
$ecmdir = new EcmDirectory($db);
$relativepath='';
if ($section > 0)
{
@ -80,7 +84,7 @@ else // For no ajax call
}
}
$relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
$upload_dir = $rootdirfordoc.'/'.$relativepath;
}
if (empty($url)) $url=DOL_URL_ROOT.'/ecm/index.php';
@ -95,8 +99,7 @@ if ($user->societe_id > 0) $socid = $user->societe_id;
//print 'xxx'.$upload_dir;
// Security:
// On interdit les remontees de repertoire ainsi que les pipe dans
// les noms de fichiers.
// On interdit les remontees de repertoire ainsi que les pipe dans les noms de fichiers.
if (preg_match('/\.\./',$upload_dir) || preg_match('/[<>|]/',$upload_dir))
{
dol_syslog("Refused to deliver file ".$upload_dir);
@ -105,6 +108,16 @@ if (preg_match('/\.\./',$upload_dir) || preg_match('/[<>|]/',$upload_dir))
exit;
}
// Check permissions
if ($modulepart == 'ecm')
{
if (! $user->rights->ecm->read) accessforbidden();
}
if ($modulepart == 'medias')
{
// Always allowed
}
/*
* Action
@ -153,7 +166,7 @@ if ($type == 'directory')
$excludefiles = array('^SPECIMEN\.pdf$','^\.','(\.meta|_preview.*\.png)$','^temp$','^payments$','^CVS$','^thumbs$');
$sorting = (strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC);
// Right area. If module is defined, we are in automatic ecm.
// Right area. If module is defined here, we are in automatic ecm.
$automodules = array('company', 'invoice', 'invoice_supplier', 'propal', 'order', 'order_supplier', 'contract', 'product', 'tax', 'project', 'fichinter', 'user', 'expensereport');
// TODO change for multicompany sharing
@ -197,20 +210,33 @@ if ($type == 'directory')
$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);
$perm=$user->rights->ecm->upload;
$formfile->list_of_autoecmfiles($upload_dir,$filearray,$module,$param,1,'',$perm,1,$textifempty,$maxlengthname,$url,1);
}
// Manual list
else
{
$relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
if ($module == 'medias')
{
$relativepath=GETPOST('file','alpha');
$upload_dir = $dolibarr_main_data_root.'/medias/'.$relativepath;
}
else
{
$relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
}
// If $section defined with value 0
if ($section === '0' || empty($section))
if (($section === '0' || empty($section)) && ($module != 'medias'))
{
$filearray=array();
}
else $filearray=dol_dir_list($upload_dir,"files",0,'',array('^\.','(\.meta|_preview.*\.png)$','^temp$','^CVS$'),$sortfield, $sorting,1);
else
{
$filearray=dol_dir_list($upload_dir,"files",0,'',array('^\.','(\.meta|_preview.*\.png)$','^temp$','^CVS$'),$sortfield, $sorting,1);
}
if ($section)
{
@ -222,7 +248,18 @@ if ($type == 'directory')
else if ($section === '0') $textifempty='<br><div align="center"><font class="warning">'.$langs->trans("DirNotSynchronizedSyncFirst").'</font></div><br>';
else $textifempty=($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("ECMSelectASection"));
$formfile->list_of_documents($filearray,'','ecm',$param,1,$relativepath,$user->rights->ecm->upload,1,$textifempty,$maxlengthname,'',$url);
if ($module == 'medias')
{
$modulepart='medias';
$perm=($user->rights->websites->creer || $user->rights->emailing->creer);
}
else
{
$modulepart='ecm';
$perm=$user->rights->ecm->upload;
}
$formfile->list_of_documents($filearray,'',$modulepart,$param,1,$relativepath,$perm,1,$textifempty,$maxlengthname,'',$url);
}
}

View File

@ -45,13 +45,14 @@ if ($selecteddir != '/') $selecteddir = preg_replace('/\/$/','',$selecteddir);
$langs->load("ecm");
// Define selecteddir (fullpath).
// Define fullpathselecteddir.
$fullpathselecteddir='<none>';
if ($modulepart == 'ecm') $fullpathselecteddir=$conf->ecm->dir_output.'/'.($selecteddir != '/' ? $selecteddir : '');
if ($modulepart == 'medias') $fullpathselecteddir=$dolibarr_main_data_root.'/medias/'.($selecteddir != '/' ? $selecteddir : '');
// Security:
// On interdit les remontees de repertoire ainsi que les pipe dans
// les noms de fichiers.
// 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);
@ -63,9 +64,12 @@ if (preg_match('/\.\./',$fullpathselecteddir) || preg_match('/[<>|]/',$fullpaths
// Check permissions
if ($modulepart == 'ecm')
{
if (! $user->rights->ecm->read) accessforbidden();
if (! $user->rights->ecm->read) accessforbidden();
}
if ($modulepart == 'medias')
{
// Always allowed
}
/*
@ -97,7 +101,8 @@ foreach($sqltree as $keycursor => $val)
if (file_exists($fullpathselecteddir))
{
$files = @scandir($fullpathselecteddir);
if ($files)
if ($files)
{
natcasesort($files);
if ( count($files) > 2 ) /* The 2 accounts for . and .. */

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2008-2014 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2008-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2008-2010 Regis Houssin <regis.houssin@capnetworks.com>
*
* This program is free software; you can redistribute it and/or modify
@ -61,7 +61,6 @@ $pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="fullname";
if ($module == 'invoice_supplier' && $sortfield == "fullname") $sortfield="level1name";
$ecmdir = new EcmDirectory($db);
if ($section)
@ -346,16 +345,11 @@ 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', $langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"), 1, '');
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
?>
@ -394,7 +388,7 @@ 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)
if ((empty($section) || $section == -1) && ($module != 'medias'))
{
?>
<script type="text/javascript">
@ -419,7 +413,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
@ -631,7 +625,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
@ -654,8 +648,10 @@ include_once DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirpreview.php';
// End of page
dol_fiche_end(1);
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';

View File

@ -357,7 +357,7 @@ $classviewhide='inline-block';
$head = ecm_prepare_dasboard_head('');
dol_fiche_head($head, 'index_auto', $langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"), 1, '');
dol_fiche_head($head, 'index_auto', $langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"), -1, '');
// Start container of all panels
@ -484,7 +484,7 @@ include_once DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirpreview.php';
// End of page
dol_fiche_end(1);
dol_fiche_end();
if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) {

View File

@ -24,6 +24,8 @@
<script type="text/javascript">
<?php
if (empty($module)) $module='ecm';
print 'var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working2.gif".'\';'."\n";
$openeddir='/';
@ -34,7 +36,7 @@ $(document).ready(function() {
$('#filetree').fileTree({
root: '<?php print dol_escape_js($openeddir); ?>',
// Ajax called if we click to expand a dir (not a file). Parameter of dir is provided as a POST parameter.
script: '<?php echo DOL_URL_ROOT.'/core/ajax/ajaxdirtree.php?modulepart=ecm&openeddir='.urlencode($openeddir); ?>',
script: '<?php echo DOL_URL_ROOT.'/core/ajax/ajaxdirtree.php?modulepart='.$module.'&openeddir='.urlencode($openeddir); ?>',
folderEvent: 'click', // 'dblclick'
multiFolder: false },
// Called if we click on a file (not a dir)
@ -73,7 +75,7 @@ function loadandshowpreview(filedirname,section)
$('#ecmfileview').empty();
var url = '<?php echo dol_buildpath('/core/ajax/ajaxdirpreview.php',1); ?>?action=preview&module=ecm&section='+section+'&file='+urlencode(filedirname);
var url = '<?php echo dol_buildpath('/core/ajax/ajaxdirpreview.php',1); ?>?action=preview&module=<?php echo $module; ?>&section='+section+'&file='+urlencode(filedirname);
$.get(url, function(data) {
//alert('Load of url '+url+' was performed : '+data);
pos=data.indexOf("TYPE=directory",0);

View File

@ -1950,26 +1950,8 @@ td.ecmroot {
}
.largebutton {
/*background-image: -o-linear-gradient(bottom, rgba(200,200,200,0.1) 0%, rgba(255,255,255,0.3) 120%) !important;
background-image: -moz-linear-gradient(bottom, rgba(200,200,200,0.1) 0%, rgba(255,255,255,0.3) 120%) !important;
background-image: -webkit-linear-gradient(bottom, rgba(200,200,200,0.1) 0%, rgba(255,255,255,0.3) 120%) !important;
background-image: -ms-linear-gradient(bottom, rgba(200,200,200,0.1) 0%, rgba(255,255,255,0.3) 120%) !important;
background-image: linear-gradient(bottom, rgba(200,200,200,0.1) 0%, rgba(255,255,255,0.3) 120%) !important;
background: #FFF;
background-repeat: repeat-x !important;
*/
border-top: 1px solid #CCC !important;
/*-moz-border-radius: 4px 4px 4px 4px !important;
-webkit-border-radius: 4px 4px 4px 4px !important;
border-radius: 4px 4px 4px 4px !important;
-moz-box-shadow: 2px 2px 4px #DDD;
-webkit-box-shadow: 2px 2px 4px #DDD;
box-shadow: 2px 2px 4px #DDD;
*/
padding: 10px 4px 14px 4px !important;
/* border-top: 1px solid #CCC !important; */
padding: 0px 4px 14px 4px !important;
min-height: 32px;
}

View File

@ -1954,25 +1954,8 @@ td.ecmroot {
}
.largebutton {
/*background-image: -o-linear-gradient(bottom, rgba(200,200,200,0.1) 0%, rgba(255,255,255,0.3) 120%) !important;
background-image: -moz-linear-gradient(bottom, rgba(200,200,200,0.1) 0%, rgba(255,255,255,0.3) 120%) !important;
background-image: -webkit-linear-gradient(bottom, rgba(200,200,200,0.1) 0%, rgba(255,255,255,0.3) 120%) !important;
background-image: -ms-linear-gradient(bottom, rgba(200,200,200,0.1) 0%, rgba(255,255,255,0.3) 120%) !important;
background-image: linear-gradient(bottom, rgba(200,200,200,0.1) 0%, rgba(255,255,255,0.3) 120%) !important;
background: #FFF;
background-repeat: repeat-x !important;
*/
border-top: 1px solid #CCC !important;
/*-moz-border-radius: 2px 2px 2px 2px !important;
-webkit-border-radius: 2px 2px 2px 2px !important;
border-radius: 2px 2px 2px 2px !important;
-moz-box-shadow: 2px 2px 4px #f4f4f4;
-webkit-box-shadow: 2px 2px 4px #f4f4f4;
box-shadow: 2px 2px 4px #f4f4f4;*/
padding: 10px 4px 14px 4px !important;
/* border-top: 1px solid #CCC !important; */
padding: 0px 4px 14px 4px !important;
min-height: 32px;
}