Code

Switched html_options from values+output to options
[gosa.git] / plugins / admin / fai / class_faiVariable.inc
index 7d4f8fb628740b5a4f174f1ed1ff43c9430c3713..f0949890e14ea2aa1469139846b6845a96264108 100644 (file)
@@ -25,7 +25,7 @@ class faiVariable extends plugin
 
   /* Attributes to initialise for each subObject */
   var $subAttributes    = array("cn","description","FAIvariableContent"); 
-  var $sub64coded       = array("FAIvariableContent");  
+  var $sub64coded       = array();  
 
   /* Specific attributes */
   var $cn               = "";       // The class name for this object
@@ -34,18 +34,36 @@ class faiVariable extends plugin
   var $dialog           = NULL;     // a dialog, e.g. new disk dialog
   var $SubObjects       = array();  // All leafobjects of this object
 
+  var $FAIstate         = "";
+
   function faiVariable ($config, $dn= NULL)
   {
     /* Load Attributes */
     plugin::plugin ($config, $dn);
 
+    $this->acl ="#all#";
+
     /* If "dn==new" we try to create a new entry
      * Else we must read all objects from ldap which belong to this entry.
      * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
      */
+
     if($dn != "new"){
       $this->dn =$dn;
 
+      /* Set acls
+       */
+      $ui   = get_userinfo();
+      $acl  = get_permissions ($this->dn, $ui->subtreeACL);
+      $acli = get_module_permission($acl, "FAIclass", $this->dn);
+      $this->acl=$acli;
+
+      /* 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();
@@ -75,6 +93,9 @@ class faiVariable extends plugin
 
   function execute()
   {
+       /* Call parent execute */
+       plugin::execute();
+
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
@@ -82,21 +103,33 @@ class faiVariable extends plugin
     /* Add new sub object */
     if(isset($_POST['AddSubObject'])){
       $this->dialog= new $this->subClassName($this->config,"new");
+      $this->dialog->acl = $this->acl;
       $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']]);
+
+      $var = $_POST['SubObject'][0];
+      $this->dialog= new $this->subClassName($this->config,$this->dn,$this->SubObjects[$var]);
+      $this->dialog->acl = $this->acl;
+      $_SESSION['objectinfo'] = $this->SubObjects[$var]['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 $var){
+        if($this->SubObjects[$var]['status'] == "edited"){
+          $this->SubObjects[$var]['status']= "delete";
+        }else{
+          unset($this->SubObjects[$var]);
+        }
       }
     }
 
@@ -128,6 +161,17 @@ class faiVariable 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; 
@@ -143,19 +187,23 @@ class faiVariable extends plugin
     }
 
     $smarty->assign("SubObjects",$this->getList());
-    $smarty->assign("SubObjectKeys",array_flip($this->getList()));
 
       /* Magic quotes GPC, escapes every ' " \, to solve some security risks
      * If we post the escaped strings they will be escaped again
      */
+
     foreach($this->attributes as $attrs){
       if(get_magic_quotes_gpc()){
-        $smarty->assign($attrs,stripslashes($this->$attrs));
+        $smarty->assign($attrs,htmlentities (stripslashes(utf8_decode($this->$attrs))));
       }else{
-        $smarty->assign($attrs,($this->$attrs));
+        $smarty->assign($attrs,htmlentities (utf8_decode($this->$attrs)));
       }
     }
 
+      foreach($this->attributes as $attr){
+      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
+    }
+
 
     $display.= $smarty->fetch(get_template_path('faiVariable.tpl', TRUE));
     return($display);
@@ -201,7 +249,7 @@ class faiVariable extends plugin
    */
   function save_object()
   {
-    if(isset($_POST['FAIvariable_posted'])){
+    if((isset($_POST['FAIvariable_posted'])) && ($this->FAIstate != "freeze") ){
       plugin::save_object();
       foreach($this->attributes as $attrs){
         if(isset($_POST[$attrs])){
@@ -215,7 +263,9 @@ class faiVariable extends plugin
   /* Check supplied data */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
+
     return ($message);
   }
 
@@ -231,7 +281,9 @@ class faiVariable 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(preg_replace('/^[^,]+,[^,]+,/', '', $this->dn));
@@ -289,7 +341,9 @@ class faiVariable 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"){