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

	$mCommentId = $p["commentId"];
	if($systemExecution->runQuery("SELECT COUNT(id) AS likeCount FROM web_likes WHERE user_id = '%s' AND comment_id = '%s'", array("{user.id}", $mCommentId))->fetch_object()->likeCount == 0) {
		$systemExecution->runQuery("INSERT INTO web_likes (comment_id, user_id, submit_date) VALUES ('%s', '%s', '%s')", array($mCommentId, $systemHandler->loadHandler("SESSION")->loadSession("USER"), time()));
		$a["isLike"] = true;
		$systemCore->importCommentLike($mCommentId);
	} else {
		$systemExecution->runQuery("DELETE FROM web_likes WHERE comment_id = '%s' AND user_id = '%s'", array($mCommentId, $systemHandler->loadHandler("SESSION")->loadSession("USER")));
		$a["isLike"] = false;
		$systemCore->deleteCommentLike($mCommentId);
	}
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>