<?php


session_start();
include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];

if ($_SESSION[USERID] != "" && $_SESSION[USERID] >= 0 && is_numeric($_SESSION[USERID]))
{
	$messageid = htmlentities(strip_tags($_REQUEST[messageid]));
	$messageid = escape($messageid);
	
	if (is_numeric($messageid))
	{
		$query = "SELECT MSGTO from messages_inbox where MID='".mysql_real_escape_string($messageid)."' order by MID desc limit 1";
		$executequery = $conn->Execute($query);
		$MSGTO = $executequery->fields[MSGTO];

		if (is_numeric($MSGTO) && $MSGTO != "" && $MSGTO == $_SESSION[USERID])
		{
			$query = "DELETE FROM messages_inbox where MID='".mysql_real_escape_string($messageid)."' limit 1";
			$conn->Execute($query);
			
			if(mysql_affected_rows()==1)
			{
				$error = "1";
			}
			else
			{
				$error = "0";
			}
		}
		else
		{
			$error = "0";
		}
	
	}
	else
	{
		$error = "0";
	}
	header("Location:$config[baseurl]/myinbox.php?deleted=$error");

}
else
{
	header("Location:$config[baseurl]/login.php");exit;
}

?>