';
@@ -361,7 +361,8 @@ if ($_GET['action'] == 'delete')
// Confirm remove file
if ($_GET['action'] == 'delete_dir')
{
- $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_REQUEST["section"], $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection'), 'confirm_deletedir');
+ $relativepathwithoutslash=preg_replace('/[\/]$/','',$relativepath);
+ $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_REQUEST["section"], $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$relativepathwithoutslash), 'confirm_deletedir', '', 1, 1);
if ($ret == 'html') print '
';
}
diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php
index bdcc41f80fe..1fd21ea26b4 100644
--- a/htdocs/ecm/index.php
+++ b/htdocs/ecm/index.php
@@ -50,9 +50,9 @@ $result = restrictedArea($user, 'ecm','');
$user->getrights('ecm');
// Get parameters
-$socid = isset($_GET["socid"])?$_GET["socid"]:'';
-$action = isset($_GET["action"])?$_GET["action"]:$_POST['action'];
-$section=isset($_GET["section"])?$_GET["section"]:$_POST['section'];
+$socid=GETPOST('socid');
+$action=GETPOST("action");
+$section=GETPOST("section");
if (! $section) $section=0;
$upload_dir = $conf->ecm->dir_output.'/'.$section;
@@ -67,9 +67,9 @@ if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="label";
$ecmdir = new ECMDirectory($db);
-if (! empty($_REQUEST["section"]))
+if (GETPOST("section"))
{
- $result=$ecmdir->fetch($_REQUEST["section"]);
+ $result=$ecmdir->fetch(GETPOST("section"));
if (! $result > 0)
{
dol_print_error($db,$ecmdir->error);
@@ -77,6 +77,10 @@ if (! empty($_REQUEST["section"]))
}
}
+$form=new Form($db);
+$ecmdirstatic = new ECMDirectory($db);
+$userstatic = new User($db);
+
/*******************************************************************
* ACTIONS
@@ -84,17 +88,9 @@ if (! empty($_REQUEST["section"]))
* Put here all code to do according to value of "action" parameter
********************************************************************/
-// Envoie fichier
-if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
+// Upload file
+if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
-
- $result=$ecmdir->fetch($_REQUEST["section"]);
- if (! $result > 0)
- {
- dol_print_error($db,$ecmdir->error);
- exit;
- }
$relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
@@ -131,12 +127,12 @@ if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
}
}
-// Action ajout d'un produit ou service
-if ($_POST["action"] == 'add' && $user->rights->ecm->setup)
+// Add directory
+if (GETPOST("action") == 'add' && $user->rights->ecm->setup)
{
- $ecmdir->ref = $_POST["ref"];
- $ecmdir->label = $_POST["label"];
- $ecmdir->description = $_POST["desc"];
+ $ecmdir->ref = 'NOTUSEDYET';
+ $ecmdir->label = GETPOST("label");
+ $ecmdir->description = GETPOST("desc");
$id = $ecmdir->create($user);
if ($id > 0)
@@ -152,9 +148,9 @@ if ($_POST["action"] == 'add' && $user->rights->ecm->setup)
}
// Remove file
-if ($_REQUEST['action'] == 'confirm_deletefile' && $_REQUEST['confirm'] == 'yes')
+if (GETPOST('action') == 'confirm_deletefile' && GETPOST('confirm') == 'yes')
{
- $result=$ecmdir->fetch($_REQUEST["section"]);
+ $result=$ecmdir->fetch(GETPOST("section"));
if (! $result > 0)
{
dol_print_error($db,$ecmdir->error);
@@ -162,7 +158,7 @@ if ($_REQUEST['action'] == 'confirm_deletefile' && $_REQUEST['confirm'] == 'yes'
}
$relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
- $file = $upload_dir . "/" . $_REQUEST['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
+ $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
$result=dol_delete_file($file);
@@ -173,13 +169,123 @@ if ($_REQUEST['action'] == 'confirm_deletefile' && $_REQUEST['confirm'] == 'yes'
}
// Remove directory
-if ($_REQUEST['action'] == 'confirm_deletesection' && $_REQUEST['confirm'] == 'yes')
+if (GETPOST('action') == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
{
$result=$ecmdir->delete($user);
$mesg = '
'.$langs->trans("ECMSectionWasRemoved", $ecmdir->label).'
';
}
+// Refresh directory view
+if (GETPOST("action") == 'refreshmanual')
+{
+ $diroutputslash=str_replace('\\','/',$conf->ecm->dir_output);
+ $diroutputslash.='/';
+ // Scan directory tree on disk
+ $disktree=dol_dir_list($conf->ecm->dir_output,'directories',1,'','','','',0);
+
+ // Scan directory tree in database
+ $sqltree=$ecmdirstatic->get_full_arbo(0);
+
+ $adirwascreated=0;
+
+ // Now we compare both trees to complete missing trees into database
+ //var_dump($disktree);
+ //var_dump($sqltree);
+ foreach($disktree as $dirdesc)
+ {
+ $dirisindatabase=0;
+ foreach($sqltree as $dirsqldesc)
+ {
+ if ($conf->ecm->dir_output.'/'.$dirsqldesc['fullrelativename'] == $dirdesc['fullname'])
+ {
+ $dirisindatabase=1;
+ break;
+ }
+ }
+
+ if (! $dirisindatabase)
+ {
+ $txt="Directory found on disk ".$dirdesc['fullname'].", not found into database so we add it";
+ dol_syslog($txt);
+ print $txt."
\n";
+
+ // We must first find the fk_parent of directory to create $dirdesc['fullname']
+ $fk_parent=-1;
+ $relativepathmissing=str_replace($diroutputslash,'',$dirdesc['fullname']);
+ $relativepathtosearchparent=$relativepathmissing;
+ //dol_syslog("Try to find parent id for directory ".$relativepathtosearchparent);
+ if (preg_match('/\//',$relativepathtosearchparent))
+ //while (preg_match('/\//',$relativepathtosearchparent))
+ {
+ $relativepathtosearchparent=preg_replace('/\/[^\/]*$/','',$relativepathtosearchparent);
+ $txt="Is relative parent path ".$relativepathtosearchparent." for ".$relativepathmissing." found in sql tree ?";
+ dol_syslog($txt);
+ print $txt." -> ";
+ $parentdirisindatabase=0;
+ foreach($sqltree as $dirsqldesc)
+ {
+ if ($dirsqldesc['fullrelativename'] == $relativepathtosearchparent)
+ {
+ $parentdirisindatabase=$dirsqldesc['id'];
+ break;
+ }
+ }
+ if ($parentdirisindatabase > 0)
+ {
+ dol_syslog("Yes with id ".$parentdirisindatabase);
+ print "Yes with id ".$parentdirisindatabase."
\n";
+ $fk_parent=$parentdirisindatabase;
+ //break; // We found parent, we can stop the while loop
+ }
+ else
+ {
+ dol_syslog("No");
+ print "No
\n";
+ }
+ }
+ else
+ {
+ $fk_parent=0; // Parent is root
+ }
+
+ if ($fk_parent >= 0)
+ {
+ $ecmdirtmp=new ECMDirectory($db);
+ $ecmdirtmp->ref = 'NOTUSEDYET';
+ $ecmdirtmp->label = basename($dirdesc['fullname']);
+ $ecmdirtmp->description = '';
+ $ecmdirtmp->fk_parent = $fk_parent;
+
+ $txt="We create directory ".$ecmdirtmp->label." with parent ".$fk_parent;
+ dol_syslog($txt);
+ print $txt."
\n";
+ $id = $ecmdirtmp->create($user);
+ //$id=999;
+ if ($id > 0)
+ {
+ $newdirsql=array('id'=>$id,
+ 'id_mere'=>$ecmdirtmp->fk_parent,
+ 'label'=>$ecmdirtmp->label,
+ 'description'=>$ecmdirtmp->description,
+ 'fullrelativename'=>$relativepathmissing);
+ $sqltree[]=$newdirsql; // We complete fulltree for following loops
+ //var_dump($sqltree);
+ $adirwascreated=1;
+ }
+ }
+ else {
+ $txt="Parent of ".$dirdesc['fullname']." not found";
+ dol_syslog($txt);
+ print $txt."
\n";
+ }
+ }
+ }
+
+ // If a directory was added, the fulltree array is not correctly completed and sorted, so we clean
+ // it to be sure that fulltree array is not used without reloading it.
+ if ($adirwascreated) $sqltree=null;
+}
/*******************************************************************
@@ -231,7 +337,7 @@ html, body {
center__paneSelector: \".ui-in-layout-center\"
, south__paneSelector: \".ui-in-layout-south\"
, resizable: false
- , south__miSize: 34
+ , south__minSize: 32
, south__resizable: false
, south__closable: false
, useStateCookie: true /* Put this to false for dev */
@@ -241,11 +347,6 @@ html, body {
llxHeader($morehead,$langs->trans("ECM"),'','','','',$morejs,'',0,0);
-$form=new Form($db);
-$ecmdirstatic = new ECMDirectory($db);
-$userstatic = new User($db);
-
-
// Ajout rubriques automatiques
$rowspan=0;
$sectionauto=array();
@@ -269,7 +370,7 @@ print $langs->trans("ECMAreaDesc2")."
";
print "
\n";
// Confirm remove file
-if ($_GET['action'] == 'delete')
+if (GETPOST('action') == 'delete')
{
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_REQUEST["section"].'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
if ($ret == 'html') print '
';
@@ -277,7 +378,7 @@ if ($_GET['action'] == 'delete')
if ($mesg) { print $mesg."
"; }
-// Tool bar
+// Toolbar
$head = ecm_prepare_head_fm($fac);
//dol_fiche_head($head, 'file_manager', '', 1);
@@ -300,9 +401,9 @@ else
print '
';
}
-// Construit liste des repertoires
-if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action))
-{
+// Show button to create a directory
+//if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action))
+//{
if ($user->rights->ecm->setup)
{
print '';
@@ -317,13 +418,10 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
print ' ';
print '';
}
-}
-//print ' | ';
-//print '';
-//print ''.img_picto($langs->trans("Refresh"),'refresh').'';
+//}
+// Show button to refresh listing
print '';
print ' ';
-//print $langs->trans('Refresh');
print '';
@@ -498,7 +596,7 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
// Load full tree
- $fulltree=$ecmdirstatic->get_full_arbo();
+ if (empty($sqltree)) $sqltree=$ecmdirstatic->get_full_arbo(0);
// ----- This section will show a tree from a fulltree array -----
// $section must also be defined
@@ -506,7 +604,7 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
// Define fullpathselected ( _x_y_z ) of $section parameter
$fullpathselected='';
- foreach($fulltree as $key => $val)
+ foreach($sqltree as $key => $val)
{
//print $val['id']."-".$section." ";
if ($val['id'] == $section)
@@ -542,7 +640,7 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
foreach($oldexpandedsectionarray as $sectioncursor)
{
// is_in_subtree(fulltree,sectionparent,sectionchild)
- if ($sectioncursor && ! is_in_subtree($fulltree,$section,$sectioncursor)) $expandedsectionarray[]=$sectioncursor;
+ if ($sectioncursor && ! is_in_subtree($sqltree,$section,$sectioncursor)) $expandedsectionarray[]=$sectioncursor;
}
$_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
}
@@ -551,7 +649,7 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
$nbofentries=0;
$oldvallevel=0;
$var=true;
- foreach($fulltree as $key => $val)
+ foreach($sqltree as $key => $val)
{
$var=false;
@@ -593,7 +691,7 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
// Show tree graph pictos
print ' | ';
print '| ';
- $resarray=tree_showpad($fulltree,$key);
+ $resarray=tree_showpad($sqltree,$key);
$a=$resarray[0];
$nbofsubdir=$resarray[1];
$c=$resarray[2];
@@ -609,7 +707,8 @@ if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$acti
else $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop'.$n.'.gif','',1);
if ($option == 'indexexpanded') $lien = '';
if ($option == 'indexnotexpanded') $lien = '';
- $newref=str_replace('_',' ',$ref);
+ //$newref=str_replace('_',' ',$ref);
+ $newref=$ref;
$lienfin='';
print $lien.$newref.$lienfin;
if (! in_array($val['id'],$expandedsectionarray)) print img_picto($ecmdirstatic->ref,DOL_URL_ROOT.'/theme/common/treemenu/folder.gif','',1);
@@ -766,7 +865,6 @@ else
print ' | ';
}
-print ' ';
// End of page
$db->close();
diff --git a/htdocs/install/mysql/migration/2.9.0-3.0.0.sql b/htdocs/install/mysql/migration/2.9.0-3.0.0.sql
index 38ef4117254..13856ba26e4 100644
--- a/htdocs/install/mysql/migration/2.9.0-3.0.0.sql
+++ b/htdocs/install/mysql/migration/2.9.0-3.0.0.sql
@@ -73,3 +73,7 @@ ALTER TABLE llx_categorie ADD COLUMN import_key varchar(14);
ALTER TABLE llx_product ADD COLUMN customcode varchar(32) after note;
ALTER TABLE llx_product ADD COLUMN fk_country integer after customcode;
+
+
+ALTER TABLE llx_ecm_directories ADD UNIQUE INDEX idx_ecm_directories (label, fk_parent, entity);
+ALTER TABLE llx_ecm_documents ADD UNIQUE INDEX idx_ecm_documents (fullpath_dol);
diff --git a/htdocs/install/mysql/tables/llx_ecm_directories.key.sql b/htdocs/install/mysql/tables/llx_ecm_directories.key.sql
new file mode 100644
index 00000000000..b899c4303e1
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_ecm_directories.key.sql
@@ -0,0 +1,23 @@
+-- ============================================================================
+-- Copyright (C) 2010 Laurent Destailleur
+--
+-- 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 2 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, write to the Free Software
+-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+--
+-- $Id$
+-- ============================================================================
+
+
+ALTER TABLE llx_ecm_directories ADD UNIQUE INDEX idx_ecm_directories (label, fk_parent, entity);
+
\ No newline at end of file
diff --git a/htdocs/install/mysql/tables/llx_ecm_documents.key.sql b/htdocs/install/mysql/tables/llx_ecm_documents.key.sql
new file mode 100644
index 00000000000..6de1b23eb64
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_ecm_documents.key.sql
@@ -0,0 +1,23 @@
+-- ============================================================================
+-- Copyright (C) 2010 Laurent Destailleur
+--
+-- 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 2 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, write to the Free Software
+-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+--
+-- $Id$
+-- ============================================================================
+
+
+ALTER TABLE llx_ecm_documents ADD UNIQUE INDEX idx_ecm_documents (fullpath_dol);
+
\ No newline at end of file
diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php
index a5b3cd7cf7b..c1dbb6442a3 100644
--- a/htdocs/lib/files.lib.php
+++ b/htdocs/lib/files.lib.php
@@ -24,23 +24,24 @@
*/
/**
- * Scan a directory and return a list of files/directories. Content for string is UTF8.
+ * Scan a directory and return a list of files/directories.
+ * Content for string is UTF8 and dir separator is "/".
* @param $path Starting path from which to search
* @param $types Can be "directories", "files", or "all"
* @param $recursive Determines whether subdirectories are searched
* @param $filter Regex for include filter
- * @param $exludefilter Regex for exclude filter (example: '\.meta$')
- * @param $sortcriteria Sort criteria ("name","date","size")
+ * @param $excludefilter Regex for exclude filter (example: '\.meta$')
+ * @param $sortcriteria Sort criteria ("","name","date","size")
* @param $sortorder Sort order (SORT_ASC, SORT_DESC)
- * @param $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower)
+ * @param $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only
* @return array Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file')
*/
function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="name", $sortorder=SORT_ASC, $mode=0)
{
dol_syslog("files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".$excludefilter);
- $loaddate=$mode?true:false;
- $loadsize=$mode?true:false;
+ $loaddate=($mode==1||$mode==2)?true:false;
+ $loadsize=($mode==1||$mode==3)?true:false;
// Clean parameters
$path=preg_replace('/([\\/]+)$/i','',$path);
@@ -114,7 +115,7 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
$myarray[$key] = $row[$sortcriteria];
}
// Sort the data
- array_multisort($myarray, $sortorder, $file_list);
+ if ($sortorder) array_multisort($myarray, $sortorder, $file_list);
return $file_list;
}
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index 8d46cda6ac4..daa87800824 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -111,22 +111,23 @@ function dol_now($mode='tzserver')
/**
- * \brief Clean a string to use it as a file name.
- * \param str String to clean
- * \param newstr String to replace bad chars by
- * \return string String cleaned (a-zA-Z_)
- * \seealso dol_string_nospecial, dol_string_unaccent
+ * Clean a string to use it as a file name.
+ * @param str String to clean
+ * @param newstr String to replace bad chars with
+ * @return string String cleaned (a-zA-Z_)
+ * @see dol_string_nospecial, dol_string_unaccent
*/
function dol_sanitizeFileName($str,$newstr='_')
{
- return dol_string_nospecial(dol_string_unaccent($str),$newstr);
+ global $conf;
+ return dol_string_nospecial(dol_string_unaccent($str),$newstr,$conf->filesystem_forbidden_chars);
}
/**
- * \brief Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
- * \param str String to clean
- * \return string Cleaned string
- * \seealso dol_sanitizeFilename, dol_string_nospecial
+ * Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
+ * @param str String to clean
+ * @return string Cleaned string
+ * @see dol_sanitizeFilename, dol_string_nospecial
*/
function dol_string_unaccent($str)
{
@@ -169,19 +170,21 @@ function dol_string_unaccent($str)
}
/**
- * \brief Clean a string from all punctuation characters to use it as a ref or login.
- * \param str String to clean
- * \param newstr String to replace bad chars by
- * \return string Cleaned string
- * \seealso dol_sanitizeFilename, dol_string_unaccent
+ * Clean a string from all punctuation characters to use it as a ref or login.
+ * @param str String to clean
+ * @param newstr String to replace forbidden chars with
+ * @param badchars List of forbidden characters
+ * @return string Cleaned string
+ * @see dol_sanitizeFilename, dol_string_unaccent
*/
-function dol_string_nospecial($str,$newstr='_')
+function dol_string_nospecial($str,$newstr='_',$badchars='')
{
- $forbidden_chars_to_underscore=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",",",";","=");
- //$forbidden_chars_to_remove=array("(",")");
+ $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",",",";","=");
$forbidden_chars_to_remove=array();
+ if (is_array($badchars)) $forbidden_chars_to_replace=$badchars;
+ //$forbidden_chars_to_remove=array("(",")");
- return str_replace($forbidden_chars_to_underscore,$newstr,str_replace($forbidden_chars_to_remove,"",$str));
+ return str_replace($forbidden_chars_to_replace,$newstr,str_replace($forbidden_chars_to_remove,"",$str));
}
/**
|