diff --git a/htdocs/ecm/docdir.php b/htdocs/ecm/docdir.php
index ae104ad4b32..bbae295b361 100644
--- a/htdocs/ecm/docdir.php
+++ b/htdocs/ecm/docdir.php
@@ -107,7 +107,8 @@ if ($_POST["action"] == 'add' && $user->rights->ecm->setup)
}
else
{
- $mesg='
Error '.$langs->trans($ecmdir->error).'
';
+ $langs->load("errors");
+ $mesg=''.$langs->trans($ecmdir->error).'
';
$_GET["action"] = "create";
}
}
@@ -199,7 +200,6 @@ if (! $_GET["action"] || $_GET["action"] == 'delete_section')
// Construit fiche rubrique
-print $user->rights->ecm->setup;
// Actions buttons
print '';
if ($user->rights->ecm->setup)
diff --git a/htdocs/ecm/ecmdirectory.class.php b/htdocs/ecm/ecmdirectory.class.php
index f6577e13fb1..2969466264d 100644
--- a/htdocs/ecm/ecmdirectory.class.php
+++ b/htdocs/ecm/ecmdirectory.class.php
@@ -83,50 +83,93 @@ class EcmDirectory // extends CommonObject
$this->fk_user_c=$user->id;
if ($this->fk_parent <= 0) $this->fk_parent=0;
- // Check parameters
- // Put here code to add control on parameters values
-
- // Insert request
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."ecm_directories(";
- $sql.= "label,";
- $sql.= "fk_parent,";
- $sql.= "description,";
- $sql.= "cachenbofdoc,";
- $sql.= "date_c,";
- $sql.= "fk_user_c";
- $sql.= ") VALUES (";
- $sql.= " '".addslashes($this->label)."',";
- $sql.= " '".$this->fk_parent."',";
- $sql.= " '".addslashes($this->description)."',";
- $sql.= " ".($this->cachenbofdoc).",";
- $sql.= " ".$this->db->idate($this->date_c).",";
- $sql.= " '".$this->fk_user_c."'";
- $sql.= ")";
+ // Check if same directory does not exists with this name
+ $relativepath=$this->label;
+ if ($this->fk_parent)
+ {
+ $parent = new ECMDirectory($this->db);
+ $parent->fetch($this->fk_parent);
+ $relativepath=$parent->getRelativePath().$relativepath;
+ }
+ $relativepath=eregi_replace('[\/]+','/',$relativepath); // Avoid duplicate / or \
+ //print $relativepath.'
';
- dolibarr_syslog("EcmDirectories::create sql=".$sql, LOG_DEBUG);
- $resql=$this->db->query($sql);
- if ($resql)
- {
- $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ecm_directories");
-
- $dir=$conf->ecm->dir_output.'/'.$this->getRelativePath();
- $result=create_exdir($dir);
-
- // Appel des triggers
- include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
- $interface=new Interfaces($this->db);
- $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // Fin appel triggers
+ $cat = new ECMDirectory($this->db);
+ $cate_arbo = $cat->get_full_arbo(1);
+ $pathfound=0;
+ foreach ($cate_arbo as $key => $categ)
+ {
+ $path=eregi_replace('[ -><\/]+','/',$categ['fulllabel']);
+ //print $path.'
';
+ if ($path == $relativepath)
+ {
+ $pathfound=1;
+ break;
+ }
+ }
- return $this->id;
- }
- else
- {
- $this->error="Error ".$this->db->lasterror();
- dolibarr_syslog("EcmDirectories::create ".$this->error, LOG_ERR);
- return -1;
- }
+ if ($pathfound)
+ {
+ $this->error="ErrorDirAlreadyExists";
+ dolibarr_syslog("EcmDirectories::create ".$this->error, LOG_WARNING);
+ return -1;
+ }
+ else
+ {
+ $this->db->begin();
+
+ // Insert request
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."ecm_directories(";
+ $sql.= "label,";
+ $sql.= "fk_parent,";
+ $sql.= "description,";
+ $sql.= "cachenbofdoc,";
+ $sql.= "date_c,";
+ $sql.= "fk_user_c";
+ $sql.= ") VALUES (";
+ $sql.= " '".addslashes($this->label)."',";
+ $sql.= " '".$this->fk_parent."',";
+ $sql.= " '".addslashes($this->description)."',";
+ $sql.= " ".($this->cachenbofdoc).",";
+ $sql.= " ".$this->db->idate($this->date_c).",";
+ $sql.= " '".$this->fk_user_c."'";
+ $sql.= ")";
+
+ dolibarr_syslog("EcmDirectories::create sql=".$sql, LOG_DEBUG);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ecm_directories");
+
+ $dir=$conf->ecm->dir_output.'/'.$this->getRelativePath();
+ $result=create_exdir($dir);
+
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
+ if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // Fin appel triggers
+
+ if (! $error)
+ {
+ $this->db->commit();
+ return $this->id;
+ }
+ else
+ {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+ else
+ {
+ $this->error="Error ".$this->db->lasterror();
+ dolibarr_syslog("EcmDirectories::create ".$this->error, LOG_ERR);
+ $this->db->rollback();
+ return -1;
+ }
+ }
}
/**
diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php
index 923740ae735..e5287b4697b 100644
--- a/htdocs/ecm/index.php
+++ b/htdocs/ecm/index.php
@@ -336,6 +336,7 @@ else
print '
';
*/
+print '
';
// End of page
$db->close();
diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang
index a78e5e5f59e..107bb349b43 100644
--- a/htdocs/langs/en_US/errors.lang
+++ b/htdocs/langs/en_US/errors.lang
@@ -18,9 +18,10 @@ ErrorFailedToWriteInDir=Failed to write in directory %s
UserCannotBeDelete=User can not be deleted. May be it is associated on Dolibarr entities.
ErrorFieldsRequired=Some required fields were not filled.
ErrorFailedToCreateDir=Failed to create a directory. Check that Web server user has permissions to write into Dolibarr documents directory. If parameter safe_mode is enabled on this PHP, check that Dolibarr php files owns to web server user (or group).
-ErrorNoMailDefinedForThisUser=No mail defined for this user
+ErrorNoMailDefinedForThisUser=No mail defined for this user
ErrorFeatureNeedJavascript=This feature need javascript to be activated to work. Change this in setup - display.
ErrorTopMenuMustHaveAParentWithId0=A menu of type 'Top' can't have a parent menu. Put 0 in parent menu or choose a menu of type 'Left'.
ErrorLeftMenuMustHaveAParentId=A menu of type 'Left' must have a parent id.
ErrorGenbarCodeNotfound=File not found (Bad path, wrong permissions or access denied by openbasedir parameter)
ErrorFunctionNotAvailableInPHP=Function %s is required for this feature but is not available in this version/setup of PHP.
+ErrorDirAlreadyExists=A directory with this name already exists.
\ No newline at end of file
diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang
index a9d2a8ac707..f81b1bd3f1d 100644
--- a/htdocs/langs/fr_FR/errors.lang
+++ b/htdocs/langs/fr_FR/errors.lang
@@ -18,9 +18,10 @@ ErrorFailedToWriteInDir=Impossible d'
UserCannotBeDelete=L'utilisateur ne peut pas etre supprimée. Peut-être est-il associé à des éléments de Dolibarr.
ErrorFieldsRequired=Des champs obligatoires n'ont pas été renseignés
ErrorFailedToCreateDir=Echec a la creation d'un repertoire. Verifiez que le user du serveur Web a bien les droits d'ecriture dans les repertoires documents de Dolibarr. Si le parametre safe_mode a été activé sur ce PHP, vérifier que les fichiers php dolibarr appartiennent à l'utilisateur du serveur Web.
-ErrorNoMailDefinedForThisUser=EMail non defini pour cet utilisateur
-ErrorFeatureNeedJavascript=Cette fonctionnalité a besoin de javascript activé pour fonctionner. Modifier dans configuration - affichage.
+ErrorNoMailDefinedForThisUser=EMail non defini pour cet utilisateur
+ErrorFeatureNeedJavascript=Cette fonctionnalité a besoin de javascript activé pour fonctionner. Modifier dans configuration - affichage.
ErrorTopMenuMustHaveAParentWithId0=Un menu de type 'Top' ne peut avoir de menu père. Mettre 0 dans l'id père ou choisir un menu de type 'Left'.
ErrorLeftMenuMustHaveAParentId=Un menu de type 'Left' doit avoir un id de père.
ErrorGenbarCodeNotfound=Fichier introuvable (Mauvais chemin, permissions incorrectes ou accès interdit par le paramètre openbasedir)
-ErrorFunctionNotAvailableInPHP=La fonction %s est requise pour cette fonctionnalité mais n'est pas disponible dans cette version/installation de PHP.
\ No newline at end of file
+ErrorFunctionNotAvailableInPHP=La fonction %s est requise pour cette fonctionnalité mais n'est pas disponible dans cette version/installation de PHP.
+ErrorDirAlreadyExists=Un répertoire portant ce nom existe déjà.
\ No newline at end of file