🌹🏠🌹？》《》？《》？<?php

/**
* Formy, es una clase que permite una forma razonablemente simple, de crear
* formularios de HTML, directamente escribiendo codigo en PHP
*
* @package Formy
*/

/**
* Formy, es la clase principal. Contiene el formulario, al cual se le
* agregaran los Objetos Formy
*
* @package Formy
* @subpackage ClaseFormy
*
* @version 1.1
* @author Marco Scarnatto <mscarnatto@dpsonline.com.ar>
*/
class formy
{
    /**
    * @var boolean Seteada en TRUE escribe el codigo HTML del form en pantalla
    */
    var $debug            = false;
    /**
    * @var string Titulo del FORM
    */
    var $caption          = '';
    /**
    * @var string Codigo CSS para el style de la tabla que arma el FORM
    */
    var $tableStyle      = '';

    /**
    * @access private
    * @var string Guarda el codigo HTML de la linea <FORM ...>
    */
    var $form             = '';
    /**
    * @access private
    * @var string Guarda el codigo HTML que se enviara a pantalla
    */
    var $salida           = '';
    /**
    * @access private
    * @var array Array de Objetos_Formy en el orden en que se enviaran a pantalla
    */
    var $objetos          = array();
    /**
    * @access private
    * @var integer Contador de campos <FIELDSET> actualmente abiertos
    */
    var $fieldset_abierto = 0;
    
    var $name = '';
    var $validacion;
    var $funcionSalida = "showUpdWin()";

    /**
    * @param string URL donde se el FORM enviara los datos
    * @param string Metodo a usar: POST o GET
    */
    function __construct( $action = "?", $method = "POST", $target = "upd_content" )
    {
        $this->form .= "<form target='$target' action='$action' method='$method' onSubmit='return validar();' ";
        $this->clase( "formy_form" );
    }

    /*
    * Agrega un objeto al arbol de objetos de FORMy
    *
    * @param mixed Es la salida de {@link objeto_formy}
    */
    function agregar( $item )
    {
        $this->objetos[] = $item;

        // Para el objeto "automcompletar" hay que hacer un proceso especial
        if( $item->type == 'autocompletar' ) {
          // Creo el objeto oculto para la marca de nuevo item
          $objeto = new hidden( $item->name.'_codigo', $item->codigo );
          $this->objetos[] = $objeto;
          unset( $objeto );

          // Creo el objeto DIV para contener las opciones
          $objeto = new textosimple( '<div class="autocomplete" id="'.$item->name.'_opciones"></div>' );
          $this->objetos[] = $objeto;
          unset( $objeto );
        }
    }
    /**
    * Usado para pasar cualquier tipo de atributos al
    * FORM, que no esten contemplados en otros metodos
    *
    * @param string
    */
    function extra( $string )
    {
        $this->form .= $string . " ";
    }

    /**
    * Usado para simular <FORM id="$id"><p>
    * Permitira identificar univocamente al objeto y aplicarle atributos desde CSS o JS
    *
    * @param string
    */
    function id( $id )
    {
        $this->form .= "id=\"$id\" ";
    }

    /**
    * Usado para simular <FORM class="$class"><p>
7    * Permitira identificar al objeto y aplicarle atributos desde CSS o JS
    *
    * @param string
    */
    function clase( $class )
    {
        $this->form .= "class=\"$class\" ";
    }

    /**
    * Usado para simular <FORM style="$style"><p>
    * Y poder aplicarle atributos particulares de CSS al elemento
    *
    * @param string
    */
    function style( $style )
    {
        $this->form .= "style=\"$style\" ";
    }

    /**
    * Usado para simular <FORM title="$title"><p>
    * Mostrara un ToolTip al sobrevolar el objeto con el mouse
    *
    * @param string
    */
    function title( $title )
    {
        $this->form .= "title=\"$title\" ";
    }

    /**
    * Usado para simular <FORM name="$name"><p>
    * Asigna el atributo name al FORM para referencia desde Javascript
    *
    * @param string
    */
    function name( $name )
    {
        $this->form .= "name=\"$name\" ";
        $this->name = $name;
    }

