<? include('checkcookie.php'); ?>
<h3>Заказы рекламы в каталоге ссылок</h3>
<br>

<?
if (isset($_GET["id"]))
{

$id=$_GET["id"];
$option=$_GET["option"];
$wmid=$_POST["wmid"];
$plan=$_POST["plan"];
$linksite=$_POST["linksite"];
$text=$_POST["text"];
$t=time();
$t=$t+$plan*24*3600;

if ($option=="approve")
{
	$query = "INSERT INTO tb_catads (wmid,link,text,enddate) VALUES('$wmid','$linksite','$text','$t')";
	mysql_query($query) or die(mysql_error());

	$queryz = "DELETE FROM tb_catadsreq WHERE id='$id'";
	mysql_query($queryz) or die(mysql_error());

	echo "<font color=\"red\"><b>Ссылка добавлена</b></font><br><br>";
}

if ($option=="deny")
{
	$queryz = "DELETE FROM tb_catadsreq WHERE id='$id'";
	mysql_query($queryz) or die(mysql_error());

	echo "<font color=\"#cc0000\"><b>Заказ удален.</b></font><br><br>";
}

}
?>
<table>
	<tr>
		<th>№</th>
		<th>WMID</th>
		<th>URL</th>
		<th>Текст ссылки</th>
		<th>Дней для показа</th>
		<th></th>
		<th></th>
	</tr>
<?
$tabla = mysql_query("SELECT * FROM tb_catadsreq ORDER BY id ASC");
while ($registro = mysql_fetch_array($tabla)) {

echo "
<tr>
<td>". $registro["id"] ."</td>
<td>". $registro["wmid"] ."</td>
<td><a href=\"". $registro["link"] ."\" target=\"_blank\">". $registro["link"] ."</a></td>
<td>". $registro["text"] ."</td>
<td>". $registro["plan"] ."</td>
<td>";
?>
<form method="post" action="adminmain.php?p=catadsreq&id=<?= $registro["id"] ?>&option=approve">
<input type="hidden" name="plan" value="<?= $registro["plan"] ?>">
<input type="hidden" name="linksite" value="<?= $registro["link"] ?>">
<input type="hidden" name="text" value="<?= $registro["text"] ?>">
<input type="hidden" name="wmid" value="<?= $registro["wmid"] ?>">
<input type="submit" value="Добавить" class="button">
</form>
</td><td>
<form method="post" action="adminmain.php?p=catadsreq&id=<?= $registro["id"] ?>&option=deny">
<input type="submit" value="Удалить" class="button">
</form>
</td>
</tr>

<?

} 

?>
</table>