2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.0 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Authors: Alexey Borzov <borz_off@cs.msu.su> |
17 // | Adam Daniel <adaniel1@eesus.jnj.com> |
18 // | Bertrand Mansion <bmansion@mamasam.com> |
19 // +----------------------------------------------------------------------+
23 require_once 'HTML/QuickForm/Renderer.php';
24 require_once 'MECON/HTML/Tabla.php';
27 * A concrete renderer for HTML_QuickForm,
28 * based on QuickForm 2.x built-in one
32 class HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer {
35 * Tabla usada para dibujar el formulario.
42 * HTML con los scripts para poner antes del formulario (tipicamente
50 * HTML para agregar antes de la tabla (tipicamente un javascript).
57 * HTML para agregar despues de la tabla.
64 * True if we are inside a group
68 var $_inGroup = false;
71 * Group error related message.
75 var $_groupError = '';
78 * Array with HTML generated for group elements
82 var $_groupElements = array();
87 * @param mixed $style Estilo de la tabla.
91 function HTML_QuickForm_Renderer_Tabla($style = 'width="400"')
93 $this->HTML_QuickForm_Renderer();
94 $this->_tabla =& new Tabla($style);
98 * returns the HTML generated for the form
105 return $this->_script . $this->_prepend .
106 $this->_tabla->toHtml() .
111 * Called when visiting a form, before processing any form elements
113 * @param object An HTML_QuickForm object being visited
117 function startForm(&$form)
119 # FIXME - deberia sacarlo del QuickForm
120 #$this->_prepend = $form->getFormStart();
121 $attrs = $form->getAttributesString();
122 $this->_prepend = "\n<FORM$attrs>\n";
123 } // end func startForm
126 * Called when visiting a form, after processing all form elements
127 * Adds required note, form attributes, validation javascript and form content.
129 * @param object An HTML_QuickForm object being visited
133 function finishForm(&$form)
135 // add a required note, if one is needed
136 if (!empty($form->_required) && !$form->_freezeAll) {
137 $id = $this->_tabla->addRow(
138 array($form->getRequiredNote()),
139 array('colspan' => 2, 'align' => 'center', 'cabecera' => true)
141 //$this->_tabla->updateCellAttributes($id, array('colspan' => 2));
143 // add form attributes and content
144 //$this->_html = str_replace('{content}', $this->_html, $html);
145 // add a validation script
146 $this->_script = strval($form->getValidationScript());
147 # FIXME - deberia sacarlo del QuickForm
148 #$this->_append = $form->getFormEnd();
149 $this->_append = "\n</FORM>\n";
150 } // end func finishForm
153 * Called when visiting a header element
155 * @param object An HTML_QuickForm_header element being visited
159 function renderHeader(&$header)
161 $name = $header->getName();
162 $this->_tabla->addRow(
163 array($header->toHtml()),
164 array('colspan' => 2, $name => true, 'align' => 'center')
166 } // end func renderHeader
169 * Renders an element Html
170 * Called when visiting an element
172 * @param object An HTML_QuickForm_element object being visited
173 * @param bool Whether an element is required
174 * @param string An error message associated with an element
178 function renderElement(&$element, $required, $error)
180 if (!$this->_inGroup) {
181 $id = $this->_tabla->addRow(
183 $element->getLabel() . ($required ? '<FONT color="red">*</FONT>' : ''),
184 $element->toHtml() . ($error ? "<BR><FONT color=\"red\">$error</FONT>" : ''),
187 $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left', 'nowrap' => true));
188 $this->_tabla->updateCellAttributes($id, 1, array('align' => 'left'));
190 $this->_groupElements[] = ($element->getLabel() ? ($element->getLabel().' ') : '') . $element->toHtml();
192 } // end func renderElement
195 * Renders an hidden element
196 * Called when visiting a hidden element
198 * @param object An HTML_QuickForm_hidden object being visited
202 function renderHidden(&$element)
204 $this->_prepend .= "\n\t". $element->toHtml();
205 } // end func renderHidden
208 * Called when visiting a raw HTML/text pseudo-element
210 * @param object An HTML_QuickForm_html element being visited
214 function renderHtml(&$data)
216 $this->_tabla->addRow(
217 array($header->toHtml()),
218 array('colspan' => 2)
220 } // end func renderHtml
223 * Called when visiting a group, before processing any group elements
225 * @param object An HTML_QuickForm_group object being visited
226 * @param bool Whether a group is required
227 * @param string An error message associated with a group
231 function startGroup(&$group, $required, $error)
233 $this->_groupElements = array();
234 $this->_groupError = $error;
235 $this->_inGroup = true;
236 } // end func startGroup
239 * Called when visiting a group, after processing all group elements
241 * @param object An HTML_QuickForm_group object being visited
245 function finishGroup(&$group)
247 $name = $group->getName();
248 $sep = $group->_separator;
249 if (strtolower($name) == 'botones') {
250 $id = $this->_tabla->addRow(
251 array(join('', $this->_groupElements))
253 $this->_tabla->updateCellAttributes($id, 0, array('align' => 'right', 'colspan' => 2));
255 $id = $this->_tabla->addRow(
256 array($group->getLabel(), join($sep, $this->_groupElements)),
257 array('align' => 'left')
259 $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left', 'nowrap' => true));
261 } // end func finishGroup
263 } // end class HTML_QuickForm_Renderer_Default