Location: PHPKode > projects > Enigma > Enigma2/Enigma2_Install/LSP_install.php
<?php
/*
*****************************************************************

 LSP_install.php

*****************************************************************
LSP: Lunabyte Systems Portal
Open-Source Project Inspired by Zef Hemel (hide@address.com)
*****************************************************************
Software Version:                  LSP 2.0 "Enigma 2"
Software by:                         Lunabyte Systems (http://www.lunabyte.net)
Copyright 2002-2005 by:       Lunabyte Systems (http://www.lunabyte.net)
Support, News, Updates at:    http://www.lunabyte.net
*****************************************************************
This program is free software; you may redistribute it and/or modify it 
under the terms of the provided license as published by Lunabyte Systems.

This program is distributed in the hope that it is and will be useful,                  
but WITHOUT ANY WARRANTIES; without even any implied warranty of           
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                        

See the "LSP_license.txt" file for details of the LSP license.
The latest version can always be found at http://www.lunabyte.net.
*****************************************************************
*/

$self = $_SERVER['PHP_SELF'];

// set var for checking the intro pages location
$intro = empty($_POST['intro']) ? 1 : $_POST['intro'];

// are the options set?
$opset = empty($_POST['option']) ? '0' : '1';
$inste2_block = (empty($_POST['inste2_block'])) ? '' : $_POST['inste2_block'];
$page_title = (($opset == '0' && $intro != 6 && $_POST['option'] != 'upgrade') || ($opset == '1' && $_POST['option'] == 'install')) ? 'Installation' : 'Upgrade';

$portal_version = 'Enigma 2.0 (RC1)';

$portal = 'My Community | Powered by <a href="http://www.lunabyte.net/" title="Lunabyte Systems Portal" target="_blank">' . $portal_version . '</a>.<br />&copy; 2003-' . date('Y') . ', LSP Dev Team. All Rights Reserved.';

$current_enigma_version = 'LSP: ' . $portal_version;
$smf_version_support = 'SMF 1.0.7';
$smf_package_support = 'smf_1-0-7_';
$smf_version_setting = '1.0.7';

// Get the settings.
include_once ("Settings.php");

// Set Errors at zero.
$error = 0;

// Start upgrade display
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>', $current_enigma_version, ' ', $page_title, '</title>
<style>
	<!--
		body {
			font-family: Verdana;
			font-size: 10pt;
		}
		td {
			font-size: 10pt;
		}
		.title {
			text-align: center;
			background-color: #769D7D;
			color: #000000;
			font-size: 12pt;
			font-weight: bold;
			padding: 4px;
		}
		.main {
			margin-left: 40px;
			margin-right: 40px;
			margin-top: 10px;
		}
		.er {
			font-weight: bold;
			color: #FF0000;
		}
		.ok {
			color: #00CC00;
		}
		.stp {
			font-size: 18pt;
			font-color: #FF0000;
			font-weight: bold;
		}
		legend
		{
			font-weight: bold;
			color: #008080;
		}
		P
		{
			margin-left: 40px;
		}
		.option
		{
			margin-left: 50px;
		}
	-->
</style>
</head>
<body bgcolor="#CEDCD1">
<div class="title">', $current_enigma_version, ' ', $page_title, '</div>
<div class="main">';


