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

class Mo_event extends CI_Model {

	public $table = 't_event';
	
    function fnGetData()
    {
        $this->db->order_by('f_event_id', 'DESC');
        return $this->db->get($this->table)->result();		
	}

	function getDataId($id)
	{
		$sql = $this->db->get_where($this->table,array('f_event_id'=> $id))->row_array();
		return $sql;
	}

	function saveData()
	{
		$data = array(
				'f_event_id' => $this->input->post('f_event_id'),
				'f_customer_id' => $this->input->post('f_customer_id'),
				'f_event_name' => $this->input->post('f_event_name'),
				'f_event_no' => $this->input->post('f_event_no'),
				'f_event_active' => $this->input->post('f_event_active'),
				'f_created_on' => $this->input->post('f_created_on'),
				'f_created_by' => $this->input->post('f_created_by'),
				'f_updated_on' => $this->input->post('f_updated_on'),
				'f_updated_by' => $this->input->post('f_updated_by'),
		);
		$sql = $this->db->insert($this->table,$data);
		return $sql;
	}

	function updateData($id)
	{
		$data = array(
				'f_event_id' => $this->input->post('f_event_id'),
				'f_customer_id' => $this->input->post('f_customer_id'),
				'f_event_name' => $this->input->post('f_event_name'),
				'f_event_no' => $this->input->post('f_event_no'),
				'f_event_active' => $this->input->post('f_event_active'),
				'f_created_on' => $this->input->post('f_created_on'),
				'f_created_by' => $this->input->post('f_created_by'),
				'f_updated_on' => $this->input->post('f_updated_on'),
				'f_updated_by' => $this->input->post('f_updated_by'),
		);

		$this->db->where('f_event_id',$id);
		$sql = $this->db->update($this->table,$data);
		return $sql;		
	}

	function deleteData($id)
	{
		$this->db->where('f_event_id',$id);
		$sql = $this->db->delete($this->table);
		return $sql;		
	}
	
	function comboData()
	{
		$sql = $this->db->get('t_event');
		if($sql)
		{
			foreach($sql->result() as $r):
				$list[$r->f_event_id] = $r->f_event_id;
			endforeach;
		}
		return $list;
	}

	function remoteComboData()
	{
		if($this->input->get('term')) $this->db->like('f_event_id',$this->input->get('term')); // pencarian name
		if($this->input->get('id')) $this->db->where('f_event_id',$this->input->get('id')); // saat pencarian update
		
		$this->db->limit('10');
		$result = $this->db->get($this->table)->result();
		$data = array();
		foreach($result as $row):
			$data[] = array(
				'id'	=> $row->f_event_id, // value
				'text'	=> $row->f_event_id, // change display 
				);
		endforeach;
		return $data;
	}
}

/* End of file Mo_event.php */
/* Location: ./application/modules/Event/models/Mo_event.php */	

	


