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 $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('<font size="-2">'.$form->getRequiredNote().'</font>'),
149 array('colspan' => 2, '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)
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
275 * Actualiza atributos de la tabla interna.
277 * @param mixed $attrs Html attributes
280 * @deprecated Usar $renderer->tabla->updateAttributes().
282 function updateAttributes($attrs) {
283 $this->tabla->updateAttributes($attrs);
288 * @param mixed $attrs Html attributes
291 * @deprecated Usar $renderer->tabla->setAttributes().
293 function setAttributes($attrs) {
294 $this->tabla->setAttributes($attrs);
301 * @deprecated Usar $renderer->tabla->getAttributes().
303 function getAttributes() {
304 return $this->tabla->getAttributes();
308 * Setea la tabla que utilizará el renderer.
310 * @param Tabla $param Objeto tabla alternativo para utilizar
314 * @deprecated Usar $renderer->tabla.
316 function setTable(&$param) {
317 $this->tabla =& $param;
321 return $this->tabla->getCSS();
324 } // end class HTML_QuickForm_Renderer_Default