';
- print_simple_box_start('center','50%');
- print_string('dbmigratepostgres','admin');
- print_simple_box_end();
-
- print_simple_box_start("center", "");
- include("utfdbmigrate.html");
- print_simple_box_end();
- }
- }
-
- else { //else, print welcome to migrate page message
- echo '
';
- print_simple_box_start('center','50%');
- print_string('dbmigratewarning','admin');
- print_simple_box_end();
-
- /*************************************
- * Eloy's environement checking code *
- *************************************/
-
- $current_version = $CFG->release;
-
- /// Gather and show results
- $status = check_moodle_environment($current_version, $environment_results);
-
- //end of env checking
-
- /// We only allow to continue if environmental checks have been passed ok
- if ($status) {
- echo '';
- echo '
';
- }
- }
-
- print_footer();
-
-
-function db_migrate2utf8(){ //Eloy: Perhaps some type of limit parameter here
- //pointing to the num of records to process would be
- //useful. And it won't break anything, because the
- //crash system will continue the next time it was
- //executed. Also, the function could return:
- //0 = Some sort of error
- //1 = Finished completelly!
- //2 = Finished limit records
- //(using constants, of course ;-))
- //Then, all those errors, should be converted to
- //mtrace() and return 0. (showing the current
- //table/field/recordid)
-
- global $db, $CFG, $dbtablename, $fieldname, $record, $processedrecords;
- $debug = debugging();
-
- if ($CFG->dbtype == 'mysql') {
- check_and_create_backup_dir(BACKUP_UNIQUE_CODE); //Create the backup temp dir
- }
-
- ignore_user_abort(false); // see bug report 5352. This should kill this thread as soon as user aborts.
-
- @set_time_limit(0);
- @ob_implicit_flush(true);
- @ob_end_flush();
-
- $maxrecords = optional_param('maxrecords', 0, PARAM_INT);
- $globallang = optional_param('globallang', '', PARAM_FILE);
- $processedrecords = 0;
-
- $ignoretables = array(); //list of tables to ignore, optional
-
- //one gigantic array to hold all db table information read from all the migrate2utf8.xml file.
- require_once($CFG->dirroot.'/lib/xmlize.php');
- $xmls = utf_get_xml(1);
- $tablestoconvert = 0; // total number of tables to convert
- foreach ($xmls as $xml) { ///foreach xml file, we must get a list of tables
- $dbtables = $xml['DBMIGRATION']['#']['TABLES'][0]['#']['TABLE']; //real db tables
- foreach ($dbtables as $dbtable) {
- $tablestoconvert++;
- }
- }
- // progress bar handling
- // first let's find out how many tables there are
-
- $done = 0;
- print_progress($done, $tablestoconvert, 5, 1);
-
-
- $textlib = textlib_get_instance(); //only 1 reference
-
- //if unicodedb is set, migration is complete. die here;
- if (!$crash = get_record('config','name','dbmigration')) {
- //Duplicate the database if not unicode for postgres7
- if ($CFG->dbtype == 'postgres7' && !is_postgres_utf8() && !is_postgres_setup()) {
- echo '';
-
- if ($_SESSION['newpostgresdb']->dbcluster) {
- $cluster = ' --cluster ' . $_SESSION['newpostgresdb']->dbcluster;
- } else {
- $cluster = '';
- }
- $pgdump = 'pg_dump';
- if (!empty($_SESSION['newpostgresdb']->pathtopgdump)) {
- $pgdump = $_SESSION['newpostgresdb']->pathtopgdump;
- }
- $psql = 'psql';
- if (!empty($_SESSION['newpostgresdb']->pathtopsql)) {
- $pgsql = $_SESSION['newpostgresdb']->pathtopsql;
- }
-
- $cmd = "PGPASSWORD={$CFG->dbpass} PGCLIENTENCODING='UNICODE' PGDATABASE={$CFG->dbname} $pgdump -Fp -O -x -U {$CFG->dbuser}$cluster";
- if ($CFG->dbhost) {
- $host = split(":", $CFG->dbhost);
- if ($host[0]) $cmd .= " -h {$host[0]}";
- if (isset($host[1])) $cmd .= " -p {$host[1]}";
- }
- $cmds[] = $cmd;
- $cmds[] = 'grep -v "COMMENT ON SCHEMA"';
- $cmds[] = 'iconv -f UTF-8 -t UTF-8 -c';
- $cmd = "PGPASSWORD={$_SESSION['newpostgresdb']->dbpass} PGDATABASE={$_SESSION['newpostgresdb']->dbname} $psql -q -U {$_SESSION['newpostgresdb']->dbuser} -v ON_ERROR_STOP=1$cluster";
- if ($_SESSION['newpostgresdb']->dbhost) {
- $host = split(":", $_SESSION['newpostgresdb']->dbhost);
- if ($host[0]) $cmd .= " -h {$host[0]}";
- if (isset($host[1])) $cmd .= " -p {$host[1]}";
- }
- $cmds[] = $cmd;
- foreach ($cmds as $key => $cmd) {
- $files[] = tempnam($CFG->dataroot, 'utf8_');
- $cmd = $cmd . ($key?" < {$files[$key-1]}":'') . " 2>&1 > {$files[$key]}";
- if (stripos(PHP_OS, 'darwin') !== false && stripos($cmd,'iconv') !== false) {
- // I know this looks DREADFULLY hackish, but the iconv in mac os x seems to have a return code of 1 for warnings
- // and I cannot figure out why, it's a very different version of iconv to most *nix versions, even seems to be a
- // different gnu project.
- // If someone can figure out a better way to do this, FEEL FREE :)
- // - Penny
- $cmd .= ' || true';
- }
- exec($cmd, $output, $return_var);
- if ($key) {
- unlink($files[$key-1]);
- }
- if ($return_var) { // we are dead!
- unlink($files[$key]);
- echo '
';
- print_simple_box_start('center','50%');
- print_string('dbmigrationdupfailed','admin',htmlspecialchars(implode("\n", $output)));
- print_simple_box_end();
- print_footer();
- exit;
- }
- }
- unlink(array_pop($files));
- }
-
- $migrationconfig = new object;
- $migrationconfig->name = 'dbmigration';
- $migrationconfig->value = '-1';
- insert_record('config',$migrationconfig); //process initiated
-
- //langs used, to help make recommendations on what lang packs to install
- $langsused = new object;
- $langsused->name = 'langsused';
- $langsused->value = '';
- insert_record('config',$langsused);
-
- } else {
-
- $crashdata = explode('##',$crash->value);
- $crash->table = $crashdata[0];
- $crash->field = $crashdata[1];
- $crash->record = $crashdata[2];
-
- notify("Resuming migration from: $crash->table / .$crash->field, Record: $crash->record");
- }
-
- /************************************************************************
- * Now we got all our tables in order *
- ************************************************************************/
-
- foreach ($xmls as $xml) { ///foreach xml file, we must get a list of tables
- $dir = $xml['DBMIGRATION']['@']['type'];
- $dbtables = $xml['DBMIGRATION']['#']['TABLES'][0]['#']['TABLE']; //real db tables
-
- foreach ($dbtables as $dbtable) {
-
- $done++;
- print_progress($done, $tablestoconvert, 5, 1);
-
- $dbtablename = $dbtable['@']['name'];
-
- // exception handling for adodb_logsql
- // see bug 5003
- if ($dbtablename == 'adodb_logsql') {
- $prefix = '';
- } else {
- $prefix = $CFG->prefix;
- }
-
- if ($crash && ($dbtablename != $crash->table)) { //resuming from crash
- $done++; // need to update progress bar
- continue;
- }
-
- if ($debug) {
- print_heading("
Processsing db table ".$dbtablename.'...');
- }
-
- /* Insted of relying in the indexes defined for the table in utfmigrate.xml
- files, we are going to use the MetaIndexes() DB call in order to detect
- all the table indexes. Once fetched, they are saved in backup tables for
- safe storage and they are dropped from the table.
- At the end of the table, we'll fetch them from backup tables and all them
- will be recreated again.
- This will ensure that no index in lost in the UTF8 migration process and
- they will be exactly the same for each server (custom indexes...)
- Also this will leave free to keep the utfmigrate.xml files in sync for
- all the existing indexes and we only have to maintain fields in such
- files
- */
-
- /// Calculate all the indexes of the table
- if ($CFG->dbtype == 'mysql' && $allindexes = $db->MetaIndexes($prefix.$dbtablename)) {
- /// Send them to backup_ids table for temporal storage if crash
- backup_putid(BACKUP_UNIQUE_CODE, $prefix.$dbtablename, 1, 1, $allindexes);
- /// Drop all the indexes
- $sqlarr = array();
- foreach ($allindexes as $onekey => $oneindex) {
- $sqlarr[] = 'ALTER TABLE '.$prefix.$dbtablename.' DROP INDEX '.$onekey;
- }
- execute_sql_arr($sqlarr, true, $debug);
- }
-
- /**********************************************************
- * This is the by pass structure. It allows us to process *
- * tables on row basis instead of column/field basis *
- * It relies on a single function in migrate2utf8.php *
- **********************************************************/
-
- /// first, check to see if there's a function for the whole table. By pass point (1)
- if (file_exists($CFG->dirroot.'/'.$dir.'/db/migrate2utf8.php')) {
- require_once($CFG->dirroot.'/'.$dir.'/db/migrate2utf8.php');
- // this is a function to process table on role basis, e.g. user table in moodorg
- $tablefunction = 'migrate2utf8_'.$dbtablename;
- }
- if ($CFG->dbtype=='mysql' && function_exists($tablefunction)) {
- $tablefunction($dbtable['#']['FIELDS'][0]['#']['FIELD'], $crash, $debug, $maxrecords, $done, $tablestoconvert); // execute it.
- } else {
-
- /******************************************************
- * No function for converting whole table, we proceed *
- ******************************************************/
-
- if (!empty($dbtable['#']) && ($fields = $dbtable['#']['FIELDS'][0]['#']['FIELD']) and (!in_array($dbtablename, $ignoretables))) {
-
- $colnames = array();
- $coltypes = array(); //array to hold all column types for the table
- $collengths = array(); //array to hold all column lengths for the table
- $defaults = array(); //array to hold defaults, if any
- //reset holders
- $addindexarray = array();
- $adduniqueindexarray = array();
- $addprimaryarray = array();
-
- foreach ($fields as $field){
-
- //if in crash state, and field name is not the same as crash field name
-
- $fieldname = isset($field['@']['name'])?$field['@']['name']:"";
- $method = isset($field['@']['method'])?$field['@']['method']:"";
- $type = isset($field['@']['type'])?$field['@']['type']:"";
- $length = isset($field['@']['length'])?$field['@']['length']:"";
-
- if ($crash && ($crash->field != $fieldname)) {
- continue;
- }
-
- $dropindex = isset($field['@']['dropindex'])?$field['@']['dropindex']:"";
- $addindex = isset($field['@']['addindex'])?$field['@']['addindex']:"";
- $adduniqueindex = isset($field['@']['adduniqueindex'])?$field['@']['adduniqueindex']:"";
-
- $dropprimary = isset($field['@']['dropprimary'])?$field['@']['dropprimary']:"";
- $addprimary = isset($field['@']['addprimary'])?$field['@']['addprimary']:"";
- $default = isset($field['@']['default'])?"'".$field['@']['default']."'":"''";
-
- if ($fieldname != 'dummy') {
- $colnames[] = $fieldname;
- $coltypes[] = $type;
- $collengths[]= $length;
- }
-
- if ($debug) {
- echo "
-->
processing db field ".$fieldname.'';
- echo "
--->
method ".$method.'';
- }
-
-
- if ($CFG->dbtype == 'mysql') {
-
- /* Drop the index, because with index on, you can't change it to longblob
-
- NOTE: We aren't going to drop individual indexes anymore, because we have
- dropped them at the begining of the table iteration, saving them to
- backup temp tables. At the end of the table iteration we are going
- to rebuild them back
-
- if ($dropindex){ //drop index if index is varchar, text etc type
- $SQL = 'ALTER TABLE '.$prefix.$dbtablename.' DROP INDEX '.$dropindex.';';
- $SQL1 = 'ALTER TABLE '.$prefix.$dbtablename.' DROP INDEX '.$CFG->prefix.$dropindex.';'; // see bug 5205
- if ($debug) {
- $db->debug=999;
- }
-
- execute_sql($SQL, false); // see bug 5205
- execute_sql($SQL1, false); // see bug 5205
-
- if ($debug) {
- $db->debug=0;
- }
- } else */
- if ($dropprimary) { // drop primary key
- $SQL = 'ALTER TABLE '.$prefix.$dbtablename.' DROP PRIMARY KEY;';
- if ($debug) {
- $db->debug=999;
- }
- execute_sql($SQL, $debug);
- if ($debug) {
- $db->debug=0;
- }
- }
-
- /* Previously to change the field to LONGBLOB, we are going to
- use Meta info to fetch the NULL/NOT NULL status of the field.
- Then, when converting back the field to its final UTF8 status
- we'll apply such status (and default)
- This has been added on 1.7 because we are in the process of
- converting some fields to NULL and the assumption of all the
- CHAR/TEXT fields being always NOT NULL isn't valid anymore!
- Note that this code will leave remaining NOT NULL fiels
- unmodified at all, folowing the old approach
- */
- if(($cols = $db->MetaColumns($prefix.$dbtablename)) && $fieldname != 'dummy') {
- $cols = array_change_key_case($cols, CASE_LOWER); ///lowercase col names
- $notnull = 'NOT NULL'; ///Old default
- if ($col = $cols[strtolower($fieldname)]) {
- /// If the column was null before UTF-8 migration, save it
- if (!$col->not_null) {
- $notnull = 'NULL';
- /// And, if the column had an empty string as default, make it NULL now
- if ($default == "''") {
- $default = 'NULL';
- }
- }
- }
- }
-
- /* Change to longblob, serves 2 purposes:
- 1. column loses encoding, so when we finally change it to unicode,
- mysql does not do a double convertion
- 2. longblobs puts no limit (ok, not really but it's large enough)
- to handle most of the problems such as in bug 5194
- */
-
- $SQL = 'ALTER TABLE '.$prefix.$dbtablename;
- $SQL.= ' CHANGE '.$fieldname.' '.$fieldname.' LONGBLOB';
-
- /*
- if ($length > 0) {
- $SQL.='('.$length.') ';
- }
- $SQL .= ' CHARACTER SET binary NOT NULL DEFAULT '.$default.';';
- */
- if ($debug) {
- $db->debug=999;
- }
- if ($fieldname != 'dummy') {
- execute_sql($SQL, $debug);
- }
- if ($debug) {
- $db->debug=0;
- }
-
- }
-
- $patterns[]='/RECORDID/'; //for preg_replace
- $patterns[]='/\{\$CFG\-\>prefix\}/i'; //same here
-
- if ($method == 'PLAIN_SQL_UPDATE') {
- $sqldetectuser = $field['#']['SQL_DETECT_USER'][0]['#'];
- $sqldetectcourse = $field['#']['SQL_DETECT_COURSE'][0]['#'];
- }
- else if ($method == 'PHP_FUNCTION') {
- $phpfunction = 'migrate2utf8_'.$dbtablename.'_'.$fieldname;
- }
-
- ///get the total number of records for this field
-
- // could not use count_records because it addes prefix to adodb_logsql
- $totalrecords = count_records_sql("select count(*) from {$prefix}$dbtablename");
- $counter = 0;
- $recordsetsize = 50;
-
- if ($crash) { //if resuming from crash
- //find the number of records with id smaller than the crash id
- $indexSQL = 'SELECT COUNT(*) FROM '.$prefix.$dbtablename.' WHERE id < '.$crash->record;
- $counter = count_records_sql($indexSQL);
- }
-
- if ($debug) {
- echo "
Total number of records is ..".$totalrecords;
- echo "
Counter is $counter";
- }
-
-
- /**************************
- * converting each record *
- **************************/
- while(($counter < $totalrecords) and ($fieldname !='dummy') and ($method!='NO_CONV')) { //while there is still something
- $SQL = 'SELECT * FROM '.$prefix.$dbtablename.' ORDER BY id ASC';
- if ($records = get_records_sql($SQL, $counter, $recordsetsize)) {
- foreach ($records as $record) {
-
- //if we are up this far, either no crash, or crash with same table, field name.
- if ($crash){
- if ($crash->record != $record->id) { //might set to < just in case record is deleted
- continue;
- } else {
- $crash = 0;
- }
- }
-
- $migrationconfig = get_record('config','name','dbmigration');
- $migrationconfig->name = 'dbmigration';
- $migrationconfig->value = $dbtablename.'##'.$fieldname.'##'.$record->id;
- update_record('config',$migrationconfig);
-
- $replacements = array(); //manual refresh
- $replacements[] = $record->id;
- $replacements[] = $prefix;
-
- if (!empty($record->{$fieldname})) { //only update if not empty
- switch ($method){
- case 'PLAIN_SQL_UPDATE': //use the 2 statements to update
-
- if ($debug) {
- $db->debug=999;
- }
-
- //if global lang is set, we just use that
-
- if ($globallang) {
- $fromenc = $globallang;
- } else {
- $userid = get_record_sql(preg_replace($patterns, $replacements, $sqldetectuser));
- $courseid = get_record_sql(preg_replace($patterns, $replacements, $sqldetectcourse));
-
- $sitelang = $CFG->lang;
- $courselang = get_course_lang(isset($courseid->course)?$courseid->course:1);
- $userlang = get_user_lang(isset($userid->userid)?$userid->userid:1);
-
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
- //only update if non utf8
- if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) {
- $result = utfconvert($record->{$fieldname}, $fromenc);
- $newrecord = new object;
- $newrecord->id = $record->id;
- $newrecord->{$fieldname} = $result;
- migrate2utf8_update_record($dbtablename,$newrecord);
- }
- if ($debug) {
- $db->debug=0;
- }
- break;
-
- case 'PHP_FUNCTION': //use the default php function to execute
- if ($debug) {
- $db->debug=999;
- }
- require_once($CFG->dirroot.'/'.$dir.'/db/migrate2utf8.php');
- $phpfunction($record->id);
- if ($debug) {
- $db->debug=0;
- }
- break;
-
- default: //no_conv, don't do anything ;-)
- break;
- }
- }
- $counter++;
- if ($maxrecords) {
- if ($processedrecords == $maxrecords) {
- notify($maxrecords.' records processed. Migration Process halted');
- print_continue('utfdbmigrate.php?confirm=1&maxrecords='.$maxrecords.'&sesskey='.sesskey());
- print_footer();
- die();
- }
- }
-
- $processedrecords++;
- //print some output once in a while
- if (($processedrecords) % 1000 == 0) {
- print_progress($done, $tablestoconvert, 5, 1,
- 'Processing: '.$dbtablename.'/'.$fieldname.' ');
- }
- }
- }else {
- if ($debug) {
- notify('no records found!');
- }
- }
- } //close the while loop
-
- /********************
- * Drop index here **
- ********************/
-
- if ($CFG->dbtype == 'mysql') {
-
- /*********************************
- * Change column encoding 2 phase*
- *********************************/
-
- /*
- $SQL = 'ALTER TABLE '.$CFG->prefix.$dbtablename;
- $SQL.= ' CHANGE '.$fieldname.' '.$fieldname.' LONGTEXT';
- // if ($length > 0) {
- // $SQL.='('.$length.') ';
- // }
- $SQL .= ' CHARACTER SET binary NOT NULL DEFAULT '.$default.';';
- if ($debug) {
- $db->debug=999;
- }
- if ($fieldname != 'dummy') {
- execute_sql($SQL, $debug);
- }
- if ($debug) {
- $db->debug=0;
- }*/
- //phase 2
- $SQL = 'ALTER TABLE '.$prefix.$dbtablename;
- $SQL.= ' CHANGE '.$fieldname.' '.$fieldname.' '.$type;
- if ($length > 0) {
- $SQL.='('.$length.') ';
- }
- $SQL.=' CHARACTER SET utf8 ' . $notnull . ' DEFAULT '. $default . ';';
- if ($debug) {
- $db->debug=999;
- }
- if ($fieldname != 'dummy') {
- execute_sql($SQL, $debug);
- }
- if ($debug) {
- $db->debug=0;
- }
- /********************************************
- * build an array to add index back together*
- ********************************************/
- if ($addindex){
- $addindexarray[] = $addindex;
- } else if ($adduniqueindex) {
- $adduniqueindexarray[] = $adduniqueindex;
- } else if ($addprimary) {
- $addprimaryarray[] = $addprimary;
- }
-
- } else {
-
- //posgresql code here
- //No we don't need to do anything here
-
- }
-
- }
-
- /********************************
- * Adding the index back *
- ********************************/
- $alter = 0;
-
- if ($CFG->dbtype=='mysql'){
-
- $SQL = 'ALTER TABLE '.$prefix.$dbtablename;
- /*
- NOTE: We aren't going to create the indexes back here any more because they
- are going to be recreated at the end of the table iteration with
- the info saved at the begining of it.
-
- if (!empty($addindexarray)) {
- foreach ($addindexarray as $aidx){
- $SQL .= ' ADD INDEX '.$aidx.',';
- $alter++;
- }
- }
-
- if (!empty($adduniqueindexarray)) {
- foreach ($adduniqueindexarray as $auidx){
- $SQL .= ' ADD UNIQUE INDEX '.$auidx.',';
- $alter++;
- }
- }
- */
-
- if (!empty($addprimaryarray)) {
- foreach ($addprimaryarray as $apm){
- $SQL .= ' ADD PRIMARY KEY '.$apm.',';
- $alter++;
- }
- }
-
- $SQL = rtrim($SQL, ', ');
- $SQL.=';';
-
- } else {
- ///posgresql code here
- ///No we don't need to do anything here
-
- }
-
- if ($alter) {
- if ($debug) {
- $db->debug=999;
- }
- execute_sql($SQL, $debug);
- if ($debug) {
- $db->debug=0;
- }
- }
-
- } //if there are fields
-
-
- } /// Point 1 - bypass should end here.
-
-
- /************************************
- * now we modify the table encoding *
- ************************************/
- if ($CFG->dbtype=='mysql'){
- $SQL = 'ALTER TABLE '.$prefix.$dbtablename.' CHARACTER SET utf8';
- if ($debug) {
- $db->debug=999;
- }
- execute_sql($SQL, $debug);
- if ($debug) {
- $db->debug=0;
- }
-
- } else {
-
- ///posgresql code here
- ///No we don't need to do anything here
- }
-
- /// Recreate all the indexes previously dropped and sent to backup
- /// tables. Retrieve information from backup tables
- if ($backupindexes = backup_getid(BACKUP_UNIQUE_CODE, $prefix.$dbtablename, 1)) {
- /// Confirm we have indexes
- if ($allindexes = $backupindexes->info) {
- /// Recreate all the indexes
- $sqlarr = array();
- foreach ($allindexes as $onekey => $oneindex) {
- $unique = $oneindex['unique']? 'UNIQUE ' : '';
- $sqlarr[] = 'ALTER TABLE '.$prefix.$dbtablename.' ADD '.$unique.'INDEX '.$onekey.
- ' ('.implode(', ', $oneindex['columns']).')';
- }
- execute_sql_arr($sqlarr, true, $debug);
- }
- }
- }
- }
-
- if ($CFG->dbtype=='mysql') {
- /*********************************
- * now we modify the db encoding *
- *********************************/
- $SQL = 'ALTER DATABASE '.$CFG->dbname.' CHARACTER SET utf8';
- execute_sql($SQL, $debug);
- } else {
- if (!is_postgres_utf8()) {
- //This old database is now deprecated
- set_config('migrated_to_new_db','1');
- }
- }
- delete_records('config','name','dbmigration'); //bye bye
-
- //These have to go!
- if ($debug) {
- $db->debug=true;
- }
-
- if ($CFG->dbtype == 'postgres7') {
- $backup_db = $GLOBALS['db'];
- $GLOBALS['db'] = &get_postgres_db();
- }
-
- execute_sql('TRUNCATE TABLE '.$CFG->prefix.'cache_text', $debug);
- execute_sql('TRUNCATE TABLE '.$CFG->prefix.'cache_filters', $debug);
-
- if ($CFG->dbtype == 'postgres7') {
- $GLOBALS['db'] = $backup_db;
- unset($backup_db);
- }
- if ($debug) {
- $db->debug=0;
- }
-
- //update site language
- $sitelanguage = get_record('config','name', 'lang');
- if (strstr($sitelanguage->value, 'utf8')===false and $sitelanguage->value) {
- $sitelanguage->value.='_utf8';
- migrate2utf8_update_record('config',$sitelanguage);
- }
-
- //finish the javascript bar
- $done = $tablestoconvert;
- print_progress($done, $tablestoconvert, 5, 1);
-
- //prints the list of langs used in this site
- print_simple_box_start('center','50%');
- echo '
The following Language Packs are needed for your users and courses. Please install the following Language Packs:
';
- $langsused = get_record('config','name', 'langsused');
- $langs = explode (',',$langsused->value);
-
- foreach ($langs as $lang) {
- if (!empty($lang) and $lang != 'en_utf8') {
- echo $lang.', ';
- }
- }
- echo 'Language Import Utility';
- print_simple_box_end();
- delete_records('config','name','langsused');
-
- //remove the cache file!
- @unlink($CFG->dataroot.'/cache/languages');
-
- //remove backup temp storage
- if ($CFG->dbtype = 'mysql') {
- $pref->backup_unique_code = BACKUP_UNIQUE_CODE;
- clean_temp_data($pref);
- }
-
- // Regenerate some cached data
-
- if ($CFG->dbtype == 'mysql') {
- $db->Execute("SET NAMES 'utf8'");
- } else if ($CFG->dbtype == 'postgres7') {
- $db->Execute("SET NAMES 'utf8'");
- }
-
- rebuild_course_cache();
-
- //set the final flag
- migrate2utf8_set_config('unicodedb','true'); //this is the main flag for unicode db
-
- //echo date("H:i:s");
-}
-
-
-/* returns the course lang
- * @param int courseid
- * @return string
- */
-function get_course_lang($courseid) {
-
- static $coursecache;
-
- if (!isset($coursecache[$courseid])) {
- if ($course = get_record('course','id',$courseid)){
- $coursecache[$courseid] = $course->lang;
- return $course->lang;
- }
- return false;
- } else {
- return $coursecache[$courseid];
- }
-}
-
-/* returns the teacher's lang
- * @param int courseid
- * @return string
- */
-function get_main_teacher_lang($courseid) {
- //editting teacher > non editting teacher
- global $CFG;
- static $mainteachercache;
-
- if ($courseid == SITEID || $courseid==0) {
- $admin = get_admin();
- $mainteachercache[$courseid] = $admin->lang;
- return $admin->lang;
- }
-
- if (!isset($mainteachercache[$courseid])) {
-
- /// this is a worse guess
- if (!empty($CFG->rolesactive)) {
-
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
- $teachers = get_users_by_capability($context, 'moodle/legacy:editingteacher', 'u.id, u.lang', 'ra.id ASC', 0, 1); // only need first one
- if (is_array($teachers)) {
- $teacher = reset($teachers);
- $mainteachercache[$courseid] = $teacher->lang;
- return $teacher->lang;
- }
- /// this is a better guess
- } else {
-
- $SQL = 'SELECT u.id, u.lang
- FROM '.$CFG->prefix.'user_teachers ut,
- '.$CFG->prefix.'course c,
- '.$CFG->prefix.'user u
- WHERE c.id = ut.course AND
- ut.course = '.$courseid.' AND
- u.id = ut.userid
- ORDER BY ut.authority ASC';
-
- if ($teacher = get_record_sql($SQL, true)) {
- $mainteachercache[$courseid] = $teacher->lang;
- return $teacher->lang;
- }
- }
- /// Arriving here we haven't been able to select any teacher lang
- /// so use the admin lang
- $admin = get_admin();
- $mainteachercache[$courseid] = $admin->lang;
- return $admin->lang;
- } else {
- return $mainteachercache[$courseid];
- }
-}
-
-function get_original_encoding($sitelang, $courselang, $userlang){
-
- global $CFG, $enc;
-
- $lang = '';
- if ($courselang) {
- $lang = $courselang;
- }
- else if ($userlang) {
- $lang = $userlang;
- }
- else if ($sitelang) {
- $lang = $sitelang;
- }
- else {
- error ('no language found!');
- }
-
- if ($enc[$lang]) {
- return $enc[$lang];
- } else {
- notify ('unknown language detected: '.$lang);
- return false;
- }
-}
-
-/* returns the user's lang
- * @param int userid
- * @return string
- */
-function get_user_lang($userid) {
-
- static $usercache;
-
- if (!isset($usercache[$userid])) {
- if ($user = get_record('user','id',$userid)) {
- $usercache[$userid] = $user->lang;
- return $user->lang;
- }
- } else {
- return $usercache[$userid];
- }
- return false;
-}
-
-// a placeholder for now
-function log_the_problem_somewhere() { //Eloy: Nice function, perhaps we could use it, perhpas no. :-)
- global $CFG, $dbtablename, $fieldname, $record;
- if ($CFG->debug>7) {
- echo "
Problem converting: $dbtablename -> $fieldname -> {$record->id}!";
- }
-}
-
-// only this function should be used during db migraton, because of addslashes at the end of the convertion
-function utfconvert($string, $enc, $slash=true) {
- global $textlib;
- if ($result = $textlib->convert($string, $enc)) {
- if ($slash) {
- $result = addslashes($result);
- }
- }
- return $result;
-}
-
-function validate_form(&$form, &$err) {
- global $CFG;
-
- $newdb = &ADONewConnection('postgres7');
- error_reporting(0); // Hide errors
- $dbconnected = $newdb->Connect($form->dbhost,$form->dbuser,$form->dbpass,$form->dbname);
- error_reporting($CFG->debug); // Show errors
- if (!$dbconnected) {
- $err['dbconnect'] = get_string('dbmigrateconnecerror', 'admin');
- return;
- }
-
- if (!is_postgres_utf8($newdb)) {
- $encoding = $newdb->GetOne('SHOW server_encoding');
- $err['dbconnect'] = get_string('dbmigrateencodingerror', 'admin', $encoding);
- return;
- }
-
- if (!empty($form->pathtopgdump) && !is_executable($form->pathtopgdump)) {
- $err['pathtopgdump'] = get_string('pathtopgdumpinvalid','admin');
- return;
- }
-
- if (!empty($form->pathtopsql) && !is_executable($form->pathtopsql)) {
- $err['pathtopsql'] = get_string('pathtopsqlinvalid','admin');
- return;
- }
-
- return;
-}
-
-function is_postgres_utf8($thedb = null) {
- if ($thedb === null) {
- $thedb = &$GLOBALS['db'];
- }
-
- $db_encoding_postgres = $thedb->GetOne('SHOW server_encoding');
- if (strtoupper($db_encoding_postgres) == 'UNICODE' || strtoupper($db_encoding_postgres) == 'UTF8') {
- return true;
- } else {
- return false;
- }
-}
-
-function &get_postgres_db() {
- static $postgres_db;
-
- if (!$postgres_db) {
- if (is_postgres_utf8()) {
- $postgres_db = &$GLOBALS['db'];
- } else {
- $postgres_db = &ADONewConnection('postgres7');
- $postgres_db->Connect($_SESSION['newpostgresdb']->dbhost,$_SESSION['newpostgresdb']->dbuser,$_SESSION['newpostgresdb']->dbpass,$_SESSION['newpostgresdb']->dbname);
- }
- }
-
- return $postgres_db;
-}
-
-function is_postgres_setup() {
- $postgres_db = &get_postgres_db();
-
- return $GLOBALS['db']->MetaTables() == $postgres_db->MetaTables();
-}
-
-function migrate2utf8_update_record($table,$record) {
- global $CFG;
-
- if ($CFG->dbtype == 'mysql') {
- update_record($table,$record);
- } else {
- $backup_db = $GLOBALS['db'];
- $GLOBALS['db'] = &get_postgres_db();
- global $in;
- $in = true;
- update_record($table,$record);
- $GLOBALS['db'] = $backup_db;
- }
-}
-
-function migrate2utf8_set_config($name, $value, $plugin=NULL) {
- global $CFG;
- if ($CFG->dbtype == 'mysql') {
- set_config($name, $value, $plugin);
- } else {
- $backup_db = $GLOBALS['db'];
- $GLOBALS['db'] = &get_postgres_db();
- set_config($name, $value, $plugin);
- $GLOBALS['db'] = $backup_db;
- }
-}
-
-// this needs to print an error when a mod does not have a migrate2utf8.xml
-function utf_get_xml ($mode=0) { // if mode is 1, do not perform check for script validity
- global $CFG;
-
- $xmls = array();
- $noscript = 0; // we assume all mod and all blocks have migration scripts
-
- /*****************************************************************************
- * traverse order is mod->backup->block->block_plugin->enroll_plugin->global *
- *****************************************************************************/
-
- ///mod
- if (!$mods = get_list_of_plugins('mod')) {
- error('No modules installed!');
- }
-
- foreach ($mods as $mod){
- if (file_exists($CFG->dirroot.'/mod/'.$mod.'/db/migrate2utf8.xml')) {
- $xmls[] = xmlize(file_get_contents($CFG->dirroot.'/mod/'.$mod.'/db/migrate2utf8.xml'));
- } else if (!$mode) {
- $noscript = 1;
- notify('warning, there is no migration script detected for this module - '.$mod);
- }
- }
-
- ///Backups
- $xmls[] = xmlize(file_get_contents($CFG->dirroot.'/backup/db/migrate2utf8.xml'));
-
- ///Blocks
- $xmls[] = xmlize(file_get_contents($CFG->dirroot.'/blocks/db/migrate2utf8.xml'));
-
- ///Block Plugins
- if (!$blocks = get_list_of_plugins('blocks')) {
- //error('No blocks installed!'); //Eloy: Is this a cause to stop?
- }
-
- foreach ($blocks as $block){
- if (file_exists($CFG->dirroot.'/blocks/'.$block.'/db/migrate2utf8.xml')) {
- $xmls[] = xmlize(file_get_contents($CFG->dirroot.'/blocks/'.$block.'/db/migrate2utf8.xml'));
- } else if (!$mode) {
- if (file_exists($CFG->dirroot.'/blocks/'.$block.'/db/mysql.sql') && filesize($CFG->dirroot.'/blocks/'.$block.'/db/mysql.sql')) { // if no migration script, and have db script, we are in trouble
- notify('warning, there is no migration script detected for this block - '.$block);
- $noscript = 1;
- }
- }
- }
-
- ///Enrol
-
- if (!$enrols = get_list_of_plugins('enrol')) {
- //error('No enrol installed!'); //Eloy: enrol, not blocks :-) Is this a cause to stop?
- }
-
- foreach ($enrols as $enrol){
- if (file_exists($CFG->dirroot.'/enrol/'.$enrol.'/db/migrate2utf8.xml')) {
- $xmls[] = xmlize(file_get_contents($CFG->dirroot.'/enrol/'.$enrol.'/db/migrate2utf8.xml'));
- }
- }
-
- ///Lastly, globals
-
- $xmls[] = xmlize(file_get_contents($CFG->dirroot.'/lib/db/migrate2utf8.xml'));
-
- if ($noscript) {
- notify ('Some of your modules or Blocks do not have a migration script. It is very likely that these are contrib modules. If your Moodle site uses non-UTF8 language packs and non-en language packs, data inside these moduels or blocks will not be displayed correctly after the migration. Please proceed with caution.');
- }
-
- return $xmls;
-
-}
diff --git a/admin/xmldb/actions/get_db_directories/get_db_directories.class.php b/admin/xmldb/actions/get_db_directories/get_db_directories.class.php
index 172f2e6b6b5..2f3ea496fd9 100644
--- a/admin/xmldb/actions/get_db_directories/get_db_directories.class.php
+++ b/admin/xmldb/actions/get_db_directories/get_db_directories.class.php
@@ -141,6 +141,14 @@ class get_db_directories extends XMLDBAction {
$XMLDB->dbdirs[$dbdir->path]->path_exists = file_exists($dbdir->path); //Update status
}
}
+
+ /// Now, groups
+ $dbdir->path = $CFG->dirroot . '/group/db';
+ if (!isset($XMLDB->dbdirs[$dbdir->path])) {
+ $XMLDB->dbdirs[$dbdir->path] = $dbdir;
+ }
+ $XMLDB->dbdirs[$dbdir->path]->path_exists = file_exists($dbdir->path); //Update status
+
/// Sort by key
ksort($XMLDB->dbdirs);
diff --git a/backup/backuplib.php b/backup/backuplib.php
index 611e9321228..987d000eaed 100644
--- a/backup/backuplib.php
+++ b/backup/backuplib.php
@@ -1642,7 +1642,7 @@
$status2 = true;
//Get groups
- $groups = get_records("groups","courseid",$preferences->backup_course);
+ $groups = get_groups($preferences->backup_course); //TODO:check.
//Pring groups header
if ($groups) {
@@ -1692,7 +1692,7 @@
$status = true;
//Get groups_members
- $groups_members = get_records("groups_members","groupid",$groupid);
+ $groups_members = groups_get_members($groupid); //TODO:check.
//Pring groups_members header
if ($groups_members) {
@@ -1869,8 +1869,8 @@
//Iterate
foreach ($list as $dir) {
//Look for dir like group in groups table
- $data = get_record ('groups', 'courseid', $preferences->backup_course,
- 'id',$dir);
+ $data = groups_group_belongs_to_course($dir, $preferences->backup_course);
+ //TODO:check. get_record ('groups', 'courseid', $preferences->backup_course,'id',$dir);
//If exists, copy it
if ($data) {
$status = backup_copy_file($rootdir."/".$dir,
diff --git a/backup/db/migrate2utf8.php b/backup/db/migrate2utf8.php
deleted file mode 100755
index b3af4d4167a..00000000000
--- a/backup/db/migrate2utf8.php
+++ /dev/null
@@ -1,42 +0,0 @@
-lang;
- $courselang = null;
- $userlang = null; //N.E.!!
-
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
-/// Initialise $result
- $result = $backupids->info;
-
-/// Convert the text
- if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) {
- $result = utfconvert($backupids->info, $fromenc);
-
- $newbackupids = new object;
- $newbackupids->id = $recordid;
- $newbackupids->info = $result;
- migrate2utf8_update_record('backup_ids',$newbackupids);
- }
-/// And finally, just return the converted field
- return $result;
-}
-?>
diff --git a/backup/db/migrate2utf8.xml b/backup/db/migrate2utf8.xml
deleted file mode 100755
index 65719b7c25e..00000000000
--- a/backup/db/migrate2utf8.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
-
-
-
-
-
-
- migrate2utf8_backup_ids_info(RECORDID)
-
-
-
-
-
-
-
diff --git a/blocks/admin/block_admin.php b/blocks/admin/block_admin.php
index f8c11688cd4..4284cc3024a 100644
--- a/blocks/admin/block_admin.php
+++ b/blocks/admin/block_admin.php
@@ -88,7 +88,7 @@ class block_admin extends block_list {
if (($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context) && ($course->id!==SITEID)) {
$strgroups = get_string('groups');
- $this->content->items[]='
'.$strgroups.'';
+ $this->content->items[]='
'.$strgroups.'';
$this->content->icons[]='

';
}
diff --git a/blocks/db/migrate2utf8.php b/blocks/db/migrate2utf8.php
deleted file mode 100755
index a19c5b423ec..00000000000
--- a/blocks/db/migrate2utf8.php
+++ /dev/null
@@ -1,190 +0,0 @@
-blockid);
-
- if ($blocktype -> name == 'html') {
-
- ///find course
- if ($globallang) {
- $fromenc = $globallang;
- } else {
- $sitelang = $CFG->lang;
- $courselang = get_course_lang($blockinstance->pageid); //Non existing!
- $userlang = get_main_teacher_lang($blockinstance->pageid); //N.E.!!
-
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
- $blah = unserialize(base64_decode($blockinstance->configdata));
-
- /// We are going to use textlib facilities
-
- /// Convert the text
- $blah->title = utfconvert($blah->title, $fromenc, false);
- $blah->text = utfconvert($blah->text, $fromenc, false);
-
- $blockinstance->configdata = base64_encode(serialize($blah));
-
- migrate2utf8_update_record('block_instance',$blockinstance);
-
- return $blah;
-
- } else if ($blocktype -> name == 'rss_client'){
-
- ///find course
- if ($globallang) {
- $fromenc = $globallang;
- } else {
- $sitelang = $CFG->lang;
- $courselang = get_course_lang($blockinstance->pageid); //Non existing!
- $userlang = get_main_teacher_lang($blockinstance->pageid); //N.E.!!
-
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
- $blah = unserialize(base64_decode($blockinstance->configdata));
-
- /// We are going to use textlib facilities
-
- /// Convert the text
- $blah->title = utfconvert($blah->title, $fromenc, false);
-
- $blockinstance->configdata = base64_encode(serialize($blah));
-
- migrate2utf8_update_record('block_instance',$blockinstance);
-
- return $blah;
-
- } else if ($blocktype -> name == 'glossary_random'){
-
- ///find course
- if ($globallang) {
- $fromenc = $globallang;
- } else {
- $sitelang = $CFG->lang;
- $courselang = get_course_lang($blockinstance->pageid); //Non existing!
- $userlang = get_main_teacher_lang($blockinstance->pageid); //N.E.!!
-
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
- $blah = unserialize(base64_decode($blockinstance->configdata));
-
- /// We are going to use textlib facilities
-
- /// Convert the text
- $blah->title = utfconvert($blah->title, $fromenc, false);
- $blah->addentry = utfconvert($blah->addentry, $fromenc, false);
- $blah->viewglossary = utfconvert($blah->viewglossary, $fromenc, false);
- $blah->invisible = utfconvert($blah->invisible, $fromenc, false);
-
- $blockinstance->configdata = base64_encode(serialize($blah));
-
- migrate2utf8_update_record('block_instance',$blockinstance);
-
- return $blah;
-
- }
-
-}
-
-function migrate2utf8_block_pinned_configdata($recordid){
-global $CFG, $globallang;
-
- $blockpinned = get_record('block_pinned','id',$recordid);
-
- //get block instance type, we only need to worry about HTML blocks... right?????????
-
- $blocktype = get_record('block','id',$blockpinned->blockid);
-
- if ($blocktype -> name == 'html') {
-
- ///find course
- if ($globallang) {
- $fromenc = $globallang;
- } else {
- $sitelang = $CFG->lang;
- $courselang = get_course_lang($blockpinned->pageid); //Non existing!
- $userlang = get_main_teacher_lang($blockpinned->pageid); //N.E.!!
-
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
- $blah = unserialize(base64_decode($blockpinned->configdata));
-
- /// We are going to use textlib facilities
-
- /// Convert the text
- $blah->title = utfconvert($blah->title, $fromenc, false);
- $blah->text = utfconvert($blah->text, $fromenc, false);
-
- $blockpinned->configdata = base64_encode(serialize($blah));
-
- migrate2utf8_update_record('blockpinned',$blockpinned);
-
- return $blah;
-
- } else if ($blocktype -> name == 'rss_client'){
-
- ///find course
- if ($globallang) {
- $fromenc = $globallang;
- } else {
- $sitelang = $CFG->lang;
- $courselang = get_course_lang($blockpinned->pageid); //Non existing!
- $userlang = get_main_teacher_lang($blockpinned->pageid); //N.E.!!
-
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
- $blah = unserialize(base64_decode($blockpinned->configdata));
-
- /// We are going to use textlib facilities
-
- /// Convert the text
- $blah->title = utfconvert($blah->title, $fromenc, false);
-
- $blockpinned->configdata = base64_encode(serialize($blah));
-
- migrate2utf8_update_record('blockpinned',$blockblockpinned);
-
- return $blah;
-
- } else if ($blocktype -> name == 'glossary_random'){
-
- ///find course
- if ($globallang) {
- $fromenc = $globallang;
- } else {
- $sitelang = $CFG->lang;
- $courselang = get_course_lang($blockpinned->pageid); //Non existing!
- $userlang = get_main_teacher_lang($blockpinned->pageid); //N.E.!!
-
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
- $blah = unserialize(base64_decode($blockpinned->configdata));
-
- /// We are going to use textlib facilities
-
- /// Convert the text
- $blah->title = utfconvert($blah->title, $fromenc, false);
- $blah->addentry = utfconvert($blah->addentry, $fromenc, false);
- $blah->viewglossary = utfconvert($blah->viewglossary, $fromenc, false);
- $blah->invisible = utfconvert($blah->invisible, $fromenc, false);
-
- $blockinstance->configdata = base64_encode(serialize($blah));
-
- migrate2utf8_update_record('block_instance',$blockinstance);
-
- return $blah;
-
- }
-}
-?>
diff --git a/blocks/db/migrate2utf8.xml b/blocks/db/migrate2utf8.xml
deleted file mode 100755
index c6cbd2ff1be..00000000000
--- a/blocks/db/migrate2utf8.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
-
-
-
- migrate2utf8_block_instance_configdata(RECORDID)
-
-
-
-
-
-
-
-
-
-
- migrate2utf8_block_pinned_configdata(RECORDID)
-
-
-
-
-
-
diff --git a/blocks/online_users/block_online_users.php b/blocks/online_users/block_online_users.php
index c0d10062f1a..b7c2a2627f6 100644
--- a/blocks/online_users/block_online_users.php
+++ b/blocks/online_users/block_online_users.php
@@ -50,8 +50,8 @@ class block_online_users extends block_base {
//Add this to the SQL to show only group users
if ($currentgroup !== NULL) {
- $groupmembers = ", {$CFG->prefix}groups_members gm ";
- $groupselect .= " AND u.id = gm.userid AND gm.groupid = '$currentgroup'";
+ $groupmembers = ', '.groups_members_from_sql(); //TODO: ", {$CFG->prefix}groups_members gm ";
+ $groupselect .= groups_members_where_sql($currentgroup, 'u.id'); //" AND u.id = gm.userid AND gm.groupid = '$currentgroup'";
}
if ($COURSE->id == SITEID) { // Site-level
diff --git a/blocks/pagedemo.php b/blocks/pagedemo.php
deleted file mode 100644
index c6de2ab3c01..00000000000
--- a/blocks/pagedemo.php
+++ /dev/null
@@ -1,204 +0,0 @@
-dirroot .'/course/lib.php');
- require_once($CFG->dirroot .'/lib/blocklib.php');
- require_once($CFG->dirroot .'/mod/resource/lib.php');
- require_once($CFG->dirroot .'/mod/forum/lib.php');
-
- optional_param('blockaction');
- optional_param('instanceid', 0, PARAM_INT);
- optional_param('blockid', 0, PARAM_INT);
-
- require_login();
-
- // Begin snippet -----------------------------------------------------------------
- // This snippet should normally be defined in another file, but I 've put it all
- // in here to keep it simple.
-
- // First of all define the string identifier for this "type" of page.
- define('MOODLE_PAGE_TEST', 'testpage');
-
- // Also, define identifiers for any non-standard block positions we want to support.
- define('BLOCK_POS_CENTERUP', 'cu');
- define('BLOCK_POS_CENTERDOWN', 'cd');
-
- // The actual Page derived class
- class page_test extends page_base {
-
- // Mandatory; should return our identifier.
- function get_type() {
- return MOODLE_PAGE_TEST;
- }
-
- // For this test page, only admins are going to be allowed editing (for simplicity).
- function user_allowed_editing() {
- return isadmin();
- }
-
- // Also, admins are considered to have "always on" editing (I wanted to avoid duplicating
- // the code that turns editing on/off here; you can roll your own or copy course/view.php).
- function user_is_editing() {
- return isadmin();
- }
-
- // Simple method that accepts one parameter and prints the header. Here we just ignore
- // the parameter entirely.
- function print_header($title) {
- print_header("Page testing page", 'SAMPLE CUSTOM PAGE', 'home');
- }
-
- // This should point to the script that displays us; it's straightforward in this case.
- function url_get_path() {
- global $CFG;
- return $CFG->wwwroot .'/blocks/pagedemo.php';
- }
-
- // We do not need any special request variables such as ID in this case, so we 're not
- // going to have to override url_get_parameters() here; the default suits us nicely.
-
- // Having defined all identifiers we need, here we declare which block positions we are
- // going to support.
- function blocks_get_positions() {
- return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT, BLOCK_POS_CENTERUP, BLOCK_POS_CENTERDOWN);
- }
-
- // And here we declare where new blocks will appear (arbitrary choice).
- function blocks_default_position() {
- return BLOCK_POS_CENTERUP;
- }
-
- // Since we 're not going to be creating multiple instances of this "page" (as we do with
- // courses), we don't need to provide default blocks. Otherwise we 'd need to override
- // the blocks_get_default() method.
-
- // And finally, a little block move logic. Given a block's previous position and where
- // we want to move it to, return its new position. Pretty self-documenting.
- function blocks_move_position(&$instance, $move) {
- if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
- return BLOCK_POS_CENTERUP;
- } else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
- return BLOCK_POS_CENTERUP;
- } else if (($instance->position == BLOCK_POS_CENTERUP || $instance->position == BLOCK_POS_CENTERDOWN) && $move == BLOCK_MOVE_LEFT) {
- return BLOCK_POS_LEFT;
- } else if (($instance->position == BLOCK_POS_CENTERUP || $instance->position == BLOCK_POS_CENTERDOWN) && $move == BLOCK_MOVE_RIGHT) {
- return BLOCK_POS_RIGHT;
- } else if ($instance->position == BLOCK_POS_CENTERUP && $move == BLOCK_MOVE_DOWN) {
- return BLOCK_POS_CENTERDOWN;
- } else if ($instance->position == BLOCK_POS_CENTERDOWN && $move == BLOCK_MOVE_UP) {
- return BLOCK_POS_CENTERUP;
- }
- return $instance->position;
- }
- }
- // End snippet -------------------------------------------------------------------
-
- /// Bounds for block widths on this page
- define('BLOCK_L_MIN_WIDTH', 160);
- define('BLOCK_L_MAX_WIDTH', 210);
- define('BLOCK_R_MIN_WIDTH', 160);
- define('BLOCK_R_MAX_WIDTH', 210);
- define('BLOCK_C_MIN_WIDTH', 250);
- define('BLOCK_C_MAX_WIDTH', 350);
-
-
- // Before creating our page object, we need to map our page identifier to the actual name
- // of the class which will be handling its operations. Pretty simple, but essential.
- page_map_class(MOODLE_PAGE_TEST, 'page_test');
-
- // Now, create our page object. The identifier "1" is passed arbitrarily because we don't
- // have multiple "testpages"; if we did, that would be the "testpageid" from the database.
- $PAGE = page_create_object(MOODLE_PAGE_TEST, 1);
-
- $PAGE->print_header(NULL);
- $editing = $PAGE->user_is_editing();
-
- // That's it! From now on, everything is simply copy-pasted from course/view.php with a few
- // minor tweaks to display the page layout!
-
- // Calculate the preferred width for left, right and center (both center positions will use the same)
- if (empty($preferred_width_left)) {
- $preferred_width_left = blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]);
- }
- if (empty($preferred_width_right)) {
- $preferred_width_right = blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]);
- }
- if (empty($preferred_width_centerup)) {
- $preferred_width_centerup = blocks_preferred_width($pageblocks[BLOCK_POS_CENTERUP]);
- }
- if (empty($preferred_width_centerdown)) {
- $preferred_width_centerdown = blocks_preferred_width($pageblocks[BLOCK_POS_CENTERDOWN]);
- }
- $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH);
- $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH);
- $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH);
- $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH);
- $preferred_width_center = max($preferred_width_centerup, $preferred_width_centerdown);
- $preferred_width_center = min($preferred_width_center, BLOCK_C_MAX_WIDTH);
- $preferred_width_center = max($preferred_width_center, BLOCK_C_MIN_WIDTH);
-
- // Display the blocks and allow blocklib to handle any block action requested
- $pageblocks = blocks_get_by_page($PAGE);
-
- if($editing) {
- if (!empty($blockaction) && confirm_sesskey()) {
- if (!empty($blockid)) {
- blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
-
- }
- else if (!empty($instanceid)) {
- $instance = blocks_find_instance($instanceid, $pageblocks);
- blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
- }
- // This re-query could be eliminated by judicious programming in blocks_execute_action(),
- // but I'm not sure if it's worth the complexity increase...
- $pageblocks = blocks_get_by_page($PAGE);
- }
- }
-
- // The actual display logic is here
- echo '
';
-
- if(blocks_have_content($pageblocks,BLOCK_POS_LEFT) || $editing) {
- echo '| ';
- blocks_print_group($PAGE, $pageblocks,BLOCK_POS_LEFT);
- echo ' | ';
- }
-
- echo 'Center-up position: ';
- if(blocks_have_content($pageblocks,BLOCK_POS_CENTERUP) || $editing) {
- blocks_print_group($PAGE, $pageblocks,BLOCK_POS_CENTERUP);
- }
-
- echo 'Content Here';
-
- print_object(make_timestamp(2005, 6, 1, 0, 0, 0));
-
- echo ' ';
-
- echo 'Center-down position: ';
- if(blocks_have_content($pageblocks,BLOCK_POS_CENTERDOWN) || $editing) {
- blocks_print_group($PAGE, $pageblocks,BLOCK_POS_CENTERDOWN);
- }
- echo ' | ';
-
- if(blocks_have_content($pageblocks,BLOCK_POS_RIGHT) || $editing) {
- echo '';
- blocks_print_group($PAGE, $pageblocks,BLOCK_POS_RIGHT);
- if ($editing) {
- blocks_print_adminblock($PAGE, $pageblocks);
- }
- echo ' | ';
- }
-
- // Finished! :-)
-
- echo '
';
- print_footer();
-
-
-?>
diff --git a/blocks/quiz_results/block_quiz_results.php b/blocks/quiz_results/block_quiz_results.php
index c6e54093e7a..f0e8aaff75f 100644
--- a/blocks/quiz_results/block_quiz_results.php
+++ b/blocks/quiz_results/block_quiz_results.php
@@ -127,10 +127,10 @@ class block_quiz_results extends block_base {
}
// Now find which groups these users belong in
- $groupofuser = get_records_sql(
+ $groupofuser = groups_get_groups_users($userids, $courseid); /*TODO: get_records_sql(
'SELECT m.userid, m.groupid, g.name FROM '.$CFG->prefix.'groups g LEFT JOIN '.$CFG->prefix.'groups_members m ON g.id = m.groupid '.
'WHERE g.courseid = '.$courseid.' AND m.userid IN ('.implode(',', $userids).')'
- );
+ );*/
$groupgrades = array();
diff --git a/blocks/rss_client/db/migrate2utf8.php b/blocks/rss_client/db/migrate2utf8.php
deleted file mode 100755
index 7149f4546ad..00000000000
--- a/blocks/rss_client/db/migrate2utf8.php
+++ /dev/null
@@ -1,140 +0,0 @@
-userid);
-
- $sitelang = $CFG->lang;
- $courselang = NULL; //Non existing!
- $userlang = $user->lang; //N.E.!!
-
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
-/// We are going to use textlib facilities
-
-/// Convert the text
- if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) {
- $result = utfconvert($rssclient->title, $fromenc);
-
- $newrssclient = new object;
- $newrssclient->id = $recordid;
- $newrssclient->title = $result;
- migrate2utf8_update_record('block_rss_client',$newrssclient);
- }
-/// And finally, just return the converted field
- return $result;
-}
-
-function migrate2utf8_block_rss_client_preferredtitle($recordid){
- global $CFG, $globallang;
-
-/// Some trivial checks
- if (empty($recordid)) {
- log_the_problem_somewhere();
- return false;
- }
-
- $SQL = "SELECT brc.userid
- FROM {$CFG->prefix}block_rss_client brc
- WHERE brc.id = $recordid";
-
- if (!$rssuserid = get_record_sql($SQL)) {
- log_the_problem_somewhere();
- return false;
- }
-
- if (!$rssclient = get_record('block_rss_client','id',$recordid)) {
- log_the_problem_somewhere();
- return false;
- }
-
-
- if ($globallang) {
- $fromenc = $globallang;
- } else {
- $user = get_record('user','id',$rssuserid->userid);
- $sitelang = $CFG->lang;
- $courselang = NULL; //Non existing!
- $userlang = $user->lang; //N.E.!!
-
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
-/// We are going to use textlib facilities
-
-/// Convert the text
- if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) {
- $result = utfconvert($rssclient->preferredtitle, $fromenc);
-
- $newrssclient = new object;
- $newrssclient->id = $recordid;
- $newrssclient->preferredtitle = $result;
- migrate2utf8_update_record('block_rss_client',$newrssclient);
-/// And finally, just return the converted field
- }
- return $result;
-}
-
-function migrate2utf8_block_rss_client_description($recordid){
- global $CFG, $globallang;
-
-/// Some trivial checks
- if (empty($recordid)) {
- log_the_problem_somewhere();
- return false;
- }
-
- $SQL = "SELECT brc.userid
- FROM {$CFG->prefix}block_rss_client brc
- WHERE brc.id = $recordid";
-
- if (!$rssuserid = get_record_sql($SQL)) {
- log_the_problem_somewhere();
- return false;
- }
-
- if (!$rssclient = get_record('block_rss_client','id',$recordid)) {
- log_the_problem_somewhere();
- return false;
- }
-
-
- if ($globallang) {
- $fromenc = $globallang;
- } else {
- $user = get_record('user','id',$rssuserid->userid);
- $sitelang = $CFG->lang;
- $courselang = NULL; //Non existing!
- $userlang = $user->lang; //N.E.!!
- $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
- }
-
-/// We are going to use textlib facilities
-
-/// Convert the text
- if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) {
- $result = utfconvert($rssclient->description, $fromenc);
-
- $newrssclient = new object;
- $newrssclient->id = $recordid;
- $newrssclient->description = $result;
- migrate2utf8_update_record('block_rss_client',$newrssclient);
- }
-/// And finally, just return the converted field
- return $result;
-}
-?>
diff --git a/blocks/rss_client/db/migrate2utf8.xml b/blocks/rss_client/db/migrate2utf8.xml
deleted file mode 100755
index 86188be2035..00000000000
--- a/blocks/rss_client/db/migrate2utf8.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
- migrate2utf8_block_rss_client_title(RECORDID)
-
-
-
-
- migrate2utf8_block_rss_client_preferredtitle(RECORDID)
-
-
-
-
- migrate2utf8_block_rss_client_description(RECORDID)
-
-
-
-
-
-
-
diff --git a/blog/header.php b/blog/header.php
index b127250957f..a5c1002bdf3 100755
--- a/blog/header.php
+++ b/blog/header.php
@@ -127,17 +127,18 @@ if (!$course = get_record('course', 'id', $courseid)) {
case 'group':
- $thisgroup = get_record('groups', 'id', $filterselect);
-
- if ($tagid || !empty($tag)) {
- print_header("$course->shortname: $blogstring", $course->fullname,
+ if ($thisgroup = groups_get_group($filterselect, false)) { //TODO:
+ if ($tagid || !empty($tag)) {
+ print_header("$course->shortname: $blogstring", $course->fullname,
'
'.$thisgroup->name.' ->
'. "$blogstring -> $tagstring: $taginstance->text",'','',true,$PAGE->get_extra_header_string());
- } else {
- print_header("$course->shortname: $blogstring", $course->fullname,
+ } else {
+ print_header("$course->shortname: $blogstring", $course->fullname,
'
'.$thisgroup->name." ->
$blogstring",'','',true,$PAGE->get_extra_header_string());
-
+ }
+ } else {
+ print_error('Unable to find group');
}
break;
diff --git a/blog/index.php b/blog/index.php
index c1465945f3b..4ea6ceccb5b 100755
--- a/blog/index.php
+++ b/blog/index.php
@@ -84,7 +84,7 @@ switch ($filtertype) {
if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
error('Group blogs is not enabled');
}
- if (!$group = get_record('groups','id',$groupid)) {
+ if (! $group = groups_get_group($groupid)) { //TODO:check.
error('Incorrect group id specified');
}
if (!$course = get_record('course', 'id', $group->courseid)) {
diff --git a/blog/lib.php b/blog/lib.php
index 655e14bbb24..f2c89f13786 100755
--- a/blog/lib.php
+++ b/blog/lib.php
@@ -548,13 +548,20 @@
case 'group':
$SQL = 'SELECT '.$requiredfields.' FROM '.$CFG->prefix.'post p, '.$tagtablesql
+ .groups_members_from_sql().', '.$CFG->prefix.'user u
+ WHERE '.groups_members_where_sql($filterselect, 'p.userid').'
+ AND u.id = p.userid
+ AND u.deleted = 0
+ AND '.$permissionsql;
+
+ /*'SELECT '.$requiredfields.' FROM '.$CFG->prefix.'post p, '.$tagtablesql
.$CFG->prefix.'groups_members m, '.$CFG->prefix.'user u
WHERE p.userid = m.userid '.$tagquerysql.'
AND u.id = p.userid
AND m.groupid = '.$filterselect.'
AND u.deleted = 0
AND '.$permissionsql;
-
+ */
break;
case 'user':
diff --git a/blog/rsslib.php b/blog/rsslib.php
index f8e7ec20fc8..722b79a08c2 100755
--- a/blog/rsslib.php
+++ b/blog/rsslib.php
@@ -99,7 +99,8 @@
$info = $SITE->fullname;
break;
case 'group':
- $info = get_field('groups', 'name', 'id', $id);
+ $group = groups_get_group($id, false);
+ $info = $group->name; //TODO: get_field('groups', 'name', 'id', $id)
break;
default:
$info = '';
diff --git a/calendar/event.php b/calendar/event.php
index d5491c24580..bc6e76a579c 100644
--- a/calendar/event.php
+++ b/calendar/event.php
@@ -413,7 +413,7 @@
break;
case 'group':
$groupid = optional_param('groupid', 0, PARAM_INT);
- if(!($group = get_record('groups', 'id', $groupid) )) {
+ if (! ($group = groups_get_group($groupid))) { //TODO:check.
calendar_get_allowed_types($allowed);
$eventtype = 'select';
}
@@ -604,14 +604,14 @@ function calendar_add_event_allowed($event) {
return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $event->courseid));
case 'group':
- if (!$group = get_record('groups', 'id', $event->groupid)) {
+ if (! groups_group_exists($event->groupid)) { //TODO:check.
return false;
}
// this is ok because if you have this capability at course level, you should be able
// to edit group calendar too
// there is no need to check membership, because if you have this capability
// you will have a role in this group context
- return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_GROUP, $group->id));
+ return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_GROUP, $event->groupid));
case 'user':
if ($event->userid == $USER->id) {
diff --git a/course/groups.php b/course/groups.php
index 00d2b690e85..5419d1d6eb4 100644
--- a/course/groups.php
+++ b/course/groups.php
@@ -214,6 +214,12 @@
$sesskey = !empty($USER->id) ? $USER->sesskey : '';
+//DONOTCOMMIT: TODO:
+if (debugging()) {
+ echo '
[ AJAX groups
+ | New groups - debugging.]
';
+}
+
/// Print out the complete form
print_heading(get_string('groups'));
@@ -222,4 +228,4 @@
print_footer($course);
-?>
+?>
\ No newline at end of file
diff --git a/course/lib.php b/course/lib.php
index 373a956b909..eb3b708afc8 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -177,7 +177,7 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,
$groupmode = groupmode($course);
if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id)))) {
- if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
+ if ($groups_names = groups_get_groups_names($course->id)) { //TODO:check.
echo '
';
if ($groupmode == VISIBLEGROUPS) {
print_string('groupsvisible');
@@ -185,7 +185,7 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,
print_string('groupsseparate');
}
echo ': | ';
- choose_from_menu($groups, "selectedgroup", $selectedgroup, get_string("allgroups"), "", "");
+ choose_from_menu($groups_names, "selectedgroup", $selectedgroup, get_string("allgroups"), "", "");
echo ' | ';
}
}
@@ -305,7 +305,7 @@ function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limit
/// Getting all members of a group.
if ($groupid and !$user) {
- if ($gusers = get_records('groups_members', 'groupid', $groupid)) {
+ if ($gusers = groups_get_members($groupid)) { //TODO:check.
$first = true;
foreach($gusers as $guser) {
if ($first) {
diff --git a/doc/COPYRIGHT.txt b/doc/COPYRIGHT.txt
deleted file mode 100644
index 0e3c1dd19f7..00000000000
--- a/doc/COPYRIGHT.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-Moodle - Modular Object-Oriented Dynamic Learning Environment
-http://moodle.org
-
-Copyright (C) 1999-2004 Martin Dougiamas martin@dougiamas.com
-http://dougiamas.com
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
diff --git a/doc/contents.php b/doc/contents.php
deleted file mode 100755
index 243b5201039..00000000000
--- a/doc/contents.php
+++ /dev/null
@@ -1,38 +0,0 @@
-forcelogin) {
- require_login();
- }
-
- include($info->filepath);
-
- print_header();
-
- $ulopen = false;
-
- foreach ($string as $file => $filename) {
- if (substr($file,0,1) == "-") {
- if($ulopen) {
- echo '';
- }
- echo '
'.$filename.'
';
- $ulopen = true;
- } else {
- echo '- '.$filename.'
';
- }
- }
- if($ulopen) {
- echo '
';
- }
-
- // Sloppy way to produce valid markup... there should be a print_footer_minimal().
- echo '