<?php
include 'common.php';


function GetGameAccountId($wallet_id)
{
	$dbhandle = DB_Connect();
	//Select DB
	$db_selected = mysqli_select_db($dbhandle, DB_NAME)
	or die("Could not select db");
	
	
	$stmt = $dbhandle->prepare("select user_id from account where wallet_id=?");
	$stmt->bind_param("s", $wallet_id);
	$stmt->execute();
	$result = $stmt->get_result();
	
	
	mysqli_stmt_free_result($stmt);
	$stmt->close();
	
	
	
	$response = "GET_ACCOUNT_ID_FAILED";	
	$error = "";
	$user_id = "";
	if($result)
	{
		$response = "GET_ACCOUNT_ID_OK";
		$row = $result->fetch_assoc();
		$user_id = $row["user_id"];
	}
	else
	{
		$error = mysqli_error($dbhandle);
	}
	
	
	 mysqli_close($dbhandle);
 
    $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, 'user_id'=>$user_id,'error'=>$error));
}

$json = json_decode(file_get_contents('php://input'));
$wallet_id = $json->wallet_id;
$checksum = $json->checksum;
		
$check = $wallet_id;

if(CheckSum($wallet_id,$check,$checksum))
{
//	$wallet_id = $_GET['wallet_id'];
	GetGameAccountId($wallet_id);
}



	

?>