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

class logout extends CI_Controller
{

   /*Function to set JSON output*/
	public function output($Return=array()){
		/*Set response header*/
		header("Access-Control-Allow-Origin: *");
		header("Content-Type: application/json; charset=UTF-8");
		/*Final JSON response*/
		exit(json_encode($Return));
	}
	
	public function __construct()
     {
          parent::__construct();
          $this->load->library('session');
          $this->load->helper('form');
          $this->load->helper('url');
          $this->load->helper('html');
          $this->load->database();
          $this->load->library('form_validation');
          //load the login model
          $this->load->model("Xin_model");
     }
	 
	// Logout from admin page
	public function index() {
	
		$cookie_name = $this->Xin_model->get_cookie_name();
		$session = $this->session->userdata($cookie_name);
		if(!empty($session)){ 
			
		} else {
			redirect('');
		}
		
		if (isset($_COOKIE[$cookie_name])) {
            unset($_COOKIE[$cookie_name]);
            setcookie($cookie_name, null, -1, "/");
        } 
		
		$last_data = array(
			'is_logged_in' => '0',
			'last_logout_date' => date('d-m-Y H:i:s')
		); 
				
		// Removing session data
		$data['title'] = '';
		$sess_array = array($cookie_name => '');
		$this->session->sess_destroy();
		$Return['result'] = 'Successfully Logout.';
		redirect('', 'refresh');
	}
} 
?>