<?php 
	ini_set("display_errors", 1);
	header("Acces-Control-Allow-Origin: *");
	header("Content-type: application/json; charset=UTF-8");
	header("Acces-Control-Allow-Method: POST");
	require_once("../Database/Database.php");
	require_once("../Classes/USERS.php");
	require_once("../Constants/Constants_Variable.php");
	include_once ("../JWT/autoload.php");
	include_once ("../JWT/JWT.php");
	include_once ("../JWT/BeforeValidException.php");
	include_once ("../JWT/ExpiredException.php");
	include_once ("../JWT/SignatureInvalidException.php");
	use \Firebase\JWT\JWT;
	$db=new Database();
	$Connection=$db->Connect();
	$student=new Users($Connection);
	if($_SERVER["REQUEST_METHOD"] === "GET")
	{
		$data=json_decode(file_get_contents("php://input"));
				$query="SELECT * FROM `updates` ";
					$result = $Connection->query($query);
					if ($result->num_rows > 0) 
					{
						$students['Records']=array();
					    while ($rows=$result->fetch_assoc()) 
					    {
					    	array_push($students['Records'], array(
								'id'=>$rows['id'],
								'old_version'=>$rows['old_version'],
								'new_version'=>$rows['new_version'],
								'app_update'=>$rows['app_update']
							));	
					    }
					}
					returnResponse(SUCCESS_RESPONSE,$students['Records']);				
	}
	else
	{
		throwError(ACCESS_DENIED_RESPONSE,"Access Denied!... Please check method.");
	}

	 function throwError($code,$message)
		{
			header("content-type:application/json");
			$errorMessage=json_encode(['error'=>['status'=>$code,'message'=>$message]]);
			echo $errorMessage;
			exit;
		}
	 function returnResponse($code,$data)
		{
			header("content-type:application/json");
			$errorMessage=json_encode(['response'=>['status'=>$code,'Apps'=>$data]]);
			echo $errorMessage;
			exit;
		}
?>