Code

Updated department handling for the rootDSE entry.
[gosa.git] / gosa-core / plugins / admin / departments / class_departmentGeneric.inc
index 7b3736f7ede389e27a2b9a0d1478a2a42c2b81a9..d6cd8e31dfb8cd66e158e8fa94235268373129f9 100644 (file)
@@ -36,6 +36,9 @@ class department extends plugin
        var $gosaUnitTag= "";
   var $view_logged = FALSE;
 
+  var $type ="ou";
+  var $namingAttr = "ou";
+
        /* Headpage attributes */
        var $last_dep_sorting= "invalid";
        var $departments= array();
@@ -58,7 +61,13 @@ class department extends plugin
                $this->ui= get_userinfo();
                $this->dn= $dn;
                $this->orig_dn= $dn;
-               $this->orig_ou= $this->ou;
+
+    /* Save current naming attribuet 
+     */
+    $nA      = $this->namingAttr;
+    $orig_nA = "orig_".$nA;
+    $this->$orig_nA = $this->$nA;
+
                $this->config= $config;
 
                /* Set base */
@@ -103,6 +112,15 @@ class department extends plugin
       $smarty->assign($name."ACL",$this->getacl($name));
     }
 
+    /* Hide base selector, if this object represents the base itself 
+     */
+    $smarty->assign("is_root_dse", FALSE);
+    if($this->dn == $this->config->current['BASE']){
+      $smarty->assign("is_root_dse", TRUE);
+      $nA = $this->namingAttr."ACL";
+      $smarty->assign($nA,$this->getacl($this->namingAttr,TRUE));
+    }
+
                /* Base select dialog */
                $once = true;
                foreach($_POST as $name => $value){
@@ -162,7 +180,22 @@ class department extends plugin
       $smarty->assign("unitTag", "");
     }
 
-               return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
+    $smarty->assign("dep_type",$this->type);
+    
+
+    $dep_types = departmentManagement::get_support_departments();
+    $tpl ="";
+    foreach($dep_types as $key => $data){
+      if($data['ATTR'] == $this->type){
+        $tpl = $data['TPL'];
+        break;
+      }
+    }
+    if($tpl == "") {
+      trigger_error("No template specified for container type '".$this->type."', please update epartmentManagement::get_support_departments().");
+      $tpl = "generic.tpl";
+    }
+               return($smarty->fetch (get_template_path($tpl, TRUE)));
        }
 
        function clear_fields()
@@ -179,7 +212,7 @@ class department extends plugin
        {
                $ldap= $this->config->get_ldap_link();
                $ldap->cd ($this->dn);
-               $ldap->recursive_remove();
+               $ldap->rmdir_recursive($this->dn);
     new log("remove","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     if (!$ldap->success()){
       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
@@ -197,7 +230,12 @@ class department extends plugin
        /* Save data to object */
        function save_object()
        {
-               if (isset($_POST['dep_generic_posted'])){
+    if (isset($_POST['dep_generic_posted'])){
+
+      $nA = $this->namingAttr;
+      $old_nA = $this->$nA;
+
+
 
       /* Create a base backup and reset the
          base directly after calling plugin::save_object();
@@ -222,6 +260,13 @@ class department extends plugin
           $this->is_administrational_unit= false;
         }
       }
+
+      /* If this is the root directory service entry (rootDSE)
+         then avoid changing the naming attribute of this entry.
+       */
+      if($this->dn == $this->config->current['BASE']){
+        $this->$nA = $old_nA;
+      }
     }
        }
 
@@ -280,6 +325,11 @@ class department extends plugin
        {
                $ldap= $this->config->get_ldap_link();
 
+    /* Ensure that ou is saved too, it is required by objectClass gosaDepartment 
+     */
+    $nA = $this->namingAttr;
+    $this->ou = $this->$nA;
+
     /* Add tag objects if needed */
     if ($this->is_administrational_unit){
 
@@ -662,47 +712,6 @@ class department extends plugin
     }
   }
 
-
-  
-  /*! \brief    Returns a list of all available departments for this object.
-                If this object is new, all departments we are allowed to create a new user in are returned.
-                If this is an existing object, return all deps. we are allowed to move tis object too.
-
-      @return   Array [dn] => "..name"  // All deps. we are allowed to act on.
-  */
-  function get_allowed_bases()
-  {
-    $ui = get_userinfo();
-    $deps = array();
-
-    /* Is this a new object ? Or just an edited existing object */
-    if(!$this->initially_was_account && $this->is_account){
-      $new = true;
-    }else{
-      $new = false;
-    }
-
-    $ideps = $this->config->idepartments;
-    if(!isset($ideps[$this->base])){
-      $ideps[$this->base] = ".";
-    }
-    foreach($deps as $dn => $name){
-      if($new && $this->acl_is_createable($dn)){
-        $deps[$dn] = $name;
-      }elseif(!$new && $this->acl_is_moveable($dn)){
-        $deps[$dn] = $name;
-      }
-    }
-
-    /* Add current base */
-    if(isset($this->base) && isset($ideps[$this->base])){
-      $deps[$this->base] = $ideps[$this->base];
-    }else{
-      trigger_error("Cannot return list of departments, no default base found in class ".get_class($this).". ".$this->base);
-    }
-    return($deps);
-  }
-
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: