From 806a6d210764195d5a1de86fa1b9cd2e69ca8762 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 12 Mar 2008 07:36:57 +0000 Subject: [PATCH] Reenabled renaming of departments. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9694 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../departments/class_departmentGeneric.inc | 156 +++++++----------- .../class_departmentManagement.inc | 46 +++--- .../admin/departments/tabs_department.inc | 56 +++++-- 3 files changed, 127 insertions(+), 131 deletions(-) diff --git a/gosa-core/plugins/admin/departments/class_departmentGeneric.inc b/gosa-core/plugins/admin/departments/class_departmentGeneric.inc index f4344bc95..467765e43 100644 --- a/gosa-core/plugins/admin/departments/class_departmentGeneric.inc +++ b/gosa-core/plugins/admin/departments/class_departmentGeneric.inc @@ -36,14 +36,10 @@ class department extends plugin var $is_administrational_unit= false; var $gosaUnitTag= ""; var $view_logged = FALSE; - var $rec_dst=false; // Destination for recursive move - var $rec_src=false; // Source for recursive move - var $rec_cpy=false; // Is recursive move requested ? /* Headpage attributes */ var $last_dep_sorting= "invalid"; var $departments= array(); - var $must_be_tagged = false; /* attribute list for save action */ @@ -199,12 +195,6 @@ class department extends plugin return $this->must_be_tagged; } - function am_i_moved() - { - return $this->rec_cpy; - } - - /* Save data to object */ function save_object() { @@ -248,7 +238,7 @@ class department extends plugin $ldap->ls ("(&(ou=".$this->ou.")(objectClass=organizationalUnit))", $this->base, array('dn')); if ($this->orig_dn == "new" && $ldap->count()){ $message[]= msgPool::duplicated(_("Name")); - } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){ + } elseif ($this->orig_dn != $this->dn && $ldap->count()){ $message[]= msgPool::duplicated(_("Name")); } @@ -473,101 +463,83 @@ class department extends plugin /* Move/Rename complete trees */ function recursive_move($src_dn, $dst_dn,$force = false) { - /* If force == false prepare to recursive move this object from src to dst - on the next call. */ - if(!$force){ - $this->rec_cpy = true; - $this->rec_src = $src_dn; - $this->rec_dst = $dst_dn; - }else{ - - /* If this is called, but not wanted, abort */ - if(!$this->rec_cpy){ - return; - } - - $src_dn = $this->rec_src; - $dst_dn = $this->rec_dst; - - /* Print header to have styles included */ - $smarty= get_smarty(); - - echo ' - - - - - - - - '; - echo "

".sprintf(_("Moving '%s' to '%s'"),"".@LDAP::fix($src_dn)."","".@LDAP::fix($dst_dn)."")."

"; - - - /* Check if the destination entry exists */ - $ldap= $this->config->get_ldap_link(); + /* Print header to have styles included */ + $smarty= get_smarty(); + + echo ' + + + + + + + + '; + echo "

".sprintf(_("Moving '%s' to '%s'"),"".@LDAP::fix($src_dn)."","".@LDAP::fix($dst_dn)."")."

