]>
src.bluestatic.org Git - isso.git/blob - PrinterTableElement.php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 * Printer Table Element (PrinterTableElement.php)
28 require_once('ISSO/PrinterRootElementTable.php');
29 require_once('ISSO/PrinterBaseElement.php');
32 * Printer Table Element
34 * This represents a table row that holds elements.
37 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
42 class BSPrinterTableElement
extends BSPrinterElement
45 * Array of child nodes
48 private $children = array();
51 * Number of columns to span
56 // ###################################################################
58 * Creates a table element; takes a variable number of arguments which
59 * are added as children in the order passed
61 * @param BSPrinterTableElement... Variable number (or no) children
63 public function __construct()
65 $childs = func_get_args();
66 if (is_array($childs))
68 $this->children
= $childs;
72 // ###################################################################
74 * Prints a simple row of text and text
76 * @param string Label (left side)
77 * @param string Value (right side)
79 * @return BSPrinterTableElement Table row element
81 public static function RowLabel($label, $value)
83 $tr = new BSPrinterTableElement();
85 $tr->addChild(new BSPrinterLabelElement($label));
86 $tr->addChild(new BSPrinterLabelElement($value));
91 // ###################################################################
93 * Creates an input[text/password] field row
96 * @param string Field name
97 * @param mixed Default value
98 * @param bool A password field?
100 * @return BPrinterTableElement Table row element
102 public static function RowText($label, $name, $value = null, $password = false)
104 $tr = new BSPrinterTableElement();
106 $tr->addChild(new BSPrinterLabelElement($label));
107 $tr->addChild(new BSPrinterBaseElement(($password ? 'password' : 'text'), $name, $value));
112 // ###################################################################
114 * Creates a submit row
116 * @param array Child elements to add before the buttons
117 * @param string Save button text
118 * @param string Reset button text
120 * @return BSPrinterTableElement Table row element
122 public static function RowSubmit(Array $children = null, $save = ':submit:', $reset = ':reset:')
125 if (sizeof($children) > 0)
127 foreach ($children AS $child)
129 $build .= "\n\t\t\t" . $child->paint();
133 $save = ($save == ':submit:' ? _('Submit') : $save);
134 $reset = ($reset == ':reset:' ? _('Reset') : $reset);
138 $elm = new BSPrinterBaseElement('submit', '__submit__', " $save ");
139 $elm->setAccessKey('s');
140 $build .= "\n\t\t\t" . $elm->paint();
143 if (!is_null($reset))
145 $elm = new BSPrinterBaseElement('reset', '__reset__', " $reset ");
146 $elm->setAccessKey('r');
147 $build .= "\n\t\t\t" . $elm->paint() . "\n\t\t";
150 $tr = new BSPrinterTableElement();
151 $tr->addChild(new BSPrinterLabelElement($build));
152 $tr->setCssClass('tfoot');
157 // ###################################################################
159 * Constructs a <select> row from an array of BSPrinterBaseElement's
161 * @param string Label
163 * @param array Array of BSPrinterBaseElement[option]'s
165 * @return BSPrinterTableElement Table row
167 public static function RowList($label, $name, Array $options)
170 foreach ($options AS $option)
172 if ($option->getType() == 'option')
174 $build .= $option->paint();
178 trigger_error('Only BSPrinterBaseElement\'s of type "option" are allowed in BSPrinterTableElement::RowList()');
182 $tr = new BSPrinterTableElement();
184 $tr->addChild(new BSPrinterLabelElement($label));
185 $tr->addChild(new BSPrinterBaseElement('select', $name, $build));
190 // ###################################################################
192 * Constructs a row from an array of BSPrinterBaseElement's of checkboxes
194 * @param string Label
196 * @param array Array of BSPrinterBaseElement[checkbox]'s that follow array(box label => BSPrinterBaseElement)
198 * @return BSPrinterTableElement Table row
200 public static function RowCheckbox($label, $name, Array $boxes)
203 foreach ($boxes AS $boxLabel => $box)
205 if ($box->getType() == 'checkbox')
207 if ($box->getName() == null)
209 $box->setName($name . '[]');
211 $build .= '<div>' . $box->paint() . ' ' . $boxLabel . '</div>';
215 trigger_error('Only BSPrinterBaseElement\'s of type "checkbox" are allowed in BSPrinterTableElement::RowCheckbox()');
219 $tr = new BSPrinterTableElement();
221 $tr->addChild(new BSPrinterLabelElement($label));
222 $tr->addChild(new BSPrinterLabelElement($build));
227 // ###################################################################
229 * Factory method to create an upload form element; requires that the
230 * form this is attached to have the upload flag set
232 * @param string Label for the element
233 * @param string Name of the <input>
235 * @return BSPrinterTableElement Upload form
237 public static function RowUpload($label, $name)
239 $tr = new BSPrinterTableElement();
241 $tr->addChild(new BSPrinterLabelElement($label));
242 $tr->addChild(new BSPrinterBaseElement('upload', $name));
247 // ###################################################################
249 * Creates a row with a radio select option for yes/no
251 * @param string Row label
252 * @param string Name of the radio buttons
253 * @param bool Yes is selected? (if false, No is selected)
255 * @return BSPrinterTableElement Yes-No row
257 public static function RowYesNo($label, $name, $yes)
259 $elm = new BSPrinterBaseElement('radio', $name, 1);
260 $elm->setActive($yes);
262 $build = $elm->paint() . ' ' . _('Yes') . ' ';
264 $elm = new BSPrinterBaseElement('radio', $name, 0);
265 $elm->setActive(!$yes);
267 $build .= $elm->paint() . ' ' . _('No');
269 $tr = new BSPrinterTableElement();
270 $tr->addChild(new BSPrinterLabelElement($label));
271 $tr->addChild(new BSPrinterLabelElement($build));
275 // ###################################################################
277 * Prints a row with a textarea
279 * @param string Label
280 * @param string Textarea name
281 * @param string Value to fill with
283 * @return BSPrinterTableElement Table row
285 public static function RowTextarea($label, $name, $value = null)
287 $tr = new BSPrinterTableElement();
289 $tr->addChild(new BSPrinterLabelElement($label));
290 $tr->addChild(new BSPrinterBaseElement('textarea', $name, $value));
295 // ###################################################################
297 * Returns the number of columns in this element
299 * @return integer Column count
301 public function numberOfColumns()
303 return sizeof($this->children
);
306 // ###################################################################
308 * Adds a child node to the element
310 * @param BSPrinterElement A child element
312 public function addChild(BSPrinterElement
$child)
314 $this->children
[] = $child;
317 // ###################################################################
319 * Sets the number of columns this row should have and pads the <td>
320 * elements accordingly
322 * @param integer Column count
324 public function setColumnNumber($cols)
326 if ($cols < $this->numberOfColumns())
328 trigger_error('You need to have at least ' . $this->numberOfColumns() . ' columns');
330 $this->colspan
= $cols;
333 // ###################################################################
335 * Returns the HTML for all printed children elements
337 * @return string Printed HTML
339 protected function _paintChildren()
343 $numCols = $this->numberOfColumns();
346 if ($this->colspan %
$numCols == 0)
348 $cols = $this->colspan
/ $numCols;
353 $cols = intval($this->colspan
/ $numCols);
358 foreach ($this->children
AS $child)
361 $colspan = (($i == $numCols AND !$even) ? $cols +
1 : $cols);
362 $builder .= "\n\t\t<td" . ($colspan > 1 ? ' colspan="' . $colspan . '"' : '') . ">" . $child->paint() . "</td>";
368 // ###################################################################
370 * Paints the entire table row
372 * @return string Table row HTML
374 public function paint()
376 return "\t<tr" . $this->_prepareStyle() . ">" . $this->_paintChildren() . "\n\t</tr>";
380 /*=====================================================================*
381 || ###################################################################
384 || ###################################################################
385 \*=====================================================================*/