function wrsqz_testEnvironment(){
    global $CFG;
    require_once($CFG->dirroot . '/lib/setuplib.php');

    $unicodedb=setup_is_unicodedb();
    if($unicodedb){
        $message='Your Database has UNICODE charset.';
    }else{
        $message='Quizzes uses UNICODE characters and will not work. Please migrate your database to a UNICODE charset.';
    }
    printRow('Database', $unicodedb, $message);

    $mbstring=extension_loaded('mbstring');
    if($mbstring){
        $message='Multibyte PHP extension is loaded.';
    }else{
        $message='Quizzes uses Multibyte PHP extension but it is\'t installed or loaded. Please check your php.ini file.';
    }
    printRow('mbstring',$mbstring,$message);

    if($mbstring){
        $mbInternalEncoding = mb_internal_encoding();
        $mbInternalEncodingChange = mb_internal_encoding('UTF-8');
        $mbInternalEncodingUTF8 = mb_internal_encoding();
        $message = 'Multibyte internal encoding by default: <b>'. $mbInternalEncoding .'</b>. Current encoding: <b>'.$mbInternalEncodingUTF8.'</b>.';
        printRow('mbstring encoding',$mbInternalEncodingUTF8=='UTF-8',$message);
    }

}
Exemple #2
0
     die;
 }
 $strdatabasesetup = get_string("databasesetup");
 $strdatabasesuccess = get_string("databasesuccess");
 $navigation = build_navigation(array(array('name' => $strdatabasesetup, 'link' => null, 'type' => 'misc')));
 print_header($strdatabasesetup, $strdatabasesetup, $navigation, "", upgrade_get_javascript(), false, "&nbsp;", "&nbsp;");
 /// return to original debugging level
 $CFG->debug = $origdebug;
 error_reporting($CFG->debug);
 upgrade_log_start();
 $db->debug = true;
 /// Both old .sql files and new install.xml are supported
 /// But we prioritise install.xml (XMLDB) if present
 change_db_encoding();
 // first try to change db encoding to utf8
 if (!setup_is_unicodedb()) {
     // If could not convert successfully, throw error, and prevent installation
     print_error('unicoderequired', 'admin');
 }
 $status = false;
 if (file_exists("{$CFG->libdir}/db/install.xml")) {
     $status = install_from_xmldb_file("{$CFG->libdir}/db/install.xml");
     //New method
 } else {
     if (file_exists("{$CFG->libdir}/db/{$CFG->dbtype}.sql")) {
         $status = modify_database("{$CFG->libdir}/db/{$CFG->dbtype}.sql");
         //Old method
     } else {
         error("Error: Your database ({$CFG->dbtype}) is not yet fully supported by Moodle or install.xml is not present.  See the lib/db directory.");
     }
 }
/**
 * This function will check if unicode database requirements are satisfied
 * @param string $version xml version we are going to use to test this server
 * @return object results encapsulated in one environment_result object
 */
function environment_check_unicode($version)
{
    global $db;
    $result = new environment_results('unicode');
    /// Get the enviroment version we need
    if (!($data = get_environment_for_version($version))) {
        /// Error. No version data found
        $result->setStatus(false);
        $result->setErrorCode(NO_VERSION_DATA_FOUND);
        return $result;
    }
    /// Extract the unicode part
    if (!isset($data['#']['UNICODE'])) {
        /// Error. No UNICODE section found
        $result->setStatus(false);
        $result->setErrorCode(NO_UNICODE_SECTION_FOUND);
        return $result;
    } else {
        /// Extract level
        $level = get_level($data['#']['UNICODE']['0']);
    }
    if (!($unicodedb = setup_is_unicodedb())) {
        $result->setStatus(false);
    } else {
        $result->setStatus(true);
    }
    $result->setLevel($level);
    /// Do any actions defined in the XML file.
    process_environment_result($data['#']['UNICODE'][0], $result);
    return $result;
}
function change_db_encoding()
{
    global $CFG, $db;
    // try forcing utf8 collation, if mysql db and no tables present
    if ($CFG->dbfamily == 'mysql' && !$db->Metatables()) {
        $SQL = 'ALTER DATABASE ' . $CFG->dbname . ' CHARACTER SET utf8';
        execute_sql($SQL, false);
        // silent, if it fails it fails
        if (setup_is_unicodedb()) {
            configure_dbconnection();
        }
    }
}