    /**
    * Devuelve un string con el codigo generado, listo para ser mostrado en pantalla
    *
    * @return string
    */
    function mostrar()
    {
        $Primera_Pasada = true;
        $vuelta = 0;
        $mascaras = null;
        $autocompletar = null;
        
        $this->salida = $this->form . ">\n<table class='formy_table'  cellspacing='0' cellpadding='0' style='" . $this->tableStyle . "'>\n";

        if( $this->caption )
            $this->salida .= "<tr><td colspan=\"99\" class=\"formy_caption\">" . $this->caption . "</td></tr>\n";

        foreach( $this->objetos as $obj )
        {
            if( $obj->type == "text" && $obj->mascara )
              $mascaras[$obj->name] = array( $obj->mascara, $obj->tipo );

            if( $obj->type == "autocompletar" ) {
              $autocompletar[$obj->name] = $obj->url;

              if( ! $obj->permitirNuevo )
                $this->validacion .= 'if( $F("'.$obj->name.'_codigo") == "_nuevo_" )
                                        return formyVerError( "_nuevo_" );';
            }

            if( $obj->requerido ) 
            {
              if( $obj->type == "select" )
              {
                $this->validacion .= "campo = document.getElementById('".$obj->name."'); if(campo.selectedIndex < 1) return formyVerError();\n";
              } else {
                $this->validacion .= "if( isEmpty( campo = document.getElementById('".$obj->name."') ) ) return formyVerError(); \n";
              } 
            } 
            if( $obj->fecha ) $this->validacion .= "campo=document.getElementById('".$obj->name."'); if( campo.value != '' && ! isDate(campo.value, '/' ) ) { alert('Alg�n campo contiene una fecha invalida'); campo.focus(); return false; }\n";

            if( $obj->type == "hidden" )
            {
                $this->salida .= "<input type=\"" . $obj->type . "\" " . $obj->atributos . "/>\n";
                continue;
            }

            if( $obj->rowspan && ! $obj->colspan )
            {
                $this->salida .= "</td><td style=\"vertical-align: top;\" rowspan=\"".$obj->rowspan."\">\n";
            }

            if( $obj->ultimaFila )
            {
                $this->salida .= "<tr class=\"formy_ultimafila\">\n<td colspan=\"99\">";

            } else if( $obj->label || $obj->colspan ) {
                if( ! $Primera_Pasada && ! $obj->colspan )
                    $this->salida .= "</td></tr>\n";

                if( $obj->label && $obj->colspan )
                {
                    $vuelta = abs( $vuelta -1 );
                    $this->salida .= "<tr class=\"formy_fila".$vuelta."\">\n<td class='formy_label'>" . $this->hotkey( $obj->label ) . "</td>\n<td" . ( ($obj->colspan)? " colspan='" . $obj->colspan . "'" : "" ) . ">";

                } else if( $obj->colspan ) {
                    $this->salida .= "<td colspan='". $obj->colspan ."' class='formy_colspan'>\n";

                } else {
                    $vuelta = abs( $vuelta -1 );
                    $this->salida .= "<tr class=\"formy_fila".$vuelta."\">\n<td class='formy_label'>" . $this->hotkey( $obj->label ) . "</td>\n<td>";
                }
            }

            if( $obj->nl )
                if( $obj->type == "fieldset" )
                {
                    $this->salida .= "<p>\n";

                } else {
                    $this->salida .= "<br>\n";
                }

            if( $obj->cartel && $obj->type != "textosimple" )
                $this->salida .= $obj->cartel . "\n";

            switch( strtolower( (string)$obj->type ) )
            {
                case "textarea":
                    $this->salida .= "<textarea " . $obj->atributos . ">" . $obj->textarea_datos . "</textarea>\n";
                    break;

                case "select":
                    $this->salida .= "<select " . $obj->atributos . ">\n";
                    foreach( $obj->option as $clave => $valor )
                    {
                        $seleccionado = ( $clave == $obj->selected ) ? "selected=\"selected\"" : "";
                        $this->salida .= "<option $seleccionado value=\"" . $clave . "\">" . $valor . "</option>\n";
                    }
                    $this->salida .= "</select>\n";
                    break;

                case "fieldset":
                    $this->fieldset_abierto++;
                    $this->salida .= "<fieldset " . $obj->atributos . ">\n";
                    if( $obj->legend ) $this->salida .= "<legend class=\"formy_legend\">" . $obj->legend . "</legend>\n";
                    break;

                case "/fieldset":
                    $this->salida .= "</fieldset>\n";
                    $this->fieldset_abierto--;
                    break;

                case "textosimple":
                	$this->salida .= "<span " . $obj->atributos . ">" . $obj->cartel . "</span>\n";
                	break;

                case "celdavacia":
                	$this->salida .= "&nbsp;\n";
                	break;

                case "button":
                    $this->salida .= "<button " . $obj->atributos . ">" . $obj->value . "</button>\n";
                    break;

                case "calendar":
                    $this->salida .= "<input type='text' $obj->atributos /><img onClick='displayCalendar(".$obj->name.", \"dd/mm/yyyy\", this)' style='border:none; vertical-align: middle; cursor:pointer;' src='/gargano_dps/include/calendario/images/calendar.gif' />\n";
                    break;
                    
                case "agregar":
                    $this->salida .= "&nbsp;<img title='Agregar nuevo item' $obj->atributos style='border:none; vertical-align: middle; cursor:pointer;' src='/gargano_dps/imagenes/plus.png' />\n";
                    break;                    

                default:
                    $this->salida .= "<input type=\"" . $obj->type . "\" " . $obj->atributos . "/>\n";
                    break;
            }
            if( $obj->requerido ) $this->salida .= "<img style='vertical-align:middle' title='Campo obligatorio' src='/gargano_dps/include/formy/req.gif'/>";
            $Primera_Pasada = false;

        }

        $this->salida .= "</td></tr></table>\n</form>\n";
        if( $this->debug ) $this->salida .= "<pre>" . htmlspecialchars( $this->salida ) . "</pre>";

        $this->salida .= "<script>\n";
        if( $mascaras )
            foreach ( $mascaras as $objeto => $mask ) 
                $this->salida .= 'msk = new Mask("'.$mask[0].'", "'.$mask[1].'");' . "\nmsk.attach( document.".$this->name.".".$objeto.");\n";

        if( $autocompletar )
          foreach ( $autocompletar as $objeto => $datos)
            $this->salida .= 'new Ajax.Autocompleter( "' . $objeto .'",
                                                      "' . $objeto . '_opciones",
                                                      "' . $datos . '",
                                                      {
                                                        callback: function( input, querystring ) {
                                                                    $("'.$objeto.'_codigo").value = "_nuevo_";
                                                                    return querystring + "&sessionName="+sessionName;
                                                                  },
                                                        afterUpdateElement: function ( input, elegido) {
                                                                              $("'.$objeto.'_codigo").value = elegido.id;
                                                                            }
                                                      } ); ';

