<?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);
		echo 4;
		exit;
	}

	// retrieve JSON from POST body
	$json_str = file_get_contents('php://input');
	$json_obj = json_decode($json_str);
	$storage_account = $json_obj->storage_account;
	IF ( $storage_account ){		
		
		$query = " SELECT * FROM  loc8_storage_reportdata WHERE storage_account = '$storage_account'";
		$result = $db->query($query);
		$count=$result->num_rows;
			
		if($count > 0) {
			
		}else{
			$query=" INSERT INTO loc8_storage_reportdata (storage_account, storage_data) values ('$storage_account', '{}') "; $db->query($query);
		}
				
		echo json_encode( array( 'ReplyCode' => '000', 'data' => $query, '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 );

}
?>
