<?php
include_once("inc/conn.php");
include_once("inc/function.php");
login_check();

$query=$db->query("Select * from {$web_dbtop}adsp where id=".intval($_GET["adid"]));
if($rs=$db->fetch_array($query)){
	$adid=$rs["id"];
	$adtitle=$rs["title"];
	$dailynum=$rs["dailynum"];
	$points=$rs["points"];
	$adurl=$rs["adurl"];
	$adtype=$rs["type"];
}

$db->query("delete from {$web_dbtop}adip where type=".$adtype." and STR_TO_DATE(time,'%Y-%m-%d')<'".date('Y:m:d')."'");
$query=$db->query("Select id from {$web_dbtop}adip where uid=".intval($_COOKIE["usersid"])." and type=".$adtype." and adid=".$adid."");
if($rs=$db->fetch_array($query)){
	$num=$db->num_rows($query);
}
if($dailynum<=$num){
	echo "<script language=javascript>location.href='".$adurl."';</script>";
}else{
	$db->query("insert into {$web_dbtop}adlogusers (adtitle,uid,uip,time,adpoints,type) values ('".$adtitle."',".intval($_COOKIE["usersid"]).",'".usersip()."','".date("Y-m-d H:i:s")."',".$points.",".$adtype.")");
	$db->query("insert into {$web_dbtop}adip (uid,ip,time,type,adid) values (".intval($_COOKIE["usersid"]).",'".usersip()."','".date("Y-m-d H:i:s")."',".$adtype.",".$adid.")");
	echo "<script language=javascript>location.href='".$adurl."';</script>";
}
?>