Added BSPrinterBaseElement::getType()
[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 * Constructor
71 */
72 function __construct($type, $name, $value = '')
73 {
74 $this->type = $type;
75 $this->name = $name;
76 $this->value = $value;
77 $this->setCssClass('input');
78 }
79
80 // ###################################################################
81 /**
82 * If the type is either checkbox, radio, or option then this will
83 * set the selected/checked attribute
84 *
85 * @param boolean Active?
86 */
87 public function setActive($active)
88 {
89 if (!in_array($this->type, array('checkbox', 'radio', 'option')))
90 {
91 trigger_error('PrinterBaseElement::setActive() can only be used on elements of type checkbox, radio, or option');
92 }
93 $this->active = $active;
94 }
95
96 // ###################################################################
97 /**
98 * Returns the type
99 *
100 * @return string Element type
101 */
102 public function getType()
103 {
104 return $this->type;
105 }
106
107 // ###################################################################
108 /**
109 * Returns the output HTML
110 *
111 * @return string Output HTML
112 */
113 public function paint()
114 {
115 $name = ' name="' . $this->name . '"';
116 $value = ' value="' . $this->value . '"';
117 switch ($this->type)
118 {
119 case 'text':
120 case 'password':
121 case 'button':
122 case 'submit':
123 case 'reset':
124 return '<input type="' . $this->type . '"' . $name . $value . (($this->type == 'text' OR $this->type == 'password') ? ' size="35" maxlength="255"' : ''). $this->_prepareStyle() . ' />';
125 break;
126
127 case 'hidden':
128 return '<input type="hidden"' . $name . $value . ' />';
129 break;
130
131 case 'checkbox':
132 case 'radio':
133 return '<input type="' . $this->type . '"' . $name . $value . ($this->active ? ' checked="checked"' : '') . $this->_prepareStyle() . ' />';
134 break;
135
136 case 'upload':
137 return '<input type="file" size="35"' . $name . $this->_prepareStyle() . ' />';
138 break;
139
140 case 'option':
141 return '<option' . $value . ($this->active ? ' selected="selected"' : '') . $this->_prepareStyle() . '>' . $this->name . '</option>';
142 break;
143
144 default:
145 trigger_error('Invalid PrinterBaseElement type "' . $this->type . '"');
146 break;
147 }
148 }
149 }
150
151 /*=====================================================================*
152 || ###################################################################
153 || # $HeadURL$
154 || # $Id$
155 || ###################################################################
156 \*=====================================================================*/
157 ?>