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 $style Estilo de la tabla.
95 function MECON_HTML_QuickForm_Renderer_Tabla($style = array())
97 $this->HTML_QuickForm_Renderer();
98 $this->_tabla =& new Tabla($style);
102 * returns the HTML generated for the form
109 return $this->_script . $this->_prepend .
110 $this->_tabla->toHtml() .
115 * Called when visiting a form, before processing any form elements
117 * @param object An HTML_QuickForm object being visited
121 function startForm(&$form)
123 # FIXME - deberia sacarlo del QuickForm
124 #$this->_prepend = $form->getFormStart();
125 $attrs = $form->getAttributesString();
126 $this->_prepend = "\n<FORM$attrs>\n";
127 } // end func startForm
130 * Called when visiting a form, after processing all form elements
131 * Adds required note, form attributes, validation javascript and form content.
133 * @param object An HTML_QuickForm object being visited
137 function finishForm(&$form)
139 // add a required note, if one is needed
140 if (!empty($form->_required) && !$form->_freezeAll) {
141 $id = $this->_tabla->addRow(
142 array($form->getRequiredNote()),
143 array('colspan' => 2, 'align' => 'center', 'cabecera' => true)
145 //$this->_tabla->updateCellAttributes($id, array('colspan' => 2));
147 // add form attributes and content
148 //$this->_html = str_replace('{content}', $this->_html, $html);
149 // add a validation script
150 $this->_script = strval($form->getValidationScript());
151 # FIXME - deberia sacarlo del QuickForm
152 #$this->_append = $form->getFormEnd();
153 $this->_append = "\n</FORM>\n";
154 } // end func finishForm
157 * Called when visiting a header element
159 * @param object An HTML_QuickForm_header element being visited
163 function renderHeader(&$header)
165 $name = $header->getName();
166 $this->_tabla->addRow(
167 array($header->toHtml()),
168 array('colspan' => 2, $name => true, 'align' => 'center')
170 } // end func renderHeader
173 * Renders an element Html
174 * Called when visiting an element
176 * @param object An HTML_QuickForm_element object being visited
177 * @param bool Whether an element is required
178 * @param string An error message associated with an element
182 function renderElement(&$element, $required, $error)
184 if (!$this->_inGroup) {
185 $id = $this->_tabla->addRow(
187 $element->getLabel() . ($required ? '<FONT color="red">*</FONT>' : ''),
188 $element->toHtml() . ($error ? "<BR><FONT color=\"red\">$error</FONT>" : ''),
191 $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left'));
192 $this->_tabla->updateCellAttributes($id, 1, array('align' => 'left'));
194 $this->_groupElements[] = ($element->getLabel() ? ($element->getLabel().' ') : '') . $element->toHtml();
196 } // end func renderElement
199 * Renders an hidden element
200 * Called when visiting a hidden element
202 * @param object An HTML_QuickForm_hidden object being visited
206 function renderHidden(&$element)
208 $this->_prepend .= "\n\t". $element->toHtml();
209 } // end func renderHidden
212 * Called when visiting a raw HTML/text pseudo-element
214 * @param object An HTML_QuickForm_html element being visited
218 function renderHtml(&$data)
220 $this->_tabla->addRow(
221 array($header->toHtml()),
222 array('colspan' => 2)
224 } // end func renderHtml
227 * Called when visiting a group, before processing any group elements
229 * @param object An HTML_QuickForm_group object being visited
230 * @param bool Whether a group is required
231 * @param string An error message associated with a group
235 function startGroup(&$group, $required, $error)
237 $this->_groupElements = array();
238 $this->_groupError = $error;
239 $this->_inGroup = true;
240 } // end func startGroup
243 * Called when visiting a group, after processing all group elements
245 * @param object An HTML_QuickForm_group object being visited
249 function finishGroup(&$group)
251 $name = $group->getName();
252 $sep = $group->_separator;
253 if (strtolower($name) == 'botones') {
254 $id = $this->_tabla->addRow(
255 array(join('', $this->_groupElements))
257 $this->_tabla->updateCellAttributes($id, 0, array('valign' => 'middle', 'align' => 'center', 'colspan' => 2));
259 $id = $this->_tabla->addRow(
260 array($group->getLabel(), join($sep, $this->_groupElements)),
261 array('valign' => 'middle', 'align' => 'left')
263 $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left'));
265 $this->_inGroup = false;
266 } // end func finishGroup
268 } // end class HTML_QuickForm_Renderer_Default