<? include('checkcookie.php'); ?>
<h3>Заказы ссылок</h3>
<br>

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

$id=$_GET["id"];
$option=$_GET["option"];
$pemail=$_POST["paypalemail"];
$plan=$_POST["plan"];
$url=$_POST["url"];
$description=$_POST["description"];
$bold=$_POST["bold"];
$highlight=$_POST["highlight"];
$fechainicia=time();
$timer=$_POST["timer"];
$dopsec=$_POST["dopsec"];
$vip=$_POST["vip"];
$act=$_POST["act"];
$date=time();
$res=mysql_query("select count(id) as kolvo from tb_ads where vip='1'");
$res=mysql_fetch_array($res);
$vipmest1=$res["kolvo"];
$res=mysql_query("select count(id) as kolvo from tb_ads where vip='1'");
$res=mysql_fetch_array($res);
$vipmest2=$res["kolvo"];
$vipmest=$vipmest1+$vipmest2;
$res=mysql_query("select price from tb_config where item='vipcount'");
$res=mysql_Fetch_array($res);
$vipcount=$res["price"];
$sql="select price from tb_config where item='hits'";
$res=mysql_query($sql);
$dyn=mysql_result($res,0,0);
$sql="select price from tb_config where item='hldyn'";
$res=mysql_query($sql);
$hldyn=mysql_result($res,0,0);
$sql="select price from tb_config where item='timer5'";
$res=mysql_query($sql);
$timer5=mysql_result($res,0,0);
$sql="select price from tb_config where item='dopsec'";
$res=mysql_query($sql);
$ds=mysql_result($res,0,0);
$sql="select price from tb_config where item='vipblock'";
$res=mysql_query($sql);
$vipprice=mysql_result($res,0,0);
$sql="select price from tb_config where item='actwin'";
$res=mysql_query($sql);
$vipprice=mysql_result($res,0,0);
$sql="select price from tb_config where item='captcha'";
$res=mysql_query($sql);
$captcha=mysql_result($res,0,0);
$tim=0;
if($timer==25) $tim=1;
if($timer==30) $tim=2;
if($timer==35) $tim=3;
if($timer==40) $tim=4;
$precio=$dyn*$plan+$tim*$timer5+$vipprice*$vip*$act;
if ($highlight==1) { $precio=$precio+$hldyn; }
if ($dopsec==1) { $precio=$precio+$ds; }
if ($dopsec==2) { $precio=$precio+$captcha; }

if ($option=="approve"){
	$nums=mysql_num_rows(mysql_query("SELECT * FROM sfb_advs WHERE wmid='$pemail'"));
	if($nums==0) mysql_query("INSERT INTO sfb_advs (wmid,summ,data) VALUES ('$pemail','$precio','$date')");
	if($nums==1) mysql_query("UPDATE sfb_advs SET data='$date',summ=summ+'$precio' WHERE wmid='$pemail'");

    $query = "INSERT INTO tb_ads (fechainicia, act, paypalemail, plan, url, description, tipo, highlight, timer, dopsec, vip, status) VALUES('$fechainicia','$act','413649037837','$plan','$url','$description','ads','$highlight', '$timer', '$dopsec','$vip','0')";
    mysql_query($query) or die(mysql_error());

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

	$t=date("d.m.Y", time());
		$res=mysql_query("select count(id) as kol from tb_adsdate where data='$t'");
	$res=mysql_Fetch_array($res);
	if($res["kol"]>0)
	{
		mysql_query("update tb_adsdate set kolvo=kolvo+1 where data='$t'");
	}else{
		mysql_query("insert into tb_adsdate (data,kolvo) values ('$t','1')");
	}

    echo "<font color=\"green\"><b>Реклама добавлена.</b></font><br><br>";
}

if ($option=="deny"){

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

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


}
?>

<table width='100%' border='0' cellpadding='0' cellspacing='0'>
	<tr>
		<th>№</th>
		<th>WMID</th>
		<th>Визитов</th>
		<th>Таймер</th>
		<th>URL</th>
		<th>Описание</th>
		<th>Выделение</th>
		<th>Доп. защита</th>
		<th>Размещение в VIP блоке</th>
		<th>Размещение в Акт</th>
		<th></th>
		<th></th>
	</tr>
<?
$tabla = mysql_query("SELECT * FROM tb_ads where tipo='ads' and status='1' ORDER BY id ASC");
while ($registro = mysql_fetch_array($tabla)) {

echo "
<tr>
<td>". $registro["id"] ."</td>
<td>". $registro["paypalemail"] ."</td>
<td>". $registro["plan"] ."</td>
<td>". $registro["timer"] ."</td>
<td><a href=\"". $registro["url"] ."\" target=\"_blank\">". $registro["url"] ."</a></td>
<td>". $registro["description"] ."</td>
<td>". $registro["highlight"] ."</td><td>"; 
if($registro["dopsec"]=='0') echo "Нет";
if($registro["dopsec"]=='1') echo "Подтверждение просмотра";
if($registro["dopsec"]=='2') echo "Ввод каптчи";
echo "</td><td>";
if($registro["vip"]!='0') { echo "Да"; }else{ echo "Нет"; }
echo "</td><td>";
if($registro["act"]!='0') { echo "Да"; }else{ echo "Нет"; }
echo "</td><td>";
?>
<form method="post" action="adminmain.php?p=viewreklreq&id=<?= $registro["id"] ?>&option=approve">
<input type="hidden" name="pemail" value="<?= $registro["pemail"] ?>">
<input type="hidden" name="plan" value="<?= $registro["plan"] ?>">
<input type="hidden" name="timer" value="<?= $registro["timer"] ?>">
<input type="hidden" name="url" value="<?= $registro["url"] ?>">
<input type="hidden" name="description" value="<?= $registro["description"] ?>">
<input type="hidden" name="highlight" value="<?= $registro["highlight"] ?>">
<input type="hidden" name="dopsec" value="<?= $registro["dopsec"] ?>">
<input type="hidden" name="vip" value="<?= $registro["vip"] ?>">
<input type="hidden" name="act" value="<?= $registro["act"] ?>">
<input type="submit" value="добавить" class="button">
</form>
</td><td>
<form method="post" action="adminmain.php?p=viewreklreq&id=<?= $registro["id"] ?>&option=deny">
<input type="submit" value="удалить" class="button">
</form>
</td>
</tr>
<?
} 
?>
</table>