function process_step3() { global $DEFAULTS, $DBALS, $LOCALES, $REQUIRE; $tpl = new Template_Wrap(); $tpl->set_handle('body', 'install_step3.html'); /** * Get our posted data */ $db_config['dbtype'] = post_or_db('dbtype'); $db_config['host'] = post_or_db('dbhost'); $db_config['database'] = post_or_db('dbname'); $db_config['username'] = post_or_db('dbuser'); $db_config['password'] = post_or_db('dbpass'); $db_config['table_prefix'] = post_or_db('table_prefix', $DEFAULTS); $default_locale = post_or_db('default_lang', $DEFAULTS); $server_name = post_or_db('server_name'); $create['username'] = post_or_db('dbuser_c'); $create['password'] = post_or_db('dbpass_c'); define('ROSTER_DB_DIR', ROSTER_LIB . 'dbal' . DIR_SEP); $dbal_file = ROSTER_DB_DIR . $db_config['dbtype'] . '.php'; if (!file_exists($dbal_file)) { $tpl->message_die('Unable to find the database abstraction layer for <strong>' . $db_config['dbtype'] . '</strong>, check to make sure ' . $dbal_file . ' exists.'); } /** * Database population */ include_once $dbal_file; // Hey, looks like we are making the database, YAY! if ($create['username'] != '' && $create['password'] != '') { include_once $dbal_file; $db = new roster_db($db_config['host'], '', $create['username'], $create['password']); $db->query("CREATE DATABASE IF NOT EXISTS `" . $db_config['database'] . "`;"); unset($db, $create); } // Try to connect $db = new roster_db($db_config['host'], $db_config['database'], $db_config['username'], $db_config['password'], $db_config['table_prefix']); $db->log_level(); $db->error_die(); // Check to make sure a connection was made if (!is_resource($db->link_id)) { // Attempt to $tpl->message_die('Failed to connect to database <strong>' . $db_config['database'] . '</strong> as <strong>' . $db_config['username'] . '@' . $db_config['host'] . '</strong><br />' . $db->connect_error() . '<br /><br />' . '<form method="post" action="index.php" name="post"><input type="hidden" name="install_step" value="2" /><div align="center"><input type="submit" name="submit" value="Try Again" /></div></form>'); } $db_structure_file = ROSTER_DB_DIR . 'structure' . DIR_SEP . $db_config['dbtype'] . '_structure.sql'; $db_data_file = ROSTER_DB_DIR . 'structure' . DIR_SEP . $db_config['dbtype'] . '_data.sql'; $remove_remarks_function = $DBALS[$db_config['dbtype']]['comments']; // I require MySQL version 4.1.0 minimum. $server_version = $db->server_info(); $client_version = $db->client_info(); if (isset($server_version) && isset($client_version)) { $tpl->message_append('MySQL server version ' . $REQUIRE['mysql_version'] . ' or higher is required for WoWRoster.<br /><br /> <strong>You are running:</strong> <ul> <li><strong>Your server version: ' . $server_version . '</strong></li> <li><strong>Your client version: ' . $client_version . '</strong></li> </ul> Your server meets the MySQL requirements for WoWRoster.'); if (version_compare($server_version, $REQUIRE['mysql_version'], '<')) { $tpl->message_die('MySQL server version ' . $REQUIRE['mysql_version'] . ' or higher is required for WoWRoster.<br /><br /> <strong>You are running:</strong> <ul> <li><strong>Your server version: ' . $server_version . '</strong></li> <li><strong>Your client version: ' . $client_version . '</strong></li> </ul> We are sorry, your MySQL server version is not high enough to install WoWRoster, please upgrade MySQL.'); } } else { $tpl->message_die('Failed to get version information for database <strong>' . $db_config['database'] . '</strong> as <strong>' . $db_config['username'] . '@' . $db_config['host'] . '</strong><br />' . $db->connect_error() . '<br /><br />' . '<form method="post" action="index.php" name="post"><input type="hidden" name="install_step" value="2" /><div align="center"><input type="submit" name="submit" value="Try Again" /></div></form>'); } // Parse structure file and create database tables $sql = @fread(@fopen($db_structure_file, 'r'), @filesize($db_structure_file)); $sql = preg_replace('#renprefix\\_(\\S+?)([\\s\\.,]|$)#', $db_config['table_prefix'] . '\\1\\2', $sql); $sql = $remove_remarks_function($sql); $sql = parse_sql($sql, $DBALS[$db_config['dbtype']]['delim']); $sql_count = count($sql); $i = 0; while ($i < $sql_count) { if (isset($sql[$i]) && $sql[$i] != '') { if (!$db->query($sql[$i])) { $tpl->message_die('Error in SQL query<br />' . $sql[$i] . '<br />' . 'Error: ' . $db->error() . '<br />' . '<a href="index.php">Restart Installation</a>'); } } $i++; } unset($sql); // Parse the data file and populate the database tables $sql = @fread(@fopen($db_data_file, 'r'), @filesize($db_data_file)); $sql = preg_replace('#renprefix\\_(\\S+?)([\\s\\.,]|$)#', $db_config['table_prefix'] . '\\1\\2', $sql); $sql = $remove_remarks_function($sql); $sql = parse_sql($sql, $DBALS[$db_config['dbtype']]['delim']); $sql_count = count($sql); $i = 0; while ($i < $sql_count) { if (isset($sql[$i]) && $sql[$i] != '') { if (!$db->query($sql[$i])) { $tpl->message_die('Error in SQL query<br />' . $sql[$i] . '<br />' . 'Error: ' . $db->error() . '<br />' . '<a href="index.php">Restart Installation</a>'); } } $i++; } unset($sql); /** * Update some config settings */ $db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '{$default_locale}' WHERE `config_name` = 'locale';"); $db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '" . ROSTER_VERSION . "' WHERE `config_name` = 'version';"); $db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '{$server_name}' WHERE `config_name` = 'website_address';"); /** * Write the config file */ $config_file = "<?php\n"; $config_file .= "/**\n * AUTO-GENERATED CONF FILE\n * DO NOT EDIT !!!\n */\n\n"; $config_file .= "\$db_config['host'] = " . var_export($db_config['host'], true) . ";\n"; $config_file .= "\$db_config['username'] = "******";\n"; $config_file .= "\$db_config['password'] = "******";\n"; $config_file .= "\$db_config['database'] = " . var_export($db_config['database'], true) . ";\n"; $config_file .= "\$db_config['table_prefix'] = " . var_export($db_config['table_prefix'], true) . ";\n"; $config_file .= "\$db_config['dbtype'] = " . var_export($db_config['dbtype'], true) . ";\n"; // Set our permissions to execute-only @umask(0111); if (!($fp = @fopen('conf.php', 'w'))) { $error_message = 'The <strong>conf.php</strong> file couldn\'t be opened for writing. Paste the following in to conf.php and save the file to continue:<br /><pre>' . htmlspecialchars($config_file) . '</pre>'; $tpl->error_append($error_message); } else { @fputs($fp, $config_file); @fclose($fp); $tpl->message_append('Your configuration file has been written with the initial values<br />But installation will not be complete until you create an administrator account in this step'); } /** * Output the page */ $tpl->sql_output($db); $tpl->page_header(); $tpl->page_tail(); }
/** * Get the data for the current scope and assign it to $this->data */ function get_scope_data() { // --[ Resolve the anchor ]-- $this->anchor = isset($_GET['a']) ? $_GET['a'] : ''; if (empty($this->anchor)) { $this->atype = 'none'; } elseif (strpos($this->anchor, ':') !== FALSE) { list($this->atype, $this->anchor) = explode(':', $this->anchor); switch ($this->atype) { case 'r': case 'realm': $this->atype = 'realm'; break; case 'g': case 'guild': $this->atype = 'guild'; break; case 'u': case 'user': $this->atype = 'user'; break; case 'c': case 'char': $this->atype = 'char'; break; default: $this->atype = 'none'; break; } } elseif (strpos($this->anchor, '@') === FALSE) { $this->atype = 'realm'; } else { // There is no way to see from the anchor if this is a guild anchor or a char anchor. // To keep it simple, we'll just assume it's an anchor for the current scope. $this->atype = $this->scope; } if ($this->atype == 'none' && in_array($this->scope, array('guild', 'realm'))) { // No anchor at all, but for realm/guild we have a default $defquery = "SELECT `name`, `server`, `region`" . " FROM `" . $this->db->table('upload') . "`" . " WHERE `default` = '1'" . " LIMIT 1;"; $this->db->query($defquery); $data = $this->db->fetch(); if ($data) { $name = $this->db->escape($data['name']); $realm = $this->db->escape($data['server']); $region = $this->db->escape($data['region']); $this->atype = 'default'; $this->anchor = $name . '@' . $region . '-' . $realm; } else { $this->atype = 'none'; $this->anchor = ''; // roster_die(sprintf($this->locale->act['nodefguild'], makelink('rostercp-upload')), $this->locale->act['nodata_title']); $this->set_message(sprintf($this->locale->act['nodefguild'], makelink('rostercp-upload')), $this->locale->act['nodata_title'], 'error'); $this->_break_scope(); return; } } // --[ Build the query ]-- switch ($this->atype) { case 'char': // Parse the attribute if (is_numeric($this->anchor)) { $where = ' `players`.`member_id` = "' . $this->anchor . '"'; } elseif (strpos($this->anchor, '@') !== false) { list($name, $realm) = explode('@', $this->anchor); if (strpos($realm, '-') !== false) { list($region, $realm) = explode('-', $realm, 2); $where = ' `players`.`name` = "' . $name . '" ' . 'AND `players`.`server` = "' . $realm . '" ' . 'AND `players`.`region` = "' . strtoupper($region) . '" '; } else { $where = ' `players`.`name` = "' . $name . '" ' . 'AND `players`.`server` = "' . $realm . '" '; } } else { $name = $this->anchor; $where = ' `players`.`name` = "' . $name . '"'; } // Get the data $query = 'SELECT guild.*, members.*, players.*, ' . 'DATE_FORMAT( DATE_ADD(`players`.`dateupdatedutc`, INTERVAL ' . $this->config['localtimeoffset'] . ' HOUR ), "' . $this->locale->act['timeformat'] . '" ) AS "update_format" ' . 'FROM `' . $this->db->table('players') . '` players ' . 'LEFT JOIN `' . $this->db->table('members') . '` members ON `players`.`member_id` = `members`.`member_id` ' . 'LEFT JOIN `' . $this->db->table('guild') . '` guild ON `players`.`guild_id` = `guild`.`guild_id` ' . 'WHERE ' . $where . ";"; $result = $this->db->query($query); if (!$result) { die_quietly($this->db->error(), 'Database error', __FILE__, __LINE__, $query); } if (!($this->data = $this->db->fetch($result))) { // roster_die('The member ' . $this->anchor . ' is not in the database', $this->locale->act['roster_error']); $this->set_message(sprintf($roster->locale->act['no_char_in_db'], $this->anchor), $this->locale->act['roster_error'], 'error'); $this->_break_scope(); return; } $this->db->free_result($result); $this->anchor = $this->data['member_id']; // Scope specific functions $scope_class = new CharScope(); $scope_class->set_tpl($this->data); $scope_class->alt_name_hover(); $scope_class->mini_members_list(); break; // We have a separate atype for default, but it loads a guild anchor from the uploads table. // We have a separate atype for default, but it loads a guild anchor from the uploads table. case 'guild': case 'user': case 'default': if (in_array($this->scope, array('char'))) { $this->set_message($roster->locale->act['not_valid_anchor'], '', 'error'); $this->anchor = 'none'; $this->atype = 'none'; } // Parse the attribute if (is_numeric($this->anchor)) { $where = ' `guild_id` = "' . $this->anchor . '"'; } elseif (strpos($this->anchor, '@') !== false) { list($name, $realm) = explode('@', $this->anchor); if (strpos($realm, '-') !== false) { list($region, $realm) = explode('-', $realm, 2); $where = ' `guild_name` = "' . $name . '" ' . 'AND `server` = "' . $realm . '" ' . 'AND `region` = "' . strtoupper($region) . '" '; } else { $where = ' `guild_name` = "' . $name . '" ' . 'AND `server` = "' . $realm . '" '; } } else { $name = $this->anchor; $where = ' `guild_name` = "' . $name . '"'; } // Get the data $query = 'SELECT guild.* ' . "FROM `" . $this->db->table('guild') . "` guild " . "WHERE " . $where . ";"; $result = $this->db->query($query); if (!$result) { die_quietly($this->db->error(), 'Database Error', __FILE__ . '<br />Function: ' . __FUNCTION__, __LINE__, $query); } if (!($this->data = $this->db->fetch($result))) { // roster_die(sprintf($this->locale->act['nodata'], $name, $realm, makelink('update'), makelink('rostercp-upload')), $this->locale->act['nodata_title']); $this->set_message(sprintf($this->locale->act['nodata'], $name, $realm, makelink('update'), makelink('rostercp-upload')), $this->locale->act['nodata_title'], 'error'); $this->_break_scope(); return; } $this->db->free_result($result); $this->anchor = $this->data['guild_id']; // Scope specific functions $scope_class = new GuildScope(); $scope_class->set_tpl($this->data); break; case 'realm': if (in_array($this->scope, array('char', 'guild'))) { $this->set_message($roster->locale->act['not_valid_anchor'], '', 'error'); $this->anchor = 'none'; $this->atype = 'none'; } if (strpos($this->anchor, '-') !== false) { list($region, $realm) = explode('-', $this->anchor, 2); $where = ' `server` = "' . $realm . '" ' . 'AND `region` = "' . strtoupper($region) . '"'; } else { $realm = $this->anchor; $where = ' `server` = "' . $realm . '" '; } // Check if there's data for this realm $query = "SELECT DISTINCT `server`, `region`" . " FROM `" . $this->db->table('guild') . "`" . " WHERE {$where}" . " UNION SELECT DISTINCT `server`, `region`" . " FROM `" . $this->db->table('players') . "`" . " WHERE {$where}" . " LIMIT 1;"; $result = $this->db->query($query); if (!$result) { die_quietly($this->db->error(), 'Database Error', __FILE__ . '<br />Function: ' . __FUNCTION__, __LINE__, $query); } if (!($this->data = $this->db->fetch($result, SQL_ASSOC))) { // roster_die(sprintf($this->locale->act['nodata'], '', $realm, makelink('update'), makelink('rostercp-upload')), $this->locale->act['nodata_title']); $this->set_message(sprintf($this->locale->act['nodata'], '', $realm, makelink('update'), makelink('rostercp-upload')), $this->locale->act['nodata_title'], 'error'); $this->_break_scope(); return; } $this->anchor = $this->data['region'] . '-' . $this->data['server']; // Scope specific functions $scope_class = new RealmScope(); break; default: if (in_array($this->scope, array('char', 'guild', 'realm'))) { $this->set_message($this->locale->act['not_valid_anchor'], '', 'error'); $this->anchor = 'none'; $this->atype = 'none'; } // no anchor passed, and we didn't load defaults so we're in util or page scope. No data needed. $this->data = array(); // Scope specific functions $scope_class = new UtilScope(); break; } // Figure out the armory url based on region if (isset($this->data['region'])) { switch ($this->data['region']) { case 'US': $this->data['armoryurl'] = 'http://www.wowarmory.com'; break; case 'EU': $this->data['armoryurl'] = 'http://eu.wowarmory.com'; break; default: $this->data['armoryurl'] = ''; } } // Set menu array if (isset($this->data['member_id'])) { $this->output['show_menu']['char'] = 1; } $this->output['show_menu'][$this->scope == 'page' ? 'util' : $this->scope] = 1; }