<?php
include 'common.php';

function CharacterSkillQuery($character_uid){
	//Connect DB
	$dbhandle = DB_Connect();
	
	
	$db_selected = mysqli_select_db($dbhandle, DB_NAME)
	or die("Could not select db");

	
	$strQuery = "select * from owned_skill where character_uid=".$character_uid." order by skill_uid asc";
	
	//echo $strQuery;
	//return;
	
	//Query Result
	if($result = mysqli_query($dbhandle, $strQuery))
	{
		$count = 0;
		$list = "";
		while($row=mysqli_fetch_array($result, MYSQLI_ASSOC))
		{
			$count++;
			$dataArray[] = $row["owned_skill_uid"].",". $row["character_uid"].",".$row["skill_uid"] .",".$row["is_equiped"].",".$row["level"].",".$row["slot_idx"].",".$row["is_passive"];
		}
		
	}
	else
	{
		
	}
	mysqli_free_result($result);

	
	if($count <= 0  )
	{
		$return = "NOT_EXIST_OWNED_SKILL";
		
		$response = array('result'=>$return,'error'=>"",'list'=>null);
	}
	else
	{
		$return = "OWNED_SKILL_LIST_OK";
		$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);
		
	mysqli_close($dbhandle);
}

$json = json_decode(file_get_contents('php://input'));
$character_uid = $json->character_uid;

CharacterSkillQuery($character_uid);

?>