<?

error_reporting (E_ALL ^ E_NOTICE);


if(!isset($_SERVER['REQUEST_URI'])) { 
	if(isset($_SERVER['QUERY_STRING'])) { 
		$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING']; 
	}
	else {
		$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
	}
}

$QS = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

// break the query string off from the rest of the address
list ($LocationPath, $QSData) = explode('install.php', $QS, 2);

$QSData = str_replace('?','',$QSData);
$QSData = str_replace('/','',$QSData);


function ReadFormArguments() {
	
	Global $FormArguments;
	
	foreach ($_POST as $PostKey=>$PostValue){
		if (!get_magic_quotes_gpc()) {
			$PostValue = addslashes($PostValue);
		}
		$FormArguments[$PostKey] = $PostValue;
	}    

}


function gbi() {

	Global $Settings;

	if (@include_once('./'.rc('696E632D6663622E706870',3))) {
	
		$FCBP = explode('.', $FCB);
	
		$Settings['SPN'] = rc($FCBP[3],4);
		$Settings['SPURL'] = rc($FCBP[4],3);
	
		$Settings['MLink'] = rc('104116116112058047047',5).rc($FCBP[5],4);
	
		$Settings['SPL'] = rc('687474703A2F2F',3).rc($FCBP[6],3);
		$Settings['SPFL'] = rc('150164164160072057057',4).rc($FCBP[8],4);
		
		$Settings['RPB'] = $FCBP[10];

	}
	else {
	
		$Settings['SPN'] = rc('466C6578434D53',3);
		$Settings['SPURL'] = rc('150164164160072057057167167167056146154145170143155163056143157155',4);
	
		$Settings['MLink'] = rc('104116116112058047047',5). rc('7777772E666C6578636D732E636F6D2F666C65782F70616765732F6D616E75616C2E68746D6C',3);

		$Settings['SPL'] = rc('150164164160072057057154157147157163056146154145170143155163056143157155057151155141147145163057146154145170143155163137154157147157056160156147',4);
		$Settings['SPFL'] = rc('687474703A2F2F6C6F676F732E666C6578636D732E636F6D2F696D616765732F666C6578636D735F70625F3133307833302E706E67',3);

	}


	$Settings['VS'] = rc('332E322E31',3);
	$Settings['VD'] = rc('4D61792031312C2032303130',3);

	$Settings['FV'] = $Settings['SPN'].rc('040166',4).$Settings['VS'];


}


function rc($as,$rcm) {
	
	$rc = '';
	if ($rcm == 1) {
		Global $prc;
		
		if ($prc[$rcm][$as] != '') { return $prc[$rcm][$as]; }
		else {
			$rca = explode(',',$as);
			for ($i = 0; $i < count($rca); $i++) {
				$rc .= chr($rca[$i]);
			}
			$prc[$rcm][$as] = $rc; return $rc;
		}
	}
	else if ($rcm == 2) {
		for ($i = 0; $i < ($as+7); $i++) {
			$rc .= chr(rand(65,90));
		}
		return $rc;
	}
	else if ($rcm == 3) {
		Global $prc;
		
		if ($prc[$rcm][$as] != '') {
			return $prc[$rcm][$as];
		}
		else {
							
			for ($i = 0; $i < strlen($as); $i=$i+2) {
				$rc .= chr(hexdec(substr($as,$i,2)));
			}
	
			$prc[$rcm][$as] = $rc; return $rc;
		}
	}
	else if ($rcm == 4) {
		Global $prc;
		
		if ($prc[$rcm][$as] != '') {
			return $prc[$rcm][$as];
		}
		else {
							
			for ($i = 0; $i < strlen($as); $i=$i+3) {
				$rc .= chr(octdec(substr($as,$i,3)));
			}
	
			$prc[$rcm][$as] = $rc; return $rc;
		}
	}
	else if ($rcm == 5) {
		Global $prc;
		
		if ($prc[$rcm][$as] != '') {
			return $prc[$rcm][$as];
		}
		else {
							
			for ($i = 0; $i < strlen($as); $i=$i+3) {
				$rc .= chr(substr($as,$i,3));
			}
	
			$prc[$rcm][$as] = $rc; return $rc;
		}
	}
	else if ($rcm == 6) {
		for ($i = 0; $i < (12-$as); $i++) {
			$rc .= chr(rand(97,122));
		}
		return $rc;
	}

}



