Adding a bunch of new Printer stuff that I'm not sure works quite yet
[isso.git] / PrinterBaseElement.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
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 parent containing element
47 * @var BSPrinterElement
48 */
49 private $parent;
50
51 /**
52 * The name of the element
53 * @var string
54 */
55 private $name;
56
57 /**
58 * Type of element
59 * @var string
60 */
61 private $type;
62
63 /**
64 * The value of the element
65 * @var string
66 */
67 private $value;
68
69 /**
70 * The checked/selected attribute (checkbox, radio, and option only)
71 * @var boolean
72 */
73 private $active;
74
75 /**
76 * Constructor
77 */
78 function __construct(BSPrinterElement $parent, $type, $name, $value = '')
79 {
80 $this->setParent($parent);
81 $this->type = $type;
82 $this->name = $name;
83 $this->value = $value;
84 }
85
86 // ###################################################################
87 /**
88 * Sets the parent element
89 *
90 * @param BSPrinterElement The parent
91 */
92 public function setParent(BSPrinterElement $parent)
93 {
94 $this->parent = $parent;
95 $this->parent->addChild($this);
96 }
97
98 // ###################################################################
99 /**
100 * Returns the parent element
101 *
102 * @return BSPrinterElement The parent element
103 */
104 public function getParent()
105 {
106 return $this->parent;
107 }
108
109 // ###################################################################
110 /**
111 * If the type is either checkbox, radio, or option then this will
112 * set the selected/checked attribute
113 *
114 * @param boolean Active?
115 */
116 public function setActive($active)
117 {
118 if (!in_array($this->type, array('checkbox', 'radio', 'option')))
119 {
120 trigger_error('PrinterBaseElement::setActive() can only be used on elements of type checkbox, radio, or option');
121 }
122 $this->active = $active;
123 }
124
125 // ###################################################################
126 /**
127 * Returns the output HTML
128 *
129 * @return string Output HTML
130 */
131 public function paint()
132 {
133 $name = ' name="' . $this->name . '"';
134 $style = ($this->_prepareStyle() ? ' style="' . $this->_prepareStyle() . '"' : '');
135 $value = ($this->value ? ' value="' . $this->value . '"' : '');
136 switch ($this->type)
137 {
138 case 'text':
139 case 'password':
140 case 'button':
141 case 'submit':
142 case 'reset':
143 return '<input type="' . $this->type . '"' . $name . $value . $style . ' />';
144 break;
145
146 case 'checkbox':
147 case 'radio':
148 return '<input type="' . $this->type . '"' . $name . $value . ($this->active ? ' checked="checked"' : '') . $style . ' />';
149 break;
150
151 case 'option':
152 return '<option' . $value . ($this->active ? ' selected="selected"' : '') . $style . '>' . $this->name . '</option>';
153 break;
154
155 default:
156 trigger_error('Invalid PrinterBaseElement type "' . $this->type . '"');
157 break;
158 }
159 }
160 }
161
162 /*=====================================================================*
163 || ###################################################################
164 || # $HeadURL$
165 || # $Id$
166 || ###################################################################
167 \*=====================================================================*/
168 ?>