<?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 = $systemHandler->loadHandler("USER")->mUserId;
	$a["htmlContent"] = "";
	
	$mQuery = $systemExecution->runQuery("SELECT web_notifications.id, web_notifications.user_id, web_notifications.has_seen, web_notifications.submit_date, web_notifications.notification_type, web_notifications.sender_user, web_notifications.container_id, web_notifications.comment_id, web_notifications.picture_id FROM web_notifications JOIN web_friends WHERE (web_friends.user_one_id = web_notifications.sender_user AND web_friends.user_two_id = '%s') OR (web_friends.user_one_id = '%s' AND web_friends.user_two_id = web_notifications.sender_user) ORDER BY id DESC LIMIT 30", array($mUserId, $mUserId));
	
	while($mRow = $mQuery->fetch_array()) {
		switch($mRow[4]) {
			case 0: // CONTAINER LIKED
				$mReceiverUser = new systemUSER($mRow[1]);
				$mSenderUser = new systemUSER($mRow[5]);
				$a["htmlContent"] .= '<li class="list-group-item">
										<a href="page.profile.php?profile-id='.$mSenderUser->mUserId.'"><img src="'.$mSenderUser->mProfilePicture.'" class="notificationImage"></a>
										<div class="notificationText">
											<strong><a href="page.profile.php?profile-id='.$mSenderUser->mUserId.'">'.$mSenderUser->mFullname.'</a></strong> has liked <strong><a href="page.profile.php?profile-id='.$mReceiverUser->mUserId.'">'.$mReceiverUser->mFullname.'</a></strong>\'s entry.
										</div>
									</li>';
			break;
			
			case 1: // COMMENT LIKED
				$mReceiverUser = new systemUSER($mRow[1]);
				$mSenderUser = new systemUSER($mRow[5]);
				$a["htmlContent"] .= '<li class="list-group-item">
										<a href="page.profile.php?profile-id='.$mSenderUser->mUserId.'"><img src="'.$mSenderUser->mProfilePicture.'" class="notificationImage"></a>
										<div class="notificationText">
											<strong><a href="page.profile.php?profile-id='.$mSenderUser->mUserId.'">'.$mSenderUser->mFullname.'</a></strong> has liked <strong><a href="page.profile.php?profile-id='.$mReceiverUser->mUserId.'">'.$mReceiverUser->mFullname.'</a></strong>\'s comment.
										</div>
									</li>';
			break;
							
			case 2: // PICTURE LIKED
				$mReceiverUser = new systemUSER($mRow[1]);
				$mSenderUser = new systemUSER($mRow[5]);
				$a["htmlContent"] .= '<li class="list-group-item">
										<img src="'.$mSenderUser->mProfilePicture.'" class="notificationImage">
										<div class="notificationText">
											<strong><a href="page.profile.php?profile-id='.$mSenderUser->mUserId.'">'.$mSenderUser->mFullname.'</a></strong> has liked <strong><a href="page.profile.php?profile-id='.$mReceiverUser->mUserId.'">'.$mReceiverUser->mFullname.'</a></strong>\'s picture.
										</div>
									</li>';
			break;
			
			case 3: // NEW COMMENT
				$mReceiverUser = new systemUSER($mRow[1]);
				$mSenderUser = new systemUSER($mRow[5]);
				$a["htmlContent"] .= '<li class="list-group-item">
										<a href="page.profile.php?profile-id='.$mSenderUser->mUserId.'"><img src="'.$mSenderUser->mProfilePicture.'" class="notificationImage"></a>
										<div class="notificationText">
											<strong><a href="page.profile.php?profile-id='.$mSenderUser->mUserId.'">'.$mSenderUser->mFullname.'</a></strong> has commented <strong><a href="page.profile.php?profile-id='.$mReceiverUser->mUserId.'">'.$mReceiverUser->mFullname.'</a></strong>\'s entry.
										</div>
									</li>';
			break;
		}
	}
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>