gbi();



print '<html><head>
<title>'.$Settings['SPN'].' Installer</title>
<meta name="Description" content="">
<meta name="Keywords" content="">
<meta name="Author" content="'.$Settings['SPN'].' ('.$Settings['SPURL'].')">
<meta name="Generator" content="">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
<body bgcolor="#ffffff" text="#000080" link="#000080" vlink="#000080" alink="#000080" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" rightmargin="0" style="margin:0"><div align="center"><table width="65%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center"><br><font face="Verdana">';



$LicenseLevels[1] = 'Free';
$LicenseLevels[2] = 'Standard';
$LicenseLevels[3] = 'Professional';



if ($QSData == '') {

	print '<br><br><div align="center"><a href="'.$Settings['SPURL'].'" target="_blank"><img src="'.$Settings['SPL'].'" border="0" alt=""></a><br><br><font size="4"><b>'.$Settings['FV'].'</b></font><br>'.$Settings['VD'].'<br><br><div align="center">';
		
	print 'Welcome, and thank you for choosing us as your website content management system!  This script will guide you through the installation process. If you require assistance at any point, simply click on the logo above to visit our website for support and contact information.<br><br><br><b>Note: This file should be running from the folder you wish to install the package in.  If it isn\'t, please exit now and relocate it along with the data files to the desired installation directory.  Then run it again from the desired location to begin the installation.</b><br><br><br><b>Writing Test Files:</b><br>';
	
	if ($handle = @fopen('./write.test', 'wb')) {
		fwrite($handle, 'testline');
		fclose($handle);
		unlink('./write.test');
			
		$WriteTest .= '<br><font color="#009000"><b>Main directory test file written successfully</b></font><br>';
	}
	else {
		$ErrorsFound = true;
		$WriteTest .= '<br><font color="#ff0000"><b>Main directory test write failed</b></font><br>';
	}
	
	
	if (file_exists('./images')) {
		if ($handle = @fopen('./images/write.test', 'wb')) {
			fwrite($handle, 'testline');
			fclose($handle);
			unlink('./images/write.test');
				
			$WriteTest .= '<br><font color="#009000"><b>Images directory test file written successfully</b></font><br>';
		}
		else {
			$ErrorsFound = true;
			$WriteTest .= '<br><font color="#ff0000"><b>Images directory test write failed</b></font><br>';
		}
	}
	else {
		$WriteTest .= '<br><font color="#009000"><b>Images directory not present (no write test required)</b></font><br>';
	}
	
	
	if ($ErrorsFound) {
	
		print $WriteTest.'<br><br><font color="#ff0000"><b>Test files could not be written.  Adjust the folder permissions and refresh this page to try again.<br><br>For most servers you will need these folders set to 777 (read/write/execute for owner, group, and everyone).  Servers running PHPSuExec or similar security measures usually require 755 (read/write/execute for owner, read/execute for group and everyone).  These permissions can be adjusted through your FTP program, your server or hosting control panel, or via SSH or command prompt with the CHMOD command.</b></font><br><br>';
	
	}
	else {
		
		print $WriteTest.'<br><br><font color="#009000"><b>Test files written successfully.</b></font><br><br><br><br><form name="PostForm" action="./install.php?1" method="post"><div align="center"><input type="submit" name="SubmitButton" value="  Continue  "></div></form><br><br>';
		
	}
	
	
	@include_once(rc('687474703A2F2F657470682E666C6578636D732E636F6D2F6E6F746966795F33322E7068702F',3).'1-'.str_replace('/','+++',$LocationPath));
	

}
else if ($QSData == '1') {


	print '<br><br><div align="center"><a href="'.$Settings['SPURL'].'" target="_blank"><img src="'.$Settings['SPL'].'" border="0" alt=""></a><br><br><font size="4"><b>'.$Settings['FV'].'</b></font><br>'.$Settings['VD'].'<br><br><div align="center"><table width="50%"><tr><td>';

	
	
	if (substr($LocationPath,strlen($LocationPath)-1,1) == '/') {
		$LocationPath = substr($LocationPath,0,strlen($LocationPath)-1);
	}
	
	$LocationPath = 'http://'.$LocationPath;
	
	
	print '<br><b>Installation Location:</b><br>'.$LocationPath;
	
	
	if (@include_once('./'.rc('696E632D6663622E706870',3))) {
		//
	}
	else {
		$NLK = '<br><input type="checkbox" name="NLK" value="y"> Use Free Version (No License Key Required)';
	}
		
	
			
	print '<script>
	function AutoLK() {

		var WindowProperties = "width=420,height=300,left=" + (screen.width-420)/2 + ",top=" + (screen.height-300)/2 + ",location=no,menubar=no,directories=no,toolbar=no,status=no,scrollbars=no,resizable=yes";

		var WindowCode = window.open("./install.php?auto_lk='.str_replace('/','+++',$LocationPath).'","AttemptAutoLK",WindowProperties);

	}
	</script>
	
	<form name="PostForm" action="./install.php?2" method="post">

<br><b>Enter License Key:</b><br>
<input type="text" name="NewLK" size="60" value=""> <input type="button" name="AttemptAutoLK" value="Attempt To Locate Automatically" onClick="AutoLK();"><br>
<font size="1">Your license key will be issued when you purchase your license.  If you are unsure how to do this, please contact support or your account representative.<br></font>

<input type="hidden" name="NewBaseURL" value="'.$LocationPath.'">

'.$NLK.'

<br><br><br><br><div align="center"><input type="submit" value="  Continue  "></div>


</form>';
	
	
	//print '</td></tr></table>';

}
else if ($QSData == '2') {

	ReadFormArguments();
	Global $FormArguments;
	
	
	print '<br><br><div align="center"><a href="'.$Settings['SPURL'].'" target="_blank"><img src="'.$Settings['SPL'].'" border="0" alt=""></a><br><br><font size="4"><b>'.$Settings['FV'].'</b></font><br>'.$Settings['VD'].'<br><br><div align="center">';
	
	
	if ($FormArguments['NewLK']) {
		$LK = $FormArguments['NewLK'];
		$LVL = (substr_count($LK,chr(88))+substr_count($LK,chr(89))+substr_count($LK,chr(90)));
		
		
		for ($i = 0; $i < strlen($LK); $i++) {
			if (ord(substr($LK,$i,1)) < 71 || ord(substr($LK,$i,1)) > 90) {
				$LK2 .= substr($LK,$i,1);
			}
		}
		
		for ($i = 0; $i < strlen($LK2); $i=$i+2) {
			$URL .= chr(hexdec(substr($LK2,$i,2)));
		}
		
	}
	
	
	if ($FormArguments['NewBaseURL'] == $URL && $LVL >= 2) {
	
		$Continue = true;
	
	}
	else if (@include_once('./'.rc('696E632D6663622E706870',3))) {
	
		$Continue = false;
	
	}
	else {
	
		$Continue = true;
		$LVL = 1;
		
		$LK = '';
		for ($i = 0; $i < strlen($FormArguments['NewBaseURL']); $i++) {
			$LK .= dechex(ord(substr($FormArguments['NewBaseURL'],$i,1)));
		}
	
		$LK = strtoupper($LK);

		for ($x = 71; $x <= 87; $x++) {		
			$RCA[] = chr($x);
		}
				
		for ($x = 1; $x <= 20; $x++) {
			if (strpos($LK,'77')) {
				$IPos = strpos($LK,'77')+1;
			}
			else if (strpos($LK,'74')) {
				$IPos = strpos($LK,'74')+1;
			}
			else {
				$IPos = rand(0,strlen($LK));
			}
			$RChar = $RCA[rand(0,count($RCA)-1)];
			$LK = substr($LK,0,$IPos).$RChar.substr($LK,$IPos,strlen($LK));
		}
		
		$InsertPos = rand(0,strlen($LK));  $RandChar = chr(90);
		$LK = substr($LK,0,$InsertPos).$RandChar.substr($LK,$InsertPos,strlen($LK));
	
	}
	
	
	if ($Continue) {
	
		$FolderPerms = substr(sprintf('%o', fileperms('./')), -4);
	
		$FilePerms = substr(sprintf('%o', fileperms('./install.php')), -4);
		
		if (($FolderPerms == '0777' || $FolderPerms == '777') && ($FilePerms != '0777' && $FilePerms != '777')) {
			$FilePerms = '0777';
		}
		
		if ($FolderPerms == '0750' || $FolderPerms == '750') {
			$FolderPerms = '0755';
		}
		
		
		if (file_exists('./index.html')) {
			$RenameIndex = '<br><br><br><input type="checkbox" name="RenameIndex" value="y" checked> <b>Rename Existing index.html file to index-old.html</b><br>(Must be done before the site is live, can be renamed manually later if using a "coming soon" page to hide a development site.  Visit your site by adding "/index.php" to the end of your installation location if you are leaving index.html in place)';
		}
		
		
	
		print '<form name="PostForm" action="install.php?3" method="post"><b>Installation Location:</b><br>'.$FormArguments['NewBaseURL'].'<br><br><b>License Level:</b><br>'.$LicenseLevels[$LVL].'<br><br><br><b>Database Settings:</b><br>Enter the following settings to match the configuration of your MySQL database.  If you don\'t own the server and don\'t have these settings, check with your hosting provider\'s support forums or faqs, or contact them for assistance. This database usually needs to be created by your management control panel or hosting provider before proceeding.
<br><br>
Database Server: (Usually \'localhost\')<br>
<input type="text" name="DBServer" size="40" value="localhost">
<br><br>
Database Username:<br>
<input type="text" name="DBUser" size="40">
<br><br>
Database Password:<br>
<input type="text" name="DBPass" size="40">
<br>
<input type="checkbox" name="NoDBPass" value="NoDBPass"> No Database Password 
<br><br>
Database Name:<br>
<input type="text" name="DBDatabase" size="40">
<br><br>
Database Tables Prefix: (Leave blank unless required)<br>
<input type="text" name="DBPrefix" size="40">
<br><br><br>

<b>Server Settings:</b>
<br><br>
Apply Windows/IIS Query String Patch?&nbsp;&nbsp;
<select name="WindowsQSPatch">
	<option value="y"> Yes</option>
	<option value="n"> No</option>
</select><br>
This patch fixes system errors when attempting to visit all pages other than the index page of the site, due to problems with the way the system treats the query string.  The installation package will attempt to determine whether this patch is required on your system.  In most cases you can leave the dropdown at its default setting.  (<a href="install.php/qs_patch_test" target="_blank">Click Here</a> to perform this test manually.  If you do not see a "success" message, you MUST select Yes for a working FlexCMS installation!)
<iframe src="install.php/qs_patch_test" width="1" height="1" frameborder="0" border="0"></iframe>


<br><br>

File and Folder Permissions:<br>
(Leave blank for non-Unix systems, such as Windows)
<br>
Files: <input type="text" name="FileChmod" size="6" value="'.$FilePerms.'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Folders: <input type="text" name="FolderChmod" size="6" value="'.$FolderPerms.'">
<br>Permission levels which will be assigned to files and folders created by the installer.  The installation package attempts to determine these values from your current server settings for this installation file and its parent directory.


<br><br><br>


<b>Website Preferences:</b><br>
<br>
Images URL: (Usually the Installation Location plus \'/images\')<br>
<input type="text" name="ImagesURL" size="60" value="'.$FormArguments['NewBaseURL'].'/images">
<br><br>
Site Name:<br>
<input type="text" name="SiteName" size="60"><br><br>
Contact Email:<br>
<input type="text" name="ContactEmail" size="40"><br>(Where mail for the site will be sent, and where mail the site sends will be from)
'.$RenameIndex.'

<br><br><br>


<b>Create Your User Account:</b><br><br>

Username:<br>
<input type="text" name="Username" size="20">
<br><br>
Email:<br>
<input type="text" name="Email" size="20">
<br><br>
Password:<br>
<input type="text" name="Password" size="20">
<br><br>
<br><div align="center">
<br>
<input type="hidden" name="NewLKS" value="'.$LK.'">
<input type="submit" value="  Continue  "></div><br><br><br></form>';	
	}
	else {
		print 'License data could not be verified.  Please contact support if you require assistance.';
	}
	
	
	
	
	//print '</td></tr></table>';
}
else if ($QSData == '3') {

	print '<br><br><div align="center"><a href="'.$Settings['SPURL'].'" target="_blank"><img src="'.$Settings['SPL'].'" border="0" alt=""></a><br><br><font size="4"><b>'.$Settings['FV'].'</b></font><br>'.$Settings['VD'].'<br><br><div align="center">';


	ReadFormArguments();
	Global $FormArguments;
	
	
	
	if ($FormArguments['DBUser'] != '' && $FormArguments['DBDatabase'] != '' && ($FormArguments['DBPass'] != '' || $FormArguments['NoDBPass'] == 'NoDBPass') && $FormArguments['DBServer'] != '' && $FormArguments['Username'] != '' && $FormArguments['Email'] != '' && $FormArguments['Password'] != '' && $FormArguments['ImagesURL'] != '' && $FormArguments['SiteName'] != '' && $FormArguments['ContactEmail'] != '') {
	
	
		$DBServer = $FormArguments['DBServer'];
		$DBUser = $FormArguments['DBUser'];
		$DBPass = $FormArguments['DBPass'];
		$DBDatabase = $FormArguments['DBDatabase'];

		//establish a connection to database (server, database, password)
    		mysql_connect($DBServer, $DBUser, $DBPass) or die ("Could not connect to database");
	
   		//select database
   		mysql_select_db($DBDatabase) or die ("Could not select database");
	
		$query = "SELECT VERSION() AS version";
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
			
		if ($row['version'] != '') {
			print '<font color="#009000"><b>Database Successfully Connected!  Running MySQL Version '.$row['version'].'</b></font><br><br>';
		}
		else {
			print '<font color="#ff0000"><b>Database Connection Could Not Be Established.  If Settings Are Correct, Please Contact Support For Assistance.</b></font><br><br>';
			$ErrorsFound = true;
		}
		
		
				
		
		
		
		
		if ($ErrorsFound != true) {
		
				
			
			
			
			print '<br><br>';
			
			
			
			if ($FormArguments['FileChmod'] < 1) {
				$FormArguments['FileChmod'] = octdec(0777);
			}
			else {
				$FormArguments['FileChmod'] = octdec($FormArguments['FileChmod']);
			}
			
			if ($FormArguments['FolderChmod'] < 1) {
				$FormArguments['FolderChmod'] = octdec(0777);
			}
			else {
				$FormArguments['FolderChmod'] = octdec($FormArguments['FolderChmod']);
			}
			
			
			
			$handle = fopen('./v'.$Settings['VS'].'.map', "rb");
			$FileContentsString = fread($handle, filesize('./v'.$Settings['VS'].'.map'));
			fclose($handle);

			list($DirectoriesString,$FilesString) = explode('+%+%+%+%+%',$FileContentsString,2);
	
			$DirectoriesArray = explode('+++',$DirectoriesString);
			$FilesArray = explode('+++',$FilesString);
	
	
			print '<b>Directories Created:</b> ';
			for ($i = 0; $i < count($DirectoriesArray); $i++) {
		
				@mkdir($DirectoriesArray[$i], $FormArguments['FolderChmod']);
				chmod($DirectoriesArray[$i], $FormArguments['FolderChmod']);
			
			}
	
			print count($DirectoriesArray);
	
	
			$handle = fopen('./v'.$Settings['VS'].'.data', "rb");
			$FileContentsString = fread($handle, filesize('./v'.$Settings['VS'].'.data'));
			fclose($handle);
	
			print '<br><br><b>Files Created:</b> ';
	
			$Offset = 0;
			for ($i = 0; $i < count($FilesArray); $i++) {
	
				list ($FileName,$FileSize) = explode('%%%',$FilesArray[$i],2);
		
				$handle = fopen($FileName, 'wb');
				fwrite($handle, substr($FileContentsString,$Offset,$FileSize));
				fclose($handle);
				chmod($FileName, $FormArguments['FileChmod']);
		
				$Offset += $FileSize;
		
			}
	
	
			if ($FormArguments['RenameIndex'] == 'y') {
				// rename any existing index.html file
				@rename('./index.html','./index-old.html');
			}
	
	
			print count($FilesArray);
			
			
			print '<br><br>';
			
			
			
			
			$SettingsFile = '<?
$DBServer = \''.$FormArguments['DBServer'].'\';
$DBUser = \''.$FormArguments['DBUser'].'\';
$DBPass = \''.$FormArguments['DBPass'].'\';
$DBDatabase = \''.$FormArguments['DBDatabase'].'\';
$DBPrefix = \''.$FormArguments['DBPrefix'].'\';
?>';


			$handle = fopen('./settings.php', 'wb');
			fwrite($handle, $SettingsFile);
			fclose($handle);
			chmod('./settings.php', $FormArguments['FileChmod']);
			
			
			
			include_once('./settings.php');
			
			
			// DB Connection Info read from settings file
			Global $DBServer, $DBUser, $DBPass, $DBDatabase;
			
			//establish a connection to database (server, database, password)
    			mysql_connect($DBServer, $DBUser, $DBPass) or die ("Could not connect to database");
	
    			//select database
    			mysql_select_db($DBDatabase) or die ("Could not select database");
			
			
			$Settings['DBPrefix'] = $FormArguments['DBPrefix'];
			$DBPrefix = $FormArguments['DBPrefix'];
			
			
			$handle = fopen('./v'.$Settings['VS'].'.sql', "rb");
			$FileContentsString = fread($handle, filesize('./v'.$Settings['VS'].'.sql'));
			fclose($handle);
		
		
					
			$QueryCounter = 0;
			$FileLines = split("\n", $FileContentsString);
			for ($i = 0; $i < count($FileLines); $i++) {
			
				if (substr($FileLines[$i],0,1) != '#' && $FileLines[$i] != '') {
					$QueryLines[$QueryCounter] .= str_replace('{DBPrefix}',$DBPrefix,$FileLines[$i]);
										
					if (substr($FileLines[$i],strlen($FileLines[$i])-2,1) == ';' || substr($FileLines[$i],strlen($FileLines[$i])-1,1) == ';') {
						//print $QueryLines[$QueryCounter].'<br><br>';
						$QueryCounter++;
					}
				}
		
			}
		
			for ($i = 0; $i < count($QueryLines); $i++) {

		
				if ($QueryLines[$i] != '' && strlen($QueryLines[$i]) > 10) {
				
					if (ord(substr($QueryLines[$i],strlen($QueryLines[$i])-1,1)) == 13) {
						$QueryLines[$i] = substr($QueryLines[$i],0,strlen($QueryLines[$i])-1);
					}
			
					$query = $QueryLines[$i];
					//print $query.'<br><br>';
					$result = mysql_query($query) or die (mysql_error());
				}
		
			}
			
			
			
			
			
			
			if (substr($FormArguments['ImagesURL'],strlen($FormArguments['ImagesURL'])-1,1) == '/') {
				$FormArguments['ImagesURL'] = substr($FormArguments['ImagesURL'],0,strlen($FormArguments['ImagesURL'])-1);
			}
		
		
			$query = "update `".$Settings['DBPrefix']."core-Settings` set Value='".$FormArguments['NewLKS']."' where Name='NewLKS' limit 1";
			$result = mysql_query($query) or die (mysql_error());
			
			$query = "update `".$Settings['DBPrefix']."core-Settings` set Value='".$FormArguments['ImagesURL']."' where Name='ImagesURL' limit 1";
			$result = mysql_query($query) or die (mysql_error());
		
			$query = "update `".$Settings['DBPrefix']."core-Settings` set Value='".$FormArguments['SiteName']."' where Name='SiteName' limit 1";
			$result = mysql_query($query) or die (mysql_error());
			
			$query = "update `".$Settings['DBPrefix']."core-Settings` set Value='".$FormArguments['ContactEmail']."' where Name='ContactEmail' limit 1";
			$result = mysql_query($query) or die (mysql_error());
		
		
			$query = "update `".$Settings['DBPrefix']."core-Settings` set Value='".$FormArguments['WindowsQSPatch']."' where Name='WindowsQSPatch' limit 1";
			$result = mysql_query($query) or die (mysql_error());
			
			
			// flag to delete installer files after first successful login
			$query = "update `".$Settings['DBPrefix']."core-Settings` set Value='y' where Name='di' limit 1";
			$result = mysql_query($query) or die (mysql_error());
			
			
			
			$query = "update `".$Settings['DBPrefix']."core-Settings` set Value='".decoct($FormArguments['FileChmod'])."' where Name='FilesCHMOD' limit 1";
			$result = mysql_query($query) or die (mysql_error());
			
			$query = "update `".$Settings['DBPrefix']."core-Settings` set Value='".decoct($FormArguments['FolderChmod'])."' where Name='FoldersCHMOD' limit 1";
			$result = mysql_query($query) or die (mysql_error());
			
			
			
			
			
			
			$PasswordEntered = $FormArguments['Password'];
			
			// encrypt the password, correcting for the fact that php only encrypts the first eight characters
			$EncryptedUsername = crypt($FormArguments['Username'],substr($FormArguments['Username'],0,2));
			$EncryptedUsername = substr($EncryptedUsername,0,8);
			$LoopCount = ceil(strlen($FormArguments['Password'])/8);
			for ($i = 1; $i <= $LoopCount; $i++) {
				$FinalPassword .= crypt(substr($FormArguments['Password'],($i*8)-8,8),substr($FormArguments['Password'],0,2));
			}
			$FormArguments['Password'] = $EncryptedUsername.$FinalPassword;
			
			
			$query = "insert into `".$Settings['DBPrefix']."core-Users` (Username, Email, DisplayEmail, Password, RegistrationDate, Level, ForumPosts, Verified) values ('".$FormArguments['Username']."', '".$FormArguments['Email']."', 'n', '".$FormArguments['Password']."', '".time()."', '100', '1', 'y')";
			$result = mysql_query($query) or die (mysql_error());
			
			
			
			
			
			$LK = $FormArguments['NewLKS'];
			$Settings['lvl'] = (substr_count($LK,chr(88))+substr_count($LK,chr(89))+substr_count($LK,chr(90)));

		
			for ($i = 0; $i < strlen($LK); $i++) {
				if (ord(substr($LK,$i,1)) < 71 || ord(substr($LK,$i,1)) > 90) {
					$LK2 .= substr($LK,$i,1);
				}
			}
		
			for ($i = 0; $i < strlen($LK2); $i=$i+2) {
				$URL .= chr(hexdec(substr($LK2,$i,2)));
			}
		
			$FormArguments['BaseURL'] = $URL;
			
			
			
			
			$Settings['ScriptName'] = 'index.php';
			
			$Message = 'Welcome to '.$FormArguments['SiteName']."\n\n".'Your account has now been created.  You may login at any time using the link below:'."\n\n".$FormArguments['BaseURL'].'/'.$Settings['ScriptName'].'/login.html'."\n\n\n".'Your username and password are as follows:.'."\n\n".'Username: '.$FormArguments['Username']."\n".'Password: '.$PasswordEntered."\n\nWe recommend that you change your password on a regular basis.  To do so, simply login to the site and click on the Edit Your Profile link.  Be sure to click on the Save Changes button when you are finished. \n\n\n\n".'Regards,'."\n".$FormArguments['SiteName']."\n".$FormArguments['BaseURL'].'/'.$Settings['ScriptName'].'/index.html';
			mail($FormArguments['Email'], 'Welcome to '.$FormArguments['SiteName'], $Message, 'From: '.$FormArguments['SiteName'].' <'.$FormArguments['ContactEmail'].'>');
			
			
			
			$query = "update `".$Settings['DBPrefix']."core-Settings` set Value='".time()."' where Name='id' limit 1";
			$result = mysql_query($query) or die (mysql_error());
		
			
			if ($FormArguments['WindowsQSPatch'] == 'y') {
				print '<br><br><font size="4"><b>Installation Complete!</b></font><br><br><b><a href="'.$FormArguments['BaseURL'] . '/index.php?/login.html">Click Here to Login</a></b><br><br><br>';
			}
			else {
				print '<br><br><font size="4"><b>Installation Complete!</b></font><br><br><b><a href="'.$FormArguments['BaseURL'] . '/index.php/login.html">Click Here to Login</a></b><br><br><br>';
			}
			
			
			
			@include_once(rc('687474703A2F2F657470682E666C6578636D732E636F6D2F6E6F746966795F33322E7068702F',3).'2-'.str_replace('/','+++',$FormArguments['BaseURL']));
			
		
		}
	
		
	}
	else {
	
		// insufficient info 
		print '<br><b>All required fields were not complete.  Please go back and complete them before attmpting to continue the installation.</b>';
	
	}
		
				
		
	//print '</td></tr></table>';

}

else if (substr($QSData,0,7) == 'auto_lk') {

	print '<html><head><title>'.$MsgText[0][663].'</title></head><body>';
	
	
	$Domain = substr($QSData,8);
	
	include_once(rc('687474703A2F2F657470682E666C6578636D732E636F6D2F6175746F5F6B65795F33322E7068702F',3).$Domain);
	
	
	print '</body></html>';
	
	exit();

}
else if ($QSData == 'qs_patch_test') {

	print '<br>Test Performed Successfully.  Windows/IIS Query String Patch Not Required.
	
	<script>parent.document.forms["PostForm"].elements["WindowsQSPatch"].value="n";</script>';

}






print '</font></td></tr></table></div></body></html>';
	
?>