]>
src.bluestatic.org Git - isso.git/blob - PrinterBaseElement.php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-2007 Blue Static
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 2 of the License.
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
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 \*=====================================================================*/
23 * Base Printer Element (PrinterElement.php)
28 require_once('ISSO/PrinterElement.php');
31 * Base Printer Element
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.
38 * @copyright Copyright (c)2002 - 2007, Blue Static
42 class BSPrinterBaseElement
extends BSPrinterElement
45 * The name of the element
57 * The value of the element
63 * The checked/selected attribute (checkbox, radio, and option only)
69 * The JavaScript onClick attribute
83 function __construct($type, $name, $value = '')
87 $this->value
= $value;
88 $this->setCssClass('input');
90 if ($type == 'textarea')
92 $this->setStyle(array('width' => '100%', 'height' => '50px'));
96 // ###################################################################
98 * If the type is either checkbox, radio, or option then this will
99 * set the selected/checked attribute
101 * @param boolean Active?
103 public function setActive($active)
105 if (!in_array($this->type
, array('checkbox', 'radio', 'option')))
107 throw new Exception('BSPrinterBaseElement::setActive() can only be used on elements of type checkbox, radio, or option');
109 $this->active
= $active;
112 // ###################################################################
114 * Sets the JavaScript onclick action
116 * @param string onClick attribute value
118 public function setOnClick($onClick)
120 $this->onClick
= $onClick;
123 // ###################################################################
125 * Sets the accesskey attribute value
127 * @param string Access key
129 public function setAccessKey($accessKey)
131 $this->accessKey
= $accessKey;
134 // ###################################################################
138 * @return string Element type
140 public function getType()
145 // ###################################################################
147 * Returns the name of the element
149 * @return string Name
151 public function getName()
156 // ###################################################################
158 * Sets the name of the element
160 * @param string A new name
162 public function setName($name)
167 // ###################################################################
169 * Returns the output HTML
171 * @return string Output HTML
173 public function paint()
175 $name = ' name="' . $this->name
. '"';
176 $value = ' value="' . $this->value
. '"';
177 $onclick = ($this->onClick
? ' onclick="' . $this->onClick
. '"' : '');
178 $accesskey = ($this->accessKey
? ' accesskey="' . $this->accessKey
. '"' : '');
180 $attrs = $name . $value . $onclick . $accesskey;
189 return '<input type="' . $this->type
. '"' . $attrs . (($this->type
== 'text' OR $this->type
== 'password') ? ' size="35" maxlength="255"' : ''). $this->_prepareStyle() . ' />';
193 return '<input type="hidden"' . $name . $value . ' />';
198 return '<input type="' . $this->type
. '"' . $attrs . ($this->active
? ' checked="checked"' : '') . $this->_prepareStyle() . ' />';
202 return '<input type="file" size="35"' . $name . $this->_prepareStyle() . ' />';
206 return '<option' . $value . ($this->active
? ' selected="selected"' : '') . $this->_prepareStyle() . '>' . $this->name
. '</option>';
210 return '<select' . $name . $this->_prepareStyle() . $accesskey . '>' . $this->value
. '</select>';
214 if (!isset($this->style
['height']) OR !isset($this->style
['width']))
216 throw new Exception('BSPrinterBaseElement of type "textarea" require a "height" and "width" style attribute');
219 return '<textarea' . $name . ' cols="50" rows="2"' . $this->_prepareStyle() . $accesskey . '>' . $this->value
. '</textarea>';
223 throw new Exception('Invalid PrinterBaseElement type "' . $this->type
. '"');