[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;
18 protected $readable = TRUE;
19 protected $writeable = TRUE;
21 /*! \brief Constructs the template widget and sets the default values.
22 * @param Config The GOsa configuration object.
23 * @param String A name for the widget.
24 * @param String The initial value.
25 * @param String A description.
26 * @param String True/False Must-Value/Optional-Value.
27 * @param String The widget type.
28 * @param String A display name for the widget.
29 */
30 function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display, $values=array())
31 {
32 $this->config = &$config;
33 $this->name = $name;
34 $this->value = $value;
35 $this->description = $description;
36 $this->required = $required;
37 $this->type = $type;
38 $this->syntax = $syntax;
39 $this->values = $values;
40 $this->display = $display;
41 $class = get_class();
42 $this->postName = "{$class}_{$this->name}";
43 }
46 /*! \brief Enabled or disabled the widget.
47 */
48 function setEnabled($bool = TRUE)
49 {
50 $this->enabled = $bool;
51 }
54 /*! \brief Sets the writeable status for a widget
55 */
56 function setWriteable($bool = TRUE)
57 {
58 $this->writeable = $bool;
59 }
62 /*! \brief Sets the readable status for a widget
63 */
64 function setReadable($bool = TRUE)
65 {
66 $this->readable = $bool;
67 }
70 /*! \brief Returns the enable status.
71 */
72 function isEnabled()
73 {
74 return($this->enabled);
75 }
78 /*! \brief Returns the writeable status.
79 */
80 function isWriteable()
81 {
82 return($this->writeable);
83 }
86 /*! \brief Returns the readable status.
87 */
88 function isReadable()
89 {
90 return($this->readable);
91 }
94 /*! \brief Returns the display-name for the current widget.
95 * @return String The display-name for the widget, this
96 * name will usually be rendered infront of input fields.
97 */
98 function getDisplayName()
99 {
100 $must = ($this->required)?"<span class='required'>*</span>":"";
101 return($this->display.$must);
102 }
105 /*! \brief Returns the description for the widget.
106 */
107 function getDescription()
108 {
109 return($this->description);
110 }
113 /*! \brief Generates the HTML code for the widget.
114 * @return The HTML content for the widget.
115 */
116 function render()
117 {
118 return("");
119 }
122 /*! \brief Keep track of posted values.
123 */
124 function save_object()
125 {
126 if(isset($_POST[$this->postName])){
127 $this->value = get_post($this->postName);
128 }
129 }
132 /*! \brief Returns the current value.
133 * @return Mixed The widgets value.
134 */
135 function getValue()
136 {
137 return($this->value);
138 }
141 /*! \brief Returns the name of the widget.
142 * @param String The widgets name.
143 */
144 function getName()
145 {
146 return($this->name);
147 }
150 /*! \brief Sets a new value for the widget.
151 * @param String The new value.
152 */
153 function setValue($value)
154 {
155 $this->value = $value;
156 }
159 /*! \brief Check the value entry using the provieded syntax.
160 * @return Array Returns a list of errors
161 */
162 function check()
163 {
164 if($this->required && empty($this->value)){
165 return(array(msgPool::required($this->display)));
166 }
167 if(!empty($this->value) &&
168 !empty($this->syntax) &&
169 !empty($this->syntax) && !preg_match($this->syntax, $this->value)){
170 return(array(msgPool::invalid($this->display, $this->value, $this->syntax)));
171 }
172 return(array());
173 }
174 }
175 ?>