<?php
include 'common.php';


function SaveSpDistribution($account_id, $char_uid, $str, $intellect, $dex, $wis, $con)
{
	$dbhandle = DB_Connect();
	//Select DB
	$db_selected = mysqli_select_db($dbhandle, DB_NAME)
	or die("Could not select db");
	
	
	
	$update_query = "update character_list set stat_strength=".$str.", stat_intellect=".$intellect.", stat_agility=".$dex.",stat_wisdom=".$wis.",stat_health=".$con." where user_id='".$account_id."' and character_uid='".$char_uid."'";

	//Query Result
	$result = @mysqli_query($dbhandle,$update_query);
	$response = "SAVE_SP_DIST_FAILED";
	$error = "";
	if($result)
	{
		$response = "SAVE_SP_DIST_OK";
		// don't use for upate/insert query, because these query result is true/false, not mysqli_result object
		//mysqli_free_result($result); 
	}
	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,'error'=>$error));
}

SaveSpDistribution($_GET['account_id'], $_GET['char_uid'], $_GET['str'], $_GET['intellect'], $_GET['dex'], $_GET['wis'], $_GET['con']);

?>