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

class Login extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('Model_login', 'ML');
	} 

	public function index()
	{
		$this->load->view('view_login');
	}

	public function logout()
	{
		$this->session->unset_userdata('name');
		$this->load->view('view_login');
	}

	public function userAuth()
	{
		
		 $arr['name'] = $this->input->post('user_name');
		 $arr['password'] = MD5($this->input->post('password'));
		 $this->form_validation->set_rules('user_name','User_name','required');
		 $this->form_validation->set_rules('password','User_password','required');
		//$url = h''
		//redirect('http:///infection');
		if($this->form_validation->run()){

			$check = $this->ML->user_auth($arr);
			if($check)
			{	
				$this->session->set_userdata('name',$arr['name']);
				
				log_message("debug","SESSION VALUE :: ".$this->session->userdata('name'));
				//echo base_url().'landing_page';
				//redirect('Dashboard');
				redirect('landing_page');
			}
			else
			{
				redirect('login');
			}
		}

	}

	public function landingPage(){

		log_message("debug","LANDING SESSION VALUE :: ".$this->session->userdata('name'));
		if($this->session->userdata('name')){

			$this->load->view('main_header');
			$this->load->view('sidebar');
			$this->load->view('infection_dashboard');
			$this->load->view('footer');
		} else {
			redirect('login');
		}

	}

}