"; + + + /* Check if the destination entry exists */ + $ldap= $this->config->get_ldap_link(); - /* Check if destination exists - abort */ - $ldap->cat($dst_dn, array('dn')); - if ($ldap->fetch()){ - trigger_error("Recursive_move ".@LDAP::fix($dst_dn)." already exists.", - E_USER_WARNING); - echo sprintf("Recursive_move: '%s' already exists", @LDAP::fix($dst_dn))."
"; - return (FALSE); - } + /* Check if destination exists - abort */ + $ldap->cat($dst_dn, array('dn')); + if ($ldap->fetch()){ + trigger_error("Recursive_move ".@LDAP::fix($dst_dn)." already exists.", + E_USER_WARNING); + echo sprintf("Recursive_move: '%s' already exists", @LDAP::fix($dst_dn))."
"; + return (FALSE); + } - /* Perform a search for all objects to be moved */ - $objects= array(); - $ldap->cd($src_dn); - $ldap->search("(objectClass=*)", array("dn")); - while($attrs= $ldap->fetch()){ - $dn= $attrs['dn']; - $objects[$dn]= strlen($dn); - } + /* Perform a search for all objects to be moved */ + $objects= array(); + $ldap->cd($src_dn); + $ldap->search("(objectClass=*)", array("dn")); + while($attrs= $ldap->fetch()){ + $dn= $attrs['dn']; + $objects[$dn]= strlen($dn); + } - /* Sort objects by indent level */ - asort($objects); - reset($objects); + /* Sort objects by indent level */ + asort($objects); + reset($objects); - /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */ - foreach ($objects as $object => $len){ + /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */ + foreach ($objects as $object => $len){ - $src= str_replace("\\","\\\\",$object); - $dst= preg_replace("/".str_replace("\\","\\\\",$src_dn)."$/", "$dst_dn", $object); - $dst= str_replace($src_dn,$dst_dn,$object); + $src= str_replace("\\","\\\\",$object); + $dst= preg_replace("/".str_replace("\\","\\\\",$src_dn)."$/", "$dst_dn", $object); + $dst= str_replace($src_dn,$dst_dn,$object); - echo ""._("Object").": ".@LDAP::fix($src)."
"; + echo ""._("Object").": ".@LDAP::fix($src)."
"; - $this->update_acls($object, $dst,TRUE); + $this->update_acls($object, $dst,TRUE); - if (!$this->copy($src, $dst)){ - echo "
".sprintf(_("FAILED to copy %s, aborting operation"),@LDAP::fix($src))."
"; - return (FALSE); - } - echo "" ; - flush(); - } + if (!$this->copy($src, $dst)){ + echo "
".sprintf(_("FAILED to copy %s, aborting operation"),@LDAP::fix($src))."
"; + return (FALSE); + } + echo "" ; + flush(); + } - /* Remove src_dn */ - $ldap->cd($src_dn); - $ldap->recursive_remove(); - $this->dn = $this->rec_dst; - $this->rec_src = $this->rec_dst = ""; - $this->rec_cpy =false; + /* Remove src_dn */ + $ldap->cd($src_dn); + $ldap->recursive_remove(); + $this->orig_dn = $this->dn = $dst_dn; + $this->orig_base= $this->base; - echo '

 

'; + echo '

 

