<?php
include('aconnect.php');
$db->query("set names utf8");

function clean($value = "") {
    $value = trim($value);
    $value = stripslashes($value);
    $value = strip_tags($value);
    $value = htmlspecialchars($value); 
    $value = str_replace(";", ",", $value);          
    return $value;
}

function _isCurl(){
	return function_exists('curl_version');
}
	
if($_SERVER["REQUEST_METHOD"] == "POST") {	

	if (!_isCurl()){	
		$arr = array('replyCode' => '1000', 'msg'=>'Set up Curl');
		echo json_encode($arr);
		exit;
	}

	// retrieve JSON from POST body
	$json_str = file_get_contents('php://input');
	
	$json_obj = json_decode($json_str);
	$storage_name = $json_obj->storage_name;
	$storage_account = $json_obj->storage_account;
	$storage_data = $json_obj->storage_data;
	
	IF ( $storage_account && $storage_data ){
		switch($storage_name){
			case 'COM.QUIKTRAK.QUIKLOC8.REPORTDATADB':
				$query=" UPDATE loc8_storage_reportdata SET storage_data = '$json_str' WHERE storage_account = '$storage_account' ";$db->query($query);
			break;
		}
				
		echo json_encode( array( 'ReplyCode' => '000', 'data' => '000', 'msg'=>'Done'), JSON_FORCE_OBJECT );
		
		$db->close();
	}else{

		echo json_encode( array( 'ReplyCode' => '999', 'msg'=>'No data received'), JSON_FORCE_OBJECT );

	}
    
} else {

	echo json_encode( array( 'ReplyCode' => '1000', 'msg'=>'Request error'), JSON_FORCE_OBJECT );

}
?>
