<?php
   
require APPPATH . 'libraries/REST_Controller.php';
     
class C_Api extends REST_Controller {
    
	  /**
     * Get All Data from this method.
     *
     * @return Response
    */
    public function __construct() {
       parent::__construct();
       $this->load->database();
       $this->load->model('m_masters');
    }
       
    /**
     * Get All Data from this method.
     *
     * @return Response
    */
	public function index_get()
	{   

        // $querystring = "select * from tabledatamapping where tabledata like '%" . $id. "%'";
        $id = $this->get("id");
        if($id <> ''){
            // $data = $this->m_masters->querying("items", ['id' => $id])->row_array();
            $querystring = "select * from tabledatamapping where tabledata like '%" . $id. "%'";
            $data = json_encode($this->m_masters->querying($querystring)->result());
        }else{
            // $data = $this->db->get("items")->result();
            // $data = $this->m_masters->querying($querystring)->row_array();
            $querystring = "select * from tabledatamapping";
            $data = json_encode($this->m_masters->querying($querystring)->result());
        }
        
        $this->response($data, REST_Controller::HTTP_OK);
	}
      
    /**
     * Get All Data from this method.
     *
     * @return Response
    */
    // $grup,$kunci,$oleh,$kapan
    public function index_post()
    {
        $OG = $this->post("OG");
        $GSecret = $this->post("GSecret");
        $Creator = $this->post("Creator");
        $CreatedDate = $this->post("CreatedDate");
        // $this->db->insert('items',$input);
        
        $querystring = "insert into gsecret values ('".$OG . "','".$GSecret."','".$Creator . "','".$CreatedDate."')";
        $this->m_masters->querying($querystring);

        $this->response(['Item created successfully.'], REST_Controller::HTTP_OK);
    } 
     
    /**
     * Get All Data from this method.
     *
     * @return Response
    */
    public function index_put($id)
    {
        $input = $this->put();
        $this->db->update('items', $input, array('id'=>$id));
     
        $this->response(['Item updated successfully.'], REST_Controller::HTTP_OK);
    }
     
    /**
     * Get All Data from this method.
     *
     * @return Response
    */
    public function index_delete($id)
    {
        $this->db->delete('items', array('id'=>$id));
       
        $this->response(['Item deleted successfully.'], REST_Controller::HTTP_OK);
    }
    	
}