<?php

class Login_model extends CI_Model {

   	public function login ($username,$password)
	{

			$this->db->select("*");
			$this->db->from("users");
			$this->db->where('username',$username);
			$this->db->where('password',md5($password));
			$this->db->where('status','active');
			$admin=$this->db->get()->row();
		
		if (count($admin)) {
			// Log in user
			$data = array(
				'username' => $admin->username,
				'first_name' =>$admin->first_name,
				'last_name' =>$admin->last_name,
				'email' => $admin->email,
				'id' => $admin->id,
				'loggedin' => TRUE,
				'user_type' =>$admin->user_type
			);
			$this->session->set_userdata($data);
		}
	}

	public function logout ()
	{
		$this->session->sess_destroy();
	}

	public function loggedin ()
	{
		return (bool) $this->session->userdata('loggedin');
	}
	
	public function get_userType ()
	{
		return $this->session->userdata('user_type');
	}

}