<?php
/*
* @category    Clase Manejo Base Datos
* @package     Nube Apps - Planificador
* @author      Jorge Ancizar Galeano Ruiz<desarrollo@nubeapps.com.co>
* @copyright   2010 Jorge Ancizar Galeano Ruiz
* @version     Planificador Ver 1.0
* @license     COMERCIAL
* @link        http://www.nubeapps.com.co
* @country     Colombia
* @telephone   3168345866
*/
set_time_limit(900);
class baseDatos{
    //******************************************************************************************************
    //ATRIBUTOS
    //******************************************************************************************************
    public $Servidor;
    public $Puerto;
    public $DSN;
    public $BaseDatos;
    public $Usuario;
    public $Contrasena;
    public $ConexionID = 0;
    public $QryID = 0;
    public $QryErrNro = 0;
    public $QryErrDes = "";
    public $esValido = false;
    public $CamposValoraMedica = "NA";

    function  __construct($lBD="medicare_oficlinic", $lServidor="198.136.48.90", $lUsario="medicare_app", $lPass="AncizarGaleano2012+@")
    //function  __construct($lBD="eoficlin_dor_medicare", $lServidor="localhost", $lUsario="root", $lPass="admin")
    {
        $this->Servidor = $lServidor;
        $this->Usuario = $lUsario;
        $this->Contrasena = $lPass;
        $this->BaseDatos = $lBD;
    }
    function conectar(){
        $this->ConexionID = @new mysqli($this->Servidor,$this->Usuario, $this->Contrasena, $this->BaseDatos);
        if (mysqli_connect_errno())
        {
            printf("La Conexion Fallo.....: %s\n", mysqli_connect_error());
        exit();
        }
    }
    function cerrar(){
        @mysqli_close($this->ConexionID);
    }
    function ejecutar(){
        @mysqli_query($this->ConexionID, $query);
    }
    function liberar(){
        @mysqli_free_result($this->QryID);
    }
    function getArray($qry){
        $query = stripslashes($qry);
        $cadena = "";
        if ($this->QryID = @mysqli_query($this->ConexionID, $query))
        {
            $arr = array();
            $registros = 0;
            while($obj = @mysqli_fetch_assoc($this->QryID))
            {
                $nRow = $obj;
                foreach($obj as $key => $val)
                {
                    //$cadena .=  utf8_decode(str_replace("\n\n", "\n",preg_replace('/\<br(\s*)?\/?\>/i', "\n",$val))) . "^";
                    $cadena .=  str_replace("\n\n", "\n",preg_replace('/\<br(\s*)?\/?\>/i', "\n",AcentosHTML($val))) . "^";
                    
                }
                $registros ++;
            }
            if($registros > 0){
                echo $cadena;
            }else{
                return '{success:false}';
            }
        }
    }
    function nroRegistros(){
        return @mysqli_num_rows($this->QryID);
    }
    function jasonSP_array($qry){
        $query = stripslashes($qry);
        $cadena = "";
        if ($this->QryID = @mysqli_query($this->ConexionID, $query)){
            $arr = array();
            $registros = 0;
            while($obj = @mysqli_fetch_assoc($this->QryID)){
                $nRow = $obj;
                foreach($obj as $key => $val){
                    $cadena .=  utf8_decode(str_replace("\n\n", "\n",preg_replace('/\<br(\s*)?\/?\>/i', "\n",$val))) . "^";
                }
                $registros ++;
            }
            if($registros > 0){
                return $cadena;
            }else{
                return '{success:false}';
            }
        }
    }
}

