Index: trunk/admin/install/install_lib.php =================================================================== diff -u -r41 -r78 --- trunk/admin/install/install_lib.php (.../install_lib.php) (revision 41) +++ trunk/admin/install/install_lib.php (.../install_lib.php) (revision 78) @@ -501,4 +501,90 @@ echo $ret; } +function &VerifyDB($error_state, $next_state, $success_func = null, $db_must_exist = false) +{ + // perform various check type to database specified + // 1. user is allowed to connect to database + // 2. user has all types of permissions in database + global $state, $db_error; + + // enshure we use data from post & not from config + $GLOBALS['g_DBType'] = $_POST["ServerType"]; + $GLOBALS['g_DBHost'] = $_POST["ServerHost"]; + $GLOBALS['g_DBName'] = $_POST["ServerDB"]; + $GLOBALS['g_DBUser'] = $_POST["ServerUser"]; + $GLOBALS['g_DBUserPassword'] = $_POST["ServerPass"]; + + // connect to database + $ado = inst_GetADODBConnection(); + if($ado->ErrorNo() != 0) + { + // was error while connecting + $db_error = "Connection Error: (".$ado->ErrorNo().") ".$ado->ErrorMsg(); + $state = $error_state; + + } + elseif( $ado->ErrorNo() == 0 ) + { + // if connected, then check if all sql statements work + $test_result = 1; + + $sql_tests[] = 'DROP TABLE IF EXISTS test_table'; + $sql_tests[] = 'CREATE TABLE test_table(test_col mediumint(6))'; + $sql_tests[] = 'INSERT INTO test_table(test_col) VALUES (5)'; + $sql_tests[] = 'UPDATE test_table SET test_col = 12'; + $sql_tests[] = 'ALTER TABLE test_table ADD COLUMN new_col varchar(10)'; + $sql_tests[] = 'SELECT * FROM test_table'; + $sql_tests[] = 'DELETE FROM test_table'; + $sql_tests[] = 'DROP TABLE test_table'; + + foreach($sql_tests as $sql_test) + { + $ado->Execute($sql_test); + if( $ado->ErrorNo()!=0 ) + { + $test_result = 0; + break; + } + } + + if($test_result == 1) + { + // if statements work & connection made, then check table existance + $db_exists = TableExists($ado,"ConfigurationAdmin,Category,Permissions"); + if($db_exists != $db_must_exist) + { + $state = $error_state; + $db_error = $db_must_exist ? 'An In-Portal Database already exists at this location' : 'An In-Portal Database was not found at this location'; + } + else + { + $state = $next_state; + if( isset($success_func) ) $success_func(); + } + } + else + { + // user has insufficient permissions in database specified + $db_error = "Permission Error: (".$ado->ErrorNo().") ".$ado->ErrorMsg(); + $state = $error_state; + } + } + return $ado; +} + +function SaveDBConfig() +{ + // save new database configuration + echo "in_ere"; + set_ini_value("Database", "DBType",$_POST["ServerType"]); + set_ini_value("Database", "DBHost",$_POST["ServerHost"]); + set_ini_value("Database", "DBName",$_POST["ServerDB"]); + set_ini_value("Database", "DBUser",$_POST["ServerUser"]); + set_ini_value("Database", "DBUserPassword",$_POST["ServerPass"]); + set_ini_value("Database","TablePrefix",$_POST["TablePrefix"]); + save_values(); + $GLOBALS['include_file'] = 'install/install_finish.php'; +} + ?>