Index: branches/2.8.x/CHANGELOG
===================================================================
--- branches/2.8.x/CHANGELOG	(revision 1422)
+++ branches/2.8.x/CHANGELOG	(revision 1423)
@@ -11,6 +11,8 @@
 ! = Update/Change
 
 ------------------------------------- 2.8.2 -------------------------------------
+30 Jan-2011 Build 1423 Werner v.d.Decken(DarkViper)
+! add FINGERPRINT_WITH_IP_OCTETS to table settings
 30 Jan-2011 Build 1422 Dietmar Woellbrink (Luisehahne)
 ! update SecureForm.php to work behind Proxies
 27 Jan-2011 Build 1421 Dietmar Woellbrink (Luisehahne)
Index: branches/2.8.x/wb/upgrade-script.php
===================================================================
--- branches/2.8.x/wb/upgrade-script.php	(revision 1422)
+++ branches/2.8.x/wb/upgrade-script.php	(revision 1423)
@@ -1,577 +1,588 @@
-<?php
-/**
- *
- * @category        backend
- * @package         installation
- * @author          WebsiteBaker Project
- * @copyright       2004-2009, Ryan Djurovich
- * @copyright       2009-2011, Website Baker Org. e.V.
- * @link			http://www.websitebaker2.org/
- * @license         http://www.gnu.org/licenses/gpl.html
- * @platform        WebsiteBaker 2.8.x
- * @requirements    PHP 5.2.2 and higher
- * @version         $Id$
- * @filesource		$HeadURL$
- * @lastmodified    $Date$
- *
- */
-
-@require_once('config.php');
-
-// this function checks the basic configurations of an existing WB intallation
-function status_msg($message, $class='check', $element='span') {
-	// returns a status message
-	echo '<'.$element .' class="' .$class .'">' .$message .'</' .$element.'>';
-}
-
-$version = '2.8.2';
-// database tables including in WB package
-$table_list = array (
-    'settings','groups','addons','pages','sections','search','users',
-    'mod_captcha_control','mod_code','mod_droplets','mod_form_fields',
-    'mod_form_settings','mod_form_submissions','mod_jsadmin','mod_menu_link',
-    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
-    'mod_output_filter','mod_wrapper','mod_wysiwyg'
-);
-
-// analyze/check database tables
-function mysqlCheckTables( $dbName )
-{
-    global $table_list;
-    $table_prefix = TABLE_PREFIX;
-    $sql = "SHOW TABLES FROM " . $dbName;
-    $result = @mysql_query( $sql );
-    $data = array();
-    $x = 0;
-
-    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
-    {
-        $tmp = str_replace($table_prefix, '', $row[0]);
-
-        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$table_list) )
-        {
-            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
-            $analyze = @mysql_query( $sql );
-            $rowFetch = @mysql_fetch_array( $analyze, MYSQL_ASSOC );
-            $data[$x]['Op'] = $rowFetch["Op"];
-            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
-            $msgColor = '<span class="error">';
-            $data[$x]['Table'] = $row[0];
-           // print  " ";
-            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
-            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
-           // print  "<br />";
-            $x++;
-        }
-    }
-
-
-
-
-    return $data;
-}
-
-
-// check existings tables for upgrade or install
-function check_wb_tables()
-{
-    global $database,$table_list;
-
- // if prefix inludes '_' or '%'
- $search_for = addcslashes ( TABLE_PREFIX, '%_' );
- $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
-
-        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
-        $all_tables = array();
-        if($get_result->numRows() > 0)
-        {
-            while ($data = $get_result->fetchRow())
-            {
-                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
-                if(in_array($tmp,$table_list))
-                {
-                    $all_tables[] = $tmp;
-                }
-            }
-        }
-     return $all_tables;
-}
-
-// check existing tables
-$all_tables = check_wb_tables();
-
-// only for array tests
-function show_array($array=array())
-{
-    print '<pre>';
-    print_r ($array);
-    print '</pre>';
-}
-
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<title>Upgrade script</title>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<style type="text/css">
-html { overflow: -moz-scrollbars-vertical; /* Force firefox to always show room for a vertical scrollbar */ }
-
-body {
-	margin:0;
-	padding:0;
-	border:0;
-	background: #EBF7FC;
-	color:#000;
-	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
-	font-size: small;
-	height:101%;
-}
-
-#container {
-	width:85%;
-	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
-	border:1px solid #000;
-	color:#000;
-	margin:2em auto;
-	padding:0 15px;
-	min-height: 500px;
-	text-align:left;
-}
-
-p { line-height:1.5em; }
-
-h1,h2,h3,h4,h5,h6 {
-	font-family: Verdana, Arial, Helvetica, sans-serif;
-	color: #369;
-	margin-top: 1.0em;
-	margin-bottom: 0.1em;
-}
-
-h1 { font-size:150%; }
-h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
-h3 { font-size: 120%; }
-
-.ok, .error { font-weight:bold; }
-.ok { color:green; }
-.error { color:red; }
-.check { color:#555; }
-
-.warning {
-	width: 98%;
-	background:#FFDBDB;
-	padding:0.2em;
-	margin-top:0.5em;
-	border: 1px solid black;
-}
-.info {
-	width: 98%;
-	background:#99CC99;
-	padding:0.2em;
-	margin-top:0.5em;
-	border: 1px solid black;
-}
-
-</style>
-</head>
-<body>
-<div id="container">
-<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
-
-<h1>WebsiteBaker Upgrade</h1>
-<p>This script upgrades an existing WebsiteBaker <strong>Version 2.7 and higher</strong> installation to the <strong>Version <?php echo $version ?></strong>. The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
-
-<?php
-/**
- * Check if disclaimer was accepted
- */
-if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
-<h2>Step 1: Backup your files</h2>
-<p>It is highly recommended to <strong>create a manual backup</strong> of the entire <strong>/pages folder</strong> and the <strong>MySQL database</strong> before proceeding.<br /><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
-
-<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
-<textarea cols="80" rows="5">DISCLAIMER: The WebsiteBaker upgrade script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. One needs to confirm that a manual backup of the /pages folder (including all files and subfolders contained in it) and backup of the entire WebsiteBaker MySQL database was created before you can proceed.</textarea>
-<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;I confirm that a manual backup of the /pages folder and the MySQL database was created.
-<br /><br /><input name="send" type="submit" value="Start upgrade script" />
-</form>
-<br />
-
-<?php
-	status_msg('<strong>Notice:</strong><br />You need to confirm that you have created a manual backup of the /pages directory and the MySQL database before you can proceed.', 'warning', 'div');
-	echo '<br /><br />';
-    echo "</div>
-    </body>
-    </html>
-    ";
-	exit();
-}
-
-echo '<h2>Step 2: Updating database entries</h2>';
-
-require_once(WB_PATH.'/framework/functions.php');
-require_once(WB_PATH.'/framework/class.admin.php');
-$admin = new admin('Addons', 'modules', false, false);
-
-$OK   = '<span class="ok">OK</span>';
-$FAIL = '<span class="error">FAILED</span>';
-
-// function to add a var/value-pair into settings-table
-function db_add_key_value($key, $value) {
-	global $database; global $OK; global $FAIL;
-	$table = TABLE_PREFIX.'settings';
-	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
-	if($query->numRows() > 0) {
-		echo "$key: already exists. $OK.<br />";
-		return true;
-	} else {
-		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
-		echo (mysql_error()?mysql_error().'<br />':'');
-		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
-		if($query->numRows() > 0) {
-			echo "$key: $OK.<br />";
-			return true;
-		} else {
-			echo "$key: $FAIL!<br />";
-			return false;
-		}
-	}
-}
-
-// function to add a new field into a table
-function db_add_field($field, $table, $desc) {
-	global $database; global $OK; global $FAIL;
-	$table = TABLE_PREFIX.$table;
-	$query = $database->query("DESCRIBE $table '$field'");
-	if($query->numRows() == 0) { // add field
-		$query = $database->query("ALTER TABLE $table ADD $field $desc");
-		echo (mysql_error()?mysql_error().'<br />':'');
-		$query = $database->query("DESCRIBE $table '$field'");
-		echo (mysql_error()?mysql_error().'<br />':'');
-		if($query->numRows() > 0) {
-			echo "'$field' added. $OK.<br />";
-		} else {
-			echo "adding '$field' $FAIL!<br />";
-		}
-	} else {
-		echo "'$field' already exists. $OK.<br />";
-	}
-}
-
-/**********************************************************
- *  - Adding field default_theme to settings table
- */
-echo "<br />Adding default_theme to settings table<br />";
-$cfg = array(
-	'default_theme' => 'wb_theme'
-);
-
-foreach($cfg as $key=>$value) {
-	db_add_key_value($key, $value);
-}
-
-/**********************************************************
- *  - install droplets
- */
-    $drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
-    echo $drops;
-
-     $file_name = (!in_array ( "mod_droplets", $all_tables)) ? "install.php" : "upgrade.php";
-     require_once (WB_PATH."/modules/droplets/".$file_name);
-
-// check again all tables, to get a new array
- if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
-/**********************************************************
- *  - check tables comin with WebsiteBaker
- */
-    $check_text = 'total ';
-    // $check_tables = mysqlCheckTables( DB_NAME ) ;
-
-    if(sizeof($all_tables) == 22)
-    {
-        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
-    }
-    else
-    {
-        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
-    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
-        $result = array_diff ( $table_list, $all_tables );
-        echo '<h4 class="warning"><br />';
-        while ( list ( $key, $val ) = each ( $result ) )
-        {
-            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
-        }
-        echo '<br /></h4>';
-    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
-    	echo '<input type="submit" value="kick me back" style="float:left;" />';
-    	echo '</form>';
-        if(defined('ADMIN_URL'))
-        {
-        	echo '<form action="'.ADMIN_URL.'" target="_self">';
-        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
-        	echo '</form>';
-        }
-        echo "<br /><br /></div>
-        </body>
-        </html>
-        ";
-        exit();
-    }
-
-/**********************************************************
- *  - Adding field sec_anchor to settings table
- */
-
-echo "<br />Adding sec_anchor to settings table<br />";
-$cfg = array(
-	'sec_anchor' => 'wb_'
-);
-foreach($cfg as $key=>$value) {
-	db_add_key_value($key, $value);
-}
-
-/**********************************************************
- *  - Adding redirect timer to settings table
- */
-echo "<br />Adding redirect timer to settings table<br />";
-$cfg = array(
-	'redirect_timer' => '1500'
-);
-foreach($cfg as $key=>$value) {
-	db_add_key_value($key, $value);
-}
-
-/**********************************************************
- *  - Adding mediasettings to settings table
- */
-echo "<br />Adding mediasettings to settings table<br />";
-$cfg = array(
-	'mediasettings' => ''
-);
-foreach($cfg as $key=>$value) {
-	db_add_key_value($key, $value);
-}
-
-/**********************************************************
- *  - Add field "redirect_type" to table "mod_menu_link"
- */
-echo "<br />Adding field redirect_type to mod_menu_link table<br />";
-db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
-
-
-
-if (version_compare(WB_VERSION, '2.8.0') < 0)
-{
-    /**********************************************************
-     *  - Update search no results database filed to create
-     *  valid XHTML if search is empty
-     */
-    echo "<br />Updating database field `no_results` of search table: ";
-    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
-    $sql = "UPDATE `" . TABLE_PREFIX . "search` SET `value` = '$search_no_results' WHERE `name`= 'no_results'";
-    $database->query($sql);
-    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL<br />";
-    /**********************************************************
-     *  - Update settings of News Modul
-     */
-
-    // These are the default setting
-    $header = '<table cellpadding=\"0\" cellspacing=\"0\" class=\"loop-header\">'."\n";
-    $post_loop = '<tr class=\"post_top\">
-<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
-<td class=\"post_date\">[PUBLISHED_TIME], [PUBLISHED_DATE]</td>
-</tr>
-<tr>
-<td class=\"post_short\" colspan=\"2\">
-[SHORT]
-<span style=\"visibility:[SHOW_READ_MORE];\"><a href=\"[LINK]\">[TEXT_READ_MORE]</a></span>
-</td>
-</tr>';
-    $footer = '</table>
-<table cellpadding="0" cellspacing="0" class="page-header" style="display: [DISPLAY_PREVIOUS_NEXT_LINKS]">
-<tr>
-<td class="page-left">[PREVIOUS_PAGE_LINK]</td>
-<td class="page-center">[OF]</td>
-<td class="page-right">[NEXT_PAGE_LINK]</td>
-</tr>
-</table>';
-    $post_header = addslashes('<table cellpadding="0" cellspacing="0" class="post-header">
-<tr>
-<td><h1>[TITLE]</h1></td>
-<td rowspan="3" style="display: [DISPLAY_IMAGE]">[GROUP_IMAGE]</td>
-</tr>
-<tr>
-<td class="public-info"><b>[TEXT_POSTED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [PUBLISHED_DATE]</b></td>
-</tr>
-<tr style="display: [DISPLAY_GROUP]">
-<td class="group-page"><a href="[BACK]">[PAGE_TITLE]</a> &gt;&gt; <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
-</tr>
-</table>');
-    $post_footer = '<p>[TEXT_LAST_CHANGED]: [MODI_DATE] [TEXT_AT] [MODI_TIME]</p>
-<a href=\"[BACK]\">[TEXT_BACK]</a>';
-    $comments_header = addslashes('<br /><br />
-<h2>[TEXT_COMMENTS]</h2>
-<table cellpadding="2" cellspacing="0" class="comment-header">');
-    $comments_loop = addslashes('<tr>
-<td class="comment_title">[TITLE]</td>
-<td class="comment_info">[TEXT_BY] [DISPLAY_NAME] [TEXT_ON] [DATE] [TEXT_AT] [TIME]</td>
-</tr>
-<tr>
-<td colspan="2" class="comment_text">[COMMENT]</td>
-</tr>');
-    $comments_footer = '</table>
-<br /><a href=\"[ADD_COMMENT_URL]\">[TEXT_ADD_COMMENT]</a>';
-    $comments_page = '<h1>[TEXT_COMMENT]</h1>
-<h2>[POST_TITLE]</h2>
-<br />';
-
-if(in_array('mod_news_settings', $all_tables))
-{
-   // Insert default settings into database
-   $query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
-   if($query_dates->numRows() > 1)
-   {
-        while($result = $query_dates->fetchRow())
-        {
-
-        	echo "<br /><u>Add default settings to database for news section_id= ".$result['section_id']."</u><br />";
-        	$section_id = $result['section_id'];
-
-        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
-        		echo 'Database data header added successfully';
-        	}
-        	echo mysql_error().'<br />';
-
-        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
-        		echo 'Database data post_loop added successfully';
-        	}
-        	echo mysql_error().'<br />';
-
-        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `footer` = '$footer' WHERE `section_id` = $section_id")) {
-        		echo 'Database data footer added successfully';
-        	}
-        	echo mysql_error().'<br />';
-
-        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
-        		echo 'Database data post_header added successfully';
-        	}
-        	echo mysql_error().'<br />';
-
-        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
-        		echo 'Database data post_footer added successfully';
-        	}
-        	echo mysql_error().'<br />';
-
-        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
-        		echo 'Database data comments_header added successfully';
-        	}
-        	echo mysql_error().'<br />';
-
-        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_loop` = '$comments_loop' WHERE `section_id` = $section_id")) {
-        		echo 'Database data comments_loop added successfully';
-        	}
-        	echo mysql_error().'<br />';
-
-        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_footer` = '$comments_footer' WHERE `section_id` = $section_id")) {
-        		echo 'Database data comments_footer added successfully';
-        	}
-        	echo mysql_error().'<br />';
-
-        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_page` = '$comments_page' WHERE `section_id` = $section_id")) {
-        		echo 'Database data comments_page added successfully';
-        	}
-        	echo mysql_error().'<br />';
-
-        }
-
-
-      if ((version_compare(WB_VERSION, '2.8.1') <= 0) && file_exists(WB_PATH."/modules/news/upgrade.php"))
-      {
-              echo '<h4>Upgrade existings postfiles to new format</h4><br />';
-              // change old postfiles to new postfiles
-              require_once(WB_PATH."/modules/news/upgrade.php");
-      }
-    }
-
-   }
-
-}
-
-/**********************************************************
- *  - Set Version to WB 2.8.2
- */
-echo "<br />Update database version number to 2.8.2 : ";
-echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
-
-/**********************************************************
- *  - Reload all addons
- */
-
-//delete modules
-$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
-// Load all modules
-if($handle = opendir(WB_PATH.'/modules/')) {
-	while(false !== ($file = readdir($handle))) {
-		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
-			load_module(WB_PATH.'/modules/'.$file);
-		}
-	}
-	closedir($handle);
-}
-echo '<br />Modules reloaded<br />';
-
-//delete templates		
-$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
-// Load all templates
-if($handle = opendir(WB_PATH.'/templates/')) {
-	while(false !== ($file = readdir($handle))) {
-		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
-			load_template(WB_PATH.'/templates/'.$file);
-		}
-	}
-	closedir($handle);
-}
-echo '<br />Templates reloaded<br />';
-
-//delete languages
-$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
-// Load all languages
-if($handle = opendir(WB_PATH.'/languages/')) {
-	while(false !== ($file = readdir($handle))) {
-		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
-			load_language(WB_PATH.'/languages/'.$file);
-		}
-	}
-	closedir($handle);
-}
-echo '<br />Languages reloaded<br />';
-
-
-/**********************************************************
- *  - End of upgrade script
- */
-
-// require(WB_PATH.'/framework/initialize.php');
-
-if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', 'wb_theme'); }
-if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
-
-echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
-status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
-// show buttons to go to the backend or frontend
-echo '<br />';
-if(defined('WB_URL')) {
-	echo '<form action="'.WB_URL.'">';
-	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
-	echo '</form>';
-}
-if(defined('ADMIN_URL')) {
-	echo '<form action="'.ADMIN_URL.'">';
-	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
-	echo '</form>';
-}
-echo '<p>&nbsp;</p>';
-
-?>
-</div>
-</body>
+<?php
+/**
+ *
+ * @category        backend
+ * @package         installation
+ * @author          WebsiteBaker Project
+ * @copyright       2004-2009, Ryan Djurovich
+ * @copyright       2009-2011, Website Baker Org. e.V.
+ * @link			http://www.websitebaker2.org/
+ * @license         http://www.gnu.org/licenses/gpl.html
+ * @platform        WebsiteBaker 2.8.x
+ * @requirements    PHP 5.2.2 and higher
+ * @version         $Id$
+ * @filesource		$HeadURL$
+ * @lastmodified    $Date$
+ *
+ */
+
+@require_once('config.php');
+
+// this function checks the basic configurations of an existing WB intallation
+function status_msg($message, $class='check', $element='span') {
+	// returns a status message
+	echo '<'.$element .' class="' .$class .'">' .$message .'</' .$element.'>';
+}
+
+$version = '2.8.2';
+// database tables including in WB package
+$table_list = array (
+    'settings','groups','addons','pages','sections','search','users',
+    'mod_captcha_control','mod_code','mod_droplets','mod_form_fields',
+    'mod_form_settings','mod_form_submissions','mod_jsadmin','mod_menu_link',
+    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
+    'mod_output_filter','mod_wrapper','mod_wysiwyg'
+);
+
+// analyze/check database tables
+function mysqlCheckTables( $dbName )
+{
+    global $table_list;
+    $table_prefix = TABLE_PREFIX;
+    $sql = "SHOW TABLES FROM " . $dbName;
+    $result = @mysql_query( $sql );
+    $data = array();
+    $x = 0;
+
+    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
+    {
+        $tmp = str_replace($table_prefix, '', $row[0]);
+
+        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$table_list) )
+        {
+            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
+            $analyze = @mysql_query( $sql );
+            $rowFetch = @mysql_fetch_array( $analyze, MYSQL_ASSOC );
+            $data[$x]['Op'] = $rowFetch["Op"];
+            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
+            $msgColor = '<span class="error">';
+            $data[$x]['Table'] = $row[0];
+           // print  " ";
+            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
+            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
+           // print  "<br />";
+            $x++;
+        }
+    }
+
+
+
+
+    return $data;
+}
+
+
+// check existings tables for upgrade or install
+function check_wb_tables()
+{
+    global $database,$table_list;
+
+ // if prefix inludes '_' or '%'
+ $search_for = addcslashes ( TABLE_PREFIX, '%_' );
+ $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
+
+        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
+        $all_tables = array();
+        if($get_result->numRows() > 0)
+        {
+            while ($data = $get_result->fetchRow())
+            {
+                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
+                if(in_array($tmp,$table_list))
+                {
+                    $all_tables[] = $tmp;
+                }
+            }
+        }
+     return $all_tables;
+}
+
+// check existing tables
+$all_tables = check_wb_tables();
+
+// only for array tests
+function show_array($array=array())
+{
+    print '<pre>';
+    print_r ($array);
+    print '</pre>';
+}
+
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Upgrade script</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+html { overflow: -moz-scrollbars-vertical; /* Force firefox to always show room for a vertical scrollbar */ }
+
+body {
+	margin:0;
+	padding:0;
+	border:0;
+	background: #EBF7FC;
+	color:#000;
+	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
+	font-size: small;
+	height:101%;
+}
+
+#container {
+	width:85%;
+	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
+	border:1px solid #000;
+	color:#000;
+	margin:2em auto;
+	padding:0 15px;
+	min-height: 500px;
+	text-align:left;
+}
+
+p { line-height:1.5em; }
+
+h1,h2,h3,h4,h5,h6 {
+	font-family: Verdana, Arial, Helvetica, sans-serif;
+	color: #369;
+	margin-top: 1.0em;
+	margin-bottom: 0.1em;
+}
+
+h1 { font-size:150%; }
+h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
+h3 { font-size: 120%; }
+
+.ok, .error { font-weight:bold; }
+.ok { color:green; }
+.error { color:red; }
+.check { color:#555; }
+
+.warning {
+	width: 98%;
+	background:#FFDBDB;
+	padding:0.2em;
+	margin-top:0.5em;
+	border: 1px solid black;
+}
+.info {
+	width: 98%;
+	background:#99CC99;
+	padding:0.2em;
+	margin-top:0.5em;
+	border: 1px solid black;
+}
+
+</style>
+</head>
+<body>
+<div id="container">
+<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
+
+<h1>WebsiteBaker Upgrade</h1>
+<p>This script upgrades an existing WebsiteBaker <strong>Version 2.7 and higher</strong> installation to the <strong>Version <?php echo $version ?></strong>. The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
+
+<?php
+/**
+ * Check if disclaimer was accepted
+ */
+if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
+<h2>Step 1: Backup your files</h2>
+<p>It is highly recommended to <strong>create a manual backup</strong> of the entire <strong>/pages folder</strong> and the <strong>MySQL database</strong> before proceeding.<br /><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
+
+<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
+<textarea cols="80" rows="5">DISCLAIMER: The WebsiteBaker upgrade script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. One needs to confirm that a manual backup of the /pages folder (including all files and subfolders contained in it) and backup of the entire WebsiteBaker MySQL database was created before you can proceed.</textarea>
+<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;I confirm that a manual backup of the /pages folder and the MySQL database was created.
+<br /><br /><input name="send" type="submit" value="Start upgrade script" />
+</form>
+<br />
+
+<?php
+	status_msg('<strong>Notice:</strong><br />You need to confirm that you have created a manual backup of the /pages directory and the MySQL database before you can proceed.', 'warning', 'div');
+	echo '<br /><br />';
+    echo "</div>
+    </body>
+    </html>
+    ";
+	exit();
+}
+
+echo '<h2>Step 2: Updating database entries</h2>';
+
+require_once(WB_PATH.'/framework/functions.php');
+require_once(WB_PATH.'/framework/class.admin.php');
+$admin = new admin('Addons', 'modules', false, false);
+
+$OK   = '<span class="ok">OK</span>';
+$FAIL = '<span class="error">FAILED</span>';
+
+// function to add a var/value-pair into settings-table
+function db_add_key_value($key, $value) {
+	global $database; global $OK; global $FAIL;
+	$table = TABLE_PREFIX.'settings';
+	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
+	if($query->numRows() > 0) {
+		echo "$key: already exists. $OK.<br />";
+		return true;
+	} else {
+		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
+		echo (mysql_error()?mysql_error().'<br />':'');
+		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
+		if($query->numRows() > 0) {
+			echo "$key: $OK.<br />";
+			return true;
+		} else {
+			echo "$key: $FAIL!<br />";
+			return false;
+		}
+	}
+}
+
+// function to add a new field into a table
+function db_add_field($field, $table, $desc) {
+	global $database; global $OK; global $FAIL;
+	$table = TABLE_PREFIX.$table;
+	$query = $database->query("DESCRIBE $table '$field'");
+	if($query->numRows() == 0) { // add field
+		$query = $database->query("ALTER TABLE $table ADD $field $desc");
+		echo (mysql_error()?mysql_error().'<br />':'');
+		$query = $database->query("DESCRIBE $table '$field'");
+		echo (mysql_error()?mysql_error().'<br />':'');
+		if($query->numRows() > 0) {
+			echo "'$field' added. $OK.<br />";
+		} else {
+			echo "adding '$field' $FAIL!<br />";
+		}
+	} else {
+		echo "'$field' already exists. $OK.<br />";
+	}
+}
+
+/**********************************************************
+ *  - Adding field default_theme to settings table
+ */
+echo "<br />Adding default_theme to settings table<br />";
+$cfg = array(
+	'default_theme' => 'wb_theme'
+);
+
+foreach($cfg as $key=>$value) {
+	db_add_key_value($key, $value);
+}
+
+/**********************************************************
+ *  - install droplets
+ */
+    $drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
+    echo $drops;
+
+     $file_name = (!in_array ( "mod_droplets", $all_tables)) ? "install.php" : "upgrade.php";
+     require_once (WB_PATH."/modules/droplets/".$file_name);
+
+// check again all tables, to get a new array
+ if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
+/**********************************************************
+ *  - check tables comin with WebsiteBaker
+ */
+    $check_text = 'total ';
+    // $check_tables = mysqlCheckTables( DB_NAME ) ;
+
+    if(sizeof($all_tables) == 22)
+    {
+        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
+    }
+    else
+    {
+        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
+    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
+        $result = array_diff ( $table_list, $all_tables );
+        echo '<h4 class="warning"><br />';
+        while ( list ( $key, $val ) = each ( $result ) )
+        {
+            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
+        }
+        echo '<br /></h4>';
+    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
+    	echo '<input type="submit" value="kick me back" style="float:left;" />';
+    	echo '</form>';
+        if(defined('ADMIN_URL'))
+        {
+        	echo '<form action="'.ADMIN_URL.'" target="_self">';
+        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
+        	echo '</form>';
+        }
+        echo "<br /><br /></div>
+        </body>
+        </html>
+        ";
+        exit();
+    }
+
+/**********************************************************
+ *  - Adding field sec_anchor to settings table
+ */
+
+echo "<br />Adding sec_anchor to settings table<br />";
+$cfg = array(
+	'sec_anchor' => 'wb_'
+);
+foreach($cfg as $key=>$value) {
+	db_add_key_value($key, $value);
+}
+
+/**********************************************************
+ *  - Adding redirect timer to settings table
+ */
+echo "<br />Adding redirect timer to settings table<br />";
+$cfg = array(
+	'redirect_timer' => '1500'
+);
+foreach($cfg as $key=>$value) {
+	db_add_key_value($key, $value);
+}
+
+/**********************************************************
+ *  - Adding mediasettings to settings table
+ */
+echo "<br />Adding mediasettings to settings table<br />";
+$cfg = array(
+	'mediasettings' => ''
+);
+foreach($cfg as $key=>$value) {
+	db_add_key_value($key, $value);
+}
+
+/**********************************************************
+ *  - Adding fingerprint_with_ip_octets to settings table
+ */
+echo "<br />Adding fingerprint_with_ip_octets to settings table<br />";
+$cfg = array(
+	'fingerprint_with_ip_octets' => '3'
+);
+foreach($cfg as $key=>$value) {
+	db_add_key_value($key, $value);
+}
+
+/**********************************************************
+ *  - Add field "redirect_type" to table "mod_menu_link"
+ */
+echo "<br />Adding field redirect_type to mod_menu_link table<br />";
+db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
+
+
+
+if (version_compare(WB_VERSION, '2.8.0') < 0)
+{
+    /**********************************************************
+     *  - Update search no results database filed to create
+     *  valid XHTML if search is empty
+     */
+    echo "<br />Updating database field `no_results` of search table: ";
+    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
+    $sql = "UPDATE `" . TABLE_PREFIX . "search` SET `value` = '$search_no_results' WHERE `name`= 'no_results'";
+    $database->query($sql);
+    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL<br />";
+    /**********************************************************
+     *  - Update settings of News Modul
+     */
+
+    // These are the default setting
+    $header = '<table cellpadding=\"0\" cellspacing=\"0\" class=\"loop-header\">'."\n";
+    $post_loop = '<tr class=\"post_top\">
+<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
+<td class=\"post_date\">[PUBLISHED_TIME], [PUBLISHED_DATE]</td>
+</tr>
+<tr>
+<td class=\"post_short\" colspan=\"2\">
+[SHORT]
+<span style=\"visibility:[SHOW_READ_MORE];\"><a href=\"[LINK]\">[TEXT_READ_MORE]</a></span>
+</td>
+</tr>';
+    $footer = '</table>
+<table cellpadding="0" cellspacing="0" class="page-header" style="display: [DISPLAY_PREVIOUS_NEXT_LINKS]">
+<tr>
+<td class="page-left">[PREVIOUS_PAGE_LINK]</td>
+<td class="page-center">[OF]</td>
+<td class="page-right">[NEXT_PAGE_LINK]</td>
+</tr>
+</table>';
+    $post_header = addslashes('<table cellpadding="0" cellspacing="0" class="post-header">
+<tr>
+<td><h1>[TITLE]</h1></td>
+<td rowspan="3" style="display: [DISPLAY_IMAGE]">[GROUP_IMAGE]</td>
+</tr>
+<tr>
+<td class="public-info"><b>[TEXT_POSTED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [PUBLISHED_DATE]</b></td>
+</tr>
+<tr style="display: [DISPLAY_GROUP]">
+<td class="group-page"><a href="[BACK]">[PAGE_TITLE]</a> &gt;&gt; <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
+</tr>
+</table>');
+    $post_footer = '<p>[TEXT_LAST_CHANGED]: [MODI_DATE] [TEXT_AT] [MODI_TIME]</p>
+<a href=\"[BACK]\">[TEXT_BACK]</a>';
+    $comments_header = addslashes('<br /><br />
+<h2>[TEXT_COMMENTS]</h2>
+<table cellpadding="2" cellspacing="0" class="comment-header">');
+    $comments_loop = addslashes('<tr>
+<td class="comment_title">[TITLE]</td>
+<td class="comment_info">[TEXT_BY] [DISPLAY_NAME] [TEXT_ON] [DATE] [TEXT_AT] [TIME]</td>
+</tr>
+<tr>
+<td colspan="2" class="comment_text">[COMMENT]</td>
+</tr>');
+    $comments_footer = '</table>
+<br /><a href=\"[ADD_COMMENT_URL]\">[TEXT_ADD_COMMENT]</a>';
+    $comments_page = '<h1>[TEXT_COMMENT]</h1>
+<h2>[POST_TITLE]</h2>
+<br />';
+
+if(in_array('mod_news_settings', $all_tables))
+{
+   // Insert default settings into database
+   $query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
+   if($query_dates->numRows() > 1)
+   {
+        while($result = $query_dates->fetchRow())
+        {
+
+        	echo "<br /><u>Add default settings to database for news section_id= ".$result['section_id']."</u><br />";
+        	$section_id = $result['section_id'];
+
+        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
+        		echo 'Database data header added successfully';
+        	}
+        	echo mysql_error().'<br />';
+
+        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
+        		echo 'Database data post_loop added successfully';
+        	}
+        	echo mysql_error().'<br />';
+
+        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `footer` = '$footer' WHERE `section_id` = $section_id")) {
+        		echo 'Database data footer added successfully';
+        	}
+        	echo mysql_error().'<br />';
+
+        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
+        		echo 'Database data post_header added successfully';
+        	}
+        	echo mysql_error().'<br />';
+
+        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
+        		echo 'Database data post_footer added successfully';
+        	}
+        	echo mysql_error().'<br />';
+
+        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
+        		echo 'Database data comments_header added successfully';
+        	}
+        	echo mysql_error().'<br />';
+
+        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_loop` = '$comments_loop' WHERE `section_id` = $section_id")) {
+        		echo 'Database data comments_loop added successfully';
+        	}
+        	echo mysql_error().'<br />';
+
+        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_footer` = '$comments_footer' WHERE `section_id` = $section_id")) {
+        		echo 'Database data comments_footer added successfully';
+        	}
+        	echo mysql_error().'<br />';
+
+        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_page` = '$comments_page' WHERE `section_id` = $section_id")) {
+        		echo 'Database data comments_page added successfully';
+        	}
+        	echo mysql_error().'<br />';
+
+        }
+
+
+      if ((version_compare(WB_VERSION, '2.8.1') <= 0) && file_exists(WB_PATH."/modules/news/upgrade.php"))
+      {
+              echo '<h4>Upgrade existings postfiles to new format</h4><br />';
+              // change old postfiles to new postfiles
+              require_once(WB_PATH."/modules/news/upgrade.php");
+      }
+    }
+
+   }
+
+}
+
+/**********************************************************
+ *  - Set Version to WB 2.8.2
+ */
+echo "<br />Update database version number to 2.8.2 : ";
+echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
+
+/**********************************************************
+ *  - Reload all addons
+ */
+
+//delete modules
+$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
+// Load all modules
+if($handle = opendir(WB_PATH.'/modules/')) {
+	while(false !== ($file = readdir($handle))) {
+		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
+			load_module(WB_PATH.'/modules/'.$file);
+		}
+	}
+	closedir($handle);
+}
+echo '<br />Modules reloaded<br />';
+
+//delete templates		
+$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
+// Load all templates
+if($handle = opendir(WB_PATH.'/templates/')) {
+	while(false !== ($file = readdir($handle))) {
+		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
+			load_template(WB_PATH.'/templates/'.$file);
+		}
+	}
+	closedir($handle);
+}
+echo '<br />Templates reloaded<br />';
+
+//delete languages
+$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
+// Load all languages
+if($handle = opendir(WB_PATH.'/languages/')) {
+	while(false !== ($file = readdir($handle))) {
+		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
+			load_language(WB_PATH.'/languages/'.$file);
+		}
+	}
+	closedir($handle);
+}
+echo '<br />Languages reloaded<br />';
+
+
+/**********************************************************
+ *  - End of upgrade script
+ */
+
+// require(WB_PATH.'/framework/initialize.php');
+
+if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', 'wb_theme'); }
+if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
+
+echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
+status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
+// show buttons to go to the backend or frontend
+echo '<br />';
+if(defined('WB_URL')) {
+	echo '<form action="'.WB_URL.'">';
+	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
+	echo '</form>';
+}
+if(defined('ADMIN_URL')) {
+	echo '<form action="'.ADMIN_URL.'">';
+	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
+	echo '</form>';
+}
+echo '<p>&nbsp;</p>';
+
+?>
+</div>
+</body>
 </html>
