Location: PHPKode > projects > SiteX > signup.php
<?PHP
ob_start();
session_start();
include("includes/globals.php.inc");
include("includes/functions.php");

if($sxSetup['UserValidation'])
	$sxValKey = getRand(32);
				
include("lang/English.php");
if(strtolower($sxSetup['Language']) != 'english') include("lang/".$sxSetup['Language'].".php");
include("themes/$THEME_FOLDER/config.php.inc");

if($sxSetup['AllowSignup'] != 1)
{
	header("Loction:".$sxThemeConfig['Homepage']);
	die();
}

if($Submit)
{
	$process_form = false;
		
	// If form is secured
	if($sxSetup['FormSecurity'] == 1)
	{
		// Validate the code
		if(validateSecurityCode(htmlspecialchars($security_code), intval($codeid,10)) == true)
			$process_form = true;
		else
			$message = $sxLang['MessageSecurityCodeRejected'];
	}
	else
		$process_form = true;
	
	if($process_form)
	{
		if(
		($firstnameNew)AND
		($lastnameNew)AND
		($passwordNew)AND
		($emailNew)AND
		($usernameNew)AND
		(strpos($emailNew,"@"))
		
		)
		{
			$usernameNew = htmlspecialchars(str_replace(" ","_",trim($usernameNew)));
			$passwordNew = htmlspecialchars($passwordNew);
			$firstnameNew = htmlspecialchars($firstnameNew);
			$lastnameNew = htmlspecialchars($lastnameNew);
			$locationNew = htmlspecialchars($locationNew);
			$emailNew = htmlspecialchars(trim($emailNew));
			$websiteNew = htmlspecialchars(trim($websiteNew));
			$skypeidNew = htmlspecialchars(trim($skypeidNew));
			$msnidNew = htmlspecialchars(trim($msnidNew));
			$bioNew = htmlspecialchars(trim($bioNew));
			
			include("lang/English.php");
if(strtolower($sxSetup['Language']) != 'english') include("lang/".$sxSetup['Language'].".php");
			
			// Check username for existance
			$query = "SELECT * FROM $DB_Users WHERE username='$usernameNew'";
			$result = mysql_query($query, $Link) or queryError("29", mysql_error());
			if(!mysql_num_rows($result))
			{
				// Check email address for existance
				$query = "SELECT * FROM $DB_Users WHERE email='$emailNew'";
				$result = mysql_query($query, $Link) or queryError("29", mysql_error());
				if(!mysql_num_rows($result))
				{
					if($sxSetup['UserValidation'])
					{
						$sxValA1 = ", validated, validation_code";
						$sxValA2 = ", '0', '".$sxValKey."'";
					}
					else
					{
						$sxValA1 = ", validated";
						$sxValA2 = ", '1'";
					}
					
					if($sxSetup['UserApproval'])
					{
						$sxValB1 = ", active";
						$sxValB2 = ", '0'";
					}
					else
					{
						$sxValB1 = ", active";
						$sxValB2 = ", '1'";
					}
					
					if($showemailNew != 1)
						$showemailNew = 0;
					if($newsletterNew != 1)
						$newsletterNew = 0;
					
					$query = "INSERT INTO $DB_Users 
							  (username, password, firstname, lastname, location, email, website, skypeid, msnid, bio, lastlogin, membersince, newsletter, showemail, timezone$sxValA1$sxValB1) VALUES 
							  ('$usernameNew', '$passwordNew', '$firstnameNew', '$lastnameNew', '$locationNew', '$emailNew', '$websiteNew', '$skypeidNew', '$msnidNew', '$bioNew', '$NOW', '$NOW', '$newsletterNew', '$showemailNew', '$my_timezoneNew'$sxValA2$sxValB2)";
					$result = mysql_query($query, $Link) or queryError("29", mysql_error());
					
					$query = "SELECT * FROM $DB_Users WHERE username='$usernameNew'";
					$result = mysql_query($query, $Link) or queryError("29", mysql_error());
					$ROW = mysql_fetch_object($result);
					
					$query = "INSERT INTO $DB_Users_Assoc (userid, typeid) VALUES ('$ROW->id', '2')";
					$result = mysql_query($query, $Link) or die('insert died with :'.mysql_error());
					
					if($sxSetup['UserApproval'])
						mail($sxSetup['AdminEmail'], $sxLangMail['SubjectUserNewApprovalAdmin'], $sxLangMail['UserNewApprovalAdmin'], "From: ".$sxSetup['AdminEmail']);
					
					if((!$sxSetup['UserValidation'])AND(!$sxSetup['UserApproval']))
					{
						mail($emailNew, $sxLangMail['SubjectUserNewNoApprovalNoValidation'], $sxLangMail['UserNewNoApprovalNoValidation'], "From: ".$sxSetup['AdminEmail']);
						header("Location: login.php?message=".str_replace(" ","_",urlencode($sxLang['MessageSignupSuccessful'])));
						die();
					}
					elseif(($sxSetup['UserValidation'])AND(!$sxSetup['UserApproval']))
					{
						mail($emailNew, $sxLangMail['SubjectUserNewNoApprovalValidation'], $sxLangMail['UserNewNoApprovalValidation'], "From: ".$sxSetup['AdminEmail']);
						header("Location: login.php?message=".str_replace(" ","_",urlencode($sxLang['MessageSignupSuccessfulVal'])));
						die();
					}
					elseif((!$sxSetup['UserValidation'])AND($sxSetup['UserApproval']))
					{
						mail($emailNew, $sxLangMail['SubjectUserNewApprovalNoValidation'], $sxLangMail['UserNewApprovalNoValidation'], "From: ".$sxSetup['AdminEmail']);
						header("Location: login.php?message=".str_replace(" ","_",urlencode($sxLang['MessageSignupSuccessfulApp'])));
						die();
					}
					elseif(($sxSetup['UserValidation'])AND($sxSetup['UserApproval']))
					{
						mail($emailNew, $sxLangMail['SubjectUserNewApprovalValidation'], $sxLangMail['UserNewApprovalValidation'], "From: ".$sxSetup['AdminEmail']);
						header("Location: login.php?message=".str_replace(" ","_",urlencode($sxLang['MessageSignupSuccessfulValApp'])));
						die();
					}
				}
				else
				{
					$error = 1;
					$message = $sxLang['MessageUserEmailInUse'];
					$emailNew = "";
				}
			}
			else
			{
				$error = 1;
				$message = $sxLang['MessageUserUsernameInUse'];
				$usernameNew = "";
			}
		}
		else
		{
			$error = 1;
			$message = $sxLang['MessageUserRequiredFields'];
		}
	}
	else
		$error = 1;
}

