<?php

defined('BASEPATH') or exit('No direct script access allowed');

class Login extends CI_Controller
{
    public function index($param = true)
    {
        $this->load->view('login/vheader');
        $this->load->view('login/vlogin', array("param" => $param));
        $this->load->view('login/vfooter');
    }
    public function verify()
    {
        $user = $this->input->post('user');
        $pass = $this->input->post('pass');
        $where = array(
            "u.usua_user = '$user'",
            "u.usua_pass = '$pass'",
            "u.usua_esta_ide = 1",
            //"u.usua_ugel_ide = ug.ugel_ide"
        );
        $this->load->model("mgeneral");
        $result = $this->mgeneral->get_data("*", "usuarios u,ugel ug", $where);
        if (count($result) == 0) {
            redirect(site_url("login/index/0"));
            return;
        }
        $data = array(
            "usua_ide" => $result[0]->usua_ide,
            "usua_user" => $result[0]->usua_user,
            "usua_tipo" => $result[0]->usua_tipo_nombre,
            "usua_nombres" => $result[0]->usua_nombres,
            "usua_apellidos" => $result[0]->usua_apellidos,
            "ugel_ide" => $result[0]->usua_ugel_ide,
            "ugel_nombre" => $result[0]->ugel_nombre,
            "login" => "i5L0g1n"
        );
        $this->session->set_userdata($data);
        redirect(site_url("sistema"));
    }
}
