<? include('checkcookie.php'); ?>
<h3>Просмотр сообщений в чате</h3>
<br>
<?
if (isset($_POST["user1"]))
{
	$user=$_POST["user1"];
	$reason=$_POST["reason"];
	
	mysql_query("insert into tb_chatban (user,reason) values ('$user','$reason')");
	echo "<font color=\"#00dd00\"><b>Бан на пользователя $user наложен.</b></font><br><br>";
}

if (isset($_GET["id"]))
{
	$id=$_GET["id"];
	$option=$_GET["option"];

	if ($option=="delete")
	{
		$queryz = "DELETE FROM tb_chat WHERE id='$id'";
		mysql_query($queryz) or die(mysql_error());
		echo "<font color=\"#dd0000\"><b>Сообдение удалено.</b></font><br><br>";
	}
	
	if ($option=="ban")
	{
		$user=$_POST["user"];

		?>
		<form method="post" action="adminmain.php?p=chatlist&option=save">
			<b>Причина бана:</b>&nbsp;<input type="text" name="reason" size="30" maxlength="150" value=""><br>
			<input type="hidden" value="<?=$user ?>" name="user1">
			<input type="submit" value="Сохранить">
		</form>
		<?
	}
}
?>

<table cellspacing="0" cellpadding="0">
<tr align="center">
<th>Имя пользователя</th>
<th>IP адрес</th>
<th>Текст сообщения</th>
<th>Дата и время сообщения</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<?
$res = mysql_query("SELECT * FROM tb_chat ORDER BY id DESC");
while ($row = mysql_fetch_array($res)) {

echo "
<tr align=\"center\">
<td>". $row["user"] ."</td>
<td>". $row["ip"] ."</td>
<td>". $row["message"] ."</td>
<td>". date("d.m.Y H:i", $row["data"]) ."</td>
<td>";
?>
<form method="post" action="adminmain.php?p=chatlist&id=<?=$row["id"] ?>&option=ban">
<input type="hidden" name="user" value="<?=$row["user"] ?>">
<input type="submit" value="Бан пользователя" class="button">
</form>
</td>
<td>
<form method="post" action="adminmain.php?p=chatlist&id=<?=$row["id"] ?>&option=delete">
<input type="submit" value="Удалить сообщение" class="button">
</form>
</td>
</tr>

<?

}

?>
</table>