Code

Initial commit for department tagging & recursive move
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 12 May 2006 05:31:10 +0000 (05:31 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 12 May 2006 05:31:10 +0000 (05:31 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3302 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/departments/class_departmentGeneric.inc
plugins/admin/departments/class_departmentManagement.inc
plugins/admin/departments/tabs_department.inc

index 61160d2f6dd7590e749cf72aa506c7d0fc878051..53afc78d764a2522553ad083b63b4cf79b46d4e5 100644 (file)
@@ -161,7 +161,6 @@ class department extends plugin
                }
        }
 
-
        function remove_from_parent()
        {
                $ldap= $this->config->get_ldap_link();
@@ -172,6 +171,16 @@ class department extends plugin
                $this->handle_post_events('remove');
        }
 
+       function must_be_tagged()
+       {
+               return $this->must_be_tagged;
+       }
+
+       function am_i_moved()
+       {
+               return $this->rec_cpy;
+       }
+
 
        /* Save data to object */
        function save_object()
@@ -258,7 +267,9 @@ class department extends plugin
 
                /* Add tag objects if needed */
                if ($this->is_administrational_unit){
-                       $this->objectclasses[]= "gosaAdministrativeUnit";
+      if(!in_array_ics("gosaAdministrativeUnit",$this->objectclasses)){
+                       $this->objectclasses[]= "gosaAdministrativeUnit";
+      }
                        if ($this->gosaUnitTag == ""){
 
                                /* It's unlikely, but check if already used... */
@@ -320,14 +331,24 @@ class department extends plugin
                }
                show_ldap_error($ldap->get_error());
 
-               
+    /* The parameter forces only to set must_be_tagged, and don't touch any objects 
+        This will be done later */
+    $this->tag_objects(true);
+    
     /* Optionally execute a command after we're done */
-    $this->must_be_tagged =true;
                $this->postcreate();
     return(true);
        }
 
 
+  function ShowMoveFrame()
+  {
+    $smarty = get_smarty();
+    $smarty->assign("src","?plug=".$_GET['plug']."&PerformRecMove");
+    $display=  $smarty->fetch(get_template_path("recursive_move.tpl",TRUE));
+    return($display);
+  }
+
   function ShowTagFrame()
   {
     $smarty = get_smarty();
@@ -337,7 +358,7 @@ class department extends plugin
   }
 
        /* Tag objects to have the gosaAdministrativeUnitTag */
-       function tag_objects()
+       function tag_objects($OnlySetTagFlag = false)
        {
                $add= $this->is_administrational_unit;
                $len= strlen($this->dn);
@@ -371,38 +392,36 @@ class department extends plugin
                                }
                        }
 
-                       /* Fix entry if needed */
-                       if ($fix){
-        echo "asdfasdfasdfasdf";
-                               $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, true);
+      /* Fix entry if needed */
+      if ($fix){
+        if($OnlySetTagFlag){
+          $this->must_be_tagged =true;
+          return;
+        }
+                               $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE );
                        }
                }
-                       echo '<p class="seperator">&nbsp;</p>';
-
-                       echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
-                               <br><input type='submit' name='back' value='"._("Continue")."'>
-                               </form></div>";
-
+    if(!$OnlySetTagFlag){
+      echo '<p class="seperator">&nbsp;</p>';
+      echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
+        <br><input type='submit' name='back' value='"._("Continue")."'>
+        </form></div>";
+    }
        }
 
 
        /* 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;
-
-                       $smarty = get_smarty();
-
-                       $smarty->assign("src","?plug=".$_GET['plug']."&PerformRecMove");
-
-                       $display=  $smarty->fetch(get_template_path("recursive_move.tpl",TRUE));
-                       return($display);
-
                }else{
+
+      /* If this is called, but not wanted, abort */
                        if(!$this->rec_cpy){ 
                                return;
                        }
@@ -426,7 +445,7 @@ class department extends plugin
                        if ($ldap->fetch()){
                                trigger_error("Recursive_move $dst_dn already exists.",
                                                E_USER_WARNING);
-                               echo sprintf_("Recursive_move: '%s' already exists", $dst_dn)."<br>"; 
+                               echo sprintf("Recursive_move: '%s' already exists", $dst_dn)."<br>"; 
                                return (FALSE);
                        }
 
@@ -478,17 +497,6 @@ class department extends plugin
                        return (TRUE);
                }
        }
-
-       function must_be_tagged()
-       {
-               return $this->must_be_tagged;
-       }
-
-       function am_i_moved()
-       {
-               return $this->rec_cpy;
-       }
-
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index 1d231605b9ad3496d60663baeb127f3729248faa..2fcbe8fdee774148b1fc1edbfb430f4d00d2b09c 100644 (file)
@@ -39,6 +39,10 @@ class departmentManagement extends plugin
        var $attributes= array();
        var $objectclasses= array();
 
+  var $ObjectInSaveMode         = false;
+  var $RecursiveRemoveRequested = false;
+  var $ObjectTaggingRequested   = false;
+
        function departmentManagement ($config, $ui)
        {
                $this->ui= $ui;
@@ -208,40 +212,6 @@ class departmentManagement extends plugin
                        }
                }
 
