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 = "";
18 /*! \brief Constructs the template widget and sets the default values.
19 * @param Config The GOsa configuration object.
20 * @param String A name for the widget.
21 * @param String The initial value.
22 * @param String A description.
23 * @param String True/False Must-Value/Optional-Value.
24 * @param String The widget type.
25 * @param String A display name for the widget.
26 */
27 function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display, $values=array())
28 {
29 $this->config = &$config;
30 $this->name = $name;
31 $this->value = $value;
32 $this->description = $description;
33 $this->required = $required;
34 $this->type = $type;
35 $this->syntax = $syntax;
36 $this->values = $values;
37 $this->display = $display;
38 $class = get_class();
39 $this->postName = "{$class}_{$this->name}";
40 }
43 /*! \brief Returns the display-name for the current widget.
44 * @return String The display-name for the widget, this
45 * name will usually be rendered infront of input fields.
46 */
47 function getDisplayName()
48 {
49 $must = ($this->required)?"<span class='required'>*</span>":"";
50 return($this->display.$must);
51 }
54 /*! \brief Returns the description for the widget.
55 */
56 function getDescription()
57 {
58 return($this->description);
59 }
62 /*! \brief Generates the HTML code for the widget.
63 * @return The HTML content for the widget.
64 */
65 function render()
66 {
67 return("");
68 }
71 /*! \brief Keep track of posted values.
72 */
73 function save_object()
74 {
75 if(isset($_POST[$this->postName])){
76 $this->value = get_post($this->postName);
77 }
78 }
81 /*! \brief Returns the current value.
82 * @return Mixed The widgets value.
83 */
84 function getValue()
85 {
86 return($this->value);
87 }
90 /*! \brief Returns the name of the widget.
91 * @param String The widgets name.
92 */
93 function getName()
94 {
95 return($this->name);
96 }
99 /*! \brief Sets a new value for the widget.
100 * @param String The new value.
101 */
102 function setValue($value)
103 {
104 $this->value = $value;
105 }
108 /*! \brief Check the value entry using the provieded syntax.
109 * @return Array Returns a list of errors
110 */
111 function check()
112 {
113 if($this->required && empty($this->value)){
114 return(array(msgPool::required($this->display)));
115 }
116 if(!empty($this->value) && !empty($this->syntax) && !preg_match("/".$this->syntax."/", $this->value)){
117 return(array(msgPool::invalid($this->display, $this->value, "/".$this->syntax."/")));
118 }
119 return(array());
120 }
121 }
122 ?>