<?php
date_default_timezone_set('America/Mexico_City');
class baseDeDatosIndex{
    public function filtro_str_mysql($str){//,"'","#","VALUES","UPDATE",
        /*"SELECT","FROM","WHERE","ORDER",
                "INSERT","INTO",
                "SET","PASSWORD","FLUSH","DELETE",
                "ALTER","TABLE","LOAD","CREATE",
                "SHOW","USE","DATABASE","TRIGGER",
                "EVENT","LOCK","ROUTINE","VIEW",
                "DROP","EXECUTE","REFERENCES"*/
        $val = array(

        );//,"\""
        foreach($val as &$valor){
            if(preg_match("/".strtoupper($valor)."\b/",strtoupper($str))) die();
        }
        return $str;
    }
    public function filtro_str($str){
        if(($str == "") || ($str == '') || ($str == NULL)) die();
        $this->filtro_str_mysql($str);
        $str = strip_tags($str);
        //$txt = htmlentities($txt, ENT_NOQUOTES);
        //$txt = strtoupper($txt);
        //$txt = strtolower($txt);
        //$txt = urlencode($txt);
        $str = preg_replace("/#/", "", $str);
        $str = preg_replace("/'/", "", $str);
        $str = preg_replace("/\"/", "", $str);
        //$txt = htmlspecialchars($txt);
        //$str = htmlentities($str);
        return $str;
    }
    public function connectDBBDD(){
        $servername = "localhost";
        $username = "root";
        $password = "PkJXPQFykKLmS3cWhqmZKNYE";
        $dbname =   "PPD";
        $conn = new mysqli($servername, $username, $password, $dbname);
        $conn->set_charset("utf8");
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }
        return $conn;
    }
    public function definesgnl(){
        $conn = $this->connectDBBDD();
        $res = mysqli_query($conn,"SELECT NAME,VALU FROM tbl_sistema_defines");
        if(mysqli_num_rows($res) > 0){
            while($row = mysqli_fetch_assoc($res)){
                define($row["NAME"],$row["VALU"]);
            }
        }else{
            define(SYS_ADMIN_PLANTILLA,1);
        }
        return 1;
    }
    public function guardarreg(){
        //date_default_timezone_set('UTC');
        date_default_timezone_set('America/Mexico_City');
        $conn = $this->connectDBBDD();
        $v2 = $_SERVER["REMOTE_ADDR"];
        $v3 = date("Y")."-".date("m")."-".date("d")." ".date("H").":".date("i").":".date("s");
        //$v4 = time();
        $v4 = strtotime(date("Y")."/".date("m")."/".date("d"));
        $v5 = $this->filtro_str_mysql($this->filtro_str($_SERVER["HTTP_USER_AGENT"]));
        $v6 = $this->filtro_str_mysql($this->filtro_str($_SERVER["REQUEST_URI"]));
        $res = mysqli_query($conn,"INSERT INTO tbl_registro_general VALUES (null,'".$v2."','".$v3."','".$v4."','".$v5."','".$v6."');");
        $conn->close();
    }
}
//define(SYS_ADMIN_PLANTILLA,1);
//echo "<pre>";print_r($_POST);print_r($_FILES);echo "<pre>";die();
$baseDeDatosIndex = new baseDeDatosIndex();
$baseDeDatosIndex -> guardarreg();
$baseDeDatosIndex -> definesgnl();
// change the following paths if necessary
$yii=dirname(__FILE__).'/yii-master/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

// remove the following lines when in production mode
//defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
//defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

require_once($yii);
Yii::createWebApplication($config)->run();