<?php

session_start();
ob_start();

include "config.php";
include "inc/memberfunctions.php";
include "inc/functions.php";
$pageid ='';
if(isset($_REQUEST['pageid'])) $pageid = $_REQUEST['pageid'];
if(isset($_REQUEST['t'])) $type = $_REQUEST['t'];
if(isset($_REQUEST['u'])) $rid = $_REQUEST['u'];
if(isset($_REQUEST['uid'])) $userid = $_REQUEST['uid'];
if(isset($_REQUEST['adid'])) $adid = $_REQUEST['adid'];
if(isset($_REQUEST['url'])) $url = $_REQUEST['url'];
if(isset($_REQUEST['num'])) $num = $_REQUEST['num'];
if(isset($_REQUEST['message'])) $message = $_REQUEST['message'];
if(isset($_REQUEST['btyp'])) $table = $_REQUEST['btyp'];


if(isset($_COOKIE['uid'])) $userid = $_COOKIE['uid'];
if(isset($_SESSION['uname'])) 

$redirecturl="<a href=/members/index.php target=_top>Go back to the member area</a>";
else $redirecturl="<a href=./index.php target=_top><font color=BLUE>>> Account Login <<</a>";

$uid = uid($rid);
setcookie('uid', $uid, time()+60);
if($pageid == 2) {
docform ();
if(!$_GET['message']) {
	$afloat = base64_encode(" " . $num1 = rand(0,3) . "." . $num2 = rand(100,999) . "
	 Float " . $num3 = rand(1,4) . "." . $num4 = rand(100,999) . "  ");
	$aler = "> 139";
	if(round($num1 . "." . $num2) <= round($num3 . "." . $num4)) {$aler = "< 146";}
	$_SESSION['igif_'.$_GET['adid']] = "create_gif.php?a=" . $afloat . "";
	$_SESSION['afloat_'.$_GET['adid']] = $afloat;
}
?>
<html>
<head>
<style type="text/css">
a:hover, a:visited, a:link, a:active
{
    font-family: Tahoma;
    font-size: 11pt;
    text-decoration: none !important;
}
/* click image */
.cd {
width: 285px;
height: 30px;
background-image: url(<?=$_SESSION['igif_'.$_GET['adid']]."&uid=".$_GET['uid']."&c=".$_GET['adid'];?>);
background-repeat: no-repeat;
position: relative;
z-index: 2;
}
</style>
</head>
<?
echo "<body background=\"/images/frame.png\">";
if($message) {
$str=textlink($userid,$url);
print $str;
print $_GET['message'];
include "banners.php"; 
exit();
}
$str=textlink($userid,$url);
print $str;
$adcredittimer = "10";
$memtype = umemtype($userid);
$earn=adearn($type,$userid,$memtype,$adid);
echo countdowntime($type,$earn,$adcredittimer);
include "banners.php";
} elseif($pageid == 3) {
?>
<style>
a:hover, a:visited, a:link, a:active
{
    font-family: Tahoma;
    font-size: 11pt;
    text-decoration: none !important;
}
</style>
<?
echo "<body background=\"/images/frame.png\">";
$str=textlink($userid,$url);
print $str;
$memtype = umemtype($userid);
$earn=adearn($type,$userid,$memtype,$adid);
// if submit
	if (($_POST[x])&&(substr($_SESSION['igif_'.$adid], 17) === $_SESSION['afloat_'.$adid])){

	// posted
	$x = $_POST[x];

	// decode, strip string and round numbers
	$a = base64_decode($_SESSION['afloat_'.$adid]);
	$b = 0 + $a;
	$a = explode(" ", $a);
	$a = $a[3];
	$bb = round($b);
	$aa = round($a);

	// x coords
	$gc = explode(" ", '0 30 58 85 112 139 146 174 199 225 254 285');

	// check if correct number has been clicked
	$ac = $aa + 6;
	if ($bb <= $aa){ $ac = $bb + 1; }

		unset($_SESSION['afloat_'.$adid]);
		unset($_SESSION['igif_'.$adid]);
	
		#mysql_query("UPDATE members SET captcha_clicks=captcha_clicks+1 WHERE userid = '$userid'");
	
		if (($x >= $gc[$ac-1]) && ($x <= $gc[$ac])){	
$queryupdate=updatestats($type,$earn,$adid,$userid);
$condition=condition($type);
$cstr = "<div align=center><b>You have earned&nbsp;";
if($condition=="commissions") {
$cstr .="$";
} $cstr .="$earn $condition - ".$redirecturl." </b></div>";
print $cstr;
  
} else {	
			#mysql_query("UPDATE members SET captcha_invalid=captcha_invalid+1 WHERE userid = '$userid'");
			echo "<center>You clicked the wrong number.</center>";		
		}
}
include "banners.php"; 
}
elseif($pageid == 4) {
ob_start();
$getbanner = mysql_query("Select id, url from $table WHERE id='".$adid."'");
$bannerid = mysql_result($getbanner, 0, "id");
$bannerurl = mysql_result($getbanner, 0, "url");
updatenosessionb($table, $bannerid);
$url = $bannerurl;
header('Location: '.$url);
ob_flush();
}
elseif($pageid == 5) {
ob_start();
$getdata = mysql_query("Select id, url from $table WHERE id='".$adid."'");
$id = mysql_result($getdata, 0, "id");
$url = mysql_result($getdata, 0, "url");
updatenosessions($table, $id);
$url = $url;
header('Location: '.$url);
ob_flush();
}
elseif($pageid == 6) {
ob_start();
$getbanner = mysql_query("Select id, url from texts WHERE id='".$adid."'");
$bannerid = mysql_result($getbanner, 0, "id");
$bannerurl = mysql_result($getbanner, 0, "url");
updatenosessiont($bannerid);
$url = $bannerurl;
header('Location: '.$url);
ob_flush();
}
elseif($pageid == 7) {
ob_start();
$getbanner = mysql_query("Select id, url from membermail WHERE id='".$adid."'");
$bannerid = mysql_result($getbanner, 0, "id");
$bannerurl = mysql_result($getbanner, 0, "url");
$url = $bannerurl;
header('Location: '.$url);
ob_flush();
}
else {
if(empty($type)) {
$adid = 0;
$adurl = $domain;
$top = "earn.php?pageid=2&uid=".$uid."&message=".urlencode("<div align=center><b>Invalid Ad - ".$redirecturl." </b></div>")."&adid=".$adid."&url=".urlencode($adurl);
} 
elseif(empty($num)) {
$adid = 0;
$adurl = $domain;
$top = "earn.php?pageid=2&uid=".$uid."&message=".urlencode("<div align=center><b>Invalid Ad - ".$redirecturl." </b></div>")."&adid=".$adid."&url=".urlencode($adurl);
}
elseif(empty($rid)) {
$adid = 0;
$adurl = $domain;
$top = "earn.php?pageid=2&uid=".$uid."&message=".urlencode("<div align=center><b>Invalid Member Account - ".$redirecturl." </b></div>")."&adid=".$adid."&url=".urlencode($adurl);
} else {
$adresult = adtype($type,$uid,$adid,$num);
if(@mysql_num_rows($adresult)) {
$adid = mysql_result($adresult,0,"id");
$adurl = mysql_result($adresult,0,"url");
$top = "earn.php?pageid=2&t=".$type."&uid=".$uid."&adid=".$adid."&url=".urlencode($adurl);
} else {
$adresult = adtype2($type,$adid);
if(@mysql_num_rows($adresult)) {
$adid = mysql_result($adresult,0,"id");
$adurl = mysql_result($adresult,0,"url");
$top = "earn.php?pageid=2&uid=".$uid."&message=".urlencode("<div align=center><b>You Already Viewed This Ad - ".$redirecturl." </b></div>")."&adid=".$adid."&url=".urlencode($adurl);
} else {
$adid = 0;
$adurl = $domain;
$top = "earn.php?pageid=2&uid=".$uid."&message=".urlencode("<div align=center><b>Invalid Ad - ".$redirecturl." </b></div>")."&adid=".$adid."&url=".urlencode($adurl);
}
}
}
if(empty($adurl)) $adurl = $domain;
?>
<title>Earn Credits</title>
<frameset rows="175,*" border=0 frameborder=1 framespacing=0>
<frame name="header" scrolling="no" noresize marginheight="1" marginwidth="1" target="main" src="<?php echo $top ?>">
<frame name="main" src="<?php echo $adurl ?>">
</frameset>
<?php
}

?>