<?php
	/* WebWall */
	define("ONLINE", 1);
	$root = dirname( dirname( dirname(__FILE__) ) );
	require_once "$root/core.php";
	$get["cmd"] = $_GET["cmd"];
	$add["post"] = ucfirst(text_filter($_POST["post"], 1));
	$add["to_user"] = text_filter($_POST["username"], 1);
	$add["anonymous"] = $_POST["anonymous"];
	$delete["id"] = $_GET["del_id"];
$answer["answer"] = ucfirst(text_filter($_POST["response"], 1));
$answer["id"] = $_POST["qa_id"];
$like["id"] = $_POST["id"];
$stream_type = $_POST["streamtype"];
$user = text_filter($_POST["username"], 1);
$typenotify = $_POST["ntype"];
$stickerid = $_POST['stickerid'];
$verified = $_POST['verified'];
$check["username"] = text_filter(ucfirst(strtolower($_POST["username"])), 1);
	$photo_file = $_FILES["photo"];
if(isset($get["cmd"]))
{
	switch($get["cmd"])
	{
		case "addpost":		$engine_session->add($add["post"], $add["to_user"], $add["anonymous"], $photo_file);
							break;
		case "delete":		$engine_session->delete($delete["id"]);
							break;
		case "addsticker":	if($verified!="")
							{
								$engine_session->verified($user,$verified);
							}
							else
							{
								$engine_session->addsticker($stickerid,$user);
							}
							break;
		case "giftposition": $engine_session->giftposition($_POST['giftid'], $_POST['posx'], $_POST['posy']);
							break;
		case "like":		$engine_session->like($like["id"],USER_USERNAME);
							break;
		case "likes":		$engine_session->getalllikes($like["id"]);
							break;
		case "toppeople":	$engine_session->toppeople($_POST["optiontype"]);
							break;
		case "notify":		$engine_session->notify(USER_USERNAME,$typenotify);
							break;
		case "stream":		$engine_session->stream($stream_type);
							break;
		case "check_name":	$engine_session->checkname($check["username"]);
							break;   
		case "changelang":	$engine_session->changelang();
							break;  
		case "comment":		if($_POST["comment"]!="" && $_POST["ajax"]!=0)
							{
								$currentUnixTime = time(); 
								if(isset($_POST["anonymous"]))
								{ 
									$from = null; 
									$anon = 1; 
									$msg = "<img src=\"media/images/users/photo_anonymous.png\" id=\"postavatar\" /> ".langVar(300);
								}
								else
								{
									$from = USER_USERNAME;
									$sqlgetphoto = mysql_query("SELECT photo FROM users WHERE username = '".USER_USERNAME."'");
									$iii = mysql_fetch_assoc($sqlgetphoto);
									$msg = "<a href=\"http://".SITE_DOMAIN."/".USER_USERNAME."\"><img src=\"media/images/users/".$iii["photo"]."\" id=\"postavatar\" />".USER_USERNAME."</a>"; 
									$anon = 0;
								}
								$gettouser = mysql_query('SELECT to_user, from_user FROM posts where id = "'.$_POST["id"].'"'); 
								$gettouserres = mysql_fetch_assoc($gettouser);
								$to = $gettouserres['to_user'];
								$post_from = $gettouserres['from_user'];

								$comment = text_filter($_POST["comment"], 1);
								$createComment = mysql_query('INSERT INTO comments (post_id, comment, anonymous, to_user, from_user, post_user, time, viewed) values ("'.$_POST["id"].'", "'.$comment.'", "'.$anon.'", "'.$to.'", "'.$from.'", "'.$post_from.'", "'.$currentUnixTime.'", "0")');
								$getCommentId = mysql_query('SELECT * FROM comments WHERE time = "'.$currentUnixTime.'"'); 
								if($createComment && $getCommentId)
								{ 
									$commentID = mysql_fetch_assoc($getCommentId);
									$html .= '<li id="comment'.$getQD["id"].'" style="display: list-item;" class="commentbox">';
									$html .= '<div id="commentname">'.$msg.':</div>';
									$html .= '<div id="commenttext">';
									$html .= utf8_encode(html_entity_decode($_POST["comment"]));
									$html .= '</div>';
									$html .= '<a class="commentDate">'.langVar(420).' '.date("d/m/Y").' '.langVar(65).' '.date("H:i:s").'</a>&nbsp;&nbsp;';
									$html .= '</li>';  
									$json = array("error" => "", "html" => "$html");
									echo(json_encode($json)); 
									exit;
								}
								else 
								{
									$json = array("error" => "error");
									echo(json_encode($json)); 
									;
								}
							}
							break;
		case "blockuser":	if($_POST["username"]!="" && $_POST["ajax"]!=0)
							{ 
								$block = mysql_query('INSERT INTO users_blocked (username, blocked, status) VALUES ("'.USER_USERNAME.'", "'.$_POST["username"].'", "1")');  
								if($block)
								{ 
									$json = array("error" => NULL);
								}
								else $json = array("error" => "Database AJAX error");
								echo(json_encode($json)); exit;
							}
							break;	  
		case "unblockuser":	if($_POST["username"]!="" && $_POST["ajax"]!=0)
							{ 
								$block = mysql_query('DELETE FROM users_blocked WHERE username="'.USER_USERNAME.'" AND blocked="'.$_POST["username"].'"');				
								if($block)
								{ 
									$json = array("error" => NULL);
								}
								else $json = array("error" => "Database AJAX error");
								echo(json_encode($json)); exit;
							}
							break;
		case "addfriend":	if($_POST["username"]!="" && $_POST["ajax"]!=0)
							{ 
								$block = mysql_query('INSERT INTO users_friends (username, friend, status, time) VALUES ("'.USER_USERNAME.'", "'.$_POST["username"].'", "1", "'.time().'")'); 		
								if($block)
								{ 
									$json = array("error" => NULL);
								}
								else $json = array("error" => "Database AJAX error");
								echo(json_encode($json)); exit;
							}
							break;
		case "removefriend":  if($_POST["username"]!="" && $_POST["ajax"]!=0)
						    { 
								$block = mysql_query('DELETE FROM users_friends WHERE username="'.USER_USERNAME.'" AND friend="'.$_POST["username"].'"');				
								if($block)
								{ 
									$json = array("error" => NULL);
								}
								else $json = array("error" => "Database AJAX error");
								echo(json_encode($json)); exit;
						    }
							break;
		case "getposts": $user = text_filter(ucfirst(strtolower($_POST["user"])), 1);
							$nr = text_filter($_POST["number"], 1);
							$q = text_filter($_POST["offset"], 1);
							getposts($user, $q, $nr);
							break;
		case "tz": 			session_start();
							$_SESSION['tzname'] = $_POST['tzname'];
							break;
		default:			$engine_session->headerin();
							break;
	}
}
else
{
	$engine_session->headerin();
}
?>