<?php

session_start ();

$message = "";

include "config.php";

if (empty ( $userid )) {

$message = "Invalid link";

}

if (empty ( $email )) {

$message = "Invalid link";

}

$query = "select * from members where userid='" . $userid . "' and contact_email='" . $email . "'";

$result = mysql_query ( $query ) or 

die ( "Query failed" );

$numrows = @ mysql_num_rows ( $result );

if ($numrows == 1) {

$userinfo = mysql_query ( "select * from members where userid='" . $userid . "'" );

$userrecord = mysql_fetch_array ( $userinfo );

$query2 = "update members set verified=1 where userid='" . $userid . "'";

$result2 = mysql_query ( $query2 ) or 

die ( "Query failed" );

$query3 = "update members set bounce=0 where userid='".$userid."'";
$result3 = mysql_query ($query3)
or die ("Query failed"); 

if ($userrecord ['confirmed'] == 0) {

$_SESSION ['verifiedoto'] = 1;

$userinfo2 = mysql_query ( "select * from members where userid='" . $userrecord ['referid'] . "'" );

$userrecord2 = mysql_fetch_array ( $userinfo2 );

$today = date ( 'Y-m-d', strtotime ( "now" ) );

$query2 = "update members set confirmed='" . $today . "' where userid='" . $userid . "'";

$result2 = mysql_query ( $query2 ) or 

die ( "Query failed" );



// Referral points


if ($userrecord2 ['memtype'] == "PRO") {

$referpoints = $prorefpoints;

} elseif ($userrecord2 ['memtype'] == "JV Member") {

$referpoints = $jvrefpoints;

} else {

$referpoints = $superjvrefpoints;

}

mysql_query ( "UPDATE members SET points=points+" . $referpoints . " WHERE userid='" . $userrecord ['referid'] . "'" );



// Referral commission upgrade_jv
	

    
	$sql = mysql_query ( "SELECT referid FROM members WHERE userid = '" . $userid . "'" );
	
	$referid = mysql_result ( $sql, 0 );
	
	$resultrefer = mysql_query ( "SELECT * FROM members WHERE userid = '" . $referid . "'" );
	
	$line = mysql_fetch_array ( $resultrefer );
	
	$mem = $line ["memtype"];
	
	if ($mem == "SUPER JV") {
		
		$commission = $superjvjvcom;
	
	} elseif ($mem == "JV Member") {
		
		$commission = $jvjvcom;
	
	} elseif ($mem == "PRO") {
		
		$commission = $projvcom;
	
	}




// Referral commission upgrade_superjv
	
} else {
    
	$sql = mysql_query ( "SELECT referid FROM members WHERE userid = '" . $userid . "'" );
	
	$referid = mysql_result ( $sql, 0 );
	
	$resultrefer = mysql_query ( "SELECT * FROM members WHERE userid = '" . $referid . "'" );
	
	$line = mysql_fetch_array ( $resultrefer );
	
	$mem = $line ["memtype"];
	
	if ($mem == "SUPER JV") {
		
		$commission = $superjv2supercom;
	
	} elseif ($mem == "JV Member") {
		
		$commission = $jvsupercom;
	
	} elseif ($mem == "PRO") {
		
		$commission = $prosupercom;
	
	}
	
	mysql_query ( "UPDATE members SET commission=commission+" . $commission . " WHERE userid='" . $referid . "'" );
	
	

if ($userrecord2 ['userid']) {

if ($commission)
mysql_query ( "INSERT INTO referraltrans VALUES ('id', '" . $userrecord2 ['userid'] . "','Referral Signup Commissions ($userid)','" . time () . "','$$commission')" );

if ($referpoints)
mysql_query ( "INSERT INTO referraltrans VALUES ('id', '" . $userrecord2 ['userid'] . "','Referral Signup Points ($userid)','" . time () . "','$referpoints points')" );

$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";

if ($userrecord2 ['memtype'] == "PRO")

mail ( $userrecord2 ['contact_email'], "Congratulations! You Have A New Referral At " . $sitename, "Hi " . $userrecord2 ['userid'] . " ,\n\nYou just gained a new referral on $sitename!\n

Great Job!\n

With this new referral, you have earned $$commission in commissions and $referpoints points.\n

Login today to view your stats and to browse some newly posted ads. The more you browse the more you earn.\n

$domain/memberlogin.php\n\n

To your success,\n

$adminname\n



---------------------------------------------------------\n



You are receiving this as you are a member of $sitename. If you wish to remove yourself, please login and delete your membership.\n\nUserid: " . $userrecord2 ['userid'] . ", Password: " . $userrecord2 ['pword'] . "\n\n$sitename\n$adminaddress", $headers );

else

mail ( $userrecord2 ['contact_email'], "Congratulations! You Have A New Referral At " . $sitename, "Hi " . $userrecord2 ['userid'] . " ,\n\nYou just received a new referral on $sitename!\n

Excellent!\n

With this new referral, you have earned $$commission in commissions and $referpoints points.\n

Login today to view your stats and to browse newly posted ads. The more you browse the more you earn.\n

$domain/memberlogin.php\n\n

To your success,\n

$adminname\n


---------------------------------------------------------\n



You are receiving this as you are a member of $sitename. You can opt out of receiving emails only by deleting your account.<br>Please click the link below to delete your account.\n\n$domain/delete.php?userid=" . $userrecord ['referid'] . "&code=" . md5 ( $userrecord2 ['pword'] ) . ".\n\n$sitename\n$adminaddress", $headers );

}

}

$message = "<br><br><center><p><b><font size=2 face='$fonttype' color='$fontcolour'><b><center><font size=5>Your email address has been verified.<br>You will be redirected to a special ONE-TIME OFFER</font></b></p></center><br><br>";

?>



<head>



<META HTTP-EQUIV="Refresh"
CONTENT="5; URL=oto.php?id=<?
echo $userid;
?>">



</head>



<?

} //end if ($numrows == 1)


else {

$message = "Invalid link.";

}

include "header.php";

include ("banners2.php");

echo "<font size=2 face='$fonttype' color='$fontcolour'><p><b><center>";

echo $message;

include "footer.php";

mysql_close ( $dblink );

?>