<?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"];
	$mUserId = $systemHandler->loadHandler("SESSION")->loadSession("USER");
	
	$mOwnerId = $systemExecution->runQuery("SELECT web_timeline.post_user_id FROM web_comments, web_timeline WHERE web_timeline.id = web_comments.container_id AND web_comments.id = '%s'", $mCommentId)->fetch_object()->post_user_id;
	
	if($systemExecution->runQuery("SELECT COUNT(id) AS commentCount FROM web_comments WHERE id = '%s' AND user_id = '%s'", array($mCommentId, $mUserId))->fetch_object()->commentCount > 0 || $mUserId == $mOwnerId) {
		$systemExecution->runQuery("DELETE FROM web_comments WHERE id = '%s'", $mCommentId);
		$a["isValid"] = true;
	} else $a["isValid"] = false;
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>