ISSO is no longer a product regularly released so we'll remove the issoversion tag...
[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 output HTML
99 *
100 * @return string Output HTML
101 */
102 public function paint()
103 {
104 $name = ' name="' . $this->name . '"';
105 $value = ' value="' . $this->value . '"';
106 switch ($this->type)
107 {
108 case 'text':
109 case 'password':
110 case 'button':
111 case 'submit':
112 case 'reset':
113 return '<input type="' . $this->type . '"' . $name . $value . (($this->type == 'text' OR $this->type == 'password') ? ' size="35" maxlength="255"' : ''). $this->_prepareStyle() . ' />';
114 break;
115
116 case 'hidden':
117 return '<input type="hidden"' . $name . $value . ' />';
118 break;
119
120 case 'checkbox':
121 case 'radio':
122 return '<input type="' . $this->type . '"' . $name . $value . ($this->active ? ' checked="checked"' : '') . $this->_prepareStyle() . ' />';
123 break;
124
125 case 'upload':
126 return '<input type="file" size="35"' . $name . $this->_prepareStyle() . ' />';
127 break;
128
129 case 'option':
130 return '<option' . $value . ($this->active ? ' selected="selected"' : '') . $this->_prepareStyle() . '>' . $this->name . '</option>';
131 break;
132
133 default:
134 trigger_error('Invalid PrinterBaseElement type "' . $this->type . '"');
135 break;
136 }
137 }
138 }
139
140 /*=====================================================================*
141 || ###################################################################
142 || # $HeadURL$
143 || # $Id$
144 || ###################################################################
145 \*=====================================================================*/
146 ?>