<?php
include 'common.php';


function DeleteGuildMyApplication($character_uid)
{
	//Connect DB
	$dbhandle = DB_Connect();
	
	
	$db_selected = mysqli_select_db($dbhandle, DB_NAME)
	or die("Could not select db");
	 
	$stmt = $dbhandle->prepare("DELETE FROM guild_apply WHERE character_uid=?");
	$stmt->bind_param("i", $character_uid);
	$result = $stmt->execute();
	$stmt->close();

	if ($result)
	{
		$return = "GUILD_MY_APPLICATION_DELETE_OK";
		$error = "";
		$response = array('result'=>$return,'error'=>$error);
	}
	else
	{
		$return = "DB_ERROR";
		$error = mysqli_error($dbhandle);
		$response = array('result'=>$return,'error'=>$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($response);
		
	mysqli_close($dbhandle);
}


$character_uid = $_GET['character_uid'];

if(CheckValidatedServerIP())
{
	DeleteGuildMyApplication($character_uid);
}
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	));
}


?>