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

class Smslog_model extends MY_Model
{
	
	protected $table_name = 'tblsmslog';
	protected $id_name = 'id';

	function __construct()
	{
		parent::__construct();
	}
	
	function get_smslogs($data)
	{
		$sql = "SELECT * FROM " . $this->table_name;
		if ($data['keyword'])
		{
			$sql.=" WHERE (sender LIKE '%".$data['keyword']."%' OR mobody LIKE '%".$data['keyword']."%' OR mtbody LIKE '%".$data['keyword']."%') ";
		}
		$order = "";
		if ($data['sorting_order'] != "sorting") {
			$sort = "DESC";
			if ($data['sorting_order'] == "sorting_asc")
				$sort = "ASC";
			$order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
		}
		return $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ")->result_array();
	}
	
	function get_total_smslogs($data)
	{
		$sql="SELECT COUNT(".$this->id_name.") AS total FROM ".$this->table_name;
		if (isset($data['keyword']))
		{
			if (strlen($data['keyword'])>0)
				$sql.=" WHERE (sender LIKE '%".$data['keyword']."%' OR mobody LIKE '%".$data['keyword']."%' OR mtbody LIKE '%".$data['keyword']."%') ";
		}
		return $this->db->query($sql)->row_array()['total'];
	}
}