<?php
	require_once("../system.engine/system.core.php");
	$l->setPrefix("ajax.handle.fetch.likes");
	
	$mPong = array();
	$a = &$mPong;
	$p = &$_POST;
	
	global $systemHandler;
	$systemExecution = $systemHandler->loadHandler("EXECUTION");
	$systemHash = $systemHandler->loadHandler("HASH");
	/* ### DO YOUR CODES ONLY FROM HERE ### */

	$mLikesIdentifier = $p["likesIdentifier"];
	$mLikesType = $p["likesType"] == "comment" ? "comment" : "container";
	$mCount = $systemExecution->runQuery("SELECT COUNT(id) AS likesCount FROM web_likes WHERE %s = '%s'", array(vsprintf("%s_id", strtolower($mLikesType)), $mLikesIdentifier))->fetch_object()->likesCount;
	
	if($mCount > 0) {
		$mDataCollection = $systemExecution->runQuery("SELECT * FROM web_likes WHERE %s = '%s'", array(vsprintf("%s_id", strtolower($mLikesType)), $mLikesIdentifier));
		
		$a["htmlContainer"] = "<ul class=\"list-group setScrollbar\">";
		while($mRow = $mDataCollection->fetch_assoc()) {
			$mCachedUser = new systemUSER($mRow["user_id"]);
			
			$a["htmlContainer"] .= "<li class=\"list-group-item\">
										<div class=\"row\">
											<div class=\"col-md-2\">
												<center>
													<a href=\"page.profile.php?profile-id=".$mCachedUser->mUserId."\">
														<img src=\"".$mCachedUser->mProfilePicture."\" class=\"pull-left likesProfilePicture\" />
													</a>
												</center>
											</div>
											<div class=\"col-md-10\" style=\"font-size: 16px; text-align: left\">
												<strong><a href=\"page.profile.php?profile-id=".$mCachedUser->mUserId."\">".$mCachedUser->mFullname."</a></strong>
													<br />
												".$systemCore->timeAgo($mRow["submit_date"])."
											</div>
										</div>
									</li>";
		}
		$a["htmlContainer"] .= "</ul>";
	} else $a["htmlContainer"] = "<center>".$l->getValue("currentlynolikes")."</center>";
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>