function AcentosHTML($Texto){
    $txt = $Texto;
    $result = preg_replace('/&#96;/',"`",$txt);
    $result1 = preg_replace('/&#123;/',"{",$result);
    $result = preg_replace('/&#124;/',"|",$result1);
    $result1 = preg_replace('/&#125;/',"}",$result);
    $result = preg_replace('/&#161;/',"¡",$result1);
    $result1 = preg_replace('/&#162;/',"¢",$result);
    $result = preg_replace('/&#163;/',"£",$result1);
    $result1 = preg_replace('/&#164;/',"¤",$result);
    $result = preg_replace('/&#165;/',"¥",$result1);
    $result1 = preg_replace('/&#166;/',"¦",$result);
    $result = preg_replace('/&#167;/',"§",$result1);
    $result1 = preg_replace('/&#168;/',"¨",$result);
    $result = preg_replace('/&#169;/',"©",$result1);
    $result1 = preg_replace('/&#170;/',"ª",$result);
    $result = preg_replace('/&#171;/',"«",$result1);
    $result1 = preg_replace('/&#173;/',"­",$result);
    $result = preg_replace('/&#174;/',"®",$result1);
    $result1 = preg_replace('/&#175;/',"¯",$result);
    $result = preg_replace('/&#176;/',"°",$result1);
    $result1 = preg_replace('/&#177;/',"±",$result);
    $result = preg_replace('/&#178;/',"²",$result1);
    $result1 = preg_replace('/&#179;/',"³",$result);
    $result = preg_replace('/&#180;/',"´",$result1);
    $result1 = preg_replace('/&#181;/',"µ",$result);
    $result = preg_replace('/&#182;/',"¶",$result1);
    $result1 = preg_replace('/&#183;/',"·",$result);
    $result = preg_replace('/&#184;/',"¸",$result1);
    $result1 = preg_replace('/&#185;/',"¹",$result);
    $result = preg_replace('/&#186;/',"º",$result1);
    $result1 = preg_replace('/&#187;/',"»",$result);
    $result = preg_replace('/&#188;/',"¼",$result1);
    $result1 = preg_replace('/&#189;/',"½",$result);
    $result = preg_replace('/&#190;/',"¾",$result1);
    $result1 = preg_replace('/&#191;/',"¿",$result);
    $result = preg_replace('/&#192;/',"À",$result1);
    $result1 = preg_replace('/&#193;/',"Á",$result);
    $result = preg_replace('/&#194;/',"Â",$result1);
    $result1 = preg_replace('/&#195;/',"Ã",$result);
    $result = preg_replace('/&#196;/',"Ä",$result1);
    $result1 = preg_replace('/&#197;/',"Å",$result);
    $result = preg_replace('/&#198;/',"Æ",$result1);
    $result1 = preg_replace('/&#199;/',"Ç",$result);
    $result = preg_replace('/&#200;/',"È",$result1);
    $result1 = preg_replace('/&#201;/',"É",$result);
    $result = preg_replace('/&#202;/',"Ê",$result1);
    $result1 = preg_replace('/&#203;/',"Ë",$result);
    $result = preg_replace('/&#204;/',"Ì",$result1);
    $result1 = preg_replace('/&#205;/',"Í",$result);
    $result = preg_replace('/&#206;/',"Î",$result1);
    $result1 = preg_replace('/&#207;/',"Ï",$result);
    $result = preg_replace('/&#208;/',"Ð",$result1);
    $result1 = preg_replace('/&#209;/',"Ñ",$result);
    $result = preg_replace('/&#210;/',"Ò",$result1);
    $result1 = preg_replace('/&#211;/',"Ó",$result);
    $result = preg_replace('/&#212;/',"Ô",$result1);
    $result1 = preg_replace('/&#213;/',"Õ",$result);
    $result = preg_replace('/&#214;/',"Ö",$result1);
    $result1 = preg_replace('/&#215;/',"×",$result);
    $result = preg_replace('/&#216;/',"Ø",$result1);
    $result1 = preg_replace('/&#217;/',"Ù",$result);
    $result = preg_replace('/&#218;/',"Ú",$result1);
    $result1 = preg_replace('/&#219;/',"Û",$result);
    $result = preg_replace('/&#220;/',"Ü",$result1);
    $result1 = preg_replace('/&#221;/',"Ý",$result);
    $result = preg_replace('/&#222;/',"Þ",$result1);
    $result1 = preg_replace('/&#223;/',"ß",$result);
    $result = preg_replace('/&#224;/',"à",$result1);
    $result1 = preg_replace('/&#225;/',"á",$result);
    $result = preg_replace('/&#226;/',"â",$result1);
    $result1 = preg_replace('/&#227;/',"ã",$result);
    $result = preg_replace('/&#228;/',"ä",$result1);
    $result1 = preg_replace('/&#229;/',"å",$result);
    $result = preg_replace('/&#230;/',"æ",$result1);
    $result1 = preg_replace('/&#231;/',"ç",$result);
    $result = preg_replace('/&#232;/',"è",$result1);
    $result1 = preg_replace('/&#233;/',"é",$result);
    $result = preg_replace('/&#234;/',"ê",$result1);
    $result1 = preg_replace('/&#235;/',"ë",$result);
    $result = preg_replace('/&#236;/',"ì",$result1);
    $result1 = preg_replace('/&#237;/',"í",$result);
    $result = preg_replace('/&#238;/',"î",$result1);
    $result1 = preg_replace('/&#239;/',"ï",$result);
    $result = preg_replace('/&#240;/',"ð",$result1);
    $result1 = preg_replace('/&#241;/',"ñ",$result);
    $result = preg_replace('/&#242;/',"ò",$result1);
    $result1 = preg_replace('/&#243;/',"ó",$result);
    $result = preg_replace('/&#244;/',"ô",$result1);
    $result1 = preg_replace('/&#245;/',"õ",$result);
    $result = preg_replace('/&#246;/',"ö",$result1);
    $result1 = preg_replace('/&#247;/',"÷",$result);
    $result = preg_replace('/&#248;/',"ø",$result1);
    $result1 = preg_replace('/&#249;/',"ù",$result);
    $result = preg_replace('/&#250;/',"ú",$result1);
    $result1 = preg_replace('/&#251;/',"û",$result);
    $result = preg_replace('/&#252;/',"ü",$result1);
    $result1 = preg_replace('/&#253;/',"ý",$result);
    $result = preg_replace('/&#254;/',"þ",$result1);
    $result1 = preg_replace('/&#255;/',"ÿ",$result);
    $result = preg_replace('/&#338;/',"Œ",$result1);
    $result1 = preg_replace('/&#339;/',"œ",$result);
    $result = preg_replace('/&#352;/',"Š",$result1);
    $result1 = preg_replace('/&#353;/',"š",$result);
    $result = preg_replace('/&#376;/',"Ÿ",$result1);
    $result1 = preg_replace('/&#402;/',"ƒ",$result);
    $result = preg_replace('/&#8212;/',"—",$result1);
    $result1 = preg_replace('/&#8216;/',"‘",$result);
    $result = preg_replace('/&#8217;/',"’",$result1);
    $result1 = preg_replace('/&#8218;/',"‚",$result);
    $result = preg_replace('/&#8220;/',"“",$result1);
    $result1 = preg_replace('/&#8221;/',"”",$result);
    $result = preg_replace('/&#8222;/',"„",$result1);
    $result1 = preg_replace('/&#8224;/',"†",$result);
    $result = preg_replace('/&#8225;/',"‡",$result1);
    $result1 = preg_replace('/&#8226;/',"•",$result);
    $result = preg_replace('/&#8230;/',"…",$result1);
    $result1 = preg_replace('/&#8240;/',"‰",$result);
    $result = preg_replace('/&#8364;/',"€",$result1);
    $result1 = preg_replace('/&#8482;/',"™",$result);
    return $result1;
}

?>