<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mod_chat extends CI_Model{
	
	var $table = "messages";
	function __construct()
	{
		parent::__construct();	
	}	
	
	function getMsg()
	{
		$this->db->SELECT('*');
		$this->db->from("messages");
		$this->db->where('date',date('Y-m-d'));
		//$this->db->order_by('id', 'DESC');
		return $this->db->get();	
	}
	
	function serviceMsg($message,$trn_id)
	{
		$current = date('H:i:sa');
		$user = "Customer Service";
		$date = date('Y-m-d');
		$sql = "INSERT INTO messages SET msg='$message', time='$current',trn_id='$trn_id', user='$user',date='$date',Status=1";
		return $this->db->query($sql);
	}
	
	function getUser($date)
	{
		$this->db->select('`id`,`sessionId`,`ip_address`,`active`,`date`');	
		$this->db->from('ci_sessions');
		//$this->db->where('date',$date);
		$this->db->where('active',1);
		return $this->db->get();
	}
	
	function countStatus($sessionId)
	{
		$this->db->where('trn_id',$sessionId);
		$this->db->where('Status',1);
		return $this->db->count_all_results('messages');
	}
	
	function filterMsg($date,$trn_id)
	{
		//$data = date like '$date' AND trn_id = '$trn_id';
		$this->db->select('*');
		$this->db->from('messages');
		$this->db->where('trn_id',$trn_id);
		$this->db->like('date',$date);
		return $this->db->get();
	}
	
	
}

