<?php

function FetchingData($path) {
	$curl = curl_init();
	curl_setopt_array($curl, array(	
	CURLOPT_URL => API_URL.$path,
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'GET',
	)); 
	$response = curl_exec($curl);
	curl_close($curl);
	return json_decode($response);
}

function UpdateData($path,$body) {
	$curl = curl_init();
	curl_setopt_array($curl, array(
	CURLOPT_URL => API_URL.$path,
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'PATCH',
	CURLOPT_POSTFIELDS => json_encode($body),
	CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
	),
	));
	$response = curl_exec($curl);
	curl_close($curl);
	return json_decode($response);
}

function InsertData($path,$body) {
	$curl = curl_init();
	curl_setopt_array($curl,array( CURLOPT_URL => API_URL.$path,
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'POST',
	CURLOPT_POSTFIELDS => json_encode($body),
	CURLOPT_HTTPHEADER => array( 'Content-Type: application/json' ),));
	$response = curl_exec($curl);
	curl_close($curl);
	return json_decode($response);
}

function DeleteData($path) {
	$curl = curl_init();
	curl_setopt_array($curl, array(
	  CURLOPT_URL => API_URL.$path,
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => '',
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 0,
	  CURLOPT_FOLLOWLOCATION => true,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => 'DELETE',
	));
	$response = curl_exec($curl);
	curl_close($curl);
	echo $response;
}

function DeleteDataWithoutEcho($path) {
	$curl = curl_init();
	curl_setopt_array($curl, array(
	  CURLOPT_URL => API_URL.$path,
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => '',
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 0,
	  CURLOPT_FOLLOWLOCATION => true,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => 'DELETE',
	));
	$response = curl_exec($curl);
	curl_close($curl);
	return;
}

function DeleteYearData($path) {
	$curl = curl_init();
	curl_setopt_array($curl, array(
	  CURLOPT_URL => API_URL.$path,
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => '',
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 0,
	  CURLOPT_FOLLOWLOCATION => true,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => 'DELETE',
	));
	$response = curl_exec($curl);
	curl_close($curl);
	return json_decode($response);
}

function GetProvinceByCode($path) {
	$curl = curl_init();
	curl_setopt_array($curl,array( CURLOPT_URL => API_URL.$path,
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'GET',
	));
	$response = curl_exec($curl);
	curl_close($curl);
	return json_decode($response);
}

function GetDataById($path) {
	$curl = curl_init();
	curl_setopt_array($curl, array(CURLOPT_URL => API_URL.$path,
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'GET',
	));
	$response = curl_exec($curl);
	curl_close($curl);
	return $response;	
}

function EncryptMe($txt) {
	$curl = curl_init();
	curl_setopt_array($curl, array(
	  CURLOPT_URL => API_SMATACO.'/encdec_login/?pwd='.$txt,
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => '',
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 0,
	  CURLOPT_FOLLOWLOCATION => true,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => 'GET',
	));
	$response = curl_exec($curl);
	curl_close($curl);
	return $response;
}

function SendRemoteFCM($path) {
$path = str_replace(" ", '%20', $path);
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => $path,
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
));
	$response = curl_exec($curl);
	return $response;
}
