Code

Updated FAI template entry.
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiScript.inc
index d94b760c24e9e159ac6dd1b6182422f7117eab56..db8e38e68da18b904c6dcee6e003bacc3a2fb982 100644 (file)
@@ -30,7 +30,7 @@ class faiScript extends plugin
   var $is_dialog        = false;    // specifies which buttons will be shown to save or abort
   var $SubObjects       = array();  // All leafobjects of this object
 
-  var $FAIstate         = "";
+  var $FAIstate         = "branch";
   var $sort_by          = "name";
   var $sort_order       = "up";
 
@@ -47,45 +47,29 @@ class faiScript extends plugin
      * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
      */
     if($dn != "new"){
-
       $this->dn =$dn;
 
-      /* Get FAIstate
-       */
-      if(isset($this->attrs['FAIstate'][0])){
-        $this->FAIstate = $this->attrs['FAIstate'][0];
-      }
-
       /* 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;
       }
-    
     }
+
+    $this->is_new = FALSE;
+    if($this->dn == "new"){
+      $this->is_new =TRUE;
+    }
     $this->ui = get_userinfo();
   }
 
@@ -124,9 +108,9 @@ class faiScript extends plugin
   /* Return a valid dn to fetch acls. Because 'new' will not work. */
   function acl_base_for_current_object($dn)
   {
-    if($dn == "new"){
+    if($dn == "new" || $dn == ""){
       if($this->dn == "new"){
-        $dn= "cn=dummy,".session::get('CurrentMainBase');
+        $dn= $this->parent->parent->acl_base;
       }else{
         $dn = $this->dn;
       }
@@ -150,8 +134,9 @@ class faiScript extends plugin
     $display= "";
 
     /* Add new sub object */
-    if(isset($_POST['AddSubObject'])){
+    if(isset($_POST['AddSubObject']) && !preg_match("/freeze/i",$this->FAIstate)){
       $this->dialog= new $this->subClassName($this->config,"new");
+      $this->dialog->FAIstate = $this->FAIstate;
       $this->dialog->set_acl_base($this->acl_base);
       $this->dialog->set_acl_category("fai");
       $this->dialog->parent = &$this;
@@ -184,7 +169,7 @@ class faiScript extends plugin
       }
 
       /* Delete script requested */
-      if(preg_match("/^deletescript_/",$name)){
+      if(preg_match("/^deletescript_/",$name) && !preg_match("/freeze/i",$this->FAIstate)){
         $s_action = "remove";
         $s_entry = preg_replace("/^deletescript_/","",$name);
         $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
@@ -209,6 +194,7 @@ class faiScript extends plugin
 
       /* Create new dialog and set acl attributes  */
       $this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
+      $this->dialog->FAIstate = $this->FAIstate;
       $this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn']));
       $this->dialog->set_acl_category("fai");
 
@@ -325,9 +311,9 @@ class faiScript extends plugin
     $plug = $_GET['plug'];
    
     if($this->sort_order == "up"){
-      $dir = "<img src='images/sort_up.png' title='"._("Sort direction")."' alt='\/' border=0>";
+      $dir = "<img src='images/lists/sort-up.png' title='"._("Sort direction")."' alt='\/' border=0>";
     }else{
-      $dir = "<img src='images/sort_down.png' title='"._("Sort direction")."' alt='/\' border=0>";
+      $dir = "<img src='images/lists/sort-down.png' title='"._("Sort direction")."' alt='/\' border=0>";
     }
  
     if($this->sort_by == "name"){
@@ -355,11 +341,11 @@ class faiScript extends plugin
       
       /* Hide delete icon if this object is freezed */
       if(preg_match("/freeze/", $this->FAIstate)){
-        $act .= "<input type='image' src='images/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
+        $act .= "<input type='image' src='images/lists/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
       }else{
-        $act .= "<input type='image' src='images/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
+        $act .= "<input type='image' src='images/lists/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
         if(preg_match("/d/",$acl)){
-          $act .="<input type='image' src='images/edittrash.png' name='deletescript_%s'  title='"._("delete")."' alt='"._("delete")."'>";
+          $act .="<input type='image' src='images/lists/trash.png' name='deletescript_%s'  title='"._("delete")."' alt='"._("delete")."'>";
         }
       }
 
@@ -445,21 +431,13 @@ class faiScript extends plugin
     if($this->acl_is_removeable()){
       $ldap = $this->config->get_ldap_link();
       $ldap->cd ($this->dn);
-      $faifilter = session::get('faifilter');
-      $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
-      if($faifilter['branch'] == "main"){
-        $use_dn = $this->dn;
-      }
-   
+      $release = $this->parent->parent->fai_release;
+      $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", $faifilter['branch'], $obj['dn']);
-        if($faifilter['branch'] == "main"){
-          $use_dn = $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");
@@ -473,11 +451,6 @@ class faiScript extends plugin
   {
     if((isset($_POST['FAIscript_posted'])) && !preg_match("/freeze/", $this->FAIstate)){
       plugin::save_object();
-      foreach($this->attributes as $attrs){
-        if(isset($_POST[$attrs])){
-          $this->$attrs = $_POST[$attrs];
-        }
-      }
     }
     
     /* Get sort order */
@@ -503,12 +476,8 @@ class faiScript extends plugin
     /* Ensure that we do not overwrite an allready existing entry 
      */
     if($this->is_new){
-      $new_dn= 'cn='.$this->cn.",".get_ou('faiscriptou').get_ou('faiou').session::get('CurrentMainBase');
-      $faifilter = session::get('faifilter');
-      if($faifilter['branch']!="main"){
-        $new_dn ='cn='.$this->cn.",".get_ou('faiscriptou').$faifilter['branch'];
-      }
-
+      $release = $this->parent->parent->fai_release;
+      $new_dn= 'cn='.$this->cn.",".get_ou('faiScriptRDN').get_ou('faiBaseRDN').$release;
       $res = faiManagement::check_class_name("FAIscript",$this->cn,$new_dn);
       if(isset($res[$this->cn])){
         $message[] = msgPool::duplicated(_("Name"));
@@ -568,8 +537,8 @@ class faiScript 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])) continue; 
+        if($obj[$attrs] == ""){
           $obj[$attrs] = array();
         }
         if(!is_array($obj[$attrs])){
@@ -617,29 +586,17 @@ class faiScript 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;
     }
   }