        $this->salida .= "function validar() {\n" .
                            $this->validacion . "\n
                            updModal = " . $this->funcionSalida . ";
                            return true;
                          }\n
                          </script>\n";

        return $this->salida;
    }

    function hotkey( $value )
    {
        if( ($p = strpos( $value, "&" ) ) !== false )
            $value = preg_replace( "/(.*)(&)(.+?)(.*)/", "$1<u>$3</u>$4", $value );

        return $value;
    }

}

/**
* Define un objeto para luego agregarlo al formulario generado por Formy
*
* Objetos Formy son cualquiera de los elementos <INPUT>, <SELECT>, <TEXTAREA> de HTML
*
* @package Formy
* @subpackage ObjetoFormy
*
*/
class objeto_formy
{
    /**
    * Seteada en TRUE unira (colspan) las columans del formulario
    * @var boolean
    */
    var $colspan     = 0;

    /**
    * Unira n filas del formulario o hasta que
    * aparezca un objeto conteniendo un LABEL
    *
    * @var integer
    */
    var $rowspan     = 0;

    /**
    * Contiene un texto que se mostrara delante del objeto
    * @var string
    */
    var $cartel      = '';

    /**
    * Contiene los atributos del campo que se van pasando
    * @var string
    * @access private
    */
    var $atributos   = '';
    /**
    * Mantiene el texto a mostrar como titulo de la fila
    * @var string
    * @access private
    */
    var $label       = '';
    /**
    * En TRUE genera un <P> antes de mostrar el objeto
    * @var boolean
    * @access private
    */
    var $nl          = false;

