Code

b5e48a5a6c1b6e99c97e0c54b018496ac1f5e488
[gosa.git] / gosa-plugins / goto-ng / admin / newConfigManagement / TemplateEngine / class_TemplateWidget.inc
1 <?php
3 /*! \brief  The base class for all template-widgets used by the 
4  *           device-configuration class.
5  */
6 class TemplateWidget
7 {
8     protected $name = "unnamed";
9     protected $value = "";
11     protected $description = "";
12     protected $required = "";
13     protected $type = "";
14     protected $display = "";
15     protected $syntax = "";
16     protected $values = "";
17     protected $enabled = TRUE;
19     /*! \brief  Constructs the template widget and sets the default values.
20      *  @param  Config  The GOsa configuration object.
21      *  @param  String  A name for the widget.
22      *  @param  String  The initial value.
23      *  @param  String  A description.
24      *  @param  String  True/False  Must-Value/Optional-Value.
25      *  @param  String  The widget type. 
26      *  @param  String  A display name for the widget.
27      */
28     function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display, $values=array())
29     {
30         $this->config = &$config;
31         $this->name = $name;
32         $this->value = $value;
33         $this->description = $description;
34         $this->required = $required;
35         $this->type = $type;
36         $this->syntax = $syntax;
37         $this->values = $values;
38         $this->display = $display;
39         $class = get_class();
40         $this->postName = "{$class}_{$this->name}";
41     }
44     /*! \brief  Enabled or disabled the widget.
45      */    
46     function setEnabled($bool = TRUE)
47     {
48         $this->enabled = $bool;
49     }
51     
52     /*! \brief  Returns the enable status.
53      */
54     function isEnabled()
55     {
56         return($this->enabled);
57     }
60     /*! \brief  Returns the display-name for the current widget.
61      *  @return  String     The display-name for the widget, this 
62      *                       name will usually be rendered infront of input fields.
63      */
64     function getDisplayName()
65     {
66         $must = ($this->required)?"<span class='required'>*</span>":"";
67         return($this->display.$must);
68     }
71     /*! \brief  Returns the description for the widget.
72      */
73     function getDescription()
74     {
75         return($this->description);
76     }
79     /*! \brief  Generates the HTML code for the widget.
80      *  @return  The HTML content for the widget.
81      */
82     function render()
83     {
84         return("");
85     }
88     /*! \brief  Keep track of posted values.
89      */
90     function save_object()
91     {
92         if(isset($_POST[$this->postName])){
93             $this->value = get_post($this->postName);
94         }
95     }
98     /*! \brief  Returns the current value.
99      *  @return  Mixed  The widgets value.
100      */
101     function getValue()
102     {
103         return($this->value);
104     }
107     /*! \brief  Returns the name of the widget.
108      *  @param  String  The widgets name.
109      */
110     function getName()
111     {
112         return($this->name);
113     }
116     /*! \brief  Sets a new value for the widget.
117      *  @param  String  The new value.
118      */
119     function setValue($value)
120     {
121         $this->value = $value;
122     }
125     /*! \brief  Check the value entry using the provieded syntax.
126      * @return  Array   Returns a list of errors
127      */
128     function check()
129     {
130         if($this->required && empty($this->value)){
131             return(array(msgPool::required($this->display)));
132         }
133         if(!empty($this->value) && 
134             !empty($this->syntax) &&
135             !empty($this->syntax) && !preg_match($this->syntax, $this->value)){
136             return(array(msgPool::invalid($this->display, $this->value, $this->syntax)));
137         }
138         return(array());
139     }
141 ?>