<?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 ### */

	$mUserId = $p["profileId"];
	$mCurrentIndex = $p["currentIndex"];
	$a["htmlOutput"] = "";
	$mFriendsCount = 0;
	$mRealCount = 0;
	
	$mQuery = $systemExecution->runQuery("SELECT * FROM web_friends WHERE user_one_id = '%s' OR user_two_id = '%s' LIMIT %s,30", array($mUserId, $mUserId, $mCurrentIndex));
	while($mRow = $mQuery->fetch_assoc()) {
		$mRealCount++;
		
		if($mRealCount == 1)
			$a["htmlOutput"] .= "<div class=\"row\" style=\"margin-top: 25px\">";
		
		$mFriendId = $mUserId == $mRow["user_one_id"] ? $mRow["user_two_id"] : $mRow["user_one_id"];
		$mFriend = new systemUSER($mFriendId);
		$a["htmlOutput"] .= "<div class=\"col-md-4 col-xs-12\">
								<a href=\"page.profile.php?profile-id=".$mFriendId."\">
									<img src=\"".$mFriend->mProfilePicture."\" class=\"profileFriend\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"".$mFriend->mFullname."\" />
								</a>
							</div>";
		
		if($mRealCount % 3 == 0) {
			$mRealCount = 0;
			$a["htmlOutput"] .= "</div>";
		}
		
		$mFriendsCount++;
	}
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>