+<?php\r
+/* vim: set expandtab tabstop=4 shiftwidth=4: */\r
+// +----------------------------------------------------------------------+\r
+// | PHP version 4.0 |\r
+// +----------------------------------------------------------------------+\r
+// | Copyright (c) 1997-2003 The PHP Group |\r
+// +----------------------------------------------------------------------+\r
+// | This source file is subject to version 2.0 of the PHP license, |\r
+// | that is bundled with this package in the file LICENSE, and is |\r
+// | available at through the world-wide-web at |\r
+// | http://www.php.net/license/2_02.txt. |\r
+// | If you did not receive a copy of the PHP license and are unable to |\r
+// | obtain it through the world-wide-web, please send a note to |\r
+// | license@php.net so we can mail you a copy immediately. |\r
+// +----------------------------------------------------------------------+\r
+// | Authors: Alexey Borzov <borz_off@cs.msu.su> |\r
+// | Adam Daniel <adaniel1@eesus.jnj.com> |\r
+// | Bertrand Mansion <bmansion@mamasam.com> |\r
+// +----------------------------------------------------------------------+\r
+//\r
+// $Id$\r
+\r
+require_once 'HTML/QuickForm/Renderer.php';\r
+require_once 'HTML/Tabla.php';\r
+\r
+/**\r
+ * A concrete renderer for HTML_QuickForm,\r
+ * based on QuickForm 2.x built-in one\r
+ * \r
+ * @access public\r
+ */\r
+class HTML_QuickForm_Renderer_Tabla extends HTML_QuickForm_Renderer {\r
+\r
+ /**\r
+ * Tabla usada para dibujar el formulario.\r
+ * @var object Tabla\r
+ * @access private\r
+ */\r
+ var $_tabla;\r
+\r
+ /**\r
+ * HTML con los scripts para poner antes del formulario (tipicamente\r
+ * un javascript).\r
+ * @var string\r
+ * @access private\r
+ */\r
+ var $_script = '';\r
+\r
+ /**\r
+ * HTML para agregar antes de la tabla (tipicamente un javascript).\r
+ * @var string\r
+ * @access private\r
+ */\r
+ var $_prepend = '';\r
+\r
+ /**\r
+ * HTML para agregar despues de la tabla.\r
+ * @var string\r
+ * @access private\r
+ */\r
+ var $_append = '';\r
+\r
+ /**\r
+ * True if we are inside a group \r
+ * @var bool\r
+ * @access private\r
+ */\r
+ var $_inGroup = false;\r
+\r
+ /**\r
+ * Array with HTML generated for group elements\r
+ * @var array\r
+ * @access private\r
+ */\r
+ var $_groupElements = array();\r
+\r
+ /**\r
+ * Constructor.\r
+ *\r
+ * @param mixed $style Estilo de la tabla.\r
+ *\r
+ * @access public\r
+ */\r
+ function HTML_QuickForm_Renderer_Tabla($style = 'width="400"')\r
+ {\r
+ $this->HTML_QuickForm_Renderer();\r
+ $this->_tabla =& new Tabla($style);\r
+ } // end constructor\r
+\r
+ /**\r
+ * returns the HTML generated for the form\r
+ *\r
+ * @access public\r
+ * @return string\r
+ */\r
+ function toHtml()\r
+ {\r
+ return $this->_script . $this->_prepend .\r
+ $this->_tabla->toHtml() .\r
+ $this->_append;\r
+ } // end func toHtml\r
+ \r
+ /**\r
+ * Called when visiting a form, before processing any form elements\r
+ *\r
+ * @param object An HTML_QuickForm object being visited\r
+ * @access public\r
+ * @return void\r
+ */\r
+ function startForm(&$form)\r
+ {\r
+ # FIXME - deberia sacarlo del QuickForm\r
+ #$this->_prepend = $form->getFormStart();\r
+ $this->_prepend = "\n<FORM>\n";\r
+ } // end func startForm\r
+\r
+ /**\r
+ * Called when visiting a form, after processing all form elements\r
+ * Adds required note, form attributes, validation javascript and form content.\r
+ * \r
+ * @param object An HTML_QuickForm object being visited\r
+ * @access public\r
+ * @return void\r
+ */\r
+ function finishForm(&$form)\r
+ {\r
+ // add a required note, if one is needed\r
+ if (!empty($form->_required) && !$form->_freezeAll) {\r
+ $id = $this->_tabla->addRow(array($form->getRequiredNote()), array('colspan' => 2, 'align' => 'center', 'cabecera' => true));\r
+ //$this->_tabla->updateCellAttributes($id, array('colspan' => 2));\r
+ }\r
+ // add form attributes and content\r
+ //$html = str_replace('{attributes}', $form->getAttributesString(), $this->_formTemplate);\r
+ //$this->_html = str_replace('{content}', $this->_html, $html);\r
+ // add a validation script\r
+ $this->_script = strval($form->getValidationScript());\r
+ # FIXME - deberia sacarlo del QuickForm\r
+ #$this->_append = $form->getFormEnd();\r
+ $this->_append = "\n</FORM>\n";\r
+ } // end func finishForm\r
+ \r
+ /**\r
+ * Called when visiting a header element\r
+ *\r
+ * @param object An HTML_QuickForm_header element being visited\r
+ * @access public\r
+ * @return void\r
+ */\r
+ function renderHeader(&$header)\r
+ {\r
+ $name = $header->getName();\r
+ $this->_tabla->addRow(array($header->toHtml()), array('colspan' => 2, $name => true, 'align' => 'center'));\r
+ } // end func renderHeader\r
+\r
+ /**\r
+ * Renders an element Html\r
+ * Called when visiting an element\r
+ *\r
+ * @param object An HTML_QuickForm_element object being visited\r
+ * @param bool Whether an element is required\r
+ * @param string An error message associated with an element\r
+ * @access public\r
+ * @return void\r
+ */\r
+ function renderElement(&$element, $required, $error)\r
+ {\r
+ if (!$this->_inGroup) {\r
+ if ($element->getLabel()) {\r
+ $id = $this->_tabla->addRow(\r
+ array(\r
+ $element->getLabel() . ($required ? '<FONT color="red">*</FONT>' : ''),\r
+ $element->toHtml(),\r
+ )\r
+ );\r
+ $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'left', 'nowrap' => true));\r
+ $this->_tabla->updateCellAttributes($id, 1, array('align' => 'left'));\r
+ } else {\r
+ $id = $this->_tabla->addRow(\r
+ array(\r
+ $element->toHtml(),\r
+ )\r
+ );\r
+ $this->_tabla->updateCellAttributes($id, 0, array('colspan' => 2, 'align' => 'center'));\r
+ }\r
+ } else {\r
+ $this->_groupElements[] = $element->toHtml();\r
+ }\r
+ } // end func renderElement\r
+ \r
+ /**\r
+ * Renders an hidden element\r
+ * Called when visiting a hidden element\r
+ * \r
+ * @param object An HTML_QuickForm_hidden object being visited\r
+ * @access public\r
+ * @return void\r
+ */\r
+ function renderHidden(&$element)\r
+ {\r
+ $this->_prepend .= "\n\t". $element->toHtml();\r
+ } // end func renderHidden\r
+\r
+ /**\r
+ * Called when visiting a raw HTML/text pseudo-element\r
+ * \r
+ * @param object An HTML_QuickForm_html element being visited\r
+ * @access public\r
+ * @return void\r
+ */\r
+ function renderHtml(&$data)\r
+ {\r
+ $this->_tabla->addRow(array($header->toHtml()), array('colspan' => 2));\r
+ } // end func renderHtml\r
+\r
+ /**\r
+ * Called when visiting a group, before processing any group elements\r
+ *\r
+ * @param object An HTML_QuickForm_group object being visited\r
+ * @param bool Whether a group is required\r
+ * @param string An error message associated with a group\r
+ * @access public\r
+ * @return void\r
+ */\r
+ function startGroup(&$group, $required, $error)\r
+ {\r
+ $this->_groupElements = array();\r
+ $this->_inGroup = true;\r
+ } // end func startGroup\r
+\r
+ /**\r
+ * Called when visiting a group, after processing all group elements\r
+ *\r
+ * @param object An HTML_QuickForm_group object being visited\r
+ * @access public\r
+ * @return void\r
+ */\r
+ function finishGroup(&$group)\r
+ {\r
+ $id = $this->_tabla->addRow(array($group->getLabel(), join('', $this->_groupElements)));\r
+ $this->_tabla->updateCellAttributes($id, 0, array('titulo' => true, 'align' => 'right', 'nowrap' => true));\r
+ $this->_tabla->updateCellAttributes($id, 1, array('align' => 'left'));\r
+/* if (!empty($this->_groupWrap)) {\r
+ $html = str_replace('{content}', implode('', $this->_groupElements), $this->_groupWrap);\r
+ } else {\r
+ $separator = $group->_separator;\r
+ if (is_array($separator)) {\r
+ $count = count($separator);\r
+ $html = '';\r
+ for ($i = 0; $i < count($this->_groupElements); $i++) {\r
+ $html .= $this->_groupElements[$i] . $separator[$i % $count];\r
+ }\r
+ $html = substr($html, 0, -strlen($separator[($i - 1) % $count]));\r
+ } else {\r
+ if (is_null($separator)) {\r
+ $separator = ' ';\r
+ }\r
+ $html = implode((string)$separator, $this->_groupElements);\r
+ }\r
+ }\r
+ $this->_html .= str_replace('{element}', $html, $this->_groupTemplate);\r
+ $this->_inGroup = false;*/\r
+ } // end func finishGroup\r
+\r
+} // end class HTML_QuickForm_Renderer_Default\r
+\r
+?>\r