// Secure imaging
if($sxSetup['FormSecurity'] == 1)
	$sxSecureImage = sxCreateSecurityImage();

$sxTitleAddendum = $sxLang['UserHeadingSignup'];
include("themes/$THEME_FOLDER/header.php");
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function submitIt(myForm){
	if(myForm.usernameNew.value.length < 3){
		alert("<?PHP echo $sxLang['UserJSUsername']; ?>");
		myForm.usernameNew.select();
		return false;
	}
	if(myForm.firstnameNew.value == ""){
		alert("<?PHP echo $sxLang['UserJSFirstName']; ?>");
		myForm.firstname.select();
		return false;
	}
	if(myForm.lastnameNew.value == ""){
		alert("<?PHP echo $sxLang['UserJSLastName']; ?>");
		myForm.lastname.select();
		return false;
	}
	if(myForm.emailNew.value == ""){
		alert("<?PHP echo $sxLang['UserJSEmail1']; ?>");
		myForm.emailNew.select();
		return false;
	}
	if(myForm.passwordNew.value.length < 5){
		alert("<?PHP echo $sxLang['UserJSPassword1']; ?>");
		myForm.passwordNew.select();
		return false;
	}
	if(myForm.passwordNew.value != myForm.passwordNewConfirm.value){
		alert("<?PHP echo $sxLang['UserJSPassword2']; ?>");
		myForm.passwordNew.select();
		return false;
	}
	if(emailCheck(myForm.emailNew.value) == false){
		myForm.emailNew.select();
		return false;
	}
}
function emailCheck (emailStr) {

	// Adapted from V1.1.3: Sandeep V. Tamhankar (hide@address.com)

	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
		alert("<?PHP echo $sxLang['UserJSEmail11']; ?>");
		return false;
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("<?PHP echo $sxLang['UserJSEmail12']; ?>");
			return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("<?PHP echo $sxLang['UserJSEmail13']; ?>");
			return false;
	   }
	}
	
	if (user.match(userPat)==null) {
		alert("<?PHP echo $sxLang['UserJSEmail14']; ?>");
		return false;
	}
	
	var IPArray=domain.match(ipDomainPat);
	
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("<?PHP echo $sxLang['UserJSEmail15']; ?>");
				return false;
	   		}
		}
		return true;
	}
	
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("<?PHP echo $sxLang['UserJSEmail16']; ?>");
			return false;
	   }
	}
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("<?PHP echo $sxLang['UserJSEmail17']; ?>");
		return false;
	}
	
	if (len<2) {
		alert("<?PHP echo $sxLang['UserJSEmail18']; ?>");
		return false;
	}
	
	return true;
}
//-->
</script>     
<div class="bodyWrapper">
<h1><?PHP echo $sxLang['UserHeadingSignup']; ?></h1>
<?PHP echoMessage($message); ?>
<form action="<?PHP echo $PHP_SELF; ?>" method="post" name="sxFormSignup" onsubmit="return submitIt(this)">
<div class="sxSection"><?PHP echo $sxLang['UserSectionAccountInfo']; ?></div>
<table width="500" border="0" cellspacing="0" cellpadding="5">
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemUsername']; ?>*</td>
	<td> <input type="text" name="usernameNew" maxlength="40"<?PHP if($error) echo " value=\"$usernameNew\""; ?> /> 
	</td>
  </tr>
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemPassword']; ?>*</td>
	<td> 
	  <input name="passwordNew" type="password" id="passwordNew" maxlength="32"<?PHP if($error) echo " value=\"$passwordNew\""; ?> /> 
	</td>
  </tr>
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemPasswordConfirm']; ?>*</td>
	<td> 
	  <input name="passwordNewConfirm" type="password" id="passwordNewConfirm" maxlength="32"<?PHP if($error) echo " value=\"$passwordNew\""; ?> /> 
	</td>
  </tr>
