<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class home extends MY_Controller{
	function __construct(){
        parent::__construct();
        $this->load->model('home_model', '', TRUE);
        // if($this->data['userid']!=''){
        //     redirect($this->data['base_url'] . 'dashbord');   
        //     exit;
        // }
    }
    function index(){
        $this->data['message'] = $this->session->flashdata('message');
        $this->breadcrumb->add('Dashboard', $this->data['base_url']);
        $this->data['breadcrumb'] = $this->breadcrumb->output();
        $this->smarty->assign('data', $this->data);
        $this->smarty->view('login.tpl');
    } 
    function login(){
       if($this->input->post()){  
            $username = $this->input->post('username');
            $password = $this->input->post('password');
            $auth_exists = $this->home_model->check_auth($username,$password);

            if($auth_exists['logged_in'] == TRUE){
                $this->session->set_userdata('userid', $auth_exists['id']);
                $time=time();
                $this->session->set_userdata('timeout',$time);
                redirect($this->data['base_url'] . 'dashbord/');  
            }else{
                $this->session->set_flashdata('message',$auth_exists['msg']);
                redirect($this->data['base_url'] . 'home/');
                exit;
            }
        }elseif($this->session->userdata('userid') !=''){
            redirect($this->data['base_url'] . 'dashbord/');
            exit;
        }
        else{
            redirect($this->data['base_url'] . 'home/');
            exit;
        }

        
    }
    
}