    var $name        = false;
    var $requerido   = false;
    var $fecha       = false;
    var $mascara;
    var $value;
    var $type;
    var $tipo;
    
    /**
    * Constructor de la clase
    * - No se usa directamente, sino que es llamada desde sus subclases
    * - Este objeto sera usado en {@link formy::agregar()}
    *
    * @see text
    */
    function __construct( $type, $name = false, $nl = false )
    {
        $this->type = $type;
        if( $nl ) $this->nl = true;
    }

    /**
    * El OBJETO ser� creado en una nueva celda a la derecha de la actual
    * 
    */
    function nuevaCelda()
    {
        $this->rowspan="1";
    }

    /**
    * Usado para simular <OBJETO id="$id"><p>
    * Permitira identificar univocamente al objeto y aplicarle atributos desde CSS o JS
    * @param string
    */
    function id( $id )
    {
        $this->atributos .= "id=\"$id\" ";
    }

    /**
    * Usado para simular <OBJETO class="$class"><p>
    * Permitira identificar al objeto y aplicarle atributos desde CSS o JS
    * @param string
    */
    function clase( $class )
    {
        $this->atributos .= "class=\"$class\" ";
    }

    /**
    * Usado para simular <OBJETO style="$style"><p>
    * Y poder aplicarle atributos particulares de CSS al elemento
    * @param string
    */
    function style( $style )
    {
        $this->atributos .= "style=\"$style\" ";
    }

    /**
    * Usado para simular <OBJETO title="$title"><p>
    * Mostrara un ToolTip (mesajito) al sobrevolar el objeto con el mouse
    * @param string
    */
    function title( $title )
    {
        $this->atributos .= "title=\"$title\" ";
    }

    /**
    * Usado para simular <OBJETO disabled><p>
    * El objeto quedar� visible pero inutilizable por el
    * usuario y no se enviara con el FORM
    */
    function disabled()
    {
        $this->atributos .= "disabled=\"disabled\" ";
    }

    function validarRequerido()
    {
        $this->requerido = true;
    }

    function validarFecha()
    {
        $this->fecha = true;
    }

    /**
    * Usado para simular <OBJETO readonly><p>
    * Similar a {@link disabled} pero aun ser� enviado por POST/GET
    */
    function readonly()
    {
        $this->atributos .= "readonly=\"readonly\" ";
    }

    /**
    * Usado para simular <OBJETO accesskey="$accesskey"><p>
    * Permite cambiar el orden de los objetos al desplazarse con el teclado
    * @param integer
    */
    function accesskey( $accesskey )
    {
        $this->atributos .= "accesskey=\"$accesskey\" ";
    }

    /**
    * Usado para simular <OBJETO size="$size">
    * - En un <INPUT> cambiara el ancho del objeto
    * - En un <SELECT> la cantidad de <OPTION> que mostrara continuamente
    * @param integer
    */
    function size( $size )
    {
        $this->atributos .= "size=\"$size\" ";
    }


    /**
    * Usado para pasar cualquier tipo de atributos al
    * objeto, que no esten contemplados en otros metodos
    *
    * Por ejemplo util para Javascript:
    * <CODE>
    *  $objeto->extra( 'OnClick="alert($mensaje)" ' );
    * </CODE>
    *
    * @param string
    */
    function extra( $string )
    {
        $this->atributos .= $string . " ";
    }
}

/**
* Mostrara una celda vacia en el formulario generado.
*
* Solo util si se est�n utilizando varias columnas
* con la propiedad {@link rowspan}
*
* @package ObjetoFormy
*/
class celdavacia extends objeto_formy
{

    function __construct()
    {
        $this->type = "celdavacia";
        $this->rowspan = 1;
    }
}

