require_once AT_INCLUDE_PATH . 'lib/mysql_connect.inc.php'; if (defined('MYSQLI_ENABLED')) { $db = at_db_connect(DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME); } else { $db = at_db_connect(DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, ''); at_db_select(DB_NAME, $db); } //$db = at_db_connect(DB_HOST, DB_PORT, DB_USER, DB_PASSWORD); //at_db_select(DB_NAME, $db); } // check if the subsite is enabled if (defined('IS_SUBSITE') && IS_SUBSITE) { include_once AT_INCLUDE_PATH . '../mods/manage_multi/lib/mysql_multisite_connect.inc.php'; $db_tmp = $db; $db = $db_multisite; at_db_select(DB_NAME_MULTISITE, $db_multisite); $site_url = $_SERVER['HTTP_HOST']; $row = queryDB("SELECT * from %ssubsites where site_url = '%s'", array(TABLE_PREFIX_MULTISITE, $site_url), true); if (!$row['enabled']) { echo $site_url . ' has been disabled!'; exit; } $db = $db_tmp; } /* get config variables. if they're not in the db then it uses the installation default value in constants.inc.php */ $rows = queryDB("SELECT * FROM %sconfig", array(TABLE_PREFIX)); foreach ($rows as $row) { $_config[$row['name']] = $row['value']; } /***** 3. start session initilization block *****/ if (headers_sent()) {
@set_time_limit(0); if (!defined('AT_INCLUDE_PATH') || !defined('AT_UPGRADE_INCLUDE_PATH')) { exit; } include AT_INCLUDE_PATH . 'install/upgrade.inc.php'; $_POST['db_login'] = urldecode($_POST['db_login']); $_POST['db_password'] = urldecode($_POST['db_password']); unset($errors); //check DB & table connection //$db = at_db_connect($_POST['db_host'], $_POST['db_port'], $_POST['db_login'], urldecode($_POST['db_password'])); //at_db_select($_POST['db_name'], $db); if (defined('MYSQLI_ENABLED')) { $db = at_db_connect($_POST['db_host'], $_POST['db_port'], $_POST['db_login'], urldecode($_POST['db_password']), $_POST['db_name']); } else { $db = at_db_connect($_POST['db_host'], $_POST['db_port'], $_POST['db_login'], urldecode($_POST['db_password']), ''); at_db_select($_POST['db_name'], $db); } $row = at_db_version($db); if (version_compare($row['version'], '4.0.2', '>=') === FALSE) { $errors[] = 'MySQL version ' . $row['version'] . ' was detected. ATutor requires version 4.0.2 or later.'; } if (!$errors) { $progress[] = 'Connected to database <b>' . $_POST['db_name'] . '</b> successfully.'; unset($errors); //Save all the course primary language into session variables iff it has not been set. if (!isset($_SESSION['course_info'])) { $sql = "SELECT a.course_id, a.title, l.language_code, l.char_set FROM %scourses a left join %slanguages l ON l.language_code = a.primary_language"; $rows_courselang = queryDB($sql, array($_POST['tb_prefix'], $_POST['tb_prefix'])); foreach ($rows_courselang as $row) { $_SESSION['course_info'][$row['course_id']] = array('char_set' => $row['char_set'], 'language_code' => $row['language_code']); }
$request .= '&version=' . urlencode($stripslashes($new_version)); $request .= '&build=' . urlencode($stripslashes($build)); $request .= '&build_date=' . urlencode($stripslashes($build_date)); $request .= '&os=' . urlencode($stripslashes($_POST['log_os'])); $request .= '&server=' . urlencode($stripslashes($_POST['log_server'])); $request .= '&php=' . urlencode($stripslashes($_POST['log_php'])); $request .= '&mysql=' . urlencode($stripslashes($_POST['log_mysql'])); if ($_POST['step1']['old_path'] != '') { // get some usage data from this upgrade: //$db = at_db_connect($_POST['step1']['db_host'] , $_POST['step1']['db_port'], $_POST['step1']['db_login'], urldecode($_POST['step1']['db_password'])); //at_db_select($_POST['step1']['db_name'], $db); if (defined('MYSQLI_ENABLED')) { $db = at_db_connect($_POST['step1']['db_host'], $_POST['step1']['db_port'], $_POST['step1']['db_login'], urldecode($_POST['step1']['db_password']), $_POST['step1']['db_name']); } else { $db = at_db_connect($_POST['step1']['db_host'], $_POST['step1']['db_port'], $_POST['step1']['db_login'], urldecode($_POST['step1']['db_password'])); at_db_select($_POST['step1']['db_name'], $db); } $db_size = 0; // db size in bytes $sql = 'SHOW TABLE STATUS'; $rows_tables = queryDB($sql, array()); foreach ($rows_tables as $row) { $db_size += $row['Data_length'] + $row['Index_length']; } $sql = "SELECT COUNT(*) AS cnt FROM %scourses"; $row = queryDB($sql, array($_POST['step1']['tb_prefix']), TRUE); $num_courses = $row['cnt']; $sql = "SELECT COUNT(*) AS cnt FROM %smembers"; $row = queryDB($sql, array($_POST['step1']['tb_prefix']), TRUE); $num_users = $row['cnt']; $sql = "SELECT COUNT(*) AS cnt FROM %sadmins";
/** * Installation step to create and switch to ATutor database * @param: db_host DB host * db_port DB port * db_login DB login ID. This id must have "create database" privilege. * db_pwd The password of the login id * db_name DB name to create * schema_file The location of atutor_schema.sql * in_plain_msg if true, save the progress msg into global arrays $errors & $progress, * otherwise, save into global Message object $msg * @return An array of progress/error information or the same message in $msg depending on the flag $in_plain_msg. */ function create_and_switch_db($db_host, $db_port, $db_login, $db_pwd, $tb_prefix, $db_name, $in_plain_msg = false) { global $addslashes; global $errors, $progress, $msg; //$db = at_db_connect($db_host, $db_port, $db_login, $db_pwd); if (defined('MYSQLI_ENABLED')) { $db = at_db_connect($db_host, $db_port, $db_login, $db_pwd, ''); } else { $db = at_db_connect($db_host, $db_port, $db_login, $db_pwd, ''); //at_db_select($db_name, $db); } if (!$db) { if ($in_plain_msg) { $errors[] = 'Unable to connect to database server.'; } else { $msg->addError('UNABLE_CONNECT_DB'); } } $tb_prefix = $addslashes($tb_prefix); $db_name = $addslashes($db_name); // check mysql version number $row = at_db_version($db); $row['version'] = str_replace(array('-community-nt', '-max', '-standard'), '', strtolower($row['version'])); if (version_compare($row['version'], '4.1.10', '>=') === FALSE) { if ($in_plain_msg) { $errors[] = 'MySQL version ' . $row['version'] . ' was detected. ATutor requires version 4.1.10 or later.'; } else { $msg->addError(array('LOW_MYSQL_VERSION', $row['version'])); } } if (isset($db)) { $isdb = at_is_db($db_name, $db); } if ($isdb == 0) { $sql = "CREATE DATABASE `" . $db_name . "` CHARACTER SET utf8 COLLATE utf8_general_ci"; //$result = queryDB($sql, array($db_name)); $result = at_db_create($sql, $db); if ($result == 0) { if ($in_plain_msg) { $errors[] = 'Unable to select or create database <b>' . $db_name . '</b>.'; } else { $msg->addError(array('UNABLE_SELECT_DB', $db_name)); } } else { if ($in_plain_msg) { $progress[] = 'Database <b>' . $db_name . '</b> created successfully.'; } else { $msg->addFeedback(array('DB_CREATED', $db_name)); } at_db_select($db_name, $db); } } else { /* Check if the database that existed is in UTF-8, if not, ask for retry */ at_db_select($db_name, $db); $sql = "SHOW CREATE DATABASE `%s`"; $row = queryDB($sql, array($db_name)); if (!preg_match('/CHARACTER SET utf8/i', $row['Create Database'])) { $sql2 = 'ALTER DATABASE `%s` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci'; $result2 = queryDB($sql2, array($db_name)); if ($result2 == 0) { if ($in_plain_msg) { $errors[] = 'Database <b>' . $db_name . '</b> is not in UTF8. Please set the database character set to UTF8 before continuing by using the following query: <br /> ALTER DATABASE `' . $db_name . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci. <br />To use ALTER DATABASE, you need the ALTER privilege on the database. You can also check the MySQL manual <a href="http://dev.mysql.com/doc/refman/4.1/en/alter-database.html" target="mysql_window">here</a>.'; } else { $msg->addFeedback(array('DB_NOT_UTF8', $db_name)); } } } } return $db; }
// $Id$ define('AT_INCLUDE_PATH', 'include/'); define('AT_REDIRECT_LOADED', true); $_user_location = 'public'; //like browse, and registration, doesn't need username/passwords to get into include_once AT_INCLUDE_PATH . 'lib/vital_funcs.inc.php'; define('AT_SITE_PATH', get_site_path()); require_once AT_INCLUDE_PATH . 'classes/UrlRewrite/UrlParser.class.php'; include_once AT_SITE_PATH . 'include/config.inc.php'; require_once AT_INCLUDE_PATH . 'lib/constants.inc.php'; require_once AT_INCLUDE_PATH . 'lib/mysql_connect.inc.php'; if (defined('MYSQLI_ENABLED')) { $db = at_db_connect(DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME); } else { $db = at_db_connect(DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, ''); at_db_select(DB_NAME, $db); } //mimic config variables, vitals.inc.php 135-140 /* get config variables. if they're not in the db then it uses the installation default value in constants.inc.php */ $sql = "SELECT * FROM %sconfig"; $config_rows = queryDB($sql, array(TABLE_PREFIX)); foreach ($config_rows as $row) { $_config[$row['name']] = $row['value']; } //Get path info $pathinfo = getPathInfo(); $url_parser = new UrlParser($pathinfo); $path_array = $url_parser->getPathArray(); $_pretty_url_course_id = $path_array[0]; $obj = $path_array[1]; if (!$obj->isEmpty()) {