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

class Logout extends MY_Controller {

	public function index()
	{
		if($this->session->userdata('user_type')) {
			$this->db->trans_start();
			$this->load->model('user_model');
			$this->user_model->insert_user_log($this->session->userdata('user_id'), LOG_LOGOUT);
			$this->db->trans_complete();
			
			if ($this->db->trans_status() === TRUE) {
				$this->session->unset_userdata(array('user_id' => '', 'user_name' => '', 'username' => '', 'user_login_datetime' => '', 'user_type' => ''));
				
				redirect('login/', 'refresh');
			}
			else {
				redirect('error/', 'refresh');
			}
		}
		else {
			redirect('login/', 'refresh');
		}	
	}
}

/* End of file logout.php */
/* Location: ./application/controllers/logout.php */