/**
* Permite escribir un texto libre
*
* Aunque tambien puede ser utilizado para acciones complejas tal como:
* <CODE>
*  $link = "<a href='/algo/pagina.php'><img src='/gargano_dps/imagenes/boton.gif'></a>";
*  $objeto->textosimple( $link );
* </CODE>
*
* @package ObjetoFormy
*/
class textosimple extends objeto_formy
{
    /**
    * @param string $texto Texto que se escribira en pantalla
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $texto, $nl = false )
    {
        $this->type = "textosimple";
        $this->cartel = $texto;
        if( $nl ) $this->nl = true;
    }
}

/**
* Inicia un <FIELDSET>, osea un agrupamiento de objetos
*
* - Se usara en conjunto con {@link _fieldset}
* - Los siguiente objetos que se agreguen a Formy, quedaran incluidos en este fieldset
*
* @package ObjetoFormy
*/
class fieldset extends objeto_formy
{
    /*
    * Texto que se escribira como titulo del fieldset
    * @var string
    */
    var $legend = '';

    /**
    * @param string $legend Texto que se escribira como titulo del fieldset
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $legend = false, $nl = false )
    {
        $this->type = "fieldset";
        $this->legend = $legend;
        if( $nl ) $this->nl = true;
    }
}

/**
* Cierra un <FIELDSET> abierto
*
* @package ObjetoFormy
*/
class _fieldset extends objeto_formy
{
    function __construct( )
    {
        $this->type = "/fieldset";
    }
}

/**
* Genera un objeto de tipo Casilla de Verificaci�n (CheckBox)
*
* @package ObjetoFormy
*/
class checkbox extends objeto_formy
{
    /**
    * @param string Nombre (para HTML) del objeto
    * @param boolean Define si inicialmente aparece marcado o no
    * @param string Es el atributo VALUE del INPUT, osea el valor que enviara el FORM
    * @param string Texto que se mostrara antes del campo
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $checked = false, $value = false, $cartel = false, $nl = false )
    {
        $this->type = "checkbox";
        $this->atributos .= "name=\"$name\" ";
        if( $checked ) $this->atributos .= "checked=\"checked\" ";
        if( $value ) $this->atributos .= "value=\"$value\" ";
        if( $cartel ) $this->cartel = $cartel;
        if( $nl ) $this->nl = true;
    }
}

/**
* Genera un objeto de tipo Radio
*
* @package ObjetoFormy
*/
class radio extends objeto_formy
{
    /**
    * @param string Nombre (para HTML) del objeto
    * @param boolean Define si inicialmente aparece marcado o no
    * @param string Es el atributo VALUE del INPUT, osea el valor que enviara el FORM
    * @param string Texto que se mostrara antes del campo
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $checked = false, $value = false, $cartel = false, $nl = false )
    {
        $this->type = "radio";
        $this->atributos .= "name=\"$name\" ";
        if( $checked ) $this->atributos .= "checked=\"checked\" ";
        if( $value ) $this->atributos .= "value=\"$value\" ";
        if( $cartel ) $this->cartel = $cartel;
        if( $nl ) $this->nl = true;
    }
}

/**
* Genera un objeto de tipo SELECT
*
* @package ObjetoFormy
*/
class select extends objeto_formy
{
    /**
    * @var array Mantiene las opciones del SELECT
    */
    var $option   = '';

    /**
    * Indica cual es el item actualmente seleccionado
    */
    var $selected = '';

    /**
    * @param string Nombre (para HTML) del objeto
    * @param array Listado de las opciones a mostrar
    * @param boolean Item que aparecera inicialmente seleccionado
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $options = false, $selected = false, $nl = false )
    {
        $this->type = "select";
        $this->atributos .= "name=\"$name\" ";
        $this->id($name);
        $this->name = $name;
        if( $options ) $this->option = $options;
        if( $selected ) $this->selected = $selected;
        if( $nl ) $this->nl = true;
    }

    /**
    * Permite al SELECT que pueda seleccionar varios item a la vez
    */
    function multiple()
    {
        $this->atributos .= "multiple=\"$multiple\" ";
        $this->atributos = preg_replace('/name="[a-z0-9_]+"/i', '', $this->atributos );
        $this->atributos .= 'name="'.$this->name.'[]" ';
    }
}

/**
* Genera un objeto TEXTAREA de multiple filas de escritura
*
* @package ObjetoFormy
*/
class textarea extends objeto_formy
{
    /**
    * @var string Texto a mostrar dentro del TEXTAREA
    */
    var $textarea_datos = '';