//if ($opset == '0')
if ($intro != 'done' && empty($_POST['step']))
{
	echo '
<script language="javascript">
	function enableupgrade()
	{
	// Clear install form fields

	// Disable install form fields

	// Enable upgrade form fields

		document.doinstall.inste2_block0.disabled = false;
		document.doinstall.inste2_block1.disabled = false;

		document.doinstall.inste2_block0.checked = true;

		document.doinstall.homepage_news0.disabled = false;
		document.doinstall.homepage_news1.disabled = false;

		document.doinstall.homepage_news0.checked = true;
	}

	function disableupgrade()
	{
	// Clear upgrade form fields

		document.doinstall.inste2_block0.checked = false;
		document.doinstall.inste2_block1.checked = false;
		document.doinstall.homepage_news0.checked = false;
		document.doinstall.homepage_news1.checked = false;

	// Disable upgrade form fields

		document.doinstall.inste2_block0.disabled = true;
		document.doinstall.inste2_block1.disabled = true;
		document.doinstall.homepage_news0.disabled = true;
		document.doinstall.homepage_news1.disabled = true;

	// Enable install form fields

	}
</script>';

	if ($intro == 1)
	{
		echo '
	<fieldset name="intro1" id="options1">
		<legend id="legend1">Welcome! ', $current_enigma_version, ' Installation</legend>
		Since you have started this installer, you should have already read the "Readme_First.txt" and have ', $smf_version_support, ' installed and running!<br />
		If you have not yet read through the "Readme_First.txt" file, please do so now as it should answer any questions you may have about the options in this install script.<br /><br />
		If you already have a previous version of Enigma2 installed on your server, please <b>Stop Here!</b><br />
		This installation is only for users that have not yet installed Enigma2.  You will need to refer to the
		"Readme_First.txt" file in the <b>"Enigma2_Upgrade_from_{version}"</b> directory of the Enigma2 release.<br /><br />
		<b>Do you have ', $smf_version_support, ' installed and running?</b><br />
		<form name="intro1form" method="post" action="', $self, '">
				<p><input type="radio" name="intro" value="2" /> Yes, Continue Enigma Installation</p>
				<p><input type="radio" name="intro" value="SMFinfo" /> No, I still need to install SMF</p>
			<center><input type="submit" value="Continue" name="submit" /></center>
		</form>
	</fieldset>';
	}
	elseif ($intro == 'SMFinfo')
	{
		echo '
	<fieldset name="intro1" id="options1">
		<legend id="legend1">Welcome! ', $current_enigma_version, ' Installation</legend>

		You have indicated that you still need to install ', $smf_version_support, '.<br /><br />
		Please Select the SMF package that fits your needs!
		<p>• If you are upgrading from Enigma 1.x or YaBB SE 1.5.5 please download and install the ', $smf_package_support, ' upgrade package.</p>
		<p>• If you currently have an SMF installation older than ', $smf_version_support, ' eg:(SMF 1.0.5 or lower) please download and install the ', $smf_package_support, 'update package.</p>
		<p>• If you have never had Enigma 1.x, YaBB SE 1.5.5 or SMF 1.0.x please download and install the ', $smf_package_support, 'installation package.</p>
		Please visit <a href="http://www.simplemachines.org/download.php">SMF\'s Download site by clicking here</a>.<br />
		If you have trouble installing ', $smf_version_support, ', please refer to the SMF website for help.<br /><br />
		After installing SMF, please run this install script again. Thanks.
	</fieldset><br />';
	}
	elseif ($intro == 2)
	{
		echo '
	<fieldset name="intro2" id="options1">
		<legend id="legend1">Default Theme settings</legend>
		You have indicated that you have ', $smf_package_support, ' installed and running correctly.<br />
		After installing ', $smf_package_support, ', you should have uploaded and installed the "LSP Enigma 2.0 (RC1) Installation Package" via the Package Manager in your Admin Center.<br />
		If you have not done that yet, please refer back to the "Readme_First.txt" file in the "Enigma2_Install" directory of the Enigma2 release.<br /><br />

		<b>Have you installed the  "LSP Enigma 2.0 (RC1) Installation Package" via the Package Manager in your Admin Center without having any errors?</b>
		<form name="intro2form" method="post" action="', $self, '">
				<p><input type="radio" name="intro" value="moderrors" /> Yes, but there were errors</p>
				<p><input type="radio" name="intro" value="modinstall" /> No, I still need to install the package</p>
				<p><input type="radio" name="intro" value="3" /> Yes, Continue Enigma Installation</p>
			<center><input type="submit" value="Continue" name="submit" /></center>
		</form>
	</fieldset>';
	}
	elseif ($intro == 'moderrors')
	{
		echo '
	<fieldset name="intro2" id="options1">
		<legend id="legend1">Default Theme settings</legend>
		You have indicated that you received or encountered errors when installing  the  "LSP Enigma 2.0 (RC1) Installation Package" via the Package Manager in your Admin Center.<br /><br />
		You will need to correct these errors before continuing or your Enigma installation will not work properly.  If you can not correct these errors on your own,
		please visit the <a href="http://www.lunabyte.net">LSP Enigma Website</a> for help and support.<br /><br />
		Once you have successfully installed the package, please run this install script again.';
	}
	elseif ($intro == 'modinstall')
	{
		echo '
	<fieldset name="intro2" id="options1">
		<legend id="legend1">Default Theme settings</legend>
		You have indicated that have not yet installed the  "LSP Enigma 2.0 (RC1) Installation Package" via the Package Manager in your Admin Center.<br /><br />
		This step needs to be completed before continuing or your Enigma installation will not work properly.<br />
		Please refer to the "Readme_First.txt" file in the "Enigma2_Install" directory of the Enigma2 release for instructions and additional information.<br />
		You may also visit the <a href="http://www.lunabyte.net">LSP Enigma Website</a> for help and support.<br /><br />
		Once you have successfully installed the package, please run this install script again.';
	}
	elseif ($intro == 3)
	{
		echo '
	<fieldset name="intro2" id="options1">
		<legend id="legend1">Default Theme settings</legend>
		In order for your ', $current_enigma_version, ' Site to function properly and be as compatible as possible with any mods
		you may wish to install, you will need to make some changes to your Theme directories.<br /><br />
		<b>Before continuing any further</b> you need to rename 2 of the directories inside the "Themes" directory of Enigma/SMF on your server. Make sure
		to do this in order or you will most likely have problems.</p>
		<p>• Rename the "default" theme directory to "SMF_default"</p>
		<p>• Rename the "Enigma" theme directory to "default"</p>
		<br />
		Upon completion of the Enigma installation, your sites "default" theme will be set to the new Enigma default theme
		in order for you to fully access your site. The newly named SMF_default theme will be re-assigned as a selectable theme.
		You may modify any of the themes, to suit your personal preferences or create a new theme with custom formatting
		once your installation is completed.<br />
		It is recommended that you create a "new" custom theme, rather than editting the "default" theme as it will help prevent future
		problems with any upgrades that you may install.  For more information about creating custom themes, please visit the
		<a href="http://www.lunabyte.net">LSP Enigma Website</a> for help and support.<br /><br />
		<form name="intro3form" method="post" action="', $self, '">
			<center>Once you have finished renaming the directories as listed above, you may continue.
			<input type="hidden" name="intro" value="4" />
			<input type="submit" value="Continue" name="submit" /></center>
		</form>
	</fieldset><br />';
	}
	elseif ($intro == 4)
	{
		// check if the theme directories were renamed as instructed
		if (!Is_dir($boarddir . '/Themes/SMF_default'))
		{
			echo '
			<p><b>"SMF_default" Theme directory does not exist!</b>  You must have missed a step.<br />
			Rename your original "default" Theme directory to "SMF_default".<br />
			This needs to be corrected before continuing.</p>
			<br />';
			$themesOk = false;
		}
		elseif (Is_dir($boarddir . '/Themes/Enigma'))
		{
			echo '
			<p><b>"Enigma" Theme directory still exists!</b> You must have missed a step.<br />
			Rename the "Enigma" Theme directory to "default" after renaming the original "default" directory to SMF_Default, if you have not done it already.<br />
			This needs to be corrected before continuing.</p>
			<br />';
			$themesOk = false;
		}
		elseif (!Is_dir($boarddir . '/Themes/default'))
		{
			echo '
			<p><b>You do not have a "default" Theme directory!</b> You must have missed a step.<br />
			Please recheck the Theme directory steps in the "Readme_first.txt" file.<br />
			This needs to be corrected before continuing.</p>
			<br />';
			$themesOk = false;
		}
		else
		{
			$themesOk = true;
			$intro = 5;
		}

		if (!$themesOk)
		{
			echo '
			<form action="' . $self . '" method="post">
				<input type="hidden" name="intro" value="4" />
				<input type="submit" value="Check Again" />
			</form>';
	
		}
	}

	if ($intro == 5)
	{
		echo '
	<fieldset name="options1" id="options1">
		<legend id="legend1">Installation options</legend>

		Now we need to know if if this is the first time you have ever installed Enigma or you are upgrading from Enigma 1.x.<br /><br />
		Please check which of the following options fit your ', $current_enigma_version, ' installation.
		<form name="doinstall" method="post" action="', $self, '">

			<p><b>Option 1, First time installation of Enigma</b><br /></p>
			<p class="option"><input type="radio" name="intro" value="done" /> ', $current_enigma_version, ' Clean install.</p>

			<hr />

			<p><b>Option 2, Upgrade from Enigma 1.x</b><br /></p>
			<p class="option"><input type="radio" name="intro" value="6" /> ', $current_enigma_version, ' Upgrade.<br /></p>
			
			<center><input type="submit" value="Submit" name="submit" /></center>
		</form>
	</fieldset>';
	}
	elseif ($intro == 6)
	{
		echo '
	<fieldset name="options1" id="options1">
		<legend id="legend1">Upgrade options</legend>

		<form name="doinstall" method="post" action="', $self, '">
			You have indicated that you are upgrading from Enigma 1.x.  You will now need to select a couple of options for
			the upgrade.<br /><br />
			Enigma 1.x blocks and most custom blocks will not function correctly in Enigma2 and Enigma 1.x menu tags will not work
			in Enigma2 without being modified.  It is recommended to have the Enigma2 default Blocks and Menus installed.<br />
			<b>NOTE: All Enigma 1.x blocks will be turned off by default, even if you select not to install E2 defaults!</b><br />
			<br />
			<p><b>Would you like to install the Enigma2 default Blocks & Menus?</b></p>
			<span class="option"> <input type="radio" name="inste2_block" value="1" checked="checked" /> Yes</span><br />
			<span class="option"> <input type="radio" name="inste2_block" value="0" /> No</span><br />
			<br /><br />
			Next we need to find out what to use for your "Homepage" setting in Enigma2.<br />
			If your current homepage is using a function like news() or articleSum() it will
			not function properly in Enigma2 and we suggest changing your homepage setting.<br />
			Answering "Yes" to the option below will set your homepage to display front page news.  You may
			change this from the Admin Center when you are ready to, after the Enigma2 upgrade is complete.<br />
			<b>Note: By not selecting this option, your current, Enigma 1.x, homepage setting will be used.</b><br />
			<br />
			<p><b>Would you like to set your "Homepage" to use the Enigma2 "Sitenews"?</b></p>
			<span class="option"> <input type="radio" name="homepage_news" value="1" checked="checked" /> Yes</span><br />
			<span class="option"> <input type="radio" name="homepage_news" value="0" /> No</span><br />
			<br />
			<input type="hidden" name="intro" value="done" />
			<input type="hidden" name="option" value="upgrade" />
			<center><input type="submit" value="Continue" name="submit" /></center>
		</form>
	</fieldset>';
	}
} else {

	$x = 'Powered';
	$y = stristr($portal, $x);
	$lpc = md5($y . '$this->lsp_tag');
	$lpv = md5($y . '$this->lsp_version');
	$lpy = md5(date('Y'));

		// Initial step. Verify password and username match.
		if (empty($_POST['step']))
		{
			echo '
		<b>Before continuing any further, please remember to backup your database.  If this
			script fails for any reason, you may be required to restore your old database!</b><br />
		<br />
		<form action="' . $self . '" method="post">
			<p>We need to verify that you are the owner of this site and allowed to access the database before continuing.</p>
			<p><input type="text" name="dbn" size="10" /> Database Username<br />
				<input type="password" name="dbp" size="10" /> Database Password</p>
			<input type="hidden" name="step" value="1" />';


			if ($_POST['option'] == 'upgrade')
				echo '
			<input type="hidden" name="option" value="upgrade" />
			<input type="hidden" name="inste2_block" value="', $inste2_block, '" />
			<input type="hidden" name="homepage_news" value="', $_POST['homepage_news'], '" />';
			else
				echo '
			<input type="hidden" name="option" value="install" />';

			echo '
			<p><input type="submit" value="Authenticate Me" /></p>
			</form>';
		}

		elseif (!empty($_POST['step']))
		{
		
			if ($_POST['step'] == '1')
			{
				// Set verification counter.
				$verify = 0;

				// Verify DB username.
				if ($_POST['dbn'] == $db_user)
					$verify++;

				// Verify DB password.
				if ($_POST['dbp'] == $db_passwd)
					$verify++;

				// Verification successful, continue on to installing DB.
				if ($verify == '2')
				{
					echo '
		<form action="' . $self . '" method="post">
			<p>Authentication was successful.</p>
			<p>We are now ready to proceed with installing your database.</p>
			<p><b>Make sure you have backed up your database.  If this
			script fails for any reason, you may be required to restore your old database!</b></p>
			<input type="hidden" name="step" value="2" />';

					if ($_POST['option'] == 'upgrade')
						echo '
			<input type="hidden" name="inste2_block" value="', $inste2_block, '" />
			<input type="hidden" name="homepage_news" value="', $_POST['homepage_news'], '" />';

					echo '
			<input type="hidden" name="option" value="' . ($_POST['option']) . '" />
			<p><input type="submit" value="Proceed" /></p>
		</form>';
				}

				// Verification Failed.
				else
				{
					echo '
		<p>Authentication Failed!</p>
		<p>We are unable to proceed with ' . (($_REQUEST['option'] == 'install') ? 'installing' : 'upgrading') . ' your database.</p><br />
		<form action="' . $self . '" method="post">
			<input type="hidden" name="intro" value="done" />';
					if ($_POST['option'] == 'upgrade')
						echo '
			<input type="hidden" name="inste2_block" value="', $inste2_block, '" />
			<input type="hidden" name="homepage_news" value="', $_POST['homepage_news'], '" />';

					echo '
			<input type="hidden" name="option" value="' . ($_POST['option']) . '" />
			<p><input type="submit" value="Try Again" /></p>
		</form>';
				}
			}

	// Install the DB.
			elseif ($_POST['step'] == '2')
			{
				$dbcon = mysql_connect($db_server, $db_user, $db_passwd);
				mysql_select_db($db_name);

				// Load the existing table names into an array for checking what exists
				$result = mysql_list_tables($db_name);
				$existingTables = array();
				while ($tables=mysql_fetch_row($result))
					$existingTables[] = $tables[0];
				mysql_free_result($result);

				// make sure the path works on windows servers
				$boarddir = addslashes($boarddir);

				// set the main error counter
				$error = 0;

				if (!in_array($db_prefix . 'art_sections', $existingTables))
				{
					// Set error value of 0 for this part.
					$error1 = 0;
	// Articles - upgrades shouldn't need anything, but if they don't exist, we'll add them
					// Let them know where we're at.
					echo '<p><b><i>Working with: ' . $db_prefix . 'art_sections ...</i></b></p>';

		// Install article sections
					$artsec1 = mysql_query("CREATE TABLE {$db_prefix}art_sections (
						ID_SECTION int(11) NOT NULL auto_increment,
						title text NOT NULL, banner text NOT NULL,
						memberGroups text NOT NULL,
						position int(11) NOT NULL default '0',
						PRIMARY KEY  (`ID_SECTION`))
						TYPE=MyISAM AUTO_INCREMENT=2");
	
					if (!$artsec1) { echo '
						<div class="er">Error creating "art_sections" table.</div>'; $error++; $error1++;}
					else { echo '
						<div class="ok">Creating "art_sections" table.... Success!</div>';}
	
					$artsec2 = mysql_query("INSERT INTO {$db_prefix}art_sections
						(ID_SECTION, title, banner, memberGroups, position)
						VALUES ('1', 'Enigma Articles', '', '0', '0')");
					if (!$artsec2) { echo '<div class="er">Error updating "art_sections" table.</div>'; $error++; $error1++;}
					else { echo '<div class="ok">Updating "art_sections" table.... Success!</div>';}
	
					if ($error1 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error1 > 0) {echo '<br /><div class="er">There were errors with this table, as noted above. Continuing on.</div>';}
				}
				if (!in_array($db_prefix . 'articles', $existingTables))
				{
					// Set error value of 0 for this part.
					$error2 = 0;
	
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'articles ...</i></b></p>';
	
		// Install articles
					$art1 = mysql_query("CREATE TABLE {$db_prefix}articles (
					  ID_ARTICLE int(11) NOT NULL auto_increment,
					  ID_SECTION int(11) NOT NULL default '0',
					  stage tinyint(2) NOT NULL default '0',
					  heading text NOT NULL,
					  sub_heading text,
					  summary text NOT NULL,
					  story text NOT NULL,
					  ID_POSTER int(11) NOT NULL default '-1',
					  byline tinytext,
					  posterEmail tinytext,
					  ID_REVIEWER int(11) NOT NULL default '0',
					  dateEntered bigint(20) NOT NULL default '0',
					  dateModified bigint(20) default NULL,
					  yabbce tinyint(2) NOT NULL default '0',
					  publish tinyint(2) NOT NULL default '0',
					  featureFlag tinyint(2) NOT NULL default '0',
					  reviewFlag tinyint(2) NOT NULL default '0',
					  comment text,
					  PRIMARY KEY  (`ID_ARTICLE`)
					) TYPE=MyISAM AUTO_INCREMENT=1");
			
					if (!$art1) { echo '<div class="er">Error creating "articles" table.</div>'; $error++; $error2++;}
					else { echo '<div class="ok">Creating "articles" table.... Success!</div>';}
			
					$art2 = mysql_query("INSERT INTO {$db_prefix}articles
						(ID_ARTICLE, ID_SECTION, stage, heading, sub_heading,
						summary, story, ID_POSTER, byline, posterEmail, ID_REVIEWER,
						dateEntered, dateModified, yabbce, publish, featureFlag, reviewFlag, comment)
					VALUES (
						1, 1, 0, 'Lunabyte Systems Software', 'LSP - Enigma 2',
						'The wait has been long, but well worth it. Finally, Enigma 2 is here!',
						'The LSP Development Team would like to thank you for choosing to evaluate and use this product. There are several new features, and feature improvements that take the original Enigma to the next level.<br /><br />Don&#039;t forget to visit us at http://www.lunabyte.net for updates and information!<br /><br />',
						2, 'Luke', 'hide@address.com', 0, 1133123907,
						NULL, 0, 1, 1, 0, NULL);");

					if (!$art2) { echo '<div class="er">Error updating "articles" table.</div>'; $error++; $error2++;}
					else { echo '<div class="ok">Updating "articles" table.... Success!</div>';}
			
					if ($error2 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error2 > 0) {echo '<br /><div class="er">There were errors with this table, as noted above. Continuing on.</div>';}

				}
				// Set error value of 0 for this part.
				$error3 = 0; 
				
	// Blocks table
				// Let them know where we're at.
				echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'blocks ...</i></b></p>';

		// if blocks table already exists, then we're updating it
				if (in_array($db_prefix . 'blocks', $existingTables))
				{

			// We're going to have to make changes to the data, to
			// remove "center" from topcenter and bottomcenter blocks that Enigma 1.x used to use

			// topcenter conversion
					$blktp = mysql_query("UPDATE {$db_prefix}blocks SET side='top' WHERE side='topcenter'");
			// bottomcenter conversion
					$blkbtm = mysql_query("UPDATE {$db_prefix}blocks SET side='bottom' WHERE side='bottomcenter'");

					$block1 = mysql_query("ALTER TABLE `{$db_prefix}blocks` CHANGE `border` `border` SMALLINT( 11 ) DEFAULT '0' NOT NULL");
					if (!$block1) { echo '<div class="er">Error updating "blocks" table, step 1.</div>'; $error++; $error3++;}
					else { echo '<div class="ok">Updating "blocks" table, step 1... Success!</div>';}

					$block2 = mysql_query("ALTER TABLE `{$db_prefix}blocks` CHANGE `name` `name` MEDIUMTEXT NOT NULL");
					if (!$block2) { echo '<div class="er">Error updating "blocks" table, step 2.</div>'; $error++; $error3++;}
					else { echo '<div class="ok">Updating "blocks" table, step 2... Success!</div>';}

					$block3 = mysql_query("ALTER TABLE `{$db_prefix}blocks` CHANGE `allowance` `allowance` MEDIUMTEXT NOT NULL");
					if (!$block3) { echo '<div class="er">Error updating "blocks" table, step 3.</div>'; $error++; $error3++;}
					else { echo '<div class="ok">Updating "blocks" table, step 3... Success!</div>';}

					$block4 = mysql_query("ALTER TABLE `{$db_prefix}blocks` ADD `active` enum('0','1') NOT NULL default '1'");
					if (!$block4) { echo '<div class="er">Error updating "blocks" table, step 4.</div>'; $error++; $error3++;}
					else { echo '<div class="ok">Updating "blocks" table, step 4... Success!</div>';}

					$block5 = mysql_query("ALTER TABLE `{$db_prefix}blocks` ADD `templateName` tinytext NOT NULL default ''");
					if (!$block5) { echo '<div class="er">Error updating "blocks" table, step 5.</div>'; $error++; $error3++;}
					else { echo '<div class="ok">Updating "blocks" table, step 5... Success!</div>';}

			// Turning off Enigma 1.x blocks, default, no option!
					$boff = mysql_query("UPDATE {$db_prefix}blocks SET active='0'");

					if (!$boff) { echo '<div class="er">Error Setting Enigma 1.x blocks to off.</div>'; $error++; $error3++;}
					else { echo '<div class="ok">Enigma 1.x blocks set to off.... Success!</div>';}

				}
				else
				{
		// must be a new install, Install blocks table
					$block1 = mysql_query("CREATE TABLE {$db_prefix}blocks (
			  		id int(11) NOT NULL auto_increment,
					border smallint(11) NOT NULL default '0',
					name mediumtext NOT NULL,
					contents text NOT NULL,
					active enum('0','1') NOT NULL default '1',
					side tinytext NOT NULL,
					phpe enum('0','1') NOT NULL default '0',
					type mediumtext NOT NULL,
					visible text,
					allowance mediumtext NOT NULL,
					templateName tinytext NOT NULL,
					PRIMARY KEY  (id),
					KEY id (id))
					TYPE=MyISAM AUTO_INCREMENT=1");

					if (!$block1) { echo '<div class="er">Error creating "blocks" table.</div>'; $error++; $error3++;}
					else { echo '<div class="ok">Creating "blocks" table.... Success!</div>';}
				}
				
		// Is this a new install or was the install default E2 blocks & menus option checked?
				if ($inste2_block == '1' || $_REQUEST['option'] == 'install')
				{
		// Adding E2 blocks...

					$blockadd = mysql_query("INSERT INTO {$db_prefix}blocks
					(border, name, contents, active, side, phpe, type, visible, allowance, templateName)
					VALUES
					(-1, 'Enigma Menu', '	echo \'<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\',\nMenu(\'Enigma\'), \'\n			</table>\';', '1', 'left', '1', 'custom', 'all', '0', ''),
					(1, 'Daily Insult', '', '0', 'center', '1', 'MedievalInsults', 'all', '-2', ''),
					(1, 'Quick Stats', '', '0', 'right', '1', 'sitestats', 'all', '0', ''),
					(4, 'Latest Karma Actions', '', '0', 'center', '0', 'karmaActions', 'all', '0', ''),
					(0, 'Some news...', 'echo \$context[\'random_news_line\'];', '1', 'top', '1', 'custom', 'all', '0', ''),
					(2, 'Quote!', '', '1', 'center', '0', 'rquote', 'all', '0', ''),
					(2, 'Admin Status', '', '1', 'left', '0', 'status', 'all', '-2', ''),
					(0, 'Login', '', '1', 'left', '0', 'blogin', 'all', '-1', ''),
					(5, 'Recent Posts', '', '1', 'right', '0', 'recentp', 'all', '0', ''),
					(6, 'Recent Topics', '', '1', 'right', '0', 'recentt', 'all', '0', ''),
					(4, 'Top 5 Posters', '', '0', 'left', '0', 'topPosters', 'all', '0', ''),
					(5, 'Search', '', '1', 'left', '1', 'quickSearch', 'all', '0', ''),
					(0, 'Whos Online', '', '1', 'right', '0', 'uonline', 'all', '0', ''),
					(0, 'Mini Calendar', '', '1', 'right', '1', 'minicalendar', 'all', '0', '')");

					if (!$blockadd) { echo '<div class="er">Error updating "blocks" table.</div>'; $error++; $error3++;}
					else { echo '<div class="ok">Updating "blocks" table.... Success!</div>';}
				}

				if ($error3 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
				elseif ($error3 > 0) {echo '<br /><div class="er">There were errors with this table, as noted above. Continuing on.</div>';}


				// Set error value of 0 for this part.
				$error4 = 0;
	// Downloads
				// Let them know where we're at.
				echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'download_cats ...</i></b></p>';
		// Download Categories
				if (in_array($db_prefix . 'download_cats', $existingTables))
				{
		// it already exists, so Update download_cats
					$dl1 = mysql_query("ALTER TABLE `{$db_prefix}download_cats` ADD `permission` varchar(255) NOT NULL default '0'");
					if (!$dl1) { echo '<div class="er">Error updating "download_cats" table, step 1.</div>'; $error++; $error4++;}
					else { echo '<div class="ok">Updating "download_cats" table, step 1... Success!</div>';}
				}
				else
				{
		// otherwise Install download categories
					$dl1 = mysql_query("CREATE TABLE {$db_prefix}download_cats (
					  id int(11) NOT NULL auto_increment,
					  name mediumtext NOT NULL,
					  description text NOT NULL,
					  isSub tinyint(11) NOT NULL default '0',
					  permission varchar(255) NOT NULL default '0',
					  PRIMARY KEY  (id)
					) TYPE=MyISAM AUTO_INCREMENT=1");
			
					if (!$dl1) { echo '<div class="er">Error creating "download_cats" table.</div>'; $error++; $error4++;}
					else { echo '<div class="ok">Creating "download_cats" table.... Success!</div>';}

				}

				if ($error4 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
				elseif ($error4 > 0) {echo '<br /><div class="er">There were errors with this table, as noted above. Continuing on.</div>';}

				// Set error value of 0 for this part.
				$error5 = 0;

				// Let them know where we're at.
				echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'download_items ...</i></b></p>';
		// Download Items
				if (in_array($db_prefix . 'download_items', $existingTables))
				{
		// it already exists, so Update download_items

					$di1 = mysql_query("ALTER TABLE `{$db_prefix}download_items` CHANGE `name` `name` varchar(255) NOT NULL default ''");
					if (!$di1) { echo '<div class="er">Error updating "download_items" table, step 1.</div>'; $error++; $error5++;}
					else { echo '<div class="ok">Updating "download_items" table, step 1... Success!</div>';}

					$di2 = mysql_query("ALTER TABLE `{$db_prefix}download_items` CHANGE `author_name` `author_name` varchar(255) NOT NULL default ''");
					if (!$di2) { echo '<div class="er">Error updating "download_items" table, step 2.</div>'; $error++; $error5++;}
					else { echo '<div class="ok">Updating "download_items" table, step 2... Success!</div>';}

					$di3 = mysql_query("ALTER TABLE `{$db_prefix}download_items` CHANGE `author_email` `author_email` varchar(255) NOT NULL default ''");
					if (!$di3) { echo '<div class="er">Error updating "download_items" table, step 3.</div>'; $error++; $error5++;}
					else { echo '<div class="ok">Updating "download_items" table, step 3... Success!</div>';}

					$di4 = mysql_query("ALTER TABLE `{$db_prefix}download_items` CHANGE `website_title` `website_title` varchar(255) NOT NULL default ''");
					if (!$di4) { echo '<div class="er">Error updating "download_items" table, step 4.</div>'; $error++; $error5++;}
					else { echo '<div class="ok">Updating "download_items" table, step 4... Success!</div>';}

					$di5 = mysql_query("ALTER TABLE `{$db_prefix}download_items` ADD `views` int(11) NOT NULL default '0'");
					if (!$di5) { echo '<div class="er">Error updating "download_items" table, step 5.</div>'; $error++; $error5++;}
					else { echo '<div class="ok">Updating "download_items" table, step 5... Success!</div>';}

				}
				else
				{
		// otherwise Install download items
					$dl2 = mysql_query("CREATE TABLE {$db_prefix}download_items (
					  id int(11) NOT NULL auto_increment,
					  cat tinyint(11) NOT NULL default '0',
					  name varchar(255) NOT NULL default '',
					  ddesc text NOT NULL,
					  filename text NOT NULL,
					  author_name varchar(255) NOT NULL default '',
					  author_email varchar(255) NOT NULL default '',
					  filesize int(255) NOT NULL default '0',
					  downloads int(255) NOT NULL default '0',
					  website text NOT NULL,
					  website_title varchar(255) NOT NULL default '',
					  date bigint(20) NOT NULL default '0',
					  views int(11) NOT NULL default '0',
					  PRIMARY KEY  (id)
					) TYPE=MyISAM AUTO_INCREMENT=1");
	
					if (!$dl2) { echo '<div class="er">Error creating "download_items" table.</div>'; $error++; $error5++;}
					else { echo '<div class="ok">Creating "download_items" table.... Success!</div>';}
				}

				if ($error5 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
				elseif ($error5 > 0) {echo '<br /><div class="er">There were errors with this table, as noted above. Continuing on.</div>';}


				// Set error value of 0 for this part.
				$error6 = 0;

				// Let them know where we're at.
				echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'download_votes ...</i></b></p>';

		// Install download votes
				$dl3 = mysql_query("CREATE TABLE {$db_prefix}download_votes (
				  dl_id int(11) NOT NULL default '0',
				  member_id int(10) NOT NULL default '0',
				  vote tinyint(2) NOT NULL default '0'
				) TYPE=MyISAM");

				if (!$dl3) { echo '<div class="er">Error creating "download_votes" table.</div>'; $error++; $error6++;}
				else { echo '<div class="ok">Creating "download_votes" table.... Success!</div>';}

				if ($error6 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
				elseif ($error6 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}


	// FAQ - upgrades shouldn't need anything, but if they don't exist, we'll add them
				if (!in_array($db_prefix . 'faqanswer', $existingTables))
				{
					// Set error value of 0 for this part.
					$error7 = 0;

					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'faqanswer ...</i></b></p>';
	
		// Install FAQ Answers
					$faq1 = mysql_query("CREATE TABLE {$db_prefix}faqanswer (
					  id tinyint(4) NOT NULL auto_increment,
					  id_cat tinyint(4) default NULL,
					  question varchar(255) default NULL,
					  answer text,
					  PRIMARY KEY  (id),
					  KEY idxfaqansweridcat (id_cat),
					  KEY idxfaqanswerididcat (id,id_cat)
					) TYPE=MyISAM AUTO_INCREMENT=1");
	
					if (!$faq1) { echo '<div class="er">Error creating "faqanswer" table.</div>'; $error++; $error7++;}
					else { echo '<div class="ok">Creating "faqanswer" table.... Success!</div>';}
	
					if ($error7 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error7 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}
				}
				if (!in_array($db_prefix . 'faqcategories', $existingTables))
				{
					// Set error value of 0 for this part.
					$error8 = 0;
	
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'faqcategories ...</i></b></p>';
	
		// Install FAQ Categories
					$faq2 = mysql_query("CREATE TABLE {$db_prefix}faqcategories (
					  id_cat tinyint(3) NOT NULL auto_increment,
					  categories varchar(255) default NULL,
					  PRIMARY KEY  (id_cat)
					) TYPE=MyISAM AUTO_INCREMENT=1");
	
					if (!$faq2) { echo '<div class="er">Error creating "faqcategories" table.</div>'; $error++; $error8++;}
					else { echo '<div class="ok">Creating "faqcategories" table.... Success!</div>';}
	
					if ($error8 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error8 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}
	
				}

				// Set error value of 0 for this part.
				$error9 = 0;
	// Guestbook
				// Let them know where we're at.
				echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'guestbook ...</i></b></p>';

		// table exists, so Update guestbook
				if (in_array($db_prefix . 'guestbook', $existingTables))
				{
					$gb1 = mysql_query("ALTER TABLE `{$db_prefix}guestbook` ADD `response` int(5) default '0' NOT NULL");
					if (!$gb1) { echo '<div class="er">Error updating "guestbook" table, step 1.</div>'; $error++; $error9++;}
					else { echo '<div class="ok">Updating "guestbook" table, step 1... Success!</div>';}

					$gb2 = mysql_query("ALTER TABLE `{$db_prefix}guestbook` ADD `userid` mediumint(8) default '-1'");
					if (!$gb2) { echo '<div class="er">Error updating "guestbook" table, step 2.</div>'; $error++; $error9++;}
					else { echo '<div class="ok">Updating "guestbook" table, step 2... Success!</div>';}

					$gb3 = mysql_query("ALTER TABLE `{$db_prefix}guestbook` CHANGE `id` `id` int(11) NOT NULL AUTO_INCREMENT");
					if (!$gb2) { echo '<div class="er">Error updating "guestbook" table, step 3.</div>'; $error++; $error9++;}
					else { echo '<div class="ok">Updating "guestbook" table, step 3... Success!</div>';}
				}
				else
				{
		// otherwise, Install Guestbook
					$fgb = mysql_query("CREATE TABLE {$db_prefix}guestbook (
					  id int(11) NOT NULL auto_increment,
					  guestName tinytext,
					  emailaddress tinytext,
					  signtime bigint(20) default NULL,
					  body text,
					  response int(5) NOT NULL default '0',
					  userid mediumint(8) default '-1',
					  PRIMARY KEY  (id)
					) TYPE=MyISAM AUTO_INCREMENT=1");
	
					if (!$fgb) { echo '<div class="er">Error creating "guestbook" table.</div>'; $error++; $error9++;}
					else { echo '<div class="ok">Creating "guestbook" table.... Success!</div>';}
				}
				
				if ($error9 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
				elseif ($error9 > 0) {echo '<br /><div class="er">There were errors with this table, as noted above. Continuing on.</div>';}


	// Links - upgrades shouldn't need anything, but if they don't exist, we'll add them
				if (!in_array($db_prefix . 'links_cats', $existingTables))
				{
					// Set error value of 0 for this part.
					$error10 = 0;
	
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'links_cats ...</i></b></p>';

		// Install links_cats
					$lk1 = mysql_query("CREATE TABLE {$db_prefix}links_cats (
					  catID mediumint(9) NOT NULL auto_increment,
					  name tinytext NOT NULL,
					  description text NOT NULL,
					  PRIMARY KEY  (catID)
					) TYPE=MyISAM AUTO_INCREMENT=1");
	
					if (!$lk1) { echo '<div class="er">Error creating "links_cats" table.</div>'; $error++; $error10++;}
					else { echo '<div class="ok">Creating "links_cats" table.... Success!</div>';}
	
					if ($error10 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error10 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}
				}
				if (!in_array($db_prefix . 'links_items', $existingTables))
				{
					// Set error value of 0 for this part.
					$error11 = 0;
	
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'links_items ...</i></b></p>';
	
		// Install links_items
					$lk2 = mysql_query("CREATE TABLE {$db_prefix}links_items (
			 		linkID mediumint(9) unsigned NOT NULL auto_increment,
			 		catID mediumint(9) unsigned NOT NULL default '0',
			  		name tinytext NOT NULL,
			  		linkURL tinytext NOT NULL,
			  		description text NOT NULL,
			  		ID_SUBMITTER int(11) NOT NULL default '-1',
			  		ID_REVIEWER int(11) default NULL,
			  		dateEntered bigint(20) NOT NULL default '0',
			  		dateModified bigint(20) default NULL,
			  		submitterEmail tinytext NOT NULL,
			  		submittedBy tinytext NOT NULL,
			  		clicks mediumint(9) unsigned NOT NULL default '0',
			  		stage tinyint(2) NOT NULL default '0',
			  		reviewFlag tinyint(2) NOT NULL default '1',
			  		comment text,
			  		PRIMARY KEY  (linkID)
					) TYPE=MyISAM AUTO_INCREMENT=1");
	
					if (!$lk2) { echo '<div class="er">Error creating "links_items" table.</div>'; $error++; $error11++;}
					else { echo '<div class="ok">Creating "links_items" table.... Success!</div>';}
	
					if ($error11 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error11 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}
				}

	// News - upgrades shouldn't need it, but if it doesn't exist, install it
				if (!in_array($db_prefix . 'news', $existingTables))
				{
					// Set error value of 0 for this part.
					$error12 = 0;
	
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'news ...</i></b></p>';
	
		// Install news
					$nws = mysql_query("CREATE TABLE {$db_prefix}news (
			  		ID_NEWS int(11) NOT NULL auto_increment,
			  		ID_CATEGORY int(11) NOT NULL default '0',
			  		ID_TOPIC int(11) NOT NULL default '0',
			  		ID_POSTER int(11) NOT NULL default '0',
			  		ID_REVIEWER int(11) default NULL,
			  		reviewFlag tinyint(2) NOT NULL default '1',
			  		featureFlag tinyint(2) NOT NULL default '0',
			  		stage tinyint(4) NOT NULL default '0',
			  		publish tinyint(2) NOT NULL default '0',
			  		comment text,
			  		dateEntered bigint(20) default NULL,
			  		dateModified bigint(20) default NULL,
			  		PRIMARY KEY  (ID_NEWS),
			  		KEY ID_TOPIC (ID_TOPIC),
			  		KEY ID_POSTER (ID_POSTER),
			  		KEY ID_CATEGORY (ID_CATEGORY)
					) TYPE=MyISAM AUTO_INCREMENT=1");
	
					if (!$nws) { echo '<div class="er">Error creating "news" table.</div>'; $error++; $error12++;}
					else { echo '<div class="ok">Creating "news" table.... Success!</div>';}
	
					if ($error12 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error12 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}
				}
				if (!in_array($db_prefix . 'news_categories', $existingTables))
				{
					// Set error value of 0 for this part.
					$error13 = 0;
	
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'news_categories ...</i></b></p>';
	
		// Install news_categories
					$nws2 = mysql_query("CREATE TABLE {$db_prefix}news_categories (
			  		ID_CATEGORY tinyint(11) NOT NULL auto_increment,
			  		name text NOT NULL,
			  		image text NOT NULL,
			  		sub tinyint(4) NOT NULL default '-1',
			  		PRIMARY KEY  (ID_CATEGORY)
					) TYPE=MyISAM AUTO_INCREMENT=1");
	
					if (!$nws2) { echo '<div class="er">Error creating "news_categories" table.</div>'; $error++; $error13++;}
					else { echo '<div class="ok">Creating "news_categories" table.... Success!</div>';}
	
					$nws3 = mysql_query("INSERT INTO {$db_prefix}news_categories VALUES (1, 'Enigma', 'news.gif', -1)");
	
					if (!$nws3) { echo '<div class="er">Error updating "news_categories" table.</div>'; $error++; $error13++;}
					else { echo '<div class="ok">Updating "news_categories" table.... Success!</div>';}
	
					if ($error13 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error13 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}
					elseif ($error13 >1) {echo '<br /><div class="er">There were ' . $error13 . ' errors with this table, as noted above. Continuing on.</div>';}
				}

	// Admin Status Block
		// Check to see if the astatus column exists in the members table
				$request = mysql_query("
					SHOW COLUMNS
					FROM {$db_prefix}members
					LIKE 'astatus'");

				if (mysql_num_rows($request) != '1')
				{
					// Set error value of 0 for this part.
					$error14 = 0;
	
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'members ...</i></b></p>';
	
			// Install the column
					$stat = mysql_query("ALTER TABLE {$db_prefix}members
			  		ADD astatus tinytext;");
	
					if (!$stat) { echo '<div class="er">Error updating "members" table.</div>'; $error++; $error14++;}
					else { echo '<div class="ok">Updating "members" table.... Success!</div>';}
	
					if ($error14 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error14 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}
				}
				else
					mysql_free_result($request);

	// Menus
		// Menu Groups
			// upgrades shouldn't need a menugrps table, but if it doesn't exist, we'll create it
				if (!in_array($db_prefix . 'menugrps', $existingTables))
				{
					// Set error value of 0 for this part.
					$error15 = 0;

					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'menugrps ...</i></b></p>';

			// Create menugrps
					$mg1= mysql_query("CREATE TABLE {$db_prefix}menugrps (
			  		grpID smallint(11) NOT NULL auto_increment,
			  		menutype tinyint(1) NOT NULL default '0',
			  		itemsep text NOT NULL,
			  		tagname text NOT NULL,
			  		css text NOT NULL,
			  		UNIQUE KEY grpID (grpID),
			  		FULLTEXT KEY itemsep (itemsep,tagname)
					) TYPE=MyISAM AUTO_INCREMENT=1");

					if (!$mg1) { echo '<div class="er">Error creating "menugrps" table.</div>'; $error++; $error15++;}
					else { echo '<div class="ok">Creating "menugrps" table.... Success!</div>';}

					if ($error15 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error15 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}

				}

		// Menu Items table
				// Set error value of 0 for this part.
				$error16 = 0;

				// Let them know where we're at.
				echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'menu ...</i></b></p>';

				if (in_array($db_prefix . 'menu', $existingTables))
				{
		// menu table exists, Update menu

					$mn1 = mysql_query("ALTER TABLE `{$db_prefix}menu` CHANGE `grpID` `grpID` smallint(11) NOT NULL default '1'");
					if (!$mn1) { echo '<div class="er">Error updating "menu" table, step 1.</div>'; $error++; $error16++;}
					else { echo '<div class="ok">Updating "menu" table, step 1... Success!</div>';}

					$mn2 = mysql_query("ALTER TABLE `{$db_prefix}menu` CHANGE `position` `position` smallint(11) NOT NULL default '0'");
					if (!$mn2) { echo '<div class="er">Error updating "menu" table, step 2.</div>'; $error++; $error16++;}
					else { echo '<div class="ok">Updating "menu" table, step 2... Success!</div>';}
				}
				else
				{
		// otherwise, Install menu table
					$m1= mysql_query("CREATE TABLE {$db_prefix}menu (
			  		id int(11) NOT NULL auto_increment,
			  		grpID smallint(11) NOT NULL default '1',
			  		memberGroup text NOT NULL,
			  		img text NOT NULL,
			  		alt text NOT NULL,
			  		position smallint(11) NOT NULL default '0',
			  		url text NOT NULL,
			 		 imgfolder text NOT NULL,
			  		imgborder tinyint(11) NOT NULL default '0',
			  		imgwidth tinytext NOT NULL,
			  		imgheight tinytext NOT NULL,
			  		imgloc tinyint(1) NOT NULL default '0',
			  		urltarget text NOT NULL,
			  		special text NOT NULL,
			  		PRIMARY KEY  (id),
			  		KEY id (id)
					) TYPE=MyISAM AUTO_INCREMENT=1");
	
					if (!$m1) { echo '<div class="er">Error creating "menu" table.</div>'; $error++; $error16++;}
					else { echo '<div class="ok">Creating "menu" table.... Success!</div>';}
				}

		// if this is a new install or the option was selected to install E2 default menus and blocks
		// Install Enigma 2 Menus & Groups
				if ($inste2_block == '1' || $_REQUEST['option'] == 'install')
				{
					$get_theme = mysql_query("SELECT MAX(ID_THEME) FROM {$db_prefix}themes");
					list ($thID) = mysql_fetch_row($get_theme);
					mysql_free_result($get_theme);
					$thID++;
					$mnge = mysql_query("SELECT MAX(grpID) FROM {$db_prefix}menugrps");
					list ($lmng) = mysql_fetch_row($mnge);
					if ($lmng > 0)
						mysql_free_result($mnge);
					else
						$lmng = 0;
					$lastg1 = $lmng + 1;
					$lastg2 = $lmng + 2;
			
		// Adding E2 Menu Groups
					$mng = mysql_query("INSERT INTO {$db_prefix}menugrps 
					(grpID, menutype, itemsep, tagname, css)
					VALUES
					('{$lastg1}', 0, '&nbsp;', 'default', 'nav'),
					('{$lastg2}', 3, '', 'Enigma', '')");
			
					if (!$mng) { echo '<div class="er">Error Adding Menu Groups to E2 "menugrps" table.</div>'; $error++; $error16++;}
					else { echo '<div class="ok">Adding Menu Groups to E2 "menugrps" table.... Success!</div>';}

		// Adding E2 Menus...
					$m3 = mysql_query("INSERT INTO {$db_prefix}menu
					(grpID, memberGroup, img, alt, position, url, imgfolder, imgborder, imgwidth, imgheight, imgloc, urltarget, special)
			 		VALUES
					('{$lastg1}', '0', 'home.gif', 'home', 0, 'index.php', '', 0, '', '', 0, '', ''),
					('{$lastg1}', '0', 'forum.gif', 'forums', 1, 'index.php?action=forum', '', 0, '', '', 0, '', ''),
					('{$lastg1}', '0', 'downloads.gif', 'downloads', 2, 'index.php?module=Downloads', '', 0, '', '', 0, '', ''),
					('{$lastg1}', '0', 'search.gif', 'search', 2, 'index.php?action=search', '', 0, '', '', 0, '', ''),
					('{$lastg1}', '1', 'admin.gif', 'admin', 5, 'index.php?action=admin', '', 0, '', '', 0, '', ''),
					('{$lastg1}', '-2', 'profile.gif', 'profile', 8, 'index.php?action=profile', '', 0, '', '', 0, '', ''),
					('{$lastg1}', '-1', 'login.gif', 'login', 10, 'index.php?action=login', '', 0, '', '', 0, '', ''),
					('{$lastg1}', '-1', 'register.gif', 'register', 11, 'index.php?action=register', '', 0, '', '', 0, '', ''),
					('{$lastg1}', '-2', 'logout.gif', 'logout', 10, '', '', 0, '', '', 0, '', 'logout'),
					('{$lastg1}', '0', 'help.gif', 'Help', 3, 'index.php?action=help', '', 0, '', '', 0, '_blank', ''),
					('{$lastg1}', '-1', 'pages.gif', 'Pages', 4, 'index.php?action=PageListing', '', 0, '', '', 0, '', ''),
					('{$lastg1}', '-2', 'calendar.gif', 'Calendar', 9, 'index.php?action=calendar', '', 0, '', '', 0, '', ''),
					('{$lastg1}', '-1', 'guestbook.gif', 'GuestBook', 12, 'index.php?module=Guestbook', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'Home', 0, 'index.php', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'Forums', 1, 'index.php?action=forum', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'Downloads', 2, 'index.php?module=Downloads', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'FAQ', 3, 'index.php?module=Faq', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'Guestbook', 6, 'index.php?module=Guestbook', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'Submissions', 8, 'index.php?op=submissions', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'Calendar', 1, 'index.php?action=calendar', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'Links', 7, 'index.php?module=Links', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'Pages', 10, 'index.php?op=PageListing', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'News', 11, 'index.php?op=News', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '1', '', '<br />', 15, '', '', 0, '', '', 0, '', 'custsep'),
					('{$lastg2}', '1', '', 'Admin', 16, 'index.php?action=admin', '', 0, '', '', 0, '', ''),
					('{$lastg2}', '0', '', 'Articles', 9, 'index.php?op=Articles', '', 0, '', '', 0, '', '')");

					if (!$m3) { echo '<div class="er">Error adding to "menu" table.</div>'; $error++; $error16++;}
					else { echo '<div class="ok">Adding to "menu" table.... Success!</div>';}

				}
				if ($error16 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
				elseif ($error16 > 0) {echo '<br /><div class="er">There were errors with this table, as noted above. Continuing on.</div>';}


	// Page Folders - upgrades shoudn't need it, but we'll check anyway
				if (!in_array($db_prefix . 'page_folders', $existingTables))
				{
					// Set error value of 0 for this part.
					$error17 = 0;
	
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'page_folders ...</i></b></p>';
	
		// Install page_folders
					$pg1 = mysql_query("CREATE TABLE {$db_prefix}page_folders (
			  		id int(11) NOT NULL auto_increment,
			  		name text NOT NULL,
			  		isSub tinyint(11) NOT NULL default '0',
			  		PRIMARY KEY  (id)
					) TYPE=MyISAM AUTO_INCREMENT=1");
	
					if (!$pg1) { echo '<div class="er">Error creating "page_folders" table.</div>'; $error++; $error17++;}
					else { echo '<div class="ok">Creating "page_folders" table.... Success!</div>';}
	
					if ($error17 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error17 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}
				}

				// Set error value of 0 for this part.
				$error18 = 0; 
	// Pages table
				// Let them know where we're at.
				echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'pages ...</i></b></p>';
		// it exists, so we have to update it
				if (in_array($db_prefix . 'pages', $existingTables))
				{
					$pg1 = mysql_query("ALTER TABLE `{$db_prefix}pages` CHANGE `phpe` `phpe` tinyint(2) default '0' NOT NULL");
					if (!$pg1) { echo '<div class="er">Error updating "pages" table, step 1.</div>'; $error++; $error18++;}
					else { echo '<div class="ok">Updating "pages" table, step 1... Success!</div>';}

					$pg2 = mysql_query("ALTER TABLE `{$db_prefix}pages` ADD `views` INT( 11 ) DEFAULT '0' NOT NULL");
					if (!$pg2) { echo '<div class="er">Error updating "pages" table, step 2.</div>'; $error++; $error18++;}
					else { echo '<div class="ok">Updating "pages" table, step 2... Success!</div>';}

					$pg3 = mysql_query("ALTER TABLE `{$db_prefix}pages` ADD `block_override` tinyint(1) NOT NULL default 0");
					if (!$pg3) { echo '<div class="er">Error updating "pages" table, step 3.</div>'; $error++; $error18++;}
					else { echo '<div class="ok">Updating "pages" table, step 3... Success!</div>';}

					$pg4 = mysql_query("ALTER TABLE `{$db_prefix}pages` ADD list ENUM('0','1') NOT NULL DEFAULT '1'");
					if (!$pg4) { echo '<div class="er">Error updating "pages" table, step 4.</div>'; $error++; $error18++;}
					else { echo '<div class="ok">Updating "pages" table, step 4... Success!</div>';}
				}
		// doesn't exist, create it
				else
				{
					// Install page
					$pg2 = mysql_query("CREATE TABLE {$db_prefix}pages (
			  		id int(11) NOT NULL auto_increment,
			  		title mediumtext NOT NULL,
			  		stitle mediumtext NOT NULL,
			  		contents text NOT NULL,
			  		phpe tinyint(2) NOT NULL default '0',
			  		memberGroup text NOT NULL,
			  		folder tinyint(11) NOT NULL default '0',
			  		yabbce tinyint(4) NOT NULL default '0',
			  		views int(11) NOT NULL default '0',
					list ENUM('0','1') NOT NULL DEFAULT '1',
			  		block_override tinyint(1) NOT NULL default '0',
			  		PRIMARY KEY  (id),
			  		KEY id (id)
					) TYPE=MyISAM AUTO_INCREMENT=1");
			
					if (!$pg2) { echo '<div class="er">Error creating "pages" table.</div>'; $error++; $error18++;}
					else { echo '<div class="ok">Creating "pages" table.... Success!</div>';}
				}

				if ($error18 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
				elseif ($error18 > 0) {echo '<br /><div class="er">There were errors with this table, as noted above. Continuing on.</div>';}
		
	// Random Quotes for Block
		// upgrades shouldn't need it, but w'll check
				if (!in_array($db_prefix . 'rand_quotes', $existingTables))
				{
					// Set error value of 0 for this part.
					$error19 = 0; 
					
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'rand_quotes ...</i></b></p>';
					
			// Install rand_quotes
					$rq1= mysql_query("CREATE TABLE {$db_prefix}rand_quotes (
			  		id tinyint(4) NOT NULL auto_increment,
			  		quote text NOT NULL,
			  		author text NOT NULL,
			  		PRIMARY KEY  (id)
					) TYPE=MyISAM AUTO_INCREMENT=51");
			
					if (!$rq1) { echo '<div class="er">Error creating "rand_quotes" table.</div>'; $error++; $error19++;}
					else { echo '<div class="ok">Creating "rand_quotes" table.... Success!</div>';}
				
					$rq2 = mysql_query("INSERT INTO {$db_prefix}rand_quotes
					(id, quote, author)
			 		VALUES (1, 'No matter where you go, there you are.', 'Buckaroo Bonzai'),
					(2, 'I saw a werewolf with a Chinese menu in his hand, his hair was perfect.', 'Warren Zevon'),
					(3, '\'An it harm none, do as ye will.', 'Wiccan Rede'),
					(4, 'Ever mind the rule of three,\nThree times your deeds return to thee. \nThis lesson well, thou must learn, \nthee only gets what thou does earn.', 'Lady Gwen'),
					(5, 'Never discourage anyone...who continually makes progress, no matter how slow.', 'Plato'),
					(6, 'Every man is guilty of all the good he didn\'t do.', 'Voltaire'),
					(7, 'I may disagree with what you have to say, but I shall defend to the death your right to say it.', 'Voltaire'),
					(8, 'There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.<br />There is another theory which states that this has already happened.', 'Douglas Adams'),
					(9, 'There are three kinds of lies: lies, damned lies, and statistics.', 'Benjamin Disraeli'),
					(10, 'It is common sense to take a method and try it. If it fails, admit it frankly and try another. But above all, try something.', 'Franklin D. Roosevelt'),
					(11, 'Only two things are infinite, the universe and human stupidity, and I\'m not sure about the former.', 'Albert Einstein'),
					(12, 'We make war that we may live in peace.', 'Aristotle'),
					(13, 'Reality is merely an illusion, albeit a very persistent one.', 'Albert Einstein'),
					(14, 'Reality is that which, when you stop believing in it, doesn\'t go away', 'Philip K. Dick'),
					(15, 'Any sufficiently advanced technology is indistinguishable from magic.', 'Arthur C. Clarke'),
					(16, 'The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts.', 'Bertrand Russell'),
					(17, 'Those who cannot remember the past are condemned to repeat it.', 'George Santayana'),
					(18, 'No act of kindness, no matter how small, is ever wasted.', 'Aesop, The Lion and the Mouse'),
					(19, 'The past is a source of knowledge, and the future is a source of hope. Love of the past implies faith in the future.', 'Stephen Ambrose, in Fast Company'),
					(20, 'One, a robot may not injure a human being, or through inaction, allow a human being to come to harm;\nTwo, a robot must obey the orders given it by human beings except where such orders would conflict with the First Law; Three, a robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.', 'Isaac Asimov, Laws of Robotics from I. Robot, 1950'),
					(21, 'Violence is the last refuge of the incompetent.', 'Isaac Asimov, Salvor Hardin in \"Foundation\"'),
					(22, 'All that is necessary for the triumph of evil is that good men do nothing.', 'Edmund Burke'),
					(23, 'Hope, It is the quintessential Human delusion, Simultaneously the source for your greatest strength and your greatest weakness!', 'The Architect'),
					(24, 'Nothing is as easy as it looks.', 'Murphy\'s Law'),
					(25, 'Everything takes longer than you think.', 'Murphy\'s Law'),
					(26, 'Anything that can go wrong will go wrong.', 'Murphy\'s Law'),
					(27, 'If there is a possibility of several things going wrong, the one that will cause the most damage will be the one to go wrong.', 'Murphy\'s Law'),
					(28, 'If there is a worse time for something to go wrong, it will happen then.', 'Murphy\'s Law'),
					(29, 'If anything simply cannot go wrong, it will anyway.', 'Murphy\'s Law'),
					(30, 'If you perceive that there are four possible ways in which a procedure can go wrong, and circumvent these, then a fifth way, unprepared for, will promptly develop.', 'Murphy\'s Law'),
					(31, 'Left to themselves, things tend to go from bad to worse.', 'Murphy\'s Law'),
					(32, 'If everything seems to be going well, you have obviously overlooked something.', 'Murphy\'s Law'),
					(33, 'Nature always sides with the hidden flaw.', 'Murphy\'s Law'),
					(34, 'It is impossible to make anything foolproof because fools are so ingenious.', 'Murphy\'s Law'),
					(35, 'Whenever you set out to do something, something else must be done first.', 'Murphy\'s Law'),
					(36, 'Every solution breeds new problems.', 'Murphy\'s Law'),
					(37, 'Trust everybody ... then cut the cards.', 'Murphy\'s Law'),
					(38, 'Two wrongs are only the beginning.', 'Murphy\'s Law'),
					(39, 'If at first you don\'t succeed, destroy all evidence that you tried.', 'Murphy\'s Law'),
					(40, 'To succeed in politics, it is often necessary to rise above your principles.', 'Murphy\'s Law'),
					(41, 'Exceptions prove the rule ... and wreck the budget.', 'Murphy\'s Law'),
					(42, 'Success always occurs in private, and failure in full view.', 'Murphy\'s Law')");
			
					if (!$rq2) { echo '<div class="er">Error updating "rand_quotes" table.</div>'; $error++; $error19++;}
					else { echo '<div class="ok">Updating "rand_quotes" table.... Success!</div>';}
			
					if ($error19 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error19 > 0) {echo '<br /><div class="er">There were errors with this table, as noted above. Continuing on.</div>';}
				}

	// Themes, this is a fun one! ;-)
				// Set error value of 0 for this part.
				$error19 = 0;

		// What themes are installed? We need to know!
				$get_theme = mysql_query("SELECT MAX(ID_THEME) FROM {$db_prefix}themes");
				list ($thID) = mysql_fetch_row($get_theme);
				mysql_free_result($get_theme);
				$thID++;
				$thCE = $thID + 1;

		// Update existing default theme
				echo '<hr /><p><b><i>Updating: ' . $db_prefix . 'themes ...</i></b></p>';
				
				$th1 = mysql_query("UPDATE {$db_prefix}themes SET ID_THEME={$thID} WHERE ID_THEME=1");
				if (!$th1) { echo '<div class="er">Error updating "themes" table, step 1.</div>'; $error++; $error19++;}
				else { echo '<div class="ok">Updating "themes" table, step 1... Success!</div>';}

				$th2 = mysql_query("UPDATE {$db_prefix}themes SET value='{$boardurl}/Themes/SMF_default' WHERE ID_THEME={$thID} AND variable='theme_url'");
				if (!$th2) { echo '<div class="er">Error updating "themes" table, step 2.</div>'; $error++; $error19++;}
				else { echo '<div class="ok">Updating "themes" table, step 2... Success!</div>';}

				$th3 = mysql_query("UPDATE {$db_prefix}themes SET value='{$boardurl}/Themes/SMF_default/images' WHERE ID_THEME={$thID} AND variable='images_url'");
				if (!$th3) { echo '<div class="er">Error updating "themes" table, step 3.</div>'; $error++; $error19++;}
				else { echo '<div class="ok">Updating "themes" table, step 3... Success!</div>';}

				$th4 = mysql_query("UPDATE {$db_prefix}themes SET value='{$boarddir}/Themes/SMF_default' WHERE ID_THEME={$thID} AND variable='theme_dir'");
				if (!$th4) { echo '<div class="er">Error updating "themes" table, step 4.</div>'; $error++; $error19++;}
				else { echo '<div class="ok">Updating "themes" table, step 4... Success!</div>';}
		
		// Add the Enigma theme as the new default
				$th5 = mysql_query("INSERT INTO {$db_prefix}themes
						(ID_MEMBER, ID_THEME, variable, value)
				 		VALUES (0, 1, 'name', 'Enigma Default Theme'),
							  (0, 1, 'theme_url', '{$boardurl}/Themes/default'),
							  (0, 1, 'images_url', '{$boardurl}/Themes/default/images'),
							  (0, 1, 'theme_dir', '{$boarddir}/Themes/default'),
							  (0, 1, 'show_bbc', '1'),
							  (0, 1, 'show_latest_member', '1'),
							  (0, 1, 'show_modify', '1'),
							  (0, 1, 'show_user_images', '1'),
							  (0, 1, 'show_blurb', '1'),
							  (0, 1, 'show_gender', '0'),
							  (0, 1, 'show_newsfader', '0'),
							  (0, 1, 'number_recent_posts', '0'),
							  (0, 1, 'show_member_bar', '1'),
							  (0, 1, 'linktree_link', '1'),
							  (0, 1, 'show_profile_buttons', '1'),
							  (0, 1, 'show_mark_read', '1'),
							  (0, 1, 'show_sp1_info', '1'),
							  (0, 1, 'linktree_inline', '0'),
							  (0, 1, 'show_board_desc', '1'),
							  (0, 1, 'newsfader_time', '5000'),
							  (0, 1, 'allow_no_censored', '0'),
							  (0, 1, 'additional_options_collapsable', '1'),
							  (0, 1, 'use_image_buttons', '1'),
							  (0, 1, 'enable_news', '1'),
							  (0, $thCE, 'name', 'Classic Enigma Theme'),
							  (0, $thCE, 'theme_dir', '{$boardurl}/Themes/classic_e1/'),
							  (0, $thCE, 'images_url', '{$boardurl}/Themes/classic_e1/images'),
							  (0, $thCE, 'theme_url', '{$boardurl}/Themes/classic_e1')");

				if (!$th5) { echo '<div class="er">Error updating "themes" table, step 5.</div>'; $error++; $error19++;}
				else { echo '<div class="ok">Updating "themes" table, step 5... Success!</div>';}

				if ($error19 == 0) {echo '<br /><div class="ok">No errors in this section! Continuing on.</div>';}
				elseif ($error19 > 0) {echo '<br /><div class="er">There were errors updating this table, as noted above. Continuing on.</div>';}


		// Update default theme settings
				// Set error value of 0 for this part.
				$error19a = 0;

				echo '<hr /><p><b><i>Updating: default theme settings ...</i></b></p>';
		
			// Get the list of known themes
				$known_themes = mysql_query("SELECT value FROM `{$db_prefix}settings` WHERE `variable` = 'knownThemes' LIMIT 1 ");
				$kt = mysql_fetch_assoc($known_themes);		

				$th_list = $kt['value'] . ',' . $thID . ',' . $thCE;
		
			// Update Settings table
				$ths1 = mysql_query("REPLACE INTO {$db_prefix}settings
					(variable, value)
			 		VALUES
					('theme_default', '1'),
					('knownThemes', '{$th_list}'),
					('theme_guests', '1'),
					('theme_allow', '1')");
				if (!$ths1) { echo '<div class="er">Error setting default theme.</div>'; $error++; $error19a++;}
				else { echo '<div class="ok">default theme Installed.... Success!</div>';}

				$ths2 = mysql_query("UPDATE {$db_prefix}members SET ID_THEME=1");
				if (!$ths2) { echo '<div class="er">Error updating member themes setting.</div>'; $error++; $error19a++;}
				else { echo '<div class="ok">Updating member themes setting... Success!</div>';}

				if ($error19a == 0) {echo '<br /><div class="ok">No errors in this section! Continuing on.</div>';}
				elseif ($error19a > 0) {echo '<br /><div class="er">There were errors updating this section, as noted above. Continuing on.</div>';}

	// Settings table - main settings for Enigma2
				// Set error value of 0 for this part.
				$error20 = 0;
		
				// Update settings
				echo '<hr /><p><b><i>Updating: ' . $db_prefix . 'settings ...</i></b></p>';

		// Load Prefs if this is an upgrade and they exist
				if (in_array($db_prefix . 'prefs', $existingTables))
				{
					$get_prefs = mysql_query("SELECT * FROM {$db_prefix}prefs");
					while ($prefsR = mysql_fetch_assoc($get_prefs))
					{
						if ($prefsR['variable'] == 'logo') { $logo = $prefsR['value']; }
						$prefs["$prefsR[variable]"] = $prefsR['value'];
					}
					mysql_free_result($get_prefs);
				}

				if (!empty($_POST['homepage_news']) && $_POST['homepage_news'] == 1) { $phm = 'usenews'; $pun = 1;}
				elseif (!empty($prefs['usepage']) && $prefs['usenews'] != 1) {$phm = $prefs['usepage']; $pun = 1;}
				else { $phm = 'usenews'; $pun = 1;}
		

		// Add Engima settings
				// we'll use REPLACE just in case one of these already exists (maybe the ShoutBox settings?
				$st1 = mysql_query("REPLACE INTO {$db_prefix}settings
					(variable, value)
		 		VALUES
					('enigma_installed', '1'),
					('max_gb_entries_per_page', '10'),
					('enablesitenews', '1'),
					('NewsTitle', '" . (!empty($prefs['title']) ? $prefs['title'] . 'News:' : 'Enigma News:') . "'),
					('portal_home_page', '{$phm}'),
					('news_defaultboard', 'Board_1'),
					('use_portal_home_page', '{$pun}'),
					('enableblocks', '1'),
					('maxlinksviewlinks', '10'),
					('maxlinksperpage', '5'),
					('maxnewsitems', '" . (!empty($prefs['newslimit']) ? $prefs['newslimit'] : '8') . "'),
					('enablesitemenus', '1'),
					('enablemodules', '1'),
					('enablefaq', '1'),
					('enableresourcei', '1'),
					('resourcedoubbc', '1'),
					('enabledls', '1'),
					('dlsdir', '" . (!empty($prefs['dldir']) ? $prefs['dldir'] : $boarddir . '/downloads') . "'),
					('dlsurl', '" . (!empty($prefs['dlurl']) ? $prefs['dlurl'] : $boardurl . '/downloads') . "'),
					('parse_query_string', '0'),
					('enablearticles', '1'),
					('featuredarticles', '" . (!empty($prefs['artslimit']) ? $prefs['artslimit'] : '5') . "'),
					('polls_display', '" . (!empty($prefs['showpolls']) ? $prefs['showpolls'] : '-2') . "'),
					('initime', '1134667706'),
					('pversion', '{$lpv}'),
					('pclass', '{$lpc}'),
					('phy', '{$lpy}'),
					('not_bot', 'false'),
					('shoutdir', '0'),
					('enablearchiveshout', '1'),
					('shoutlimit', '10'),
					('shoutmaxchr', '30'),
					('shoutsplitchr', '27'),
					('shoutsmileys', '1'),
					('enablescrollshout', '1'),
					('shoutscrollwidth', '130'),
					('shoutscrollheight', '200'),
					('shoutscrollspeed', '2'),
					('shoutscrolldir', 'up'),
					('shoutscrolldelay', '60'),
					('smfVersion', '$smf_version_setting')");

				if (!$st1) { echo '<div class="er">Error updating "settings" table.</div>'; $error++; $error20++;}
				else { echo '<div class="ok">Updating "settings" table... Success!</div>';}


				if ($error20 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
				elseif ($error20 > 0) {echo '<br /><div class="er">There was an error updating settings, as noted above. Continuing on.</div>';}
		
	// ShoutBox module table
				// Set error value of 0 for this part.
				$error21 = 0;
				
				// Let them know where we're at.
				echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'shoutbox ...</i></b></p>';
		
		// Was the ShoutBox installed previously
				if (in_array($db_prefix . 'shoutbox', $existingTables))
				{
			// Check to see if SMF shoutbox mod was installed
					$request = mysql_query("
						SHOW COLUMNS
						FROM {$db_prefix}shoutbox
						LIKE 'ID_SHOUT'");
					
					if (mysql_num_rows($request) > 0)
					{
			// SMF mod exists, update it
						mysql_free_result($request);

						$sbxupd = mysql_query("
							ALTER TABLE {$db_prefix}shoutbox
							CHANGE COLUMN `ID_SHOUT` `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
							CHANGE COLUMN `ID_MEMBER` `name` TEXT NOT NULL");
	
						if (!$sbxupd) { echo '<div class="er">Error converting SMF Shoutbox mod - "shoutbox" table to Enigma settings.</div>'; $error++; $error21++;}
						else { echo '<div class="ok">SMF Shoutbox mod - "shoutbox" table converted.... Success!</div>';}
					}
			// table is ok, nothing to do
					else
					{
						echo '<div class="ok">Shout Box table already exists and has the proper settings, nothing to do here.... Success!</div>';
					}
				}
				else
				{
		// doesn't exist, Install Shout Box
					$sbx = mysql_query("CREATE TABLE {$db_prefix}shoutbox (
					  id int(11) NOT NULL auto_increment,
					  name text NOT NULL,
					  displayname text NOT NULL,
					  message longtext NOT NULL,
					  email tinytext NOT NULL,
					  time text NOT NULL,
					  PRIMARY KEY  (id)
					) TYPE=MyISAM AUTO_INCREMENT=1");

					if (!$sbx) { echo '<div class="er">Error creating "shoutbox" table.</div>'; $error++; $error21++;}
					else { echo '<div class="ok">Creating "shoutbox" table.... Success!</div>';}
				}

				if ($error21 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
				elseif ($error21 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}

	// Bridges table
		// Does the table already exist?  If not, install it
				if (!in_array($db_prefix . 'bridges', $existingTables))
				{
					// Set error value of 0 for this part.
					$error22 = 0;
					
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'bridges ...</i></b></p>';
	
					$brt = mysql_query("CREATE TABLE {$db_prefix}bridges (
					  `bridgeName` tinytext NOT NULL,
					  `bridgeDirectory` text NOT NULL,
					  PRIMARY KEY  (`bridgeName`(30))
					) TYPE=MyISAM AUTO_INCREMENT=1");

					if (!$brt) { echo '<div class="er">Error creating "bridges" table.</div>'; $error++; $error22++;}
					else { echo '<div class="ok">Creating "bridges" table.... Success!</div>';}

					if ($error22 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error22 == 1) {echo '<br /><div class="er">There was 1 error with this table, as noted above. Continuing on.</div>';}
				}

	// current_versions table
		// Does the table already exist?  If not, install it
				if (!in_array($db_prefix . 'current_versions', $existingTables))
				{
					// Set error value of 0 for this part.
					$error23 = 0;
					
					// Let them know where we're at.
					echo '<hr /><p><b><i>Working with: ' . $db_prefix . 'current_versions ...</i></b></p>';
	
					$cv = mysql_query("CREATE TABLE {$db_prefix}current_versions (
					  `name` varchar(20) NOT NULL default '',
					  `version` varchar(10) NOT NULL default '0',
					  PRIMARY KEY  (`name`)
					) TYPE=MyISAM AUTO_INCREMENT=1");

					if (!$cv) { echo '<div class="er">Error creating "current_versions" table.</div>'; $error++; $error23++;}
					else { echo '<div class="ok">Creating "current_versions" table.... Success!</div>';}

					$cv2 = mysql_query("INSERT INTO {$db_prefix}current_versions
							(name, version)
						VALUES
							('Enigma', '2.0 (RC1)')");

					if (!$cv2) { echo '<div class="er">Error adding Enigma version to the "current_versions" table.</div>'; $error++; $error23++;}
					else { echo '<div class="ok">Adding Enigma version to the "current_versions" table.... Success!</div>';}

					if ($error23 == 0) {echo '<br /><div class="ok">No errors so far! Continuing on.</div>';}
					elseif ($error23 > 0) {echo '<br /><div class="er">There was errors with this table, as noted above. Continuing on.</div>';}
				}

			}
		}
}

if ($_POST['step'] == 2)
{
	if ($error == 0)
	{
			echo '<br /><br />
				<p>Database Installation Complete!</p>
				<p>Congratulations, you have successfully setup the database for Enigma 2.0.</p>
				<p><a href="' . $boardurl . '/index.php">View your new Enigma 2.0 Installation!</a></p>';
	}
	elseif ($error == 1)
	{
			echo '<br /><br />
				<div class="stp">STOP!!!</div>
				<p>There was 1 error encountered while setting up the database for your portal.<br />
				Please scroll up, find the error, and make note of what it is.<br />';
	}
	elseif ($error > 1)
	{
		echo '<br /><br />
				<div class="stp">STOP!!!</div>
				<p>There were ' . $error . ' errors encountered while setting up the database for your portal.<br />
				Please scroll up, find the errors, and make note of what and where they were.<br />';
	}
	
	if ($error > 0)
	{
		echo '
				Next, open the LSP_install.php file in a text editor and look for the line<br />
				that corresponds with the error step given. Then see if you can correct it<br />
				via PhpMyAdmin.<br /><br />
				It is highly recommended that you save a copy of this page for future reference. <br />
				You can do so by choosing "file", then "save as" from your browsers menu.<br />
				If you can not, or lack the capability to correct this error, then please <br />
				<a href="http://www.lunabyte.net/index.php?action=forum">check the forums</a> for more information<br />
				and post your problem if it has not been covered already.</p>
				<p>Once you have verified and fixed the error, <a href="' . $boardurl . '/index.php">View your new Enigma 2.0 Installation!</a></p>';
	}
	
	echo '
				<p>Please Note:  With the default theme directory changes made during this installation, your web browser will
				have most likely cached all the images used for the SMF theme.  When you click the link above to go to your site,
				you may get a mixed theme display.  Click the refresh button in your web browser to fix the display.  If by
				chance, that does not work, you may need to clear your browser cache.<br />
				Your users may have the same problem IF you were running SMF prior to installing Enigma2.  If a simple refresh
				does not fix the problem for them, please advise them to clear the cache in their web browser.</p>';
}

echo '</div>
	</body>
	</html>';
?>
Return current item: Enigma