2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
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 * Factory method that creates a checkbox row
137 * @param string Label
138 * @param string Element name
140 * @param boolean Checked?
142 * @return BSPrinterTableElement A proper table element
144 public static function RowCheckbox($label, $name, $value, $checked = false
)
146 $tr = new BSPrinterTableElement();
148 $tr->addChild(new BSPrinterLabelElement($label));
150 $elm = new BSPrinterBaseElement('checkbox', $name, $value);
151 $elm->setActive($checked);
158 // ###################################################################
160 * Returns the number of columns in this element
162 * @return integer Column count
164 public function numberOfColumns()
166 return sizeof($this->children
);
169 // ###################################################################
171 * Adds a child node to the element
173 * @param BSPrinterElement A child element
175 public function addChild(BSPrinterElement
$child)
177 $this->children
[] = $child;
180 // ###################################################################
182 * Sets the number of columns this row should have and pads the <td>
183 * elements accordingly
185 * @param integer Column count
187 public function setColumnNumber($cols)
189 if ($cols < $this->numberOfColumns())
191 trigger_error('You need to have at least ' . $this->numberOfColumns() . ' columns');
193 $this->colspan
= $cols;
196 // ###################################################################
198 * Returns the HTML for all printed children elements
200 * @return string Printed HTML
202 protected function _paintChildren()
206 $numCols = $this->numberOfColumns();
209 if ($this->colspan %
$numCols == 0)
211 $cols = $this->colspan
/ $numCols;
216 $cols = intval($this->colspan
/ $numCols);
221 foreach ($this->children
AS $child)
224 $colspan = (($i == $numCols AND !$even) ?
$cols +
1 : $cols);
225 $builder .= "\n\t\t<td" . ($colspan > 1 ?
' colspan="' . $colspan . '"' : '') . ">" . $child->paint() . "</td>";
231 // ###################################################################
233 * Paints the entire table row
235 * @return string Table row HTML
237 public function paint()
239 return "\t<tr" . $this->_prepareStyle() . ">" . $this->_paintChildren() . "\n\t</tr>";
243 /*=====================================================================*
244 || ###################################################################
247 || ###################################################################
248 \*=====================================================================*/