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