<?php  
include 'common.php';

function EchoRespone($return, $responseMsg)
{
	$response = array('result'=>$return,'error'=>$responseMsg);
    
 
    $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);
}

function BlockAll($gm_account_id, $gm_login_key)
{
    $dbhandle = DB_Connect();
	$db_selected = mysqli_select_db($dbhandle, DB_NAME)
    or die("Could not select db");


	if(!CheckLoginKey($dbhandle, $gm_account_id, $gm_login_key))
	{
		PrintLoginKeyError();
        mysqli_close($dbhandle);
		return;
	}


    $update_query = "update character_list set block=1";
    //Query Result
    $result = @mysqli_query($dbhandle,$update_query);
    if($result)
    {
        EchoRespone("BLOCK_ALL_OK", $character_name);
    }
    else
    {
        $error = mysqli_error($dbhandle);
        EchoRespone("BLOCK_ALL_FAILED", $error);
    }
            
    mysqli_close($dbhandle);
}

//BlockAll();

if(CheckValidatedServerIP())
{
	BlockAll($_GET['gm_account_id'], $_GET['gm_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	));
}

?>