<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// process registration form
	// ========================================================================================
	

	$PageTitle = $MsgText[0][124];
	$BrowserTitle = $MsgText[0][124];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > '.$MsgText[0][124];
	
	
	ReadFormArguments();
	Global $FormArguments;
	
	if (count($FormArguments) > 0) {
	
		//$FormArguments['NewUsername'] = strtolower($FormArguments['NewUsername']);
		
	
	ReadPermissions();
	Global $Permissions;
	
	
	// if either guest registrations are allowed and they're not logged in, or they are and have permission to create accounts
	if (($Settings['AllowGuestRegistrations'] == 'y' && $LoggedIn != 'y') || ($LoggedIn == 'y' && $Permissions[10] == 'y')) {
	
	/*if ($LoggedIn == 'y' && $Permissions[10] == 'y') {
		$FormArguments['EmailConfirm'] = $FormArguments['Email']; 
		$FormArguments['PasswordConfirm'] = $FormArguments['Password'];
	}*/

		$ErrorsFound = '';
		
		$RegFormOpts = explode('%%', $Settings['RegFormOpts']);
		
		
		if ($FormArguments['NewUsername'] != '') {
			for ($i = 0; $i < strlen($FormArguments['NewUsername']); $i++) {
				$cc = ord(substr($FormArguments['NewUsername'],$i,1));
				// filter out all but a-z A-Z 0-9 . - _
				if (($cc >= 48 && $cc <= 57) || ($cc >= 65 && $cc <= 90) || ($cc >= 97 && $cc <= 122) || $cc == 45 || $cc == 46 || $cc == 95) {
					$GoodString .= chr($cc);
				}
				else {
					$BadChars .= chr($cc);
				}
			}
			
			if ($BadChars == '') {
		
				DBConnect();
	
				//query the database and validate the input from the login page
				//assign $result to do a lookup up in the database flexcms users table
				//where the username is equal to the database field username, validates password
				$query = "select * from `".$Settings['DBPrefix']."core-Users` where Username='".$FormArguments['NewUsername']."' LIMIT 1";
				$result = mysql_query($query) or die (mysql_error());
		
				// if no rows are returned, the username is available
				if (mysql_num_rows($result) == 0) {
					$FinalCode .= '<b>'.$MsgText[0][99].'</b>: (A-Z a-z 0-9 . - _ '.$MsgText[0][129].')<br><input type="text" name="NewUsername" size="25" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['NewUsername'].'">';
				}
				else {
					$ErrorsFound = 'y';
					$FinalCode .= '<b>'.$MsgText[0][99].'</b>: (A-Z a-z 0-9 . - _ '.$MsgText[0][129].')<br><input type="text" name="NewUsername" size="25" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['NewUsername'].'"> <font color="#ff0000"><b>('.$MsgText[0][135].')</b></font>';
				}
			}
			else {
				$ErrorsFound = 'y';
				$FinalCode .= '<b>'.$MsgText[0][99].'</b>: (A-Z a-z 0-9 . - _ '.$MsgText[0][129].')<br><input type="text" name="NewUsername" size="25" maxlength="40" style="'.$FormStyle.'" value="'.$GoodString.'"> <font color="#ff0000"><b>('.$MsgText[0][136].': '.$BadChars.')</b></font>';
			}
		}
		else {
			$ErrorsFound = 'y';
			$FinalCode .= '<b>'.$MsgText[0][99].'</b>: (A-Z a-z 0-9 . - _ '.$MsgText[0][129].')<br><input type="text" name="NewUsername" size="25" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['NewUsername'].'"> <font color="#ff0000"><b>('.$MsgText[0][137].')</b></font>';
		}
		
		
		if (VerifyCleanString($FormArguments['Email'],1) != '' && VerifyCleanString($FormArguments['EmailConfirm'],1) != '') {
			if ($FormArguments['Email'] == $FormArguments['EmailConfirm']) {
				$query = "select * from `".$Settings['DBPrefix']."core-Users` where Email='".VerifyCleanString($FormArguments['Email'],1)."' LIMIT 1";
				$result = mysql_query($query) or die (mysql_error());
		
				// if no rows are returned, the username is available
				if (mysql_num_rows($result) == 0) {
					$FinalCode .= '<br><br><b>'.$MsgText[0][88].'</b>:<br><input type="text" name="Email" size="35" maxlength="50" style="'.$FormStyle.'" value="'.$FormArguments['Email'].'"><br><b>'.$MsgText[0][130].'</b>:<br><input type="text" name="EmailConfirm" size="35" maxlength="50" style="'.$FormStyle.'" value="'.$FormArguments['EmailConfirm'].'">';
				}
				else {
					$ErrorsFound = 'y';
					$FinalCode .= '<br><br><font color="#ff0000"><b>('.$MsgText[0][706].') - <a href="'.$MainURL.'/lost_username.html">'.$MsgText[0][707].'?</a></b></font><br><b>'.$MsgText[0][88].'</b>:<br><input type="text" name="Email" size="35" maxlength="50" style="'.$FormStyle.'" value="'.VerifyCleanString($FormArguments['Email'],1).'"><br><b>'.$MsgText[0][130].'</b>:<br><input type="text" name="EmailConfirm" size="35" maxlength="50" style="'.$FormStyle.'" value="'.VerifyCleanString($FormArguments['EmailConfirm'],1).'">';
				}
							
			}
			else {
				$ErrorsFound = 'y';
				$FinalCode .= '<br><br><font color="#ff0000"><b>('.$MsgText[0][138].')</b></font><br><b>'.$MsgText[0][88].'</b>:<br><input type="text" name="Email" size="35" maxlength="50" style="'.$FormStyle.'"><br><b>'.$MsgText[0][130].'</b>:<br><input type="text" name="EmailConfirm" size="35" maxlength="50" style="'.$FormStyle.'">';
			}
		}
		else {
			$ErrorsFound = 'y';
			if ($FormArguments['Email'] == '') {
				$FinalCode .= '<br><br><b>'.$MsgText[0][88].'</b>:<br><input type="text" name="Email" size="35" maxlength="50" style="'.$FormStyle.'"> <font color="#ff0000"><b>('.$MsgText[0][137].')</b></font>';
			}
			else {
				$FinalCode .= '<br><br><b>'.$MsgText[0][88].'</b>:<br><input type="text" name="Email" size="35" maxlength="50" style="'.$FormStyle.'" value="'.VerifyCleanString($FormArguments['Email'],1).'">';
			}
			
			if ($FormArguments['EmailConfirm'] == '') {
				$FinalCode .= '<br><b>'.$MsgText[0][130].'</b>:<br><input type="text" name="EmailConfirm" size="35" maxlength="50" style="'.$FormStyle.'"> <font color="#ff0000"><b>('.$MsgText[0][137].')</b></font>';
			}
			else {
				$FinalCode .= '<br><b>'.$MsgText[0][130].'</b>:<br><input type="text" name="EmailConfirm" size="35" maxlength="50" style="'.$FormStyle.'" value="'.VerifyCleanString($FormArguments['EmailConfirm'],1).'">';
			}
		}
		
		
		if ($FormArguments['NewPassword'] != '' && $FormArguments['PasswordConfirm'] != '') {
			if ($FormArguments['NewPassword'] == $FormArguments['PasswordConfirm']) {
				$FinalCode .= '<br><br><b>'.$MsgText[0][131].'</b>:<br><input type="password" name="NewPassword" size="20" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['NewPassword'].'"><br><b>'.$MsgText[0][132].'</b>:<br><input type="password" name="PasswordConfirm" size="20" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['PasswordConfirm'].'">';
			}
			else {
				$ErrorsFound = 'y';
				$FinalCode .= '<br><br><font color="#ff0000"><b>('.$MsgText[0][139].')</b></font><br><b>'.$MsgText[0][131].'</b>:<br><input type="password" name="NewPassword" size="20" maxlength="40" style="'.$FormStyle.'"><br><b>'.$MsgText[0][132].'</b>:<br><input type="password" name="PasswordConfirm" size="20" maxlength="40" style="'.$FormStyle.'">';
			}
		}
		else {
			$ErrorsFound = 'y';
			if ($FormArguments['NewPassword'] == '') {
				$FinalCode .= '<br><br><b>'.$MsgText[0][131].'</b>:<br><input type="password" name="NewPassword" size="20" maxlength="40" style="'.$FormStyle.'"> <font color="#ff0000"><b>('.$MsgText[0][137].')</b></font>';
			}
			else {
				$FinalCode .= '<br><br><b>'.$MsgText[0][131].'</b>:<br><input type="password" name="NewPassword" size="20" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['NewPassword'].'">';
			}
			
			if ($FormArguments['PasswordConfirm'] == '') {
				$FinalCode .= '<br><b>'.$MsgText[0][132].'</b>:<br><input type="password" name="PasswordConfirm" size="20" maxlength="40" style="'.$FormStyle.'"> <font color="#ff0000"><b>('.$MsgText[0][137].')</b></font>';
			}
			else {
				$FinalCode .= '<br><b>'.$MsgText[0][132].'</b>:<br><input type="password" name="PasswordConfirm" size="20" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['PasswordConfirm'].'">';
			}
		}
		
				
		
		$FieldName[1] = $MsgText[0][100];
		$FieldValue[1] = $FormArguments['FirstName'];
		$FieldCode[1] = '<input type="text" name="FirstName" size="20" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['FirstName'].'">';
		
		$FieldName[2] = $MsgText[0][101];
		$FieldValue[2] = $FormArguments['LastName'];
		$FieldCode[2] = '<input type="text" name="LastName" size="20" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['LastName'].'">';
		
		$FieldName[3] = $MsgText[0][102];
		$FieldValue[3] = $FormArguments['OrganizationCompany'];
		$FieldCode[3] = '<input type="text" name="OrganizationCompany" size="35" maxlength="50" style="'.$FormStyle.'" value="'.str_replace('"','&#34;',$FormArguments['OrganizationCompany']).'">';
		
		$FieldName[4] = $MsgText[0][103];
		$FieldValue[4] = $FormArguments['Address1'];
		$FieldCode[4] = '<input type="text" name="Address1" size="30" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['Address1'].'">';
		$FieldName[5] = $MsgText[0][103];
		$FieldValue[5] = $FormArguments['Address2'];
		$FieldCode[5] = '<input type="text" name="Address2" size="30" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['Address2'].'">';
		$FieldName[6] = $MsgText[0][103];
		$FieldValue[6] = $FormArguments['Address3'];
		$FieldCode[6] = '<input type="text" name="Address3" size="30" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['Address3'].'">';
		$FieldName[7] = $MsgText[0][103];
		$FieldValue[7] = $FormArguments['Address4'];
		$FieldCode[7] = '<input type="text" name="Address4" size="30" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['Address4'].'">';
		
		$FieldName[8] = $MsgText[0][104];
		$FieldValue[8] = $FormArguments['City'];
		$FieldCode[8] = '<input type="text" name="City" size="20" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['City'].'">';
				
		$FieldName[9] = $MsgText[0][105];
		$FieldValue[9] = $FormArguments['StateProvince'];
		$FieldCode[9] = '<input type="text" name="StateProvince" size="25" maxlength="40" style="'.$FormStyle.'" value="'.$FormArguments['StateProvince'].'">';
		
		$FieldName[10] = $MsgText[0][106];
		$FieldValue[10] = $FormArguments['ZipPostal'];
		$FieldCode[10] = '<input type="text" name="ZipPostal" size="10" maxlength="15" style="'.$FormStyle.'" value="'.$FormArguments['ZipPostal'].'">';
		
		$FieldName[11] = $MsgText[0][107];
		$FieldValue[11] = $FormArguments['Country'];
		$FieldCode[11] = '<select name="Country" style="'.$FormStyle.'"><option value="'.$FormArguments['Country'].'">'.$FormArguments['Country'].'<option value="AF">Afghanistan<option value="AL">Albania<option value="DZ">Algeria<option value="AS">American Samoa<option value="AD">Andorra<option value="AO">Angola<option value="AI">Anguilla<option value="AQ">Antarctica<option value="AG">Antigua and Barbuda<option value="AR">Argentina<option value="AM">Armenia<option value="AW">Aruba<option value="AU">Australia<option value="AT">Austria<option value="AZ">Azerbaijan<option value="BS">Bahamas<option value="BH">Bahrain<option value="BD">Bangladesh<option value="BB">Barbados<option value="BY">Belarus<option value="BE">Belgium<option value="BZ">Belize<option value="BJ">Benin<option value="BM">Bermuda<option value="BT">Bhutan<option value="BO">Bolivia<option value="BA">Bosnia and Herzegovina<option value="BW">Botswana<option value="BV">Bouvet Island<option value="BR">Brazil<option value="IO">British Indian Ocean Territory<option value="BN">Brunei Darussalam<option value="BG">Bulgaria<option value="BF">Burkina Faso<option value="BI">Burundi<option value="KH">Cambodia<option value="CM">Cameroon<option value="CA">Canada<option value="CV">Cape Verde<option value="KY">Cayman Islands<option value="CF">Central African Republic<option value="TD">Chad<option value="CL">Chile<option value="CN">China<option value="CX">Christmas Island<option value="CC">Cocos (Keeling) Islands<option value="CO">Colombia<option value="KM">Comoros<option value="CG">Congo<option value="CK">Cook Islands<option value="CR">Costa Rica<option value="CI">Cote D\'Ivoire (Ivory Coast)<option value="HR">Croatia (Hrvatska)<option value="CU">Cuba<option value="CY">Cyprus<option value="CZ">Czech Republic<option value="CS">Czechoslovakia (former)<option value="DK">Denmark<option value="DJ">Djibouti<option value="DM">Dominica<option value="DO">Dominican Republic<option value="TP">East Timor<option value="EC">Ecuador<option value="EG">Egypt<option value="SV">El Salvador<option value="GQ">Equatorial Guinea<option value="ER">Eritrea<option value="EE">Estonia<option value="ET">Ethiopia<option value="FK">Falkland Islands (Malvinas)<option value="FO">Faroe Islands<option value="FJ">Fiji<option value="FI">Finland<option value="FR">France<option value="GF">French Guiana<option value="PF">French Polynesia<option value="TF">French Southern Territories<option value="GA">Gabon<option value="GM">Gambia<option value="GE">Georgia<option value="DE">Germany<option value="GH">Ghana<option value="GI">Gibraltar<option value="GR">Greece<option value="GL">Greenland<option value="GD">Grenada<option value="GP">Guadeloupe<option value="GU">Guam<option value="GT">Guatemala<option value="GN">Guinea<option value="GW">Guinea-Bissau<option value="GY">Guyana<option value="HT">Haiti<option value="HM">Heard and McDonald Islands<option value="HN">Honduras<option value="HK">Hong Kong<option value="HU">Hungary<option value="IS">Iceland<option value="IN">India<option value="ID">Indonesia<option value="IR">Iran<option value="IQ">Iraq<option value="IE">Ireland<option value="IM">Isle of Man<option value="IL">Israel<option value="IT">Italy<option value="JM">Jamaica<option value="JP">Japan<option value="DQ">Jarvis Island<option value="JO">Jordan<option value="KZ">Kazakhstan<option value="KE">Kenya<option value="KI">Kiribati<option value="KP">Korea (North)<option value="KR">Korea (South)<option value="KW">Kuwait<option value="KG">Kyrgyzstan<option value="LA">Laos<option value="LV">Latvia<option value="LB">Lebanon<option value="LS">Lesotho<option value="LR">Liberia<option value="LY">Libya<option value="LI">Liechtenstein<option value="LT">Lithuania<option value="LU">Luxembourg<option value="MO">Macau<option value="MK">Macedonia<option value="MG">Madagascar<option value="MW">Malawi<option value="MY">Malaysia<option value="MV">Maldives<option value="ML">Mali<option value="MT">Malta<option value="MH">Marshall Islands<option value="MQ">Martinique<option value="MR">Mauritania<option value="MU">Mauritius<option value="YT">Mayotte<option value="MX">Mexico<option value="FM">Micronesia<option value="MD">Moldova<option value="MC">Monaco<option value="MN">Mongolia<option value="MS">Montserrat<option value="MA">Morocco<option value="MZ">Mozambique<option value="MM">Myanmar<option value="NA">Namibia<option value="NR">Nauru<option value="NP">Nepal<option value="NL">Netherlands<option value="AN">Netherlands Antilles<option value="NT">Neutral Zone<option value="NC">New Caledonia<option value="NZ">New Zealand (Aotearoa)<option value="NI">Nicaragua<option value="NE">Niger<option value="NG">Nigeria<option value="NU">Niue<option value="NF">Norfolk Island<option value="MP">Northern Mariana Islands<option value="NO">Norway<option value="OM">Oman<option value="PK">Pakistan<option value="PW">Palau<option value="PA">Panama<option value="PG">Papua New Guinea<option value="PY">Paraguay<option value="PE">Peru<option value="PH">Philippines<option value="PN">Pitcairn<option value="PL">Poland<option value="PT">Portugal<option value="PR">Puerto Rico<option value="QA">Qatar<option value="RE">Reunion<option value="RO">Romania<option value="RU">Russian Federation<option value="RW">Rwanda<option value="KN">Saint Kitts and Nevis<option value="LC">Saint Lucia<option value="VC">Saint Vincent and the Grenadines<option value="WS">Samoa<option value="SM">San Marino<option value="ST">Sao Tome and Principe<option value="SA">Saudi Arabia<option value="SN">Senegal<option value="SC">Seychelles<option value="SL">Sierra Leone<option value="SG">Singapore<option value="SK">Slovak Republic<option value="SI">Slovenia<option value="SB">Solomon Islands<option value="SO">Somalia<option value="ZA">South Africa<option value="GS">South Georgia and South Sandwich Isls.<option value="ES">Spain<option value="LK">Sri Lanka<option value="SH">St. Helena<option value="PM">St. Pierre and Miquelon<option value="SD">Sudan<option value="SR">Suriname<option value="SJ">Svalbard and Jan Mayen Islands<option value="SZ">Swaziland<option value="SE">Sweden<option value="CH">Switzerland<option value="SY">Syria<option value="TW">Taiwan<option value="TJ">Tajikistan<option value="TZ">Tanzania<option value="TH">Thailand<option value="TG">Togo<option value="TK">Tokelau<option value="TO">Tonga<option value="TT">Trinidad and Tobago<option value="TN">Tunisia<option value="TR">Turkey<option value="TM">Turkmenistan<option value="TC">Turks and Caicos Islands<option value="TV">Tuvalu<option value="UM">US Minor Outlying Islands<option value="SU">USSR (former)<option value="UG">Uganda<option value="UA">Ukraine<option value="AE">United Arab Emirate<option value="UK">United Kingdom<option value="US">United States<option value="UY">Uruguay<option value="UZ">Uzbekistan<option value="VU">Vanuatu<option value="VA">Vatican City State (Holy See)<option value="VE">Venezuela<option value="VN">Viet Nam<option value="VG">Virgin Islands (British)<option value="VI">Virgin Islands (U.S.)<option value="WF">Wallis and Futuna Islands<option value="EH">Western Sahara<option value="YE">Yemen<option value="YU">Yugoslavia<option value="ZR">Zaire<option value="ZM">Zambia<option value="ZW">Zimbabwe</select>';
		
		$FieldName[12] = $MsgText[0][108];
		$FieldValue[12] = $FormArguments['Phone'];
		$FieldCode[12] = '<input type="text" name="Phone" size="15" maxlength="20" style="'.$FormStyle.'" value="'.$FormArguments['Phone'].'">';		
		
		$FieldName[13] = $MsgText[0][109];
		$FieldValue[13] = $FormArguments['Fax'];
		$FieldCode[13] = '<input type="text" name="Fax" size="15" maxlength="20" style="'.$FormStyle.'" value="'.$FormArguments['Fax'].'">';
		
		$FieldName[14] = $MsgText[0][110];
		$FieldValue[14] = $FormArguments['Cell'];
		$FieldCode[14] = '<input type="text" name="Cell" size="15" maxlength="20" style="'.$FormStyle.'" value="'.$FormArguments['Cell'].'">';
		
		$FieldName[15] = $MsgText[0][111];
		$FieldValue[15] = $FormArguments['Pager'];
		$FieldCode[15] = '<input type="text" name="Pager" size="15" maxlength="20" style="'.$FormStyle.'" value="'.$FormArguments['Pager'].'">';
		
		$FieldName[16] = $MsgText[0][112];
		$FieldValue[16] = $FormArguments['Website'];
		$FieldCode[16] = '<input type="text" name="Website" size="35" maxlength="70" style="'.$FormStyle.'" value="'.$FormArguments['Website'].'">';
		
		$FieldName[17] = $MsgText[0][113];
		$FieldValue[17] = $FormArguments['ReferredBy'];
		$FieldCode[17] = '<input type="text" name="ReferredBy" size="35" maxlength="50" style="'.$FormStyle.'" value="'.str_replace('"','&#34;',$FormArguments['ReferredBy']).'">';
					
		$FieldName[18] = $RegFormOpts[0];
		$FieldValue[18] = $FormArguments['Custom1'];
		$FieldCode[18] = '<input type="text" name="Custom1" size="35" maxlength="50" style="'.$FormStyle.'" value="'.str_replace('"','&#34;',$FormArguments['Custom1']).'">';
		
		$FieldName[19] = $RegFormOpts[1];
		$FieldValue[19] = $FormArguments['Custom2'];
		$FieldCode[19] = '<input type="text" name="Custom2" size="35" maxlength="50" style="'.$FormStyle.'" value="'.str_replace('"','&#34;',$FormArguments['Custom2']).'">';
		
		$FieldName[20] = $RegFormOpts[2];
		$FieldValue[20] = $FormArguments['Custom3'];
		$FieldCode[20] = '<input type="text" name="Custom3" size="35" maxlength="50" style="'.$FormStyle.'" value="'.str_replace('"','&#34;',$FormArguments['Custom3']).'">';
		
		
		
		for ($i = 3; $i < count($RegFormOpts); $i++) {
			if ($FieldName[$i-2] != '' && $FieldCode[$i-2] != '') {
				
				if ($i == 4) {
					if ($RegFormOpts[$i] == 'r') {
						$RegFormCode .= '<br><b>'.$FieldName[$i-2].'</b>:<br>'.$FieldCode[$i-2];			
					}
					else if ($RegFormOpts[$i] == 'o') {
						$RegFormCode .= '<br>'.$FieldName[$i-2].':<br>'.$FieldCode[$i-2];
					}
				}
				else if ($i == 7 || $i == 8 || $i == 9) {
					if ($RegFormOpts[$i] == 'r') {
						$RegFormCode .= '<br>'.$FieldCode[$i-2];			
					}
					else if ($RegFormOpts[$i] == 'o') {
						$RegFormCode .= '<br>'.$FieldCode[$i-2].' (optional)';
					}
				}
				else {
					if ($RegFormOpts[$i] == 'r') {
						$RegFormCode .= '<br><br><b>'.$FieldName[$i-2].'</b>:<br>'.$FieldCode[$i-2];			
					}
					else if ($RegFormOpts[$i] == 'o') {
						$RegFormCode .= '<br><br>'.$FieldName[$i-2].':<br>'.$FieldCode[$i-2];
					}
				}
				
				if ($RegFormOpts[$i] == 'r' && $FieldValue[$i-2] == '') {
					$ErrorsFound = 'y';
					$RegFormCode .= ' <font color="#ff0000"><b>(Required)</b></font>';
				}
			} 
		}
		
		$FinalCode .= $RegFormCode;
	
	
	
		if ($ErrorsFound == '') {
				
			$PasswordEntered = $FormArguments['NewPassword'];
			
			// encrypt the password, correcting for the fact that php only encrypts the first eight characters (oy!)
			$EncryptedUsername = crypt($FormArguments['NewUsername'],substr($FormArguments['NewUsername'],0,2));
			$EncryptedUsername = substr($EncryptedUsername,0,8);
			$LoopCount = ceil(strlen($FormArguments['NewPassword'])/8);
			for ($i = 1; $i <= $LoopCount; $i++) {
				$FinalPassword .= crypt(substr($FormArguments['NewPassword'],($i*8)-8,8),substr($FormArguments['NewPassword'],0,2));
			}
			$FormArguments['NewPassword'] = $EncryptedUsername.$FinalPassword;
			
			
			if ($FormArguments['NewUserLevel'] > 1 && $FormArguments['NewUserLevel'] <= $UserLevel && $Permissions[4] == 'y') {
				$NewUserLevel = intval($FormArguments['NewUserLevel']);
			}
			else {
				$NewUserLevel = 1;
			}
			
			
					
			
			if ($LoggedIn == 'y' && $Permissions[10] == 'y') {
			
				$query = "insert into `".$Settings['DBPrefix']."core-Users` (Username, Email, DisplayEmail, Password, RegistrationDate, FirstName, LastName, OrganizationCompany, Address1, Address2, Address3, Address4, City, StateProvince, ZipPostal, Country, Phone, Fax, Cell, Pager, Website, ReferredBy, Custom1, Custom2, Custom3, Level, Verified) values ('".$FormArguments['NewUsername']."', '".$FormArguments['Email']."', 'n', '".$FormArguments['NewPassword']."', '".GetTimestamp()."', '".$FormArguments['FirstName']."', '".$FormArguments['LastName']."', '".$FormArguments['OrganizationCompany']."', '".$FormArguments['Address1']."', '".$FormArguments['Address2']."', '".$FormArguments['Address3']."', '".$FormArguments['Address4']."', '".$FormArguments['City']."', '".$FormArguments['StateProvince']."', '".$FormArguments['ZipPostal']."', '".$FormArguments['Country']."', '".$FormArguments['Phone']."', '".$FormArguments['Fax']."', '".$FormArguments['Cell']."', '".$FormArguments['Pager']."', '".$FormArguments['Website']."', '".$FormArguments['ReferredBy']."', '".$FormArguments['Custom1']."', '".$FormArguments['Custom2']."', '".$FormArguments['Custom3']."', '".$NewUserLevel."', 'y')";
				$result = mysql_query($query) or die (mysql_error());
			
			
				$FormArguments['NewPassword'] = str_replace('/','+++',$FormArguments['NewPassword']);
			
			
				$Message = $MsgText[0][143]."\n\n".$MsgText[0][140]."\n\n".$MsgText[0][99].': '.$FormArguments['NewUsername']."\n".$MsgText[0][131].': '.$PasswordEntered."\n\n".$MsgText[0][141]."\n\n\n\n".$MsgText[0][142].','."\n".$Settings['SiteName']."\n".$IndexURL;
				mail($FormArguments['Email'], $MsgText[0][143], $Message, 'From: "'.$Settings['SiteName'].'" <'.$Settings['ContactEmail'].'>','-f'.$Settings['ContactEmail']);
			
			}
			else if ($Settings['VerifyEmails'] == 'y') {
			
				$Chars = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');
				for ($i = 1; $i <= 20; $i++) {
					$RandomNum = rand(0,35);
					$ConfirmationCode .= $Chars[$RandomNum];
				}
			
						
			
				$query = "insert into `".$Settings['DBPrefix']."core-Users` (Username, Email, DisplayEmail, Password, RegistrationDate, FirstName, LastName, OrganizationCompany, Address1, Address2, Address3, Address4, City, StateProvince, ZipPostal, Country, Phone, Fax, Cell, Pager, Website, ReferredBy, Custom1, Custom2, Custom3, Level, ConfirmationCode, Verified, BarePassword, ReturnTo) values ('".$FormArguments['NewUsername']."', '".$FormArguments['Email']."', 'n', '".$FormArguments['NewPassword']."', '".GetTimestamp()."', '".$FormArguments['FirstName']."', '".$FormArguments['LastName']."', '".$FormArguments['OrganizationCompany']."', '".$FormArguments['Address1']."', '".$FormArguments['Address2']."', '".$FormArguments['Address3']."', '".$FormArguments['Address4']."', '".$FormArguments['City']."', '".$FormArguments['StateProvince']."', '".$FormArguments['ZipPostal']."', '".$FormArguments['Country']."', '".$FormArguments['Phone']."', '".$FormArguments['Fax']."', '".$FormArguments['Cell']."', '".$FormArguments['Pager']."', '".$FormArguments['Website']."', '".$FormArguments['ReferredBy']."', '".$FormArguments['Custom1']."', '".$FormArguments['Custom2']."', '".$FormArguments['Custom3']."', '".$NewUserLevel."', '".$ConfirmationCode."', 'n', '".$PasswordEntered."', '".$FormArguments['ReturnTo']."')";
				$result = mysql_query($query) or die (mysql_error());
			
			
				$FormArguments['NewPassword'] = str_replace('/','+++',$FormArguments['NewPassword']);
				
			
			
				$Message = $MsgText[0][143]."\n\n".$MsgText[0][656]."\n\n".$MainURL."/register-verify/".$FormArguments['Email']."/".$ConfirmationCode."\n\n\n\n".$MsgText[0][142].','."\n".$Settings['SiteName']."\n".$IndexURL;
				mail($FormArguments['Email'], $MsgText[0][143], $Message, 'From: "'.$Settings['SiteName'].'" <'.$Settings['ContactEmail'].'>','-f'.$Settings['ContactEmail']);
				
				
				
			}
			else {
			
				$query = "insert into `".$Settings['DBPrefix']."core-Users` (Username, Email, DisplayEmail, Password, RegistrationDate, FirstName, LastName, OrganizationCompany, Address1, Address2, Address3, Address4, City, StateProvince, ZipPostal, Country, Phone, Fax, Cell, Pager, Website, ReferredBy, Custom1, Custom2, Custom3, Level, Verified) values ('".$FormArguments['NewUsername']."', '".$FormArguments['Email']."', 'n', '".$FormArguments['NewPassword']."', '".GetTimestamp()."', '".$FormArguments['FirstName']."', '".$FormArguments['LastName']."', '".$FormArguments['OrganizationCompany']."', '".$FormArguments['Address1']."', '".$FormArguments['Address2']."', '".$FormArguments['Address3']."', '".$FormArguments['Address4']."', '".$FormArguments['City']."', '".$FormArguments['StateProvince']."', '".$FormArguments['ZipPostal']."', '".$FormArguments['Country']."', '".$FormArguments['Phone']."', '".$FormArguments['Fax']."', '".$FormArguments['Cell']."', '".$FormArguments['Pager']."', '".$FormArguments['Website']."', '".$FormArguments['ReferredBy']."', '".$FormArguments['Custom1']."', '".$FormArguments['Custom2']."', '".$FormArguments['Custom3']."', '".$NewUserLevel."', 'y')";
				$result = mysql_query($query) or die (mysql_error());
			
			
				$FormArguments['NewPassword'] = str_replace('/','+++',$FormArguments['NewPassword']);
			
			
				$Message = $MsgText[0][143]."\n\n".$MsgText[0][140]."\n\n".$MsgText[0][99].': '.$FormArguments['NewUsername']."\n".$MsgText[0][131].': '.$PasswordEntered."\n\n".$MsgText[0][141]."\n\n\n\n".$MsgText[0][142].','."\n".$Settings['SiteName']."\n".$IndexURL;
				mail($FormArguments['Email'], $MsgText[0][143], $Message, 'From: "'.$Settings['SiteName'].'" <'.$Settings['ContactEmail'].'>','-f'.$Settings['ContactEmail']);
				
				
				if ($LoggedIn != 'y') {
				
					if ($Settings['Notify'] == 'y') {
				
						if ($Settings['NotifyEmail'] != '') {
							$NotifyEmail = $Settings['NotifyEmail'];
						}
						else {
							$NotifyEmail = $Settings['ContactEmail'];
						}
				
						
						$Message = "\n".'A new user account has been created.'."\n\n\n".'Username: '.$FormArguments['NewUsername']."\n\n".'Name: '.$FormArguments['FirstName'].' '.$FormArguments['LastName']."\n\n\n\n".$MsgText[0][142].','."\n".$Settings['SiteName']."\n".$IndexURL;
						mail($NotifyEmail, 'New User Account Created', $Message, 'From: "'.$Settings['SiteName'].'" <'.$Settings['ContactEmail'].'>','-f'.$Settings['ContactEmail']);
				
			
					}
				
				}
				
			}
			
			
			
				
			
			
			
			
			$PageTitle = $MsgText[0][144];
			
			
			if ($FormArguments['ReturnTo'] != '') {
				$FormArguments['ReturnTo'] = '/'.$FormArguments['ReturnTo'];
			}
			
			if ($LoggedIn == 'y') {
				$PageContents = $MsgText[0][145].': <a href="'.$MainURL . '/login-submit-nf/'.$FormArguments['NewUsername'].'/'.$FormArguments['NewPassword'].$FormArguments['ReturnTo'].'">'.$MsgText[0][146].'</a><br><br>';			
			}
			else {
				if ($Settings['VerifyEmails'] == 'y') {
					$PageContents = $MsgText[0][659];
				}
				else {
					$PageContents = $MsgText[0][147].': <a href="'.$MainURL. '/login-submit-nf/'.$FormArguments['NewUsername'].'/'.$FormArguments['NewPassword'].$FormArguments['ReturnTo'].'">'.$MsgText[0][146].'</a><br><br>';
				}
			}
							
		}
	
		else {
	
			$PageTitle = $MsgText[0][148];
			
			if ($LoggedIn == 'y' && $Permissions[10] == 'y' && $Permissions[4] == 'y') {
				$LevelSelected[$FormArguments['NewUserLevel']] = ' selected';
				$query = "select * from `".$Settings['DBPrefix']."core-Permissions` where Level>=1 and Level<='".$UserLevel."' order by Level desc";
				$result = mysql_query($query) or die (mysql_error());
				while ($row = mysql_fetch_array($result)) {
					$LevelsDropdown .= '<option value="'.$row['Level'].'"'.$LevelSelected[$row['Level']].'> '.$row['Description'].' ('.$row['Level'].')</option>';
					//$LevelDescriptions[$row['Level']] = $row['Description'];
				}
			
				$NewUserLevel = '<br><br><br><b>'.$MsgText[0][224].'</b>:<br><select name="NewUserLevel" style="'.$FormStyle.'">'.$LevelsDropdown.'</select><br><br>';
			}
			else {
				$NewUserLevel = '<input type="hidden" name="NewUserLevel" value="1">';
			}
			
		
			$PageContents = $MsgText[0][149].'<br><br><br><form action="'.$MainURL. '/register-submit" method="post"><input type="hidden" name="ReturnTo" value="'.$FormArguments['ReturnTo'].'">'.$FinalCode.'<br>'.$NewUserLevel.'<br><br><br>'.$FiltersMessage.'<input type="submit" value="'.$MsgText[0][133].'" style="'.$FormStyle.'"></form>';
		
	
		}
	}
	else {
		
		if ($LoggedIn == 'y') {
			$PageContents = $MsgText[0][150];
		}
		else {
			$PageContents = $MsgText[0][134];
		}
	
	}
	
	
	}
	else {
		$PageContents = $MsgText[0][98];
	}
	

	// ========================================================================================




?>
