<?php

Class User extends CI_Controller
{

	function __construct()
	{
		parent::__construct();
		$this->load->library('session');
		$this->load->helpers('url');
		$this->load->model('users');
		$this->load->model('offices');
		/*if( $this->session->userdata('type') == "" )
		{
			$this->session->set_flashdata('error_msg','Not Login Yet');
			redirect('user/index');
		}*/
	}

	function index()
	{
		$this->load->view('common/login');
	}

	function check_login()
	{
		
		$user_email = $this->input->post('user_email');
		$user_pass = $this->input->post('user_pass');
		$logintype = $this->offices->get_user_login($user_email,$user_pass);
		
		$this->session->set_userdata('admin_name', $logintype);
		if($logintype=="admin") {
			
			redirect('user/dashboard');
			
		}
		if($logintype=="office") {
			redirect('lwd');
		}
		if($logintype=="wronguser") {
			
			$this->session->set_flashdata('error_msg', 'Login Fail');
			redirect('user/index');
		}
		
	}

	function dashboard()
	{
		if( $this->session->has_userdata('login_id') != 1 )
		{
			$this->session->set_flashdata('error_msg', 'Not Login Yet');
			redirect('user/index');
		}
		else
		{
			$data['costcenter'] = $this->users->count_cost_center();
			$data['contractarea'] = $this->users->count_contract_area();
			$data['office'] = $this->users->count_office();
			$data['lwd'] = $this->users->count_lwd();
			$this->load->view('common/dashboard', $data);
		}
	}

	function logout()
	{
		$this->session->unset_userdata('login_id');
		$this->session->unset_userdata('office_id');
		$this->session->unset_userdata('contractarea_id');
		$this->session->unset_userdata('type');
		$this->session->set_flashdata('error_msg', 'Logout Successful');
		redirect('user/index');
	}

	function cost_center()
	{
		$this->load->view('cost_center');
	}
	function contract_area()
	{
		$this->load->view('contract_area');
	}
	function lwd()
	{
		$this->load->view('lwd');
	} 
	function office()
	{
		$this->load->view('office');
	}
	
	function lwd_list()
	{
		$this->load->view('lwd_list');
	}

	function lwd_profile()
	{
		$this->load->view('lwd_profile');
	}
}