<?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"];
	$mNewContent = $p["newContent"];
	$mUserId = $systemHandler->loadHandler("USER")->mUserId;
	
	$a["newCommentHTML"] = null;
	
	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) {
		$systemExecution->runQuery("UPDATE web_comments SET comment_text = '%s' WHERE id = '%s' AND user_id = '%s'", array($mNewContent, $mCommentId, $mUserId));
		
		$a["newCommentHTML"] = $systemHandler->loadHandler("SMILIES")->initializeSmilies($systemExecution->runQuery("SELECT comment_text FROM web_comments WHERE id = '%s'", $mCommentId)->fetch_object()->comment_text, true);
	}
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>