    /**
    * @param string Nombre (para HTML) del objeto
    * @param integer Numero de filas del TEXTAREA
    * @param integer Numero de columnas del TEXTAREA
    * @param string Texto a mostrar dentro del TEXTAREA
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $rows = false, $cols = false, $texto = false, $nl = false )
    {
        $this->type = "textarea";
        $this->atributos .= "name=\"$name\" ";
        if( $rows ) $this->atributos .= "rows=\"$rows\" ";
        if( $cols ) $this->atributos .= "cols=\"$cols\" ";
        if( $texto ) $this->textarea_datos = $texto;
        if( $nl ) $this->nl = true;
    }
}

/**
* Clase que permite dibujar los diferentes tipos de botones
*
* No se llama a esta clase en forma directa sino a travez de sus subclases
*
* @package ObjetoFormy
* @subpackage ObjetoFormy_boton
*/
class boton extends objeto_formy
{
    /**
    * @param string El tipo de boton que mostrara
    * @param string Nombre (para HTML) del objeto
    * @param string Es el atributo VALUE del INPUT, osea el valor que enviara el FORM
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $type, $name, $value = false, $nl = false )
    {
        $this->type = $type;
        $this->atributos .= "name=\"$name\" ";
        $this->atributos .= "id=\"$name\" ";

        if( $value !== false ) $this->atributos .= "value=\"$value\" ";
        if( $nl ) $this->nl = true;
    }
}

/**
* Crea un boton de envio de archivos
*
* @package ObjetoFormy_boton
*/
class archivo extends boton
{
    /**
    * @param string Nombre (para HTML) del objeto
    * @param string Es el atributo VALUE del INPUT, osea el valor que enviara el FORM
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $value = false, $nl = false )
    {
        parent::__construct( "file", $name, $value, $nl );
    }
}

/**
* Crea un INPUT comun de texto
*
* @package ObjetoFormy_boton
*/
class text extends boton
{
    /**
    * @param string Nombre (para HTML) del objeto
    * @param string Es el atributo VALUE del INPUT, osea el valor que enviara el FORM
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $value = false, $nl = false )
    {
        parent::__construct( "text", $name, $value, $nl );
        $this->name = $name;
    }
    
    /**
    * Usado para simular <INPUT maxlenght="$maxlenght">
    * Valida no poder escribir mas de n caracteres en el campo
    * @param integer
    */
    function maxlength( $maxlength )
    {
        $this->atributos .= "maxlength=\"$maxlength\" ";
    }
    
    function mask( $mascara, $tipo = false )
    {
        $this->mascara = $mascara;
        if($tipo) $this->tipo = $tipo;
    }
    

}

class hora extends text
{
    
    function __construct( $name, $value = false, $nl = false )
    {
        $this->extra( "onKeyDown='return formyAhora(this,event)' " );
        parent::__construct( $name, $value, $nl );
        $this->name = $name;
        $this->type = "text";
    }      
  
}

class autocompletar extends text
{
    var $url;
    var $codigo;
    var $permitirNuevo;

