Skip to content
Snippets Groups Projects
Commit 08426c1b authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: Avoid duplicate directories

parent 4c2e6df6
Branches
Tags
No related merge requests found
...@@ -107,7 +107,8 @@ if ($_POST["action"] == 'add' && $user->rights->ecm->setup) ...@@ -107,7 +107,8 @@ if ($_POST["action"] == 'add' && $user->rights->ecm->setup)
} }
else else
{ {
$mesg='<div class="error">Error '.$langs->trans($ecmdir->error).'</div>'; $langs->load("errors");
$mesg='<div class="error">'.$langs->trans($ecmdir->error).'</div>';
$_GET["action"] = "create"; $_GET["action"] = "create";
} }
} }
...@@ -199,7 +200,6 @@ if (! $_GET["action"] || $_GET["action"] == 'delete_section') ...@@ -199,7 +200,6 @@ if (! $_GET["action"] || $_GET["action"] == 'delete_section')
// Construit fiche rubrique // Construit fiche rubrique
print $user->rights->ecm->setup;
// Actions buttons // Actions buttons
print '<div class="tabsAction">'; print '<div class="tabsAction">';
if ($user->rights->ecm->setup) if ($user->rights->ecm->setup)
......
...@@ -83,8 +83,40 @@ class EcmDirectory // extends CommonObject ...@@ -83,8 +83,40 @@ class EcmDirectory // extends CommonObject
$this->fk_user_c=$user->id; $this->fk_user_c=$user->id;
if ($this->fk_parent <= 0) $this->fk_parent=0; if ($this->fk_parent <= 0) $this->fk_parent=0;
// Check parameters // Check if same directory does not exists with this name
// Put here code to add control on parameters values $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.'<br>';
$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.'<br>';
if ($path == $relativepath)
{
$pathfound=1;
break;
}
}
if ($pathfound)
{
$this->error="ErrorDirAlreadyExists";
dolibarr_syslog("EcmDirectories::create ".$this->error, LOG_WARNING);
return -1;
}
else
{
$this->db->begin();
// Insert request // Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."ecm_directories("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."ecm_directories(";
...@@ -119,15 +151,26 @@ class EcmDirectory // extends CommonObject ...@@ -119,15 +151,26 @@ class EcmDirectory // extends CommonObject
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
if (! $error)
{
$this->db->commit();
return $this->id; return $this->id;
} }
else else
{
$this->db->rollback();
return -1;
}
}
else
{ {
$this->error="Error ".$this->db->lasterror(); $this->error="Error ".$this->db->lasterror();
dolibarr_syslog("EcmDirectories::create ".$this->error, LOG_ERR); dolibarr_syslog("EcmDirectories::create ".$this->error, LOG_ERR);
$this->db->rollback();
return -1; return -1;
} }
} }
}
/** /**
* \brief Update database * \brief Update database
......
...@@ -336,6 +336,7 @@ else ...@@ -336,6 +336,7 @@ else
print '</div>'; print '</div>';
*/ */
print '<br>';
// End of page // End of page
$db->close(); $db->close();
......
...@@ -24,3 +24,4 @@ ErrorTopMenuMustHaveAParentWithId0=A menu of type 'Top' can't have a parent menu ...@@ -24,3 +24,4 @@ ErrorTopMenuMustHaveAParentWithId0=A menu of type 'Top' can't have a parent menu
ErrorLeftMenuMustHaveAParentId=A menu of type 'Left' must have a parent id. 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) ErrorGenbarCodeNotfound=File not found (Bad path, wrong permissions or access denied by openbasedir parameter)
ErrorFunctionNotAvailableInPHP=Function <b>%s</b> is required for this feature but is not available in this version/setup of PHP. ErrorFunctionNotAvailableInPHP=Function <b>%s</b> 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
...@@ -24,3 +24,4 @@ ErrorTopMenuMustHaveAParentWithId0=Un menu de type 'Top' ne peut avoir de menu p ...@@ -24,3 +24,4 @@ ErrorTopMenuMustHaveAParentWithId0=Un menu de type 'Top' ne peut avoir de menu p
ErrorLeftMenuMustHaveAParentId=Un menu de type 'Left' doit avoir un id de père. 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) ErrorGenbarCodeNotfound=Fichier introuvable (Mauvais chemin, permissions incorrectes ou accès interdit par le paramètre openbasedir)
ErrorFunctionNotAvailableInPHP=La fonction <b>%s</b> est requise pour cette fonctionnalité mais n'est pas disponible dans cette version/installation de PHP. ErrorFunctionNotAvailableInPHP=La fonction <b>%s</b> 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment