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