\ No newline at end of file
Index: branches/2.8.x/wb/admin/interface/version.php
===================================================================
--- branches/2.8.x/wb/admin/interface/version.php	(revision 1422)
+++ branches/2.8.x/wb/admin/interface/version.php	(revision 1423)
@@ -52,6 +52,6 @@
 
 // check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
 if(!defined('VERSION')) define('VERSION', '2.8.2.RC5');
-if(!defined('REVISION')) define('REVISION', '1422');
+if(!defined('REVISION')) define('REVISION', '1423');
 
 ?>
Index: branches/2.8.x/wb/install/save.php
===================================================================
--- branches/2.8.x/wb/install/save.php	(revision 1422)
+++ branches/2.8.x/wb/install/save.php	(revision 1423)
@@ -1,792 +1,793 @@
-<?php
-/**
- *
- * @category        backend
- * @package         install
- * @author          WebsiteBaker Project
- * @copyright       2004-2009, Ryan Djurovich
- * @copyright       2009-2011, Website Baker Org. e.V.
- * @link			http://www.websitebaker2.org/
- * @license         http://www.gnu.org/licenses/gpl.html
- * @platform        WebsiteBaker 2.8.x
- * @requirements    PHP 5.2.2 and higher
- * @version      	$Id$
- * @filesource		$HeadURL:  $
- * @lastmodified    $Date: $
- *
- */
-
-$debug = true;
-
-if (true === $debug) {
-	ini_set('display_errors', 1);
-	error_reporting(E_ALL);
-}
-// Start a session
-if(!defined('SESSION_STARTED')) {
-	session_name('wb_session_id');
-	session_start();
-	define('SESSION_STARTED', true);
-}
-// get random-part for session_name()
-list($usec,$sec) = explode(' ',microtime());
-srand((float)$sec+((float)$usec*100000));
-$session_rand = rand(1000,9999);
-
-// Function to set error
-function set_error($message, $field_name = '') {
-	global $_POST;
-	if(isset($message) AND $message != '') {
-		// Copy values entered into session so user doesn't have to re-enter everything
-		if(isset($_POST['website_title'])) {
-			$_SESSION['wb_url'] = $_POST['wb_url'];
-			$_SESSION['default_timezone'] = $_POST['default_timezone'];
-			$_SESSION['default_language'] = $_POST['default_language'];
-			if(!isset($_POST['operating_system'])) {
-				$_SESSION['operating_system'] = 'linux';
-			} else {
-				$_SESSION['operating_system'] = $_POST['operating_system'];
-			}
-			if(!isset($_POST['world_writeable'])) {
-				$_SESSION['world_writeable'] = false;
-			} else {
-				$_SESSION['world_writeable'] = true;
-			}
-			$_SESSION['database_host'] = $_POST['database_host'];
-			$_SESSION['database_username'] = $_POST['database_username'];
-			$_SESSION['database_password'] = $_POST['database_password'];
-			$_SESSION['database_name'] = $_POST['database_name'];
-			$_SESSION['table_prefix'] = $_POST['table_prefix'];
-			if(!isset($_POST['install_tables'])) {
-				$_SESSION['install_tables'] = false;
-			} else {
-				$_SESSION['install_tables'] = true;
-			}
-			$_SESSION['website_title'] = $_POST['website_title'];
-			$_SESSION['admin_username'] = $_POST['admin_username'];
-			$_SESSION['admin_email'] = $_POST['admin_email'];
-			$_SESSION['admin_password'] = $_POST['admin_password'];
-			$_SESSION['admin_repassword'] = $_POST['admin_repassword'];
-		}
-		// Set the message
-		$_SESSION['message'] = $message;
-		// Set the element(s) to highlight
-		if($field_name != '') {
-			$_SESSION['ERROR_FIELD'] = $field_name;
-		}
-		// Specify that session support is enabled
-		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
-		// Redirect to first page again and exit
-		header('Location: index.php?sessions_checked=true');
-		exit();
-	}
-}
-
-// Dummy class to allow modules' install scripts to call $admin->print_error
-class admin_dummy
-{
-	var $error='';
-	function print_error($message)
-	{
-		$this->error=$message;
-	}
-}
-
-// Function to workout what the default permissions are for files created by the webserver
-function default_file_mode($temp_dir) {
-	$v = explode(".",PHP_VERSION);
-	$v = $v[0].$v[1];
-	if($v > 41 AND is_writable($temp_dir)) {
-		$filename = $temp_dir.'/test_permissions.txt';
-		$handle = fopen($filename, 'w');
-		fwrite($handle, 'This file is to get the default file permissions');
-		fclose($handle);
-		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
-		unlink($filename);
-	} else {
-		$default_file_mode = '0777';
-	}
-	return $default_file_mode;
-}
-
-// Function to workout what the default permissions are for directories created by the webserver
-function default_dir_mode($temp_dir) {
-	$v = explode(".",PHP_VERSION);
-	$v = $v[0].$v[1];
-	if($v > 41 AND is_writable($temp_dir)) {
-		$dirname = $temp_dir.'/test_permissions/';
-		mkdir($dirname);
-		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
-		rmdir($dirname);
-	} else {
-		$default_dir_mode = '0777';
-	}
-	return $default_dir_mode;
-}
-
-function add_slashes($input) {
-	if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
-		return $input;
-	}
-	$output = addslashes($input);
-	return $output;
-}
-
-// Begin check to see if form was even submitted
-// Set error if no post vars found
-if(!isset($_POST['website_title'])) {
-	set_error('Please fill-in the form below');
-}
-// End check to see if form was even submitted
-
-// Begin path and timezone details code
-
-// Check if user has entered the installation url
-if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
-	set_error('Please enter an absolute URL', 'wb_url');
-} else {
-	$wb_url = $_POST['wb_url'];
-}
-// Remove any slashes at the end of the URL
-if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
-	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
-}
-if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
-	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
-}
-if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
-	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
-}
-if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
-	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
-}
-// Get the default time zone
-if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
-	set_error('Please select a valid default timezone', 'default_timezone');
-} else {
-	$default_timezone = $_POST['default_timezone']*60*60;
-}
-// End path and timezone details code
-
-// Get the default language
-$allowed_languages = array('BG','CA', 'CS', 'DA', 'DE', 'EN', 'ES', 'ET', 'FI', 'FR', 'HR', 'HU', 'IT', 'LV', 'NL', 'NO', 'PL', 'PT', 'RU','SE','SK','TR');
-if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
-	set_error('Please select a valid default backend language','default_language');
-} else {
-	$default_language = $_POST['default_language'];
-	// make sure the selected language file exists in the language folder
-	if(!file_exists('../languages/' .$default_language .'.php')) {
-		set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language','default_language');
-	}
-}
-// End default language details code
-
-// Begin operating system specific code
-// Get operating system
-if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
-	set_error('Please select a valid operating system');
-} else {
-	$operating_system = $_POST['operating_system'];
-}
-// Work-out file permissions
-if($operating_system == 'windows') {
-	$file_mode = '0777';
-	$dir_mode = '0777';
-} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
-	$file_mode = '0777';
-	$dir_mode = '0777';
-} else {
-	$file_mode = default_file_mode('../temp');
-	$dir_mode = default_dir_mode('../temp');
-}
-// End operating system specific code
-
-// Begin database details code
-// Check if user has entered a database host
-if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
-	set_error('Please enter a database host name', 'database_host');
-} else {
-	$database_host = $_POST['database_host'];
-}
-// Check if user has entered a database username
-if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
-	set_error('Please enter a database username','database_username');
-} else {
-	$database_username = $_POST['database_username'];
-}
-// Check if user has entered a database password
-if(!isset($_POST['database_password'])) {
-	set_error('Please enter a database password', 'database_password');
-} else {
-	$database_password = $_POST['database_password'];
-}
-// Check if user has entered a database name
-if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
-	set_error('Please enter a database name', 'database_name');
-} else {
-	// make sure only allowed characters are specified
-	if(preg_match('/[^a-z0-9_-]+/i', $_POST['database_name'])) {
-		// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
-		set_error('Only characters a-z, A-Z, 0-9, - and _ allowed in database name.', 'database_name');
-	}
-	$database_name = $_POST['database_name'];
-}
-// Get table prefix
-if(preg_match('/[^a-z0-9_]+/i', $_POST['table_prefix'])) {
-	// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
-	set_error('Only characters a-z, A-Z, 0-9 and _ allowed in table_prefix.', 'table_prefix');
-} else {
-	$table_prefix = $_POST['table_prefix'];
-}
-
-// Find out if the user wants to install tables and data
-if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
-	$install_tables = true;
-} else {
-	$install_tables = false;
-}
-// End database details code
-
-// Begin website title code
-// Get website title
-if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
-	set_error('Please enter a website title', 'website_title');
-} else {
-	$website_title = add_slashes($_POST['website_title']);
-}
-// End website title code
-
-// Begin admin user details code
-// Get admin username
-if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
-	set_error('Please enter a username for the Administrator account','admin_username');
-} else {
-	$admin_username = $_POST['admin_username'];
-}
-// Get admin email and validate it
-if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
-	set_error('Please enter an email for the Administrator account','admin_email');
-} else {
-	if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i', $_POST['admin_email'])) {
-		$admin_email = $_POST['admin_email'];
-	} else {
-		set_error('Please enter a valid email address for the Administrator account','admin_email');
-	}
-}
-// Get the two admin passwords entered, and check that they match
-if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
-	set_error('Please enter a password for the Administrator account','admin_password');
-} else {
-	$admin_password = $_POST['admin_password'];
-}
-if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
-	set_error('Please make sure you re-enter the password for the Administrator account','admin_repassword');
-} else {
-	$admin_repassword = $_POST['admin_repassword'];
-}
-if($admin_password != $admin_repassword) {
-	set_error('Sorry, the two Administrator account passwords you entered do not match','admin_repassword');
-}
-// End admin user details code
-
-// Try and write settings to config file
-$config_content = "" .
-"<?php\n".
-"\n".
-"define('DB_TYPE', 'mysql');\n".
-"define('DB_HOST', '$database_host');\n".
-"define('DB_USERNAME', '$database_username');\n".
-"define('DB_PASSWORD', '$database_password');\n".
-"define('DB_NAME', '$database_name');\n".
-"define('TABLE_PREFIX', '$table_prefix');\n".
-"\n".
-"define('WB_PATH', dirname(__FILE__));\n".
-"define('WB_URL', '$wb_url');\n".
-"define('ADMIN_PATH', WB_PATH.'/admin');\n".
-"define('ADMIN_URL', '$wb_url/admin');\n".
-"\n".
-"require_once(WB_PATH.'/framework/initialize.php');\n".
-"\n".
-"?>";
-
-$config_filename = '../config.php';
-
-// Check if the file exists and is writable first.
-if(file_exists($config_filename) AND is_writable($config_filename)) {
-	if(!$handle = fopen($config_filename, 'w')) {
-		set_error("Cannot open the configuration file ($config_filename)");
-	} else {
-		if (fwrite($handle, $config_content) === FALSE) {
-			set_error("Cannot write to the configuration file ($config_filename)");
-		}
-		// Close file
-		fclose($handle);
-	}
-} else {
-	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
-}
-
-// Define configuration vars
-define('DB_TYPE', 'mysql');
-define('DB_HOST', $database_host);
-define('DB_USERNAME', $database_username);
-define('DB_PASSWORD', $database_password);
-define('DB_NAME', $database_name);
-define('TABLE_PREFIX', $table_prefix);
-define('WB_PATH', str_replace(array('/install','\install'), '',dirname(__FILE__)));
-define('WB_URL', $wb_url);
-define('ADMIN_PATH', WB_PATH.'/admin');
-define('ADMIN_URL', $wb_url.'/admin');
-
-// Check if the user has entered a correct path
-if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
-	set_error('It appears the Absolute path that you entered is incorrect');
-}
-
-// Try connecting to database	
-if(!@mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
-	set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
-}
-
-// Try to create the database
-mysql_query('CREATE DATABASE `'.$database_name.'`');
-
-// Close the mysql connection
-mysql_close();
-
-// Include WB functions file
-require_once(WB_PATH.'/framework/functions.php');
-
-// Re-connect to the database, this time using in-build database class
-require_once(WB_PATH.'/framework/class.login.php');
-$database=new database();
-
-// Check if we should install tables
-if($install_tables == true) {
-	if (!defined('WB_INSTALL_PROCESS')) define ('WB_INSTALL_PROCESS', true);
-	// Remove tables if they exist
-
-	// Pages table
-	$pages = "DROP TABLE IF EXISTS `".TABLE_PREFIX."pages`";
-	$database->query($pages);
-	// Sections table
-	$sections = "DROP TABLE IF EXISTS `".TABLE_PREFIX."sections`";
-	$database->query($sections);
-	// Settings table
-	$settings = "DROP TABLE IF EXISTS `".TABLE_PREFIX."settings`";
-	$database->query($settings);
-	// Users table
-	$users = "DROP TABLE IF EXISTS `".TABLE_PREFIX."users`";
-	$database->query($users);
-	// Groups table
-	$groups = "DROP TABLE IF EXISTS `".TABLE_PREFIX."groups`";
-	$database->query($groups);
-	// Search table
-	$search = "DROP TABLE IF EXISTS `".TABLE_PREFIX."search`";
-	$database->query($search);
-	// Addons table
-	$addons = "DROP TABLE IF EXISTS `".TABLE_PREFIX."addons`";
-	$database->query($addons);
-				
-	// Try installing tables
-	
-	// Pages table
-	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,'
-	       . ' `parent` INT NOT NULL DEFAULT \'0\','
-	       . ' `root_parent` INT NOT NULL DEFAULT \'0\','
-	       . ' `level` INT NOT NULL DEFAULT \'0\','
-	       . ' `link` TEXT NOT NULL,'
-	       . ' `target` VARCHAR( 7 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `page_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `menu_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `description` TEXT NOT NULL ,'
-	       . ' `keywords` TEXT NOT NULL ,'
-	       . ' `page_trail` TEXT NOT NULL  ,'
-	       . ' `template` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `visibility` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `position` INT NOT NULL DEFAULT \'0\','
-	       . ' `menu` INT NOT NULL DEFAULT \'0\','
-	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `searching` INT NOT NULL DEFAULT \'0\','
-	       . ' `admin_groups` TEXT NOT NULL ,'
-	       . ' `admin_users` TEXT NOT NULL ,'
-	       . ' `viewing_groups` TEXT NOT NULL ,'
-	       . ' `viewing_users` TEXT NOT NULL ,'
-	       . ' `modified_when` INT NOT NULL DEFAULT \'0\','
-	       . ' `modified_by` INT NOT NULL  DEFAULT \'0\','
-	       . ' PRIMARY KEY ( `page_id` ) '
-	       . ' )';
-	$database->query($pages);
-	
-	// Sections table
-	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'
-	       . ' `page_id` INT NOT NULL DEFAULT \'0\','
-	       . ' `position` INT NOT NULL DEFAULT \'0\','
-	       . ' `module` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `block` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `publ_start` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
-	       . ' `publ_end` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,' 
-	       . ' PRIMARY KEY ( `section_id` ) '
-	       . ' )';
-	$database->query($pages);
-
-	require(ADMIN_PATH.'/interface/version.php');
-	
-	// Settings table
-	$settings='CREATE TABLE `'.TABLE_PREFIX.'settings` ( `setting_id` INT NOT NULL auto_increment,'
-		. ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-		. ' `value` TEXT NOT NULL ,'
-		. ' PRIMARY KEY ( `setting_id` ) '
-		. ' )';
-	$database->query($settings);
-
-	$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` "
-	." (name, value) VALUES "
-	." ('wb_version', '".VERSION."'),"
-	." ('website_title', '$website_title'),"
-	." ('website_description', ''),"
-	." ('website_keywords', ''),"
-	." ('website_header', ''),"
-	." ('website_footer', ''),"
-	." ('wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
-	." ('rename_files_on_upload', 'php,asp,phpx,aspx'),"
-	." ('er_level', ''),"
-	." ('default_language', '$default_language'),"
-	." ('app_name', 'wb_$session_rand'),"
-	." ('sec_anchor', 'wb_'),"
-	." ('default_timezone', '$default_timezone'),"
-	." ('default_date_format', 'M d Y'),"
-	." ('default_time_format', 'g:i A'),"
-	." ('redirect_timer', '1500'),"
-	." ('home_folders', 'true'),"
-	." ('warn_page_leave', '1'),"
-	." ('default_template', 'round'),"
-	." ('default_theme', 'wb_theme'),"
-	." ('default_charset', 'utf-8'),"
-	." ('multiple_menus', 'true'),"
-	." ('page_level_limit', '4'),"
-	." ('intro_page', 'false'),"
-	." ('page_trash', 'inline'),"
-	." ('homepage_redirection', 'false'),"
-	." ('page_languages', 'true'),"
-	." ('wysiwyg_editor', 'fckeditor'),"
-	." ('manage_sections', 'true'),"
-	." ('section_blocks', 'true'),"
-	." ('smart_login', 'true'),"
-	." ('frontend_login', 'false'),"
-	." ('frontend_signup', 'false'),"
-	." ('search', 'public'),"
-	." ('page_extension', '.php'),"
-	." ('page_spacer', '-'),"
-	." ('pages_directory', '/pages'),"
-	." ('media_directory', '/media'),"
-	." ('operating_system', '$operating_system'),"
-	." ('string_file_mode', '$file_mode'),"
-	." ('string_dir_mode', '$dir_mode'),"
-	." ('wbmailer_routine', 'phpmail'),"
-	." ('server_email', 'admin@yourdomain.com'),"		// avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
-	." ('wbmailer_default_sendername', 'WB Mailer'),"
-	." ('wbmailer_smtp_host', ''),"
-	." ('wbmailer_smtp_auth', ''),"
-	." ('wbmailer_smtp_username', ''),"
-	." ('wbmailer_smtp_password', ''),"
-	." ('mediasettings', '')";
-	$database->query($settings_rows);
-	
-	// Users table
-	$users = 'CREATE TABLE `'.TABLE_PREFIX.'users` ( `user_id` INT NOT NULL auto_increment,'
-	       . ' `group_id` INT NOT NULL DEFAULT \'0\','
-	       . ' `groups_id` VARCHAR( 255 ) NOT NULL DEFAULT \'0\','
-	       . ' `active` INT NOT NULL DEFAULT \'0\','
-	       . ' `username` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `password` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `remember_key` VARCHAR( 255 ) NOT NULL DEFAULT \'\','
-	       . ' `last_reset` INT NOT NULL DEFAULT \'0\','
-	       . ' `display_name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `email` TEXT NOT NULL ,'
-	       . ' `timezone` INT NOT NULL DEFAULT \'0\','
-	       . ' `date_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `time_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'' .$default_language .'\' ,'
-	       . ' `home_folder` TEXT NOT NULL ,'
-	       . ' `login_when` INT NOT NULL  DEFAULT \'0\','
-	       . ' `login_ip` VARCHAR( 15 ) NOT NULL DEFAULT \'\' ,'
-	       . ' PRIMARY KEY ( `user_id` ) '
-	       . ' )';
-	$database->query($users);
-	
-	// Groups table
-	$groups = 'CREATE TABLE `'.TABLE_PREFIX.'groups` ( `group_id` INT NOT NULL auto_increment,'
-	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	        . ' `system_permissions` TEXT NOT NULL ,'
-	        . ' `module_permissions` TEXT NOT NULL ,'
-	        . ' `template_permissions` TEXT NOT NULL ,'
-	        . ' PRIMARY KEY ( `group_id` ) '
-	        . ' )';
-	$database->query($groups);
-	
-	// Search settings table
-	$search = 'CREATE TABLE `'.TABLE_PREFIX.'search` ( `search_id` INT NOT NULL auto_increment,'
-	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-	        . ' `value` TEXT NOT NULL ,'
-	        . ' `extra` TEXT NOT NULL ,'
-	        . ' PRIMARY KEY ( `search_id` ) '
-	        . ' )';
-	$database->query($search);
-	
-	// Addons table
-	$addons = 'CREATE TABLE `'.TABLE_PREFIX.'addons` ( '
-			.'`addon_id` INT NOT NULL auto_increment ,'
-			.'`type` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-			.'`directory` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-			.'`name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-			.'`description` TEXT NOT NULL ,'
-			.'`function` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-			.'`version` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-			.'`platform` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-			.'`author` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-			.'`license` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
-			.' PRIMARY KEY ( `addon_id` ) '
-			.' )';
-	$database->query($addons);
-
-	// Insert default data
-	
-	// Admin group
-	$full_system_permissions = 'pages,pages_view,pages_add,pages_add_l0,pages_settings,pages_modify,pages_intro,pages_delete,media,media_view,media_upload,media_rename,media_delete,media_create,addons,modules,modules_view,modules_install,modules_uninstall,templates,templates_view,templates_install,templates_uninstall,languages,languages_view,languages_install,languages_uninstall,settings,settings_basic,settings_advanced,access,users,users_view,users_add,users_modify,users_delete,groups,groups_view,groups_add,groups_modify,groups_delete,admintools';
-	$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
-	$database->query($insert_admin_group);
-	// Admin user
-	$insert_admin_user = "INSERT INTO `".TABLE_PREFIX."users` (user_id,group_id,groups_id,active,username,password,email,display_name) VALUES ('1','1','1','1','$admin_username','".md5($admin_password)."','$admin_email','Administrator')";
-	$database->query($insert_admin_user);
-	
-	// Search header
-	$search_header = addslashes('
-<h1>[TEXT_SEARCH]</h1>
-
-<form name="searchpage" action="[WB_URL]/search/index.php" method="get">
-<table cellpadding="3" cellspacing="0" border="0" width="500">
-<tr>
-<td>
-<input type="hidden" name="search_path" value="[SEARCH_PATH]" />
-<input type="text" name="string" value="[SEARCH_STRING]" style="width: 100%;" />
-</td>
-<td width="150">
-<input type="submit" value="[TEXT_SEARCH]" style="width: 100%;" />
-</td>
-</tr>
-<tr>
-<td colspan="2">
-<input type="radio" name="match" id="match_all" value="all"[ALL_CHECKED] />
-<label for="match_all">[TEXT_ALL_WORDS]</label>
-<input type="radio" name="match" id="match_any" value="any"[ANY_CHECKED] />
-<label for="match_any">[TEXT_ANY_WORDS]</label>
-<input type="radio" name="match" id="match_exact" value="exact"[EXACT_CHECKED] />
-<label for="match_exact">[TEXT_EXACT_MATCH]</label>
-</td>
-</tr>
-</table>
-
-</form>
-
-<hr />
-	');
-	$insert_search_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'header', '$search_header', '')";
-	$database->query($insert_search_header);
-	// Search footer
-	$search_footer = addslashes('');
-	$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
-	$database->query($insert_search_footer);
-	// Search results header
-	$search_results_header = addslashes(''.
-'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
-<table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');
-	$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
-	$database->query($insert_search_results_header);
-	// Search results loop
-	$search_results_loop = addslashes(''.
-'<tr style="background-color: #F0F0F0;">
-<td><a href="[LINK]">[TITLE]</a></td>
-<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
-</tr>
-<tr><td colspan="2" style="text-align: justify; padding-bottom: 5px;">[DESCRIPTION]</td></tr>
-<tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[EXCERPT]</td></tr>');
-
-	$insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
-	$database->query($insert_search_results_loop);
-	// Search results footer
-	$search_results_footer = addslashes("</table>");
-	$insert_search_results_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_footer', '$search_results_footer', '')";
-	$database->query($insert_search_results_footer);
-	// Search no results
-	$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
-	$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
-	$database->query($insert_search_no_results);
-	// Search module-order
-	$search_module_order = addslashes('faqbaker,manual,wysiwyg');
-	$insert_search_module_order = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'module_order', '$search_module_order', '')";
-	$database->query($insert_search_module_order);
-	// Search max lines of excerpt
-	$search_max_excerpt = addslashes('15');
-	$insert_search_max_excerpt = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'max_excerpt', '$search_max_excerpt', '')";
-	$database->query($insert_search_max_excerpt);
-	// max time to search per module
-	$search_time_limit = addslashes('0');
-	$insert_search_time_limit = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'time_limit', '$search_time_limit', '')";
-	$database->query($insert_search_time_limit);
-	// some config-elements
-	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_old_search', 'true', '')");
-	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_keywords', 'true', '')");
-	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_description', 'true', '')");
-	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_show_description', 'true', '')");
-	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_flush', 'false', '')");
-	// Search template
-	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
-		
-	require_once(WB_PATH.'/framework/initialize.php');
-	
-	// Include the PclZip class file (thanks to 
-	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
-			
-	// Install add-ons
-	if(file_exists(WB_PATH.'/install/modules')) {
-		// Unpack pre-packaged modules
-			
-	}
-	if(file_exists(WB_PATH.'/install/templates')) {
-		// Unpack pre-packaged templates
-		
-	}
-	if(file_exists(WB_PATH.'/install/languages')) {
-		// Unpack pre-packaged languages
-		
-	}
-	
-	$admin=new admin_dummy();
-	// Load addons into DB
-	$dirs['modules'] = WB_PATH.'/modules/';
-	$dirs['templates'] = WB_PATH.'/templates/';
-	$dirs['languages'] = WB_PATH.'/languages/';
-	foreach($dirs AS $type => $dir) {
-		if($handle = opendir($dir)) {
-			while(false !== ($file = readdir($handle))) {
-				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
-					// Get addon type
-					if($type == 'modules') {
-						load_module($dir.'/'.$file, true);
-						// Pretty ugly hack to let modules run $admin->set_error
-						// See dummy class definition admin_dummy above
-						if ($admin->error!='') {
-							set_error($admin->error);
-						}
-					} elseif($type == 'templates') {
-						load_template($dir.'/'.$file);
-					} elseif($type == 'languages') {
-						load_language($dir.'/'.$file);
-					}
-				}
-			}
-		closedir($handle);
-		}
-	}
-	
-	// Check if there was a database error
-	if($database->is_error()) {
-		set_error($database->get_error());
-	}
-
-// end of if install_tables	
-} else {
-	/**
-	 *	DB - Exists
-	 *	Tables also?
-	 *
-	 */
-	$requested_tables = array("pages","sections","settings","users","groups","search","addons");
-	for($i=0;$i<count($requested_tables);$i++) $requested_tables[$i] = $table_prefix.$requested_tables[$i];
-	
-	$result = mysql_list_tables( DB_NAME );
-	$all_tables = array();
-	for($i=0; $i < mysql_num_rows($result); $i++) $all_tables[] = mysql_table_name($result, $i);
-
-	$missing_tables = array();
-	foreach($requested_tables as $temp_table) {
-		if (!in_array($temp_table, $all_tables)) {
-			$missing_tables[] = $temp_table;
-		}
-	}
-	
-	/**
-	 *	If one or more needed tables are missing, so 
-	 *	we can't go on and have to display an error
-	 */
-	if ( count($missing_tables) > 0 ) {
-		$error_message  = "One or more tables are missing in the selected database <b><font color='#990000'>".DB_NAME."</font></b>.<br />";
-		$error_message .= "Please install the missing tables or choose 'install tables' as recommend.<br />";
-		$error_message .= "Missing tables are: <b>".implode(", ", $missing_tables)."</b>";
-		
-		set_error( $error_message );
-	}
-	
-	/**
-	 *	Try to get some default settings ...
-	 */
-	$vars = array(
-		'DEFAULT_THEME'	=> "wb_theme",
-		'THEME_URL'		=> WB_URL."/templates/wb_theme",
-		'THEME_PATH'	=> WB_PATH."/templates/wb_theme",
-		'LANGUAGE'		=> $_POST['default_language'],
-		'SERVER_EMAIL'	=> "admin@yourdomain.com",
-		'SMART_LOGIN'	=> false
-	);
-	foreach($vars as $k => $v) if (!defined($k)) define($k, $v);
-	
-	if (!isset($MESSAGE)) include (WB_PATH."/languages/".LANGUAGE.".php");
-	
-	/**
-	 *	The important part ...
-	 *	Is there an valid user?
-	 */
-	$result = $database->query("SELECT * from ".$table_prefix."users where username='".$_POST['admin_username']."'");
-	if ( $database->is_error() ) {
-		set_error ($database->get_error() );
-	}
-	if ($result->numRows() == 0) {
-		/**
-		 *	No matches found ... user properly unknown
-	 	 */
-	 	set_error ("Unkown user. Please use a valid username.");
-	} else {
-	 	
-		$data = $result->fetchRow();
-	 	/**
-	 	 *	Does the password match
-	 	 */
-	 	if ( md5($_POST['admin_password']) != $data['password']) {
-	 		set_error ("Password didn't match");
-	 	}
-	}
-}
-// Log the user in and go to Website Baker Administration
-$thisApp = new Login(
-		array(
-				"MAX_ATTEMPS" => "50",
-				"WARNING_URL" => ADMIN_URL."/login/warning.html",
-				"USERNAME_FIELDNAME" => 'admin_username',
-				"PASSWORD_FIELDNAME" => 'admin_password',
-				"REMEMBER_ME_OPTION" => SMART_LOGIN,
-				"MIN_USERNAME_LEN" => "2",
-				"MIN_PASSWORD_LEN" => "2",
-				"MAX_USERNAME_LEN" => "30",
-				"MAX_PASSWORD_LEN" => "30",
-				'LOGIN_URL' => ADMIN_URL."/login/index.php",
-				'DEFAULT_URL' => ADMIN_URL."/start/index.php",
-				'TEMPLATE_DIR' => ADMIN_PATH."/login",
-				'TEMPLATE_FILE' => "template.html",
-				'FRONTEND' => false,
-				'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
-				'USERS_TABLE' => TABLE_PREFIX."users",
-				'GROUPS_TABLE' => TABLE_PREFIX."groups",
-		)
-);
-?>
+<?php
+/**
+ *
+ * @category        backend
+ * @package         install
+ * @author          WebsiteBaker Project
+ * @copyright       2004-2009, Ryan Djurovich
+ * @copyright       2009-2011, Website Baker Org. e.V.
+ * @link			http://www.websitebaker2.org/
+ * @license         http://www.gnu.org/licenses/gpl.html
+ * @platform        WebsiteBaker 2.8.x
+ * @requirements    PHP 5.2.2 and higher
+ * @version      	$Id$
+ * @filesource		$HeadURL:  $
+ * @lastmodified    $Date: $
+ *
+ */
+
+$debug = true;
+
+if (true === $debug) {
+	ini_set('display_errors', 1);
+	error_reporting(E_ALL);
+}
+// Start a session
+if(!defined('SESSION_STARTED')) {
+	session_name('wb_session_id');
+	session_start();
+	define('SESSION_STARTED', true);
+}
+// get random-part for session_name()
+list($usec,$sec) = explode(' ',microtime());
+srand((float)$sec+((float)$usec*100000));
+$session_rand = rand(1000,9999);
+
+// Function to set error
+function set_error($message, $field_name = '') {
+	global $_POST;
+	if(isset($message) AND $message != '') {
+		// Copy values entered into session so user doesn't have to re-enter everything
+		if(isset($_POST['website_title'])) {
+			$_SESSION['wb_url'] = $_POST['wb_url'];
+			$_SESSION['default_timezone'] = $_POST['default_timezone'];
+			$_SESSION['default_language'] = $_POST['default_language'];
+			if(!isset($_POST['operating_system'])) {
+				$_SESSION['operating_system'] = 'linux';
+			} else {
+				$_SESSION['operating_system'] = $_POST['operating_system'];
+			}
+			if(!isset($_POST['world_writeable'])) {
+				$_SESSION['world_writeable'] = false;
+			} else {
+				$_SESSION['world_writeable'] = true;
+			}
+			$_SESSION['database_host'] = $_POST['database_host'];
+			$_SESSION['database_username'] = $_POST['database_username'];
+			$_SESSION['database_password'] = $_POST['database_password'];
+			$_SESSION['database_name'] = $_POST['database_name'];
+			$_SESSION['table_prefix'] = $_POST['table_prefix'];
+			if(!isset($_POST['install_tables'])) {
+				$_SESSION['install_tables'] = false;
+			} else {
+				$_SESSION['install_tables'] = true;
+			}
+			$_SESSION['website_title'] = $_POST['website_title'];
+			$_SESSION['admin_username'] = $_POST['admin_username'];
+			$_SESSION['admin_email'] = $_POST['admin_email'];
+			$_SESSION['admin_password'] = $_POST['admin_password'];
+			$_SESSION['admin_repassword'] = $_POST['admin_repassword'];
+		}
+		// Set the message
+		$_SESSION['message'] = $message;
+		// Set the element(s) to highlight
+		if($field_name != '') {
+			$_SESSION['ERROR_FIELD'] = $field_name;
+		}
+		// Specify that session support is enabled
+		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
+		// Redirect to first page again and exit
+		header('Location: index.php?sessions_checked=true');
+		exit();
+	}
+}
+
+// Dummy class to allow modules' install scripts to call $admin->print_error
+class admin_dummy
+{
+	var $error='';
+	function print_error($message)
+	{
+		$this->error=$message;
+	}
+}
+
+// Function to workout what the default permissions are for files created by the webserver
+function default_file_mode($temp_dir) {
+	$v = explode(".",PHP_VERSION);
+	$v = $v[0].$v[1];
+	if($v > 41 AND is_writable($temp_dir)) {
+		$filename = $temp_dir.'/test_permissions.txt';
+		$handle = fopen($filename, 'w');
+		fwrite($handle, 'This file is to get the default file permissions');
+		fclose($handle);
+		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
+		unlink($filename);
+	} else {
+		$default_file_mode = '0777';
+	}
+	return $default_file_mode;
+}
+
+// Function to workout what the default permissions are for directories created by the webserver
+function default_dir_mode($temp_dir) {
+	$v = explode(".",PHP_VERSION);
+	$v = $v[0].$v[1];
+	if($v > 41 AND is_writable($temp_dir)) {
+		$dirname = $temp_dir.'/test_permissions/';
+		mkdir($dirname);
+		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
+		rmdir($dirname);
+	} else {
+		$default_dir_mode = '0777';
+	}
+	return $default_dir_mode;
+}
+
+function add_slashes($input) {
+	if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
+		return $input;
+	}
+	$output = addslashes($input);
+	return $output;
+}
+
+// Begin check to see if form was even submitted
+// Set error if no post vars found
+if(!isset($_POST['website_title'])) {
+	set_error('Please fill-in the form below');
+}
+// End check to see if form was even submitted
+
+// Begin path and timezone details code
+
+// Check if user has entered the installation url
+if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
+	set_error('Please enter an absolute URL', 'wb_url');
+} else {
+	$wb_url = $_POST['wb_url'];
+}
+// Remove any slashes at the end of the URL
+if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
+	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
+}
+if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
+	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
+}
+if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
+	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
+}
+if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
+	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
+}
+// Get the default time zone
+if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
+	set_error('Please select a valid default timezone', 'default_timezone');
+} else {
+	$default_timezone = $_POST['default_timezone']*60*60;
+}
+// End path and timezone details code
+
+// Get the default language
+$allowed_languages = array('BG','CA', 'CS', 'DA', 'DE', 'EN', 'ES', 'ET', 'FI', 'FR', 'HR', 'HU', 'IT', 'LV', 'NL', 'NO', 'PL', 'PT', 'RU','SE','SK','TR');
+if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
+	set_error('Please select a valid default backend language','default_language');
+} else {
+	$default_language = $_POST['default_language'];
+	// make sure the selected language file exists in the language folder
+	if(!file_exists('../languages/' .$default_language .'.php')) {
+		set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language','default_language');
+	}
+}
+// End default language details code
+
+// Begin operating system specific code
+// Get operating system
+if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
+	set_error('Please select a valid operating system');
+} else {
+	$operating_system = $_POST['operating_system'];
+}
+// Work-out file permissions
+if($operating_system == 'windows') {
+	$file_mode = '0777';
+	$dir_mode = '0777';
+} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
+	$file_mode = '0777';
+	$dir_mode = '0777';
+} else {
+	$file_mode = default_file_mode('../temp');
+	$dir_mode = default_dir_mode('../temp');
+}
+// End operating system specific code
+
+// Begin database details code
+// Check if user has entered a database host
+if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
+	set_error('Please enter a database host name', 'database_host');
+} else {
+	$database_host = $_POST['database_host'];
+}
+// Check if user has entered a database username
+if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
+	set_error('Please enter a database username','database_username');
+} else {
+	$database_username = $_POST['database_username'];
+}
+// Check if user has entered a database password
+if(!isset($_POST['database_password'])) {
+	set_error('Please enter a database password', 'database_password');
+} else {
+	$database_password = $_POST['database_password'];
+}
+// Check if user has entered a database name
+if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
+	set_error('Please enter a database name', 'database_name');
+} else {
+	// make sure only allowed characters are specified
+	if(preg_match('/[^a-z0-9_-]+/i', $_POST['database_name'])) {
+		// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
+		set_error('Only characters a-z, A-Z, 0-9, - and _ allowed in database name.', 'database_name');
+	}
+	$database_name = $_POST['database_name'];
+}
+// Get table prefix
+if(preg_match('/[^a-z0-9_]+/i', $_POST['table_prefix'])) {
+	// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
+	set_error('Only characters a-z, A-Z, 0-9 and _ allowed in table_prefix.', 'table_prefix');
+} else {
+	$table_prefix = $_POST['table_prefix'];
+}
+
+// Find out if the user wants to install tables and data
+if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
+	$install_tables = true;
+} else {
+	$install_tables = false;
+}
+// End database details code
+
+// Begin website title code
+// Get website title
+if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
+	set_error('Please enter a website title', 'website_title');
+} else {
+	$website_title = add_slashes($_POST['website_title']);
+}
+// End website title code
+
+// Begin admin user details code
+// Get admin username
+if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
+	set_error('Please enter a username for the Administrator account','admin_username');
+} else {
+	$admin_username = $_POST['admin_username'];
+}
+// Get admin email and validate it
+if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
+	set_error('Please enter an email for the Administrator account','admin_email');
+} else {
+	if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i', $_POST['admin_email'])) {
+		$admin_email = $_POST['admin_email'];
+	} else {
+		set_error('Please enter a valid email address for the Administrator account','admin_email');
+	}
+}
+// Get the two admin passwords entered, and check that they match
+if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
+	set_error('Please enter a password for the Administrator account','admin_password');
+} else {
+	$admin_password = $_POST['admin_password'];
+}
+if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
+	set_error('Please make sure you re-enter the password for the Administrator account','admin_repassword');
+} else {
+	$admin_repassword = $_POST['admin_repassword'];
+}
+if($admin_password != $admin_repassword) {
+	set_error('Sorry, the two Administrator account passwords you entered do not match','admin_repassword');
+}
+// End admin user details code
+
+// Try and write settings to config file
+$config_content = "" .
+"<?php\n".
+"\n".
+"define('DB_TYPE', 'mysql');\n".
+"define('DB_HOST', '$database_host');\n".
+"define('DB_USERNAME', '$database_username');\n".
+"define('DB_PASSWORD', '$database_password');\n".
+"define('DB_NAME', '$database_name');\n".
+"define('TABLE_PREFIX', '$table_prefix');\n".
+"\n".
+"define('WB_PATH', dirname(__FILE__));\n".
+"define('WB_URL', '$wb_url');\n".
+"define('ADMIN_PATH', WB_PATH.'/admin');\n".
+"define('ADMIN_URL', '$wb_url/admin');\n".
+"\n".
+"require_once(WB_PATH.'/framework/initialize.php');\n".
+"\n".
+"?>";
+
+$config_filename = '../config.php';
+
+// Check if the file exists and is writable first.
+if(file_exists($config_filename) AND is_writable($config_filename)) {
+	if(!$handle = fopen($config_filename, 'w')) {
+		set_error("Cannot open the configuration file ($config_filename)");
+	} else {
+		if (fwrite($handle, $config_content) === FALSE) {
+			set_error("Cannot write to the configuration file ($config_filename)");
+		}
+		// Close file
+		fclose($handle);
+	}
+} else {
+	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
+}
+
+// Define configuration vars
+define('DB_TYPE', 'mysql');
+define('DB_HOST', $database_host);
+define('DB_USERNAME', $database_username);
+define('DB_PASSWORD', $database_password);
+define('DB_NAME', $database_name);
+define('TABLE_PREFIX', $table_prefix);
+define('WB_PATH', str_replace(array('/install','\install'), '',dirname(__FILE__)));
+define('WB_URL', $wb_url);
+define('ADMIN_PATH', WB_PATH.'/admin');
+define('ADMIN_URL', $wb_url.'/admin');
+
+// Check if the user has entered a correct path
+if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
+	set_error('It appears the Absolute path that you entered is incorrect');
+}
+
+// Try connecting to database	
+if(!@mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
+	set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
+}
+
+// Try to create the database
+mysql_query('CREATE DATABASE `'.$database_name.'`');
+
+// Close the mysql connection
+mysql_close();
+
+// Include WB functions file
+require_once(WB_PATH.'/framework/functions.php');
+
+// Re-connect to the database, this time using in-build database class
+require_once(WB_PATH.'/framework/class.login.php');
+$database=new database();
+
+// Check if we should install tables
+if($install_tables == true) {
+	if (!defined('WB_INSTALL_PROCESS')) define ('WB_INSTALL_PROCESS', true);
+	// Remove tables if they exist
+
+	// Pages table
+	$pages = "DROP TABLE IF EXISTS `".TABLE_PREFIX."pages`";
+	$database->query($pages);
+	// Sections table
+	$sections = "DROP TABLE IF EXISTS `".TABLE_PREFIX."sections`";
+	$database->query($sections);
+	// Settings table
+	$settings = "DROP TABLE IF EXISTS `".TABLE_PREFIX."settings`";
+	$database->query($settings);
+	// Users table
+	$users = "DROP TABLE IF EXISTS `".TABLE_PREFIX."users`";
+	$database->query($users);
+	// Groups table
+	$groups = "DROP TABLE IF EXISTS `".TABLE_PREFIX."groups`";
+	$database->query($groups);
+	// Search table
+	$search = "DROP TABLE IF EXISTS `".TABLE_PREFIX."search`";
+	$database->query($search);
+	// Addons table
+	$addons = "DROP TABLE IF EXISTS `".TABLE_PREFIX."addons`";
+	$database->query($addons);
+				
+	// Try installing tables
+	
+	// Pages table
+	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,'
+	       . ' `parent` INT NOT NULL DEFAULT \'0\','
+	       . ' `root_parent` INT NOT NULL DEFAULT \'0\','
+	       . ' `level` INT NOT NULL DEFAULT \'0\','
+	       . ' `link` TEXT NOT NULL,'
+	       . ' `target` VARCHAR( 7 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `page_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `menu_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `description` TEXT NOT NULL ,'
+	       . ' `keywords` TEXT NOT NULL ,'
+	       . ' `page_trail` TEXT NOT NULL  ,'
+	       . ' `template` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `visibility` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `position` INT NOT NULL DEFAULT \'0\','
+	       . ' `menu` INT NOT NULL DEFAULT \'0\','
+	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `searching` INT NOT NULL DEFAULT \'0\','
+	       . ' `admin_groups` TEXT NOT NULL ,'
+	       . ' `admin_users` TEXT NOT NULL ,'
+	       . ' `viewing_groups` TEXT NOT NULL ,'
+	       . ' `viewing_users` TEXT NOT NULL ,'
+	       . ' `modified_when` INT NOT NULL DEFAULT \'0\','
+	       . ' `modified_by` INT NOT NULL  DEFAULT \'0\','
+	       . ' PRIMARY KEY ( `page_id` ) '
+	       . ' )';
+	$database->query($pages);
+	
+	// Sections table
+	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'
+	       . ' `page_id` INT NOT NULL DEFAULT \'0\','
+	       . ' `position` INT NOT NULL DEFAULT \'0\','
+	       . ' `module` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `block` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `publ_start` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
+	       . ' `publ_end` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,' 
+	       . ' PRIMARY KEY ( `section_id` ) '
+	       . ' )';
+	$database->query($pages);
+
+	require(ADMIN_PATH.'/interface/version.php');
+	
+	// Settings table
+	$settings='CREATE TABLE `'.TABLE_PREFIX.'settings` ( `setting_id` INT NOT NULL auto_increment,'
+		. ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+		. ' `value` TEXT NOT NULL ,'
+		. ' PRIMARY KEY ( `setting_id` ) '
+		. ' )';
+	$database->query($settings);
+
+	$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` "
+	." (name, value) VALUES "
+	." ('wb_version', '".VERSION."'),"
+	." ('website_title', '$website_title'),"
+	." ('website_description', ''),"
+	." ('website_keywords', ''),"
+	." ('website_header', ''),"
+	." ('website_footer', ''),"
+	." ('wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
+	." ('rename_files_on_upload', 'php,asp,phpx,aspx'),"
+	." ('er_level', ''),"
+	." ('default_language', '$default_language'),"
+	." ('app_name', 'wb_$session_rand'),"
+	." ('sec_anchor', 'wb_'),"
+	." ('default_timezone', '$default_timezone'),"
+	." ('default_date_format', 'M d Y'),"
+	." ('default_time_format', 'g:i A'),"
+	." ('redirect_timer', '1500'),"
+	." ('home_folders', 'true'),"
+	." ('warn_page_leave', '1'),"
+	." ('default_template', 'round'),"
+	." ('default_theme', 'wb_theme'),"
+	." ('default_charset', 'utf-8'),"
+	." ('multiple_menus', 'true'),"
+	." ('page_level_limit', '4'),"
+	." ('intro_page', 'false'),"
+	." ('page_trash', 'inline'),"
+	." ('homepage_redirection', 'false'),"
+	." ('page_languages', 'true'),"
+	." ('wysiwyg_editor', 'fckeditor'),"
+	." ('manage_sections', 'true'),"
+	." ('section_blocks', 'true'),"
+	." ('smart_login', 'true'),"
+	." ('frontend_login', 'false'),"
+	." ('frontend_signup', 'false'),"
+	." ('search', 'public'),"
+	." ('page_extension', '.php'),"
+	." ('page_spacer', '-'),"
+	." ('pages_directory', '/pages'),"
+	." ('media_directory', '/media'),"
+	." ('operating_system', '$operating_system'),"
+	." ('string_file_mode', '$file_mode'),"
+	." ('string_dir_mode', '$dir_mode'),"
+	." ('wbmailer_routine', 'phpmail'),"
+	." ('server_email', 'admin@yourdomain.com'),"		// avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
+	." ('wbmailer_default_sendername', 'WB Mailer'),"
+	." ('wbmailer_smtp_host', ''),"
+	." ('wbmailer_smtp_auth', ''),"
+	." ('wbmailer_smtp_username', ''),"
+	." ('wbmailer_smtp_password', ''),"
+	." ('fingerprint_with_ip_octets', '3'),"
+	." ('mediasettings', '')";
+	$database->query($settings_rows);
+	
+	// Users table
+	$users = 'CREATE TABLE `'.TABLE_PREFIX.'users` ( `user_id` INT NOT NULL auto_increment,'
+	       . ' `group_id` INT NOT NULL DEFAULT \'0\','
+	       . ' `groups_id` VARCHAR( 255 ) NOT NULL DEFAULT \'0\','
+	       . ' `active` INT NOT NULL DEFAULT \'0\','
+	       . ' `username` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `password` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `remember_key` VARCHAR( 255 ) NOT NULL DEFAULT \'\','
+	       . ' `last_reset` INT NOT NULL DEFAULT \'0\','
+	       . ' `display_name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `email` TEXT NOT NULL ,'
+	       . ' `timezone` INT NOT NULL DEFAULT \'0\','
+	       . ' `date_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `time_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'' .$default_language .'\' ,'
+	       . ' `home_folder` TEXT NOT NULL ,'
+	       . ' `login_when` INT NOT NULL  DEFAULT \'0\','
+	       . ' `login_ip` VARCHAR( 15 ) NOT NULL DEFAULT \'\' ,'
+	       . ' PRIMARY KEY ( `user_id` ) '
+	       . ' )';
+	$database->query($users);
+	
+	// Groups table
+	$groups = 'CREATE TABLE `'.TABLE_PREFIX.'groups` ( `group_id` INT NOT NULL auto_increment,'
+	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	        . ' `system_permissions` TEXT NOT NULL ,'
+	        . ' `module_permissions` TEXT NOT NULL ,'
+	        . ' `template_permissions` TEXT NOT NULL ,'
+	        . ' PRIMARY KEY ( `group_id` ) '
+	        . ' )';
+	$database->query($groups);
+	
+	// Search settings table
+	$search = 'CREATE TABLE `'.TABLE_PREFIX.'search` ( `search_id` INT NOT NULL auto_increment,'
+	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+	        . ' `value` TEXT NOT NULL ,'
+	        . ' `extra` TEXT NOT NULL ,'
+	        . ' PRIMARY KEY ( `search_id` ) '
+	        . ' )';
+	$database->query($search);
+	
+	// Addons table
+	$addons = 'CREATE TABLE `'.TABLE_PREFIX.'addons` ( '
+			.'`addon_id` INT NOT NULL auto_increment ,'
+			.'`type` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+			.'`directory` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+			.'`name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+			.'`description` TEXT NOT NULL ,'
+			.'`function` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+			.'`version` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+			.'`platform` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+			.'`author` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+			.'`license` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
+			.' PRIMARY KEY ( `addon_id` ) '
+			.' )';
+	$database->query($addons);
+
+	// Insert default data
+	
+	// Admin group
+	$full_system_permissions = 'pages,pages_view,pages_add,pages_add_l0,pages_settings,pages_modify,pages_intro,pages_delete,media,media_view,media_upload,media_rename,media_delete,media_create,addons,modules,modules_view,modules_install,modules_uninstall,templates,templates_view,templates_install,templates_uninstall,languages,languages_view,languages_install,languages_uninstall,settings,settings_basic,settings_advanced,access,users,users_view,users_add,users_modify,users_delete,groups,groups_view,groups_add,groups_modify,groups_delete,admintools';
+	$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
+	$database->query($insert_admin_group);
+	// Admin user
+	$insert_admin_user = "INSERT INTO `".TABLE_PREFIX."users` (user_id,group_id,groups_id,active,username,password,email,display_name) VALUES ('1','1','1','1','$admin_username','".md5($admin_password)."','$admin_email','Administrator')";
+	$database->query($insert_admin_user);
+	
+	// Search header
+	$search_header = addslashes('
+<h1>[TEXT_SEARCH]</h1>
+
+<form name="searchpage" action="[WB_URL]/search/index.php" method="get">
+<table cellpadding="3" cellspacing="0" border="0" width="500">
+<tr>
+<td>
+<input type="hidden" name="search_path" value="[SEARCH_PATH]" />
+<input type="text" name="string" value="[SEARCH_STRING]" style="width: 100%;" />
+</td>
+<td width="150">
+<input type="submit" value="[TEXT_SEARCH]" style="width: 100%;" />
+</td>
+</tr>
+<tr>
+<td colspan="2">
+<input type="radio" name="match" id="match_all" value="all"[ALL_CHECKED] />
+<label for="match_all">[TEXT_ALL_WORDS]</label>
+<input type="radio" name="match" id="match_any" value="any"[ANY_CHECKED] />
+<label for="match_any">[TEXT_ANY_WORDS]</label>
+<input type="radio" name="match" id="match_exact" value="exact"[EXACT_CHECKED] />
+<label for="match_exact">[TEXT_EXACT_MATCH]</label>
+</td>
+</tr>
+</table>
+
+</form>
+
+<hr />
+	');
+	$insert_search_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'header', '$search_header', '')";
+	$database->query($insert_search_header);
+	// Search footer
+	$search_footer = addslashes('');
+	$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
+	$database->query($insert_search_footer);
+	// Search results header
+	$search_results_header = addslashes(''.
+'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
+<table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');
+	$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
+	$database->query($insert_search_results_header);
+	// Search results loop
+	$search_results_loop = addslashes(''.
+'<tr style="background-color: #F0F0F0;">
+<td><a href="[LINK]">[TITLE]</a></td>
+<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
+</tr>
+<tr><td colspan="2" style="text-align: justify; padding-bottom: 5px;">[DESCRIPTION]</td></tr>
+<tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[EXCERPT]</td></tr>');
+
+	$insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
+	$database->query($insert_search_results_loop);
+	// Search results footer
+	$search_results_footer = addslashes("</table>");
+	$insert_search_results_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_footer', '$search_results_footer', '')";
+	$database->query($insert_search_results_footer);
+	// Search no results
+	$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
+	$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
+	$database->query($insert_search_no_results);
+	// Search module-order
+	$search_module_order = addslashes('faqbaker,manual,wysiwyg');
+	$insert_search_module_order = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'module_order', '$search_module_order', '')";
+	$database->query($insert_search_module_order);
+	// Search max lines of excerpt
+	$search_max_excerpt = addslashes('15');
+	$insert_search_max_excerpt = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'max_excerpt', '$search_max_excerpt', '')";
+	$database->query($insert_search_max_excerpt);
+	// max time to search per module
+	$search_time_limit = addslashes('0');
+	$insert_search_time_limit = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'time_limit', '$search_time_limit', '')";
+	$database->query($insert_search_time_limit);
+	// some config-elements
+	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_old_search', 'true', '')");
+	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_keywords', 'true', '')");
+	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_description', 'true', '')");
+	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_show_description', 'true', '')");
+	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_flush', 'false', '')");
+	// Search template
+	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
+		
+	require_once(WB_PATH.'/framework/initialize.php');
+	
+	// Include the PclZip class file (thanks to 
+	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
+			
+	// Install add-ons
+	if(file_exists(WB_PATH.'/install/modules')) {
+		// Unpack pre-packaged modules
+			
+	}
+	if(file_exists(WB_PATH.'/install/templates')) {
+		// Unpack pre-packaged templates
+		
+	}
+	if(file_exists(WB_PATH.'/install/languages')) {
+		// Unpack pre-packaged languages
+		
+	}
+	
+	$admin=new admin_dummy();
+	// Load addons into DB
+	$dirs['modules'] = WB_PATH.'/modules/';
+	$dirs['templates'] = WB_PATH.'/templates/';
+	$dirs['languages'] = WB_PATH.'/languages/';
+	foreach($dirs AS $type => $dir) {
+		if($handle = opendir($dir)) {
+			while(false !== ($file = readdir($handle))) {
+				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
+					// Get addon type
+					if($type == 'modules') {
+						load_module($dir.'/'.$file, true);
+						// Pretty ugly hack to let modules run $admin->set_error
+						// See dummy class definition admin_dummy above
+						if ($admin->error!='') {
+							set_error($admin->error);
+						}
+					} elseif($type == 'templates') {
+						load_template($dir.'/'.$file);
+					} elseif($type == 'languages') {
+						load_language($dir.'/'.$file);
+					}
+				}
+			}
+		closedir($handle);
+		}
+	}
+	
+	// Check if there was a database error
+	if($database->is_error()) {
+		set_error($database->get_error());
+	}
+
+// end of if install_tables	
+} else {
+	/**
+	 *	DB - Exists
+	 *	Tables also?
+	 *
+	 */
+	$requested_tables = array("pages","sections","settings","users","groups","search","addons");
+	for($i=0;$i<count($requested_tables);$i++) $requested_tables[$i] = $table_prefix.$requested_tables[$i];
+	
+	$result = mysql_list_tables( DB_NAME );
+	$all_tables = array();
+	for($i=0; $i < mysql_num_rows($result); $i++) $all_tables[] = mysql_table_name($result, $i);
+
+	$missing_tables = array();
+	foreach($requested_tables as $temp_table) {
+		if (!in_array($temp_table, $all_tables)) {
+			$missing_tables[] = $temp_table;
+		}
+	}
+	
+	/**
+	 *	If one or more needed tables are missing, so 
+	 *	we can't go on and have to display an error
+	 */
+	if ( count($missing_tables) > 0 ) {
+		$error_message  = "One or more tables are missing in the selected database <b><font color='#990000'>".DB_NAME."</font></b>.<br />";
+		$error_message .= "Please install the missing tables or choose 'install tables' as recommend.<br />";
+		$error_message .= "Missing tables are: <b>".implode(", ", $missing_tables)."</b>";
+		
+		set_error( $error_message );
+	}
+	
+	/**
+	 *	Try to get some default settings ...
+	 */
+	$vars = array(
+		'DEFAULT_THEME'	=> "wb_theme",
+		'THEME_URL'		=> WB_URL."/templates/wb_theme",
+		'THEME_PATH'	=> WB_PATH."/templates/wb_theme",
+		'LANGUAGE'		=> $_POST['default_language'],
+		'SERVER_EMAIL'	=> "admin@yourdomain.com",
+		'SMART_LOGIN'	=> false
+	);
+	foreach($vars as $k => $v) if (!defined($k)) define($k, $v);
+	
+	if (!isset($MESSAGE)) include (WB_PATH."/languages/".LANGUAGE.".php");
+	
+	/**
+	 *	The important part ...
+	 *	Is there an valid user?
+	 */
+	$result = $database->query("SELECT * from ".$table_prefix."users where username='".$_POST['admin_username']."'");
+	if ( $database->is_error() ) {
+		set_error ($database->get_error() );
+	}
+	if ($result->numRows() == 0) {
+		/**
+		 *	No matches found ... user properly unknown
+	 	 */
+	 	set_error ("Unkown user. Please use a valid username.");
+	} else {
+	 	
+		$data = $result->fetchRow();
+	 	/**
+	 	 *	Does the password match
+	 	 */
+	 	if ( md5($_POST['admin_password']) != $data['password']) {
+	 		set_error ("Password didn't match");
+	 	}
+	}
+}
+// Log the user in and go to Website Baker Administration
+$thisApp = new Login(
+		array(
+				"MAX_ATTEMPS" => "50",
+				"WARNING_URL" => ADMIN_URL."/login/warning.html",
+				"USERNAME_FIELDNAME" => 'admin_username',
+				"PASSWORD_FIELDNAME" => 'admin_password',
+				"REMEMBER_ME_OPTION" => SMART_LOGIN,
+				"MIN_USERNAME_LEN" => "2",
+				"MIN_PASSWORD_LEN" => "2",
+				"MAX_USERNAME_LEN" => "30",
+				"MAX_PASSWORD_LEN" => "30",
+				'LOGIN_URL' => ADMIN_URL."/login/index.php",
+				'DEFAULT_URL' => ADMIN_URL."/start/index.php",
+				'TEMPLATE_DIR' => ADMIN_PATH."/login",
+				'TEMPLATE_FILE' => "template.html",
+				'FRONTEND' => false,
+				'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
+				'USERS_TABLE' => TABLE_PREFIX."users",
+				'GROUPS_TABLE' => TABLE_PREFIX."groups",
+		)
+);
+?>
