<?php
session_start();
include "header.php";
include "config.php";


// ban
if ($_SERVER['REMOTE_ADDR'] == "123.100.138.21") {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>You have been banned.</p></b></center></font>";
exit;
}

$ip=$_SERVER["REMOTE_ADDR"];
$new_userid = $_POST['new_userid'];
$new_userid = str_replace(' ', '', $new_userid);
$new_password = $_POST['new_password'];
$new_passwordv = $_POST['new_passwordv'];
$new_fullname = $_POST['new_fullname'];
$new_lastname = $_POST['new_lastname'];
$new_contact = $_POST['new_contact'];

if (isset($_POST['$new_subscribed'])) {
$new_subscribed= $new_contact;
}
else {
$new_subscribed= $new_contact;
}
if (isset($_COOKIE['referid'])) {
$referid = $_COOKIE['referid'];
}
else {
$referid="admin";
}

if (isset($_POST['solo'])) {
$solo = $_POST['solo'];
if ($solo=="on") {
$solo=1;
}
else {
$solo=0;
}
}
else {
$solo=1;
}

// errorchecking first:
if(empty($_POST['captcha']) || $_POST['captcha'] != $_SESSION['captcha']){
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Invalid Security Code. Please click your browsers back button.</b></p></center></font>";
include "footer.php";
exit();
}

// errorchecking first:
if (empty($new_userid) OR $new_userid=='admin') {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! Userid field is empty. Please click your browsers back button.</p></b></center></font>";
exit;
}

// errorchecking first:
if (!$_POST['terms']) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! You must agree to the term and conditions to join. Please click your browsers back button.</p></b></center></font>";
exit;
}   

$sql = mysql_query("SELECT * FROM banned_emails");
while($each = mysql_fetch_array($sql)) {
if(strpos(strtolower($new_contact), strtolower(trim($each['email']))) !== false) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! That email address has been banned.</p></b></center></font>";
exit;	
}
}     


$query = "select * from members where userid='".$new_userid."'";
$result = mysql_query ($query);
$numrows = mysql_num_rows($result);

if ($numrows>0) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! Userid already exists. Please click your browsers back button.</p></b></center></font>";
exit;
}

// Check if the ip is banned or not
$query = "select * from leaves_bannedips where ip='".$ip."'";
$result = mysql_query ($query);
$numrows = mysql_num_rows($result);

if ($numrows>0) {

echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>This IP Address has been banned.</p></b></center></font>";

exit;
}

//$query = "select * from members where ip='".$ip."'";
//$result = mysql_query ($query);
//$numrows = mysql_num_rows($result);

//if ($numrows>0) {
//echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! A member already exists with your IP address.</p></b></center></font>";
//exit;
//}

$queryc = "select * from members where contact_email='".$new_contact."'";
$resultc = mysql_query ($queryc);
$numrowsc = mysql_num_rows($resultc);


// Check the e-mail if it passes the check or not
// Load the settings
$query = "select * from jse_bdomainsettings";
$result = mysql_query( $query )
or die( "Connection error. Check database settings!" );

$array = mysql_fetch_array($result);
$jse_mode = $array["type"];

// Get all the information of the domains listed in jse_allow
if( $jse_mode == 'allow' )
{
$query2 = "select * from jse_allow";
$result2 = mysql_query( $query2 )
or die( "Connection error. Check database settings!(2)" );

$array2 = mysql_fetch_array($result2);
}
// Get all the information of the domains listed in jse_allow
else if( $jse_mode == 'reject' )
{
$query2 = "select * from jse_reject";
$result2 = mysql_query( $query2 )
or die( "Connection error. Check database settings!(2)" );

$array2 = mysql_fetch_array($result2);
}
$jse_rows = mysql_num_rows( $result2 );
$jse_contact = $array2['domain'];
$jse_passed = 0;

if( $jse_rows != 0)
{
if( $jse_mode == 'reject' )
{
$jse_contact = split("@",$new_contact);
if( $jse_contact[1] == $array2['domain'] )
{
echo( "<center>This site doesn't allow email addresses from &quot;$jse_contact[1]&quot; (1)</center><br><br>" );
include "footer.php";
exit;
}

while( $line = mysql_fetch_array( $result2 ) )
{
$jse_contact = split("@",$new_contact);
if( $jse_contact[1] == $line['domain'] )
{
echo( "<center>This site doesn't allow email addresses from &quot;$jse_contact[1]&quot; (2)</center><br><br>" );
include "footer.php";
exit;
}
}
}
else if( $jse_mode == 'allow' )
{
$jse_contact = split("@",$new_contact);
if( $jse_contact[1] == $array2['domain'] )
{
$jse_ignore = 1;
}
else
{
//echo( "1.)".$jse_contact[0]."<br>2.)".$jse_contact[1]."<br>3.)".$jse_contact[2]."<br>4.)".$array2['domain'] );
echo( "<center>This site doesn't allow email addresses from &quot;$jse_contact[1]&quot; (3)</center><br><br>" );
echo( $jse_passed);
include "footer.php";
exit;
}

if( $jse_ignore != 1 )
{
while( $line = mysql_fetch_array( $result2 ) )
{
if( $jse_contact[1] == $line['domain'] )
{

}
else
{
//echo( "1.)".$jse_contact[0]."<br>2.)".$jse_contact[1]."<br>3.)".$jse_contact[2]."<br>4.)".$array2['domain'] );
echo( "<center>This site doesn't allow email addresses from &quot;$jse_contact[1]&quot; (4)</center><br><br>" );
echo( $jse_passed);
include "footer.php";
exit;
}
}
}
}
}