</table>
<div class="sxSection"><?PHP echo $sxLang['UserSectionPersonalInfo']; ?></div>
<table width="500" border="0" cellspacing="0" cellpadding="5">
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemFirstName']; ?>*</td>
	<td> <input name="firstnameNew" type="text" maxlength="40"<?PHP if($error) echo " value=\"$firstnameNew\""; ?> /> 
	</td>
  </tr>
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemLastName']; ?>*</td>
	<td> <input type="text" name="lastnameNew" maxlength="40"<?PHP if($error) echo " value=\"$lastnameNew\""; ?> /> 
	</td>
  </tr>
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemEmail']; ?>*</td>
	<td> <input type="text" name="emailNew" maxlength="80"<?PHP if($error) echo " value=\"$emailNew\""; ?> /> 
	</td>
  </tr>
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemWebsite']; ?></td>
	<td> <input type="text" name="websiteNew" maxlength="80"<?PHP if($error) echo " value=\"$websiteNew\""; ?> />
	<em>(http://www.google.com)</em></td>
  </tr>
  <?PHP if($sxSetup['UserSkype']){ ?>
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemSkypeID']; ?></td>
	<td> <input type="text" name="skypeidNew" maxlength="80"<?PHP if($error) echo " value=\"$skypeidNew\""; ?> /></td>
  </tr>
  <?PHP } ?>
  <?PHP if($sxSetup['UserMSN']){ ?>
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemMSNID']; ?></td>
	<td> <input type="text" name="msnidNew" maxlength="80"<?PHP if($error) echo " value=\"$msnidNew\""; ?> />
	<em>(hide@address.com)</em></td>
  </tr>
  <?PHP } ?>
  <?PHP if($sxSetup['UserBio']){ ?>
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemBio']; ?></td>
	<td> <textarea name="bioNew" style="width:300px;height:100px;" /><?PHP if($error) echo " value=\"$bioNew\""; ?></textarea></td>
  </tr>
  <?PHP } ?>
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemLocation']; ?></td>
	<td> <input type="text" name="locationNew" maxlength="80"<?PHP if($error) echo " value=\"$locationNew\""; ?> /></td>
  </tr>
</table>
<div class="sxSection"><?PHP echo $sxLang['GeneralSectionSettings']; ?></div>
<table width="500" border="0" cellspacing="0" cellpadding="5">
  <tr> 
	<td width="150" class="sxTdItem"><?PHP echo $sxLang['UserItemTimezone']; ?></td>
	<td><select name="my_timezoneNew">
<?PHP
		for($i = -24; $i <= 24; $i++)
		{
			echo '		<option value="' . $i . '"';
			
			if( ( ($i == 0) AND (!$error) )
				OR
			    ( ($error) AND ($i == $my_timezoneNew) )
			  )
				echo ' selected="selected"';
			
			echo '>';
			
			if($i > 0)
				echo '+ ';
			
			echo $i . '</option>'."\n";
		}
		?>
		</select> <span class="sxSmallText"><?PHP echo $sxLang['UserHoursFrom']; ?><br />(<?PHP echo $sxLang['CurrentTime']; ?>: <?PHP echo fetchDate($NOW, 99, 1); ?>)</span>
	</td>
  </tr>
  <tr> 
	<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemShowEmail']; ?></td>
	<td><input name="showemailNew" type="checkbox" value="1"<?PHP if((($error)AND($showemailNew == 1)) OR (!$error)) echo ' checked="checked"'; ?> /></td>
  </tr>
  <tr> 
	<td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['UserItemNewsletter']; ?></td>
	<td><input name="newsletterNew" type="checkbox" value="1"<?PHP if((($error)AND($newsletterNew == 1)) OR (!$error)) echo ' checked="checked"'; ?> /></td>
  </tr>
	<?PHP if($sxSetup['FormSecurity'] == 1){ ?>
	<tr> 
	  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem">&nbsp;</td>
	  <td><img src="<?PHP echo $sxSecureImage['url']; ?>" /><br/><?PHP echo $sxLang['GeneralItemSecureCase']; ?></td>
	</tr>
	<tr> 
	  <td width="<?PHP echo $sxThemeConfig['ContentWidth']/4; ?>" class="sxTdItem"><?PHP echo $sxLang['GeneralItemSecureCode']; ?>*</td>
	  <td><input name="security_code" type="text" id="security_code" maxlength="255" />
		  <input type="hidden" name="codeid" value="<?PHP echo $sxSecureImage['codeid']; ?>" /></td>
	</tr>
	<?PHP } ?>
</table>
<p align="center"><input name="Submit" type="submit" value="<?PHP echo $sxLang['UserButtonSignup2']; ?>" style="width:230px;" class="sxButton" /><input type="hidden" name="codeid" value="<?PHP echo $sxSecureImage['codeid']; ?>" /></p>
</form>
</div>
<?PHP
include("themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>
Return current item: SiteX