$_SESSION["grid"]->SetDatabaseConnection(MY_DB_IN, USR_DB, PWD_DB);
//Propiedades del GRID
$mGridTitulo = "Creditos.- Propiedades Contables";
$mGridKeyField = "idcreditos_tipoconvenio";
//Nombre del Campo Unico
$mGridKeyEdit = false;
//Es editable el Campo
$mGridTable = "creditos_tipoconvenio";
//Nombre de la tabla
$mGridSQL = "idcreditos_tipoconvenio, descripcion_tipoconvenio, capital_vencido_renovado, capital_vencido_reestructurado, capital_vencido_normal, capital_vigente_renovado, capital_vigente_reestructurado, capital_vigente_normal, interes_vencido_renovado, interes_vencido_reestructurado, interes_vencido_normal, interes_vigente_renovado, interes_vigente_reestructurado, interes_vigente_normal, interes_cobrado, moratorio_cobrado";
$mGridWhere = "";
//layout: [Campo] => Titulo, Editable, Tamaño
$mGridProp = array();
//Obtiene el Grid de la Tabla de general_description
if ($mGridTable != "") {
    $xTs = new cTableStructure($mGridTable);
    $xAF = explode(",", $mGridSQL);
    foreach ($xAF as $key => $value) {
        $DField = $xTs->getInfoField(trim($value));
        $mGridProp[$DField["campo"]] = $DField["titulo"] . ",true," . $DField["longitud"];
    }
    unset($xAF, $key, $value);
}
//===========================================================================================================
$_SESSION["grid"]->SetSqlSelect($mGridSQL, $mGridTable, $mGridWhere);
$_SESSION["grid"]->SetUniqueDatabaseColumn($mGridKeyField, $mGridKeyEdit);
$_SESSION["grid"]->SetTitleName($mGridTitulo);
$_SESSION["grid"]->SetEditModeAdd(false);
$_SESSION["grid"]->SetDatabaseColumnEditable("descripcion_tipoconvenio", false);
$_SESSION["grid"]->SetDatabaseColumnName("descripcion_tipoconvenio", "Tipo de Convenio");
//interes_vencido_renovado, interes_vencido_reestructurado, interes_vencido_normal, interes_vigente_renovado, interes_vigente_reestructurado, interes_vigente_normal
/**
 * 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($NTable, $TCond = 0, $options = array())
{
    //$TCond 1 = Actualizar, 0 = Nuevo
    /**
     * Crea la Estructura de una Tabla Determinada
     */
    $msg = "";
    $xSt = new cTableStructure($NTable);
    $msg = $xSt->setStructureTableByDemand($TCond, $options);
    return $msg;
}
$theFile = __FILE__;
$permiso = getSIPAKALPermissions($theFile);
if ($permiso === false) {
    header("location:../404.php?i=999");
}
$_SESSION["current_file"] = addslashes($theFile);
//<=====	FIN_H
$iduser = $_SESSION["log_id"];
//=====================================================================================================
$xHP = new cHPage("TR.Editar estructura", HP_FORM);
$oficial = elusuario($iduser);
$table = parametro("ctable", false, MQL_RAW);
$actualizar = parametro("forzar", false, MQL_BOOL);
if ($actualizar == true) {
    $table = strtolower($table);
    $xUtil = new cTableStructure($table);
    $command = $xUtil->getNumeroDeCampos() > 0 ? SYS_CERO : SYS_UNO;
    $xUtil->setStructureTableByDemand($command);
    //0 update
}
if ($table == false) {
    $xHP->init();
    $xFRM = new cHForm("frmeditstructure", "frm_edit_structure.php");
    $xBtn = new cHButton();
    $xTxt = new cHText();
    $xDate = new cHDate();
    $xChk = new cHCheckBox();
    //$xSel		= new cHSelect();
    $xFRM->setTitle("TR.Editar Estructura del Sistema");
    $xSel = new cSelect("ctable", "ctable", "SHOW TABLES IN " . MY_DB_IN);
    $xSel->setEsSql();
$_SESSION["grid"]->SetDatabaseConnection(MY_DB_IN, USR_DB, PWD_DB);
//Propiedades del GRID
$mGridTitulo = "Cajas Locales";
$mGridKeyField = "idsocios_cajalocal";
//Nombre del Campo Unico
$mGridKeyEdit = true;
//Es editable el Campo
$mGridTable = "socios_cajalocal";
//Nombre de la tabla
$mGridSQL = "*";
$mGridWhere = "";
//layout: [Campo] => Titulo, Editable, Tamaño
$mGridProp = array();
//Obtiene el Grid de la Tabla de general_description
if ($mGridTable != "") {
    $xTs = new cTableStructure($mGridTable);
    $mGridSQL = $xTs->getCampos_InText();
    $xAF = explode(",", $mGridSQL);
    foreach ($xAF as $key => $value) {
        $DField = $xTs->getInfoField(trim($value));
        $mGridProp[$DField["campo"]] = $DField["titulo"] . STD_LITERAL_DIVISOR . "true" . STD_LITERAL_DIVISOR . $DField["longitud"];
    }
    unset($xAF, $key, $value);
}
$xT = new cTipos();
//===========================================================================================================
$_SESSION["grid"]->SetSqlSelect($mGridSQL, $mGridTable, $mGridWhere);
$_SESSION["grid"]->SetUniqueDatabaseColumn($mGridKeyField, $mGridKeyEdit);
$_SESSION["grid"]->SetTitleName($mGridTitulo);
//===========================================================================================================
foreach ($mGridProp as $mCampo => $mProps) {
 function compileFromSQL($sql)
 {
     $arrWithTilde = array("varchar" => "varchar", "date" => "date", "text" => "text", "tinytext" => "tinytext", "enum" => "enum", "blob" => "blob", "string" => "string", "longtext" => "longtext", "datetime" => "datetime", "time" => "time");
     $arrTypesPHP = array("enum" => "string", "varchar" => "string", "tinytext" => "string", "float" => "float", "decimal" => "float", "int" => "integer", "integer" => "integer", "text" => "string", "longtext" => "string", "blob" => "string", "tinyint" => "integer", "datetime" => "string", "date" => "string", "time" => "string");
     $arrTypesNum = array("float" => "float", "decimal" => "float", "int" => "integer", "integer" => "integer", "tinyint" => "integer");
     //$IniMvtos		= strpos($texto_contrato, "---");
     $this->addCSS("../css/xml.css", "print");
     $this->addCSS("../css/xml.css", "screen");
     $this->getCampos($sql);
     //obtener info del field
     foreach ($this->mAFieldN as $clave => $valor) {
         //propiedades extras
         $mNumFormat = "";
         $mAlin = "ALIGN='CENTER'";
         $xTInfo = new cTableStructure($this->mAFieldD[$clave]);
         $IField = $xTInfo->getInfoField($valor);
         $FTipo = strtolower(trim($IField["tipo"]));
         $FNombre = $IField["campo"];
         if ($arrTypesPHP[$FTipo] == "float") {
             $mNumFormat = "NUMBERFORMATEX='2'";
         }
         if (isset($arrTypesNum[$FTipo])) {
             $mAlin = "ALIGN='LEFT'";
         }
         /**/
         $this->mAGrpField[] = "<COL  TYPE='FIELD' {$mAlin}  CELLCLASS='FIELDS' {$mNumFormat} >" . $this->mAFieldT[$clave] . "</COL>\r\n";
         $this->mAGrpTit[] = "<COL ALIGN='CENTER'  CELLCLASS='GROUP_HEADER' >" . strtoupper($this->mAFieldT[$clave]) . "</COL>\r\n";
     }
 }