<?php
	require_once("../system.engine/system.core.php");
	$l->setPrefix("ajax.handle.notifications.friends");
	
	$mPong = array();
	$a = &$mPong;
	$p = &$_POST;
	
	global $systemHandler;
	$systemExecution = $systemHandler->loadHandler("EXECUTION");
	$systemHash = $systemHandler->loadHandler("HASH");
	/* ### DO YOUR CODES ONLY FROM HERE ### */
	
	$a["containerHTML"] = null;
	$mQuery = $systemExecution->runQuery("SELECT * FROM web_friendrequests WHERE receiver_id = '%s' ORDER BY id DESC", $systemHandler->loadHandler("USER")->mUserId);
	$mCount = 0;
	while($mRow = $mQuery->fetch_assoc()) {
		$mUser = new systemUSER($mRow["sender_id"]);
		$a["containerHTML"] .= "<li friendstatus-location=\"".$mUser->mUserId."\">
								<a href=\"javascript:;\">
									<div class=\"row black\">
										<div class=\"col-md-2 col-xs-2\">
											<img src=\"".$mUser->mProfilePicture."\" class=\"notificationPicture thumbnail\" />
										</div>
										<div class=\"col-md-10 col-xs-10 textWrap\">
											<b>".$mUser->mFullname."</b>
												<br />
											<small>".$mUser->mFirstname." has <b>".$mUser->mFriendsCount."</b> friends.</small>
												<br />
												<div class=\"btn-group\" style=\"width: 100%\" role=\"group\" aria-label=\"\">
													<button data-event=\"accept-friend\" data-parameter=\"".$mUser->mUserId."\" type=\"button\" class=\"btn btn-default btn-xs\"><i class=\"glyphicon glyphicon-plus font12\"></i> ".$l->getValue("accept")."</button>
													<button data-event=\"decline-friend\" data-parameter=\"".$mUser->mUserId."\" type=\"button\" class=\"btn btn-danger btn-xs\"><i class=\"glyphicon glyphicon-minus font12\"></i> ".$l->getValue("decline")."</button>
												</div>
										</div>
									</div>
								</a>
							</li>";
		$mCount++;
	}
	
	if($mCount == 0)
		$a["containerHTML"] .= "<li><center>".$l->getValue("nofriendrequests")."</center></li>";
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>