--- /dev/null
+<?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
+-------------------------------------------------------------------------------
+ Ministerio de EconomÃa
+ meconlib
+-------------------------------------------------------------------------------
+This file is part of meconlib.
+
+meconlib is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2 of the License, or (at your option)
+any later version.
+
+meconlib is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License; if not,
+write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+Boston, MA 02111-1307 USA
+-------------------------------------------------------------------------------
+Creado: mar mar 30 16:06:26 ART 2004
+Autor: Leandro Lucarella <llucar@mecon.gov.ar>
+-------------------------------------------------------------------------------
+$Id: Tabla.php 462 2004-01-09 21:11:01Z www-data $
+-----------------------------------------------------------------------------*/
+
+require_once 'HTML/QuickForm/Renderer.php';
+require_once 'MECON/HTML/Tabla.php';
+
+/**
+ * QuickForm renderer que usa Tabla como backend. Es similar a
+ * MECON_HTML_QuickForm_Renderer_Tabla pero dibuja la tabla horizontalmente.
+ * Ej:
+ * <code>
+ * $form = new MECON_HTML_QuickForm();
+ * $form->renderer = new MECON_HTML_QuickForm_Renderer_TablaHorizontal(array('width' => 400));
+ * // Sigo creando el formulario normalmente...
+ * </code>
+ */
+class MECON_HTML_QuickForm_Renderer_TablaHorizontal extends HTML_QuickForm_Renderer {
+
+ /**
+ * Tabla usada para dibujar el formulario.
+ * @var object Tabla
+ * @access private
+ */
+ var $tabla;
+
+ /**
+ * Estructura de la tabla en filas a usar para renderizar.
+ * @access private
+ */
+ var $_rows = array();
+
+ /**
+ * Guarda posición de la fila donde comienzan los elementos.
+ * @private
+ */
+ var $_elementsPos = null;
+
+ /**
+ * Guarda elementos del formulario.
+ * @private
+ */
+ var $_elements = array();
+
+ /**
+ * HTML con los scripts para poner antes del formulario (tipicamente
+ * un javascript).
+ * @var string
+ * @access private
+ */
+ var $_script = '';
+
+ /**
+ * HTML para agregar antes de la tabla (tipicamente un javascript).
+ * @var string
+ * @access private
+ */
+ var $_prepend = '';
+
+ /**
+ * HTML para agregar despues de la tabla.
+ * @var string
+ * @access private
+ */
+ var $_append = '';
+
+ /**
+ * True if we are inside a group
+ * @var bool
+ * @access private
+ */
+ var $_inGroup = false;
+
+ /**
+ * Group error related message.
+ * @var string
+ * @access private
+ */
+ var $_groupError = '';
+
+ /**
+ * Array with HTML generated for group elements
+ * @var array
+ * @access private
+ */
+ var $_groupElements = array();
+
+ /**
+ * Constructor.
+ *
+ * @param mixed $param Array o sting con el estilo de la tabla u objeto
+ * tabla alternativo para usar.
+ *
+ * @access public
+ */
+ function MECON_HTML_QuickForm_Renderer_TablaHorizontal($param = array())
+ {
+ parent::HTML_QuickForm_Renderer();
+ if (is_a($param, 'Tabla')) {
+ $this->setTable($param);
+ }
+ else {
+ $this->setTable(new MECON_HTML_Tabla($param));
+ }
+ } // end constructor
+
+ /**
+ * returns the HTML generated for the form
+ *
+ * @access public
+ * @return string
+ */
+ function toHtml()
+ {
+ $pos = $this->_elementsPos;
+ $rows = count($this->_rows);
+ foreach ($this->_elements as $e) {
+ list($label, $elem, $req, $err) = $e;
+ $cols = array();
+ for ($i = 0; $i < $pos; ++$i) {
+ $cols[] = '';
+ }
+ $cols[] = $label . ($req ? '<font color="red">*</font>' : '');
+ $cols[] = $elem . ($err ? "<br><font color=\"red\">$err</font>" : '');
+ for ($i = $pos + 2; $i < $rows; ++$i) {
+ $cols[] = '';
+ }
+ $id = $this->tabla->addCol($cols, array(array('align' => 'center')));
+ $this->tabla->updateCellAttributes($pos, $id, array('titulo' => true));
+ }
+ foreach ($this->_rows as $i => $row) {
+ if ($row) { // Si no son las filas de los elementos...
+ list($html, $attrs) = $row;
+ $attrs['colspan'] = count($this->_elements);
+ $this->tabla->updateRowAttributes($i, $attrs);
+ $this->tabla->setCellContents($i, 0, $html);
+ }
+ }
+ return $this->_script . $this->_prepend .
+ $this->tabla->toHtml() .
+ $this->_append;
+ } // end func toHtml
+
+ /**
+ * Called when visiting a form, before processing any form elements
+ *
+ * @param object An HTML_QuickForm object being visited
+ * @access public
+ * @return void
+ */
+ function startForm(&$form)
+ {
+ $attrs = $form->getAttributes(true);
+ $this->_prepend = "\n<form$attrs>\n";
+
+ } // end func startForm
+
+ /**
+ * Called when visiting a form, after processing all form elements
+ * Adds required note, form attributes, validation javascript and form content.
+ *
+ * @param object An HTML_QuickForm object being visited
+ * @access public
+ * @return void
+ */
+ function finishForm(&$form)
+ {
+ // add a required note, if one is needed
+ if (!empty($form->_required) && !$form->_freezeAll) {
+ $this->_rows[] = array('<font size="-2">'.$form->getRequiredNote().'</font>', array('cabecera' => true));
+ }
+ // add a validation script
+ $this->_script = strval($form->getValidationScript());
+ $this->_append = "\n</form>\n";
+ } // end func finishForm
+
+ /**
+ * Called when visiting a header element
+ *
+ * @param object An HTML_QuickForm_header element being visited
+ * @access public
+ * @return void
+ */
+ function renderHeader(&$header)
+ {
+ $this->_rows[] = array($header->toHtml(),
+ array($header->getName() => true));
+ } // end func renderHeader
+
+ /**
+ * Renders an element Html
+ * Called when visiting an element
+ *
+ * @param object An HTML_QuickForm_element object being visited
+ * @param bool Whether an element is required
+ * @param string An error message associated with an element
+ * @access public
+ * @return void
+ */
+ function renderElement(&$element, $required, $error)
+ {
+ if (!$this->_inGroup) {
+ $this->_checkInElements();
+ $this->_elements[] = array(
+ $element->getLabel() . ($required ? '<font color="red">*</font>' : ''),
+ $element->toHtml() . ($error ? "<br><font color=\"red\">$error</font>" : ''),
+ $required, $error);
+ } else {
+ $this->_groupElements[] = ($element->getLabel() ? ($element->getLabel().' ') : '') . $element->toHtml();
+ }
+ } // end func renderElement
+
+ /**
+ * Renders an hidden element
+ * Called when visiting a hidden element
+ *
+ * @param object An HTML_QuickForm_hidden object being visited
+ * @access public
+ * @return void
+ */
+ function renderHidden(&$element)
+ {
+ $this->_prepend .= "\n\t". $element->toHtml();
+ } // end func renderHidden
+
+ /**
+ * Called when visiting a raw HTML/text pseudo-element
+ *
+ * @param object An HTML_QuickForm_html element being visited
+ * @access public
+ * @return void
+ */
+ function renderHtml(&$data)
+ {
+ $this->_rows[] = array(&$data, array());
+ } // end func renderHtml
+
+ /**
+ * Called when visiting a group, before processing any group elements
+ *
+ * @param object An HTML_QuickForm_group object being visited
+ * @param bool Whether a group is required
+ * @param string An error message associated with a group
+ * @access public
+ * @return void
+ */
+ function startGroup(&$group, $required, $error)
+ {
+ $this->_groupElements = array();
+ $this->_groupError = $error;
+ $this->_inGroup = true;
+ } // end func startGroup
+
+ /**
+ * Called when visiting a group, after processing all group elements
+ *
+ * @param object An HTML_QuickForm_group object being visited
+ * @access public
+ * @return void
+ */
+ function finishGroup(&$group)
+ {
+ $name = $group->getName();
+ $sep = $group->_separator;
+ if (strtolower($name) == 'botones') {
+ $this->_rows[] = array(join('', $this->_groupElements), array('valign' => 'middle', 'align' => 'center'));
+ } else {
+ $this->_checkInElements();
+ $this->_elements[] = array(array($group->getLabel(),
+ join($sep, $this->_groupElements)), false, false);
+ }
+ $this->_inGroup = false;
+ } // end func finishGroup
+
+ function _checkInElements() {
+ if (is_null($this->_elementsPos)) {
+ $this->_elementsPos = count($this->_rows);
+ $this->_rows[] = false;
+ $this->_rows[] = false;
+ }
+ }
+
+ function setTable(&$table) {
+ $this->tabla =& $table;
+ }
+
+ function getCSS() {
+ return $this->tabla->getCSS();
+ }
+
+} // end class HTML_QuickForm_Renderer_Default
+
+?>