1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
2 -------------------------------------------------------------------------------
3 Ministerio de EconomÃa
5 -------------------------------------------------------------------------------
6 This file is part of meconlib.
8 meconlib is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option)
13 meconlib is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License; if not,
18 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 Boston, MA 02111-1307 USA
20 -------------------------------------------------------------------------------
21 Creado: mar mar 30 16:06:26 ART 2004
22 Autor: Leandro Lucarella <llucar@mecon.gov.ar>
23 -------------------------------------------------------------------------------
24 $Id: Tabla.php 462 2004-01-09 21:11:01Z www-data $
25 -----------------------------------------------------------------------------*/
27 require_once 'HTML/QuickForm/Renderer.php';
28 require_once 'MECON/HTML/Tabla.php';
31 * QuickForm renderer que usa Tabla como backend. Es similar a
32 * MECON_HTML_QuickForm_Renderer_Tabla pero dibuja la tabla horizontalmente.
35 * $form = new MECON_HTML_QuickForm();
36 * $form->renderer = new MECON_HTML_QuickForm_Renderer_TablaHorizontal(array('width' => 400));
37 * // Sigo creando el formulario normalmente...
40 class MECON_HTML_QuickForm_Renderer_TablaHorizontal extends HTML_QuickForm_Renderer {
43 * Tabla usada para dibujar el formulario.
50 * Estructura de la tabla en filas a usar para renderizar.
56 * Guarda posición de la fila donde comienzan los elementos.
59 var $_elementsPos = null;
62 * Guarda elementos del formulario.
65 var $_elements = array();
68 * HTML con los scripts para poner antes del formulario (tipicamente
76 * HTML para agregar antes de la tabla (tipicamente un javascript).
83 * HTML para agregar despues de la tabla.
90 * True if we are inside a group
94 var $_inGroup = false;
97 * Group error related message.
101 var $_groupError = '';
104 * Array with HTML generated for group elements
108 var $_groupElements = array();
113 * @param mixed $param Array o sting con el estilo de la tabla u objeto
114 * tabla alternativo para usar.
118 function MECON_HTML_QuickForm_Renderer_TablaHorizontal($param = array())
120 parent::HTML_QuickForm_Renderer();
121 if (is_a($param, 'Tabla')) {
122 $this->setTable($param);
125 $this->setTable(new MECON_HTML_Tabla($param));
130 * returns the HTML generated for the form
137 $pos = $this->_elementsPos;
138 $rows = count($this->_rows);
139 foreach ($this->_elements as $e) {
140 list($label, $elem, $req, $err) = $e;
142 for ($i = 0; $i < $pos; ++$i) {
145 $cols[] = $label . ($req ? '<font color="red">*</font>' : '');
146 $cols[] = $elem . ($err ? "<br><font color=\"red\">$err</font>" : '');
147 for ($i = $pos + 2; $i < $rows; ++$i) {
150 $id = $this->tabla->addCol($cols, array(array('align' => 'center')));
151 $this->tabla->updateCellAttributes($pos, $id, array('titulo' => true));
153 foreach ($this->_rows as $i => $row) {
154 if ($row) { // Si no son las filas de los elementos...
155 list($html, $attrs) = $row;
156 $attrs['colspan'] = count($this->_elements);
157 $this->tabla->updateRowAttributes($i, $attrs);
158 $this->tabla->setCellContents($i, 0, $html);
161 return $this->_script . $this->_prepend .
162 $this->tabla->toHtml() .
167 * Called when visiting a form, before processing any form elements
169 * @param object An HTML_QuickForm object being visited
173 function startForm(&$form)
175 $attrs = $form->getAttributes(true);
176 $this->_prepend = "\n<form$attrs>\n";
178 } // end func startForm
181 * Called when visiting a form, after processing all form elements
182 * Adds required note, form attributes, validation javascript and form content.
184 * @param object An HTML_QuickForm object being visited
188 function finishForm(&$form)
190 // add a required note, if one is needed
191 if (!empty($form->_required) && !$form->_freezeAll) {
192 $this->_rows[] = array('<font size="-2">'.$form->getRequiredNote().'</font>', array('cabecera' => true));
194 // add a validation script
195 $this->_script = strval($form->getValidationScript());
196 $this->_append = "\n</form>\n";
197 } // end func finishForm
200 * Called when visiting a header element
202 * @param object An HTML_QuickForm_header element being visited
206 function renderHeader(&$header)
208 $this->_rows[] = array($header->toHtml(),
209 array($header->getName() => true));
210 } // end func renderHeader
213 * Renders an element Html
214 * Called when visiting an element
216 * @param object An HTML_QuickForm_element object being visited
217 * @param bool Whether an element is required
218 * @param string An error message associated with an element
222 function renderElement(&$element, $required, $error)
224 if (!$this->_inGroup) {
225 $this->_checkInElements();
226 $this->_elements[] = array(
227 $element->getLabel() . ($required ? '<font color="red">*</font>' : ''),
228 $element->toHtml() . ($error ? "<br><font color=\"red\">$error</font>" : ''),
231 $this->_groupElements[] = ($element->getLabel() ? ($element->getLabel().' ') : '') . $element->toHtml();
233 } // end func renderElement
236 * Renders an hidden element
237 * Called when visiting a hidden element
239 * @param object An HTML_QuickForm_hidden object being visited
243 function renderHidden(&$element)
245 $this->_prepend .= "\n\t". $element->toHtml();
246 } // end func renderHidden
249 * Called when visiting a raw HTML/text pseudo-element
251 * @param object An HTML_QuickForm_html element being visited
255 function renderHtml(&$data)
257 $this->_rows[] = array(&$data, array());
258 } // end func renderHtml
261 * Called when visiting a group, before processing any group elements
263 * @param object An HTML_QuickForm_group object being visited
264 * @param bool Whether a group is required
265 * @param string An error message associated with a group
269 function startGroup(&$group, $required, $error)
271 $this->_groupElements = array();
272 $this->_groupError = $error;
273 $this->_inGroup = true;
274 } // end func startGroup
277 * Called when visiting a group, after processing all group elements
279 * @param object An HTML_QuickForm_group object being visited
283 function finishGroup(&$group)
285 $name = $group->getName();
286 $sep = $group->_separator;
287 if (strtolower($name) == 'botones') {
288 $this->_rows[] = array(join('', $this->_groupElements), array('valign' => 'middle', 'align' => 'center'));
290 $this->_checkInElements();
291 $this->_elements[] = array(array($group->getLabel(),
292 join($sep, $this->_groupElements)), false, false);
294 $this->_inGroup = false;
295 } // end func finishGroup
297 function _checkInElements() {
298 if (is_null($this->_elementsPos)) {
299 $this->_elementsPos = count($this->_rows);
300 $this->_rows[] = false;
301 $this->_rows[] = false;
305 function setTable(&$table) {
306 $this->tabla =& $table;
310 return $this->tabla->getCSS();
313 } // end class HTML_QuickForm_Renderer_Default