Code

Updated FAI template entry.
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiPackageConfiguration.inc
index 18f3e2b6c737c515bfe55c0a76ae975a3c525ee4..ab437c3bc3254caff06dc610194527eb1a9f1a74 100644 (file)
@@ -2,11 +2,6 @@
 
 class faiPackageConfiguration extends plugin
 {
-  /* CLI vars */
-  var $cli_summary        = "Manage server basic objects";
-  var $cli_description    = "Some longer text\nfor help";
-  var $cli_parameters     = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* attribute list for save action */
   var $ignore_account = TRUE;
   var $attributes     = array();
@@ -15,25 +10,54 @@ class faiPackageConfiguration extends plugin
   var $Debconf_handle = NULL;
   var $pkg_config ;
   var $obj;
+  var $release;
+
 
-  function faiPackageConfiguration (&$config, $dn= NULL,$obj,$path,$pkg_config)
+  /*! \brief  Configure a FAI package entry.
+      @param  Object  $config GOsa configuration object;
+      @param  String  The DN of the current package.
+      @param  String  The package name (e.g. apache)
+      @param  String  The release name (e.g. edge)
+      @param  Array   The current package configuration.
+   */
+  function faiPackageConfiguration (&$config, $dn= NULL,$obj,$release,$pkg_config)
   {
     plugin::plugin ($config, $dn);
     $this->obj = $obj;
-    $this->Debconf_handle = new debconf();
-    $this->Debconf_handle->set_template_directory($path);
-    $this->Debconf_handle->set_package($this->obj);
-    $this->Debconf_handle->set_language(preg_replace('/_.*$/', '', get_browser_language()));
+    $this->release = $release;
+    $this->pkg_config = $pkg_config;
+
+    /* Read pkg debconf info from gosaSupportDaemon
+     */
+    $q = new gosaSupportDaemon();
+    $ret = $q->FAI_get_packages($this->release,array("package","template"),array($this->obj));
+    if($q->is_error()){
+      msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
+    }
 
-    if( $this->Debconf_handle->load() ) {
-      $this->pkg_config = $pkg_config;
+    /* If we do not get a useable answer, use an empty template 
+     */
+    $tpl = "";
+    if(isset($ret['ANSWER1']) && isset($ret['ANSWER1']['TEMPLATE'])){
+      $tpl = base64_decode($ret['ANSWER1']['TEMPLATE']);
+    }
 
+    /* Create package configuration mask
+     */
+    $this->Debconf_handle = new debconf(preg_replace('/_.*$/', '', get_browser_language()));
+    $this->Debconf_handle->load_from_string($tpl);
+    if($this->Debconf_handle->has_template()){
       foreach($this->pkg_config as $var){
         $this->Debconf_handle->SetDefault($var['Name'],$var['Value']);
       }
     }
   }
 
+
+  /*! \brief  Returns a html interface, that allow to modify 
+               the package attributes.
+      @return String  HTML content/ui for this plugin
+   */
   function execute()
   {
     /* Call parent execute */
@@ -41,17 +65,13 @@ class faiPackageConfiguration extends plugin
 
     /* Fill templating stuff */
     $smarty     = get_smarty();
-    $display = "";
     $smarty->assign("headline", sprintf(_("Debconf information for package '%s'"), $this->obj));
-
     $this->Debconf_handle->PostCheck();
-
     $smarty->assign("Config",$this->Debconf_handle->get_dialog());
-
-    $display.= $smarty->fetch(get_template_path('faiPackageConfiguration.tpl', TRUE));
-    return($display);
+    return($smarty->fetch(get_template_path('faiPackageConfiguration.tpl', TRUE)));
   }
 
+
   /* Save data to object */
   function save_object()
   {
@@ -62,15 +82,17 @@ class faiPackageConfiguration extends plugin
   {
     /* Call common method to give check the hook */
     $message= plugin::check();
-
     return ($message);
   }
 
+
+  /*! \brief  Returns an array with all configured attributes 
+      @return Array   All configured attributes.
+   */
   function save()
   {
     $this->Debconf_handle->PostCheck();
     $pkgs = $this->Debconf_handle->template;
-
     $tmp = array();
     foreach($pkgs as $pkg){
       $tmp[$this->obj][$pkg['Name']]['Value']= $pkg['Default'];