Index: trunk/CHANGELOG
===================================================================
--- trunk/CHANGELOG	(revision 986)
+++ trunk/CHANGELOG	(revision 987)
@@ -11,6 +11,14 @@
 ! = Update/Change
 
 ------------------------------------- 2.8.0 -------------------------------------
+14-June-2009 Dietrich Roland Pehlke (aldus)
+# Bugfixes for (ticket #728)
++ Add additional constant to "install/save.php" to avoid conflikts during
+	installation inside "/framework/initialize.php".
++ Add condition inside "/framework/initialize.php" to avoid conflikts
+	during installation; table "mod_captcha_control" doesn't exsits at runtime.
++ Add test for tables inside "install/save.php" if the user uncheck "install table" option.
++ Additional Errormessage if nessesary tables are not found (english).
 13-jun-2009 Matthias Gallas
 +	Added jQuery-insert.js and jQuery plugins (Thanks to Luisehahne)
 !	Moved images in lQuery plugins folder (Thanks to Luisehahne)
Index: trunk/wb/framework/initialize.php
===================================================================
--- trunk/wb/framework/initialize.php	(revision 986)
+++ trunk/wb/framework/initialize.php	(revision 987)
@@ -51,21 +51,22 @@
 	$string_dir_mode = STRING_DIR_MODE;
 	define('OCTAL_DIR_MODE',(int) octdec($string_dir_mode));
 	
-	// get CAPTCHA and ASP settings
-	$table = TABLE_PREFIX.'mod_captcha_control';
-	if($get_settings = $database->query("SELECT * FROM $table LIMIT 1")) {
-		if($get_settings->numRows() == 0) { die("CAPTCHA-Settings not found"); }
-		$setting = $get_settings->fetchRow();
-		if($setting['enabled_captcha'] == '1') define('ENABLED_CAPTCHA', true);
-		else define('ENABLED_CAPTCHA', false);
-		if($setting['enabled_asp'] == '1') define('ENABLED_ASP', true);
-		else define('ENABLED_ASP', false);
-		define('CAPTCHA_TYPE', $setting['captcha_type']);
-		define('ASP_SESSION_MIN_AGE', (int)$setting['asp_session_min_age']);
-		define('ASP_VIEW_MIN_AGE', (int)$setting['asp_view_min_age']);
-		define('ASP_INPUT_MIN_AGE', (int)$setting['asp_input_min_age']);
+	if (!defined("WB_INSTALL_PROCESS")) {
+		// get CAPTCHA and ASP settings
+		$table = TABLE_PREFIX.'mod_captcha_control';
+		if($get_settings = $database->query("SELECT * FROM $table LIMIT 1")) {
+			if($get_settings->numRows() == 0) { die("CAPTCHA-Settings not found"); }
+			$setting = $get_settings->fetchRow();
+			if($setting['enabled_captcha'] == '1') define('ENABLED_CAPTCHA', true);
+			else define('ENABLED_CAPTCHA', false);
+			if($setting['enabled_asp'] == '1') define('ENABLED_ASP', true);
+			else define('ENABLED_ASP', false);
+			define('CAPTCHA_TYPE', $setting['captcha_type']);
+			define('ASP_SESSION_MIN_AGE', (int)$setting['asp_session_min_age']);
+			define('ASP_VIEW_MIN_AGE', (int)$setting['asp_view_min_age']);
+			define('ASP_INPUT_MIN_AGE', (int)$setting['asp_input_min_age']);
+		}
 	}
-
 	// set error-reporting
 	if(is_numeric(ER_LEVEL)) {
 		error_reporting(ER_LEVEL);
Index: trunk/wb/install/save.php
===================================================================
--- trunk/wb/install/save.php	(revision 986)
+++ trunk/wb/install/save.php	(revision 987)
@@ -22,7 +22,12 @@
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 */
+$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');
@@ -126,12 +131,12 @@
 }
 
 function add_slashes($input) {
-		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
-			return $input;
-		}
-		$output = addslashes($input);
-		return $output;
+	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
@@ -364,7 +369,7 @@
 
 // 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
@@ -693,29 +698,99 @@
 	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",
-							)
-					);
+		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",
+		)
+);
 ?>
