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

class Login extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model('My_model');
	}

	public function index()
	{
		$data['err_msg'] = '';
		// redirect('signin', 'refresh');
		if($_POST){
			$username = $this->input->post('username', true);
			$password = $this->input->post('password', true);

		
			$res = $this->My_model->get_row('admins',array('username'=>$username, 'password'=>$password));
			// echo $this->db->last_query();
			if($res){
				$this->session->set_userdata('user_id',$res->admin_id);
				$this->session->set_userdata('logged_in',$res->username);
				$this->session->set_userdata('type',$res->type);
				
				if($res->type==1){
					redirect('manage_claim_dst','refresh');
				}else if($res->type==2){
					redirect('claim_report_icam','refresh');
				}else{
					redirect('claim_report_fa','refresh');
				}
				
			}else{
				$data['err_msg'] = "Invalid username or password.";
			}
		}

		$this->load->view('view_login',$data);
	}
}
