<?php


class main_controller extends controller{

    
    function _get_loged(){
        if (!isset($_SESSION['LOGIN'])){
            $this->setCss( array("init.css", "disponibilidad.css") );
            $this->setJs( array("init.js") );
            $datax['main'] = $this->view("login", array(""),"main_menu");
            $datax['titulo']= "Login";
            $this->render($datax);
            die();
        }
    }
    
    function x_login(){
        $user = $_POST['usuario'];
        $pass = $_POST['password'];
        $ret = $this->mod->login($user, $pass);
        if ($ret){
            $_SESSION['LOGIN'] = 1;
            $_SESSION['USUARIO'] = $ret[0];
        }
        echo $ret ? "1" : "0" ;
    }
    
    function x_cambiar_clave(){
        
        $oldpass = $_POST['oldpass'];
        $newpass = $_POST['newpass'];
        $user = $_POST['user'];
        
        $ret = $this->mod->cambiar_clave($user, $oldpass, $newpass);
        
        if ($ret){
            //$_SESSION['LOGIN'] = 1;
            //$_SESSION['USUARIO'] = $ret[0];
            
        }
        
        
        
        echo $ret ? "1" : "0" ;
    }   
    
    function get_fecha(){
        $dias = array(
            "Domingo", 
            "Lunes", 
            "Martes", 
            "Miercoles", 
            "Jueves", 
            "Viernes", 
            "Sabado");
        
        $meses = array(
            "Enero",
            "Febrero",
            "Marzo",
            "Abril",
            "Mayo",
            "Junio",
            "Julio",
            "Agosto",
            "Septiembre",
            "Octubre",
            "Noviembre",
            "Diciembre"
        );
        
        $dia_semana = $dias[date("w")];
        $mes = $meses[date("n")-1];
        $fecha = $dia_semana.", ".date("d")." de ".$mes." del ".date("Y");
        return $fecha;
    }
    
    function _obtener_login(){
        $datax = array();
        return  $this->view("login", $datax);
    }
    
    function _identificar_host(){
        $ip = $_SERVER['REMOTE_ADDR'];
        //$mod = $this->load_gmodel("main_model");
        //$config = $mod->get_identifiacion($ip);
        $config['LOGIN'] = 0;
        /*
        if ($config and 0){
            $_SESSION['CONF']['PVE']=$config[0]['PVE'];
            $_SESSION['CONF']['NOM_PVE']=$config[0]['NOM'];
            $config['LOGIN'] = isset($_SESSION['USER']) ? 1 : 0;
            
            $this->_js_array['_USER'] = isset($_SESSION['USER'])?$_SESSION['USER'] : array();
            
            $this->_js_var['_LOGIN'] = $config['LOGIN'];
            
        }
        */
        $config['LOGIN'] = isset($_SESSION['USER']) ? 1 : 0;
        $this->_js_array['_USER'] = isset($_SESSION['USER'])?$_SESSION['USER'] : array();
        $this->_js_var['_LOGIN'] = $config['LOGIN'];
        
        return $config;
    }

    
    
}
?>
