$section="register";
require('./session.php');
$firsterr=0;
$lasterr=0;
$disperr=0;
$passerr=0;
$passerr2=0;
$emailerr=0;
$ziperr=0;
$charerr=0;
$confirm = ( isset($HTTP_GET_VARS["confirm"]) ? $HTTP_GET_VARS["confirm"] : 0 );
if ($_REQUEST['submitted']==1) {
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$displayname=$_POST['displayname'];
$passwd=$_POST['passwd'];
$passwd2=$_POST['passwd2'];
$email=$_POST['email'];
$useridnum=md5($email);
$zipcode=$_POST['zipcode'];
$char=$_POST['char'];
$codenum=$_POST['codenum'];
$enc = md5(date('r', time()));
if ($firstname==''){$firsterr='first name';}
if ($lastname==''){$lasterr='last name';}
if ($passwd==''){$passerr='password';}
if ($passwd2==''){$passerr2='retype password';}
if ($email==''){$emailerr='email address';}
if ($zipcode==''){$ziperr='zip code';}
if ($char==''){$charerr='enter the characters below';}
require('./accessdb.php');
if ($displayname!=''){
$query="SELECT * FROM filam_members WHERE displayname='$displayname'";
$num=mysql_numrows(mysql_query($query));
if (strlen($displayname)>15){$disperr='display name too long';}
}
if ($email!=''){
$query="SELECT * FROM filam_members WHERE email='$email'";
$num=mysql_numrows(mysql_query($query));
if ($num>0){$emailerr='email already in use';}
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
$emailerr='invalid email address';
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
$emailerr='invalid email address';
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
$emailerr='invalid email address';
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
$emailerr='invalid email address';
}
}
}
}
if ($zipcode!=''){
$query="SELECT * FROM zip_code WHERE zip_code='$zipcode'";
$num=mysql_numrows(mysql_query($query));
if ($num==0){$ziperr='invalid zip code';}
}
if ($passwd2!=''){
if ($passwd2!=$passwd){$passerr2='password does not match';}
}
if ($char!=''){
if ($codenum==1){$code="k3p7dw";}
if ($codenum==2){$code="4zqmj5";}
if ($codenum==3){$code="sw28th";}
if ($char!=$code){$charerr='characters do not match';}
}
if ($firsterr=='0' && $lasterr=='0' && $disperr=='0' && $passerr=='0' && $passerr2=='0' && $emailerr=='0' && $ziperr=='0' && $charerr=='0'){
$query="SELECT * FROM zip_code WHERE zip_code='$zipcode'";
$result=mysql_query($query);
$city=mysql_result($result,0,"city");
$state=mysql_result($result,0,"state_name");
$query="INSERT INTO `filam_members` (firstname, lastname, displayname, password, email, city, state, zipcode, userid, confirmnum) VALUES ('$firstname', '$lastname', '$displayname', '$passwd', '$email', '$city', '$state', '$zipcode', '$useridnum', '$enc')";
mysql_query($query) or die('Error, insert query failed');
//define the receiver of the email
$to = $email;
//define the subject of the email
$subject = "filamconnect.com - Confirm your account registration.";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: filamconnect@filamconnect.com";
//define attachment name
$attachment_file = "";
//read the attachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents($attachment_file)));
$message = "Dear $firstname,\n\n";
$message .= "Thank you for creating an account with us. Please click the following link to complete and confirm your registration.\n";
$message .= "http://www.filamconnect.com/register.suphp?confirm=$enc\n\n";
$message .= "Sincerely,\n";
$message .= "filamconnect.com\n\n";
$message .= "NOTE: Please do not reply to this email as we are unable to respond to your reply from this address.\n";
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
$confirm='1';
// LET JED KNOW SOMEONE REGISTERED FOR AN ACCOUNT
$to = 'jedalan@gmail.com';
//define the subject of the email
$subject = "filamconnect.com - Account registration.";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: filamconnect@filamconnect.com";
//define attachment name
$attachment_file = "";
//read the attachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents($attachment_file)));
$message = "Member # $useridnum has registered for an account.\n\n";
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
}
}
?>