- Added support for <select> where the value attribute is the built children <option...
[isso.git] / PrinterBaseElement.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Base Printer Element (PrinterElement.php)
24 *
25 * @package ISSO
26 */
27
28 require_once('ISSO/PrinterElement.php');
29
30 /**
31 * Base Printer Element
32 *
33 * This class represents the lowest level of printer elements:
34 * buttons, input fields, etc. These cannot have children elements
35 * and are only attached to a parent.
36 *
37 * @author Blue Static
38 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
39 * @version $Revision$
40 * @package ISSO
41 *
42 */
43 class BSPrinterBaseElement extends BSPrinterElement
44 {
45 /**
46 * The name of the element
47 * @var string
48 */
49 private $name;
50
51 /**
52 * Type of element
53 * @var string
54 */
55 private $type;
56
57 /**
58 * The value of the element
59 * @var string
60 */
61 private $value;
62
63 /**
64 * The checked/selected attribute (checkbox, radio, and option only)
65 * @var boolean
66 */
67 private $active;
68
69 /**
70 * Constructor
71 */
72 function __construct($type, $name, $value = '')
73 {
74 $this->type = $type;
75 $this->name = $name;
76 $this->value = $value;
77 $this->setCssClass('input');
78 }
79
80 // ###################################################################
81 /**
82 * If the type is either checkbox, radio, or option then this will
83 * set the selected/checked attribute
84 *
85 * @param boolean Active?
86 */
87 public function setActive($active)
88 {
89 if (!in_array($this->type, array('checkbox', 'radio', 'option')))
90 {
91 trigger_error('PrinterBaseElement::setActive() can only be used on elements of type checkbox, radio, or option');
92 }
93 $this->active = $active;
94 }
95
96 // ###################################################################
97 /**
98 * Returns the type
99 *
100 * @return string Element type
101 */
102 public function getType()
103 {
104 return $this->type;
105 }
106
107 // ###################################################################
108 /**
109 * Returns the name of the element
110 *
111 * @return string Name
112 */
113 public function getName()
114 {
115 return $this->name;
116 }
117
118 // ###################################################################
119 /**
120 * Sets the name of the element
121 *
122 * @param string A new name
123 */
124 public function setName($name)
125 {
126 $this->name = $name;
127 }
128
129 // ###################################################################
130 /**
131 * Returns the output HTML
132 *
133 * @return string Output HTML
134 */
135 public function paint()
136 {
137 $name = ' name="' . $this->name . '"';
138 $value = ' value="' . $this->value . '"';
139 switch ($this->type)
140 {
141 case 'text':
142 case 'password':
143 case 'button':
144 case 'submit':
145 case 'reset':
146 return '<input type="' . $this->type . '"' . $name . $value . (($this->type == 'text' OR $this->type == 'password') ? ' size="35" maxlength="255"' : ''). $this->_prepareStyle() . ' />';
147 break;
148
149 case 'hidden':
150 return '<input type="hidden"' . $name . $value . ' />';
151 break;
152
153 case 'checkbox':
154 case 'radio':
155 return '<input type="' . $this->type . '"' . $name . $value . ($this->active ? ' checked="checked"' : '') . $this->_prepareStyle() . ' />';
156 break;
157
158 case 'upload':
159 return '<input type="file" size="35"' . $name . $this->_prepareStyle() . ' />';
160 break;
161
162 case 'option':
163 return '<option' . $value . ($this->active ? ' selected="selected"' : '') . $this->_prepareStyle() . '>' . $this->name . '</option>';
164 break;
165
166 case 'select':
167 return '<select' . $name . $this->_prepareStyle() . '>' . $this->value . '</select>';
168
169 default:
170 trigger_error('Invalid PrinterBaseElement type "' . $this->type . '"');
171 break;
172 }
173 }
174 }
175
176 /*=====================================================================*
177 || ###################################################################
178 || # $HeadURL$
179 || # $Id$
180 || ###################################################################
181 \*=====================================================================*/
182 ?>