2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
\r
3 // +----------------------------------------------------------------------+
\r
4 // | PHP version 4.0 |
\r
5 // +----------------------------------------------------------------------+
\r
6 // | Copyright (c) 1997-2003 The PHP Group |
\r
7 // +----------------------------------------------------------------------+
\r
8 // | This source file is subject to version 2.0 of the PHP license, |
\r
9 // | that is bundled with this package in the file LICENSE, and is |
\r
10 // | available at through the world-wide-web at |
\r
11 // | http://www.php.net/license/2_02.txt. |
\r
12 // | If you did not receive a copy of the PHP license and are unable to |
\r
13 // | obtain it through the world-wide-web, please send a note to |
\r
14 // | license@php.net so we can mail you a copy immediately. |
\r
15 // +----------------------------------------------------------------------+
\r
16 // | Authors: Alexey Borzov <borz_off@cs.msu.su> |
\r
17 // | Adam Daniel <adaniel1@eesus.jnj.com> |
\r
18 // | Bertrand Mansion <bmansion@mamasam.com> |
\r
19 // +----------------------------------------------------------------------+
\r
23 require_once 'HTML/QuickForm/Renderer.php';
\r
24 require_once 'HTML/Tabla.php';
\r
27 * A concrete renderer for HTML_QuickForm,
\r
28 * based on QuickForm 2.x built-in one
\r
32 class HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer {
\r
35 * Tabla usada para dibujar el formulario.
\r
42 * HTML con los scripts para poner antes del formulario (tipicamente
\r
50 * HTML para agregar antes de la tabla (tipicamente un javascript).
\r
57 * HTML para agregar despues de la tabla.
\r
64 * True if we are inside a group
\r
68 var $_inGroup = false;
\r
71 * Array with HTML generated for group elements
\r
75 var $_groupElements = array();
\r
80 * @param mixed $style Estilo de la tabla.
\r
84 function HTML_QuickForm_Renderer_Tabla($style = 'width="400"')
\r
86 $this->HTML_QuickForm_Renderer();
\r
87 $this->_tabla =& new Tabla($style);
\r
88 } // end constructor
\r
91 * returns the HTML generated for the form
\r
98 return $this->_script . $this->_prepend .
\r
99 $this->_tabla->toHtml() .
\r
101 } // end func toHtml
\r
104 * Called when visiting a form, before processing any form elements
\r
106 * @param object An HTML_QuickForm object being visited
\r
110 function startForm(&$form)
\r
112 # FIXME - deberia sacarlo del QuickForm
\r
113 #$this->_prepend = $form->getFormStart();
\r
114 $this->_prepend = "\n<FORM>\n";
\r
115 } // end func startForm
\r
118 * Called when visiting a form, after processing all form elements
\r
119 * Adds required note, form attributes, validation javascript and form content.
\r
121 * @param object An HTML_QuickForm object being visited
\r
125 function finishForm(&$form)
\r
127 // add a required note, if one is needed
\r
128 if (!empty($form->_required) && !$form->_freezeAll) {
\r
129 $id = $this->_tabla->addRow(array($form->getRequiredNote()), array('colspan' => 2, 'align' => 'center', 'cabecera' => true));
\r
130 //$this->_tabla->updateCellAttributes($id, array('colspan' => 2));
\r
132 // add form attributes and content
\r
133 //$html = str_replace('{attributes}', $form->getAttributesString(), $this->_formTemplate);
\r
134 //$this->_html = str_replace('{content}', $this->_html, $html);
\r
135 // add a validation script
\r
136 $this->_script = strval($form->getValidationScript());
\r
137 # FIXME - deberia sacarlo del QuickForm
\r
138 #$this->_append = $form->getFormEnd();
\r
139 $this->_append = "\n</FORM>\n";
\r
140 } // end func finishForm
\r
143 * Called when visiting a header element
\r
145 * @param object An HTML_QuickForm_header element being visited
\r
149 function renderHeader(&$header)
\r
151 $name = $header->getName();
\r
152 $this->_tabla->addRow(array($header->toHtml()), array('colspan' => 2, $name => true, 'align' => 'center'));
\r
153 } // end func renderHeader
\r
156 * Renders an element Html
\r
157 * Called when visiting an element
\r
159 * @param object An HTML_QuickForm_element object being visited
\r
160 * @param bool Whether an element is required
\r
161 * @param string An error message associated with an element
\r
165 function renderElement(&$element, $required, $error)
\r
167 if (!$this->_inGroup) {
\r
168 if ($element->getLabel()) {
\r
169 $id = $this->_tabla->addRow(
\r
171 $element->getLabel() . ($required ? '<FONT color="red">*</FONT>' : ''),
\r
172 $element->toHtml(),
\r
175 $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left', 'nowrap' => true));
\r
176 $this->_tabla->updateCellAttributes($id, 1, array('align' => 'left'));
\r
178 $id = $this->_tabla->addRow(
\r
180 $element->toHtml(),
\r
183 $this->_tabla->updateCellAttributes($id, 0, array('colspan' => 2, 'align' => 'center'));
\r
186 $this->_groupElements[] = $element->toHtml();
\r
188 } // end func renderElement
\r
191 * Renders an hidden element
\r
192 * Called when visiting a hidden element
\r
194 * @param object An HTML_QuickForm_hidden object being visited
\r
198 function renderHidden(&$element)
\r
200 $this->_prepend .= "\n\t". $element->toHtml();
\r
201 } // end func renderHidden
\r
204 * Called when visiting a raw HTML/text pseudo-element
\r
206 * @param object An HTML_QuickForm_html element being visited
\r
210 function renderHtml(&$data)
\r
212 $this->_tabla->addRow(array($header->toHtml()), array('colspan' => 2));
\r
213 } // end func renderHtml
\r
216 * Called when visiting a group, before processing any group elements
\r
218 * @param object An HTML_QuickForm_group object being visited
\r
219 * @param bool Whether a group is required
\r
220 * @param string An error message associated with a group
\r
224 function startGroup(&$group, $required, $error)
\r
226 $this->_groupElements = array();
\r
227 $this->_inGroup = true;
\r
228 } // end func startGroup
\r
231 * Called when visiting a group, after processing all group elements
\r
233 * @param object An HTML_QuickForm_group object being visited
\r
237 function finishGroup(&$group)
\r
239 $id = $this->_tabla->addRow(array($group->getLabel(), join('', $this->_groupElements)));
\r
240 $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'right', 'nowrap' => true));
\r
241 $this->_tabla->updateCellAttributes($id, 1, array('align' => 'left'));
\r
242 /* if (!empty($this->_groupWrap)) {
\r
243 $html = str_replace('{content}', implode('', $this->_groupElements), $this->_groupWrap);
\r
245 $separator = $group->_separator;
\r
246 if (is_array($separator)) {
\r
247 $count = count($separator);
\r
249 for ($i = 0; $i < count($this->_groupElements); $i++) {
\r
250 $html .= $this->_groupElements[$i] . $separator[$i % $count];
\r
252 $html = substr($html, 0, -strlen($separator[($i - 1) % $count]));
\r
254 if (is_null($separator)) {
\r
255 $separator = ' ';
\r
257 $html = implode((string)$separator, $this->_groupElements);
\r
260 $this->_html .= str_replace('{element}', $html, $this->_groupTemplate);
\r
261 $this->_inGroup = false;*/
\r
262 } // end func finishGroup
\r
264 } // end class HTML_QuickForm_Renderer_Default
\r