<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Centre
 *
 * @author user
 */
require APPPATH . '/libraries/REST_Controller.php';

class Centre extends REST_Controller {

    function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->model('Centre_modal');
        $this->load->model('Token_modal');
    }

    public function getcentrelistbyarea_post() {
        $headers = $this->input->request_headers();
        $valid = $this->Token_modal->exit_token($headers['Token']);
        if ($valid != null) {
            header('Content-type: application/json');
            $object = json_decode(file_get_contents('php://input'), true);
            $data = $object['GetCenterByAreaRequest']['Area'];
            $centre = $this->Centre_modal->get_centre_list_by_area($data);
            $centre_list = array("Center" => $centre);
            $message = array("Status" => "200",
                "CenterList" => $centre_list);
            $response_message = array("GetCenterByAreaResponse" => $message);
            $this->response($response_message);
        } else {
            $message = array("Status" => "1002",
                "Message" => "Invalid token");
            $response_message = array("GetCenterByAreaResponse" => $message);
            $this->response($response_message);
        }
    }

}
