<? include('checkcookie.php'); ?>
<h3>Просмотр и редактирование ссылок</h3>
<br>

<?
if (isset($_POST["id"]))
{
	$id=$_POST["id"];
	$plan=$_POST["plan"];
	$url=$_POST["url"];
	$description=$_POST["description"];
	$highlight=$_POST["highlight"];
	$timer=$_POST["timer"];
	$dopsec=$_POST["dopsec"];
	$vip=$_POST["vip"];

	$query = "UPDATE tb_ads1 SET vip='$vip', timer='$timer', highlight='$highlight', plan='$plan', url='$url', description='$description', dopsec='$dopsec' where id='$id'";
	mysql_query($query) or die(mysql_error());
	echo "<font color=\"green\"><b>Изменения сохранены</b></font><br><br>";
}

if (isset($_GET["id"]))
{
	$id=$_GET["id"];
	$option=$_GET["option"];
	if ($option=="edit")
	{
		$res = mysql_query("SELECT * FROM tb_ads1 where id='$id'");
		while ($row = mysql_fetch_array($res))
		{ 
			?>
			<form method="post" action="adminmain.php?p=editrekl1">

			№: <input type="hidden" name="id" value="<?= $row["id"] ?>"><?= $row["id"] ?><br>
			Заказано просмотров: <input type="text" name="plan" value="<?= $row["plan"] ?>"><br>
			Таймер: <input type="text" name="timer" value="<?= $row["timer"] ?>"><br>
			URL: <input type="text" name="url" value="<?= $row["url"] ?>"><br>
			Описание: <input type="text" name="description" value="<?= $row["description"] ?>"><br>
			Выделение: <input type="text" name="highlight" value="<?= $row["highlight"] ?>"><br>
			Доп. защита (<? if($row["dopsec"]!='0') { echo "Да"; }else{ echo "Нет"; } ?>): <select name="dopsec">
				<option value="<?=$row["dopsec"]?>"></option>
				<option value="0">Нет</option>
				<option value="1">Да</option>
			</select>
			<br>
			Размещение в VIP блоке (<? if($row["vip"]!='0') { echo "Да"; }else{ echo "Нет"; } ?>): <select name="vip">
				<option value="<?=$row["vip"]?>"></option>
				<option value="0">Нет</option>
				<option value="1">Да</option>
			</select>
			<br>
			<input type="submit" value="Сохранить" class="button">
			</form>
			<br><br>
			<?
		}
	}
	if ($option=="delete")
	{
		$queryz = "DELETE FROM tb_ads1 WHERE id='$id'";
		mysql_query($queryz) or die(mysql_error());
		echo "<font color=\"#cc0000\"><b>Реклама удалена.</b></font><br><br>";
	}
}
?>
<table cellspacing="0" cellpadding="0">
<tr>
<th width=50 align=center>№</th>
<th width=50 align=center>URL</th>
<th>Описание</th>
<th align=center>Просмотров</th>
<th align=center>Таймер</th>
<th align=center>Логин заказчика</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<?
$res = mysql_query("SELECT * FROM tb_ads1 where tipo='ads' ORDER BY id ASC");
while ($row = mysql_fetch_array($res)) { 

echo "
<tr>
<td align=center width=50>". $row["id"] ."</td>
<td align=center width=50><a href=\"". $row["url"] ."\" target=\"_blank\">". $row["url"] ."</a></td>
<td>". $row["description"] ."</td>
<td align=center>". $row["plan"] ."</td>
<td align=center>". $row["timer"] ."</td>
<td align=center>". $row["paypalemail"] ."</td>
<td>";
?>
<form method="post" action="adminmain.php?p=editrekl1&id=<?= $row["id"] ?>&option=edit">
<input type="submit" value="Редактировать" class="button">
</form>
</td>
<td>
<form method="post" action="adminmain.php?p=editrekl1&id=<?= $row["id"] ?>&option=delete">
<input type="submit" value="Удалить" class="button">
</form>
</td>
</tr>
<?
}
?>
</table>