<?php
include 'common.php';


function LoadGoldCash($account_id, $character_uid, $login_key)
{
    $dbhandle = DB_Connect();
	$db_selected = mysqli_select_db($dbhandle, DB_NAME)
    or die("Could not select db");
    
	if(!CheckLoginKey($dbhandle, $account_id, $login_key))
	{
		PrintLoginKeyError();
		mysqli_close($dbhandle);
		return;
	}
	
	
	$gold = GetGold($dbhandle, $account_id, $character_uid);
    $cash = GetCash($dbhandle, $account_id);

	mysqli_close($dbhandle);

	$dataArray = $gold.",".$cash;
	
	$return = "GOLD_CASH_OK";
	$error = "";
	$response = array('result'=>$return,'error'=>"",'list'=>$dataArray);
    
    $isXmlHttpRequest = (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) ?
	(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false: false;
	($isXmlHttpRequest) ? header('Content-type: application/json') : header('Content-type: text/plain');
 
	echo json_encode($response);
}

$account_id = $_GET['account_id'];
$login_key = $_GET['login_key'];
$character_uid = $_GET['character_uid'];



if(CheckValidatedServerIP())
{
	LoadGoldCash($account_id, $character_uid, $login_key);
}
else
{
	$response = "INVALIDATED_SERVER";
	$error = "CheckValidatedServerIP ERROR";
	$isXmlHttpRequest = (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) ?
	(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false: false;
	($isXmlHttpRequest) ? header('Content-type: application/json') : header('Content-type: text/plain'); 
 
	echo json_encode(array(	'result'=>$response,'error'=>$error	));
}

?>