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 MECON_HTML_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 $attrs = $form->getAttributes(true);
133 $this->_prepend = "\n<form$attrs>\n";
135 } // end func startForm
138 * Called when visiting a form, after processing all form elements
139 * Adds required note, form attributes, validation javascript and form content.
141 * @param object An HTML_QuickForm object being visited
145 function finishForm(&$form)
147 // add a required note, if one is needed
148 if (!empty($form->_required) && !$form->_freezeAll) {
149 $id = $this->tabla->addRow(
150 array('<font size="-2">'.$form->getRequiredNote().'</font>'),
151 array('colspan' => 2, 'cabecera' => true)
153 //$this->tabla->updateCellAttributes($id, array('colspan' => 2));
155 // add form attributes and content
156 //$this->_html = str_replace('{content}', $this->_html, $html);
157 // add a validation script
158 $this->_script = strval($form->getValidationScript());
159 # FIXME - deberia sacarlo del QuickForm
160 #$this->_append = $form->getFormEnd();
161 $this->_append = "\n</form>\n";
162 } // end func finishForm
165 * Called when visiting a header element
167 * @param object An HTML_QuickForm_header element being visited
171 function renderHeader(&$header)
173 $name = $header->getName();
174 $this->tabla->addRow(
175 array($header->toHtml()),
176 array('colspan' => 2, $name => true)
178 } // end func renderHeader
181 * Renders an element Html
182 * Called when visiting an element
184 * @param object An HTML_QuickForm_element object being visited
185 * @param bool Whether an element is required
186 * @param string An error message associated with an element
190 function renderElement(&$element, $required, $error)
192 if (!$this->_inGroup) {
193 $id = $this->tabla->addRow(
195 $element->getLabel() . ($required ? '<font color="red">*</FONT>' : ''),
196 $element->toHtml() . ($error ? "<br><font color=\"red\">$error</FONT>" : ''),
199 $this->tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left'));
200 $this->tabla->updateCellAttributes($id, 1, array('align' => 'left'));
202 $this->_groupElements[] = ($element->getLabel() ? ($element->getLabel().' ') : '') . $element->toHtml();
204 } // end func renderElement
207 * Renders an hidden element
208 * Called when visiting a hidden element
210 * @param object An HTML_QuickForm_hidden object being visited
214 function renderHidden(&$element)
216 $this->_prepend .= "\n\t". $element->toHtml();
217 } // end func renderHidden
220 * Called when visiting a raw HTML/text pseudo-element
222 * @param object An HTML_QuickForm_html element being visited
226 function renderHtml(&$data)
228 $this->tabla->addRow(
229 array($header->toHtml()),
230 array('colspan' => 2)
232 } // end func renderHtml
235 * Called when visiting a group, before processing any group elements
237 * @param object An HTML_QuickForm_group object being visited
238 * @param bool Whether a group is required
239 * @param string An error message associated with a group
243 function startGroup(&$group, $required, $error)
245 $this->_groupElements = array();
246 $this->_groupError = $error;
247 $this->_inGroup = true;
248 } // end func startGroup
251 * Called when visiting a group, after processing all group elements
253 * @param object An HTML_QuickForm_group object being visited
257 function finishGroup(&$group)
259 $name = $group->getName();
260 $sep = $group->_separator;
261 if (strtolower($name) == 'botones') {
262 $id = $this->tabla->addRow(
263 array(join('', $this->_groupElements))
265 $this->tabla->updateCellAttributes($id, 0, array('valign' => 'middle', 'align' => 'center', 'colspan' => 2));
267 $id = $this->tabla->addRow(
268 array($group->getLabel(), join($sep, $this->_groupElements)),
269 array('valign' => 'middle', 'align' => 'left')
271 $this->tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left'));
273 $this->_inGroup = false;
274 } // end func finishGroup
277 * Actualiza atributos de la tabla interna.
279 * @param mixed $attrs Html attributes
282 * @deprecated Usar $renderer->tabla->updateAttributes().
284 function updateAttributes($attrs) {
285 $this->tabla->updateAttributes($attrs);
290 * @param mixed $attrs Html attributes
293 * @deprecated Usar $renderer->tabla->setAttributes().
295 function setAttributes($attrs) {
296 $this->tabla->setAttributes($attrs);
303 * @deprecated Usar $renderer->tabla->getAttributes().
305 function getAttributes() {
306 return $this->tabla->getAttributes();
310 * Setea la tabla que utilizará el renderer.
312 * @param Tabla $param Objeto tabla alternativo para utilizar
316 * @deprecated Usar $renderer->tabla.
318 function setTable(&$param) {
319 $this->tabla =& $param;
323 return $this->tabla->getCSS();
326 } // end class HTML_QuickForm_Renderer_Default