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

class Home extends MX_Controller 
{
	public function __construct() 
	{
		parent::__construct();
		$this->load->helper('cookie');
	}
	
	public function index ()
	{
            
		$admin_info = $this->session->userdata('adminInfo');
		if ($admin_info)
		{
			$this->load->view('index');
		}else
		{
			$this->load->view ( 'login');
		}
	}
	
	public function login()
	{
           
		$username = $this->input->post('user_admin');
		$password = $this->input->post('password');
		
		$this->load->model(array('admin_model'));
		$data = $this->admin_model->check_login($username, $password);
		if ($data == null)
		{
			$this->session->set_flashdata('login_error', TRUE);
			redirect("/admin/home");
		}
		else
		{
			$admindata = array('user_admin' => $username, "logined_in" => TRUE);
			$this->session->set_userdata('adminInfo', $admindata);
			redirect("/admin/home");
		}
	}
	
	public function logout()
	{
		$this->session->sess_destroy();
		redirect("/admin/home");
	}
	
	public function user_profile()
	{
		$admin_info = $this->session->userdata('adminInfo');
		if($admin_info)
		{
			$this->load->view('user_profile');
		}else
		{
			redirect("/admin/home");
		}
	}
}