<?php

session_start();
include "config.php";
include "header.php";
include "style.php";
// errorchecking first:

if (empty($password)) {
	echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Password field is empty, please click your browsers 'back' button.</font></b></p>";
	include "footer.php";
	exit;
}

if (empty($userid)) {
	echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Userid  field is empty, please click your browsers 'back' button.</font></b></p>";
	include "footer.php";
	exit;
}

$query = "SELECT * FROM members where userid='".dbput($userid)."' and pword='".dbput($password)."' and status=1";
$result = mysql_query ($query);

$num_rows = mysql_num_rows($result);

if($num_rows==0)
{
	echo "<center>Error. Could not login.  <BR><BR><B><font size=3>If You Know For Sure, Your Username and Password Are Correct, Your Account May Have Been Deleted Due To Bounced Emails Or An Unverified Account - Unverified Accounts Get Deleted After 24 Hours.  <br><br>Please Sign Up Again And If You Can, Use A GMail Account.  If You Were A Upgraded Member, Simply Contact Me $adminname ($adminemail) With Your Payment Receipt Info And I Will Upgrade Your New Account</font><br><br><br></center>";
	include "footer.php";
	exit;
}
else
{

	$info = mysql_fetch_array($result);
	if($info['lastlogin']!=date('Y-m-d') AND $info['referid']!='admin') {
		$sql = mysql_query("SELECT * FROM members WHERE userid='".$info['referid']."'");
		if(@mysql_num_rows($sql)) {
			$info2 = mysql_fetch_array($sql);

			if($info2['memtype']=="SUPER JV") $earn = $superjvreflogin;
			elseif($info2['memtype']=="JV Member") $earn = $jvreflogin;
			else $earn = $proreflogin;
			if($earn) {

				$headers = "From: $sitename<$adminemail>\n";
				$headers .= "Reply-To: <$adminemail>\n";
				$headers .= "X-Sender: <$adminemail>\n";
				$headers .= "X-Mailer: PHP4\n";
				$headers .= "X-Priority: 3\n";
				$headers .= "Return-Path: <$adminemail>\n";


				mail($info2['contact_email'], "You've Got Bonus Points at ". $sitename, "

Congratulations, ".$info2['name']."!  You just earned $earn points for referring an active member!\n
Userid \"$userid\" just logged in and we awarded you with $earn bonus points.\n
Keep referring active members and you'll keep getting bonus points every time they login!

To your success,\n

$adminname\n

$domain/memberlogin.php\n\n

You are receiving this as you are a member of $sitename. \n
You can opt out of receiving emails only by deleting your account, click here to delete your account.\n\n$domain/delete.php?userid=".$info['referid']."&code=".md5($info2['pword']).".\n\n$sitename\n$adminaddress", $headers);


				mysql_query("UPDATE members SET points=points+$earn WHERE userid='".$info['referid']."'");
				mysql_query("INSERT INTO referraltrans VALUES ('id', '".$info2['userid']."','Referral Login $userid','".time()."','$earn points')");
			}



		}
	}


	mysql_query("UPDATE members set lastlogin = '".date('Y-m-d')."' where userid='$userid'");
	$_SESSION["ulogin"] = true;	$_SESSION['uname'] = $userid;	$_SESSION['pw'] = $password;
	//header("Location: /members/index.php");


	$sql = mysql_query("SELECT * FROM offerpage LIMIT 1");
	$offer = mysql_fetch_array($sql);
	$memtype = mysql_result($result, 0, "memtype");
	$fulllogin_viewed = @mysql_result($result, 0, "fulllogin_viewed");
	if($offer['enable']){

		if($offer['memtype'] == $memtype OR $offer['memtype'] == "ALL") $url = $domain.'/offerpage.php';
		else $url = $domain.'/members/index.php';
		

	} else{		$url = $domain.'/offerpage2.php';	
	    
	}	
	if($url == $domain.'/members/index.php' AND $fulllogin_viewed!=date('Y-m-j') AND $fullloginurl!="")
	{		
	    $url = $domain.'/members/fulllogin_frame.php';	
	    
	}

	echo '<META HTTP-EQUIV="Refresh" Content="3;URL='.$url.'">';
  ?>
    <div style="text-align: center;"><br>
<center>
    <b><font face="cooper, verdana" size="3">While you are being logged into your account, please visit our sponsor below...<br>Your click will open in a new window. Thanks! </font></b><br><br><img src="../images/loader.gif">
<center>
<br>
You will automatically be redirected in just a few seconds...<BR></a>
	<?
	echo "<font size=3 face='$fonttype' color='$fontcolour'>";

	$count = mysql_num_rows(mysql_query("SELECT * FROM loginads WHERE approved=1 AND hits<max"));

	$rand = rand(1,$count+10);

	if($rand > 10) {

		$query1 = "SELECT * FROM loginads WHERE approved=1 AND hits<max ORDER BY rand() LIMIT 1";
		$result1 = mysql_query ($query1);

		$line1 = mysql_fetch_array($result1);
		mysql_query("UPDATE loginads SET hits=hits+1 WHERE id='".$line1['id']."'");
		echo dbget($line1['adbody']);
	} else {

		$query1 = "SELECT * FROM pages WHERE name='Login #".rand(1,10)."'";
		$result1 = mysql_query ($query1);

		$line1 = mysql_fetch_array($result1);
		echo dbget($line1["htmlcode"]);


	}

	echo "</font>";
	?>


	</center><br>
<div>
    <?
}

include "footer.php";
mysql_close($dblink);
?>