Code

Fixed problem with not clickable buttons in fai package error msgs
[gosa.git] / plugins / admin / fai / class_faiHookEntry.inc
index 1ab8d6c1a9b2c95c45abfd4928badffd2f2da7ef..52b4e76b03076afe4ab00cb11d11248bdb63aafd 100644 (file)
@@ -15,13 +15,15 @@ class faiHookEntry extends plugin
   var $orig_cn              = "";
   var $tasks                = array("chboot", "configure", "debconf", "extrbase", "faiend", "finish",
                                     "install", "instsoft", "mirror", "mountdisks", "partition", "prepareapt",
-                                    "savelog", "softupdate", "sysinfo"," updatebase");
+                                    "savelog", "softupdate", "sysinfo","updatebase");
   var $dn            = "";
   var $cn            = "";
-  var $FAItask       = "";
+  var $FAItask       = "chboot";
   var $FAIscript     = "";
   var $description   = "";
   var $status        = "new";
+  var $parent        = NULL;
+  var $FAIstate      = "";
   
   function faiHookEntry ($config, $dn= NULL,$object=false)
   {
@@ -33,15 +35,33 @@ class faiHookEntry extends plugin
         $oname = $name;
         $this->$oname=$value;
       }
-    }else{
-      $this->status = "new";
-      $this->orig_cn       = false;
+
+      if(isset($this->attrs['FAIstate'][0])){
+        $this->FAIstate = $this->attrs['FAIstate'][0];
+      }
+
+    }elseif(is_array($object)){
+      if(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 = "";
@@ -57,19 +77,45 @@ class faiHookEntry extends plugin
         $this->FAIscript = $str;
       }
     }
-    $smarty->assign("tasks", $this->tasks);
+
+    /* Create download button*/
+    if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
+      $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
+          <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0 class='center'>
+        </a>");
+    }else{
+      $smarty->assign("DownMe","");  
+    }
+
+    $used_tasks = $this->parent->getUsedFAItask($this->cn);
+    $tasks = $this->tasks;
+    foreach($this->tasks as $id => $task){
+      if(in_array($task,$used_tasks)){
+        unset($tasks[$id]);
+      }
+    }
+    $smarty->assign("tasks", $tasks);
 
      /* 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,(stripslashes($this->$attrs)));
       }else{
         $smarty->assign($attrs,($this->$attrs));
       }
     }
 
+    $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);
+    }
+
     $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
     return($display);
   }
@@ -77,12 +123,14 @@ class faiHookEntry 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 = "";
+          }
         }
       }
     }
@@ -91,7 +139,13 @@ class faiHookEntry extends plugin
   /* Check supplied data */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
+
+    if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
+      $message[] =_("There is already a hook with the given name.");
+    }
+
     if(empty($this->FAIscript)) {
       $message[]=_("Please enter a value for script.");
     }
@@ -100,10 +154,6 @@ class faiHookEntry extends plugin
       $message[] = _("Please enter a name.");
     }
 
-    if(preg_match("/[^0-9a-z]/i",$this->cn)){
-      $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
-    }
-  
     return ($message);
   }
  
@@ -114,6 +164,9 @@ class faiHookEntry 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'];
@@ -123,6 +176,26 @@ class faiHookEntry extends plugin
     $tmp['status']  = $this->status;  
     return($tmp);
   }
+
+    /* Return plugin informations for acl handling */
+  function plInfo()
+  {
+    return (array(
+          "plShortName" => _("Hook entry"),
+          "plDescription" => _("FAI hook entry"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 21,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("fai"),
+          "plProvidedAcls" => array(
+            "cn"                => _("Name"),
+            "description"       => _("Description"),
+            "FAItask"           => _("Task"),
+            "FAIscript"         => _("FAI script"))
+          ));
+  }
+
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>