Code

Some page reload fixes,
[gosa.git] / plugins / admin / fai / class_faiTemplate.inc
index fd30c52e0204386f0fd2096d3695b4e62262815a..10f81c719542047b246f5f68c7dd0987689b1538 100644 (file)
@@ -24,8 +24,8 @@ class faiTemplate extends plugin
   var $subClassName     = "faiTemplateEntry";      
 
   /* Attributes to initialise for each subObject */
-  var $subAttributes    = array("cn","description","FAItemplateFile","FAItemplatePath"); 
-  var $sub64coded       = array("FAItemplateFile","FAItemplatePath");
+  var $subAttributes    = array("cn","description","FAItemplateFile","FAItemplatePath","FAIowner","FAImode"); 
+  var $sub64coded       = array();
 
   /* Specific attributes */
   var $cn               = "";       // The class name for this object
@@ -64,19 +64,22 @@ class faiTemplate extends plugin
         }
 
         foreach($this->sub64coded as $codeIt){
-          $this->SubObjects[$object['cn'][0]][$codeIt]=base64_decode($this->SubObjects[$object['cn'][0]][$codeIt]);
+          $this->SubObjects[$object['cn'][0]][$codeIt]= base64_decode($this->SubObjects[$object['cn'][0]][$codeIt]);
         }       
 
-        $this->SubObjects[$object['cn'][0]]['FAItemplateFile'] =base64_decode($this->readBinary("FAItemplateFile",$object['dn']));
+        $this->SubObjects[$object['cn'][0]]['FAItemplateFile']= $this->readBinary("FAItemplateFile",$object['dn']);
        
-        $this->SubObjects[$object['cn'][0]]['status']      = "edited";
-        $this->SubObjects[$object['cn'][0]]['dn']          = $object['dn'];
+        $this->SubObjects[$object['cn'][0]]['status']= "edited";
+        $this->SubObjects[$object['cn'][0]]['dn']= $object['dn'];
       }
     }
   }
 
   function execute()
   {
+       /* Call parent execute */
+       plugin::execute();
+
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
@@ -87,18 +90,29 @@ class faiTemplate extends plugin
       $this->is_dialog=true;
     }
 
+    if($this->dn != "new"){
+      $_SESSION['objectinfo']= $this->dn;
+    }
+
+
     /* Edit selected Sub Object */
     if((isset($_POST['EditSubObject']))&&(isset($_POST['SubObject']))){
-      $this->dialog= new $this->subClassName($this->config,$this->dn,$this->SubObjects[$_POST['SubObject']]);
+
+      $temp = $_POST['SubObject'][0];
+    
+      $this->dialog= new $this->subClassName($this->config,$this->dn,$this->SubObjects[$temp]);
+      $_SESSION['objectinfo'] = $this->SubObjects[$temp]['dn'];
       $this->is_dialog=true;
     }
     
     /* Remove Sub object */
     if((isset($_POST['DelSubObject']))&&(isset($_POST['SubObject']))){
-      if($this->SubObjects[$_POST['SubObject']]['status'] == "edited"){
-        $this->SubObjects[$_POST['SubObject']]['status']= "delete";
-      }else{
-        unset($this->SubObjects[$_POST['SubObject']]);
+      foreach($_POST['SubObject'] as $temp){
+        if($this->SubObjects[$temp]['status'] == "edited"){
+          $this->SubObjects[$temp]['status']= "delete";
+        }else{
+          unset($this->SubObjects[$temp]);
+        }
       }
     }
 
@@ -130,6 +144,17 @@ class faiTemplate extends plugin
       }
     }
 
+    /* Sort entries */
+    $tmp = $keys = array();
+    foreach($this->SubObjects as $key => $entry){
+      $keys[$key]=$key;
+    }
+    natcasesort($keys);
+    foreach($keys as $key){
+      $tmp[$key]=$this->SubObjects[$key];
+    }
+    $this->SubObjects = $tmp;
+
     /* Cancel Dialog */
     if(isset($_POST['CancelSubObject'])){
       $this->is_dialog=false; 
@@ -169,7 +194,11 @@ class faiTemplate extends plugin
     $a_return=array();
     foreach($this->SubObjects as $obj){
       if($obj['status'] != "delete"){
+      
         if((isset($obj['description']))&&(!empty($obj['description']))){
+          if(strlen($obj['description']) > 40){
+            $obj['description'] = substr($obj['description'],0,40)."...";
+          }
           $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]";
         }else{
           $a_return[$obj['cn']]= $obj['cn'];
@@ -194,10 +223,12 @@ class faiTemplate extends plugin
    */
   function save_object()
   {
-    plugin::save_object();
-    foreach($this->attributes as $attrs){
-      if(isset($_POST[$attrs])){
-        $this->$attrs = $_POST[$attrs];
+    if(isset($_POST['FAItemplate_posted'])){
+      plugin::save_object();
+      foreach($this->attributes as $attrs){
+        if(isset($_POST[$attrs])){
+          $this->$attrs = $_POST[$attrs];
+        } 
       }
     }
   }
@@ -222,7 +253,9 @@ class faiTemplate extends plugin
     if($ldap->count()!=0){
       /* Write FAIscript to ldap*/
       $ldap->cd($this->dn);
-      $ldap->modify($this->attrs);
+      $this->cleanup();
+$ldap->modify ($this->attrs); 
+
     }else{
       /* Write FAIscript to ldap*/
       $ldap->cd($this->config->current['BASE']);
@@ -279,7 +312,9 @@ class faiTemplate extends plugin
         $this->handle_post_events("remove");
       }elseif($obj['status'] == "edited"){
         $ldap->cd($sub_dn);
-        $ldap->modify($tmp);
+        $this->cleanup();
+$ldap->modify ($tmp); 
+
         $this->handle_post_events("modify");
       }elseif($obj['status']=="new"){