<?php
header('content-type: application/json');
header("access-control-allow-origin: *");
require_once(dirname(__FILE__)."/../packages/require_api.php");

if(isset($_GET['action'])){

	require_once($global['root-model']."Crud.php");
	$obj_crud = new Crud();

	require_once($global['root-model']."Region.php");
	$obj_region = new Region();

	//===================================== Get Data ========================================
	if($_GET['action'] == 'get_data_select'){

		$R_message = array("code" => "400", "message" => "No Data");

		$N_user_id = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : "";
		
		if($N_user_id != ""){

			$result = $obj_region->get_data_select($obj_crud);
			
			if(is_array($result)){
				$R_message = array("code" => "200", "message" => "Fetch success", "num_data" => count($result), "data" => $result);
			}

			echo json_encode($R_message); 

		} else {
			$R_message = array("code" => "402", "message" => "Unauthorized access");
			echo json_encode($R_message);
		}
	} else {
		$R_message = array("code" => "404", "message" => "Action Not Found");
		echo json_encode($R_message);
	}
}//end gate
else{
	$R_message = array("code" => "404", "message" => "Not Found");
	echo json_encode($R_message);
}
?>