Code

Implement a debconf configuration overview (Trac #2025)
[gosa.git] / trunk / gosa-plugins / fai / admin / fai / class_NewDebconfConfiguration.inc
1 <?php
3 class NewDebconfConfiguration extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account     = TRUE;
7   var $attributes         = array();
8   var $objectclasses      = array("whatever");
10   var $objectClass        = false;
11   var $DebconfConfiguration = array();
12   var $packages = array();
13   var $variable_types = array(
14                             "boolean" => "boolean",
15                             "multiselect" => "multiselect",
16                             "password" => "password",
17                             "select" => "select",
18                             "string" => "string",
19                           );
20   var $parent;
22   function NewDebconfConfiguration (&$config, $dn, &$parent)
23   {
24     plugin::plugin ($config, $dn);
26     /* Get list of packages */
27     $this->packages = $parent->packages;
28     /* Add d-i as special exception */
29     $this->packages['d-i'] = 'd-i';
30     ksort($this->packages);
32     $this->parent = $parent;
33   }
35   function execute()
36   {
37     /* Call parent execute */
38     plugin::execute();
40     /* Fill templating stuff */
41     $smarty = get_smarty();
42     $display= "";
44     $ldap = $this->config->get_ldap_link();
45     /* Get package names */
47     /* Pre-Fill input fields (needed for save_object if input fields are missing) */
48     $variable = "";
49     $variable_type = "";
50     $content = "";
51     $package = "";
52     if (isset($this->DebconfConfiguration['Package'])) {
53       $package = $this->DebconfConfiguration['Package'];
54     }
55     if (isset($this->DebconfConfiguration['FAIvariable'])) {
56       $variable = $this->DebconfConfiguration['FAIvariable'];
57     }
58     if (isset($this->DebconfConfiguration['FAIvariableType'])) {
59       $variable_type = $this->DebconfConfiguration['FAIvariableType'];
60     }
62     if (isset($this->DebconfConfiguration['FAIvariableContent'])){
63       $content = $this->DebconfConfiguration['FAIvariableContent'];
64     }
65     $smarty->assign("package", $package);
66     $smarty->assign("variable", $variable);
67     $smarty->assign("variable_type", $variable_type);
68     $smarty->assign("content", $content);
69     
71     /* Assign packages and variable types */
72     $smarty->assign("variable_types", $this->variable_types);
73     $smarty->assign("packages", $this->packages);
75     /* Fetch template and display */
76     $display.= $smarty->fetch(get_template_path('NewDebconfConfiguration.tpl', TRUE));
77     return($display);
78   }
80   /* Get posts and set class name 
81    */ 
82   function save_object()
83   {
84     if (isset($_POST['save_AddDebconf'])) {
85       foreach (array("FAIvariableType", "FAIvariableContent", "FAIvariable", "Package") as $attr) 
86       {
87         if (isset($_POST[$attr])) {
88           $this->DebconfConfiguration[$attr] = get_post($attr);
89         }
90       }
92       /* Normalize boolean values */
93       if($this->DebconfConfiguration['FAIvariableType'] == 'boolean') {
94         $this->DebconfConfiguration['FAIvariableContent'] = $this->parent->normalize_bool($this->DebconfConfiguration['FAIvariableContent']);
95       }
96     }
97   }
99   /* Check given class name 
100    */
101   function check()
102   {
103     /* Call common method to give check the hook */
104     $message= plugin::check();
106     $package = $this->DebconfConfiguration['Package'];
107     if (!isset($this->DebconfConfiguration['FAIvariable']) || empty($this->DebconfConfiguration['FAIvariable'])) {
108       $message[] = msgPool::required("Variable");
109     }
111     if ($this->DebconfConfiguration['FAIvariableType'] == 'boolean') {
112       if (!empty($this->DebconfConfiguration['FAIvariableContent'])) {
113         $value = strtolower($this->DebconfConfiguration['FAIvariableContent']);
114       }
115       else {
116         $value = "";
117       }
118       if (!$this->parent->normalize_bool($value, TRUE)) {
119         $message[] = sprintf(_("The specified value '%s' for the variable type boolean is invalid.<br><i>Allowed values: true, false, 1, 0.</i>"), $this->DebconfConfiguration['FAIvariableContent']);
120       }
121         
122     }
123     
124     if (isset($this->DebconfConfiguration['FAIvariable'])){
125         $name = $this->DebconfConfiguration['FAIvariable'];
126         if (isset($this->parent->DebconfConfigurations[$package][$name])) {
127             $message[] = msgPool::duplicated('Variable');
128         }
130         if (isset($this->parent->DebconfDefaults[$package][$name])) {
131             $message[] = msgPool::duplicated('Variable');
132         }
133     }
136     return ($message);
137   }
140   /* Return the class name */
141   function save()
142   {
143     return($this->DebconfConfiguration);
144   }
148 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
149 ?>