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

class Logreport extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('Useraccess');
		$query = $this->Useraccess->useraccess_id_module2('5', 'reports');
		if(!$query){
			echo '<script>alert("Not authorised..");
				window.location.replace("'.base_url().'Error");
				</script>';
		}
		$this->load->library('layouts');
		$this->load->model('menu');
	}

	//database transaction report
	public function index($user = '',$startDate = '',$endDate = '',$type = '',$search = ''){
		$this->lang->load('logreport',$this->session->userdata('language'));
		
		//gather current company users
		$this->load->model('Usermaster');
		$data["users"] = $this->Usermaster->userByCompany();
	
		//retrive start & end date.
		if($startDate == '') 	$startDate = date('Y-m-d', strtotime(date('Y-m-1')));
		if($endDate == '') 		$endDate = date('Y-m-d', time());
		$data['dateFrom'] 	= 	$startDate;
		$data['dateTo'] 	= 	$endDate;

		$user = !empty($user)?$user:'All';
		$type = !empty($type)?$type:'All';

		//Pre data
		$data['search'] = !empty($search)?$search:'';
		$data['user'] = $user;
		$data['type'] = $type;

		$this->load->model("logreport/Log_model");
		$data['datatbls'] = $this->Log_model->loglist($user,date('Y-m-d', strtotime($startDate)),date('Y-m-d', strtotime($endDate)),$type,$search);
		
		if(!empty($data['datatbls'])) foreach($data['datatbls'] as &$v){ $v->query = substr($v->query,0,40); }
		//Configuration for table header
		$data['tbHdr'] = array(
				'createdTS' => 'createdTS',
				'username' => 'username',
				'type' => 'type',
				'query' => 'query',
				'executionTime' => 'executionTime',
				'userIP' => 'userIP'
			);
		//print_r($data);
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('logreport/loglist', array('latest' => 'sidebar/latest'), $data);
	}
}


/* End of file logreport.php */
/* Location: ./application/controller/logreport.php */