<? include('checkcookie.php'); ?>
<h3>Просмотр и редактирование баннеров</h3>
<br>
<?
if (isset($_POST["id"]))
{
	$id=$_POST["id"];
	$urlsite=$_POST["urlsite"];
	$urlpic=$_POST["urlpic"];
	$numdays=$_POST["numdays"];
	
	mysql_query("update tb_advban set urlsite='$urlsite', urlpic='$urlpic', numdays='$numdays' 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")
	{
		mysql_query("DELETE FROM tb_advban WHERE id='$id'");
		echo "<font color=\"#dd0000\"><b>Баннер удален.</b></font><br><br>";
	}
	if ($option=="edit")
	{
		$urlsite=$_POST["urlsite"];
		$urlpic=$_POST["urlpic"];
		$numdays=$_POST["numdays"];

		?>
		<form method="post" action="adminmain.php?p=bannerview&option=save">
			<b>URL сайта:</b>&nbsp;<input type="text" name="urlsite" size="30" maxlength="150" value="<?=$urlsite ?>"><br>
			<b>URL баннера:</b>&nbsp;<input type="text" name="urlpic" size="30" maxlength="150" value="<?=$urlpic ?>"><br>
			<b>Количество дней для показа:</b>&nbsp;<input type="text" name="numdays" size="10" maxlength="5" value="<?=$numdays ?>"><br><br>
			<input type="hidden" value="<?=$id ?>" name="id">
			<input type="submit" value="Сохранить">
		</form>
		<?
	}
}
?>

<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<th>URL сайта</th>
<th>URL баннера</th>
<th>Дней показа</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<?
$res = mysql_query("SELECT * FROM tb_advban ORDER BY id ASC");
while ($row = mysql_fetch_array($res)) { 

echo "
<tr>
<td><a href=\"". $row["urlsite"] ."\" target=\"_blank\">". $row["urlsite"] ."</a></td>
<td><a href=\"". $row["urlpic"] ."\" target=\"_blank\">". $row["urlpic"] ."</a></td>
<td>". $row["numdays"] ."</td>
<td>";
?>
<form method="post" action="adminmain.php?p=bannerview&id=<?= $row["id"] ?>&option=edit">
<input type="hidden" name="urlsite" value="<?=$row["urlsite"] ?>">
<input type="hidden" name="urlpic" value="<?=$row["urlpic"] ?>">
<input type="hidden" name="numdays" value="<?=$row["numdays"] ?>">
<input type="submit" value="Редактировать" class="button">
</form>
</td>
<td>
<form method="post" action="adminmain.php?p=bannerview&id=<?= $row["id"] ?>&option=delete">
<input type="submit" value="Удалить" class="button">
</form>
</td>
</tr>

<?

}

?>
</table>