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 * Prints a simple row of text and text
60 * @param string Label (left side)
61 * @param string Value (right side)
63 * @return BSPrinterTableElement Table row element
65 public static function RowLabel($label, $value)
67 $tr = new BSPrinterTableElement();
69 $tr->addChild(new BSPrinterLabelElement($label));
70 $tr->addChild(new BSPrinterLabelElement($value));
75 // ###################################################################
77 * Creates an input[text/password] field row
80 * @param string Field name
81 * @param mixed Default value
82 * @param bool A password field?
84 * @return BPrinterTableElement Table row element
86 public static function RowText($label, $name, $value = null
, $password = false
)
88 $tr = new BSPrinterTableElement();
90 $tr->addChild(new BSPrinterLabelElement($label));
91 $tr->addChild(new BSPrinterBaseElement(($password ?
'password' : 'text'), $name, $value));
96 // ###################################################################
98 * Creates a submit row
100 * @param array Child elements to add before the buttons
101 * @param string Save button text
102 * @param string Reset button text
104 * @return BSPrinterTableElement Table row element
106 public static function RowSubmit(Array $children = null
, $save = ':submit:', $reset = ':reset:')
109 if (sizeof($children) > 0)
111 foreach ($children AS $child)
113 $build .= "\n\t\t\t" . $child->paint();
117 $save = ($save == ':submit:' ?
_('Submit') : $save);
118 $reset = ($reset == ':reset:' ?
_('Reset') : $reset);
120 $elm = new BSPrinterBaseElement('submit', '__submit__', " $save ");
121 $build .= "\n\t\t\t" . $elm->paint();
123 $elm = new BSPrinterBaseElement('reset', '__reset__', " $reset ");
124 $build .= "\n\t\t\t" . $elm->paint() . "\n\t\t";
126 $tr = new BSPrinterTableElement();
127 $tr->addChild(new BSPrinterLabelElement($build));
128 $tr->setCssClass('tfoot');
133 // ###################################################################
135 * Constructs a <select> row from an array of BSPrinterBaseElement's
137 * @param string Label
139 * @param array Array of BSPrinterBaseElement[option]'s
141 * @return BSPrinterTableElement Table row
143 public static function RowList($label, $name, Array $options)
146 foreach ($options AS $option)
148 if ($option->getType() == 'option')
150 $build .= $option->paint();
154 trigger_error('Only BSPrinterBaseElement\'s of type "option" are allowed in BSPrinterTableElement::RowList()');
158 $tr = new BSPrinterTableElement();
160 $tr->addChild(new BSPrinterLabelElement($label));
161 $tr->addChild(new BSPrinterBaseElement('select', $name, $build));
166 // ###################################################################
168 * Constructs a row from an array of BSPrinterBaseElement's of checkboxes
170 * @param string Label
172 * @param array Array of BSPrinterBaseElement[checkbox]'s that follow array(box label => BSPrinterBaseElement)
174 * @return BSPrinterTableElement Table row
176 public static function RowCheckbox($label, $name, Array $boxes)
179 foreach ($boxes AS $boxLabel => $box)
181 if ($box->getType() == 'checkbox')
183 if ($box->getName() == null
)
185 $box->setName($name . '[]');
187 $build .= '<div>' . $box->paint() . ' ' . $boxLabel . '</div>';
191 trigger_error('Only BSPrinterBaseElement\'s of type "checkbox" are allowed in BSPrinterTableElement::RowCheckbox()');
195 $tr = new BSPrinterTableElement();
197 $tr->addChild(new BSPrinterLabelElement($label));
198 $tr->addChild(new BSPrinterLabelElement($build));
203 // ###################################################################
205 * Factory method to create an upload form element; requires that the
206 * form this is attached to have the upload flag set
208 * @param string Label for the element
209 * @param string Name of the <input>
211 * @return BSPrinterTableElement Upload form
213 public static function RowUpload($label, $name)
215 $tr = new BSPrinterTableElement();
217 $tr->addChild(new BSPrinterLabelElement($label));
218 $tr->addChild(new BSPrinterBaseElement('upload', $name));
223 // ###################################################################
225 * Creates a row with a radio select option for yes/no
227 * @param string Row label
228 * @param string Name of the radio buttons
229 * @param bool Yes is selected? (if false, No is selected)
231 * @return BSPrinterTableElement Yes-No row
233 public static function RowYesNo($label, $name, $yes)
235 $elm = new BSPrinterBaseElement('radio', $name, 1);
236 $elm->setActive($yes);
238 $build = $elm->paint() . ' ' . _('Yes') . ' ';
240 $elm = new BSPrinterBaseElement('radio', $name, 0);
241 $elm->setActive(!$yes);
243 $build .= $elm->paint() . ' ' . _('No');
245 $tr = new BSPrinterTableElement();
246 $tr->addChild(new BSPrinterLabelElement($label));
247 $tr->addChild(new BSPrinterLabelElement($build));
251 // ###################################################################
253 * Returns the number of columns in this element
255 * @return integer Column count
257 public function numberOfColumns()
259 return sizeof($this->children
);
262 // ###################################################################
264 * Adds a child node to the element
266 * @param BSPrinterElement A child element
268 public function addChild(BSPrinterElement
$child)
270 $this->children
[] = $child;
273 // ###################################################################
275 * Sets the number of columns this row should have and pads the <td>
276 * elements accordingly
278 * @param integer Column count
280 public function setColumnNumber($cols)
282 if ($cols < $this->numberOfColumns())
284 trigger_error('You need to have at least ' . $this->numberOfColumns() . ' columns');
286 $this->colspan
= $cols;
289 // ###################################################################
291 * Returns the HTML for all printed children elements
293 * @return string Printed HTML
295 protected function _paintChildren()
299 $numCols = $this->numberOfColumns();
302 if ($this->colspan %
$numCols == 0)
304 $cols = $this->colspan
/ $numCols;
309 $cols = intval($this->colspan
/ $numCols);
314 foreach ($this->children
AS $child)
317 $colspan = (($i == $numCols AND !$even) ?
$cols +
1 : $cols);
318 $builder .= "\n\t\t<td" . ($colspan > 1 ?
' colspan="' . $colspan . '"' : '') . ">" . $child->paint() . "</td>";
324 // ###################################################################
326 * Paints the entire table row
328 * @return string Table row HTML
330 public function paint()
332 return "\t<tr" . $this->_prepareStyle() . ">" . $this->_paintChildren() . "\n\t</tr>";
336 /*=====================================================================*
337 || ###################################################################
340 || ###################################################################
341 \*=====================================================================*/