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

<?
if (isset($_GET["id"]))
{
	$id=$_GET["id"];
	$option=$_GET["option"];
	$urlsite=$_POST["urlsite"];
	$description=$_POST["description"];
	$wmid=$_POST["wmid"];
       	$cvet=$_POST["cvet"];
	$plan=$_POST["plan"];
	$t=time();

$sql="select price from tb_config where item='advstatlink'";
$res=mysql_query($sql);
$sl=mysql_result($res,0,0);
	$sql="select price from tb_config where item='cvet_link'";
$res=mysql_query($sql);
$cvet1=mysql_result($res,0,0);
	$precio=$plan*$sl;
	if ($cvet==1) { $price=$price+$cvet1; }
	
	if ($option=="approve")
	{
	$nums=mysql_num_rows(mysql_query("SELECT * FROM sfb_advs WHERE wmid='$wmid'"));
	if($nums==0) mysql_query("INSERT INTO sfb_advs (wmid,summ,data) VALUES ('$wmid','$precio','$t')");
	if($nums==1) mysql_query("UPDATE sfb_advs SET data='$t',summ=summ+'$precio' WHERE wmid='$wmid'");

		$query = "INSERT INTO tb_statlinks (url,description,cvet,wmid,leftblock,begindate,numdays) VALUES('$urlsite','$description','$cvet','$wmid','$lb','$t','$plan')";
		mysql_query($query) or die(mysql_error());

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

		$sql="select * tb_statlinks order by id asc";
		$res=mysql_query($sql);

		$res=mysql_query("select * from tb_comp where param='7'");
		if(mysql_num_rows($res)>0)
		{
			while($row=mysql_fetch_array($res))
			{
				$id=$row["id"];
				$lidertype=$row["lidername"];
				$t=time();
				$sd=strtotime($row["startdate"]);
				$ed=strtotime($row["enddate"]);
				if($t>$sd && $t<$ed)
				{
					if($lidertype=='0')
					{
						$res1=mysql_query("select username from tb_users where wmid='$wmid'");
						if(mysql_num_rows($res1)>0){$res1=mysql_fetch_array($res1); $lidername=$res1["username"];}else{$lidername='';}
					}else{
						$lidername=$wmid;
					}
					if($lidername!='')
					{
						$res1=mysql_query("select * from tb_compdata where idk='$id' and user='$lidername'");
						if(mysql_num_rows($res1)>0)
						{
							$res1=mysql_Fetch_array($res1);
							$resvalue=$res1["resvalue"]+$plan;
							$purse='';
							mysql_query("update tb_compdata set resvalue='$resvalue', purse='$purse' where id='".$res1["id"]."'");
						}else{
							$purse='';
							mysql_query("insert into tb_compdata (idk,user,resvalue,purse) values ('$id','$lidername','$plan','$purse')");
						}
					}
				}
			}
		}

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

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

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

<table width='100%' border='0' cellpadding='0' cellspacing='0'>
	<tr>
		<th>№</th>
		<th>WMID</th>
		<th>URL сайта</th>
		<th>Текст ссылки</th>
		<th>Дней показа</th>
		<th>Цвет</th>
		<th></th>
		<th></th>
	</tr>
<?
$tabla = mysql_query("SELECT * FROM tb_statlinksreq ORDER BY id ASC");
while ($registro = mysql_fetch_array($tabla)) {

echo "
<tr>
<td>". $registro["id"] ."</td>
<td>". $registro["wmid"] ."</td>
<td><a href=\"". $registro["url"] ."\" target=\"_blank\">". $registro["url"] ."</a></td>
<td>". $registro["description"] ."</td>
<td>". $registro["plan"] ."</td><td>";
if($registro["cvet"]=='1') { echo "Да"; }else{ echo "Нет"; }
echo "</td><td>";
?>
<form method="post" action="adminmain.php?p=statlinkreq&id=<?= $registro["id"] ?>&option=approve">
<input type="hidden" name="urlsite" value="<?= $registro["url"] ?>">
<input type="hidden" name="description" value="<?= $registro["description"] ?>">
<input type="hidden" name="wmid" value="<?= $registro["wmid"] ?>">
<input type="hidden" name="plan" value="<?= $registro["plan"] ?>">
<input type="hidden" name="cvet" value="<?= $registro["cvet"] ?>">
<input type="submit" value="Добавить" class="button">
</form>
</td><td>
<form method="post" action="adminmain.php?p=statlinkreq&id=<?= $registro["id"] ?>&option=deny">
<input type="submit" value="Удалить" class="button">
</form>
</td>
</tr>

<?

} 

?>
</table>