<?
session_start();

$nameus=$_SESSION["username"];
$urlpage='<font color=#ff0000>Зарабатывает</font>';

require('config.php');

$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);
}

mysql_close($con);

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

require('config.php');
$res=mysql_query("select count(*) as kolvo from tb_ads1 where id='$ad'");
$res=mysql_fetch_array($res);
mysql_close($con);

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

require('config.php');
$res=mysql_query("select url, description, timer, outside from tb_ads1 where id='$ad'");
$res=mysql_fetch_array($res);
mysql_close($con);

$urlsite=$res["url"];

$_SESSION["urlsite"]=$res["url"];
$_SESSION["desc"]=$res["description"];
$_SESSION["timer"]=$res["timer"];
$_SESSION["ad"]=$ad;

if($_SESSION["username"]==NULL)
{
	$outside=$res["outside"]+1;
	
	require('config.php');
	mysql_query("update tb_ads1 set outside='$outside' where id='$ad'");
	mysql_close($con);

	?>
	<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><? include('sitename.php'); ?> - Система Активной Рекламы</title>

<frameset rows="31,25,*">
<frame marginwidth="0" marginheight="0" name="frminfo" scrolling="no" noresize src="vls1.php">
<frame name="frmads" noresize scrolling="no" marginwidth="0" marginheight="0" src="vfa.php">
<frame name="frmsite" src="<?=$urlsite ?>">
</frameset>

</head>
</html>