<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Logout extends MY_Controller{
	public function index(){
		$this->load->model("login_model");
		
		if($this->record_login && $this->session->userdata('login_id') != ""){
			$login_data['DATE_LOGOUT'] = date("Y-m-d H:i:s");
			
			$this->login_model->sql_update($login_data, $this->session->userdata('login_id'));
		}
		
		$prev_page = $this->session->flashdata('prev_page');
		
		$this->session->sess_destroy();
		
		if($this->input->get('by_user') != "1"){
			$this->session->sess_create();
			$this->session->set_flashdata('page_after_login', $prev_page);
		}
		
		redirect(base_url());
	}
}