Code

d0e0df3c5784811acb347ea53e0e17e16f8db68e
[gosa.git] / trunk / gosa-plugins / fai / admin / fai / class_faiPackageConfiguration.inc
1 <?php
3 class faiPackageConfiguration extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account = TRUE;
7   var $attributes     = array();
8   var $objectclasses  = array();
10   var $Debconf_handle = NULL;
11   var $pkg_config ;
12   var $obj;
13   var $release;
16   /*! \brief  Configure a FAI package entry.
17       @param  Object  $config GOsa configuration object;
18       @param  String  The DN of the current package.
19       @param  String  The package name (e.g. apache)
20       @param  String  The release name (e.g. edge)
21       @param  Array   The current package configuration.
22    */
23   function faiPackageConfiguration (&$config, $dn= NULL,$obj,$release,$pkg_config)
24   {
25     plugin::plugin ($config, $dn);
26     $this->obj = $obj;
27     $this->release = $release;
28     $this->pkg_config = $pkg_config;
30     /* Read pkg debconf info from gosaSupportDaemon
31      */
32     $q = new gosaSupportDaemon();
33     $ret = $q->FAI_get_packages($this->release,array("package","template"),array($this->obj));
34     if($q->is_error()){
35       msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
36     }
38     /* If we do not get a useable answer, use an empty template 
39      */
40     $tpl = "";
41     if(isset($ret['ANSWER1']) && isset($ret['ANSWER1']['TEMPLATE'])){
42       $tpl = base64_decode($ret['ANSWER1']['TEMPLATE']);
43     }
45     /* Create package configuration mask
46      */
47     $this->Debconf_handle = new debconf(preg_replace('/_.*$/', '', get_browser_language()));
48     $this->Debconf_handle->load_from_string($tpl);
49     if($this->Debconf_handle->has_template()){
50       foreach($this->pkg_config as $var){
51         if (is_array($var['Value'])) {
52           $var['Value'] = "";
53         }
54         $this->Debconf_handle->SetDefault($var['Name'],$var['Value']);
55       }
56     }
57   }
60   /*! \brief  Returns a html interface, that allow to modify 
61                the package attributes.
62       @return String  HTML content/ui for this plugin
63    */
64   function execute()
65   {
66     /* Call parent execute */
67     plugin::execute();
69     /* Fill templating stuff */
70     $smarty     = get_smarty();
71     $smarty->assign("headline", sprintf(_("Debconf information for package '%s'"), $this->obj));
72     $this->Debconf_handle->PostCheck();
73     $smarty->assign("Config",$this->Debconf_handle->get_dialog());
74     return($smarty->fetch(get_template_path('faiPackageConfiguration.tpl', TRUE)));
75   }
78   /* Save data to object */
79   function save_object()
80   {
81   }
83   /* Check supplied data */
84   function check()
85   {
86     /* Call common method to give check the hook */
87     $message= plugin::check();
88     return ($message);
89   }
92   /*! \brief  Returns an array with all configured attributes 
93       @return Array   All configured attributes.
94    */
95   function save()
96   {
97     $this->Debconf_handle->PostCheck();
98     $pkgs = $this->Debconf_handle->template;
99     $tmp = array();
100     foreach($pkgs as $pkg){
101       $tmp[$this->obj][$pkg['Name']]['Value']= $pkg['Default'];
102       $tmp[$this->obj][$pkg['Name']]['Name'] = $pkg['Name'];
103       $tmp[$this->obj][$pkg['Name']]['Type'] = $pkg['Type'];
104     }
105     return($tmp);
106   }
108 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
109 ?>