$xHP = new cHPage("", HP_FORM);
$oficial = elusuario($iduser);
//$wonner		= $iduser;
$tabla = parametro("t", "", MQL_RAW);
// ( isset($_GET["t"]) ) ? $_GET["t"] : "";
$tabla = parametro("tabla", $tabla, MQL_RAW);
$filtro = isset($_GET["f"]) ? $_GET["f"] : "";
$comando = isset($_GET["cmd"]) ? $_GET["cmd"] : SYS_DEFAULT;
$clave = parametro("id", null, MQL_RAW);
$clave = parametro("clave", $clave, MQL_RAW);
//necesarios tabla clave
$encode = isset($_REQUEST["enc"]) ? $_REQUEST["enc"] : false;
$options = isset($_REQUEST["opts"]) ? $_REQUEST["opts"] : "";
$frm = "frm8db7028bdcdf054882ab54f644a9d36b";
$xRef = new MQL();
$xDBTip = $xRef->getTipos();
$xLng = new cLang();
if ($comando == SYS_DEFAULT) {
    echo $xHP->getHeader(true);
    echo $xHP->setBodyinit("initComponents()");
    $jsVars = "";
    $location = "{$frm}.php?t={$tabla}&f={$filtro}&enc={$encode}&cmd={$comando}";
    $xTxt = new cHText();
    $xBtn = new cHButton();
    $original = "";
    if ($tabla != "" and ($filtro != "" or $clave != null)) {
        $xFRM = new cHForm($frm, $location, $frm, SYS_GET);
        //$DFiltro	= explode("=", $filtro);
        $conTitulo = false;
        $xData = new cSAFETabla($tabla);
        $mObj = $xData->obj();
 function __construct($tabla, $datos, $primaryKey)
 {
     $this->mDatos = $datos;
     $this->mTabla = $tabla;
     $mql = new MQL($tabla, $datos);
     $this->mEquivalencias = $mql->getTipos();
     $this->mPrimaryKey = $primaryKey;
 }
 /**
  * Funcion que crea o actualiza una tabla en el sistema
  * @param $NTable	Nombre de la Tabla la cual desea trabajar
  * @param $TCond	Tipo de Operacion 0 = nueva Estructura, 1 = Actaulizacion de la estructura
  * @return	null
  **/
 function setStructureTableByDemand($TCond = 0, $options = array())
 {
     $xMQ = new MQL();
     $EQUIV = $xMQ->getTipos();
     //$TCond 1 = Actualizar, 0 = Nuevo
     $NTable = $this->mTable;
     /**$NTable,
      * Crea la Estructura de una Tabla Determinada
      */
     $msg = "";
     //Elimna los registros anteriores
     $sql_d_reg = "DELETE FROM general_structure WHERE tabla='{$NTable}'";
     if ($TCond == "1") {
     } else {
         my_query($sql_d_reg);
     }
     //ahora a grabar
     $sql_fields = "SHOW FIELDS IN {$NTable}";
     $rs_fields = mysql_query($sql_fields, cnnGeneral());
     $i = 0;
     $goKey = false;
     while ($rowf = mysql_fetch_array($rs_fields)) {
         $valor = $rowf[4];
         $titulo = ucfirst(str_replace("_", " ", $rowf[0]));
         $ctrl = "text";
         //$hay_div = strpos($rowf[1], "(");
         $atype = explode(" ", $rowf[1]);
         $atype = $atype[0];
         $atype = str_replace(")", "", $atype);
         $atype = str_replace("(", "@", $atype);
         $iType = explode("@", $atype);
         $field_type = isset($iType[0]) ? $iType[0] : "varchar";
         $field_long = isset($iType[1]) ? $iType[1] : 0;
         if (!$field_long) {
             $field_long = 0;
         }
         switch ($field_type) {
             case "enum":
                 $valor = str_replace(",", "", $field_long);
                 $valor = str_replace("''", "'", $valor);
                 $valor = str_replace("'", "|", $valor);
                 $field_long = 0;
                 $ctrl = "select";
                 break;
             default:
                 //pocsionamiento de float enteros+fracciones + divisor
                 if (strpos($field_long, ",") > 0) {
                     $field_long = explode(",", $field_long);
                     $field_long = $field_long[0] + $field_long[0] + 1;
                 }
                 break;
         }
         //si el key es si
         if ($rowf[3] == "PRI" and $goKey == false) {
             $valor = "primary_key";
             $goKey = true;
         }
         //if( $EQUIV[strtoupper($field_type)] == MQL_INT||$EQUIV[strtoupper($field_type)] == MQL_FLOAT) { $ctrl = "number"; }
         if ($field_long > 75) {
             $ctrl = "textarea";
         }
         $sql_i_v = "'{$NTable}','{$rowf['0']}', '{$valor}', '{$field_type}', {$field_long}, '{$titulo}', '{$ctrl}', {$i}";
         $sql_i_d = "INSERT INTO general_structure(tabla, campo,valor,tipo,longitud,titulo,control, order_index) VALUES ({$sql_i_v})";
         //
         //
         if ($TCond == "1") {
             //, control='$ctrl'
             $siHay = mifila("SELECT COUNT(valor) AS 'idcnt' FROM general_structure WHERE tabla='{$NTable}' AND campo='{$rowf['0']}'", "idcnt");
             if ($siHay > 0) {
                 //
                 $upTitulo = isset($options["actualizar_titulo"]) ? ", titulo='{$titulo}' " : "";
                 $upOrden = "";
                 $sql_i_ = "UPDATE general_structure\n\t    \t\t\t\t\t\t\t\t\tSET valor='{$valor}', tipo='{$field_type}', longitud={$field_long}\n\t    \t\t\t\t\t\t\t\t\t{$upTitulo} {$upOrden}\n\t    \t\t\t\t\t\t\t\t\tWHERE tabla='{$NTable}' AND campo='{$rowf['0']}' ";
                 $msg .= "{$NTable}\t{$rowf['0']}\tACTUALIZAR\tAgregando Campo Tipo {$field_type}, con Valor {$valor} y tamano {$field_long}\r\n";
             } else {
                 $sql_i_v = "'{$NTable}','{$rowf['0']}', '{$valor}', '{$field_type}', {$field_long}, '{$titulo}', '{$ctrl}', {$i}";
                 $sql_i_ = "INSERT INTO general_structure(tabla, campo,valor,tipo,longitud,titulo,control, order_index) VALUES ({$sql_i_v})";
                 $msg .= "{$NTable}\t{$rowf['0']}\tNUEVO\tAgregando Campo Tipo {$field_type}, con Valor {$valor} y tamano {$field_long}\r\n";
             }
             my_query($sql_i_);
         } else {
             my_query($sql_i_d);
             $msg .= "{$NTable}\t{$rowf['0']}\tNUEVO\tAgregando Campo Tipo {$field_type}, con Valor {$valor} y tamano {$field_long}\r\n";
         }
         //
         //
         //echo "<p class='aviso'>$sql_i_d</p>";
         $i++;
     }
     @mysql_free_result($rs_fields);
     return $msg;
 }