<? include('checkcookie.php'); ?>
<h3>Просмотр рекламы в чате</h3>
<br>
<?
if (isset($_POST["id"]))
{
	$id=$_POST["id"];
	$url=$_POST["url"];
	$text=$_POST["text"];
	
	mysql_query("update tb_chatads set link='$url',text='$text' where id='$id'");
	echo "<font color=\"#00dd00\"><b>Реклама в чате сохранена.</b></font><br><br>";
}

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

	if ($option=="delete")
	{
		$queryz = "DELETE FROM tb_chatads WHERE id='$id'";
		mysql_query($queryz) or die(mysql_error());
		echo "<font color=\"#dd0000\"><b>Реклама в чате удалена.</b></font><br><br>";
	}
	
	if ($option=="edit")
	{
		$url=$_POST["url"];
		$text=$_POST["text"];

		?>
		<form method="post" action="adminmain.php?p=chatadsview&option=save">
			<b>URL:</b>&nbsp;<input type="text" name="url" size="30" maxlength="150" value="<?=$url ?>"><br>
			<b>Текст ссылки:</b>&nbsp;<input type="text" name="text" size="30" maxlength="150" value="<?=$text ?>"><br><br>
			<input type="hidden" value="<?=$id ?>" name="id">
			<input type="submit" value="Сохранить">
		</form>
		<?
	}
}
?>

<table cellspacing="0" cellpadding="0">
<tr align="center">
<th>WMID</th>
<th>URL</th>
<th>Текст ссылки</th>
<th>Дата и время завершения показа</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<?
$res = mysql_query("SELECT * FROM tb_chatads ORDER BY id ASC");
while ($row = mysql_fetch_array($res)) { 

echo "
<tr align=\"center\">
<td>". $row["wmid"] ."</td>
<td><a href=\"". $row["link"] ."\" target=\"_blank\">". $row["link"] ."</a></td>
<td>". $row["text"] ."</td>
<td>". date("d.m.Y H:i", $row["enddate"]) ."</td>
<td>";
?>
<form method="post" action="adminmain.php?p=chatadsview&id=<?=$row["id"] ?>&option=edit">
<input type="hidden" name="url" value="<?=$row["link"] ?>">
<input type="hidden" name="text" value="<?=$row["text"] ?>">
<input type="submit" value="Редактировать" class="button">
</form>
</td>
<td>
<form method="post" action="adminmain.php?p=chatadsview&id=<?=$row["id"] ?>&option=delete">
<input type="submit" value="Удалить" class="button">
</form>
</td>
</tr>

<?

}

?>
</table>