-
-               /* If this var ist true, the object will be unset after the next two operations */      
-               $UnsetAfterTaggingMoving = false;
-
-               /* This department must be tagged 
-                */
-               if((isset($_GET['TagDepartment'])) && ($this->deptabs->by_object['department']->must_be_tagged())){
-                       $this->deptabs->by_object['department']->tag_objects();
-                       $UnsetAfterTaggingMoving = true;
-       
-               }
-
-               /* 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);
-                       $UnsetAfterTaggingMoving = true;        
-               }
-
-               /* Unset current object / all operations are done */
-               if($UnsetAfterTaggingMoving){
-                       /* There's no page reload so we have to read new users at
-                          this point. */
-                       del_lock ($this->dn);
-                       $this->reload ();
-                       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 */
@@ -250,38 +220,19 @@ class departmentManagement extends plugin
                        /* Save, or display error message? */
                        if (count($message) == 0){
 
-                               $res = $this->deptabs->save(true);
-                               $display  = "";
-    
+                               $this->deptabs->save(true);
+        $this->deptabs->by_object['department']->save();     
         /* Get tagging frame */
                                if($this->deptabs->by_object['department']->must_be_tagged()){
-                                       $display .= $this->deptabs->by_object['department']->ShowTagFrame();    
-                               }               
+          $this->ObjectTaggingRequested   = true; 
+        }              
 
         /* Get recursive move frame */
                                if($this->deptabs->by_object['department']->am_i_moved()){      
-                                       $display .= $res;
+          $this->RecursiveRemoveRequested = true;
                                }               
-
-        /* If no frame is returned, unset this obejct, else display those frames */
-                               if(empty($display)){
-                                       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($display);
-                               }
+        $this->ObjectInSaveMode = true;
                        } else {
                                /* Ok. There seem to be errors regarding to the tab data,
                                   show message and continue as usual. */
@@ -289,6 +240,39 @@ class departmentManagement extends plugin
                        }
                }
 
+               /* This department must be tagged */
+               if((isset($_GET['TagDepartment'])) && ($this->ObjectTaggingRequested)){
+                       $this->deptabs->by_object['department']->tag_objects();
+      $this->ObjectTaggingRequested = false;
+      exit();  
+               }
+    /* initiate recursive remove*/
+               if((isset($_GET['PerformRecMove'])) &&($this->RecursiveRemoveRequested)){
+                       $this->deptabs->by_object['department']->recursive_move("","",true);
+      $this->RecursiveRemoveRequested = false;
+      exit();
+               }
+
+    if($this->ObjectTaggingRequested){
+      return($this->deptabs->by_object['department']->ShowTagFrame());
+    }
+    if($this->RecursiveRemoveRequested){
+      return($this->deptabs->by_object['department']->ShowMoveFrame());
+    }
+
+               /* Unset current object / all operations are done */
+               if($this->ObjectInSaveMode && (!$this->RecursiveRemoveRequested) && (!$this->ObjectTaggingRequested)){
+      $this->deptabs->save();
+      $this->ObjectInSaveMode = false;
+      if ($this->dn != "new"){
+        del_lock ($this->dn);
+      }
+               gosa_log ("Department object'".$this->dn."' has been saved");
+                       $this->reload ();
+                       unset ($this->deptabs);
+                       $this->deptabs= NULL;
+                       unset ($_SESSION['objectinfo']);
+               }
 
                /* User cancelt edit oder delete
                 * Cancel dialog 
index 77834bb271b14e827d6e43b66bc4c367a3b1a878..f5d771bde0170033e5bdfba5a331a79edfe40024 100644 (file)
@@ -6,40 +6,40 @@ class deptabs extends tabs
 
   function deptabs($config, $data, $dn)
   {
-       tabs::tabs($config, $data, $dn);
-       $this->base= $this->by_object['department']->base;
+    tabs::tabs($config, $data, $dn);
+    $this->base= $this->by_object['department']->base;
   }
 
   function check()
   {
-       return (tabs::check(TRUE));
+    return (tabs::check(TRUE));
   }
-  
+
 
   function save($justsave = false)
   {
-       if(!$justsave){
-               $baseobject= $this->by_object['department'];
-               $ou= preg_replace('/,/', '\,', $baseobject->ou);
-               $new_dn= @LDAP::convert('ou='.$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;
-       }
-       return(tabs::save(TRUE));
+    $baseobject= $this->by_object['department'];
+    $ou= preg_replace('/,/', '\,', $baseobject->ou);
+    $new_dn= @LDAP::convert('ou='.$ou.','.$baseobject->base);
+    
+    if($justsave){
+      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{
+          /* Prepare to be moved */
+          $baseobject->recursive_move($this->dn, $new_dn);                     
+          return;
+        }
+      }
+    }
+    $this->dn= $new_dn;
+    return(tabs::save(TRUE));
   }
 
 }
-
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>