From a4aafbb28923c787a9956981e9eca7d15993411d Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 6 Mar 2006 12:00:40 +0000 Subject: [PATCH] Added Iframe for Department move git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2814 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../departments/class_departmentGeneric.inc | 83 +++++++++++++++++++ .../class_departmentManagement.inc | 51 ++++++++---- plugins/admin/departments/recursive_moce.tpl | 12 +++ plugins/admin/departments/tabs_department.inc | 32 +++---- 4 files changed, 148 insertions(+), 30 deletions(-) create mode 100644 plugins/admin/departments/recursive_moce.tpl diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index 3146f8a4c..e7eb59c68 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -32,6 +32,15 @@ class department extends plugin var $facsimileTelephoneNumber= ""; var $orig_dn= ""; + var $rec_dst=false; // Destination for recursive move + var $rec_src=false; // Source for recursive move + var $rec_cpy=false; // Is recursive move requested ? + + function am_i_moved() + { + return $this->rec_cpy; + } + /* Headpage attributes */ var $last_dep_sorting= "invalid"; var $departments= array(); @@ -237,6 +246,80 @@ $ldap->modify ($this->attrs); $this->postcreate(); } + /* Move/Rename complete trees */ + function recursive_move($src_dn, $dst_dn,$force = false) + { + if(! $force){ + + $this->rec_cpy = true; + $this->rec_src = $src_dn; + $this->rec_dst = $dst_dn; + + $smarty = get_smarty(); + + $smarty->assign("src","?plug=".$_GET['plug']."&PerformRecMove"); + + $display = $smarty->fetch(get_template_path("recursive_moce.tpl",TRUE)); + return($display); + exit(); + }else{ + if(!$this->rec_cpy){ + return; + + } + $src_dn = $this->rec_src; + $dst_dn = $this->rec_dst; + echo "

". + sprintf(_("Moving %s in %s"),"
".$src_dn."
","
".$dst_dn."
")."

"; + + + /* Check if the destination entry exists */ + $ldap= $this->config->get_ldap_link(); + + /* Check if destination exists - abort */ + $ldap->cat($dst_dn); + if ($ldap->fetch()){ + trigger_error("recursive_move $dst_dn already exists.", + E_USER_WARNING); + echo "recursive_move :$dst_dn already exists.
"; + 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); + } + + /* 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){ + $src= $object; + $dst= preg_replace("/$src_dn$/", "$dst_dn", $object); + echo "Moving ".$src." to ".$dst."
"; + if (!$this->copy($src, $dst)){ + return (FALSE); + } + } + + /* Remove src_dn */ + $ldap->cd($src_dn); + $ldap->recursive_remove(); + + $this->rec_src = $this->rec_dst = ""; + $this->rec_cpy =false; + echo "
"; + return (TRUE); + } + } + + } ?> diff --git a/plugins/admin/departments/class_departmentManagement.inc b/plugins/admin/departments/class_departmentManagement.inc index 89178d113..fc920491e 100644 --- a/plugins/admin/departments/class_departmentManagement.inc +++ b/plugins/admin/departments/class_departmentManagement.inc @@ -206,7 +206,23 @@ class departmentManagement extends plugin /* Edit Complete ... * Finish request - */ + */ + if((isset($_GET['PerformRecMove'])) &&( $this->deptabs->by_object['department']->am_i_moved())){ + $this->deptabs->save(true); + $this->deptabs->by_object['department']->recursive_move("","",true); + $this->reload (); + /* Group has been saved successfully, remove lock from + LDAP. */ + if ($this->dn != "new"){ + del_lock ($this->dn); + } + + unset ($this->deptabs); + $this->deptabs= NULL; + unset ($_SESSION['objectinfo']); + exit(); + } + if ((isset($_POST['edit_finish'])) && (isset($this->deptabs->config) ) ){ /* Check tabs, will feed message array */ @@ -216,22 +232,25 @@ class departmentManagement extends plugin if (count($message) == 0){ /* Save user data to ldap */ - $this->deptabs->save(); - gosa_log ("Department object'".$this->dn."' has been saved"); - - /* Group has been saved successfully, remove lock from - LDAP. */ - if ($this->dn != "new"){ - del_lock ($this->dn); + $disp = $this->deptabs->save(); + if(!$this->deptabs->by_object['department']->am_i_moved()){ + gosa_log ("Department object'".$this->dn."' has been saved"); + + /* Group has been saved successfully, remove lock from + LDAP. */ + if ($this->dn != "new"){ + del_lock ($this->dn); + } + + /* There's no page reload so we have to read new users at + this point. */ + $this->reload (); + unset ($this->deptabs); + $this->deptabs= NULL; + unset ($_SESSION['objectinfo']); + }else{ + return($disp); } - - /* There's no page reload so we have to read new users at - this point. */ - $this->reload (); - unset ($this->deptabs); - $this->deptabs= NULL; - unset ($_SESSION['objectinfo']); - } else { /* Ok. There seem to be errors regarding to the tab data, show message and continue as usual. */ diff --git a/plugins/admin/departments/recursive_moce.tpl b/plugins/admin/departments/recursive_moce.tpl new file mode 100644 index 000000000..df076df3a --- /dev/null +++ b/plugins/admin/departments/recursive_moce.tpl @@ -0,0 +1,12 @@ +

{t}Processing requested operation, the status of this operation will be displayed in an iframe below.{/t}

+ + +

 

+
+

+ +

+
diff --git a/plugins/admin/departments/tabs_department.inc b/plugins/admin/departments/tabs_department.inc index 88320a3a1..4e8e318af 100644 --- a/plugins/admin/departments/tabs_department.inc +++ b/plugins/admin/departments/tabs_department.inc @@ -16,24 +16,28 @@ class deptabs extends tabs } - function save() + function save($justsave = false) { - $baseobject= $this->by_object['department']; - $new_dn= 'ou='.preg_replace('/,/', '\\\\2C', $baseobject->ou).','.$baseobject->base; - 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)){ - print_red(_("Try to move tree failed. Destination tree is subtree of source tree.")); - }else{ - $baseobject->recursive_move($this->dn, $new_dn); + if(!$justsave){ + $baseobject= $this->by_object['department']; + $new_dn= 'ou='.preg_replace('/,/', '\\\\2C', $baseobject->ou).','.$baseobject->base; + $disp =""; + 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)){ + print_red(_("Try to move tree failed. Destination tree is subtree of source tree.")); + }else{ + $disp = ($baseobject->recursive_move($this->dn, $new_dn)); + return($disp); + } } + $this->dn= $new_dn; } - $this->dn= $new_dn; - tabs::save(TRUE); + return($disp); } } -- 2.30.2