'; - echo "
-
-
"; + echo "
+
+
"; - echo "" ; - echo ""; + echo "" ; + echo ""; - return (TRUE); - } - } + return (TRUE); + } /* Return plugin informations for acl handling */ diff --git a/gosa-core/plugins/admin/departments/class_departmentManagement.inc b/gosa-core/plugins/admin/departments/class_departmentManagement.inc index d65c66987..5d306e3c8 100644 --- a/gosa-core/plugins/admin/departments/class_departmentManagement.inc +++ b/gosa-core/plugins/admin/departments/class_departmentManagement.inc @@ -272,11 +272,25 @@ class departmentManagement extends plugin } + /*************** + Handle recursive move (Return output for an iframe) + ***************/ + + + /* initiate recursive remove (Is called from iframe, generates output)*/ + if(isset($_GET['PerformRecMove'])){ + $this->deptabs->move_me(); + $this->DivListDepartment->selectedBase = $this->deptabs->by_object['department']->dn; + exit(); + } + + /*************** Edit department finished ***************/ - if ((isset($_POST['edit_finish']) || isset($_POST['dep_move_confirm'])) && (isset($this->deptabs->config))){ + if (is_object($this->deptabs) && + (isset($_POST['edit_finish']) || isset($_POST['dep_move_confirm']) || $this->deptabs->move_done())){ /* Check tabs, will feed message array. This call will also initiate a sav_object() call. @@ -289,10 +303,15 @@ class departmentManagement extends plugin MOVED ? Check if this department is moved *************/ - if(!isset($_POST['dep_move_confirm']) && $obj->orig_dn != "new"){ - if($obj->orig_ou != $obj->ou || $obj->base != $obj->orig_base){ - return($smarty->fetch(get_template_path("dep_move_confirm.tpl",TRUE))); - } + if(!isset($_POST['dep_move_confirm']) && $this->deptabs->am_i_moved()){ + return($smarty->fetch(get_template_path("dep_move_confirm.tpl",TRUE))); + }elseif(isset($_POST['dep_move_confirm']) && $this->deptabs->am_i_moved()){ + return($this->deptabs->by_object['department']->ShowMoveFrame()); + } + + if($this->deptabs->am_i_moved()){ + echo "stop"; + exit(); } /* Save, or display error message? */ @@ -309,11 +328,6 @@ class departmentManagement extends plugin $this->ObjectTaggingRequested = true; } - /* Get recursive move is required, set RecursiveRemoveRequested to true */ - if($this->deptabs->by_object['department']->am_i_moved()){ - $this->RecursiveRemoveRequested = true; - } - /* This var indicated that there is an object which isn't saved right now. */ $this->ObjectInSaveMode = true; @@ -336,18 +350,6 @@ class departmentManagement extends plugin } - /*************** - Handle recursive move (Return output for an iframe) - ***************/ - - /* initiate recursive remove (Is called from iframe, generates output)*/ - if(isset($_GET['PerformRecMove'])){ - $this->deptabs->by_object['department']->recursive_move("","",true); - $this->DivListDepartment->selectedBase = $this->deptabs->by_object['department']->dn; - exit(); - } - - /*************** Return iframes, which call tagging / recusrsive move ***************/ diff --git a/gosa-core/plugins/admin/departments/tabs_department.inc b/gosa-core/plugins/admin/departments/tabs_department.inc index 235f3212d..4788b8acc 100644 --- a/gosa-core/plugins/admin/departments/tabs_department.inc +++ b/gosa-core/plugins/admin/departments/tabs_department.inc @@ -23,6 +23,7 @@ class deptabs extends tabs { var $base= ""; + var $moved = FALSE; function deptabs($config, $data, $dn,$category) { @@ -40,26 +41,47 @@ class deptabs extends tabs } - function save($ignore_account= FALSE) + function am_i_moved() { + if($this->moved) return(FALSE); $baseobject= &$this->by_object['department']; - $ou= preg_replace('/,/', '\,', $baseobject->ou); - $new_dn= @LDAP::convert('ou='.$ou.','.$baseobject->base); - - if($ignore_account){ - if ($this->dn != $new_dn && $this->dn != "new"){ - /* if( new_dn is subtree of this->dn ) */ - $cnt1 = count(split(",",$this->dn)); - $cnt2 = count(split(",",$new_dn)); - if((strstr($new_dn,$this->dn))&&($cnt1<$cnt2)){ - msg_dialog::display(_("LDAP error"), _("Moving LDAP tree failed: destination tree is a subtree of the source!"), ERROR_DIALOG); - }else{ - /* Prepare to be moved */ - $baseobject->recursive_move($this->dn, $new_dn); - return; - } - } + $ou = preg_replace('/,/', '\,', $baseobject->ou); + $new_dn = @LDAP::convert('ou='.$ou.','.$baseobject->base); + $old_ou = preg_replace('/,/', '\,', $baseobject->orig_ou); + $old_dn = @LDAP::convert('ou='.$ou.','.$baseobject->orig_base); + if ($this->dn != $new_dn && $this->dn != "new"){ + return(TRUE); } + return(FALSE); + } + + + function move_done() + { + return($this->moved); + } + + + function move_me() + { + if(!$this->am_i_moved()) return; + $baseobject= &$this->by_object['department']; + $ou = preg_replace('/,/', '\,', $baseobject->ou); + $new_dn = @LDAP::convert('ou='.$ou.','.$baseobject->base); + $old_ou = preg_replace('/,/', '\,', $baseobject->orig_ou); + $old_dn = @LDAP::convert('ou='.$ou.','.$baseobject->orig_base); + if ($this->dn != $new_dn && $this->dn != "new"){ + $baseobject->recursive_move($this->dn, $new_dn); + $this->moved= TRUE; + } + } + + + function save($ignore_account= FALSE) + { + $baseobject= &$this->by_object['department']; + $ou = preg_replace('/,/', '\,', $baseobject->ou); + $new_dn = @LDAP::convert('ou='.$ou.','.$baseobject->base); $this->dn= $new_dn; $baseobject->dn= $this->dn; if (!$ignore_account){ -- 2.30.2