Beispiel #1
0
ignore_user_abort(true);
@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']);
Beispiel #2
0
    $relative_path = substr(AT_INCLUDE_PATH, 0, -strlen('include/'));
    header('Location: ' . $relative_path . 'install/not_installed.php');
    exit;
}
/*** end system config block ***/
/*** 1. constants ***/
if (!defined('AT_REDIRECT_LOADED')) {
    require_once AT_INCLUDE_PATH . 'lib/constants.inc.php';
}
/*** 2. initialize db connection and populate $_config ***/
if (!defined('AT_REDIRECT_LOADED')) {
    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!';
Beispiel #3
0
/**
 * 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;
}