type = $type; $this->name = $name; $this->value = $value; $this->setCssClass('input'); if ($type == 'textarea') { $this->setStyle(array('width' => '100%', 'height' => '50px')); } } /** * Makes a new instance of the object in a static fashion * * @return object */ public static function make() { $obj = new ReflectionClass(__CLASS__); $args = func_get_args(); return $obj->newInstanceArgs($args); } // ################################################################### /** * If the type is either checkbox, radio, or option then this will * set the selected/checked attribute * * @param boolean Active? */ public function setActive($active) { if (!in_array($this->type, array('checkbox', 'radio', 'option'))) { throw new Exception('BSPrinterBaseElement::setActive() can only be used on elements of type checkbox, radio, or option'); } $this->active = $active; } // ################################################################### /** * Sets the JavaScript onclick action * * @param string onClick attribute value */ public function setOnClick($onClick) { $this->onClick = $onClick; } // ################################################################### /** * Sets the accesskey attribute value * * @param string Access key */ public function setAccessKey($accessKey) { $this->accessKey = $accessKey; } // ################################################################### /** * Returns the type * * @return string Element type */ public function getType() { return $this->type; } // ################################################################### /** * Returns the name of the element * * @return string Name */ public function getName() { return $this->name; } // ################################################################### /** * Sets the name of the element * * @param string A new name */ public function setName($name) { $this->name = $name; } // ################################################################### /** * Returns the output HTML * * @return string Output HTML */ public function paint() { $name = ' name="' . $this->name . '"'; $value = ' value="' . $this->value . '"'; $onclick = ($this->onClick ? ' onclick="' . $this->onClick . '"' : ''); $accesskey = ($this->accessKey ? ' accesskey="' . $this->accessKey . '"' : ''); $attrs = $name . $value . $onclick . $accesskey; switch ($this->type) { case 'text': case 'password': case 'button': case 'submit': case 'reset': return 'type == 'text' || $this->type == 'password') ? ' size="35" maxlength="255"' : ''). $this->_prepareStyle() . ' />'; break; case 'hidden': return ''; break; case 'checkbox': case 'radio': return 'active ? ' checked="checked"' : '') . $this->_prepareStyle() . ' />'; break; case 'upload': return '_prepareStyle() . ' />'; break; case 'option': return 'active ? ' selected="selected"' : '') . $this->_prepareStyle() . '>' . $this->name . ''; break; case 'select': return '_prepareStyle() . $accesskey . '>' . $this->value . ''; break; case 'textarea': if (!isset($this->style['height']) || !isset($this->style['width'])) { throw new Exception('BSPrinterBaseElement of type "textarea" require a "height" and "width" style attribute'); } return '_prepareStyle() . $accesskey . '>' . $this->value . ''; break; default: throw new Exception('Invalid PrinterBaseElement type "' . $this->type . '"'); break; } } } ?>