Code

Fixed problem with not clickable buttons in fai package error msgs
[gosa.git] / plugins / admin / fai / class_faiScriptEntry.inc
index 4d337ca4b3990adf3ac956de5590032cd571208b..4f5cf2990f647fff755bbdeee24b3c1f3a999d13 100644 (file)
@@ -9,17 +9,19 @@ class faiScriptEntry extends plugin
 
   /* attribute list for save action */
   var $ignore_account= TRUE;
-  var $attributes   = array("Object_cn","Object_description","Object_FAIpriority","Object_FAIscript");
+  var $attributes   = array("cn","description","FAIpriority","FAIscript");
   var $objectclasses= array();
 
   var $orig_cn              = "";
 
-  var $Object_dn            = "";
-  var $Object_cn            = "";
-  var $Object_FAIpriority   = "";
-  var $Object_FAIscript     = "";
-  var $Object_description   = "";
-  var $Object_status        = "new";
+  var $dn            = "";
+  var $cn            = "";
+  var $FAIpriority   = "0";
+  var $FAIscript     = "";
+  var $description   = "";
+  var $status        = "new";
+  var $parent        = NULL;
+  var $FAIstate      = "";
   
   function faiScriptEntry ($config, $dn= NULL,$object=false)
   {
@@ -28,43 +30,82 @@ class faiScriptEntry extends plugin
       $this->orig_cn= $object['cn'];
       $this->dn=$object['dn'];
       foreach($object as $name=>$value){
-        $oname = "Object_".$name;
+        $oname = $name;
         $this->$oname=$value;
       }
+
+      if(isset($this->attrs['FAIstate'][0])){
+        $this->FAIstate = $this->attrs['FAIstate'][0];
+      }
+
     }else{
-      $this->Object_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 = "";
   
-    if(isset($_POST['ImportUpload'])){
+    if(isset($_POST['ImportUpload']) && $this->acl_is_writeable("FAIscript")){
       if(($_FILES['ImportFile']['error']!=0)){
         print_red(_("Please select a valid file."));
       }else
       if(($_FILES['ImportFile']['size']==0)){
         print_red(_("Selected file is empty."));
       }else{
-        $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
-        $this->Object_FAIscript = $str;
+        $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
+        $this->FAIscript = $str;
       }
     }
-
   
-
     foreach($this->attributes as $attrs){
-      $smarty->assign($attrs,stripslashes($this->$attrs));
+      if(get_magic_quotes_gpc()){
+       $smarty->assign($attrs,stripslashes($this->$attrs));
+      }else{
+       $smarty->assign($attrs,($this->$attrs));
+      } 
     }
 
-    for($i =1 ; $i <= 100 ; $i++){
-      $Object_FAIprioritys[$i]=$i;
+     /* Create download button*/
+    if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
+      $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
+        <input type='button' value='"._("Download")."'>
+        </a>");
+    }else{
+      $smarty->assign("DownMe","");
     }
-    $smarty->assign("Object_FAIprioritys",$Object_FAIprioritys);
+
+    for($i =0 ; $i < 100 ; $i++){
+      $FAIprioritys[$i]=$i;
+    }
+
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translated){
+      $acl = $this->getacl($name);
+      if($this->FAIstate == "freezed"){
+        $acl = preg_replace("/w/","",$acl);
+      }
+      $smarty->assign($name."ACL",$acl);
+    }
+
+    $smarty->assign("FAIprioritys",$FAIprioritys);
     $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
     return($display);
   }
@@ -72,12 +113,14 @@ 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];
-        }else{
-          $this->$attrs = "";
+        if($this->acl_is_writeable($attrs)){
+          if(isset($_POST[$attrs])){
+            $this->$attrs = $_POST[$attrs];
+          }else{
+            $this->$attrs = "";
+          }
         }
       }
     }
@@ -86,26 +129,21 @@ class faiScriptEntry extends plugin
   /* Check supplied data */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
   
-    $str = utf8_encode("üöä");
-
-    if(empty($this->Object_FAIscript)){
-      $message[]=_("Please specify a script.");
-    }
-    
-    if(preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->Object_description)){
-      $message[] = _("Invalid character in description. Please enter a valid description.");
+    if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
+      $message[] =_("There is already a script with the given name.");
     }
 
-    if(empty($this->Object_cn)){
+    if(empty($this->cn)){
       $message[] = _("Please enter a name.");
     }
 
-    if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
-      $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
+    if(empty($this->FAIscript)){
+      $message[]=_("Please enter a script.");
     }
+
     return ($message);
   }
  
@@ -113,19 +151,43 @@ class faiScriptEntry extends plugin
   {
     $tmp=array();
     foreach($this->attributes as $attrs){ 
-      $attr = preg_replace("/^Object_/","",$attrs);
-      $tmp[$attr] = $this->$attrs;
+      $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'];
     }
   
     $tmp['dn']      = $this->dn;  
-    $tmp['status']  = $this->Object_status; 
+    $tmp['status']  = $this->status; 
     return($tmp);
   }
+
+  
+  /* Return plugin informations for acl handling */
+  function plInfo()
+  {
+    return (array(
+          "plShortName" => _("Script entry"),
+          "plDescription" => _("FAI script entry"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 19,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("fai"),
+          "plProvidedAcls" => array(
+            "cn"              => _("Name"),
+            "description"     => _("Description"),
+            "FAIscript"       => _("Script entry"),
+            "FAIpriority"     => _("Script Priority"))
+          ));
+  }
+
+
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>