<?php
/**
* ************************************************************
*
* Author: Ruben Espadas Pacheco a.k.a zir3
* Date: 21.04.2007
* Thanks to Dejitaru for your point of view of this script
*
* ************************************************************
*/
class getHTML{
var $id; // Attribute for all DOM's (function parameter)
var $name; // Attribute for all DOM's (function parameter)
var $value; // Attribute for all DOM's (function parameter)
var $style; // Attribute for all DOM's
var $class; // Attribute for all DOM's (function parameter)
var $event; // Declaration for a type of event JS in a DOM
var $extras; // Another attributes for a DOM like disabled and check
var $method; // Function tu execute when the event JS it's call
var $texto; // Text content in some DOM's
var $objet; // What DOM you want? (text => input text, pass => input pass, hide => input hidden ......)
var $label; // Attribute for all DOM's (function parameter)
var $size; // Attribute in some DOM's
var $maxlength; // Attribute in some DOM's
var $end; // Flaw for options in select DOM
var $endLine; // How do you want end your DOM? Example: <br />,  , </span> .....
var $startLine; // How do you want start your DOM? Example:  , <span> .....
var $methodform; // Decalration of method for a form
var $actionform; // Decalration of action for a form
var $img; // Declaration of a PATH and name of a image for attribute src of a img DOM
function getHTML(){
$this->clear();
}
//LIMPAIMOS PARAMETROS Y DECLARAMOS ALGUNAS VARIABLES PASADAS POR PARAMETRO
function genHTML($pObjet, $pName, $pId="", $pValue="", $pClass="", $pLabel=""){
$this->object=trim($pObjet);
$this->id=trim($pId);
$this->name=trim($pName);
$this->value=trim($pValue);
$this->class=trim($pClass);
$this->label=trim($pLabel);
$this->object($this->object);
$this->fin = false;
}
//CREAMOS EL OBJETO HTML
function object($object){
if($this->label && $this->id)
echo '<label for="'.$this->id.'">'.$this->label.'</label>';
switch($object){
case 'text':
$rAct = $this->event!=""&&$this->method!="" ? $this->actsJs():'';
echo $this->startLine.'<input type="text" id="'.$this->id.'" name="'.$this->name.'" value="'.$this->value.'" size="'.$this->size.'" maxlength="'.$this->maxlength.'" class="'.$this->class.'" '.$rAct.' '.$this->extras.' />'.$this->endLine;
break;
case 'pass':
$rAct = $this->event!=""&&$this->method!="" ? $this->actsJs():'';
echo $this->startLine.'<input type="password" id="'.$this->id.'" name="'.$this->name.'" value="'.$this->value.'" size="'.$this->size.'" maxlength="'.$this->maxlength.'" class="'.$this->class.'" '.$rAct.' '.$this->extras.' />'.$this->endLine;
break;
case 'hide':
$rAct = $this->event!=""&&$this->method!="" ? $this->actsJs():'';
echo '<input type="hidden" id="'.$this->id.'" name="'.$this->name.'" value="'.$this->value.'" size="'.$this->size.'" maxlength="'.$this->maxlength.'" class="'.$this->class.'" '.$rAct.' '.$this->extras.' />';
break;
case 'button':
$rAct = $this->event!=""&&$this->method!="" ? $this->actsJs():'';
echo $this->startLine.'<input type="button" id="'.$this->id.'" name="'.$this->name.'" value="'.$this->value.'" class="'.$this->class.'" '.$rAct.' '.$this->extras.' />'.$this->endLine;
break;
case 'submit':
$rAct = $this->event!=""&&$this->method!="" ? $this->actsJs():'';
echo $this->startLine.'<input type="submit" id="'.$this->id.'" name="'.$this->name.'" value="'.$this->value.'" class="'.$this->class.'" '.$rAct.' '.$this->extras.' />'.$this->endLine;
break;
case 'check':
$rAct = $this->event!=""&&$this->method!="" ? $this->actsJs():'';
echo $this->startLine.'<input type="checkbox" id="'.$this->id.'" name="'.$this->name.'" value="'.$this->value.'" class="'.$this->class.'" '.$rAct.' '.$this->extras.' />'.$this->endLine;
break;
case 'radio':
$rAct = $this->event!=""&&$this->method!="" ? $this->actsJs():'';
echo $this->startLine.'<input type="radio" id="'.$this->id.'" name="'.$this->name.'" value="'.$this->value.'" class="'.$this->class.'" '.$rAct.' '.$this->extras.' />'.$this->endLine;
break;
case 'select':
$this->fin == true ? $end="</select>":$end="";
$rAct = $this->event!=""&&$this->method!="" ? $this->actsJs():'';
echo '<select id="'.$this->id.'" name="'.$this->name.'" class="'.$this->class.'" '.$rAct.' '.$this->extras.'>';
break;
case 'option':
echo '<option id="'.$this->id.'" value="'.$this->value.'" class="'.$this->class.'" '.$this->extras.'>'.$this->texto.'</option>'.$end;
break;
case 'textarea':
$rAct = $this->event!=""&&$this->method!="" ? $this->actsJs():'';
echo $this->startLine.'<textarea id="'.$this->id.'" name="'.$this->name.'" class="'.$this->class.'" '.$rAct.' '.$this->extras.'>'.$this->texto.'</textarea>'.$this->endLine;
break;
case 'iniform':
echo '<form id="'.$this->id.'" name="'.$this->name.'" class="'.$this->class.'" '.$rAct.' method="'.$this->methodform.'" action="'.$this->actionform.'">';
break;
case 'endform':
echo '</form>';
break;
case 'img':
$rAct = $this->event!=""&&$this->method!="" ? $this->actsJs():'';
echo $this->startLine.'<img id="'.$this->id.'" src="'.$this->img.'" name="'.$this->name.'" class="'.$this->class.'" '.$rAct.' '.$this->extras.' />'.$this->endLine;
break;
case 'default':
echo "Objecto no encontrado";
break;
}
$this->clear();
}
//LIMPIAMOS VARIABLES
function clear(){
unset($this->object,$this->id,$this->name,$this->value,$this->class,$this->event,$this->method,$this->extras,$this->text,$this->label,$this->object,$this->size,$this->maxlength);
}
//ELEGIMOS EL EVENTO Y LE APLICAMOS EL METODO
function actsJs(){
$this->actions = array(
'load'=>'onLoad="'.$this->method.'"',
'uload'=>'onUnload="'.$this->method.'"',
'click'=>'onClick="'.$this->method.'"',
'change'=>'onChange="'.$this->method.'"',
'submit'=>'onSubmit="'.$this->method.'"',
'reset'=>'onReset="'.$this->method.'"',
'select'=>'onSelect="'.$this->method.'"',
'blur'=>'onBlur="'.$this->method.'"',
'focus'=>'onFocus="'.$this->method.'"',
'kd'=>'onKeyDown="'.$this->method.'"',
'kp'=>'onKeyPress="'.$this->method.'"',
'ku'=>'onKeyUp="'.$this->method.'"',
'dclick'=>'ondblClick="'.$this->method.'"',
'md'=>'onMouseDown="'.$this->method.'"',
'mm'=>'onMouseMove="'.$this->method.'"',
'mo'=>'onMouseOut="'.$this->method.'"',
'mov'=>'onMouseOver="'.$this->method.'"',
'mu'=>'onMouseUp="'.$this->method.'"');
return $this->actions[$this->event];
}
//CREAMOS SELECT Y OPTIONS
function genList($values, $textos, $name, $id="", $class=""){
// $this->clear();
$this->name=$name;
$this->id=$id;
$this->class=$class;
$this->object('select');
while($value = current($values)){
$texto = current($textos);
$this->clear();
$this->value = $value;
$this->texto = $texto;
$value==$values[sizeof($values)-1] ? $this->fin=true:$this->fin=false;
$this->object('option');
next($values);
next($textos);
}
$this->clear();
}
//OTROS HTML USADOS CONSTANTE
function jsAlert($pMensaje){
echo "<script language='javascript'>alert('$pMensaje')</script>";
}
function jsRedirect($pURL){
echo "<script language='javascript'>window.location.href='$pURL'</script>";
}
function jsPopUp($pURL, $pHeight, $pWidth){
echo "<script language='javascript'>window.open('".$pURL."','','left=300,top=200,height=".$pHeight.",width=".$pWidth.",toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0');</script>";
}
function jsBack(){
echo "<script language='javascript'>history.back(-1)</script>";
}
function jsReload(){
echo "<script language='javascript'>window.reload()</script>";
}
}
?>