/* Initialize DB schema with defaults. */ if (!defined("PSYCHOSTATS_INSTALL_PAGE")) { die("Unauthorized access to " . basename(__FILE__)); } // we need to raise the memory limit, since the defaults.sql file will require more than 8MB // and some systems will default to 8MB. @ini_set('memory_limit', '128M'); $validfields = array('gametype', 'modtype', 'overwrite', 'dropdb'); $cms->theme->assign_request_vars($validfields, true); $gametypes = array('cod' => "Call of Duty", 'halflife' => "Half-Life", 'soldat' => "Soldat"); $modtypes = array('cstrike' => "Counter Strike", 'dod' => "Day of Defeat", 'hldm' => "Deathmatch (valve)", 'gungame' => "Gungame", 'natural' => "Natural Selection", 'tf2' => "Team Fortress 2"); $gamesupport = array('halflife' => array('cstrike', 'dod', 'gungame', 'hldm', 'natural', 'tf2'), 'cod' => array(), 'soldat' => array()); // make DB connection load_db_opts(); $db->config(array('dbhost' => $dbhost, 'dbport' => $dbport, 'dbname' => $dbname, 'dbuser' => $dbuser, 'dbpass' => $dbpass, 'dbtblprefix' => $dbtblprefix)); $db->clear_errors(); $db->connect(); if (!$db->connected) { if ($ajax_request) { print "<script type='text/javascript'>window.location = 'go.php?s=db&re=1&install=" . urlencode($install) . "';</script>"; exit; } else { gotopage("go.php?s=db&re=1&install=" . urlencode($install)); } } $allow_next = false; $db_init = false; $errors = array(); $actions = array();
function do_test(&$t, $skip_create = false) { global $cms, $db, $min_db_version, $allow_next, $conf; global $dbhost, $dbport, $dbname, $dbuser, $dbpass, $dbtblprefix; load_db_opts($conf); $db->config(array('dbhost' => $dbhost, 'dbport' => $dbport, 'dbname' => $dbname, 'dbuser' => $dbuser, 'dbpass' => $dbpass, 'dbtblprefix' => $dbtblprefix)); $db->clear_errors(); $t['tested'] = true; $t['type'] = $db->type(); $db->connect(true); $t['connected'] = $db->connected; $t['selected'] = $db->selected; if ($db->connected) { $db_version = $db->version(); $t['db_ver'] = $db_version; $t['min_ver'] = version_compare($min_db_version, $db_version) < 1; } // don't bother doing any more tests if the DB version is too low // if (!$t['min_ver']) return false; // the dbname was invalid, so lets try and create it... if (!$t['selected']) { if ($db->dbexists($db->dbname)) { $t['exists'] = true; } else { if (!$skip_create and $db->createdb($db->dbname, "DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci")) { array_pop($db->errors); $t['created'] = true; } } if ($t['exists'] || $t['created']) { $t['selected'] = $db->selectdb(); } } else { $t['exists'] = true; } // make sure the database charset is 'utf8'. // We won't try to alter the DB if its not since that might mess up existing databases. if (version_compare('5.0', $db->version()) < 1) { $db2 = $db->copy(); $db2->selectdb('information_schema'); list($charset) = $db2->fetch_list("SELECT DEFAULT_CHARACTER_SET_NAME FROM SCHEMATA WHERE SCHEMA_NAME=" . $db->escape($db->dbname, true)); $t['charset'] = $charset == 'utf8'; $t['charset_str'] = $charset; unset($db2); $db->selectdb(); // both DB objects will be using the same DB resource, so change the DB back. } else { list($x, $str) = $db->fetch_row(0, "SHOW CREATE DATABASE " . $db->qi($db->dbname)); if (preg_match('/CHARACTER SETs (\\S+)/', $str, $m)) { $t['charset'] = $m[1] == 'utf8'; $t['charset_str'] = $m[1]; } else { // do not do anything if we can't determine the charset. Incase there is a difference in // other mysql versions that I do not know about. We'll just silently ignore this. $t['charset'] = true; } } // perform some privilege tests on the database // the user must be able to create tables, select, insert and update if ($t['selected']) { $tbl = $db->dbtblprefix . 'test_' . substr(md5(uniqid(rand(), true)), 0, 8); $t['table'] = $tbl; $t['tbl_create'] = $db->query("CREATE TABLE " . $db->qi($tbl) . " ( id INT UNSIGNED NOT NULL ) " . "ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci "); if ($t['tbl_create']) { // attempt an insert $t['tbl_insert'] = $db->insert($tbl, array('id' => 1)); $t['tbl_update'] = $db->update($tbl, array('id' => 2), 'id', 1); $t['tbl_select'] = $db->query("SELECT id FROM " . $db->qi($tbl) . " LIMIT 1") != false; $t['tbl_delete'] = $db->delete($tbl, 'id', 2); $t['tbl_drop'] = $db->droptable($tbl); } } // determine if we're able to go NEXT. Remove test results that are not actual errors first. $err = $t; unset($err['charset'], $err['charset_str'], $err['tbl_drop'], $err['table']); $false = array_search(false, $err, true); $allow_next = !$false; }