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: jue jul 17 15:36:26 ART 2003
22 Autor: Leandro Lucarella <llucar@mecon.gov.ar>
23 -------------------------------------------------------------------------------
25 -----------------------------------------------------------------------------*/
27 require_once 'HTML/QuickForm/Renderer.php';
28 require_once 'MECON/HTML/Tabla.php';
31 * QuickForm renderer que usa Tabla como backend.
32 * Basado en el QuickForm Renderer basico.
36 class MECON_HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer {
39 * Tabla usada para dibujar el formulario.
46 * HTML con los scripts para poner antes del formulario (tipicamente
54 * HTML para agregar antes de la tabla (tipicamente un javascript).
61 * HTML para agregar despues de la tabla.
68 * True if we are inside a group
72 var $_inGroup = false;
75 * Group error related message.
79 var $_groupError = '';
82 * Array with HTML generated for group elements
86 var $_groupElements = array();
91 * @param mixed $param Array o sting con el estilo de la tabla u objeto
92 * tabla alternativo para usar.
96 function MECON_HTML_QuickForm_Renderer_Tabla($param = array())
98 $this->HTML_QuickForm_Renderer();
99 if (is_a($param, 'Tabla')) {
100 $this->setTable($param);
103 $this->_tabla =& new Tabla($param);
108 * returns the HTML generated for the form
115 return $this->_script . $this->_prepend .
116 $this->_tabla->toHtml() .
121 * Called when visiting a form, before processing any form elements
123 * @param object An HTML_QuickForm object being visited
127 function startForm(&$form)
129 # FIXME - deberia sacarlo del QuickForm
130 #$this->_prepend = $form->getFormStart();
131 $attrs = $form->getAttributesString();
132 $this->_prepend = "\n<FORM$attrs>\n";
133 } // end func startForm
136 * Called when visiting a form, after processing all form elements
137 * Adds required note, form attributes, validation javascript and form content.
139 * @param object An HTML_QuickForm object being visited
143 function finishForm(&$form)
145 // add a required note, if one is needed
146 if (!empty($form->_required) && !$form->_freezeAll) {
147 $id = $this->_tabla->addRow(
148 array($form->getRequiredNote()),
149 array('colspan' => 2, 'align' => 'center', 'cabecera' => true)
151 //$this->_tabla->updateCellAttributes($id, array('colspan' => 2));
153 // add form attributes and content
154 //$this->_html = str_replace('{content}', $this->_html, $html);
155 // add a validation script
156 $this->_script = strval($form->getValidationScript());
157 # FIXME - deberia sacarlo del QuickForm
158 #$this->_append = $form->getFormEnd();
159 $this->_append = "\n</FORM>\n";
160 } // end func finishForm
163 * Called when visiting a header element
165 * @param object An HTML_QuickForm_header element being visited
169 function renderHeader(&$header)
171 $name = $header->getName();
172 $this->_tabla->addRow(
173 array($header->toHtml()),
174 array('colspan' => 2, $name => true, 'align' => 'center')
176 } // end func renderHeader
179 * Renders an element Html
180 * Called when visiting an element
182 * @param object An HTML_QuickForm_element object being visited
183 * @param bool Whether an element is required
184 * @param string An error message associated with an element
188 function renderElement(&$element, $required, $error)
190 if (!$this->_inGroup) {
191 $id = $this->_tabla->addRow(
193 $element->getLabel() . ($required ? '<FONT color="red">*</FONT>' : ''),
194 $element->toHtml() . ($error ? "<BR><FONT color=\"red\">$error</FONT>" : ''),
197 $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left'));
198 $this->_tabla->updateCellAttributes($id, 1, array('align' => 'left'));
200 $this->_groupElements[] = ($element->getLabel() ? ($element->getLabel().' ') : '') . $element->toHtml();
202 } // end func renderElement
205 * Renders an hidden element
206 * Called when visiting a hidden element
208 * @param object An HTML_QuickForm_hidden object being visited
212 function renderHidden(&$element)
214 $this->_prepend .= "\n\t". $element->toHtml();
215 } // end func renderHidden
218 * Called when visiting a raw HTML/text pseudo-element
220 * @param object An HTML_QuickForm_html element being visited
224 function renderHtml(&$data)
226 $this->_tabla->addRow(
227 array($header->toHtml()),
228 array('colspan' => 2)
230 } // end func renderHtml
233 * Called when visiting a group, before processing any group elements
235 * @param object An HTML_QuickForm_group object being visited
236 * @param bool Whether a group is required
237 * @param string An error message associated with a group
241 function startGroup(&$group, $required, $error)
243 $this->_groupElements = array();
244 $this->_groupError = $error;
245 $this->_inGroup = true;
246 } // end func startGroup
249 * Called when visiting a group, after processing all group elements
251 * @param object An HTML_QuickForm_group object being visited
255 function finishGroup(&$group)
257 $name = $group->getName();
258 $sep = $group->_separator;
259 if (strtolower($name) == 'botones') {
260 $id = $this->_tabla->addRow(
261 array(join('', $this->_groupElements))
263 $this->_tabla->updateCellAttributes($id, 0, array('valign' => 'middle', 'align' => 'center', 'colspan' => 2));
265 $id = $this->_tabla->addRow(
266 array($group->getLabel(), join($sep, $this->_groupElements)),
267 array('valign' => 'middle', 'align' => 'left')
269 $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left'));
271 $this->_inGroup = false;
272 } // end func finishGroup
277 * @param mixed $attrs Html attributes
281 function updateAttributes($attrs) {
282 $this->_tabla->updateAttributes($attrs);
287 * @param mixed $attrs Html attributes
291 function setAttributes($attrs) {
292 $this->_tabla->setAttributes($attrs);
300 function getAttributes() {
301 return $this->_tabla->getAttributes();
307 * @param Tabla $param Objeto tabla alternativo para utilizar
311 function setTable($param) {
312 $this->_tabla =& $param;
315 } // end class HTML_QuickForm_Renderer_Default