<?php
// get these values from your DB.
require_once('config.php');
$error_message;
$valid = true;



//Version
$sql="Select sys_ver_customer_cd,sys_ver_mobile_ver,sys_ver_apk_url,sys_ver_mobile_api_ver	 from sys_ver (NOLOCK)";
		
$stmt = sqlsrv_query( $conn, $sql);

if( !$stmt ) {
     $error_message = "Error selecting table (sys_ver)";
	 returnError($error_message);
     die( print_r( sqlsrv_errors(), true));
	 
}

do {
     while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {	
	 
		$sys_ver_mobile_ver = $row ['sys_ver_mobile_ver'];	
		$sys_ver_customer_cd = $row ['sys_ver_customer_cd'];
		$sys_ver_apk_url = $row ['sys_ver_apk_url'];		
		$sys_ver_mobile_api_ver = $row ['sys_ver_mobile_api_ver'];		
		
	
     }
} while ( sqlsrv_next_result($stmt) );


if ($valid) {

	
	//echo $sql;
	returnData($sys_ver_mobile_ver,$sys_ver_customer_cd,$sys_ver_apk_url,$sys_ver_mobile_api_ver);	
	sqlsrv_free_stmt( $stmt);
	sqlsrv_close( $conn);	
	
}

function returnData($sys_ver_mobile_ver,$sys_ver_customer_cd,$sys_ver_apk_url,$sys_ver_mobile_api_ver){
	$returnData = array(
	'status' => 'Update Alert',
	'message' => 'New version available Please, update app to New Version : '.$sys_ver_mobile_ver,
	'customer_cd'=>$sys_ver_customer_cd,
	'sys_ver_apk_url'=>$sys_ver_apk_url,
	'version' =>$sys_ver_mobile_ver,
	'API_version' =>$sys_ver_mobile_api_ver);
	
	echo json_encode($returnData);	
}

function returnError( $error_message){
	$json = array();
	
	$returnData = array(
	'status' => 'ERROR',
	'message' => $error_message,
	'data' => '');
	
	echo json_encode($returnData);	
	exit();	
		
}
	

 
?>