<?php
	require_once("../system.engine/system.core.php");
	
	$mPong = array();
	$a = &$mPong;
	$p = &$_POST;
	
	global $systemHandler;
	$systemExecution = $systemHandler->loadHandler("EXECUTION");
	$systemHash = $systemHandler->loadHandler("HASH");
	/* ### DO YOUR CODES ONLY FROM HERE ### */
	
	$mFriendId = $p["friendId"];
	$mUserId = $systemHandler->loadHandler("USER")->mUserId;
	$mCount = $systemExecution->runQuery("SELECT COUNT(id) AS requestsCount FROM web_friendrequests WHERE (sender_id = '%s' AND receiver_id = '%s') OR (sender_id = '%s' AND receiver_id = '%s')", array($mUserId, $mFriendId, $mFriendId, $mUserId))->fetch_object()->requestsCount;
	
	$a["currentState"] = $mCount == 0 ? 0 : 1;
	if($a["currentState"] == 0) {
		if($systemExecution->runQuery("SELECT COUNT(id) AS friendsCount FROM web_friends WHERE (user_one_id = '%s' AND user_two_id = '%s') OR (user_one_id = '%s' AND user_two_id = '%s')", array($mUserId, $mFriendId, $mFriendId, $mUserId))->fetch_object()->friendsCount > 0)
			$a["currentState"] = 2;
	}
	
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>