<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cardlog_model extends MY_Model
{
	
	protected $table_name = 'tblcardlog';
	protected $id_name = 'id';

	function __construct()
	{
		parent::__construct();
	}

	function get_cardlogs($data)
	{
		$sql = "SELECT * FROM " . $this->table_name;
		if ($data['keyword'])
		{
			$sql.=" WHERE (sender 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;
		}
		$query = $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ");
		return $query->result_array();
	}
	
	function get_total_cardlogs($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']."%'";
		}
		$query = $this->db->query($sql);
		$row = $query->row_array();
		return $row['total'];
	}
}