diff --git a/htdocs/ecm/docmine.php b/htdocs/ecm/docmine.php index eb6389860fe..f3937c7a881 100644 --- a/htdocs/ecm/docmine.php +++ b/htdocs/ecm/docmine.php @@ -139,11 +139,51 @@ if ($_POST['action'] == 'confirm_deletedir' && $_POST['confirm'] == 'yes') // Update description if ($_POST['action'] == 'update' && ! $_POST['cancel']) { + $db->begin(); + + $oldlabel=$ecmdir->label; + $olddir=$ecmdir->getRelativePath(0); + $olddir=$conf->ecm->dir_output.'/'.$olddir; + // Fetch was already done + $ecmdir->label = $_POST["label"]; $ecmdir->description = $_POST["description"]; $result=$ecmdir->update($user); - if ($result <= 0) + if ($result > 0) { + $error=0; + + // Try to rename file if changed + if ($oldlabel != $ecmdir->label + && file_exists($olddir)) + { + $newdir=$ecmdir->getRelativePath(1); // return "xxx/zzz/" from ecm directory + $newdir=$conf->ecm->dir_output.'/'.$newdir; + //print $olddir.'-'.$newdir; + $result=@rename($olddir,$newdir); + if (! $result) + { + $langs->load('errors'); + $mesg='
'.$langs->trans('ErrorFailToRenameDir',$olddir,$newdir).'
'; + $error++; + } + } + + if (! $error) + { + $db->commit(); + + $relativepath=$ecmdir->getRelativePath(); + $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; + } + else + { + $db->rollback(); + } + } + else + { + $db->rollback(); $mesg='
'.$ecmdir->error.'
'; } } @@ -186,10 +226,15 @@ $s=''; $tmpecmdir=new ECMDirectory($db); // Need to create a new one $tmpecmdir->fetch($ecmdir->id); $result = 1; +$i=0; while ($tmpecmdir && $result > 0) { $tmpecmdir->ref=$tmpecmdir->label; - $s=$tmpecmdir->getNomUrl(1).$s; + if ($i == 0 && $_GET["action"] == 'edit') + { + $s=''; + } + else $s=$tmpecmdir->getNomUrl(1).$s; if ($tmpecmdir->fk_parent) { $s=' -> '.$s; @@ -199,6 +244,7 @@ while ($tmpecmdir && $result > 0) { $tmpecmdir=0; } + $i++; } print img_picto('','object_dir').' '.$langs->trans("ECMRoot").' -> '; @@ -247,6 +293,7 @@ if ($_GET["action"] == 'edit') print ''; + // Actions buttons if ($_GET["action"] != 'edit' && $_GET['action'] != 'delete_dir' && $_GET['action'] != 'delete') { @@ -275,7 +322,7 @@ if ($_GET["action"] != 'edit' && $_GET['action'] != 'delete_dir' && $_GET['actio print ''; } -if ($mesg) { print $mesg.'
'; } +if ($mesg) { print '
'.$mesg.'
'; } // Confirm remove file diff --git a/htdocs/ecm/ecmdirectory.class.php b/htdocs/ecm/ecmdirectory.class.php index 2969466264d..dafbee06233 100644 --- a/htdocs/ecm/ecmdirectory.class.php +++ b/htdocs/ecm/ecmdirectory.class.php @@ -392,12 +392,13 @@ class EcmDirectory // extends CommonObject } /** - \brief Return relative path of a directory on disk - \return string Relative physical path - */ - function getRelativePath() + * \brief Return relative path of a directory on disk + * \param force Force reload of full arbo even if already loaded + * \return string Relative physical path + */ + function getRelativePath($force=0) { - $this->get_full_arbo(); + $this->get_full_arbo($force); $ret=''; $idtosearch=$this->id;