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

class Log_model extends CI_Model{

	//Gether all location transfer information
	public function loglist($user,$startDate,$endDate,$type,$search = ''){
		$this->db
			->select('lq.createdTS,um.username,lq.type,lq.query,lq.executionTime,lq.userIP')
			->from('_log_query lq')
			->join('tbl_usermaster um','um.fldid=lq.userID','left')
			->where(array(
						'lq.createdTS >='=>$startDate,
						'lq.createdTS <='=>$endDate,
						'lq.companyID '=>element('compID', $this->session->userdata('logged_in'))
					));

		if($user != 'all'){
			$this->db->where(array('lq.userID'=>$user));			
		}
		if($type != 'all'){
			$this->db->where(array('lq.type'=>$type));			
		}
		if($search != ''){
			$this->db->like(array('lq.query'=>$search));				
		}
		
		$query = $this->db->get();
		//echo $this->db->last_query();

		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return false;
		}
	}	
}