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

	$mContainerId = $_POST["containerId"];
	
	if($systemExecution->runQuery("SELECT COUNT(id) AS likeCount FROM web_likes WHERE user_id = '%s' AND container_id = '%s'", array("{user.id}", $mContainerId))->fetch_object()->likeCount == 0) {
		$mImageId = $systemExecution->runQuery("SELECT post_image_id FROM web_timeline WHERE id = '%s'", $mContainerId)->fetch_object()->post_image_id;
		$systemExecution->runQuery("INSERT INTO web_likes (container_id, user_id, submit_date, image_id) VALUES ('%s', '%s', '%s', '%s')", array($mContainerId, $systemSession->loadSession("USER"), time(), $mImageId));
		$a["isLike"] = true;
		$systemCore->importContainerLike($mContainerId);
	} else {
		$systemExecution->runQuery("DELETE FROM web_likes WHERE container_id = '%s' AND user_id = '%s'", array($mContainerId, $systemSession->loadSession("USER")));
		$a["isLike"] = false;
		$systemCore->deleteContainerLike($mContainerId);
	}
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>