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_Servicios 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_Servicios($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')
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' => 'left',
169 'class' => 'titulo_form')
171 } // end func renderHeader
174 * Renders an element Html
175 * Called when visiting an element
177 * @param object An HTML_QuickForm_element object being visited
178 * @param bool Whether an element is required
179 * @param string An error message associated with an element
183 function renderElement(&$element, $required, $error)
185 if (!$this->_inGroup) {
186 $id = $this->_tabla->addRow(
188 $element->getLabel() . ($required ? '<FONT color="red">*</FONT>' : ''),
189 $element->toHtml() . ($error ? "<BR><FONT color=\"red\">$error</FONT>" : ''),
192 $this->_tabla->updateCellAttributes($id, 0, array('align' => 'left',
194 $this->_tabla->updateCellAttributes($id, 1, array('align' => 'center',
197 $this->_groupElements[] = ($element->getLabel() ? ($element->getLabel().' ') : '') . $element->toHtml();
199 } // end func renderElement
202 * Renders an hidden element
203 * Called when visiting a hidden element
205 * @param object An HTML_QuickForm_hidden object being visited
209 function renderHidden(&$element)
211 $this->_prepend .= "\n\t". $element->toHtml();
212 } // end func renderHidden
215 * Called when visiting a raw HTML/text pseudo-element
217 * @param object An HTML_QuickForm_html element being visited
221 function renderHtml(&$data)
223 $this->_tabla->addRow(
224 array($header->toHtml()),
225 array('colspan' => 2)
227 } // end func renderHtml
230 * Called when visiting a group, before processing any group elements
232 * @param object An HTML_QuickForm_group object being visited
233 * @param bool Whether a group is required
234 * @param string An error message associated with a group
238 function startGroup(&$group, $required, $error)
240 $this->_groupElements = array();
241 $this->_groupError = $error;
242 $this->_inGroup = true;
243 } // end func startGroup
246 * Called when visiting a group, after processing all group elements
248 * @param object An HTML_QuickForm_group object being visited
252 function finishGroup(&$group)
254 $name = $group->getName();
255 $sep = $group->_separator;
256 if (strtolower($name) == 'botones') {
257 $id = $this->_tabla->addRow(
258 array(join('', $this->_groupElements))
260 $this->_tabla->updateCellAttributes($id, 0, array('valign' => 'middle', 'align' => 'center', 'colspan' => 2));
262 $id = $this->_tabla->addRow(
263 array($group->getLabel(), join($sep, $this->_groupElements)),
264 array('valign' => 'middle', 'align' => 'left')
266 $this->_tabla->updateCellAttributes($id, 0, array('comun' => true,
267 'align' => 'left', 'class' => 'txt1'));
268 $this->_tabla->updateCellAttributes($id, 1, array('comun' => true,
269 'align' => 'center', 'class' => 'txt1'));
271 $this->_inGroup = false;
272 } // end func finishGroup
274 } // end class HTML_QuickForm_Renderer_Default