<?

/*
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
*/



	// ========================================================================================
	// create registration page
	// ========================================================================================
	
	$PageTitle = $MsgText[0][124];
	$BrowserTitle = $MsgText[0][124];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > '.$MsgText[0][124];
	
	
	ReadPermissions();
	Global $Permissions;
	
	$AccountAllowed = 'n';
	if ($LoggedIn == 'y' && $Permissions[10] == 'y') {
		$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_usersandpermissions.gif" width="19" height="20"> '.$MsgText[0][125];
		$BrowserTitle = $MsgText[0][125];
		$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[0][125];		
		
		$PageContents = $MsgText[0][126].'<br><br>';
		
		if ($Permissions[4] == 'y') {
			$LevelSelected[1] = ' 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">';
		}
		
		
		$AccountAllowed = 'y';
	}
	else if ($Settings['AllowGuestRegistrations'] == 'y') {
	
		if ($Arguments2 != '') {
			// add the return URL into the login link if one exists
			$MsgText[0][127] = str_replace($MainURL . '/login.html', $MainURL . '/login/'.$Arguments2, $MsgText[0][127]);
		}
	
		$PageContents = $MsgText[0][127].'<br><br>';
		$FiltersMessage = $MsgText[0][128].'<br><br><br>';
		$NewUserLevel = '<input type="hidden" name="NewUserLevel" value="1">';
		$AccountAllowed = 'y';
	}
	
	if ($AccountAllowed == 'y') {
	
		$RegFormCode = '<input type="hidden" name="ReturnTo" value="'.$Arguments2.'"><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.'"><br><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.'"><br><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.'"><br>';

		$RegFormOpts = explode('%%', $Settings['RegFormOpts']);

	
		$FieldName[1] = $MsgText[0][100];
		$FieldCode[1] = '<input type="text" name="FirstName" size="20" maxlength="40" style="'.$FormStyle.'">';
		
		$FieldName[2] = $MsgText[0][101];
		$FieldCode[2] = '<input type="text" name="LastName" size="20" maxlength="40" style="'.$FormStyle.'">';
		
		$FieldName[3] = $MsgText[0][102];
		$FieldCode[3] = '<input type="text" name="OrganizationCompany" size="35" maxlength="50" style="'.$FormStyle.'">';
		
		$FieldName[4] = $MsgText[0][103];
		$FieldCode[4] = '<input type="text" name="Address1" size="30" maxlength="40" style="'.$FormStyle.'">';
		$FieldName[5] = $MsgText[0][103];
		$FieldCode[5] = '<input type="text" name="Address2" size="30" maxlength="40" style="'.$FormStyle.'">';
		$FieldName[6] = $MsgText[0][103];
		$FieldCode[6] = '<input type="text" name="Address3" size="30" maxlength="40" style="'.$FormStyle.'">';
		$FieldName[7] = $MsgText[0][103];
		$FieldCode[7] = '<input type="text" name="Address4" size="30" maxlength="40" style="'.$FormStyle.'">';
		
		$FieldName[8] = $MsgText[0][104];
		$FieldCode[8] = '<input type="text" name="City" size="20" maxlength="40" style="'.$FormStyle.'">';
				
		$FieldName[9] = $MsgText[0][105];
		$FieldCode[9] = '<input type="text" name="StateProvince" size="25" maxlength="40" style="'.$FormStyle.'">';
		
		$FieldName[10] = $MsgText[0][106];
		$FieldCode[10] = '<input type="text" name="ZipPostal" size="10" maxlength="15" style="'.$FormStyle.'">';
		
		
		if ($Settings['SiteCountry'] == '') {
			$Settings['SiteCountry'] = 'US';
		}
		
		$query6 = "select * from `".$Settings['DBPrefix']."core-Countries` where AllowUsers=1 order by Name asc";
		$result6 = mysql_query($query6) or die (mysql_error());
		while ($row6 = mysql_fetch_array($result6)) {
			if ($row6['Code'] == $Settings['SiteCountry']) {
				$CountriesList .= '<option value="'.$row6['Code'].'" selected> '.$row6['Name'].'</option>';
			}
			else {
				$CountriesList .= '<option value="'.$row6['Code'].'"> '.$row6['Name'].'</option>';
			}
		}
		
		
		$FieldName[11] = $MsgText[0][107];
		$FieldCode[11] = '<select name="Country" style="'.$FormStyle.'">'.$CountriesList.'</select>';
		
		$FieldName[12] = $MsgText[0][108];
		$FieldCode[12] = '<input type="text" name="Phone" size="15" maxlength="20" style="'.$FormStyle.'">';		
		
		$FieldName[13] = $MsgText[0][109];
		$FieldCode[13] = '<input type="text" name="Fax" size="15" maxlength="20" style="'.$FormStyle.'">';
		
		$FieldName[14] = $MsgText[0][110];
		$FieldCode[14] = '<input type="text" name="Cell" size="15" maxlength="20" style="'.$FormStyle.'">';
		
		$FieldName[15] = $MsgText[0][111];
		$FieldCode[15] = '<input type="text" name="Pager" size="15" maxlength="20" style="'.$FormStyle.'">';
		
		$FieldName[16] = $MsgText[0][112];
		$FieldCode[16] = '<input type="text" name="Website" size="35" maxlength="70" style="'.$FormStyle.'">';
		
		$FieldName[17] = $MsgText[0][113];
		$FieldCode[17] = '<input type="text" name="ReferredBy" size="35" maxlength="50" style="'.$FormStyle.'">';
					
		$FieldName[18] = $RegFormOpts[0];
		$FieldCode[18] = '<input type="text" name="Custom1" size="35" maxlength="50" style="'.$FormStyle.'">';
		
		$FieldName[19] = $RegFormOpts[1];
		$FieldCode[19] = '<input type="text" name="Custom2" size="35" maxlength="50" style="'.$FormStyle.'">';
		
		$FieldName[20] = $RegFormOpts[2];
		$FieldCode[20] = '<input type="text" name="Custom3" size="35" maxlength="50" style="'.$FormStyle.'">';
		
	
		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];
					}
				}
				
				
			} 
		}
		
		
		$PageContents .= '<form action="'.$MainURL.'/register-submit" method="post">'.$MsgText[0][114].'<br><br>'.$RegFormCode.'<br>'.$NewUserLevel.'<br><br><br>'.$FiltersMessage.'<input type="submit" value="'.$MsgText[0][133].'" style="'.$FormStyle.'"></form><br><br>';
	
	}
	else {
		
		$PageContents = $MsgText[0][134];
	
	}

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




?>