    function __construct( $name, $url, $value = false, $codigo = false, $nl = false )
    {
        parent::__construct( $name, $value, $nl );
        $this->name = $name;
        $this->type = "autocompletar";
        $this->url = $url;
        $this->codigo = ( ! $codigo ) ? '_vacio_' : $codigo ;
        $this->permitirNuevo = false;
        
        $this->extra( 'onBlur=" if(this.value == \'\' ) {
                                  $(\''.$name.'_codigo\').value = \'_vacio_\';
                                } "');
    }

    function permitirNuevo()
    {
      $this->permitirNuevo = true;
    }

    function url ( $url )
    {
        $this->url = $url;
    }
}

class calendario extends text
{
    function __construct( $name, $value = false, $nl = false )
    {
        parent::__construct( $name, $value, $nl );
        $this->name = $name;
        $this->type = "calendar";
        $this->style("text-align: rigth;");
        $this->extra( "onKeyDown='return formyHoy(this,event)' " );


    }
}

/**
* Crea un INPUT de escritura de password
*
* @package ObjetoFormy_boton
*/
class password extends boton
{
    /**
    * @param string Nombre (para HTML) del objeto
    * @param string Es el atributo VALUE del INPUT, osea el valor que enviara el FORM
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $value = false, $nl = false )
    {
        $this->name = $name;
        parent::__construct( "password", $name, $value, $nl );
    }
}

/**
* Crea un INPUT de oculto
*
* @package ObjetoFormy_boton
*/
class hidden extends boton
{
    /**
    * @param string Nombre (para HTML) del objeto
    * @param string Es el atributo VALUE del INPUT, osea el valor que enviara el FORM
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $value = false, $nl = false )
    {
        parent::__construct( "hidden", $name, $value, $nl );
    }
}

/**
* Crea un INPUT de envio del formulario
*
* @package ObjetoFormy_boton
*/
class submit extends button
{
    /**
    * @param string Nombre (para HTML) del objeto
    * @param string Es el atributo VALUE del INPUT, osea el valor que enviara el FORM
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $value = false, $nl = false )
    {
        parent::__construct( $name, $value, $nl, "submit" );
    }
}

/**
* Crea un INPUT de limpieza de campos del FORM
*
* @package ObjetoFormy_boton
*/
class resetear extends boton
{
    /**
    * @param string Nombre (para HTML) del objeto
    * @param string Es el atributo VALUE del INPUT, osea el valor que enviara el FORM
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $value = false, $nl = false )
    {
        parent::__construct( $name, $value, $nl, "reset" );
    }
}

/**
* Crea un INPUT sin accion, util para usar con JavaScript
*
* @package ObjetoFormy_boton
*/
class button extends objeto_formy
{
    var $ultimaFila;


    function __construct( $name, $value, $nl = false, $tipo = false )
    {
        $this->type = "button";
        $this->atributos .= "name=\"$name\" ";
        $this->atributos .= "id=\"$name\" ";
        $this->hotkey($value);
        if( $nl ) $this->nl = true;
        if( ! $tipo ) $tipo = "button";
        $this->atributos .= "type=\"$tipo\" ";
    }
    
    function hotkey( $value )
    {
        if( ($p = strpos( $value, "&" ) ) !== false )
        {
            $this->accesskey( strtolower( substr( $value, $p+1, 1 ) ) );
            $value = preg_replace( "/(.*)(&)(.+?)(.*)/", "$1<u>$3</u>$4", $value );
        }
        $this->value = $value;
    }
        
}
//class button extends boton
//{
//    /**
//    * @param string Nombre (para HTML) del objeto
//    * @param string Es el atributo VALUE del INPUT, osea el valor que enviara el FORM
//    * @param boolean $nl Genera un <P> antes del objeto
//    */
//    function button( $name, $value = false, $nl = false )
//    {
//        parent::__construct( "button", $name, $value, $nl );
//    }
//}

/**
* Crea un INPUT de envio mostrando una imagen
*
* @package ObjetoFormy_boton
*/
class image extends boton
{
    /**
    * @param string Nombre (para HTML) del objeto
    * @param string Es el PATH hacia la imagen que mostrara el boton
    * @param boolean $nl Genera un <P> antes del objeto
    */
    function __construct( $name, $src = false, $nl = false )
    {
        parent::__construct( "image", $name, $value, $nl );
        if( $src ) $this->atributos .= "src=\"$src\" ";
    }

}

//Crea un BOTON con la imagen +
class agregar extends boton
{
    /**
     * @param NINGUNO!    
     */    
    function __construct($path, $combo)
    {          
      $this->type  = "agregar";
      $sessionName = session_name();
      $this->extra( "onClick='if(typeof(modal) == \"undefined\")modal = crearPopWin(); showPopWin(\"/abm/$path?sinMenu=1&combo=$combo&accion=agregar&sessionName=$sessionName\", window.innerWidth * 0.95, window.innerHeight * 0.8)'" );                                                   
    }
}
?>
