]> src.bluestatic.org Git - isso.git/blob - PrinterBaseElement.php
Changing the registry part of BSRegister to be a new inner class called BSVariableReg...
[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 * The JavaScript onClick attribute
71 * @var string
72 */
73 private $onClick;
74
75 /**
76 * Accesskey attribute
77 * @var string
78 */
79 private $accessKey;
80
81 /**
82 * Constructor
83 */
84 function __construct($type, $name, $value = '')
85 {
86 $this->type = $type;
87 $this->name = $name;
88 $this->value = $value;
89 $this->setCssClass('input');
90
91 if ($type == 'textarea')
92 {
93 $this->setStyle(array('width' => '100%', 'height' => '50px'));
94 }
95 }
96
97 // ###################################################################
98 /**
99 * If the type is either checkbox, radio, or option then this will
100 * set the selected/checked attribute
101 *
102 * @param boolean Active?
103 */
104 public function setActive($active)
105 {
106 if (!in_array($this->type, array('checkbox', 'radio', 'option')))
107 {
108 throw new Exception('BSPrinterBaseElement::setActive() can only be used on elements of type checkbox, radio, or option');
109 }
110 $this->active = $active;
111 }
112
113 // ###################################################################
114 /**
115 * Sets the JavaScript onclick action
116 *
117 * @param string onClick attribute value
118 */
119 public function setOnClick($onClick)
120 {
121 $this->onClick = $onClick;
122 }
123
124 // ###################################################################
125 /**
126 * Sets the accesskey attribute value
127 *
128 * @param string Access key
129 */
130 public function setAccessKey($accessKey)
131 {
132 $this->accessKey = $accessKey;
133 }
134
135 // ###################################################################
136 /**
137 * Returns the type
138 *
139 * @return string Element type
140 */
141 public function getType()
142 {
143 return $this->type;
144 }
145
146 // ###################################################################
147 /**
148 * Returns the name of the element
149 *
150 * @return string Name
151 */
152 public function getName()
153 {
154 return $this->name;
155 }
156
157 // ###################################################################
158 /**
159 * Sets the name of the element
160 *
161 * @param string A new name
162 */
163 public function setName($name)
164 {
165 $this->name = $name;
166 }
167
168 // ###################################################################
169 /**
170 * Returns the output HTML
171 *
172 * @return string Output HTML
173 */
174 public function paint()
175 {
176 $name = ' name="' . $this->name . '"';
177 $value = ' value="' . $this->value . '"';
178 $onclick = ($this->onClick ? ' onclick="' . $this->onClick . '"' : '');
179 $accesskey = ($this->accessKey ? ' accesskey="' . $this->accessKey . '"' : '');
180
181 $attrs = $name . $value . $onclick . $accesskey;
182
183 switch ($this->type)
184 {
185 case 'text':
186 case 'password':
187 case 'button':
188 case 'submit':
189 case 'reset':
190 return '<input type="' . $this->type . '"' . $attrs . (($this->type == 'text' OR $this->type == 'password') ? ' size="35" maxlength="255"' : ''). $this->_prepareStyle() . ' />';
191 break;
192
193 case 'hidden':
194 return '<input type="hidden"' . $name . $value . ' />';
195 break;
196
197 case 'checkbox':
198 case 'radio':
199 return '<input type="' . $this->type . '"' . $attrs . ($this->active ? ' checked="checked"' : '') . $this->_prepareStyle() . ' />';
200 break;
201
202 case 'upload':
203 return '<input type="file" size="35"' . $name . $this->_prepareStyle() . ' />';
204 break;
205
206 case 'option':
207 return '<option' . $value . ($this->active ? ' selected="selected"' : '') . $this->_prepareStyle() . '>' . $this->name . '</option>';
208 break;
209
210 case 'select':
211 return '<select' . $name . $this->_prepareStyle() . $accesskey . '>' . $this->value . '</select>';
212 break;
213
214 case 'textarea':
215 if (!isset($this->style['height']) OR !isset($this->style['width']))
216 {
217 throw new Exception('BSPrinterBaseElement of type "textarea" require a "height" and "width" style attribute');
218 }
219
220 return '<textarea' . $name . ' cols="50" rows="2"' . $this->_prepareStyle() . $accesskey . '>' . $this->value . '</textarea>';
221 break;
222
223 default:
224 throw new Exception('Invalid PrinterBaseElement type "' . $this->type . '"');
225 break;
226 }
227 }
228 }
229
230 /*=====================================================================*
231 || ###################################################################
232 || # $HeadURL$
233 || # $Id$
234 || ###################################################################
235 \*=====================================================================*/
236 ?>