Code

Initial commit for department tagging & recursive move
[gosa.git] / plugins / admin / departments / tabs_department.inc
index de5e877d1703d1793cc030851b0d7d8a62053004..f5d771bde0170033e5bdfba5a331a79edfe40024 100644 (file)
@@ -6,29 +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()
-  {
-       $baseobject= $this->by_object['department'];
-       $new_dn= 'ou='.$baseobject->ou.','.$baseobject->base;
-
-       if ($this->dn != $new_dn && $this->dn != "new"){
-               $baseobject->recursive_move($this->dn, $new_dn);
-       }
-       $this->dn= $new_dn;
 
-       tabs::save(TRUE);
+  function save($justsave = false)
+  {
+    $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:
 ?>