<?
session_start();
define("beerman", true);
require('funciones.php');
include('sfb.php');
$nameus=$_SESSION["username"];
$urlpage='<font color=#ff0000>Зарабатывает</font>';

$uo_sessionTime = 1;
error_reporting(E_ERROR | E_PARSE);
$uo_ip = $_SERVER['REMOTE_ADDR'];
$uo_query = "DELETE FROM users_online WHERE unix_timestamp() - lastvisit >= $uo_sessionTime * 60";
mysql_query($uo_query);

$uo_query = "SELECT lastvisit FROM users_online WHERE visitor = '$uo_ip'";
$uo_result = mysql_query($uo_query);
if(mysql_num_rows($uo_result) == 0) {
	$uo_query = "INSERT INTO users_online (visitor,lastvisit,user,urlpage) VALUES('$uo_ip', unix_timestamp(), '$nameus', '$urlpage')";
	mysql_query($uo_query);
} else {
	$uo_query = "UPDATE users_online SET lastvisit = unix_timestamp(), urlpage='$urlpage', user='$nameus' WHERE visitor = '$uo_ip'";
	mysql_query($uo_query);
}


$ad=$_GET["ad"];
if(!ereg("^[0-9]{1,255}$", $ad))
{
	$ad=-1;
}
$ad=intval($ad);

$res=mysql_query("select count(*) as kolvo from tb_ads_p where id='$ad'");
$res=mysql_fetch_array($res);

$kolvo=$res["kolvo"];
if ($kolvo<1)
{
	echo "<img src=\"frmimg/error.png\" align=\"middle\">&nbsp;Ссылка не существует";
	exit();
}


$res=mysql_query("select url, description, timer from tb_ads_p where id='$ad'");
$res=mysql_fetch_array($res);

$urlsite=$res["url"];

$_SESSION["urlsite"]=$res["url"];
$_SESSION["desc"]=$res["description"];
if($res[timer]==0) $res[timer]=1;
if($res[timer]==1) $res[timer]=1;
if($res[timer]==2) $res[timer]=1;
if($res[timer]==3) $res[timer]=1;
if($res[timer]==4) $res[timer]=1;

$_SESSION["timer"]=$res["timer"];
$_SESSION["ad"]=$ad;

if($_SESSION["username"]==NULL)
{



	?>
	<script type="text/javascript">
	location.replace("<?=$urlsite?>");
	</script>
	<noscript>
	<meta http-equiv="refresh" content="0; url=<?=$urlsite?>">
	</noscript>
	<?
}
?>

<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<title>Фото-охота от WM Rush</title>
<link rel="shortcut icon" href="favicon.png" />
<frameset rows="120,*" bordercolor="#555555" frameborder="0" framespacing="0">
<frame marginwidth="0" marginheight="0" name="main" scrolling="no" noresize src="vls1.php">
<frame src="<?=$urlsite ?>" name="menu">
</frameset>
</head>
</html>