if (!$_POST['sql']) { $_REQUEST['act'] = 'main'; } /*------------------------------------------------------ */ //-- 用户帐号列表 /*------------------------------------------------------ */ if ($_REQUEST['act'] == 'main') { admin_priv('sql_query'); assign_query_info(); $smarty->assign('type', -1); $smarty->assign('ur_here', $_LANG['04_sql_query']); $smarty->display('sql.htm'); } if ($_REQUEST['act'] == 'query') { admin_priv('sql_query'); assign_sql($_POST['sql']); assign_query_info(); $smarty->assign('ur_here', $_LANG['04_sql_query']); $smarty->display('sql.htm'); } /** * * * @access public * @param * * @return void */ function assign_sql($sql) { global $db, $smarty, $_LANG;
function do_init($games, $mods) { global $cms, $db, $db_init, $errors, $actions, $overwrite, $dropdb, $allow_next, $schema, $defaults; $i = 1; $exists = array(); $dropped = array(); $ignore = array(); if (!$games) { $errors[] = "No 'game type' selected! You must select at least one."; } // a 'mod' must be selected if 'halflife' is selected as a game type. // the other games supported at this time do not have mods. if (!$mods and in_array('halflife', $games)) { $errors[] = "No 'mod type' selected! You must select at least one."; } if ($errors) { return false; } // get a list of all PS tables in the database (ignore tables without our prefix $db->query("SHOW TABLES LIKE '" . $db->escape($db->dbtblprefix) . "%'"); while ($r = $db->fetch_row(0)) { $exists[$r[0]] = true; } // load our SQL schema $schema = load_schema($db->type() . "/basic.sql"); if (!$schema) { $errors[] = "Unable to read basic database schema for installation!"; } // load our SQL defaults $defaults = load_schema($db->type() . "/defaults.sql"); if (!$defaults) { $errors[] = "Unable to read database defaults for installation!"; } //load our Maxmind database $maxmind = load_schema($db->type() . "/maxmind.sql"); if (!$maxmind) { $errors[] = "Unable to read Maxmind GeoIP database for installation!"; } // load the modtype defaults, if avaialble // bug: the same modtype from different games will be loaded... not an issue right now though. foreach ($games as $g) { assign_sql(load_schema($db->type() . "/{$g}.sql")); foreach ($mods as $m) { assign_sql(load_schema($db->type() . "/{$g}/{$m}.sql")); } } if ($errors) { return false; } // recreate DB if needed if ($dropdb || !$db->dbexists($db->dbname)) { $exists = array(); if (!$db->dbexists($db->dbname) || $db->dropdb($db->dbname)) { if ($db->createdb($db->dbname, "DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci")) { $actions[$db->dbname] = array('status' => 'good', 'msg' => "RECREATED DATABASE '{$db->dbname}'"); $db->selectdb(); } else { $errors[] = "Error creating database: " . $db->errstr; } } else { $errors[] = "Error dropping current database: " . $db->errstr; } } if ($errors) { return false; } $queries = array_merge($schema, $defaults, $maxmind); $allow_next = true; foreach ($queries as $sql) { if (empty($sql)) { continue; } $action = substr($sql, 0, 6); $is_create = strtolower($action) == 'create'; if (!preg_match('/(?:CREATE TABLE|INSERT INTO) ([^\\w])([\\w\\d_]+)\\1/i', $sql, $m)) { continue; } $table = $m[2]; // fix the table name to use the proper prefix if ($db->dbtblprefix != 'ps_') { $table = preg_replace('/^ps_/', $db->dbtblprefix, $table); $sql = str_replace($m[2], $table, $sql); } // if the table exists and overwrite is true, drop it first. if ($exists[$table] and $overwrite and $is_create) { if ($db->droptable($table)) { unset($exists[$table]); $actions[$table] = array('status' => 'good', 'msg' => "Dropped table '{$table}'"); $dropped[$table] = true; } else { $actions[$table] = array('status' => 'bad', 'msg' => "Error dropping table '{$table}'"); $allow_next = false; continue; } } if ($is_create) { // don't try to create a table that already exists if ($exists[$table]) { $ignore[$table] = true; $actions[$table] = array('status' => 'warn', 'msg' => "Ignoring table '{$table}' (already exists)"); } else { if ($db->query($sql)) { $actions[$table] = array('status' => 'good', 'msg' => ($dropped[$table] ? "Rec" : "C") . "reated table '{$table}'"); } else { $actions[$table] = array('status' => 'bad', 'msg' => "Error creating table '{$table}': " . $db->errstr); } } } else { // do 'insert' query if ($ignore[$table]) { continue; } if ($db->query($sql)) { $actions[$table] = array('status' => 'good', 'msg' => "Created and initialized table '{$table}'"); } else { $actions[$table] = array('status' => 'bad', 'msg' => "Error initializing table '{$table}': " . $db->errstr); } } } // foreach $queries ... // initialize some configuration defaults $tbl = $db->table('config'); // only update the config table if it was created/initialized above ... if ($actions[$tbl] and $actions[$tbl]['status'] == 'good') { // default game/mod type to the first ones selected in the form $db->query("UPDATE " . $db->qi($tbl) . " SET value='{$games['0']}' WHERE conftype='main' AND section IS NULL AND var='gametype'"); # if ($db->errstr) $errors[] = $db->errstr; $db->query("UPDATE " . $db->qi($tbl) . " SET value='{$mods['0']}' WHERE conftype='main' AND section IS NULL AND var='modtype'"); # if ($db->errstr) $errors[] = $db->errstr; } }