<?php 
class Mod_chat extends CI_Model{
	
	var $table = "messages";
	function __construct()
	{
		parent::__construct();	
	}	
	
	
	function getMsg($limit = 15)
	{
		$trn_id = $this->session->userdata('sessionId');
		$this->db->SELECT('*');
		$this->db->from("messages");
		$this->db->where("trn_id",$trn_id);
		$this->db->order_by("id", "desc"); 
		$this->db->limit($limit);
		return $this->db->get();	
		
	}

	function insertMsg($message,$trn_id)
	{
		$current = date('H:i:sa');
		$user = "User";
		$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 welcomeMsg($message,$trn_id)
	{
		$data = array(
			'time' 	 => date('H:i:sa'),
			'msg'  	 => $message,	
			'trn_id' => $trn_id,
			'date'	 => date('Y-m-d'),
			'Status' => 1,
			'user'	 => 'Customer Service',
		);
		
		$this->db->insert('messages',$data);
	}
	
}

