Code

Upps
[gosa.git] / plugins / admin / fai / class_faiScriptEntry.inc
index f7a22077d0abaa23f784d1606ed41eaf8f8a1397..617de2612d6d27e72b8d0ec6a1192ccc35c730b9 100644 (file)
@@ -20,6 +20,8 @@ class faiScriptEntry extends plugin
   var $FAIscript     = "";
   var $description   = "";
   var $status        = "new";
+
+  var $FAIstate      = "";
   
   function faiScriptEntry ($config, $dn= NULL,$object=false)
   {
@@ -31,14 +33,32 @@ class faiScriptEntry extends plugin
         $oname = $name;
         $this->$oname=$value;
       }
+
+      if(isset($this->attrs['FAIstate'][0])){
+        $this->FAIstate = $this->attrs['FAIstate'][0];
+      }
+
     }else{
-      $this->status = "new";
-      $this->orig_cn       = false;
+      if(is_array($object)&&count($object)){
+        $this->orig_cn= $object['cn'];
+        $this->dn=$object['dn'];
+        foreach($object as $name=>$value){
+          $oname = $name;
+          $this->$oname=$value;
+        }
+      }else{
+
+        $this->status = "new";
+        $this->orig_cn       = false;
+      }
     }
   }
 
   function execute()
   {
+       /* Call parent execute */
+       plugin::execute();
+
     /* Fill templating stuff */
     $smarty     = get_smarty();
     $display = "";
@@ -50,11 +70,10 @@ class faiScriptEntry extends plugin
       if(($_FILES['ImportFile']['size']==0)){
         print_red(_("Selected file is empty."));
       }else{
-        $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
+        $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
         $this->FAIscript = $str;
       }
     }
-
   
     foreach($this->attributes as $attrs){
       if(get_magic_quotes_gpc()){
@@ -64,9 +83,27 @@ class faiScriptEntry extends plugin
       } 
     }
 
+     /* Create download button*/
+    if($this->dn != "new"){
+      $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
+        <input type='button' value='"._("Download")."'>
+        </a>");
+    }else{
+      $smarty->assign("DownMe","");
+    }
+
     for($i =0 ; $i < 100 ; $i++){
       $FAIprioritys[$i]=$i;
     }
+
+    foreach($this->attributes as $attr){
+      if(($this->FAIstate == "freeze") || (chkacl($this->acl,$attr)!= "")){
+        $smarty->assign($attr."ACL"," disabled ");
+      }else{
+        $smarty->assign($attr."ACL","  ");
+      }
+    }
+
     $smarty->assign("FAIprioritys",$FAIprioritys);
     $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
     return($display);
@@ -75,7 +112,7 @@ class faiScriptEntry extends plugin
   /* Save data to object */
   function save_object()
   {
-    if(isset($_POST['SubObjectFormSubmitted'])){
+    if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
       foreach($this->attributes as $attrs){
         if(isset($_POST[$attrs])){
           $this->$attrs = $_POST[$attrs];
@@ -89,7 +126,8 @@ class faiScriptEntry extends plugin
   /* Check supplied data */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
   
     if(empty($this->cn)){
       $message[] = _("Please enter a name.");
@@ -109,6 +147,9 @@ class faiScriptEntry extends plugin
       $tmp[$attrs] = $this->$attrs;
     }
 
+    /* Strip out dos newlines */
+    $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
+
     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
       $tmp['remove']['from']  = $this->orig_cn;
       $tmp['remove']['to']    = $tmp['cn'];