if ($numrowsc>0) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! Email already exists. Please click your browsers back button.</p></b></center></font>";
exit;
}

if ((empty($new_password))||(empty($new_passwordv))) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! Password field is empty. Please click your browsers back button.</p></b></center></font>";
exit;
}

if (empty($new_fullname)) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! First Name field is empty. Please click your browsers back button.</p></b></center></font>";
exit;
}
if (empty($new_lastname)) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! Last Name field is empty. Please click your browsers back button.</p></b></center></font>";
exit;
}


if (empty($new_contact)) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! Contact field is empty. Please click your browsers back button.</p></b></center></font>";
exit;
}   
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $new_contact)) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! You've entered an invalid email address. Please click your browsers back button.</p></b></center></font>";
exit;
}
if (empty($new_subscribed)) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! Subscribed field is empty. Please click your browsers back button.</p></b></center></font>";
exit;
}
if ($new_password != $new_passwordv ) {
echo "<font size=3 face='$fonttype' color='$fontcolour'><p><b><center>Error! Passwords do not match. Please click your browsers back button.</p></b></center></font>";
exit;
}


//all clear, now add user.....



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




if($jvsignup) {
$mtY = 'JV Member';
$points=$jvpoints;
} else {
$mtY = 'PRO';
$points=$propoints;
}


$query = "INSERT INTO members ";
$query .= "(userid,pword,name,lastname,contact_email,subscribed_email,status,referid,points,memtype,solos,ip,joindate,referrer) ";
$query .= "VALUES ";
$query .= "('".dbput($new_userid)."','".dbput($new_password)."','".dbput($new_fullname)."','".dbput($new_lastname)."','".dbput($new_contact)."','".dbput($new_subscribed)."',1,'$referid','$points','$mtY',$solo,'$ip','$today','".$_POST['referrer']."')";

$result = mysql_query ($query)
or die ("Signup failed. Please contact support.");


$queryrefer="select * from members where userid='".$referid."'";

$resultrefer = mysql_query ($queryrefer);
$line = mysql_fetch_array ($resultrefer);
$mem = $line["memtype"];


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



// send the user an email to inform them about having joined. And send a verification email to subscribed....

$message = "Hi ".$new_fullname." ".$new_lastname.",\n\nThanks again for joining ".$sitename.".\nYour account details are below:\n\n"
."Userid: ".$new_userid."\nPassword: ".$new_password."\n\n"
."Before you can advertise on our site, please verify your email address by clicking this link:\n"
.$domain."/verify.php?userid=".$new_userid."&email=".$new_subscribed."\n\n"
."Your unique referral url is:\n".$domain."/index.php?referid=".$new_userid ."\n\n"
."You can log into the Member's Area to post advertising or to earn cash and points by viewing other members websites:\n"
.$domain."\n\n"
."Thank You!\n\n"
.$adminname." - Admin\n"
.$adminaddress."\n"
.$sitename."\n"
.$adminemail."\n\n\n\n";


@mail($new_contact, "Welcome to ". $sitename, wordwrap(stripslashes($message)),$headers);


include "banners2.php";

if ($adminnotice=="1") {
$headern .= "From: $sitename<$adminemail>\n";
$headern .= "Reply-To: <$adminemail>\n";
$headern .= "Bcc: <$adminemail>\n";
$headern .= "X-Sender: <$adminemail>\n";
$headern .= "X-Mailer: PHP4\n";
$headern .= "X-Priority: 3\n";
$headern .= "Return-Path: <$adminemail>\n";


$subject = "".$sitename." new member ".$new_userid." joined";
$body = "A new member ".$new_fullname."(".$new_userid.") has joined from the IP:\n".$ip."\n\nThe contact e-mail given was:\n".$new_contact;
mail($adminemail, $subject, $body,$headern);
}
elseif ($adminnotice=="0") {

}

?>
<br>
<br>
<br>
<font size=3 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>" ?><b><center>Congratulations! Your Sign-Up Was Successful!<br><BR>
Please whitelist (add to your email account as a contact) <? echo $adminemail; ?><br><br>Make sure you verify your email account.<br> 
Unverified (even paid) accounts will be deleted.<BR><BR> Check your trash or spam folder for your welcome email if it is not in your inbox.<br><br>
You will not be able to use the website until your account is verified.<br>If you do not receive the verification email within an hour, contact us.</b>
<p></font></p></center></b></b><br><br><br><br><br><br><br><br> 

<?

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