Code

Added Iframe for Department move
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Mar 2006 12:00:40 +0000 (12:00 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Mar 2006 12:00:40 +0000 (12:00 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2814 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/departments/class_departmentGeneric.inc
plugins/admin/departments/class_departmentManagement.inc
plugins/admin/departments/recursive_moce.tpl [new file with mode: 0644]
plugins/admin/departments/tabs_department.inc

index 3146f8a4c3261c5189fe1132a499ef4fc7e2fa64..e7eb59c681edad82459ec85969c2432145540360 100644 (file)
@@ -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 "<font style='font-size:11px;'><h4>".
+              sprintf(_("Moving %s in %s"),"<br><i>".$src_dn."</i><br>","<br><i>".$dst_dn."</i><br>")."</h4>";
+
+
+                 /* 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.<br>"; 
+                         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    <b>".$src."</b>  to  <b>".$dst."</b><br>";
+                         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 "</font>";
+                 return (TRUE);
+         }
+  }
+
+
 }
 
 ?>
index 89178d11324662dc8394d6b34181e4333e1a5547..fc920491e34eda49a673d7199f27eb68b8d0d91c 100644 (file)
@@ -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 (file)
index 0000000..df076df
--- /dev/null
@@ -0,0 +1,12 @@
+<h2>{t}Processing requested operation, the status of this operation will be displayed in an iframe below.{/t}</h2>
+<iframe src="{$src}" style="width:100%;height:450px;background-color:#FFFFFF;" name="status">
+       {t}Your browser isn't able to display this iframe ... use the link below intead{/t}<br>
+       <a href="{$src}">{$src}</a>
+</iframe>
+
+<p class="seperator">&nbsp;</p>
+<div style="text-align:right;">
+       <p>
+               <input type="submit" name="back" value="{t}Back{/t}">
+       </p>
+</div>
index 88320a3a16ce90a2c824335f7ed2e2817c5aed84..4e8e318aff50761bd4001f24a928c822c947b72c 100644 (file)
@@ -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);
   }
 
 }