Code

Updated FAI template entry.
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiTemplate.inc
index 75ee77434948fb8f7fcae7108fac6ade8be0e479..0c2dca46dd7cb6853f95c1d43ebb397c85784abf 100644 (file)
@@ -48,30 +48,15 @@ class faiTemplate extends plugin
 
       /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
        */
-      $ldap     = $this->config->get_ldap_link();
-      $ldap->cd ($this->dn);
-    
-      $attrs_to_search = $this->subAttributes;
-      $attrs_to_search[] = "FAIstate";
-      $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search);
-
-      $data = array();
-      while($object = $ldap->fetch()){
-        $data[] = $object;
-      }
-      foreach($data as $object){
+      $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
+      foreach($res as $obj){
 
-        /* Skip objects, that are tagged as removed */
-        if(isset($object['FAIstate'][0])){
-          if(preg_match("/removed$/",$object['FAIstate'][0])){
-            continue;
-          }
-        }
+        /* Skip not relevant objects */
+        if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
 
-        /* Set status for save management */
         $objects = array();
         $objects['status']      = "FreshLoaded";
-        $objects['dn']          = $object['dn'];
+        $objects['dn']          = $obj['dn'];
         $objects                = $this->get_object_attributes($objects,$this->subAttributes);
         $this->SubObjects[$objects['cn']] = $objects;
       }
@@ -186,12 +171,13 @@ class faiTemplate extends plugin
     if(isset($_GET['act']) && isset($_GET['id'])){
       if($_GET['act'] == "edit" && isset($this->SubObjects[$_GET['id']])){
         $obj = $this->SubObjects[$_GET['id']];
-          if($obj['status'] == "FreshLoaded"){
+        if($obj['status'] == "FreshLoaded"){
           $obj  = $this->get_object_attributes($obj,$this->sub_Load_Later);
         }
         $this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
         $this->dialog->FAIstate = $this->FAIstate;
         $this->dialog->acl = $this->acl;
+        $this->dialog->set_acl_category("fai");
         session::set('objectinfo',$obj['dn']);
         $this->dialog->parent = &$this;
         $this->is_dialog=true;
@@ -200,7 +186,7 @@ class faiTemplate extends plugin
 
     /* Add new sub object */
     if(isset($_POST['AddSubObject']) && !preg_match("/freeze/",$this->FAIstate)){
-      $acl_dn = "cn=dummy,".$this->acl_base_for_current_object($this->dn);
+      $acl_dn = $this->acl_base_for_current_object($this->dn);
       $acl    = $this->ui->get_permissions($acl_dn,"fai/faiTemplateEntry");
 
       if(preg_match("/c/",$acl)){
@@ -357,9 +343,9 @@ class faiTemplate extends plugin
 
   function acl_base_for_current_object($dn)
   {
-    if($dn == "new"){
+    if($dn == "new" || $dn == ""){
       if($this->dn == "new"){
-        $dn = session::get('CurrentMainBase');
+        $dn = $dn= $this->parent->parent->acl_base;
       }else{
         $dn = $this->dn;
       }
@@ -396,12 +382,12 @@ class faiTemplate extends plugin
       $ldap = $this->config->get_ldap_link();
       $ldap->cd ($this->dn);
       $release = $this->parent->parent->fai_release;
-      $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $release, $this->dn);
+      $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn, '/'))."/i", $release, $this->dn);
       new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
       FAI::prepare_to_save_FAI_object($use_dn,array(),true);
 
       foreach($this->SubObjects as $name => $obj){
-        $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $release, $obj['dn']);
+        $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $obj['dn']);
         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
       }
       $this->handle_post_events("remove");
@@ -429,7 +415,7 @@ class faiTemplate extends plugin
      */
     if($this->is_new){
       $release = $this->parent->parent->fai_release;
-      $new_dn= 'cn='.$this->cn.",".get_ou('faitemplateou').get_ou('faiou').$release;
+      $new_dn= 'cn='.$this->cn.",".get_ou('faiTemplateRDN').get_ou('faiBaseRDN').$release;
       $res = faiManagement::check_class_name("FAItemplate",$this->cn,$new_dn);
       if(isset($res[$this->cn])){
         $message[] = msgPool::duplicated(_("Name"));
@@ -487,7 +473,7 @@ class faiTemplate extends plugin
       $tmp = array();
       $attributes = array_merge($this->sub_Load_Later,$this->subAttributes);
       foreach($attributes as $attrs){
-        if(empty($obj[$attrs])){
+        if(!isset($obj[$attrs]) || $obj[$attrs] == ""){
           $obj[$attrs] = array();
         }
         $tmp[$attrs] =($obj[$attrs]);
@@ -527,29 +513,17 @@ class faiTemplate extends plugin
 
     /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
      */
-    $ldap     = $this->config->get_ldap_link();
-    $ldap->cd ($source['dn']);
+    $res = FAI::get_all_objects_for_given_base($source['dn'],"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
+    foreach($res as $obj){
 
-    $attrs_to_search = $this->subAttributes;
-    $attrs_to_search[] = "FAIstate";
-    $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search);
+      /* Skip not relevant objects */
+      if(!preg_match("/".preg_quote($source['dn'], '/')."$/i",$obj['dn'])) continue;
 
-    while($object = $ldap->fetch()){
-
-      /* Skip objects, that are tagged as removed */
-      if(isset($object['FAIstate'][0])){
-        if(preg_match("/removed$/",$object['FAIstate'][0])){
-          continue;
-        }
-      }
-
-      /* Set status for save management */
       $objects = array();
       $objects['status']      = "edited";
-      $objects['dn']          = $object['dn'];
+      $objects['dn']          = $obj['dn'];
       $objects                = $this->get_object_attributes($objects,$this->subAttributes);
       $objects                = $this->get_object_attributes($objects,$this->sub_Load_Later);
-
       $this->SubObjects[$objects['cn']] = $objects;
     }
   }