2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 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
. '/PrinterAbstract.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)2005 - 2008, Blue Static
42 class BSPrinterElement
extends BSPrinterAbstract
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'));
97 * Makes a new instance of the object in a static fashion
101 public static function make()
103 $obj = new ReflectionClass(__CLASS__
);
104 $args = func_get_args();
105 return $obj->newInstanceArgs($args);
108 // ###################################################################
110 * If the type is either checkbox, radio, or option then this will
111 * set the selected/checked attribute
113 * @param boolean Active?
115 * @return fluent interface
117 public function setActive($active)
119 if (!in_array($this->type
, array('checkbox', 'radio', 'option')))
121 throw new Exception('BSPrinterElement::setActive() can only be used on elements of type checkbox, radio, or option');
123 $this->active
= $active;
127 // ###################################################################
129 * Sets the JavaScript onclick action
131 * @param string onClick attribute value
133 * @return fluent interface
135 public function setOnClick($onClick)
137 $this->onClick
= $onClick;
141 // ###################################################################
143 * Sets the accesskey attribute value
145 * @param string Access key
147 * @return fluent interface
149 public function setAccessKey($accessKey)
151 $this->accessKey
= $accessKey;
155 // ###################################################################
159 * @return string Element type
161 public function getType()
166 // ###################################################################
168 * Returns the name of the element
170 * @return string Name
172 public function getName()
177 // ###################################################################
179 * Sets the name of the element
181 * @param string A new name
183 * @return fluent interface
185 public function setName($name)
191 // ###################################################################
193 * Returns the output HTML
195 * @return string Output HTML
197 public function paint()
199 $name = ' name="' . $this->name
. '"';
200 $value = ' value="' . $this->value
. '"';
201 $onclick = ($this->onClick ?
' onclick="' . $this->onClick
. '"' : '');
202 $accesskey = ($this->accessKey ?
' accesskey="' . $this->accessKey
. '"' : '');
204 $attrs = $name . $value . $onclick . $accesskey;
213 return '<input type="' . $this->type
. '"' . $attrs . (($this->type
== 'text' ||
$this->type
== 'password') ?
' size="35" maxlength="255"' : ''). $this->_prepareStyle() . ' />';
217 return '<input type="hidden"' . $name . $value . ' />';
222 return '<input type="' . $this->type
. '"' . $attrs . ($this->active ?
' checked="checked"' : '') . $this->_prepareStyle() . ' />';
226 return '<input type="file" size="35"' . $name . $this->_prepareStyle() . ' />';
230 return '<option' . $value . ($this->active ?
' selected="selected"' : '') . $this->_prepareStyle() . '>' . $this->name
. '</option>';
234 return '<select' . $name . $this->_prepareStyle() . $accesskey . '>' . $this->value
. '</select>';
238 if (!isset($this->style
['height']) ||
!isset($this->style
['width']))
240 throw new Exception('BSPrinterElement of type "textarea" require a "height" and "width" style attribute');
243 return '<textarea' . $name . ' cols="50" rows="2"' . $this->_prepareStyle() . $accesskey . '>' . $this->value
. '</textarea>';
247 throw new Exception('Invalid BSPrinterElement type "' . $this->type
. '"');