示例#1
0
function slideshow_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    global $CFG;
    if ($oldversion < 2006112100) {
        table_column('slideshow', '', 'layout', 'int', '2', 'unsigned', '0', 'not null', '');
    }
    if ($oldversion < 2006092600) {
        table_column('slideshow', '', 'location', 'int', '2', 'unsigned', '0', 'not null', '');
    }
    if ($oldversion < 2006012600) {
        table_column('slideshow', '', 'filename', 'int', '2', 'unsigned', '0', 'not null', '');
    }
    if ($oldversion < 2006112700) {
        modify_database('', "CREATE TABLE " . $CFG->prefix . "slideshow_captions (\r\n              id SERIAL PRIMARY KEY,\r\n              slideshow integer NOT NULL default '0',\r\n              image text NOT NULL,\r\n              title text NOT NULL,\r\n              caption text NOT NULL\r\n            )\r\n        ");
    }
    if ($oldversion < 2007070702) {
        table_column('slideshow', '', 'delaytime', 'int', '2', 'unsigned', '7', 'not null', '');
    }
    if ($oldversion < 2007070703) {
        table_column('slideshow', '', 'centred', 'int', '2', 'unsigned', '0', 'not null', '');
        table_column('slideshow', '', 'autobgcolor', 'int', '2', 'unsigned', '0', 'not null', '');
    }
    return true;
}
示例#2
0
function generic_comments_init()
{
    global $CFG, $db, $function, $metatags, $template;
    $metatags .= "<script type=\"text/javascript\" src=\"{$CFG->wwwroot}mod/generic_comments/generic_comments.js\"><!-- generic_comments js --></script>";
    // create the generic_comments and generic watchlist table
    $tables = $db->Metatables();
    if (!in_array($CFG->prefix . "comments", $tables) || !in_array($CFG->prefix . "watchlist", $tables)) {
        if (file_exists($CFG->dirroot . "mod/generic_comments/{$CFG->dbtype}.sql")) {
            modify_database($CFG->dirroot . "mod/generic_comments/{$CFG->dbtype}.sql");
            //reload system
            header_redirect($CFG->wwwroot);
        } else {
            error("Error: Your database ({$CFG->dbtype}) is not yet fully supported by the Elgg generic comments.  See the mod/generic_comments directory.");
        }
        print_continue("index.php");
        exit;
    }
    $function['comments:init'][] = $CFG->dirroot . "mod/generic_comments/comments_actions.php";
    $function['permissions:check'][] = $CFG->dirroot . "mod/generic_comments/permissions_check.php";
    // Add annotation support
    display_set_display_annotation_function("file::file", "generic_comments_displayobjectannotations");
    display_set_display_annotation_function("mediastream::media", "generic_comments_displayobjectannotations");
    // Register file river hook (if there)
    if (function_exists('river_save_event')) {
        river_register_friendlyname_hook('file::file', 'generic_comments_get_friendly_name');
    }
    templates_add_context('embeddedcomments', 'mod/generic_comments/comments');
    templates_add_context('embeddedcomment', 'mod/generic_comments/comment');
    templates_add_context('css', 'mod/generic_comments/css', true, false);
}
示例#3
0
function messages_init()
{
    global $CFG, $function, $db, $METATABLES;
    if (in_array($CFG->prefix . "messages", $METATABLES)) {
        $messagesTable = $db->MetaColumnNames($CFG->prefix . "messages", true);
        // If dosn't exists adding the colummns 'hidden_from' and 'hidden_to'
        if (!in_array("hidden_from", $messagesTable) || !in_array("hidden_to", $messagesTable)) {
            if (file_exists($CFG->dirroot . "mod/messages/{$CFG->dbtype}.sql")) {
                modify_database($CFG->dirroot . "mod/messages/{$CFG->dbtype}.sql");
            } else {
                error("Error: Your database ({$CFG->dbtype}) is not yet fully supported by the Elgg messages plug-in.  See the mod/messages directory.");
            }
        }
    }
    // Functions to perform initializacion
    $function['messages:init'][] = $CFG->dirroot . "mod/messages/lib/messages_init.php";
    // Compose / Delete messages
    $function['messages:new'][] = $CFG->dirroot . "mod/messages/lib/messages_new.php";
    $function['messages:new:body'][] = $CFG->dirroot . "mod/tinymce/tinymce_js.php";
    // View a message
    $function['messages:view'][] = $CFG->dirroot . "mod/messages/lib/messages_view.php";
    $function['messages:message:view'][] = $CFG->dirroot . "mod/messages/lib/messages_message_view.php";
    $function['messages:detailedview'][] = $CFG->dirroot . "mod/messages/lib/messages_message_detailedview.php";
    // Sidebar display function
    $function['messages:contact:link'][] = $CFG->dirroot . "/mod/messages/lib/messages_sidebar_link.php";
    $function['users:infobox:menu:text'][] = $CFG->dirroot . "/mod/messages/lib/messages_sidebar_link.php";
    // Inits the display field module param for the 'select' input field
    // I know, I know this is a big cannon to kill a fly, but I want to use the display_input_field function :P
    if (!isset($CFG->display_field_module)) {
        $CFG->display_field_module = array();
    }
    if (!array_key_exists("as_select", $CFG->display_field_module)) {
        $CFG->display_field_module["as_select"] = "messages";
    }
}
示例#4
0
function slideshow_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    global $CFG;
    if ($oldversion < 2006112100) {
        table_column('slideshow', '', 'layout', 'int', '2', 'unsigned', '0', 'not null', '');
    }
    if ($oldversion < 2006092600) {
        table_column('slideshow', '', 'location', 'int', '2', 'unsigned', '0', 'not null', '');
    }
    if ($oldversion < 2006012600) {
        table_column('slideshow', '', 'filename', 'int', '2', 'unsigned', '0', 'not null', '');
    }
    if ($oldversion < 2006120500) {
        modify_database('', "CREATE TABLE `" . $CFG->prefix . "slideshow_captions` (\r\n                    `id` int(10) unsigned NOT NULL auto_increment,\r\n                    `slideshow` int(10) unsigned NOT NULL default '0',\r\n                    `image` text NOT NULL,\r\n                    `title` text NOT NULL,\r\n                    `caption` text NOT NULL,\r\n                    PRIMARY KEY  (`id`),\r\n                    KEY slideshow (slideshow)\r\n                    );\r\n        ");
    }
    if ($oldversion < 2007070702) {
        table_column('slideshow', '', 'delaytime', 'int', '2', 'unsigned', '7', 'not null', '');
    }
    if ($oldversion < 2007070703) {
        table_column('slideshow', '', 'centred', 'int', '2', 'unsigned', '0', 'not null', '');
        table_column('slideshow', '', 'autobgcolor', 'int', '2', 'unsigned', '0', 'not null', '');
    }
    return true;
}
示例#5
0
/**
 * Comment wall initialisation.
 */
function commentwall_init()
{
    global $CFG, $db, $function, $metatags, $template;
    // Add meta tags
    $metatags .= "<script type=\"text/javascript\" src=\"{$CFG->wwwroot}mod/commentwall/commentwall.js\"><!-- commentwall js --></script>";
    // Define some templates
    templates_add_context('commentwallobject', 'mod/commentwall/template');
    templates_add_context('commentwallfooter', 'mod/commentwall/footer');
    templates_add_context('css', 'mod/commentwall/css');
    // Set up the database
    $tables = $db->Metatables();
    if (!in_array($CFG->prefix . "commentwall", $tables)) {
        if (file_exists($CFG->dirroot . "mod/commentwall/{$CFG->dbtype}.sql")) {
            modify_database($CFG->dirroot . "mod/commentwall/{$CFG->dbtype}.sql");
            //reload system
            header_redirect($CFG->wwwroot);
        } else {
            error("Error: Your database ({$CFG->dbtype}) is not yet fully supported by the Elgg commentwall. See the mod/commentwall directory.");
        }
        print_continue($CFG->wwwroot);
        exit;
    }
    // Add configuration options
    $function['userdetails:edit:details'][] = $CFG->dirroot . "mod/commentwall/lib/commentwall_settings.php";
}
示例#6
0
/**
 * Creates the database tables required
 */
function groups_create_database_tables()
{
    global $CFG;
    if ('mysql' == $CFG->dbfamily) {
        $createcoursegrouptablesql = "CREATE TABLE IF NOT EXISTS `{$CFG->prefix}groups_courses_groups` (\n                            `id` int(10) unsigned NOT NULL auto_increment,\n                            `courseid` int(10) unsigned NOT NULL default '0',\n                            `groupid` int(11) NOT NULL,\n                            PRIMARY KEY  (`id`),\n                            UNIQUE KEY `id` (`id`),\n                            KEY `courseid` (`courseid`)\n                          ) ";
        $creategroupstablesql = "CREATE TABLE IF NOT EXISTS `{$CFG->prefix}groups_groups` (\n                            `id` int(10) unsigned NOT NULL auto_increment,\n                            `name` varchar(254) collate latin1_general_ci NOT NULL default '',\n                            `description` text collate latin1_general_ci NOT NULL,\n                            `enrolmentkey` varchar(50) collate latin1_general_ci NOT NULL default '',\n                            `lang` varchar(10) collate latin1_general_ci NOT NULL default 'en',\n                            `theme` varchar(50) collate latin1_general_ci NOT NULL default '',\n                            `picture` int(10) unsigned NOT NULL default '0',\n                            `hidepicture` int(2) unsigned NOT NULL default '0',\n                            `timecreated` int(10) unsigned NOT NULL default '0',\n                            `timemodified` int(10) unsigned NOT NULL default '0',\n                            PRIMARY KEY  (`id`),\n                            UNIQUE KEY `id` (`id`)\n                          ) ";
        $creategroupsuserstablesql = "CREATE TABLE IF NOT EXISTS `{$CFG->prefix}groups_groups_users` (\n                            `id` int(10) unsigned NOT NULL auto_increment,\n                            `groupid` int(10) unsigned NOT NULL default '0',\n                            `userid` int(10) unsigned NOT NULL default '0',\n                            `timeadded` int(10) unsigned NOT NULL default '0',\n                            PRIMARY KEY  (`id`),\n                            UNIQUE KEY `id` (`id`),\n                            KEY `groupid` (`groupid`),\n                            KEY `userid` (`userid`)\n                          ) ";
        $createcoursesgroupingtablesql = "CREATE TABLE IF NOT EXISTS `{$CFG->prefix}groups_courses_groupings` (\n                            `id` int(10) unsigned NOT NULL auto_increment,\n                            `courseid` int(10) unsigned NOT NULL default '0',\n                            `groupingid` mediumint(9) NOT NULL,\n                            PRIMARY KEY  (`id`),\n                            UNIQUE KEY `id` (`id`),\n                            KEY `courseid` (`courseid`)\n                          ) ";
        $creategroupingstablesql = "CREATE TABLE `{$CFG->prefix}groups_groupings` (\n                            `id` int(10) unsigned NOT NULL auto_increment,\n                            `name` varchar(254) collate latin1_general_ci NOT NULL,\n                            `description` text collate latin1_general_ci NOT NULL default '',\n                            `timecreated` int(10) unsigned NOT NULL default 0,\n                            `viewowngroup` binary(1) NOT NULL default 1,\n                            `viewallgroupsmembers` binary(1) NOT NULL default 0,\n                            `viewallgroupsactivities` binary(1) NOT NULL default 0,\n                            `teachersgroupmark` binary(1) NOT NULL default 0,\n                            `teachersgroupview` binary(1) NOT NULL default 0,\n                            `teachersoverride` binary(1) NOT NULL default 0,\n                            PRIMARY KEY  (`id`),\n                            UNIQUE KEY `id` (`id`)\n                          ) ";
        $creategroupingsgroupstablesql = "CREATE TABLE IF NOT EXISTS `{$CFG->prefix}groups_groupings_groups` (\n                            `id` int(10) unsigned NOT NULL auto_increment,\n                            `groupingid` int(10) unsigned default '0',\n                            `groupid` int(10) NOT NULL,\n                            `timeadded` int(10) unsigned NOT NULL default '0',\n                            PRIMARY KEY  (`id`),\n                            UNIQUE KEY `id` (`id`),\n                            KEY `courseid` (`groupingid`)\n                          ) ";
    } else {
        //postgres7
        $createcoursegrouptablesql = "CREATE TABLE {$CFG->prefix}groups_courses_groups (\n                            id SERIAL PRIMARY KEY,\n                            courseid integer NOT NULL default '0',\n                            groupid integer NOT NULL default '0'\n                          );\n                          CREATE INDEX {$CFG->prefix}groups_courses_groups_courseid_idx ON {$CFG->prefix}groups_courses_groups (courseid);\n                          ";
        //?? CONSTRAINT {$CFG->prefix}groups_courses_groups_id_courseid_uk UNIQUE (id, courseid)
        $creategroupstablesql = "CREATE TABLE {$CFG->prefix}groups_groups (\n                            id SERIAL PRIMARY KEY,\n                            name varchar(255) NOT NULL,\n                            description text NOT NULL default '',\n                            enrolmentkey varchar(50) NOT NULL default '',\n                            lang varchar(10) NOT NULL default 'en',\n                            theme varchar(50) NOT NULL default '',\n                            picture integer NOT NULL default '0',\n                            hidepicture integer NOT NULL default '0',\n                            timecreated integer NOT NULL default '0',\n                            timemodified integer NOT NULL default '0'\n                          ) ";
        $creategroupsuserstablesql = "CREATE TABLE {$CFG->prefix}groups_groups_users (\n                            id SERIAL PRIMARY KEY,\n                            groupid integer NOT NULL default '0',\n                            userid integer NOT NULL default '0',\n                            timeadded integer NOT NULL default '0'\n                          );\n                          CREATE INDEX {$CFG->prefix}groups_groups_users_groupid_idx ON {$CFG->prefix}groups_groups_users (groupid);\n                          CREATE INDEX {$CFG->prefix}groups_groups_users_userid_idx ON {$CFG->prefix}groups_groups_users (userid);\n                          COMMENT ON TABLE {$CFG->prefix}groups_groups_users IS 'New groupings (OU).';\n                          ";
        $createcoursesgroupingtablesql = "CREATE TABLE {$CFG->prefix}groups_courses_groupings (\n                            id SERIAL PRIMARY KEY,\n                            courseid integer NOT NULL default '0',\n                            groupingid integer NOT NULL\n                          );\n                          CREATE INDEX {$CFG->prefix}groups_courses_groupings_courseid_idx ON {$CFG->prefix}groups_courses_groupings (courseid);\n                          COMMENT ON TABLE {$CFG->prefix}groups_courses_groupings IS 'New groupings (OU).';\n                          ";
        $creategroupingstablesql = "CREATE TABLE {$CFG->prefix}groups_groupings (\n                            id SERIAL PRIMARY KEY,\n                            name varchar(254) NOT NULL default,\n                            description text NOT NULL default '',\n                            timecreated integer NOT NULL default 0,\n                            viewowngroup integer NOT NULL default 1,\n                            viewallgroupsmembers integer NOT NULL default 0,\n                            viewallgroupsactivities integer NOT NULL default 0,\n                            teachersgroupmark integer NOT NULL default 0,\n                            teachersgroupview integer NOT NULL default 0,\n                            teachersoverride integer NOT NULL default 0\n                          ) ";
        $creategroupingsgroupstablesql = "CREATE TABLE {$CFG->prefix}groups_groupings_groups (\n                            id SERIAL PRIMARY KEY,\n                            groupingid integer default '0',\n                            groupid integer NOT NULL,\n                            timeadded integer NOT NULL default '0'\n                          );\n                          CREATE INDEX {$CFG->prefix}groups_groupings_groups_groupingid_idx ON {$CFG->prefix}groups_groupings_groups (groupingid);\n                          ";
    }
    modify_database('', $createcoursegrouptablesql);
    modify_database('', $creategroupstablesql);
    modify_database('', $creategroupsuserstablesql);
    modify_database('', $createcoursesgroupingtablesql);
    modify_database('', $creategroupingstablesql);
    modify_database('', $creategroupingsgroupstablesql);
}
function skype_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    ///no upgrades yet :)
    modify_database('', 'ALTER TABLE prefix_skype ADD `description` TEXT NOT NULL');
    return true;
}
function resource_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    if ($oldversion < 2004013101) {
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('resource', 'update', 'resource', 'name');");
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('resource', 'add', 'resource', 'name');");
    }
    if ($oldversion < 2004071000) {
        table_column("resource", "", "popup", "text", "", "", "", "", "alltext");
        if ($resources = get_records_select("resource", "type='3' OR type='5'", "", "id, alltext")) {
            foreach ($resources as $resource) {
                $resource->popup = addslashes($resource->alltext);
                $resource->alltext = "";
                if (!update_record("resource", $resource)) {
                    notify("Error updating popup field for resource id = {$resource->id}");
                }
            }
        }
        require_once "{$CFG->dirroot}/course/lib.php";
        rebuild_course_cache();
    }
    if ($oldversion < 2004071300) {
        table_column("resource", "", "options", "varchar", "255", "", "", "", "popup");
    }
    if ($oldversion < 2004071303) {
        table_column("resource", "type", "type", "varchar", "30", "", "", "", "");
        modify_database("", "UPDATE prefix_resource SET type='reference' WHERE type='1';");
        modify_database("", "UPDATE prefix_resource SET type='file', options='frame' WHERE type='2';");
        modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='3';");
        modify_database("", "UPDATE prefix_resource SET type='text', options='0' WHERE type='4';");
        modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='5';");
        modify_database("", "UPDATE prefix_resource SET type='html' WHERE type='6';");
        modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='7';");
        modify_database("", "UPDATE prefix_resource SET type='text', options='3' WHERE type='8';");
        modify_database("", "UPDATE prefix_resource SET type='directory' WHERE type='9';");
    }
    if ($oldversion < 2004080801) {
        modify_database("", "UPDATE prefix_resource SET alltext=reference,type='html' WHERE type='reference';");
        rebuild_course_cache();
    }
    if ($oldversion < 2004111200) {
        //drop first to avoid conflicts when upgrading
        execute_sql("DROP INDEX {$CFG->prefix}resource_course_idx;", false);
        modify_database('', 'CREATE INDEX prefix_resource_course_idx ON prefix_resource (course);');
    }
    if ($oldversion < 2005041100) {
        // replace wiki-like with markdown
        include_once "{$CFG->dirroot}/lib/wiki_to_markdown.php";
        $wtm = new WikiToMarkdown();
        $wtm->update('resource', 'alltext', 'options');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
示例#9
0
function qtype_randomsamatch_upgrade($oldversion = 0)
{
    global $CFG;
    if ($oldversion < 2006042800) {
        // This is a random questiontype and therefore answers are always shuffled, no need for this field
        modify_database('', 'ALTER TABLE prefix_question_randomsamatch DROP shuffleanswers');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
function questionnaire_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    global $CFG;
    if ($oldversion < 2004021300) {
        # Do something ...
    }
    if ($oldversion < 2004081300) {
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire` ADD `respondenttype` ENUM( \'fullname\', \'anonymous\' ) DEFAULT \'fullname\' NOT NULL AFTER `qtype`');
    }
    if ($oldversion < 2004090700) {
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire` ADD `resp_eligible` ENUM( \'all\', \'students\', \'teachers\' ) DEFAULT \'all\' NOT NULL AFTER `respondenttype`');
    }
    if ($oldversion < 2004090900) {
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire` ADD `opendate` INT( 10 ) NOT NULL AFTER `resp_eligible` , ' . 'ADD `closedate` INT( 10 ) NOT NULL AFTER `opendate`');
    }
    if ($oldversion < 2005021100) {
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire` ADD INDEX ( `sid` )');
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire_survey` ADD INDEX ( `owner` )');
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire_survey` DROP INDEX `name` , ' . 'ADD INDEX `name` ( `name` )');
        questionnaire_upgrade_2005021100();
    }
    if ($oldversion < 2005030100) {
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire_attempts` ADD `rid` INT( 10 ) UNSIGNED ' . 'DEFAULT \'0\' NOT NULL AFTER `userid`');
    }
    if ($oldversion < 2005062700) {
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_bool` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_bool` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_bool` ADD INDEX `response_question` ( `response_id` , `question_id` ) ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_single` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_single` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_single` ADD INDEX `response_question` ( `response_id` , `question_id` ) ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_rank` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_rank` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_rank` ADD INDEX `response_question_choice` ( `response_id` , `question_id`, `choice_id` ) ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_text` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_text` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_text` ADD INDEX `response_question` ( `response_id` , `question_id` ) ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_other` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_other` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_other` ADD INDEX `response_question_choice` ( `response_id` , `question_id`, `choice_id` ) ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_date` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_date` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_date` ADD INDEX `response_question` ( `response_id` , `question_id` ) ;');
    }
    if ($oldversion < 2006012700) {
        questionnaire_upgrade_2006012700();
    }
    if ($oldversion < 2006031702) {
        questionnaire_upgrade_2006031700();
    }
    return true;
}
示例#11
0
function chat_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    if ($oldversion < 2003072100) {
        modify_database("", " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('chat', 'report', 'chat', 'name'); ");
    }
    if ($oldversion < 2003072101) {
        table_column("chat", "messages", "keepdays", "integer", "10", "unsigned", "0", "not null");
    }
    if ($oldversion < 2003072102) {
        table_column("chat", "", "studentlogs", "integer", "4", "unsigned", "0", "not null", "keepdays");
    }
    if ($oldversion < 2003072500) {
        table_column("chat", "", "chattime", "integer", "10", "unsigned", "0", "not null", "studentlogs");
        table_column("chat", "", "schedule", "integer", "4", "", "0", "not null", "studentlogs");
    }
    if ($oldversion < 2004022300) {
        table_column("chat_messages", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid");
        table_column("chat_users", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid");
    }
    if ($oldversion < 2004042500) {
        include_once "{$CFG->dirroot}/mod/chat/lib.php";
        chat_refresh_events();
    }
    if ($oldversion < 2004043000) {
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('chat', 'talk', 'chat', 'name');");
    }
    if ($oldversion < 2004111200) {
        execute_sql("ALTER TABLE {$CFG->prefix}chat DROP INDEX `course`;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}chat_messages DROP INDEX  `chatid`;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}chat_messages DROP INDEX `userid`;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}chat_messages DROP INDEX `groupid`;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}chat_users DROP INDEX  `chatid`;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}chat_users DROP INDEX  `groupid`;", false);
        modify_database('', 'ALTER TABLE prefix_chat ADD INDEX `course` (`course`);');
        modify_database('', 'ALTER TABLE prefix_chat_messages ADD INDEX  `chatid` (`chatid`);');
        modify_database('', 'ALTER TABLE prefix_chat_messages ADD INDEX `userid` (`userid`);');
        modify_database('', 'ALTER TABLE prefix_chat_messages ADD INDEX `groupid` (`groupid`);');
        modify_database('', 'ALTER TABLE prefix_chat_users ADD INDEX  `chatid` (`chatid`);');
        modify_database('', 'ALTER TABLE prefix_chat_users ADD INDEX  `groupid` (`groupid`);');
    }
    if ($oldversion < 2005020300) {
        table_column('chat_users', '', 'course', 'integer', '10', 'unsigned', '0', 'not null', '');
        table_column('chat_users', '', 'lang', 'varchar', '10', '', '', 'not null', '');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
示例#12
0
function exercise_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    if ($oldversion < 2003111400) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_submissions` ADD INDEX (`userid`)");
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_submissions` DROP INDEX `title`");
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_assessments` ADD INDEX (`submissionid`)");
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_assessments` ADD INDEX (`userid`)");
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_grades` ADD INDEX (`assessmentid`)");
    }
    if ($oldversion < 2003121000) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_submissions` ADD `late` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0'");
    }
    if ($oldversion < 2004062300) {
        table_column("exercise", "", "gradinggrade", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade");
        table_column("exercise", "", "assessmentcomps", "INTEGER", "4", "UNSIGNED", "2", "NOT NULL", "usemaximum");
        execute_sql("ALTER TABLE `{$CFG->prefix}exercise` DROP COLUMN `teacherweight`");
        execute_sql("ALTER TABLE `{$CFG->prefix}exercise` DROP COLUMN `gradingweight`");
    }
    if ($oldversion < 2004090200) {
        table_column("exercise", "", "usepassword", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL");
        table_column("exercise", "", "password", "VARCHAR", "32", "", "", "NOT NULL");
    }
    if ($oldversion < 2004091000) {
        table_column("exercise_assessments", "generalcomment", "generalcomment", "text", "", "", "", "NOT NULL");
        table_column("exercise_assessments", "teachercomment", "teachercomment", "text", "", "", "", "NOT NULL");
    }
    if ($oldversion < 2004100800) {
        include_once "{$CFG->dirroot}/mod/exercise/lib.php";
        exercise_refresh_events();
    }
    if ($oldversion < 2004111200) {
        execute_sql("ALTER TABLE {$CFG->prefix}exercise DROP INDEX course;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}exercise_submissions DROP INDEX exerciseid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}exercise_assessments DROP INDEX exerciseid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}exercise_elements DROP INDEX exerciseid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}exercise_rubrics DROP INDEX exerciseid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}exercise_grades DROP INDEX exerciseid;", false);
        modify_database('', 'ALTER TABLE prefix_exercise ADD INDEX course (course);');
        modify_database('', 'ALTER TABLE prefix_exercise_submissions ADD INDEX exerciseid (exerciseid);');
        modify_database('', 'ALTER TABLE prefix_exercise_assessments ADD INDEX exerciseid (exerciseid);');
        modify_database('', 'ALTER TABLE prefix_exercise_elements ADD INDEX exerciseid (exerciseid);');
        modify_database('', 'ALTER TABLE prefix_exercise_rubrics ADD INDEX exerciseid (exerciseid);');
        modify_database('', 'ALTER TABLE prefix_exercise_grades ADD INDEX exerciseid (exerciseid);');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
示例#13
0
function journal_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    $result = true;
    if ($oldversion < 2003081705) {
        $defaultscale = NULL;
        $defaultscale->courseid = 0;
        $defaultscale->userid = 0;
        $defaultscale->timemodified = time();
        $defaultscale->name = get_string("journalrating2", "journal");
        $defaultscale->scale = get_string("journalrating1", "journal") . "," . get_string("journalrating2", "journal") . "," . get_string("journalrating3", "journal");
        if ($defaultscale->id = insert_record("scale", $defaultscale)) {
            execute_sql("UPDATE {$CFG->prefix}journal SET assessed = '-{$defaultscale->id}'", false);
        } else {
            notify("An error occurred while inserting the default journal scale");
            $result = false;
        }
    }
    if ($oldversion < 2004011400) {
        table_column("journal", "", "introformat", "integer", "2", "", "1", "not null", "intro");
    }
    if ($oldversion < 2004111200) {
        execute_sql("DROP INDEX {$CFG->prefix}journal_course_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}journal_entries_journal_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}journal_entries_userid_idx;", false);
        modify_database('', 'CREATE INDEX prefix_journal_course_idx ON prefix_journal (course);');
        modify_database('', 'CREATE INDEX prefix_journal_entries_journal_idx ON prefix_journal_entries (journal);');
        modify_database('', 'CREATE INDEX prefix_journal_entries_userid_idx ON prefix_journal_entries (userid);');
    }
    if ($oldversion < 2005041100) {
        // replace wiki-like with markdown
        include_once "{$CFG->dirroot}/lib/wiki_to_markdown.php";
        $wtm = new WikiToMarkdown();
        // journal intro
        $wtm->update('journal', 'intro', 'introformat');
        // journal entries
        $sql = "select course from {$CFG->prefix}journal, {$CFG->prefix}journal_entries ";
        $sql .= "where {$CFG->prefix}journal.id = {$CFG->prefix}journal_entries.journal ";
        $sql .= "and {$CFG->prefix}journal_entries.id = ";
        $wtm->update('journal_entries', 'text', 'format', $sql);
    }
    if ($oldversion < 2006092100) {
        table_column('journal_entries', 'comment', 'entrycomment', 'text', '', '', '', 'null');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return $result;
}
示例#14
0
function chat_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    if ($oldversion < 2004022300) {
        table_column("chat_messages", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid");
        table_column("chat_users", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid");
    }
    if ($oldversion < 2004042500) {
        include_once "{$CFG->dirroot}/mod/chat/lib.php";
        chat_refresh_events();
    }
    if ($oldversion < 2004043000) {
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('chat', 'talk', 'chat', 'name');");
    }
    if ($oldversion < 2004111200) {
        //drop them first to avoid collisions with upgrades from 1.4.2+
        execute_sql("DROP INDEX {$CFG->prefix}chat_course_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}chat_messages_chatid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}chat_messages_userid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}chat_messages_groupid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}chat_messages_timemodifiedchatid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}chat_users_chatid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}chat_users_userid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}chat_users_groupid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}chat_users_lastping_idx;", false);
        modify_database('', 'CREATE INDEX prefix_chat_course_idx ON prefix_chat(course);');
        modify_database('', 'CREATE INDEX prefix_chat_messages_chatid_idx ON prefix_chat_messages (chatid);');
        modify_database('', 'CREATE INDEX prefix_chat_messages_userid_idx ON prefix_chat_messages (userid);');
        modify_database('', 'CREATE INDEX prefix_chat_messages_groupid_idx ON prefix_chat_messages (groupid);');
        modify_database('', 'CREATE INDEX prefix_chat_messages_timemodifiedchatid_idx ON prefix_chat_messages(timestamp,chatid);');
        modify_database('', 'CREATE INDEX prefix_chat_users_chatid_idx ON prefix_chat_users (chatid);');
        modify_database('', 'CREATE INDEX prefix_chat_users_userid_idx ON prefix_chat_users (userid);');
        modify_database('', 'CREATE INDEX prefix_chat_users_groupid_idx ON prefix_chat_users (groupid);');
        modify_database('', 'CREATE INDEX prefix_chat_users_lastping_idx ON prefix_chat_users (lastping);');
    }
    if ($oldversion < 2005020300) {
        table_column('chat_users', '', 'course', 'integer', '10', 'unsigned', '0', 'not null', '');
        table_column('chat_users', '', 'lang', 'varchar', '10', '', '', 'not null', '');
    }
    if ($oldversion < 2005031001) {
        // Mass cleanup of bad upgrade scripts
        modify_database('', 'ALTER TABLE prefix_chat_users ALTER course SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_chat_users ALTER lang SET NOT NULL');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
示例#15
0
function main_upgrade($oldversion = 0)
{
    global $CFG, $db, $METATABLES;
    $result = true;
    if ($oldversion < 2007062601) {
        modify_database("", "\n            CREATE TABLE `{$CFG->prefix}extauth_hash` (\n              `id` int(11) NOT NULL auto_increment,\n              `login` varchar(15) NOT NULL default '',\n              `hash` varchar(32) NOT NULL default '',\n              `time` timestamp NOT NULL default CURRENT_TIMESTAMP,\n              PRIMARY KEY (`id`));");
        $METATABLES = $db->Metatables();
        // table added/removed without using modify_database()
        // set initial value for auth config
        set_config('auth', '');
    }
    if ($oldversion < 2007062602) {
        table_column('ponente', 'domicilio', 'domicilio', 'varchar', '255', '', '');
    }
    return $result;
}
示例#16
0
function survey_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    if ($oldversion < 2004021601) {
        modify_database("", "INSERT INTO `prefix_survey` (`course`, `template`, `days`, `timecreated`, `timemodified`, `name`, `intro`, `questions`) VALUES (0, 0, 0, 985017600, 985017600, 'ciqname', 'ciqintro', '69,70,71,72,73')");
        modify_database("", "INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (69, 'ciq1', 'ciq1short', '', '', 0, '')");
        modify_database("", "INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (70, 'ciq2', 'ciq2short', '', '', 0, '')");
        modify_database("", "INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (71, 'ciq3', 'ciq3short', '', '', 0, '')");
        modify_database("", "INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (72, 'ciq4', 'ciq4short', '', '', 0, '')");
        modify_database("", "INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (73, 'ciq5', 'ciq5short', '', '', 0, '')");
    }
    if ($oldversion < 2004021602) {
        table_column("survey_answers", "answer1", "answer1", "text", "", "", "");
        table_column("survey_answers", "answer2", "answer2", "text", "", "", "");
    }
    if ($oldversion < 2004021900) {
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('survey', 'add', 'survey', 'name');");
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('survey', 'update', 'survey', 'name');");
    }
    if ($oldversion < 2004111200) {
        execute_sql("DROP INDEX {$CFG->prefix}survey_course_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}survey_analysis_survey_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}survey_analysis_userid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}survey_answers_userid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}survey_answers_survey_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}survey_answers_question_idx;", false);
        modify_database('', 'CREATE INDEX prefix_survey_course_idx ON prefix_survey (course);');
        modify_database('', 'CREATE INDEX prefix_survey_analysis_survey_idx ON prefix_survey_analysis (survey);');
        modify_database('', 'CREATE INDEX prefix_survey_analysis_userid_idx ON prefix_survey_analysis (userid);');
        modify_database('', 'CREATE INDEX prefix_survey_answers_userid_idx ON prefix_survey_answers (userid);');
        modify_database('', 'CREATE INDEX prefix_survey_answers_survey_idx ON prefix_survey_answers (survey);');
        modify_database('', 'CREATE INDEX prefix_survey_answers_question_idx ON prefix_survey_answers (question);');
    }
    if ($oldversion < 2005031600) {
        execute_sql('SELECT setval(\'' . $CFG->prefix . 'survey_id_seq\', (select max(id) from ' . $CFG->prefix . 'survey))');
        execute_sql('SELECT setval(\'' . $CFG->prefix . 'survey_questions_id_seq\', (select max(id) from ' . $CFG->prefix . 'survey_questions))');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
示例#17
0
function label_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    global $CFG;
    if ($oldversion < 2003091400) {
        table_column("label", "", "course", "integer", "10", "unsigned", "0", "not null", "id");
    }
    if ($oldversion < 2004021900) {
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('label', 'add', 'label', 'name');");
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('label', 'update', 'label', 'name');");
    }
    if ($oldversion < 2004111200) {
        //DROP first
        execute_sql("DROP INDEX {$CFG->prefix}label_course_idx;", false);
        modify_database('', 'CREATE INDEX prefix_label_course_idx ON prefix_label (course);');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
function tab_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    global $CFG;
    if ($oldversion < 2008071159) {
        table_column("tab", "", "course", "integer", "10", "unsigned", "0", "not null", "id");
    }
    if ($oldversion < 2008071159) {
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('tab', 'add', 'quiz', 'name');");
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('tab', 'update', 'quiz', 'name');");
    }
    if ($oldversion < 2008071159) {
        //DROP first
        execute_sql("ALTER TABLE {$CFG->prefix}tab DROP INDEX course;", false);
        modify_database('', 'ALTER TABLE prefix_tab ADD INDEX course (course);');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
function elluminate_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    global $CFG;
    $result = true;
    if ($oldversion < 2006062100) {
        $result = modify_database('', "\n            CREATE TABLE `prefix_elluminate` (\n                `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n                `course` INT(10) UNSIGNED NOT NULL DEFAULT '0',\n                `creator` INT(10) UNSIGNED NOT NULL DEFAULT '0',\n                `name` VARCHAR(64) NOT NULL DEFAULT '',\n                `description` TEXT NOT NULL DEFAULT '',\n                `meetingid` VARCHAR(20) NOT NULL DEFAULT 0,\n                `private` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n                `grade` INT(10) NOT NULL DEFAULT '0',\n                `timemodified` INT(10) UNSIGNED NOT NULL DEFAULT '0',\n                PRIMARY KEY  (`id`),\n                KEY `meetingid` (`meetingid`)\n            )\n        ");
        if ($result) {
            $result = modify_database('', "\n                CREATE TABLE `prefix_elluminate_recordings` (\n                    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n                    `meetingid` VARCHAR(20) NOT NULL DEFAULT '',\n                    `recordingid` VARCHAR(30) NOT NULL DEFAULT '',\n                    `created` INT(10) UNSIGNED NOT NULL DEFAULT '0',\n                    PRIMARY KEY `id` (`id`),\n                    KEY `meetingid` (`meetingid`),\n                    KEY `recordingid` (`recordingid`)\n                )\n            ");
        }
        if ($result) {
            $result = modify_database('', "\n                CREATE TABLE `prefix_elluminate_users` (\n                    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n                    `userid` INT(10) UNSIGNED NOT NULL DEFAULT '0',\n                    `elm_id` VARCHAR(20) NOT NULL DEFAULT '',\n                    `elm_password` VARCHAR(10) NOT NULL DEFAULT '',\n                    `timecreated` INT(10) UNSIGNED NOT NULL DEFAULT '0',\n                    PRIMARY KEY `id` (`id`),\n                    KEY `userid` (`userid`),\n                    KEY `elm_id` (`elm_id`)\n                )\n            ");
        }
        if ($result) {
            $result = modify_database('', "\n                CREATE TABLE `prefix_elluminate_attendance` (\n                    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n                    `userid` INT(10) UNSIGNED NOT NULL DEFAULT '0',\n                    `elluminateid` INT(10) UNSIGNED NOT NULL DEFAULT '0',\n                    `grade` INT(11) NOT NULL DEFAULT '0',\n                    `timemodified` INT(10) UNSIGNED NOT NULL DEFAULT '0',\n                    PRIMARY KEY `id` (`id`),\n                    KEY `userid_elluminateid` (`userid`, `elluminateid`)\n                )\n            ");
        }
        /*
                if ($result) {
                    $result = modify_database('', "
                        CREATE TABLE `prefix_event_reminder` (
                            `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
                            `event` INT(10) UNSIGNED NOT NULL DEFAULT '0',
                            `type` INT(1) UNSIGNED NOT NULL DEFAULT '0',
                            `timedelta` INT(10) UNSIGNED NOT NULL DEFAULT '0',
                            `timeinterval` INT(10) UNSIGNED NOT NULL DEFAULT '0',
                            `timeend` INT(10) UNSIGNED NOT NULL DEFAULT '0',
                            PRIMARY KEY(`id`)
                        );
                    ");
                }
        */
    }
    if ($oldversion < 2006062101) {
        $result = table_column('elluminate_users', '', 'elm_username', 'VARCHAR', '50', '', '', 'NOT NULL', 'elm_id');
    }
    if ($oldversion < 2006062102) {
        $result = table_column('elluminate', '', 'seats', 'INTEGER', '10', 'UNSIGNED', '0', 'NOT NULL', 'meetingid');
    }
    return $result;
}
示例#20
0
function exercise_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    if ($oldversion < 2004062300) {
        table_column("exercise", "", "gradinggrade", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade");
        table_column("exercise", "", "assessmentcomps", "INTEGER", "4", "UNSIGNED", "2", "NOT NULL", "usemaximum");
    }
    if ($oldversion < 2004090200) {
        table_column("exercise", "", "usepassword", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL");
        table_column("exercise", "", "password", "VARCHAR", "32", "", "", "NOT NULL");
    }
    if ($oldversion < 2004091000) {
        table_column("exercise_assessments", "generalcomment", "generalcomment", "text", "", "", "", "NOT NULL");
        table_column("exercise_assessments", "teachercomment", "teachercomment", "text", "", "", "", "NOT NULL");
    }
    if ($oldversion < 2004100800) {
        include_once "{$CFG->dirroot}/mod/exercise/lib.php";
        exercise_refresh_events();
    }
    if ($oldversion < 2004111200) {
        execute_sql("DROP INDEX {$CFG->prefix}exercise_course_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}exercise_submissions_exerciseid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}exercise_assessments_exerciseid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}exercise_rubrics_exerciseid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}exercise_grades_exerciseid_idx;", false);
        modify_database('', 'CREATE INDEX prefix_exercise_course_idx ON prefix_exercise (course);');
        modify_database('', 'CREATE INDEX prefix_exercise_submissions_exerciseid_idx ON prefix_exercise_submissions (exerciseid);');
        modify_database('', 'CREATE INDEX prefix_exercise_assessments_exerciseid_idx ON prefix_exercise_assessments (exerciseid);');
        modify_database('', 'CREATE INDEX prefix_exercise_rubrics_exerciseid_idx ON prefix_exercise_rubrics (exerciseid);');
        modify_database('', 'CREATE INDEX prefix_exercise_grades_exerciseid_idx ON prefix_exercise_grades (exerciseid);');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
示例#21
0
function widget_init()
{
    global $CFG, $function, $db, $METATABLES;
    $function['init'][] = $CFG->dirroot . "mod/widget/init.php";
    // Initialise the 'allcontent' widget array - i.e., widgets where Javascript is allowed
    if (!isset($CFG->widgets->allcontent)) {
        $CFG->widgets->allcontent = array();
    }
    // register the widgets that this module provides
    $CFG->widgets->list[] = array('name' => gettext("Text box"), 'description' => gettext("Displays the text of your choice."), 'type' => "widget::text");
    if (!in_array($CFG->prefix . "widget_data", $METATABLES) || !in_array($CFG->prefix . "widgets", $METATABLES)) {
        if (file_exists($CFG->dirroot . "mod/widget/{$CFG->dbtype}.sql")) {
            modify_database($CFG->dirroot . "mod/widget/{$CFG->dbtype}.sql");
            //reload system
            header_redirect($CFG->wwwroot);
        } else {
            error("Error: Your database ({$CFG->dbtype}) is not yet fully supported by the Elgg widgets.  See the mod/widget directory.");
        }
        print_continue("index.php");
        exit;
    }
    // Delete users
    listen_for_event("user", "delete", "widget_user_delete");
}
示例#22
0
function data_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    global $CFG;
    if ($oldversion < 2006011900) {
        table_column("data_content", "", "content1", "longtext", "", "", "", "not null");
        table_column("data_content", "", "content2", "longtext", "", "", "", "not null");
        table_column("data_content", "", "content3", "longtext", "", "", "", "not null");
        table_column("data_content", "", "content4", "longtext", "", "", "", "not null");
    }
    if ($oldversion < 2006011901) {
        table_column("data", "", "approval", "tinyint", "4");
        table_column("data_records", "", "approved", "tinyint", "4");
    }
    if ($oldversion < 2006020801) {
        table_column("data", "", "scale", "integer", "10", "signed");
        table_column("data", "", "assessed", "integer", "10");
        table_column("data", "", "assesspublic", "integer", "4");
    }
    if ($oldversion < 2006022700) {
        table_column("data_comments", "", "created", "integer", "10");
        table_column("data_comments", "", "modified", "integer", "10");
    }
    if ($oldversion < 2006030700) {
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'add', 'data', 'name')");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'update', 'data', 'name')");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'record delete', 'data', 'name')");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'fields add', 'data_fields', 'name')");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'fields update', 'data_fields', 'name')");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'templates saved', 'data', 'name')");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'templates def', 'data', 'name')");
    }
    if ($oldversion < 2006032700) {
        table_column('data', '', 'defaultsort', 'integer', '10', 'unsigned', '0');
        table_column('data', '', 'defaultsortdir', 'tinyint', '4', 'unsigned', '0', 'not null', 'defaultsort');
        table_column('data', '', 'editany', 'tinyint', '4', 'unsigned', '0', 'not null', 'defaultsortdir');
    }
    if ($oldversion < 2006032900) {
        table_column('data', '', 'csstemplate', 'text', '', '', '', 'not null', 'rsstemplate');
    }
    if ($oldversion < 2006050500) {
        // 2 fields have got no default null values
        table_column('data_comments', 'content', 'content', 'text', '', '', '', 'not null');
        table_column('data_fields', 'description', 'description', 'text', '', '', '', 'not null');
        table_column('data_fields', 'param1', 'param1', 'text', '', '', '', 'not null');
        table_column('data_fields', 'param2', 'param2', 'text', '', '', '', 'not null');
        table_column('data_fields', 'param3', 'param3', 'text', '', '', '', 'not null');
        table_column('data_fields', 'param4', 'param4', 'text', '', '', '', 'not null');
        table_column('data_fields', 'param5', 'param5', 'text', '', '', '', 'not null');
        table_column('data_fields', 'param6', 'param6', 'text', '', '', '', 'not null');
        table_column('data_fields', 'param7', 'param7', 'text', '', '', '', 'not null');
        table_column('data_fields', 'param8', 'param8', 'text', '', '', '', 'not null');
        table_column('data_fields', 'param9', 'param9', 'text', '', '', '', 'not null');
        table_column('data_fields', 'param10', 'param10', 'text', '', '', '', 'not null');
    }
    if ($oldversion < 2006052400) {
        table_column('data', '', 'rsstitletemplate', 'text', '', '', '', 'not null', 'rsstemplate');
    }
    if ($oldversion < 2006081700) {
        table_column('data', '', 'jstemplate', 'text', '', '', '', 'not null', 'csstemplate');
    }
    if ($oldversion < 2006092000) {
        // Upgrades for new roles and capabilities support.
        require_once $CFG->dirroot . '/mod/data/lib.php';
        $datamod = get_record('modules', 'name', 'data');
        if ($data = get_records('data')) {
            if (!($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW))) {
                notify('Default teacher role was not found. Roles and permissions ' . 'for all your forums will have to be manually set after ' . 'this upgrade.');
            }
            if (!($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW))) {
                notify('Default student role was not found. Roles and permissions ' . 'for all your forums will have to be manually set after ' . 'this upgrade.');
            }
            foreach ($data as $d) {
                if (!data_convert_to_roles($d, $teacherroles, $studentroles)) {
                    notify('Data with id ' . $d->id . ' was not upgraded');
                }
            }
            // We need to rebuild all the course caches to refresh the state of
            // the forum modules.
            include_once "{$CFG->dirroot}/course/lib.php";
            rebuild_course_cache();
        }
        // End if.
        modify_database('', 'ALTER TABLE prefix_data DROP COLUMN participants;');
        modify_database('', 'ALTER TABLE prefix_data DROP COLUMN assesspublic;');
        modify_database('', 'ALTER TABLE prefix_data DROP COLUMN ratings;');
    }
    if ($oldversion < 2006092302) {
        // Changing some TEXT fields to NULLable and no default
        execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE singletemplate singletemplate text NULL AFTER rssarticles");
        execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE listtemplate listtemplate text NULL AFTER singletemplate");
        execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE listtemplateheader listtemplateheader text NULL AFTER listtemplate");
        execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE listtemplatefooter listtemplatefooter text NULL AFTER listtemplateheader");
        execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE addtemplate addtemplate text NULL AFTER listtemplatefooter");
        execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE rsstemplate rsstemplate text NULL AFTER addtemplate");
        execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE rsstitletemplate rsstitletemplate text NULL AFTER rsstemplate");
        execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE csstemplate csstemplate text NULL AFTER rsstitletemplate");
        execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE jstemplate jstemplate text NULL AFTER csstemplate");
        execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param1 param1 text NULL AFTER description");
        execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param2 param2 text NULL AFTER param1");
        execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param3 param3 text NULL AFTER param2");
        execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param4 param4 text NULL AFTER param3");
        execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param5 param5 text NULL AFTER param4");
        execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param6 param6 text NULL AFTER param5");
        execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param7 param7 text NULL AFTER param6");
        execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param8 param8 text NULL AFTER param7");
        execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param9 param9 text NULL AFTER param8");
        execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param10 param10 text NULL AFTER param9");
        execute_sql("ALTER TABLE {$CFG->prefix}data_content CHANGE content content longtext NULL AFTER recordid");
        execute_sql("ALTER TABLE {$CFG->prefix}data_content CHANGE content1 content1 longtext NULL AFTER content");
        execute_sql("ALTER TABLE {$CFG->prefix}data_content CHANGE content2 content2 longtext NULL AFTER content1");
        execute_sql("ALTER TABLE {$CFG->prefix}data_content CHANGE content3 content3 longtext NULL AFTER content2");
        execute_sql("ALTER TABLE {$CFG->prefix}data_content CHANGE content4 content4 longtext NULL AFTER content3");
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
示例#23
0
function main_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($oldversion < 2003010101) {
        delete_records("log_display", "module", "user");
        $new->module = "user";
        $new->action = "view";
        $new->mtable = "user";
        $new->field = "CONCAT(firstname,\" \",lastname)";
        insert_record("log_display", $new);
        delete_records("log_display", "module", "course");
        $new->module = "course";
        $new->action = "view";
        $new->mtable = "course";
        $new->field = "fullname";
        insert_record("log_display", $new);
        $new->action = "update";
        insert_record("log_display", $new);
        $new->action = "enrol";
        insert_record("log_display", $new);
    }
    //support user based course creating
    if ($oldversion < 2003032400) {
        execute_sql("CREATE TABLE {$CFG->prefix}user_coursecreators (\n                                  id int8 SERIAL PRIMARY KEY,\n                                  userid int8  NOT NULL default '0'\n                                  )");
    }
    if ($oldversion < 2003041400) {
        table_column("course_modules", "", "visible", "integer", "1", "unsigned", "1", "not null", "score");
    }
    if ($oldversion < 2003042104) {
        // Try to update permissions of all files
        if ($files = get_directory_list($CFG->dataroot)) {
            echo "Attempting to update permissions for all files... ignore any errors.";
            foreach ($files as $file) {
                echo "{$CFG->dataroot}/{$file}<br />";
                @chmod("{$CFG->dataroot}/{$file}", $CFG->directorypermissions);
            }
        }
    }
    if ($oldversion < 2003042400) {
        // Rebuild all course caches, because of changes to do with visible variable
        if ($courses = get_records_sql("SELECT * FROM {$CFG->prefix}course")) {
            require_once "{$CFG->dirroot}/course/lib.php";
            foreach ($courses as $course) {
                $modinfo = serialize(get_array_of_activities($course->id));
                if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
                    notify("Could not cache module information for course '" . format_string($course->fullname) . "'!");
                }
            }
        }
    }
    if ($oldversion < 2003042500) {
        //  Convert all usernames to lowercase.
        $users = get_records_sql("SELECT id, username FROM {$CFG->prefix}user");
        $cerrors = "";
        $rarray = array();
        foreach ($users as $user) {
            // Check for possible conflicts
            $lcname = trim(moodle_strtolower($user->username));
            if (in_array($lcname, $rarray)) {
                $cerrors .= $user->id . "->" . $lcname . '<br/>';
            } else {
                array_push($rarray, $lcname);
            }
        }
        if ($cerrors != '') {
            notify("Error: Cannot convert usernames to lowercase. \n                    Following usernames would overlap (id->username):<br/> {$cerrors} . \n                    Please resolve overlapping errors.");
            $result = false;
        }
        $cerrors = "";
        echo "Checking userdatabase:<br />";
        foreach ($users as $user) {
            $lcname = trim(moodle_strtolower($user->username));
            if ($lcname != $user->username) {
                $convert = set_field("user", "username", $lcname, "id", $user->id);
                if (!$convert) {
                    if ($cerrors) {
                        $cerrors .= ", ";
                    }
                    $cerrors .= $item;
                } else {
                    echo ".";
                }
            }
        }
        if ($cerrors != '') {
            notify("There were errors when converting following usernames to lowercase. \n                   '{$cerrors}' . Sorry, but you will need to fix your database by hand.");
            $result = false;
        }
    }
    if ($oldversion < 2003042700) {
        /// Changing to multiple indexes
        execute_sql(" CREATE INDEX {$CFG->prefix}log_coursemoduleaction_idx ON {$CFG->prefix}log (course,module,action) ");
        execute_sql(" CREATE INDEX {$CFG->prefix}log_courseuserid_idx ON {$CFG->prefix}log (course,userid) ");
    }
    if ($oldversion < 2003042801) {
        execute_sql("CREATE TABLE {$CFG->prefix}course_display (\n                         id SERIAL PRIMARY KEY,\n                         course integer NOT NULL default '0',\n                         userid integer NOT NULL default '0',\n                         display integer NOT NULL default '0'\n                      )");
        execute_sql("CREATE INDEX {$CFG->prefix}course_display_courseuserid_idx ON {$CFG->prefix}course_display (course,userid)");
    }
    if ($oldversion < 2003050400) {
        table_column("course_sections", "", "visible", "integer", "1", "unsigned", "1", "", "");
    }
    if ($oldversion < 2003050401) {
        table_column("user", "", "lang", "VARCHAR", "5", "", "{$CFG->lang}", "NOT NULL", "");
    }
    if ($oldversion < 2003050900) {
        table_column("modules", "", "visible", "integer", "1", "unsigned", "1", "", "");
    }
    if ($oldversion < 2003050902) {
        if (get_records("modules", "name", "pgassignment")) {
            print_simple_box("Note: the pgassignment module will soon be deleted from CVS!  Go to the new 'Manage Modules' page and DELETE IT from your system", "center", "50%", "{$THEME->cellheading}", "20", "noticebox");
        }
    }
    if ($oldversion < 2003051600) {
        print_simple_box("Thanks for upgrading!<p>There are many changes since the last release.  Please read the release notes carefully.  If you are using CUSTOM themes you will need to edit them.  You will also need to check your site's config.php file.", "center", "50%", "{$THEME->cellheading}", "20", "noticebox");
    }
    if ($oldversion < 2003052300) {
        table_column("user", "", "autosubscribe", "integer", "1", "unsigned", "1", "", "htmleditor");
    }
    if ($oldversion < 2003072100) {
        table_column("course", "", "visible", "integer", "1", "unsigned", "1", "", "marker");
    }
    if ($oldversion < 2003072101) {
        table_column("course_sections", "sequence", "sequence", "text", "", "", "", "", "");
    }
    if ($oldversion < 2003072800) {
        print_simple_box("The following database index improves performance, but can be quite large - if you are upgrading and you have problems with a limited quota you may want to delete this index later from the '{$CFG->prefix}log' table in your database", "center", "50%", "{$THEME->cellheading}", "20", "noticebox");
        flush();
        execute_sql(" CREATE INDEX {$CFG->prefix}log_timecoursemoduleaction_idx ON {$CFG->prefix}log (time,course,module,action) ");
        execute_sql(" CREATE INDEX {$CFG->prefix}user_students_courseuserid_idx ON {$CFG->prefix}user_students (course,userid) ");
        execute_sql(" CREATE INDEX {$CFG->prefix}user_teachers_courseuserid_idx ON {$CFG->prefix}user_teachers (course,userid) ");
    }
    if ($oldversion < 2003072802) {
        table_column("course_categories", "", "description", "text", "", "", "");
        table_column("course_categories", "", "parent", "integer", "10", "unsigned");
        table_column("course_categories", "", "sortorder", "integer", "10", "unsigned");
        table_column("course_categories", "", "courseorder", "text", "", "", "");
        table_column("course_categories", "", "visible", "integer", "1", "unsigned", "1");
        table_column("course_categories", "", "timemodified", "integer", "10", "unsigned");
    }
    if ($oldversion < 2003080400) {
        notify("If the following command fails you may want to change the type manually, from TEXT to INTEGER.  Moodle should keep working even if you don't.");
        table_column("course_categories", "courseorder", "courseorder", "integer", "10", "unsigned");
        table_column("course", "", "sortorder", "integer", "10", "unsigned", "0", "", "category");
    }
    if ($oldversion < 2003081502) {
        execute_sql(" CREATE TABLE {$CFG->prefix}scale (\n                         id SERIAL PRIMARY KEY,\n                         courseid integer NOT NULL default '0',\n                         userid integer NOT NULL default '0',\n                         name varchar(255) NOT NULL default '',\n                         scale text,\n                         description text,\n                         timemodified integer NOT NULL default '0'\n                      )");
    }
    if ($oldversion < 2003081503) {
        table_column("forum", "", "scale", "integer", "10", "unsigned", "0", "", "assessed");
        get_scales_menu(0);
        // Just to force the default scale to be created
    }
    if ($oldversion < 2003081600) {
        table_column("user_teachers", "", "editall", "integer", "1", "unsigned", "1", "", "role");
        table_column("user_teachers", "", "timemodified", "integer", "10", "unsigned", "0", "", "editall");
    }
    if ($oldversion < 2003081900) {
        table_column("course_categories", "courseorder", "coursecount", "integer", "10", "unsigned", "0");
    }
    if ($oldversion < 2003080700) {
        notify("Cleaning up categories and course ordering...");
        fix_course_sortorder();
    }
    if ($oldversion < 2003082001) {
        table_column("course", "", "showgrades", "integer", "2", "unsigned", "1", "", "format");
    }
    if ($oldversion < 2003082101) {
        execute_sql(" CREATE INDEX {$CFG->prefix}course_category_idx ON {$CFG->prefix}course (category) ");
    }
    if ($oldversion < 2003082702) {
        execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'user report', 'user', 'CONCAT(firstname,\" \",lastname)') ");
    }
    if ($oldversion < 2003091000) {
        # Old field that was never added!
        table_column("course", "", "showrecent", "integer", "10", "unsigned", "1", "", "numsections");
    }
    if ($oldversion < 2003091400) {
        table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score");
    }
    if ($oldversion < 2003092900) {
        table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
    }
    if ($oldversion < 2003102700) {
        table_column("user_students", "", "timeaccess", "integer", "10", "unsigned", "0", "", "time");
        table_column("user_teachers", "", "timeaccess", "integer", "10", "unsigned", "0", "", "timemodified");
        $db->debug = false;
        $CFG->debug = 0;
        notify("Calculating access times.  Please wait - this may take a long time on big sites...", "green");
        flush();
        if ($courses = get_records_select("course", "category > 0")) {
            foreach ($courses as $course) {
                notify("Processing " . format_string($course->fullname) . " ...", "green");
                flush();
                if ($users = get_records_select("user_teachers", "course = '{$course->id}'", "id", "id, userid, timeaccess")) {
                    foreach ($users as $user) {
                        $loginfo = get_record_sql("SELECT id, time FROM {$CFG->prefix}log                                                                                  WHERE course = '{$course->id}' and userid = '{$user->userid}'                                                               ORDER by time DESC");
                        if (empty($loginfo->time)) {
                            $loginfo->time = 0;
                        }
                        execute_sql("UPDATE {$CFG->prefix}user_teachers                                                                                      SET timeaccess = '{$loginfo->time}' \n                                     WHERE userid = '{$user->userid}' AND course = '{$course->id}'", false);
                    }
                }
                if ($users = get_records_select("user_students", "course = '{$course->id}'", "id", "id, userid, timeaccess")) {
                    foreach ($users as $user) {
                        $loginfo = get_record_sql("SELECT id, time FROM {$CFG->prefix}log \n                                                   WHERE course = '{$course->id}' and userid = '{$user->userid}' \n                                                   ORDER by time DESC");
                        if (empty($loginfo->time)) {
                            $loginfo->time = 0;
                        }
                        execute_sql("UPDATE {$CFG->prefix}user_students \n                                     SET timeaccess = '{$loginfo->time}' \n                                     WHERE userid = '{$user->userid}' AND course = '{$course->id}'", false);
                    }
                }
            }
        }
        notify("All courses complete.", "green");
        $db->debug = true;
    }
    if ($oldversion < 2003103100) {
        table_column("course", "", "showreports", "integer", "4", "unsigned", "0", "", "maxbytes");
    }
    if ($oldversion < 2003121600) {
        execute_sql("CREATE TABLE {$CFG->prefix}groups (\n                        id SERIAL PRIMARY KEY,\n                        courseid integer NOT NULL default '0',\n                        name varchar(255) NOT NULL default '',\n                        description text,\n                        lang varchar(10) NOT NULL default '',\n                        picture integer NOT NULL default '0',\n                        timecreated integer NOT NULL default '0',\n                        timemodified integer NOT NULL default '0'\n                     )");
        execute_sql("CREATE INDEX {$CFG->prefix}groups_idx ON {$CFG->prefix}groups (courseid) ");
        execute_sql("CREATE TABLE {$CFG->prefix}groups_members (\n                        id SERIAL PRIMARY KEY,\n                        groupid integer NOT NULL default '0',\n                        userid integer NOT NULL default '0',\n                        timeadded integer NOT NULL default '0'\n                     )");
        execute_sql("CREATE INDEX {$CFG->prefix}groups_members_idx ON {$CFG->prefix}groups_members (groupid) ");
    }
    if ($oldversion < 2003122600) {
        table_column("course", "", "groupmode", "integer", "4", "unsigned", "0", "", "visible");
        table_column("course", "", "groupmodeforce", "integer", "4", "unsigned", "0", "", "groupmode");
    }
    if ($oldversion < 2004010900) {
        table_column("course_modules", "", "groupmode", "integer", "4", "unsigned", "0", "", "visible");
    }
    if ($oldversion < 2004011700) {
        modify_database("", "CREATE TABLE prefix_event (\n                                id SERIAL PRIMARY KEY,\n                                name varchar(255) NOT NULL default '',\n                                description text,\n                                courseid integer NOT NULL default '0',\n                                groupid integer NOT NULL default '0',\n                                userid integer NOT NULL default '0',\n                                modulename varchar(20) NOT NULL default '',\n                                instance integer NOT NULL default '0',\n                                eventtype varchar(20) NOT NULL default '',\n                                timestart integer NOT NULL default '0',\n                                timeduration integer NOT NULL default '0',\n                                timemodified integer NOT NULL default '0'\n                             ); ");
        modify_database("", "CREATE INDEX prefix_event_courseid_idx ON prefix_event (courseid);");
        modify_database("", "CREATE INDEX prefix_event_userid_idx ON prefix_event (userid);");
    }
    if ($oldversion < 2004012800) {
        modify_database("", "CREATE TABLE prefix_user_preferences (\n                                id SERIAL PRIMARY KEY,\n                                userid integer NOT NULL default '0',\n                                name varchar(50) NOT NULL default '',\n                                value varchar(255) NOT NULL default ''\n                             ); ");
        modify_database("", "CREATE INDEX prefix_user_preferences_useridname_idx ON prefix_user_preferences (userid,name);");
    }
    if ($oldversion < 2004012900) {
        table_column("config", "value", "value", "text", "", "", "");
    }
    if ($oldversion < 2004013101) {
        table_column("log", "", "cmid", "integer", "10", "unsigned", "0", "", "module");
        set_config("upgrade", "logs");
    }
    if ($oldversion < 2004020900) {
        table_column("course", "", "lang", "varchar", "5", "", "", "", "groupmodeforce");
    }
    if ($oldversion < 2004020903) {
        modify_database("", "CREATE TABLE prefix_cache_text (\n                                id SERIAL PRIMARY KEY,\n                                md5key varchar(32) NOT NULL default '',\n                                formattedtext text,\n                                timemodified integer NOT NULL default '0'\n                             );");
    }
    if ($oldversion < 2004021000) {
        $textfilters = array();
        for ($i = 1; $i <= 10; $i++) {
            $variable = "textfilter{$i}";
            if (!empty($CFG->{$variable})) {
                /// No more filters
                if (is_readable("{$CFG->dirroot}/" . $CFG->{$variable})) {
                    $textfilters[] = $CFG->{$variable};
                }
            }
        }
        $textfilters = implode(',', $textfilters);
        if (empty($textfilters)) {
            $textfilters = 'mod/glossary/dynalink.php';
        }
        set_config('textfilters', $textfilters);
    }
    if ($oldversion < 2004021201) {
        modify_database("", "CREATE TABLE prefix_cache_filters (\n                                id SERIAL PRIMARY KEY,\n                                filter varchar(32) NOT NULL default '',\n                                version integer NOT NULL default '0',\n                                md5key varchar(32) NOT NULL default '',\n                                rawtext text,\n                                timemodified integer NOT NULL default '0'\n                             );");
        modify_database("", "CREATE INDEX prefix_cache_filters_filtermd5key_idx ON prefix_cache_filters (filter,md5key);");
        modify_database("", "CREATE INDEX prefix_cache_text_md5key_idx ON prefix_cache_text (md5key);");
    }
    if ($oldversion < 2004021500) {
        table_column("groups", "", "hidepicture", "integer", "2", "unsigned", "0", "", "picture");
    }
    if ($oldversion < 2004021700) {
        if (!empty($CFG->textfilters)) {
            $CFG->textfilters = str_replace("tex_filter.php", "filter.php", $CFG->textfilters);
            $CFG->textfilters = str_replace("multilang.php", "filter.php", $CFG->textfilters);
            $CFG->textfilters = str_replace("censor.php", "filter.php", $CFG->textfilters);
            $CFG->textfilters = str_replace("mediaplugin.php", "filter.php", $CFG->textfilters);
            $CFG->textfilters = str_replace("algebra_filter.php", "filter.php", $CFG->textfilters);
            $CFG->textfilters = str_replace("dynalink.php", "filter.php", $CFG->textfilters);
            set_config("textfilters", $CFG->textfilters);
        }
    }
    if ($oldversion < 2004022000) {
        table_column("user", "", "emailstop", "integer", "1", "unsigned", "0", "not null", "email");
    }
    if ($oldversion < 2004022200) {
        /// Final renaming I hope.  :-)
        if (!empty($CFG->textfilters)) {
            $CFG->textfilters = str_replace("/filter.php", "", $CFG->textfilters);
            $CFG->textfilters = str_replace("mod/glossary/dynalink.php", "mod/glossary", $CFG->textfilters);
            $textfilters = explode(',', $CFG->textfilters);
            foreach ($textfilters as $key => $textfilter) {
                $textfilters[$key] = trim($textfilter);
            }
            set_config("textfilters", implode(',', $textfilters));
        }
    }
    if ($oldversion < 2004030702) {
        /// Because of the renaming of Czech language pack
        execute_sql("UPDATE {$CFG->prefix}user SET lang = 'cs' WHERE lang = 'cz'");
        execute_sql("UPDATE {$CFG->prefix}course SET lang = 'cs' WHERE lang = 'cz'");
    }
    if ($oldversion < 2004041800) {
        /// Integrate Block System from contrib
        table_column("course", "", "blockinfo", "varchar", "255", "", "", "not null", "modinfo");
    }
    if ($oldversion < 2004042600) {
        /// Rebuild course caches for resource icons
        //include_once("$CFG->dirroot/course/lib.php");
        //rebuild_course_cache();
    }
    if ($oldversion < 2004042700) {
        /// Increase size of lang fields
        table_column("user", "lang", "lang", "varchar", "10", "", "en");
        table_column("groups", "lang", "lang", "varchar", "10", "", "");
        table_column("course", "lang", "lang", "varchar", "10", "", "");
    }
    if ($oldversion < 2004042701) {
        /// Add hiddentopics field to control hidden topics behaviour
        #table_column("course", "", "hiddentopics", "integer", "1", "unsigned", "0", "not null", "visible");
        #See 'hiddensections' further down
    }
    if ($oldversion < 2004042702) {
        /// Add a format field for the description
        table_column("event", "", "format", "integer", "4", "unsigned", "0", "not null", "description");
    }
    if ($oldversion < 2004043001) {
        /// Add hiddentopics field to control hidden topics behaviour
        table_column("course", "", "hiddensections", "integer", "2", "unsigned", "0", "not null", "visible");
    }
    if ($oldversion < 2004050400) {
        /// add a visible field for events
        table_column("event", "", "visible", "smallint", "1", "", "1", "not null", "timeduration");
        if ($events = get_records('event')) {
            foreach ($events as $event) {
                if ($moduleid = get_field('modules', 'id', 'name', $event->modulename)) {
                    if (get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $event->instance) == 0) {
                        set_field('event', 'visible', 0, 'id', $event->id);
                    }
                }
            }
        }
    }
    if ($oldversion < 2004052800) {
        /// First version tagged "1.4 development", version.php 1.227
        set_config('siteblocksadded', true);
        /// This will be used later by the block upgrade
    }
    if ($oldversion < 2004053000) {
        /// set defaults for site course
        $site = get_site();
        set_field('course', 'numsections', 0, 'id', $site->id);
        set_field('course', 'groupmodeforce', 1, 'id', $site->id);
        set_field('course', 'teacher', get_string('administrator'), 'id', $site->id);
        set_field('course', 'teachers', get_string('administrators'), 'id', $site->id);
        set_field('course', 'student', get_string('user'), 'id', $site->id);
        set_field('course', 'students', get_string('users'), 'id', $site->id);
    }
    if ($oldversion < 2004060100) {
        set_config('digestmailtime', 0);
        table_column('user', "", 'maildigest', 'smallint', '1', '', '0', 'not null', 'mailformat');
    }
    if ($oldversion < 2004062400) {
        table_column('user_teachers', "", 'timeend', 'int', '10', 'unsigned', '0', 'not null', 'editall');
        table_column('user_teachers', "", 'timestart', 'int', '10', 'unsigned', '0', 'not null', 'editall');
    }
    if ($oldversion < 2004062401) {
        table_column('course', '', 'idnumber', 'varchar', '100', '', '', 'not null', 'shortname');
        execute_sql('UPDATE ' . $CFG->prefix . 'course SET idnumber = shortname');
        // By default
    }
    if ($oldversion < 2004062600) {
        table_column('course', '', 'cost', 'varchar', '10', '', '', 'not null', 'lang');
    }
    if ($oldversion < 2004072900) {
        table_column('course', '', 'enrolperiod', 'int', '10', 'unsigned', '0', 'not null', 'startdate');
    }
    if ($oldversion < 2004072901) {
        // Fixing error in schema
        if ($record = get_record('log_display', 'module', 'course', 'action', 'update')) {
            delete_records('log_display', 'module', 'course', 'action', 'update');
            insert_record('log_display', $record, false);
        }
    }
    if ($oldversion < 2004081200) {
        // Fixing version errors in some blocks
        set_field('blocks', 'version', 2004081200, 'name', 'admin');
        set_field('blocks', 'version', 2004081200, 'name', 'calendar_month');
        set_field('blocks', 'version', 2004081200, 'name', 'course_list');
    }
    if ($oldversion < 2004081500) {
        // Adding new "auth" field to user table to allow more flexibility
        table_column('user', '', 'auth', 'varchar', '20', '', 'manual', 'not null', 'id');
        execute_sql("UPDATE {$CFG->prefix}user SET auth = 'manual'");
        // Set everyone to 'manual' to be sure
        if ($admins = get_admins()) {
            // Set all the NON-admins to whatever the current auth module is
            $adminlist = array();
            foreach ($admins as $user) {
                $adminlist[] = $user->id;
            }
            $adminlist = implode(',', $adminlist);
            execute_sql("UPDATE {$CFG->prefix}user SET auth = '{$CFG->auth}' WHERE id NOT IN ({$adminlist})");
        }
    }
    if ($oldversion < 2004082600) {
        //update auth-fields for external users
        // following code would not work in 1.8
        /*        include_once ($CFG->dirroot."/auth/".$CFG->auth."/lib.php");
                if (function_exists('auth_get_userlist')) {
                    $externalusers = auth_get_userlist();
                    if (!empty($externalusers)){
                        $externalusers = '\''. implode('\',\'',$externalusers).'\'';
                        execute_sql("UPDATE {$CFG->prefix}user SET auth = '$CFG->auth' WHERE username  IN ($externalusers)");
                    }
                }*/
    }
    if ($oldversion < 2004082900) {
        // Make sure guest is "manual" too.
        set_field('user', 'auth', 'manual', 'username', 'guest');
    }
    /* Just commenteed unused fields out
       if ($oldversion < 2004090300) { // Add guid-field used in user syncronization
               table_column('user', '', 'guid', 'varchar', '128', '', '', '', 'auth');
               execute_sql("CREATE INDEX {$CFG->prefix}user_auth_guid_idx ON {$CFG->prefix}user (auth, guid)"); 
       }
       */
    if ($oldversion < 2004091900) {
        //Modify idnumber to hold longer keys
        set_field('user', 'auth', 'manual', 'username', 'guest');
        table_column('user', 'idnumber', 'idnumber', 'varchar', '64', '', '', '', '');
        execute_sql("DROP INDEX {$CFG->prefix}user_idnumber_idx ;", false);
        // added in case of conflicts with upgrade from 14stable
        execute_sql("DROP INDEX {$CFG->prefix}user_auth_idx ;", false);
        // added in case of conflicts with upgrade from 14stable
        execute_sql("CREATE INDEX {$CFG->prefix}user_idnumber_idx ON {$CFG->prefix}user (idnumber)");
        execute_sql("CREATE INDEX {$CFG->prefix}user_auth_idx ON {$CFG->prefix}user (auth)");
    }
    if ($oldversion < 2004092000) {
        //redoing this just to be sure that column type is text (postgres type changes didnt work when this was done first time)
        table_column("config", "value", "value", "text", "", "", "");
    }
    if ($oldversion < 2004093001) {
        // add new table for sessions storage
        execute_sql(" CREATE TABLE {$CFG->prefix}sessions (\n                          sesskey char(32) PRIMARY KEY,\n                          expiry integer NOT null,\n                          expireref varchar(64),\n                          data text NOT null\n                      );");
        execute_sql(" CREATE INDEX {$CFG->prefix}sessions_expiry_idx ON {$CFG->prefix}sessions (expiry)");
    }
    if ($oldversion < 2004111500) {
        // Update any users/courses using wrongly-named lang pack
        execute_sql("UPDATE {$CFG->prefix}user SET lang = 'mi_nt' WHERE lang = 'ma_nt'");
        execute_sql("UPDATE {$CFG->prefix}course SET lang = 'mi_nt' WHERE lang = 'ma_nt'");
    }
    if ($oldversion < 2004111700) {
        // add indexes- drop them first silently to avoid conflicts when upgrading.
        execute_sql("DROP INDEX {$CFG->prefix}course_idnumber_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}course_shortname_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_students_userid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_teachers_userid_idx;", false);
        modify_database("", "CREATE INDEX {$CFG->prefix}course_idnumber_idx ON {$CFG->prefix}course (idnumber);");
        modify_database("", "CREATE INDEX {$CFG->prefix}course_shortname_idx ON {$CFG->prefix}course (shortname);");
        modify_database("", "CREATE INDEX {$CFG->prefix}user_students_userid_idx ON {$CFG->prefix}user_students (userid);");
        modify_database("", "CREATE INDEX {$CFG->prefix}user_teachers_userid_idx ON {$CFG->prefix}user_teachers (userid);");
    }
    if ($oldversion < 2004111700) {
        // add an index to event for timestart and timeduration- drop them first silently to avoid conflicts when upgrading.
        execute_sql("DROP INDEX {$CFG->prefix}event_timestart_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}event_timeduration_idx;", false);
        modify_database('', 'CREATE INDEX prefix_event_timestart_idx ON prefix_event (timestart);');
        modify_database('', 'CREATE INDEX prefix_event_timeduration_idx ON prefix_event (timeduration);');
    }
    if ($oldversion < 2004117000) {
        // add an index on the groups_members table- drop them first silently to avoid conflicts when upgrading.
        execute_sql("DROP INDEX {$CFG->prefix}groups_members_userid_idx;", false);
        modify_database('', 'CREATE INDEX prefix_groups_members_userid_idx ON prefix_groups_members (userid);');
    }
    if ($oldversion < 2004111700) {
        //add indexes on modules and course_modules- drop them first silently to avoid conflicts when upgrading.
        execute_sql("DROP INDEX {$CFG->prefix}course_modules_visible_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}course_modules_course_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}course_modules_module_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}course_modules_instance_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}course_modules_deleted_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}modules_name_idx;", false);
        modify_database('', 'CREATE INDEX prefix_course_modules_visible_idx ON prefix_course_modules (visible);');
        modify_database('', 'CREATE INDEX prefix_course_modules_course_idx ON prefix_course_modules (course);');
        modify_database('', 'CREATE INDEX prefix_course_modules_module_idx ON prefix_course_modules (module);');
        modify_database('', 'CREATE INDEX prefix_course_modules_instance_idx ON prefix_course_modules (instance);');
        modify_database('', 'CREATE INDEX prefix_course_modules_deleted_idx ON prefix_course_modules (deleted);');
        modify_database('', 'CREATE INDEX prefix_modules_name_idx ON prefix_modules (name);');
    }
    if ($oldversion < 2004111700) {
        // add an index on user students timeaccess (used for sorting)- drop them first silently to avoid conflicts when upgrading
        execute_sql("DROP INDEX {$CFG->prefix}user_students_timeaccess_idx;", false);
        modify_database('', 'CREATE INDEX prefix_user_students_timeaccess_idx ON prefix_user_students (timeaccess);');
    }
    if ($oldversion < 2004111700) {
        //add indexes on faux foreign keys  - drop them first silently to avoid conflicts when upgrading.
        execute_sql("DROP INDEX {$CFG->prefix}course_sections_coursesection_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}scale_courseid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_admins_userid_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_coursecreators_userid_idx;", false);
        modify_database('', 'CREATE INDEX prefix_course_sections_coursesection_idx ON prefix_course_sections (course,section);');
        modify_database('', 'CREATE INDEX prefix_scale_courseid_idx ON prefix_scale (courseid);');
        modify_database('', 'CREATE INDEX prefix_user_admins_userid_idx ON prefix_user_admins (userid);');
        modify_database('', 'CREATE INDEX prefix_user_coursecreators_userid_idx ON prefix_user_coursecreators (userid);');
    }
    if ($oldversion < 2004111700) {
        // make new indexes on user table.
        fix_course_sortorder(0, 0, 1);
        execute_sql("DROP INDEX {$CFG->prefix}course_category_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}course_category_sortorder_uk;", false);
        modify_database('', "CREATE UNIQUE INDEX prefix_course_category_sortorder_uk ON prefix_course(category,sortorder)");
        execute_sql("DROP INDEX {$CFG->prefix}user_deleted_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_confirmed_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_firstname_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_lastname_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_city_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_country_idx;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_lastaccess_idx;", false);
        modify_database("", "CREATE INDEX prefix_user_deleted_idx ON prefix_user (deleted)");
        modify_database("", "CREATE INDEX prefix_user_confirmed_idx ON prefix_user (confirmed)");
        modify_database("", "CREATE INDEX prefix_user_firstname_idx ON prefix_user (firstname)");
        modify_database("", "CREATE INDEX prefix_user_lastname_idx ON prefix_user (lastname)");
        modify_database("", "CREATE INDEX prefix_user_city_idx ON prefix_user (city)");
        modify_database("", "CREATE INDEX prefix_user_country_idx ON prefix_user (country)");
        modify_database("", "CREATE INDEX prefix_user_lastaccess_idx ON prefix_user (lastaccess)");
    }
    if ($oldversion < 2004111700) {
        // one more index for email (for sorting)
        execute_sql("DROP INDEX {$CFG->prefix}user_email_idx;", false);
        modify_database('', 'CREATE INDEX prefix_user_email_idx ON prefix_user (email);');
    }
    if ($oldversion < 2004112200) {
        // new 'enrol' field for enrolment tables
        table_column('user_students', '', 'enrol', 'varchar', '20', '', '', 'not null');
        table_column('user_teachers', '', 'enrol', 'varchar', '20', '', '', 'not null');
        modify_database("", "CREATE INDEX {$CFG->prefix}user_students_enrol_idx ON {$CFG->prefix}user_students (enrol);");
        modify_database("", "CREATE INDEX {$CFG->prefix}user_teachers_enrol_idx ON {$CFG->prefix}user_teachers (enrol);");
    }
    if ($oldversion < 2004112300) {
        // update log display to use correct postgres friendly sql
        execute_sql("UPDATE {$CFG->prefix}log_display SET field='firstname||\\' \\'||lastname' WHERE module='user' AND action='view' AND mtable='user'");
        execute_sql("UPDATE {$CFG->prefix}log_display SET field='firstname||\\' \\'||lastname' WHERE module='course' AND action='user report' AND mtable='user'");
    }
    if ($oldversion < 2004112400) {
        /// Delete duplicate enrolments
        /// and then tell the database course,userid is a unique combination
        if ($users = get_records_select("user_students", "userid > 0 GROUP BY course, userid " . "HAVING count(*) > 1", "", "max(id) as id, userid, course ,count(*)")) {
            foreach ($users as $user) {
                delete_records_select("user_students", "userid = '{$user->userid}' " . "AND course = '{$user->course}' AND id <> '{$user->id}'");
            }
        }
        flush();
        // drop some indexes quietly -- they may or may not exist depending on what version
        // the user upgrades from
        execute_sql("DROP INDEX {$CFG->prefix}user_students_courseuserid_idx ", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_students_courseuserid_uk  ", false);
        modify_database('', 'CREATE UNIQUE INDEX prefix_user_students_courseuserid_uk ON prefix_user_students (course,userid);');
        /// Delete duplicate teacher enrolments
        /// and then tell the database course,userid is a unique combination
        if ($users = get_records_select("user_teachers", "userid > 0 GROUP BY course, userid " . "HAVING count(*) > 1", "", "max(id) as id, userid, course ,count(*)")) {
            foreach ($users as $user) {
                delete_records_select("user_teachers", "userid = '{$user->userid}' " . "AND course = '{$user->course}' AND id <> '{$user->id}'");
            }
        }
        flush();
        // drop some indexes quietly -- they may or may not exist depending on what version
        // the user upgrades from
        execute_sql("DROP INDEX {$CFG->prefix}user_teachers_courseuserid_idx ", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_teachers_courseuserid_uk  ", false);
        modify_database('', 'CREATE UNIQUE INDEX prefix_user_teachers_courseuserid_uk ON prefix_user_teachers (course,userid);');
    }
    if ($oldversion < 2004112401) {
        // some postgres databases may have a non-unique index mislabeled unique.
        fix_course_sortorder(0, 0, 1);
        execute_sql("DROP INDEX {$CFG->prefix}course_category_sortorder_uk  ", false);
        execute_sql("DROP INDEX {$CFG->prefix}course_category_idx  ", false);
        modify_database('', "CREATE UNIQUE INDEX prefix_course_category_sortorder_uk ON prefix_course(category,sortorder);");
        // odd! username was missing its unique index!
        // first silently drop it just in case...
        execute_sql("ALTER TABLE {$CFG->prefix}user DROP CONSTRAINT {$CFG->prefix}user_username_uk;", false);
        execute_sql("DROP INDEX {$CFG->prefix}user_username_uk", false);
        modify_database('', "CREATE UNIQUE INDEX prefix_user_username_uk ON prefix_user (username);");
    }
    if ($oldversion < 2004112900) {
        table_column('user', '', 'policyagreed', 'integer', '1', 'unsigned', '0', 'not null', 'confirmed');
    }
    if ($oldversion < 2004121400) {
        table_column('groups', '', 'password', 'varchar', '50', '', '', 'not null', 'description');
    }
    if ($oldversion < 2004121600) {
        modify_database('', "CREATE TABLE prefix_dst_preset (\n                                id SERIAL PRIMARY KEY,\n                                name varchar(48) NOT NULL default '',\n                                apply_offset integer NOT NULL default '0',\n                                activate_index integer NOT NULL default '1',\n                                activate_day integer NOT NULL default '1',\n                                activate_month integer NOT NULL default '1',\n                                activate_time char(5) NOT NULL default '03:00',\n                                deactivate_index integer NOT NULL default '1',\n                                deactivate_day integer NOT NULL default '1',\n                                deactivate_month integer NOT NULL default '2',\n                                deactivate_time char(5) NOT NULL default '03:00',\n                                last_change integer NOT NULL default '0',\n                                next_change integer NOT NULL default '0',\n                                current_offset integer NOT NULL default '0'\n                             );");
    }
    if ($oldversion < 2004122800) {
        execute_sql("DROP TABLE {$CFG->prefix}message", false);
        execute_sql("DROP TABLE {$CFG->prefix}message_read", false);
        execute_sql("DROP TABLE {$CFG->prefix}message_contacts", false);
        execute_sql("DROP INDEX {$CFG->prefix}message_useridfrom_idx", false);
        execute_sql("DROP INDEX {$CFG->prefix}message_useridto_idx", false);
        execute_sql("DROP INDEX {$CFG->prefix}message_read_useridfrom_idx", false);
        execute_sql("DROP INDEX {$CFG->prefix}message_read_useridto_idx", false);
        execute_sql("DROP INDEX {$CFG->prefix}message_contacts_useridcontactid_idx", false);
        modify_database('', "CREATE TABLE prefix_message (\n                               id SERIAL PRIMARY KEY,\n                               useridfrom integer NOT NULL default '0',\n                               useridto integer NOT NULL default '0',\n                               message text,\n                               timecreated integer NOT NULL default '0',\n                               messagetype varchar(50) NOT NULL default ''\n                            );\n\n                            CREATE INDEX prefix_message_useridfrom_idx ON prefix_message (useridfrom);\n                            CREATE INDEX prefix_message_useridto_idx ON prefix_message (useridto);\n\n                            CREATE TABLE prefix_message_read (\n                               id SERIAL PRIMARY KEY,\n                               useridfrom integer NOT NULL default '0',\n                               useridto integer NOT NULL default '0',\n                               message text,\n                               timecreated integer NOT NULL default '0',\n                               timeread integer NOT NULL default '0',\n                               messagetype varchar(50) NOT NULL default '',\n                               mailed integer NOT NULL default '0'\n                            );\n\n                            CREATE INDEX prefix_message_read_useridfrom_idx ON prefix_message_read (useridfrom);\n                            CREATE INDEX prefix_message_read_useridto_idx ON prefix_message_read (useridto);\n                            ");
        modify_database('', "CREATE TABLE prefix_message_contacts (\n                               id SERIAL PRIMARY KEY,\n                               userid integer NOT NULL default '0',\n                               contactid integer NOT NULL default '0',\n                               blocked integer NOT NULL default '0'\n                            );\n\n                            CREATE INDEX prefix_message_contacts_useridcontactid_idx ON prefix_message_contacts (userid,contactid);\n                            ");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'write', 'user', 'firstname||\\' \\'||lastname');\n                            INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'read', 'user', 'firstname||\\' \\'||lastname');\n                            ");
    }
    if ($oldversion < 2004122801) {
        table_column('message', '', 'format', 'integer', '4', 'unsigned', '0', 'not null', 'message');
        table_column('message_read', '', 'format', 'integer', '4', 'unsigned', '0', 'not null', 'message');
    }
    if ($oldversion < 2005010100) {
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'add contact', 'user', 'firstname||\\' \\'||lastname');\n                            INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'remove contact', 'user', 'firstname||\\' \\'||lastname');\n                            INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'block contact', 'user', 'firstname||\\' \\'||lastname');\n                            INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'unblock contact', 'user', 'firstname||\\' \\'||lastname');\n                            ");
    }
    if ($oldversion < 2005011000) {
        // Create a .htaccess file in dataroot, just in case
        if (!file_exists($CFG->dataroot . '/.htaccess')) {
            if ($handle = fopen($CFG->dataroot . '/.htaccess', 'w')) {
                // For safety
                @fwrite($handle, "deny from all\r\nAllowOverride None\r\n");
                @fclose($handle);
                notify("Created a default .htaccess file in {$CFG->dataroot}");
            }
        }
    }
    if ($oldversion < 2005012500) {
        // add new table for meta courses.
        /*
        modify_database("","CREATE TABLE prefix_meta_course (
             id SERIAL primary key,
             parent_course integer NOT NULL,
             child_course integer NOT NULL
             );");
        
        modify_database("","CREATE INDEX prefix_meta_course_parent_idx ON prefix_meta_course (parent_course);");
        modify_database("","CREATE INDEX prefix_meta_course_child_idx ON prefix_meta_course (child_course);");
        table_column('course','','meta_course','integer','1','','0','not null');
        */
        // taking this OUT for upgrade from 1.4 to 1.5 (those tracking head will have already seen it)
    }
    if ($oldversion < 2005012501) {
        //fix table names for consistency
        execute_sql("DROP TABLE {$CFG->prefix}meta_course", false);
        // drop silently
        execute_sql("ALTER TABLE {$CFG->prefix}course DROP COLUMN meta_course", false);
        // drop silently
        modify_database("", "CREATE TABLE prefix_course_meta (\n             id SERIAL primary key,\n             parent_course integer NOT NULL,\n             child_course integer NOT NULL\n             );");
        modify_database("", "CREATE INDEX prefix_course_meta_parent_idx ON prefix_course_meta (parent_course);");
        modify_database("", "CREATE INDEX prefix_course_meta_child_idx ON prefix_course_meta (child_course);");
        table_column('course', '', 'metacourse', 'integer', '1', '', '0', 'not null');
    }
    if ($oldversion < 2005020100) {
        fix_course_sortorder(0, 1, 1);
    }
    if ($oldversion < 2005021000) {
        // New fields for theme choices
        table_column('course', '', 'theme', 'varchar', '50', '', '', '', 'lang');
        table_column('groups', '', 'theme', 'varchar', '50', '', '', '', 'lang');
        table_column('user', '', 'theme', 'varchar', '50', '', '', '', 'lang');
        set_config('theme', 'standardwhite');
        // Reset to a known good theme
    }
    if ($oldversion < 2005021700) {
        table_column('user', '', 'dstpreset', 'int', '10', '', '0', 'not null', 'timezone');
    }
    if ($oldversion < 2005021800) {
        modify_database("", "CREATE TABLE adodb_logsql (\n                              created timestamp NOT NULL,\n                              sql0 varchar(250) NOT NULL,\n                              sql1 text NOT NULL,\n                              params text NOT NULL,\n                              tracer text NOT NULL,\n                              timer decimal(16,6) NOT NULL\n                           );");
    }
    if ($oldversion < 2005022400) {
        table_column('dst_preset', '', 'family', 'varchar', '100', '', '', 'not null', 'name');
        table_column('dst_preset', '', 'year', 'int', '10', '', '0', 'not null', 'family');
    }
    if ($oldversion < 2005030501) {
        table_column('user', '', 'msn', 'varchar', '50', '', '', '', 'icq');
        table_column('user', '', 'aim', 'varchar', '50', '', '', '', 'icq');
        table_column('user', '', 'yahoo', 'varchar', '50', '', '', '', 'icq');
        table_column('user', '', 'skype', 'varchar', '50', '', '', '', 'icq');
    }
    if ($oldversion < 2005032300) {
        table_column('user', 'dstpreset', 'timezonename', 'varchar', '100');
        execute_sql('UPDATE ' . $CFG->prefix . 'user SET timezonename = \'\'');
    }
    if ($oldversion < 2005032600) {
        execute_sql('DROP TABLE ' . $CFG->prefix . 'dst_preset', false);
        modify_database('', "CREATE TABLE prefix_timezone (\n                              id SERIAL PRIMARY KEY,\n                              name varchar(100) NOT NULL default '',\n                              year integer NOT NULL default '0',\n                              rule varchar(20) NOT NULL default '',\n                              gmtoff integer NOT NULL default '0',\n                              dstoff integer NOT NULL default '0',\n                              dst_month integer NOT NULL default '0',\n                              dst_startday integer NOT NULL default '0',\n                              dst_weekday integer NOT NULL default '0',\n                              dst_skipweeks integer NOT NULL default '0',\n                              dst_time varchar(5) NOT NULL default '00:00',\n                              std_month integer NOT NULL default '0',\n                              std_startday integer NOT NULL default '0',\n                              std_weekday integer NOT NULL default '0',\n                              std_skipweeks integer NOT NULL default '0',\n                              std_time varchar(5) NOT NULL default '00:00'\n                            );");
    }
    if ($oldversion < 2005032800) {
        modify_database('', "CREATE TABLE prefix_grade_category (\n                              id SERIAL PRIMARY KEY,\n                              name varchar(64) default NULL,\n                              courseid integer NOT NULL default '0',\n                              drop_x_lowest integer NOT NULL default '0',\n                              bonus_points integer NOT NULL default '0',\n                              hidden integer NOT NULL default '0',\n                              weight decimal(4,2) default '0.00'\n                            );");
        modify_database('', "CREATE INDEX prefix_grade_category_courseid_idx ON prefix_grade_category (courseid);");
        modify_database('', "CREATE TABLE prefix_grade_exceptions (\n                              id SERIAL PRIMARY KEY,\n                              courseid integer  NOT NULL default '0',\n                              grade_itemid integer  NOT NULL default '0',\n                              userid integer  NOT NULL default '0'\n                            );");
        modify_database('', "CREATE INDEX prefix_grade_exceptions_courseid_idx ON prefix_grade_exceptions (courseid);");
        modify_database('', "CREATE TABLE prefix_grade_item (\n                              id SERIAL PRIMARY KEY,\n                              courseid integer default NULL,\n                              category integer default NULL,\n                              modid integer default NULL,\n                              cminstance integer default NULL,\n                              scale_grade float(11) default '1.0000000000',\n                              extra_credit integer NOT NULL default '0',\n                              sort_order integer  NOT NULL default '0'\n                            );");
        modify_database('', "CREATE INDEX prefix_grade_item_courseid_idx ON prefix_grade_item (courseid);");
        modify_database('', "CREATE TABLE prefix_grade_letter (\n                              id SERIAL PRIMARY KEY,\n                              courseid integer NOT NULL default '0',\n                              letter varchar(8) NOT NULL default 'NA',\n                              grade_high decimal(6,2) NOT NULL default '100.00',\n                              grade_low decimal(6,2) NOT NULL default '0.00'\n                            );");
        modify_database('', "CREATE INDEX prefix_grade_letter_courseid_idx ON prefix_grade_letter (courseid);");
        modify_database('', "CREATE TABLE prefix_grade_preferences (\n                              id SERIAL PRIMARY KEY,\n                              courseid integer default NULL,\n                              preference integer NOT NULL default '0',\n                              value integer NOT NULL default '0'\n                            );");
        modify_database('', "CREATE UNIQUE INDEX prefix_grade_prefs_courseidpref_uk ON prefix_grade_preferences (courseid,preference);");
    }
    if ($oldversion < 2005033100) {
        // Get rid of defunct field from course modules table
        delete_records('course_modules', 'deleted', 1);
        // Delete old records we don't need any more
        execute_sql('DROP INDEX ' . $CFG->prefix . 'course_modules_deleted_idx;');
        // Old index
        execute_sql('ALTER TABLE ' . $CFG->prefix . 'course_modules DROP deleted;');
        // Old field
    }
    if ($oldversion < 2005040800) {
        table_column('user', 'timezone', 'timezone', 'varchar', '100', '', '99');
        execute_sql(" ALTER TABLE {$CFG->prefix}user DROP timezonename ");
    }
    if ($oldversion < 2005041101) {
        require_once $CFG->libdir . '/filelib.php';
        if (is_readable($CFG->dirroot . '/lib/timezones.txt')) {
            // Distribution file
            if ($timezones = get_records_csv($CFG->dirroot . '/lib/timezones.txt', 'timezone')) {
                $db->debug = false;
                update_timezone_records($timezones);
                notify(count($timezones) . ' timezones installed');
                $db->debug = true;
            }
        }
    }
    if ($oldversion < 2005041900) {
        // Copy all Dialogue entries into Messages, and hide Dialogue module
        if ($entries = get_records_sql('SELECT e.id, e.userid, c.recipientid, e.text, e.timecreated
                                          FROM ' . $CFG->prefix . 'dialogue_conversations c,
                                               ' . $CFG->prefix . 'dialogue_entries e
                                         WHERE e.conversationid = c.id')) {
            foreach ($entries as $entry) {
                $message = NULL;
                $message->useridfrom = $entry->userid;
                $message->useridto = $entry->recipientid;
                $message->message = addslashes($entry->text);
                $message->format = FORMAT_HTML;
                $message->timecreated = $entry->timecreated;
                $message->messagetype = 'direct';
                insert_record('message_read', $message);
            }
        }
        set_field('modules', 'visible', 0, 'name', 'dialogue');
        notify('The Dialogue module has been disabled, and all the old Messages from it copied into the new standard Message feature.  If you really want Dialogue back, you can enable it using the "eye" icon here:  Admin >> Modules >> Dialogue');
    }
    if ($oldversion < 2005042100) {
        $result = table_column('event', '', 'repeatid', 'int', '10', 'unsigned', '0', 'not null', 'userid') && $result;
    }
    if ($oldversion < 2005042400) {
        // Add user tracking prefs field.
        table_column('user', '', 'trackforums', 'int', '4', 'unsigned', '0', 'not null', 'autosubscribe');
    }
    if ($oldversion < 2005051500) {
        // Add user tracking prefs field.
        table_column('grade_category', 'weight', 'weight', 'numeric(5,2)', '', '', '0.00', '', '');
    }
    if ($oldversion < 2005053000) {
        // Add config_plugins table
        // this table was created on the MOODLE_15_STABLE branch
        // so it may already exist. Therefore we hide potential errors
        // (Postgres doesn't support CREATE TABLE IF NOT EXISTS)
        execute_sql("CREATE TABLE {$CFG->prefix}config_plugins (\n                        id     SERIAL PRIMARY KEY,\n                        plugin varchar(100) NOT NULL default 'core',\n                        name   varchar(100) NOT NULL default '',\n                        value  text NOT NULL default '',\n                        CONSTRAINT {$CFG->prefix}config_plugins_plugin_name_uk UNIQUE (plugin, name)\n                     );", false);
    }
    if ($oldversion < 2005060200) {
        // migrate some config items to config_plugins table
        // NOTE: this block is in both postgres AND mysql upgrade
        // files. If you edit either, update the otherone.
        $user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");
        if (!empty($CFG->auth)) {
            // if we have no auth, just pass
            foreach ($user_fields as $field) {
                $suffixes = array('', '_editlock', '_updateremote', '_updatelocal');
                foreach ($suffixes as $suffix) {
                    $key = 'auth_user_' . $field . $suffix;
                    if (isset($CFG->{$key})) {
                        // translate keys & values
                        // to the new convention
                        // this should support upgrading
                        // even 1.5dev installs
                        $newkey = $key;
                        $newval = $CFG->{$key};
                        if ($suffix === '') {
                            $newkey = 'field_map_' . $field;
                        } elseif ($suffix === '_editlock') {
                            $newkey = 'field_lock_' . $field;
                            $newval = $newval == 1 ? 'locked' : 'unlocked';
                            // translate 0/1 to locked/unlocked
                        } elseif ($suffix === '_updateremote') {
                            $newkey = 'field_updateremote_' . $field;
                        } elseif ($suffix === '_updatelocal') {
                            $newkey = 'field_updatelocal_' . $field;
                            $newval = $newval == 1 ? 'onlogin' : 'oncreate';
                            // translate 0/1 to locked/unlocked
                        }
                        if (!(set_config($newkey, addslashes($newval), 'auth/' . $CFG->auth) && delete_records('config', 'name', $key))) {
                            notify("Error updating Auth configuration {$key} to {$CFG->auth} {$newkey} .");
                            $result = false;
                        }
                    }
                    // end if isset key
                }
                // end foreach suffix
            }
            // end foreach field
        }
    }
    if ($oldversion < 2005060201) {
        // Close down the Attendance module, we are removing it from CVS.
        if (!file_exists($CFG->dirroot . '/mod/attendance/lib.php')) {
            if (count_records('attendance')) {
                // We have some data, so should keep it
                set_field('modules', 'visible', 0, 'name', 'attendance');
                notify('The Attendance module has been discontinued.  If you really want to 
                        continue using it, you should download it individually from 
                        http://download.moodle.org/modules and install it, then 
                        reactivate it from Admin >> Configuration >> Modules.  
                        None of your existing data has been deleted, so all existing 
                        Attendance activities should re-appear.');
            } else {
                // No data, so do a complete delete
                execute_sql('DROP TABLE ' . $CFG->prefix . 'attendance', false);
                delete_records('modules', 'name', 'attendance');
                notify("The Attendance module has been discontinued and removed from your site.  \n                        You weren't using it anyway.  ;-)");
            }
        }
    }
    if ($oldversion < 2005060223) {
        // Mass cleanup of bad postgres upgrade scripts
        execute_sql("DROP TABLE {$CFG->prefix}attendance_roll", false);
        // There are no attendance module anymore
        modify_database('', 'ALTER TABLE prefix_config ALTER value SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_course ALTER metacourse SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_course ALTER theme SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_event ALTER repeatid SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_groups ALTER password SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_groups ALTER theme SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_message ALTER format SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_message_read ALTER format SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_groups ALTER theme SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_user ALTER aim DROP DEFAULT');
        modify_database('', 'ALTER TABLE prefix_user ALTER idnumber DROP DEFAULT');
        modify_database('', 'ALTER TABLE prefix_user ALTER msn DROP DEFAULT');
        modify_database('', 'ALTER TABLE prefix_user ALTER policyagreed SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_user ALTER skype DROP DEFAULT');
        modify_database('', 'ALTER TABLE prefix_user ALTER theme SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_user ALTER timezone SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_user ALTER trackforums SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_user ALTER yahoo DROP DEFAULT');
        modify_database('', 'ALTER TABLE prefix_user_students ALTER enrol SET NOT NULL');
        modify_database('', 'ALTER TABLE prefix_user_teachers ALTER enrol SET NOT NULL');
    }
    if ($oldversion < 2005071700) {
        // Close down the Dialogue module, we are removing it from CVS.
        if (!file_exists($CFG->dirroot . '/mod/dialogue/lib.php')) {
            if (count_records('dialogue')) {
                // We have some data, so should keep it
                set_field('modules', 'visible', 0, 'name', 'dialogue');
                notify('The Dialogue module has been discontinued.  If you really want to 
                        continue using it, you should download it individually from 
                        http://download.moodle.org/modules and install it, then 
                        reactivate it from Admin >> Configuration >> Modules.  
                        None of your existing data has been deleted, so all existing 
                        Dialogue activities should re-appear.');
            } else {
                // No data, so do a complete delete
                execute_sql('DROP TABLE ' . $CFG->prefix . 'dialogue', false);
                delete_records('modules', 'name', 'dialogue');
                notify("The Dialogue module has been discontinued and removed from your site.  \n                        You weren't using it anyway.  ;-)");
            }
        }
    }
    if ($oldversion < 2005072000) {
        // Add a couple fields to mdl_event to work towards iCal import/export
        table_column('event', '', 'uuid', 'char', '36', '', '', 'not null', 'visible');
        table_column('event', '', 'sequence', 'integer', '10', 'unsigned', '1', 'not null', 'uuid');
    }
    if ($oldversion < 2005072100) {
        // run the online assignment cleanup code
        include $CFG->dirroot . '/' . $CFG->admin . '/oacleanup.php';
        if (function_exists('online_assignment_cleanup')) {
            online_assignment_cleanup();
        }
    }
    if ($oldversion < 2005072200) {
        // fix the mistakenly-added currency stuff from enrol/authorize
        execute_sql("DROP TABLE {$CFG->prefix}currencies", false);
        // drop silently
        execute_sql("ALTER TABLE {$CFG->prefix}course DROP currency", false);
        $defaultcurrency = empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency;
        table_column('course', '', 'currency', 'char', '3', '', $defaultcurrency, 'not null', 'cost');
    }
    if ($oldversion < 2005081600) {
        //set up the course requests table
        modify_database('', "CREATE TABLE prefix_course_request (\n           id SERIAL PRIMARY KEY,\n           fullname varchar(254) NOT NULL default '',\n           shortname varchar(15) NOT NULL default '',\n           summary text NOT NULL default '',\n           reason text NOT NULL default '',\n           requester INTEGER NOT NULL default 0\n         );");
        modify_database('', 'CREATE INDEX prefix_course_request_shortname_idx ON prefix_course_request (shortname);');
        table_column('course', '', 'requested');
    }
    if ($oldversion < 2005081601) {
        modify_database('', 'CREATE TABLE prefix_course_allowed_modules (
            id SERIAL PRIMARY KEY,
            course INTEGER NOT NULL default 0,
            module INTEGER NOT NULL default 0
         );');
        modify_database('', 'CREATE INDEX prefix_course_allowed_modules_course_idx ON prefix_course_allowed_modules (course);');
        modify_database('', 'CREATE INDEX prefix_course_allowed_modules_module_idx ON prefix_course_allowed_modules (module);');
        table_column('course', '', 'restrictmodules', 'int', '1', '', '0', 'not null');
    }
    if ($oldversion < 2005081700) {
        table_column('course_categories', '', 'depth', 'integer');
        table_column('course_categories', '', 'path', 'varchar', '255');
    }
    if ($oldversion < 2005090100) {
        // stats!
        modify_database('', 'CREATE TABLE prefix_stats_daily (
           id SERIAL PRIMARY KEY,
           courseid INTEGER NOT NULL default 0,
           timeend INTEGER NOT NULL default 0,
           students INTEGER NOT NULL default 0,
           teachers INTEGER NOT NULL default 0,
           activestudents INTEGER NOT NULL default 0,
           activeteachers INTEGER NOT NULL default 0,
           studentreads INTEGER NOT NULL default 0,
           studentwrites INTEGER NOT NULL default 0,
           teacherreads INTEGER NOT NULL default 0,
           teacherwrites INTEGER NOT NULL default 0,
           logins INTEGER NOT NULL default 0,
           uniquelogins INTEGER NOT NULL default 0
        );');
        modify_database('', 'CREATE INDEX prefix_stats_daily_courseid_idx ON prefix_stats_daily (courseid);');
        modify_database('', 'CREATE INDEX prefix_stats_daily_timeend_idx ON prefix_stats_daily (timeend);');
        modify_database('', 'CREATE TABLE prefix_stats_weekly (
           id SERIAL PRIMARY KEY,
           courseid INTEGER NOT NULL default 0,
           timeend INTEGER NOT NULL default 0,
           students INTEGER NOT NULL default 0,
           teachers INTEGER NOT NULL default 0,
           activestudents INTEGER NOT NULL default 0,
           activeteachers INTEGER NOT NULL default 0,
           studentreads INTEGER NOT NULL default 0,
           studentwrites INTEGER NOT NULL default 0,
           teacherreads INTEGER NOT NULL default 0,
           teacherwrites INTEGER NOT NULL default 0,
           logins INTEGER NOT NULL default 0,
           uniquelogins INTEGER NOT NULL default 0
        );');
        modify_database('', 'CREATE INDEX prefix_stats_weekly_courseid_idx ON prefix_stats_weekly (courseid);');
        modify_database('', 'CREATE INDEX prefix_stats_weekly_timeend_idx ON prefix_stats_weekly (timeend);');
        modify_database('', 'CREATE TABLE prefix_stats_monthly (
           id SERIAL PRIMARY KEY,
           courseid INTEGER NOT NULL default 0,
           timeend INTEGER NOT NULL default 0,
           students INTEGER NOT NULL default 0,
           teachers INTEGER NOT NULL default 0,
           activestudents INTEGER NOT NULL default 0,
           activeteachers INTEGER NOT NULL default 0,
           studentreads INTEGER NOT NULL default 0,
           studentwrites INTEGER NOT NULL default 0,
           teacherreads INTEGER NOT NULL default 0,
           teacherwrites INTEGER NOT NULL default 0,
           logins INTEGER NOT NULL default 0,
           uniquelogins INTEGER NOT NULL default 0
        );');
        modify_database('', 'CREATE INDEX prefix_stats_monthly_courseid_idx ON prefix_stats_monthly (courseid);');
        modify_database('', 'CREATE INDEX prefix_stats_monthly_timeend_idx ON prefix_stats_monthly (timeend);');
        modify_database("", "CREATE TABLE prefix_stats_user_daily (\n           id SERIAL PRIMARY KEY,\n           courseid INTEGER NOT NULL default 0,\n           userid INTEGER NOT NULL default 0,\n           roleid INTEGER NOT NULL default 0,\n           timeend INTEGER NOT NULL default 0,\n           statsreads INTEGER NOT NULL default 0,\n           statswrites INTEGER NOT NULL default 0,\n           stattype varchar(30) NOT NULL default ''\n         );");
        modify_database("", "CREATE INDEX prefix_stats_user_daily_courseid_idx ON prefix_stats_user_daily (courseid);");
        modify_database("", "CREATE INDEX prefix_stats_user_daily_userid_idx ON prefix_stats_user_daily (userid);");
        modify_database("", "CREATE INDEX prefix_stats_user_daily_roleid_idx ON prefix_stats_user_daily (roleid);");
        modify_database("", "CREATE INDEX prefix_stats_user_daily_timeend_idx ON prefix_stats_user_daily (timeend);");
        modify_database("", "CREATE TABLE prefix_stats_user_weekly (\n           id SERIAL PRIMARY KEY,\n           courseid INTEGER NOT NULL default 0,\n           userid INTEGER NOT NULL default 0,\n           roleid INTEGER NOT NULL default 0,\n           timeend INTEGER NOT NULL default 0,\n           statsreads INTEGER NOT NULL default 0,\n           statswrites INTEGER NOT NULL default 0,\n           stattype varchar(30) NOT NULL default ''\n         );");
        modify_database("", "CREATE INDEX prefix_stats_user_weekly_courseid_idx ON prefix_stats_user_weekly (courseid);");
        modify_database("", "CREATE INDEX prefix_stats_user_weekly_userid_idx ON prefix_stats_user_weekly (userid);");
        modify_database("", "CREATE INDEX prefix_stats_user_weekly_roleid_idx ON prefix_stats_user_weekly (roleid);");
        modify_database("", "CREATE INDEX prefix_stats_user_weekly_timeend_idx ON prefix_stats_user_weekly (timeend);");
        modify_database("", "CREATE TABLE prefix_stats_user_monthly (\n           id SERIAL PRIMARY KEY,\n           courseid INTEGER NOT NULL default 0,\n           userid INTEGER NOT NULL default 0,\n           roleid INTEGER NOT NULL default 0,\n           timeend INTEGER NOT NULL default 0,\n           statsreads INTEGER NOT NULL default 0,\n           statswrites INTEGER NOT NULL default 0,\n           stattype varchar(30) NOT NULL default ''\n         );");
        modify_database("", "CREATE INDEX prefix_stats_user_monthly_courseid_idx ON prefix_stats_user_monthly (courseid);");
        modify_database("", "CREATE INDEX prefix_stats_user_monthly_userid_idx ON prefix_stats_user_monthly (userid);");
        modify_database("", "CREATE INDEX prefix_stats_user_monthly_roleid_idx ON prefix_stats_user_monthly (roleid);");
        modify_database("", "CREATE INDEX prefix_stats_user_monthly_timeend_idx ON prefix_stats_user_monthly (timeend);");
    }
    if ($oldversion < 2005100300) {
        table_column('course', '', 'expirynotify', 'integer', '1');
        table_column('course', '', 'expirythreshold', 'integer');
        table_column('course', '', 'notifystudents', 'integer', '1');
        $new = new stdClass();
        $new->name = 'lastexpirynotify';
        $new->value = 0;
        insert_record('config', $new);
    }
    if ($oldversion < 2005100400) {
        table_column('course', '', 'enrollable', 'integer', '1', 'unsigned', '1');
        table_column('course', '', 'enrolstartdate', 'integer');
        table_column('course', '', 'enrolenddate', 'integer');
    }
    if ($oldversion < 2005101200) {
        // add enrolment key to course_request.
        table_column('course_request', '', 'password', 'text');
    }
    if ($oldversion < 2006030800) {
        # add extra indexes to log (see bug #4112)
        modify_database('', "CREATE INDEX prefix_log_userid_idx ON prefix_log (userid);");
        modify_database('', "CREATE INDEX prefix_log_info_idx ON prefix_log (info);");
    }
    if ($oldversion < 2006030900) {
        table_column('course', '', 'enrol', 'varchar', '20', '', '');
        if ($CFG->enrol == 'internal' || $CFG->enrol == 'manual') {
            set_config('enrol_plugins_enabled', 'manual');
            set_config('enrol', 'manual');
        } else {
            set_config('enrol_plugins_enabled', 'manual,' . $CFG->enrol);
        }
        require_once "{$CFG->dirroot}/enrol/enrol.class.php";
        $defaultenrol = enrolment_factory::factory($CFG->enrol);
        if (!method_exists($defaultenrol, 'print_entry')) {
            // switch enrollable to off for all courses in this case
            modify_database('', 'UPDATE prefix_course SET enrollable = 0');
        }
        execute_sql("UPDATE {$CFG->prefix}user_students SET enrol='manual' WHERE enrol='' OR enrol='internal'");
        execute_sql("UPDATE {$CFG->prefix}user_teachers SET enrol='manual' WHERE enrol=''");
    }
    if ($oldversion < 2006031000) {
        modify_database("", "CREATE TABLE prefix_post (\n          id SERIAL PRIMARY KEY,\n          userid INTEGER NOT NULL default 0,\n          courseid INTEGER NOT NULL default 0,\n          groupid INTEGER NOT NULL default 0,\n          moduleid INTEGER NOT NULL default 0,\n          coursemoduleid INTEGER NOT NULL default 0,\n          subject varchar(128) NOT NULL default '',\n          summary text,\n          content text,\n          uniquehash varchar(128) NOT NULL default '',\n          rating INTEGER NOT NULL default 0,\n          format INTEGER NOT NULL default 0,\n          publishstate varchar(10) CHECK (publishstate IN ('draft','site','public')) NOT NULL default 'draft',\n          lastmodified INTEGER NOT NULL default '0',\n          created INTEGER NOT NULL default '0'\n        );");
        modify_database("", "CREATE INDEX id_user_idx ON prefix_post  (id, courseid);");
        modify_database("", "CREATE INDEX post_lastmodified_idx ON prefix_post (lastmodified);");
        modify_database("", "CREATE INDEX post_subject_idx ON prefix_post (subject);");
        modify_database("", "CREATE TABLE prefix_tags (\n          id SERIAL PRIMARY KEY,\n          type varchar(255) NOT NULL default 'official',\n          userid INTEGER NOT NULL default 0,\n          text varchar(255) NOT NULL default ''\n        );");
        modify_database("", "CREATE TABLE prefix_blog_tag_instance (\n          id SERIAL PRIMARY KEY,\n          entryid integer NOT NULL default 0,\n          tagid integer NOT NULL default 0,\n          groupid integer NOT NULL default 0,\n          courseid integer NOT NULL default 0,\n          userid integer NOT NULL default 0\n        );");
    }
    if ($oldversion < 2006031400) {
        require_once "{$CFG->dirroot}/enrol/enrol.class.php";
        $defaultenrol = enrolment_factory::factory($CFG->enrol);
        if (!method_exists($defaultenrol, 'print_entry')) {
            set_config('enrol', 'manual');
        }
    }
    if ($oldversion < 2006032000) {
        table_column('post', '', 'module', 'varchar', '20', '', '', 'not null', 'id');
        modify_database('', "CREATE INDEX post_module_idx ON prefix_post (module);");
        modify_database('', "UPDATE prefix_post SET module = 'blog';");
    }
    if ($oldversion < 2006032001) {
        table_column('blog_tag_instance', '', 'timemodified', 'integer', '10', 'unsigned', '0', 'not null', 'userid');
        modify_database('', "CREATE INDEX bti_entryid_idx ON prefix_blog_tag_instance (entryid);");
        modify_database('', "CREATE INDEX bti_tagid_idx ON prefix_blog_tag_instance (tagid);");
        modify_database('', "UPDATE prefix_blog_tag_instance SET timemodified = '" . time() . "';");
    }
    if ($oldversion < 2006040500) {
        // Add an index to course_sections that was never upgraded (bug 5100)
        execute_sql(" CREATE INDEX {$CFG->prefix}course_sections_coursesection_idx ON {$CFG->prefix}course_sections (course,section) ", false);
    }
    if ($oldversion < 2006041100) {
        table_column('course_modules', '', 'visibleold', 'integer', '1', 'unsigned', '1', 'not null', 'visible');
    }
    if ($oldversion < 2006042400) {
        // Look through table log_display and get rid of duplicates.
        $rs = get_recordset_sql('SELECT DISTINCT * FROM ' . $CFG->prefix . 'log_display');
        // Drop the log_display table and create it back with an id field.
        execute_sql("DROP TABLE {$CFG->prefix}log_display", false);
        modify_database('', "CREATE TABLE prefix_log_display (\n                               id SERIAL PRIMARY KEY,\n                               module varchar(30) NOT NULL default '',\n                               action varchar(40) NOT NULL default '',\n                               mtable varchar(30) NOT NULL default '',\n                               field varchar(50) NOT NULL default '')");
        // Add index to ensure that module and action combination is unique.
        modify_database('', 'CREATE INDEX prefix_log_display_moduleaction ON prefix_log_display (module,action)');
        // Insert the records back in, sans duplicates.
        if ($rs) {
            while (!$rs->EOF) {
                $sql = "INSERT INTO {$CFG->prefix}log_display " . "VALUES('', '" . $rs->fields['module'] . "', " . "'" . $rs->fields['action'] . "', " . "'" . $rs->fields['mtable'] . "', " . "'" . $rs->fields['field'] . "')";
                execute_sql($sql, false);
                $rs->MoveNext();
            }
            rs_close($rs);
        }
    }
    // add 2 indexes to tags table
    if ($oldversion < 2006042401) {
        modify_database('', "CREATE INDEX tags_typeuserid_idx ON prefix_tags (type, userid);");
        modify_database('', "CREATE INDEX tags_text_idx ON prefix_tags (text);");
    }
    if ($oldversion < 2006050500) {
        table_column('log', 'action', 'action', 'varchar', '40', '', '', 'not null');
    }
    if ($oldversion < 2006050502) {
        // Close down the Dialogue module, we are removing it from CVS.
        if (!file_exists($CFG->dirroot . '/mod/dialogue/lib.php')) {
            if (!count_records('dialogue_conversations')) {
                // no data, drop the extra tables
                execute_sql('DROP TABLE ' . $CFG->prefix . 'dialogue_conversations', false);
                execute_sql('DROP TABLE ' . $CFG->prefix . 'dialogue_entries', false);
                notify("The Dialogue module has been discontinued and removed from your site.  \n                        You weren't using it anyway.  ;-)");
            }
        }
        table_column('course_request', 'password', 'password', 'varchar', '50', '', '');
        table_column('course', 'currency', 'currency', 'varchar', '3');
        modify_database('', 'ALTER TABLE prefix_course_categories
            ALTER COLUMN path SET DEFAULT \'\'');
        table_column('log_display', 'module', 'module', 'varchar', '20');
        modify_database("", "DROP INDEX id_user_idx");
        modify_database("", "DROP INDEX post_lastmodified_idx");
        modify_database("", "DROP INDEX post_subject_idx");
        modify_database('', "DROP INDEX bti_entryid_idx");
        modify_database('', "DROP INDEX bti_tagid_idx");
        modify_database('', "DROP INDEX post_module_idx");
        modify_database('', "DROP INDEX tags_typeuserid_idx");
        modify_database('', "DROP INDEX tags_text_idx");
        modify_database("", "CREATE INDEX {$CFG->prefix}id_user_idx           ON prefix_post (id, courseid);");
        modify_database("", "CREATE INDEX {$CFG->prefix}post_lastmodified_idx ON prefix_post (lastmodified);");
        modify_database("", "CREATE INDEX {$CFG->prefix}post_subject_idx      ON prefix_post (subject);");
        modify_database('', "CREATE INDEX {$CFG->prefix}bti_entryid_idx       ON prefix_blog_tag_instance (entryid);");
        modify_database('', "CREATE INDEX {$CFG->prefix}bti_tagid_idx         ON prefix_blog_tag_instance (tagid);");
        modify_database('', "CREATE INDEX {$CFG->prefix}post_module_idx       ON prefix_post (moduleid);");
        modify_database('', "CREATE INDEX {$CFG->prefix}tags_typeuserid_idx   ON prefix_tags (type, userid);");
        modify_database('', "CREATE INDEX {$CFG->prefix}tags_text_idx         ON prefix_tags (text);");
    }
    // renaming of reads and writes for stats_user_xyz
    if ($oldversion < 2006052400) {
        // change this later
        // we are using this because we want silent updates
        execute_sql("ALTER TABLE {$CFG->prefix}stats_user_daily RENAME COLUMN reads TO statsreads", false);
        execute_sql("ALTER TABLE {$CFG->prefix}stats_user_daily RENAME COLUMN writes TO statswrites", false);
        execute_sql("ALTER TABLE {$CFG->prefix}stats_user_weekly RENAME COLUMN reads TO statsreads", false);
        execute_sql("ALTER TABLE {$CFG->prefix}stats_user_weekly RENAME COLUMN writes TO statswrites", false);
        execute_sql("ALTER TABLE {$CFG->prefix}stats_user_monthly RENAME COLUMN reads TO statsreads", false);
        execute_sql("ALTER TABLE {$CFG->prefix}stats_user_monthly RENAME COLUMN writes TO statswrites", false);
    }
    // Adding some missing log actions
    if ($oldversion < 2006060400) {
        // But only if they doesn't exist (because this was introduced after branch and we could be duplicating!)
        if (!record_exists('log_display', 'module', 'course', 'action', 'report log')) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'report log', 'course', 'fullname')");
        }
        if (!record_exists('log_display', 'module', 'course', 'action', 'report live')) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'report live', 'course', 'fullname')");
        }
        if (!record_exists('log_display', 'module', 'course', 'action', 'report outline')) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'report outline', 'course', 'fullname')");
        }
        if (!record_exists('log_display', 'module', 'course', 'action', 'report participation')) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'report participation', 'course', 'fullname')");
        }
        if (!record_exists('log_display', 'module', 'course', 'action', 'report stats')) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'report stats', 'course', 'fullname')");
        }
    }
    //Renaming lastIP to lastip (all fields lowercase)
    if ($oldversion < 2006060900) {
        //Not needed unded PG because it stores fieldnames lowecase by default
        //Only if it exists (because MOODLE_16_STABLE could have done this work before. Bug 5763)
        //$fields = $db->MetaColumnNames($CFG->prefix.'user');
        //if (in_array('lastIP',$fields)) {
        //    table_column("user", "lastIP", "lastip", "varchar", "15", "", "", "", "currentlogin");
        //}
    }
    if ($oldversion < 2006080400) {
        modify_database('', "CREATE TABLE prefix_role (\n                                  id SERIAL PRIMARY KEY,\n                                  name varchar(255) NOT NULL default '',\n                                  shortname varchar(100) NOT NULL default '',     \n                                  description text NOT NULL default '',\n                                  sortorder integer NOT NULL default '0'\n                                );");
        modify_database('', "CREATE TABLE prefix_context (\n                                  id SERIAL PRIMARY KEY,\n                                  level integer NOT NULL default 0,\n                                  instanceid integer NOT NULL default 0\n                                );");
        modify_database('', "CREATE TABLE prefix_role_assignments (\n                                  id SERIAL PRIMARY KEY,\n                                  roleid integer NOT NULL default 0,\n                                  contextid integer NOT NULL default 0,\n                                  userid integer NOT NULL default 0,\n                                  hidden integer NOT NULL default 0,\n                                  timestart integer NOT NULL default 0,\n                                  timeend integer NOT NULL default 0,\n                                  timemodified integer NOT NULL default 0,\n                                  modifierid integer NOT NULL default 0,\n                                  enrol varchar(20) NOT NULL default '',\n                                  sortorder integer NOT NULL default '0'\n                                );");
        modify_database('', "CREATE TABLE prefix_role_capabilities (\n                                  id SERIAL PRIMARY KEY,\n                                  contextid integer NOT NULL default 0,\n                                  roleid integer NOT NULL default 0,\n                                  capability varchar(255) NOT NULL default '',\n                                  permission integer NOT NULL default 0,\n                                  timemodified integer NOT NULL default 0,\n                                  modifierid integer NOT NULL default 0\n                                );");
        modify_database('', "CREATE TABLE prefix_role_deny_grant (\n                                  id SERIAL PRIMARY KEY,\n                                  roleid integer NOT NULL default '0',\n                                  unviewableroleid integer NOT NULL default '0'\n                                );");
        modify_database('', "CREATE TABLE prefix_capabilities ( \n                              id SERIAL PRIMARY KEY,\n                              name varchar(255) NOT NULL default '', \n                              captype varchar(50) NOT NULL default '', \n                              contextlevel integer NOT NULL default 0, \n                              component varchar(100) NOT NULL default ''\n                                );");
        modify_database('', "CREATE TABLE prefix_role_names ( \n                              id SERIAL PRIMARY KEY,\n                              roleid integer NOT NULL default 0,\n                              contextid integer NOT NULL default 0, \n                              text text NOT NULL default ''\n                                );");
    }
    if ($oldversion < 2006081000) {
        modify_database('', "CREATE INDEX prefix_role_sortorder_idx ON prefix_role (sortorder);");
        modify_database('', "CREATE INDEX prefix_context_instanceid_idx ON prefix_context (instanceid);");
        modify_database('', "CREATE UNIQUE INDEX prefix_context_levelinstanceid_idx ON prefix_context (level, instanceid);");
        modify_database('', "CREATE INDEX prefix_role_assignments_roleid_idx ON prefix_role_assignments (roleid);");
        modify_database('', "CREATE INDEX prefix_role_assignments_contextidid_idx ON prefix_role_assignments (contextid);");
        modify_database('', "CREATE INDEX prefix_role_assignments_userid_idx ON prefix_role_assignments (userid);");
        modify_database('', "CREATE UNIQUE INDEX prefix_role_assignments_contextidroleiduserid_idx ON prefix_role_assignments (contextid, roleid, userid);");
        modify_database('', "CREATE INDEX prefix_role_assignments_sortorder_idx ON prefix_role_assignments (sortorder);");
        modify_database('', "CREATE INDEX prefix_role_capabilities_roleid_idx ON prefix_role_capabilities (roleid);");
        modify_database('', "CREATE INDEX prefix_role_capabilities_contextid_idx ON prefix_role_capabilities (contextid);");
        modify_database('', "CREATE INDEX prefix_role_capabilities_modifierid_idx ON prefix_role_capabilities (modifierid);");
        // MDL-10640  adding missing index from upgrade
        modify_database('', "CREATE INDEX prefix_role_capabilities_capability_idx ON prefix_role_capabilities (capability);");
        modify_database('', "CREATE UNIQUE INDEX prefix_role_capabilities_roleidcontextidcapability_idx ON prefix_role_capabilities (roleid, contextid, capability);");
        modify_database('', "CREATE INDEX prefix_role_deny_grant_roleid_idx ON prefix_role_deny_grant (roleid);");
        modify_database('', "CREATE INDEX prefix_role_deny_grant_unviewableroleid_idx ON prefix_role_deny_grant (unviewableroleid);");
        modify_database('', "CREATE UNIQUE INDEX prefix_role_deny_grant_roleidunviewableroleid_idx ON prefix_role_deny_grant (roleid, unviewableroleid);");
        modify_database('', "CREATE UNIQUE INDEX prefix_capabilities_name_idx ON prefix_capabilities (name);");
        modify_database('', "CREATE INDEX prefix_role_names_roleid_idx ON prefix_role_names (roleid);");
        modify_database('', "CREATE INDEX prefix_role_names_contextid_idx ON prefix_role_names (contextid);");
        modify_database('', "CREATE UNIQUE INDEX prefix_role_names_roleidcontextid_idx ON prefix_role_names (roleid, contextid);");
    }
    if ($oldversion < 2006081700) {
        modify_database('', "DROP TABLE prefix_role_deny_grant");
        modify_database('', "CREATE TABLE prefix_role_allow_assign (    \n            id SERIAL PRIMARY KEY,     \n            roleid integer NOT NULL default '0',   \n            allowassign integer NOT NULL default '0'      \n        );");
        modify_database('', "CREATE INDEX prefix_role_allow_assign_roleid_idx ON prefix_role_allow_assign (roleid);");
        modify_database('', "CREATE INDEX prefix_role_allow_assign_allowassign_idx ON prefix_role_allow_assign (allowassign);");
        modify_database('', "CREATE UNIQUE INDEX prefix_role_allow_assign_roleidallowassign_idx ON prefix_role_allow_assign (roleid, allowassign);");
        modify_database('', "CREATE TABLE prefix_role_allow_override (    \n            id SERIAL PRIMARY KEY,     \n            roleid integer NOT NULL default '0',   \n            allowoverride integer NOT NULL default '0'      \n        );");
        modify_database('', "CREATE INDEX prefix_role_allow_override_roleid_idx ON prefix_role_allow_override (roleid);");
        modify_database('', "CREATE INDEX prefix_role_allow_override_allowoverride_idx ON prefix_role_allow_override (allowoverride);");
        modify_database('', "CREATE UNIQUE INDEX prefix_role_allow_override_roleidallowoverride_idx ON prefix_role_allow_override (roleid, allowoverride);");
    }
    if ($oldversion < 2006082100) {
        execute_sql("DROP INDEX {$CFG->prefix}context_levelinstanceid_idx;", false);
        table_column('context', 'level', 'aggregatelevel', 'integer', '10', 'unsigned', '0', 'not null', '');
        modify_database('', "CREATE UNIQUE INDEX prefix_context_aggregatelevelinstanceid_idx ON prefix_context (aggregatelevel, instanceid);");
    }
    if ($oldversion < 2006082200) {
        table_column('timezone', 'rule', 'tzrule', 'varchar', '20', '', '', 'not null', '');
    }
    if ($oldversion < 2006082800) {
        table_column('user', '', 'ajax', 'integer', '1', 'unsigned', '1', 'not null', 'htmleditor');
    }
    if ($oldversion < 2006082900) {
        execute_sql("DROP TABLE {$CFG->prefix}sessions", true);
        execute_sql("\n            CREATE TABLE {$CFG->prefix}sessions2 (\n                sesskey VARCHAR(255) NOT NULL default '',\n                expiry TIMESTAMP NOT NULL,\n                expireref VARCHAR(255),\n                created TIMESTAMP NOT NULL,\n                modified TIMESTAMP NOT NULL,\n                sessdata TEXT,\n                CONSTRAINT {$CFG->prefix}sess_ses_pk PRIMARY KEY (sesskey)\n            );", true);
        execute_sql("\n            CREATE INDEX {$CFG->prefix}sess_exp_ix ON {$CFG->prefix}sessions2 (expiry);", true);
        execute_sql("\n            CREATE INDEX {$CFG->prefix}sess_exp2_ix ON {$CFG->prefix}sessions2 (expireref);", true);
    }
    if ($oldversion < 2006083002) {
        table_column('capabilities', '', 'riskbitmask', 'INTEGER', '10', 'unsigned', '0', 'not null', '');
    }
    if ($oldversion < 2006083100) {
        execute_sql("ALTER TABLE {$CFG->prefix}course ALTER COLUMN modinfo DROP NOT NULL");
        execute_sql("ALTER TABLE {$CFG->prefix}course ALTER COLUMN modinfo DROP DEFAULT");
    }
    if ($oldversion < 2006083101) {
        execute_sql("ALTER TABLE {$CFG->prefix}course_categories ALTER COLUMN description DROP NOT NULL");
        execute_sql("ALTER TABLE {$CFG->prefix}course_categories ALTER COLUMN description DROP DEFAULT");
    }
    if ($oldversion < 2006083102) {
        execute_sql("ALTER TABLE {$CFG->prefix}user ALTER COLUMN description DROP NOT NULL");
        execute_sql("ALTER TABLE {$CFG->prefix}user ALTER COLUMN description DROP DEFAULT");
    }
    if ($oldversion < 2006090200) {
        execute_sql("ALTER TABLE {$CFG->prefix}course_sections ALTER COLUMN summary DROP NOT NULL");
        execute_sql("ALTER TABLE {$CFG->prefix}course_sections ALTER COLUMN summary DROP DEFAULT");
        execute_sql("ALTER TABLE {$CFG->prefix}course_sections ALTER COLUMN sequence DROP NOT NULL");
        execute_sql("ALTER TABLE {$CFG->prefix}course_sections ALTER COLUMN sequence DROP DEFAULT");
    }
    // table to keep track of course page access times, used in online participants block, and participants list
    if ($oldversion < 2006091200) {
        execute_sql("CREATE TABLE {$CFG->prefix}user_lastaccess ( \n                    id SERIAL PRIMARY KEY,     \n                    userid integer NOT NULL default 0,\n                    courseid integer NOT NULL default 0, \n                    timeaccess integer NOT NULL default 0\n                    );", true);
        execute_sql("CREATE INDEX {$CFG->prefix}user_lastaccess_userid_idx ON {$CFG->prefix}user_lastaccess (userid);", true);
        execute_sql("CREATE INDEX {$CFG->prefix}user_lastaccess_courseid_idx ON {$CFG->prefix}user_lastaccess (courseid);", true);
        execute_sql("CREATE UNIQUE INDEX {$CFG->prefix}user_lastaccess_useridcourseid_idx ON {$CFG->prefix}user_lastaccess (userid, courseid);", true);
    }
    if (!empty($CFG->rolesactive) and $oldversion < 2006091212) {
        // Reload the guest roles completely with new defaults
        if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
            delete_records('capabilities');
            $sitecontext = get_context_instance(CONTEXT_SYSTEM);
            foreach ($guestroles as $guestrole) {
                delete_records('role_capabilities', 'roleid', $guestrole->id);
                assign_capability('moodle/legacy:guest', CAP_ALLOW, $guestrole->id, $sitecontext->id);
            }
        }
    }
    if ($oldversion < 2006091700) {
        table_column('course', '', 'defaultrole', 'integer', '10', 'unsigned', '0', 'not null');
    }
    if ($oldversion < 2006091800) {
        delete_records('config', 'name', 'showsiteparticipantslist');
        delete_records('config', 'name', 'requestedteachername');
        delete_records('config', 'name', 'requestedteachersname');
        delete_records('config', 'name', 'requestedstudentname');
        delete_records('config', 'name', 'requestedstudentsname');
    }
    if (!empty($CFG->rolesactive) and $oldversion < 2006091901) {
        if ($roles = get_records('role')) {
            $first = array_shift($roles);
            if (!empty($first->shortname)) {
                // shortnames already exist
            } else {
                table_column('role', '', 'shortname', 'varchar', '100', '', '', 'not null', 'name');
                $legacy_names = array('admin', 'coursecreator', 'editingteacher', 'teacher', 'student', 'guest');
                foreach ($legacy_names as $name) {
                    if ($roles = get_roles_with_capability('moodle/legacy:' . $name, CAP_ALLOW)) {
                        $i = '';
                        foreach ($roles as $role) {
                            if (empty($role->shortname)) {
                                $updated = new object();
                                $updated->id = $role->id;
                                $updated->shortname = $name . $i;
                                update_record('role', $updated);
                                $i++;
                            }
                        }
                    }
                }
            }
        }
    }
    /// Tables for customisable user profile fields
    if ($oldversion < 2006092000) {
        execute_sql("CREATE TABLE {$CFG->prefix}user_info_field (\n                        id BIGSERIAL,\n                        name VARCHAR(255) NOT NULL default '',\n                        datatype VARCHAR(255) NOT NULL default '',\n                        categoryid BIGINT NOT NULL default 0,\n                        sortorder BIGINT NOT NULL default 0,\n                        required SMALLINT NOT NULL default 0,\n                        locked SMALLINT NOT NULL default 0,\n                        visible SMALLINT NOT NULL default 0,\n                        defaultdata TEXT,\n                        CONSTRAINT {$CFG->prefix}userinfofiel_id_pk PRIMARY KEY (id));", true);
        execute_sql("COMMENT ON TABLE {$CFG->prefix}user_info_field IS 'Customisable user profile fields';", true);
        execute_sql("CREATE TABLE {$CFG->prefix}user_info_category (\n                        id BIGSERIAL,\n                        name VARCHAR(255) NOT NULL default '',\n                        sortorder BIGINT NOT NULL default 0,\n                        CONSTRAINT {$CFG->prefix}userinfocate_id_pk PRIMARY KEY (id));", true);
        execute_sql("COMMENT ON TABLE {$CFG->prefix}user_info_category IS 'Customisable fields categories';", true);
        execute_sql("CREATE TABLE {$CFG->prefix}user_info_data (\n                        id BIGSERIAL,\n                        userid BIGINT NOT NULL default 0,\n                        fieldid BIGINT NOT NULL default 0,\n                        data TEXT NOT NULL,\n                        CONSTRAINT {$CFG->prefix}userinfodata_id_pk PRIMARY KEY (id));", true);
        execute_sql("COMMENT ON TABLE {$CFG->prefix}user_info_data IS 'Data for the customisable user fields';", true);
    }
    if ($oldversion < 2006092200) {
        table_column('context', 'aggregatelevel', 'contextlevel', 'int', '10', 'unsigned', '0', 'not null', '');
        /*      execute_sql("ALTER TABLE `{$CFG->prefix}context` DROP INDEX `aggregatelevel-instanceid`;",false);
                execute_sql("ALTER TABLE `{$CFG->prefix}context` ADD UNIQUE INDEX `contextlevel-instanceid` (`contextlevel`, `instanceid`)",false);  // see 2006092409 below */
    }
    if ($oldversion < 2006092302) {
        // fix sortorder first if needed
        if ($roles = get_all_roles()) {
            $i = 0;
            foreach ($roles as $rolex) {
                if ($rolex->sortorder != $i) {
                    $r = new object();
                    $r->id = $rolex->id;
                    $r->sortorder = $i;
                    update_record('role', $r);
                }
                $i++;
            }
        }
        /*        execute_sql("ALTER TABLE {$CFG->prefix}role DROP INDEX {$CFG->prefix}role_sor_ix;");
                execute_sql("ALTER TABLE {$CFG->prefix}role ADD UNIQUE INDEX {$CFG->prefix}role_sor_uix (sortorder)");*/
    }
    if ($oldversion < 2006092400) {
        table_column('user', '', 'trustbitmask', 'INTEGER', '10', 'unsigned', '0', 'not null', '');
    }
    if ($oldversion < 2006092409) {
        // ok, once more and now correctly!
        execute_sql("DROP INDEX \"aggregatelevel-instanceid\";", false);
        execute_sql("DROP INDEX \"contextlevel-instanceid\";", false);
        execute_sql("CREATE UNIQUE INDEX {$CFG->prefix}cont_conins_uix ON {$CFG->prefix}context (contextlevel, instanceid);", false);
        execute_sql("DROP INDEX {$CFG->prefix}role_sor_ix;", false);
        execute_sql("DROP INDEX {$CFG->prefix}role_sor_uix;", false);
        execute_sql("CREATE UNIQUE INDEX {$CFG->prefix}role_sor_uix ON {$CFG->prefix}role (sortorder);", false);
    }
    if ($oldversion < 2006092410) {
        /// Convert all the PG unique keys into their corresponding unique indexes
        /// we don't want such keys inside Moodle 1.7 and above
        /// Look for all the UNIQUE CONSTRAINSTS existing in DB
        $uniquecons = get_records_sql("SELECT conname, relname, conkey, clas.oid AS tableoid\n                                          FROM pg_constraint cons,\n                                               pg_class clas\n                                         WHERE cons.contype='u'\n                                           AND cons.conrelid = clas.oid");
        /// Iterate over every unique constraint, calculating its fields
        if ($uniquecons) {
            foreach ($uniquecons as $uniquecon) {
                $conscols = trim(trim($uniquecon->conkey, '}'), '{');
                $conscols = explode(',', $conscols);
                /// Iterate over each column to fetch its name
                $indexcols = array();
                foreach ($conscols as $conscol) {
                    $column = get_record_sql("SELECT attname, attname\n                                                 FROM pg_attribute\n                                                WHERE attrelid = {$uniquecon->tableoid}\n                                                  AND attnum   = {$conscol}");
                    $indexcols[] = $column->attname;
                }
                /// Drop the old UNIQUE CONSTRAINT
                execute_sql("ALTER TABLE {$uniquecon->relname} DROP CONSTRAINT {$uniquecon->conname}", false);
                /// Create the new UNIQUE INDEX
                execute_sql("CREATE UNIQUE INDEX {$uniquecon->relname}_" . implode('_', $indexcols) . "_uix ON {$uniquecon->relname} (" . implode(', ', $indexcols) . ')', false);
            }
        }
    }
    if ($oldversion < 2006092601) {
        table_column('log_display', 'field', 'field', 'varchar', '200', '', '', 'not null', '');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return $result;
}
示例#24
0
function upgrade_blocks_plugins($continueto)
{
    global $CFG, $db;
    $blocktitles = array();
    $invalidblocks = array();
    $validblocks = array();
    $notices = array();
    //Count the number of blocks in db
    $blockcount = count_records('block');
    //If there isn't records. This is the first install, so I remember it
    if ($blockcount == 0) {
        $first_install = true;
    } else {
        $first_install = false;
    }
    $site = get_site();
    if (!($blocks = get_list_of_plugins('blocks', 'db'))) {
        error('No blocks installed!');
    }
    include_once $CFG->dirroot . '/blocks/moodleblock.class.php';
    if (!class_exists('block_base')) {
        error('Class block_base is not defined or file not found for /blocks/moodleblock.class.php');
    }
    foreach ($blocks as $blockname) {
        if ($blockname == 'NEWBLOCK') {
            // Someone has unzipped the template, ignore it
            continue;
        }
        if (!block_is_compatible($blockname)) {
            // This is an old-style block
            //$notices[] = 'Block '. $blockname .' is not compatible with the current version of Mooodle and needs to be updated by a programmer.';
            $invalidblocks[] = $blockname;
            continue;
        }
        $fullblock = $CFG->dirroot . '/blocks/' . $blockname;
        if (is_readable($fullblock . '/block_' . $blockname . '.php')) {
            include_once $fullblock . '/block_' . $blockname . '.php';
        } else {
            $notices[] = 'Block ' . $blockname . ': ' . $fullblock . '/block_' . $blockname . '.php was not readable';
            continue;
        }
        $oldupgrade = false;
        $newupgrade = false;
        if (@is_dir($fullblock . '/db/')) {
            if (@is_readable($fullblock . '/db/' . $CFG->dbtype . '.php')) {
                include_once $fullblock . '/db/' . $CFG->dbtype . '.php';
                // defines old upgrading function
                $oldupgrade = true;
            }
            if (@is_readable($fullblock . '/db/upgrade.php')) {
                include_once $fullblock . '/db/upgrade.php';
                // defines new upgrading function
                $newupgrade = true;
            }
        }
        $classname = 'block_' . $blockname;
        if (!class_exists($classname)) {
            $notices[] = 'Block ' . $blockname . ': ' . $classname . ' not implemented';
            continue;
        }
        // Here is the place to see if the block implements a constructor (old style),
        // an init() function (new style) or nothing at all (error time).
        $constructor = get_class_constructor($classname);
        if (empty($constructor)) {
            // No constructor
            $notices[] = 'Block ' . $blockname . ': class does not have a constructor';
            $invalidblocks[] = $blockname;
            continue;
        }
        $block = new stdClass();
        // This may be used to update the db below
        $blockobj = new $classname();
        // This is what we 'll be testing
        // Inherits from block_base?
        if (!is_subclass_of($blockobj, 'block_base')) {
            $notices[] = 'Block ' . $blockname . ': class does not inherit from block_base';
            continue;
        }
        // OK, it's as we all hoped. For further tests, the object will do them itself.
        if (!$blockobj->_self_test()) {
            $notices[] = 'Block ' . $blockname . ': self test failed';
            continue;
        }
        $block->version = $blockobj->get_version();
        if (!isset($block->version)) {
            $notices[] = 'Block ' . $blockname . ': has no version support. It must be updated by a programmer.';
            continue;
        }
        $block->name = $blockname;
        // The name MUST match the directory
        $blocktitle = $blockobj->get_title();
        if ($currblock = get_record('block', 'name', $block->name)) {
            if ($currblock->version == $block->version) {
                // do nothing
            } else {
                if ($currblock->version < $block->version) {
                    if (empty($updated_blocks)) {
                        $strblocksetup = get_string('blocksetup');
                        print_header($strblocksetup, $strblocksetup, build_navigation(array(array('name' => $strblocksetup, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
                    }
                    $updated_blocks = true;
                    upgrade_log_start();
                    print_heading('New version of ' . $blocktitle . ' (' . $block->name . ') exists');
                    @set_time_limit(0);
                    // To allow slow databases to complete the long SQL
                    /// Run de old and new upgrade functions for the module
                    $oldupgrade_function = $block->name . '_upgrade';
                    $newupgrade_function = 'xmldb_block_' . $block->name . '_upgrade';
                    /// First, the old function if exists
                    $oldupgrade_status = true;
                    if ($oldupgrade && function_exists($oldupgrade_function)) {
                        $db->debug = true;
                        $oldupgrade_status = $oldupgrade_function($currblock->version, $block);
                    } else {
                        if ($oldupgrade) {
                            notify('Upgrade function ' . $oldupgrade_function . ' was not available in ' . $fullblock . '/db/' . $CFG->dbtype . '.php');
                        }
                    }
                    /// Then, the new function if exists and the old one was ok
                    $newupgrade_status = true;
                    if ($newupgrade && function_exists($newupgrade_function) && $oldupgrade_status) {
                        $db->debug = true;
                        $newupgrade_status = $newupgrade_function($currblock->version, $block);
                    } else {
                        if ($newupgrade) {
                            notify('Upgrade function ' . $newupgrade_function . ' was not available in ' . $fullblock . '/db/upgrade.php');
                        }
                    }
                    $db->debug = false;
                    /// Now analyze upgrade results
                    if ($oldupgrade_status && $newupgrade_status) {
                        // No upgrading failed
                        // Set the block cron on upgrade
                        $block->cron = !empty($blockobj->cron) ? $blockobj->cron : 0;
                        // OK so far, now update the block record
                        $block->id = $currblock->id;
                        if (!update_record('block', $block)) {
                            error('Could not update block ' . $block->name . ' record in block table!');
                        }
                        $component = 'block/' . $block->name;
                        if (!update_capabilities($component)) {
                            error('Could not update ' . $block->name . ' capabilities!');
                        }
                        events_update_definition($component);
                        notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess');
                    } else {
                        notify('Upgrading block ' . $block->name . ' from ' . $currblock->version . ' to ' . $block->version . ' FAILED!');
                    }
                    echo '<hr />';
                } else {
                    upgrade_log_start();
                    error('Version mismatch: block ' . $block->name . ' can\'t downgrade ' . $currblock->version . ' -> ' . $block->version . '!');
                }
            }
        } else {
            // block not installed yet, so install it
            // If it allows multiples, start with it enabled
            if ($blockobj->instance_allow_multiple()) {
                $block->multiple = 1;
            }
            // Set the block cron on install
            $block->cron = !empty($blockobj->cron) ? $blockobj->cron : 0;
            // [pj] Normally this would be inline in the if, but we need to
            //      check for NULL (necessary for 4.0.5 <= PHP < 4.2.0)
            $conflictblock = array_search($blocktitle, $blocktitles);
            if ($conflictblock !== false && $conflictblock !== NULL) {
                // Duplicate block titles are not allowed, they confuse people
                // AND PHP's associative arrays ;)
                error('<strong>Naming conflict</strong>: block <strong>' . $block->name . '</strong> has the same title with an existing block, <strong>' . $conflictblock . '</strong>!');
            }
            if (empty($updated_blocks)) {
                $strblocksetup = get_string('blocksetup');
                print_header($strblocksetup, $strblocksetup, build_navigation(array(array('name' => $strblocksetup, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
            }
            $updated_blocks = true;
            upgrade_log_start();
            print_heading($block->name);
            $db->debug = true;
            @set_time_limit(0);
            // To allow slow databases to complete the long SQL
            /// Both old .sql files and new install.xml are supported
            /// but we priorize install.xml (XMLDB) if present
            $status = false;
            if (file_exists($fullblock . '/db/install.xml')) {
                $status = install_from_xmldb_file($fullblock . '/db/install.xml');
                //New method
            } else {
                if (file_exists($fullblock . '/db/' . $CFG->dbtype . '.sql')) {
                    $status = modify_database($fullblock . '/db/' . $CFG->dbtype . '.sql');
                    //Old method
                } else {
                    $status = true;
                }
            }
            $db->debug = false;
            if ($status) {
                if ($block->id = insert_record('block', $block)) {
                    $blockobj->after_install();
                    $component = 'block/' . $block->name;
                    if (!update_capabilities($component)) {
                        notify('Could not set up ' . $block->name . ' capabilities!');
                    }
                    events_update_definition($component);
                    notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess');
                    echo '<hr />';
                } else {
                    error($block->name . ' block could not be added to the block list!');
                }
            } else {
                error('Block ' . $block->name . ' tables could NOT be set up successfully!');
            }
        }
        $blocktitles[$block->name] = $blocktitle;
    }
    if (!empty($notices)) {
        upgrade_log_start();
        foreach ($notices as $notice) {
            notify($notice);
        }
    }
    // Finally, if we are in the first_install of BLOCKS (this means that we are
    // upgrading from Moodle < 1.3), put blocks in all existing courses.
    if ($first_install) {
        upgrade_log_start();
        //Iterate over each course
        if ($courses = get_records('course')) {
            foreach ($courses as $course) {
                $page = page_create_object(PAGE_COURSE_VIEW, $course->id);
                blocks_repopulate_page($page);
            }
        }
    }
    if (!empty($CFG->siteblocksadded)) {
        /// This is a once-off hack to make a proper upgrade
        upgrade_log_start();
        $page = page_create_object(PAGE_COURSE_VIEW, SITEID);
        blocks_repopulate_page($page);
        delete_records('config', 'name', 'siteblocksadded');
    }
    upgrade_log_finish();
    if (!empty($updated_blocks)) {
        print_continue($continueto);
        print_footer('none');
        die;
    }
}
示例#25
0
function main_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($oldversion == 0) {
        execute_sql("\n          CREATE TABLE `config` (\n            `id` int(10) unsigned NOT NULL auto_increment,\n            `name` varchar(255) NOT NULL default '',\n            `value` varchar(255) NOT NULL default '',\n            PRIMARY KEY  (`id`),\n            UNIQUE KEY `name` (`name`)\n          ) COMMENT='Moodle configuration variables';");
        notify("Created a new table 'config' to hold configuration data");
    }
    if ($oldversion < 2002073100) {
        execute_sql(" DELETE FROM `modules` WHERE `name` = 'chat' ");
    }
    if ($oldversion < 2002080200) {
        execute_sql(" ALTER TABLE `modules` DROP `fullname`  ");
        execute_sql(" ALTER TABLE `modules` DROP `search`  ");
    }
    if ($oldversion < 2002080300) {
        execute_sql(" ALTER TABLE `log_display` CHANGE `table` `mtable` VARCHAR( 20 ) NOT NULL ");
        execute_sql(" ALTER TABLE `user_teachers` CHANGE `authority` `authority` TINYINT( 3 ) DEFAULT '3' NOT NULL ");
    }
    if ($oldversion < 2002082100) {
        execute_sql(" ALTER TABLE `course` CHANGE `guest` `guest` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL ");
    }
    if ($oldversion < 2002082101) {
        execute_sql(" ALTER TABLE `user` ADD `maildisplay` TINYINT(2) UNSIGNED DEFAULT '2' NOT NULL AFTER `mailformat` ");
    }
    if ($oldversion < 2002090100) {
        execute_sql(" ALTER TABLE `course_sections` CHANGE `summary` `summary` TEXT NOT NULL ");
    }
    if ($oldversion < 2002090701) {
        execute_sql(" ALTER TABLE `user_teachers` CHANGE `authority` `authority` TINYINT( 10 ) DEFAULT '3' NOT NULL ");
        execute_sql(" ALTER TABLE `user_teachers` ADD `role` VARCHAR(40) NOT NULL AFTER `authority` ");
    }
    if ($oldversion < 2002090800) {
        execute_sql(" ALTER TABLE `course` ADD `teachers` VARCHAR( 100 ) DEFAULT 'Teachers' NOT NULL AFTER `teacher` ");
        execute_sql(" ALTER TABLE `course` ADD `students` VARCHAR( 100 ) DEFAULT 'Students' NOT NULL AFTER `student` ");
    }
    if ($oldversion < 2002091000) {
        execute_sql(" ALTER TABLE `user` CHANGE `personality` `secret` VARCHAR( 15 ) NOT NULL DEFAULT ''  ");
    }
    if ($oldversion < 2002091400) {
        execute_sql(" ALTER TABLE `user` ADD `lang` VARCHAR( 3 ) DEFAULT 'en' NOT NULL AFTER `country`  ");
    }
    if ($oldversion < 2002091900) {
        notify("Most Moodle configuration variables have been moved to the database and can now be edited via the admin page.");
        notify("Although it is not vital that you do so, you might want to edit <U>config.php</U> and remove all the unused settings (except the database, URL and directory definitions).  See <U>config-dist.php</U> for an example of how your new slim config.php should look.");
    }
    if ($oldversion < 2002092000) {
        execute_sql(" ALTER TABLE `user` CHANGE `lang` `lang` VARCHAR(5) DEFAULT 'en' NOT NULL  ");
    }
    if ($oldversion < 2002092100) {
        execute_sql(" ALTER TABLE `user` ADD `deleted` TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL AFTER `confirmed` ");
    }
    if ($oldversion < 2002101001) {
        execute_sql(" ALTER TABLE `user` ADD `htmleditor` TINYINT(1) UNSIGNED DEFAULT '1' NOT NULL AFTER `maildisplay` ");
    }
    if ($oldversion < 2002101701) {
        execute_sql(" ALTER TABLE `reading` RENAME `resource` ");
        // Small line with big consequences!
        execute_sql(" DELETE FROM `log_display` WHERE module = 'reading'");
        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('resource', 'view', 'resource', 'name') ");
        execute_sql(" UPDATE log SET module = 'resource' WHERE module = 'reading' ");
        execute_sql(" UPDATE modules SET name = 'resource' WHERE name = 'reading' ");
    }
    if ($oldversion < 2002102503) {
        execute_sql(" ALTER TABLE `course` ADD `modinfo` TEXT NOT NULL AFTER `format` ");
        require_once "{$CFG->dirroot}/mod/forum/lib.php";
        require_once "{$CFG->dirroot}/course/lib.php";
        if (!($module = get_record("modules", "name", "forum"))) {
            notify("Could not find forum module!!");
            return false;
        }
        // First upgrade the site forums
        if ($site = get_site()) {
            print_heading("Making News forums editable for main site (moving to section 1)...");
            if ($news = forum_get_course_forum($site->id, "news")) {
                $mod->course = $site->id;
                $mod->module = $module->id;
                $mod->instance = $news->id;
                $mod->section = 1;
                if (!($mod->coursemodule = add_course_module($mod))) {
                    notify("Could not add a new course module to the site");
                    return false;
                }
                if (!($sectionid = add_mod_to_section($mod))) {
                    notify("Could not add the new course module to that section");
                    return false;
                }
                if (!set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
                    notify("Could not update the course module with the correct section");
                    return false;
                }
            }
        }
        // Now upgrade the courses.
        if ($courses = get_records_sql("SELECT * FROM course WHERE category > 0")) {
            print_heading("Making News and Social forums editable for each course (moving to section 0)...");
            foreach ($courses as $course) {
                if ($course->format == "social") {
                    // we won't touch them
                    continue;
                }
                if ($news = forum_get_course_forum($course->id, "news")) {
                    $mod->course = $course->id;
                    $mod->module = $module->id;
                    $mod->instance = $news->id;
                    $mod->section = 0;
                    if (!($mod->coursemodule = add_course_module($mod))) {
                        notify("Could not add a new course module to the course '" . format_string($course->fullname) . "'");
                        return false;
                    }
                    if (!($sectionid = add_mod_to_section($mod))) {
                        notify("Could not add the new course module to that section");
                        return false;
                    }
                    if (!set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
                        notify("Could not update the course module with the correct section");
                        return false;
                    }
                }
                if ($social = forum_get_course_forum($course->id, "social")) {
                    $mod->course = $course->id;
                    $mod->module = $module->id;
                    $mod->instance = $social->id;
                    $mod->section = 0;
                    if (!($mod->coursemodule = add_course_module($mod))) {
                        notify("Could not add a new course module to the course '" . format_string($course->fullname) . "'");
                        return false;
                    }
                    if (!($sectionid = add_mod_to_section($mod))) {
                        notify("Could not add the new course module to that section");
                        return false;
                    }
                    if (!set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
                        notify("Could not update the course module with the correct section");
                        return false;
                    }
                }
            }
        }
    }
    if ($oldversion < 2002111003) {
        execute_sql(" ALTER TABLE `course` ADD `modinfo` TEXT NOT NULL AFTER `format` ");
        if ($courses = get_records_sql("SELECT * FROM course")) {
            require_once "{$CFG->dirroot}/course/lib.php";
            foreach ($courses as $course) {
                $modinfo = serialize(get_array_of_activities($course->id));
                if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
                    notify("Could not cache module information for course '" . format_string($course->fullname) . "'!");
                }
            }
        }
    }
    if ($oldversion < 2002111100) {
        print_simple_box_start("CENTER", "", "#FFCCCC");
        echo "<FONT SIZE=+1>";
        echo "<P>Changes have been made to all built-in themes, to add the new popup navigation menu.";
        echo "<P>If you have customised themes, you will need to edit theme/xxxx/header.html as follows:";
        echo "<UL><LI>Change anywhere it says <B>\$" . "button</B> to say <B>\$" . "menu</B>";
        echo "<LI>Add <B>\$" . "button</B> elsewhere (eg at the end of the navigation bar)</UL>";
        echo "<P>See the standard themes for examples, eg: theme/standard/header.html";
        print_simple_box_end();
    }
    if ($oldversion < 2002111200) {
        execute_sql(" ALTER TABLE `course` ADD `showrecent` TINYINT(5) UNSIGNED DEFAULT '1' NOT NULL AFTER `numsections` ");
    }
    if ($oldversion < 2002111400) {
        // Rebuild all course caches, because some may not be done in new installs (eg site page)
        if ($courses = get_records_sql("SELECT * FROM course")) {
            require_once "{$CFG->dirroot}/course/lib.php";
            foreach ($courses as $course) {
                $modinfo = serialize(get_array_of_activities($course->id));
                if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
                    notify("Could not cache module information for course '" . format_string($course->fullname) . "'!");
                }
            }
        }
    }
    if ($oldversion < 2002112000) {
        set_config("guestloginbutton", 1);
    }
    if ($oldversion < 2002122300) {
        execute_sql("ALTER TABLE `log` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
        execute_sql("ALTER TABLE `user_admins` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
        execute_sql("ALTER TABLE `user_students` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
        execute_sql("ALTER TABLE `user_teachers` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
        execute_sql("ALTER TABLE `user_students` CHANGE `start` `timestart` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
        execute_sql("ALTER TABLE `user_students` CHANGE `end` `timeend` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
    }
    if ($oldversion < 2002122700) {
        if (!record_exists("log_display", "module", "user", "action", "view")) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('user', 'view', 'user', 'CONCAT(firstname,' ',lastname)') ");
        }
    }
    if ($oldversion < 2003010101) {
        delete_records("log_display", "module", "user");
        $new->module = "user";
        $new->action = "view";
        $new->mtable = "user";
        $new->field = "CONCAT(firstname,\" \",lastname)";
        insert_record("log_display", $new);
        delete_records("log_display", "module", "course");
        $new->module = "course";
        $new->action = "view";
        $new->mtable = "course";
        $new->field = "fullname";
        insert_record("log_display", $new);
        $new->action = "update";
        insert_record("log_display", $new);
        $new->action = "enrol";
        insert_record("log_display", $new);
    }
    if ($oldversion < 2003012200) {
        // execute_sql(" ALTER TABLE `log_display` CHANGE `module` `module` VARCHAR( 20 ) NOT NULL ");
        // Commented out - see below where it's done properly
    }
    if ($oldversion < 2003032500) {
        modify_database("", "CREATE TABLE `prefix_user_coursecreators` (\n                             `id` int(10) unsigned NOT NULL auto_increment,\n                             `userid` int(10) unsigned NOT NULL default '0',\n                             PRIMARY KEY  (`id`),\n                             UNIQUE KEY `id` (`id`)\n                             ) TYPE=MyISAM COMMENT='One record per course creator';");
    }
    if ($oldversion < 2003032602) {
        // Redoing it because of no prefix last time
        execute_sql(" ALTER TABLE `{$CFG->prefix}log_display` CHANGE `module` `module` VARCHAR( 20 ) NOT NULL ");
        // Add some indexes for speed
        execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX(course) ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX(userid) ");
    }
    if ($oldversion < 2003041400) {
        table_column("course_modules", "", "visible", "integer", "1", "unsigned", "1", "not null", "score");
    }
    if ($oldversion < 2003042104) {
        // Try to update permissions of all files
        if ($files = get_directory_list($CFG->dataroot)) {
            echo "Attempting to update permissions for all files... ignore any errors.";
            foreach ($files as $file) {
                echo "{$CFG->dataroot}/{$file}<br />";
                @chmod("{$CFG->dataroot}/{$file}", $CFG->directorypermissions);
            }
        }
    }
    if ($oldversion < 2003042400) {
        // Rebuild all course caches, because of changes to do with visible variable
        if ($courses = get_records_sql("SELECT * FROM {$CFG->prefix}course")) {
            require_once "{$CFG->dirroot}/course/lib.php";
            foreach ($courses as $course) {
                $modinfo = serialize(get_array_of_activities($course->id));
                if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
                    notify("Could not cache module information for course '" . format_string($course->fullname) . "'!");
                }
            }
        }
    }
    if ($oldversion < 2003042500) {
        //  Convert all usernames to lowercase.
        $users = get_records_sql("SELECT id, username FROM {$CFG->prefix}user");
        $cerrors = "";
        $rarray = array();
        foreach ($users as $user) {
            // Check for possible conflicts
            $lcname = trim(moodle_strtolower($user->username));
            if (in_array($lcname, $rarray)) {
                $cerrors .= $user->id . "->" . $lcname . '<br/>';
            } else {
                array_push($rarray, $lcname);
            }
        }
        if ($cerrors != '') {
            notify("Error: Cannot convert usernames to lowercase.\n                    Following usernames would overlap (id->username):<br/> {$cerrors} .\n                    Please resolve overlapping errors.");
            $result = false;
        }
        $cerrors = "";
        echo "Checking userdatabase:<br />";
        foreach ($users as $user) {
            $lcname = trim(moodle_strtolower($user->username));
            if ($lcname != $user->username) {
                $convert = set_field("user", "username", $lcname, "id", $user->id);
                if (!$convert) {
                    if ($cerrors) {
                        $cerrors .= ", ";
                    }
                    $cerrors .= $item;
                } else {
                    echo ".";
                }
            }
        }
        if ($cerrors != '') {
            notify("There were errors when converting following usernames to lowercase.\n                   '{$cerrors}' . Sorry, but you will need to fix your database by hand.");
            $result = false;
        }
    }
    if ($oldversion < 2003042600) {
        /// Some more indexes - we need all the help we can get on the logs
        //execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX(module) ");
        //execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX(action) ");
    }
    if ($oldversion < 2003042700) {
        /// Changing to multiple indexes
        execute_sql(" ALTER TABLE `{$CFG->prefix}log` DROP INDEX module ", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}log` DROP INDEX action ", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}log` DROP INDEX course ", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}log` DROP INDEX userid ", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX coursemoduleaction (course,module,action) ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX courseuserid (course,userid) ");
    }
    if ($oldversion < 2003042801) {
        execute_sql("CREATE TABLE `{$CFG->prefix}course_display` (\n                        `id` int(10) unsigned NOT NULL auto_increment,\n                        `course` int(10) unsigned NOT NULL default '0',\n                        `userid` int(10) unsigned NOT NULL default '0',\n                        `display` int(10) NOT NULL default '0',\n                        PRIMARY KEY  (`id`),\n                        UNIQUE KEY `id` (`id`),\n                        KEY `courseuserid` (course,userid)\n                     ) TYPE=MyISAM COMMENT='Stores info about how to display the course'");
    }
    if ($oldversion < 2003050400) {
        table_column("course_sections", "", "visible", "integer", "1", "unsigned", "1", "", "");
    }
    if ($oldversion < 2003050900) {
        table_column("modules", "", "visible", "integer", "1", "unsigned", "1", "", "");
    }
    if ($oldversion < 2003050902) {
        if (get_records("modules", "name", "pgassignment")) {
            print_simple_box("Note: the pgassignment module has been removed (it will be replaced later by the workshop module).  Go to the new 'Manage Modules' page and DELETE IT from your system", "center", "50%", "{$THEME->cellheading}", "20", "noticebox");
        }
    }
    if ($oldversion < 2003051600) {
        print_simple_box("Thanks for upgrading!<p>There are many changes since the last release.  Please read the release notes carefully.  If you are using CUSTOM themes you will need to edit them.  You will also need to check your site's config.php file.", "center", "50%", "{$THEME->cellheading}", "20", "noticebox");
    }
    if ($oldversion < 2003052300) {
        table_column("user", "", "autosubscribe", "integer", "1", "unsigned", "1", "", "htmleditor");
    }
    if ($oldversion < 2003072100) {
        table_column("course", "", "visible", "integer", "1", "unsigned", "1", "", "marker");
    }
    if ($oldversion < 2003072101) {
        table_column("course_sections", "sequence", "sequence", "text", "", "", "", "", "");
    }
    if ($oldversion < 2003072800) {
        print_simple_box("The following database index improves performance, but can be quite large - if you are upgrading and you have problems with a limited quota you may want to delete this index later from the '{$CFG->prefix}log' table in your database", "center", "50%", "{$THEME->cellheading}", "20", "noticebox");
        flush();
        execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX timecoursemoduleaction (time,course,module,action) ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}user_students` ADD INDEX courseuserid (course,userid) ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}user_teachers` ADD INDEX courseuserid (course,userid) ");
    }
    if ($oldversion < 2003072803) {
        table_column("course_categories", "", "description", "text", "", "", "");
        table_column("course_categories", "", "parent", "integer", "10", "unsigned");
        table_column("course_categories", "", "sortorder", "integer", "10", "unsigned");
        table_column("course_categories", "", "courseorder", "text", "", "", "");
        table_column("course_categories", "", "visible", "integer", "1", "unsigned", "1");
        table_column("course_categories", "", "timemodified", "integer", "10", "unsigned");
    }
    if ($oldversion < 2003080400) {
        table_column("course_categories", "courseorder", "courseorder", "integer", "10", "unsigned");
        table_column("course", "", "sortorder", "integer", "10", "unsigned", "0", "", "category");
    }
    if ($oldversion < 2003080700) {
        notify("Cleaning up categories and course ordering...");
        fix_course_sortorder();
    }
    if ($oldversion < 2003081001) {
        table_column("course", "format", "format", "varchar", "10", "", "topics");
    }
    if ($oldversion < 2003081500) {
        //        print_simple_box("Some important changes have been made to how course creators work.  Formerly, they could create new courses and assign teachers, and teachers could edit courses.  Now, ordinary teachers can no longer edit courses - they <b>need to be a teacher of a course AND a course creator</b>.  A new site-wide configuration variable allows you to choose whether to allow course creators to create new courses as well (by default this is off).  <p>The following update will automatically convert all your existing teachers into course creators, to maintain backward compatibility.  Make sure you look at your upgraded site carefully and understand these new changes.", "center", "50%", "$THEME->cellheading", "20", "noticebox");
        //        $count = 0;
        //        $errorcount = 0;
        //        if ($teachers = get_records("user_teachers")) {
        //            foreach ($teachers as $teacher) {
        //                if (! record_exists("user_coursecreators", "userid", $teacher->userid)) {
        //                    $creator = NULL;
        //                    $creator->userid = $teacher->userid;
        //                    if (!insert_record("user_coursecreators", $creator)) {
        //                        $errorcount++;
        //                    } else {
        //                        $count++;
        //                    }
        //                }
        //            }
        //        }
        //        print_simple_box("$count teachers were upgraded to course creators (with $errorcount errors)", "center", "50%", "$THEME->cellheading", "20", "noticebox");
    }
    if ($oldversion < 2003081501) {
        execute_sql(" CREATE TABLE `{$CFG->prefix}scale` (\n                         `id` int(10) unsigned NOT NULL auto_increment,\n                         `courseid` int(10) unsigned NOT NULL default '0',\n                         `userid` int(10) unsigned NOT NULL default '0',\n                         `name` varchar(255) NOT NULL default '',\n                         `scale` text NOT NULL,\n                         `description` text NOT NULL,\n                         `timemodified` int(10) unsigned NOT NULL default '0',\n                         PRIMARY KEY  (id)\n                       ) TYPE=MyISAM COMMENT='Defines grading scales'");
    }
    if ($oldversion < 2003081503) {
        table_column("forum", "", "scale", "integer", "10", "unsigned", "0", "", "assessed");
        get_scales_menu(0);
        // Just to force the default scale to be created
    }
    if ($oldversion < 2003081600) {
        table_column("user_teachers", "", "editall", "integer", "1", "unsigned", "1", "", "role");
        table_column("user_teachers", "", "timemodified", "integer", "10", "unsigned", "0", "", "editall");
    }
    if ($oldversion < 2003081900) {
        table_column("course_categories", "courseorder", "coursecount", "integer", "10", "unsigned", "0");
    }
    if ($oldversion < 2003082001) {
        table_column("course", "", "showgrades", "integer", "2", "unsigned", "1", "", "format");
    }
    if ($oldversion < 2003082101) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}course` ADD INDEX category (category) ");
    }
    if ($oldversion < 2003082702) {
        execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'user report', 'user', 'CONCAT(firstname,\" \",lastname)') ");
    }
    if ($oldversion < 2003091400) {
        table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score");
    }
    if ($oldversion < 2003092900) {
        table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
    }
    if ($oldversion < 2003102700) {
        table_column("user_students", "", "timeaccess", "integer", "10", "unsigned", "0", "", "time");
        table_column("user_teachers", "", "timeaccess", "integer", "10", "unsigned", "0", "", "timemodified");
        $db->debug = false;
        $CFG->debug = 0;
        notify("Calculating access times.  Please wait - this may take a long time on big sites...", "green");
        flush();
        if ($courses = get_records_select("course", "category > 0")) {
            foreach ($courses as $course) {
                notify("Processing " . format_string($course->fullname) . " ...", "green");
                flush();
                if ($users = get_records_select("user_teachers", "course = '{$course->id}'", "id", "id, userid, timeaccess")) {
                    foreach ($users as $user) {
                        $loginfo = get_record_sql("SELECT id, time FROM {$CFG->prefix}log                                                                                  WHERE course = '{$course->id}' and userid = '{$user->userid}'                                                               ORDER by time DESC");
                        if (empty($loginfo->time)) {
                            $loginfo->time = 0;
                        }
                        execute_sql("UPDATE {$CFG->prefix}user_teachers                                                                                      SET timeaccess = '{$loginfo->time}'\n                                     WHERE userid = '{$user->userid}' AND course = '{$course->id}'", false);
                    }
                }
                if ($users = get_records_select("user_students", "course = '{$course->id}'", "id", "id, userid, timeaccess")) {
                    foreach ($users as $user) {
                        $loginfo = get_record_sql("SELECT id, time FROM {$CFG->prefix}log\n                                                   WHERE course = '{$course->id}' and userid = '{$user->userid}'\n                                                   ORDER by time DESC");
                        if (empty($loginfo->time)) {
                            $loginfo->time = 0;
                        }
                        execute_sql("UPDATE {$CFG->prefix}user_students\n                                     SET timeaccess = '{$loginfo->time}'\n                                     WHERE userid = '{$user->userid}' AND course = '{$course->id}'", false);
                    }
                }
            }
        }
        notify("All courses complete.", "green");
        $db->debug = true;
    }
    if ($oldversion < 2003103100) {
        table_column("course", "", "showreports", "integer", "4", "unsigned", "0", "", "maxbytes");
    }
    if ($oldversion < 2003121600) {
        modify_database("", "CREATE TABLE `prefix_groups` (\n                                `id` int(10) unsigned NOT NULL auto_increment,\n                                `courseid` int(10) unsigned NOT NULL default '0',\n                                `name` varchar(254) NOT NULL default '',\n                                `description` text NOT NULL,\n                                `lang` varchar(10) NOT NULL default 'en',\n                                `picture` int(10) unsigned NOT NULL default '0',\n                                `timecreated` int(10) unsigned NOT NULL default '0',\n                                `timemodified` int(10) unsigned NOT NULL default '0',\n                                PRIMARY KEY  (`id`),\n                                KEY `courseid` (`courseid`)\n                              ) TYPE=MyISAM COMMENT='Each record is a group in a course.'; ");
        modify_database("", "CREATE TABLE `prefix_groups_members` (\n                                `id` int(10) unsigned NOT NULL auto_increment,\n                                `groupid` int(10) unsigned NOT NULL default '0',\n                                `userid` int(10) unsigned NOT NULL default '0',\n                                `timeadded` int(10) unsigned NOT NULL default '0',\n                                PRIMARY KEY  (`id`),\n                                KEY `groupid` (`groupid`)\n                              ) TYPE=MyISAM COMMENT='Lists memberships of users in groups'; ");
    }
    if ($oldversion < 2003121800) {
        table_column("course", "modinfo", "modinfo", "longtext", "", "", "");
    }
    if ($oldversion < 2003122600) {
        table_column("course", "", "groupmode", "integer", "4", "unsigned", "0", "", "showreports");
        table_column("course", "", "groupmodeforce", "integer", "4", "unsigned", "0", "", "groupmode");
    }
    if ($oldversion < 2004010900) {
        table_column("course_modules", "", "groupmode", "integer", "4", "unsigned", "0", "", "visible");
    }
    if ($oldversion < 2004011700) {
        modify_database("", "CREATE TABLE `prefix_event` (\n                              `id` int(10) unsigned NOT NULL auto_increment,\n                              `name` varchar(255) NOT NULL default '',\n                              `description` text NOT NULL,\n                              `courseid` int(10) unsigned NOT NULL default '0',\n                              `groupid` int(10) unsigned NOT NULL default '0',\n                              `userid` int(10) unsigned NOT NULL default '0',\n                              `modulename` varchar(20) NOT NULL default '',\n                              `instance` int(10) unsigned NOT NULL default '0',\n                              `eventtype` varchar(20) NOT NULL default '',\n                              `timestart` int(10) unsigned NOT NULL default '0',\n                              `timeduration` int(10) unsigned NOT NULL default '0',\n                              `timemodified` int(10) unsigned NOT NULL default '0',\n                              PRIMARY KEY  (`id`),\n                              UNIQUE KEY `id` (`id`),\n                              KEY `courseid` (`courseid`),\n                              KEY `userid` (`userid`)\n                            ) TYPE=MyISAM COMMENT='For everything with a time associated to it'; ");
    }
    if ($oldversion < 2004012800) {
        modify_database("", "CREATE TABLE `prefix_user_preferences` (\n                              `id` int(10) unsigned NOT NULL auto_increment,\n                              `userid` int(10) unsigned NOT NULL default '0',\n                              `name` varchar(50) NOT NULL default '',\n                              `value` varchar(255) NOT NULL default '',\n                              PRIMARY KEY  (`id`),\n                              UNIQUE KEY `id` (`id`),\n                              KEY `useridname` (userid,name)\n                            ) TYPE=MyISAM COMMENT='Allows modules to store arbitrary user preferences'; ");
    }
    if ($oldversion < 2004012900) {
        table_column("config", "value", "value", "text", "", "", "");
    }
    if ($oldversion < 2004013101) {
        table_column("log", "", "cmid", "integer", "10", "unsigned", "0", "", "module");
        set_config("upgrade", "logs");
    }
    if ($oldversion < 2004020900) {
        table_column("course", "", "lang", "varchar", "5", "", "", "", "groupmodeforce");
    }
    if ($oldversion < 2004020903) {
        modify_database("", "CREATE TABLE `prefix_cache_text` (\n                                `id` int(10) unsigned NOT NULL auto_increment,\n                                `md5key` varchar(32) NOT NULL default '',\n                                `formattedtext` longtext NOT NULL,\n                                `timemodified` int(10) unsigned NOT NULL default '0',\n                                PRIMARY KEY  (`id`),\n                                KEY `md5key` (`md5key`)\n                             ) TYPE=MyISAM COMMENT='For storing temporary copies of processed texts';");
    }
    if ($oldversion < 2004021000) {
        $textfilters = array();
        for ($i = 1; $i <= 10; $i++) {
            $variable = "textfilter{$i}";
            if (!empty($CFG->{$variable})) {
                /// No more filters
                if (is_readable("{$CFG->dirroot}/" . $CFG->{$variable})) {
                    $textfilters[] = $CFG->{$variable};
                }
            }
        }
        $textfilters = implode(',', $textfilters);
        if (empty($textfilters)) {
            $textfilters = 'mod/glossary/dynalink.php';
        }
        set_config('textfilters', $textfilters);
    }
    if ($oldversion < 2004021201) {
        modify_database("", "CREATE TABLE `prefix_cache_filters` (\n                                `id` int(10) unsigned NOT NULL auto_increment,\n                                `filter` varchar(32) NOT NULL default '',\n                                `version` int(10) unsigned NOT NULL default '0',\n                                `md5key` varchar(32) NOT NULL default '',\n                                `rawtext` text NOT NULL,\n                                `timemodified` int(10) unsigned NOT NULL default '0',\n                                PRIMARY KEY  (`id`),\n                                KEY `filtermd5key` (filter,md5key)\n                              ) TYPE=MyISAM COMMENT='For keeping information about cached data';");
    }
    if ($oldversion < 2004021500) {
        table_column("groups", "", "hidepicture", "integer", "2", "unsigned", "0", "", "picture");
    }
    if ($oldversion < 2004021700) {
        if (!empty($CFG->textfilters)) {
            $CFG->textfilters = str_replace("tex_filter.php", "filter.php", $CFG->textfilters);
            $CFG->textfilters = str_replace("multilang.php", "filter.php", $CFG->textfilters);
            $CFG->textfilters = str_replace("censor.php", "filter.php", $CFG->textfilters);
            $CFG->textfilters = str_replace("mediaplugin.php", "filter.php", $CFG->textfilters);
            $CFG->textfilters = str_replace("algebra_filter.php", "filter.php", $CFG->textfilters);
            $CFG->textfilters = str_replace("dynalink.php", "filter.php", $CFG->textfilters);
            set_config("textfilters", $CFG->textfilters);
        }
    }
    if ($oldversion < 2004022000) {
        table_column("user", "", "emailstop", "integer", "1", "unsigned", "0", "not null", "email");
    }
    if ($oldversion < 2004022200) {
        /// Final renaming I hope.  :-)
        if (!empty($CFG->textfilters)) {
            $CFG->textfilters = str_replace("/filter.php", "", $CFG->textfilters);
            $CFG->textfilters = str_replace("mod/glossary/dynalink.php", "mod/glossary", $CFG->textfilters);
            $textfilters = explode(',', $CFG->textfilters);
            foreach ($textfilters as $key => $textfilter) {
                $textfilters[$key] = trim($textfilter);
            }
            set_config("textfilters", implode(',', $textfilters));
        }
    }
    if ($oldversion < 2004030702) {
        /// Because of the renaming of Czech language pack
        execute_sql("UPDATE {$CFG->prefix}user SET lang = 'cs' WHERE lang = 'cz'");
        execute_sql("UPDATE {$CFG->prefix}course SET lang = 'cs' WHERE lang = 'cz'");
    }
    if ($oldversion < 2004041800) {
        /// Integrate Block System from contrib
        table_column("course", "", "blockinfo", "varchar", "255", "", "", "not null", "modinfo");
    }
    if ($oldversion < 2004042600) {
        /// Rebuild course caches for resource icons
        include_once "{$CFG->dirroot}/course/lib.php";
        rebuild_course_cache();
    }
    if ($oldversion < 2004042700) {
        /// Increase size of lang fields
        table_column("user", "lang", "lang", "varchar", "10", "", "en");
        table_column("groups", "lang", "lang", "varchar", "10", "", "");
        table_column("course", "lang", "lang", "varchar", "10", "", "");
    }
    if ($oldversion < 2004042701) {
        /// Add hiddentopics field to control hidden topics behaviour
        table_column("course", "", "hiddentopics", "integer", "1", "unsigned", "0", "not null", "visible");
    }
    if ($oldversion < 2004042702) {
        /// add a format field for the description
        table_column("event", "", "format", "integer", "4", "unsigned", "0", "not null", "description");
    }
    if ($oldversion < 2004042900) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}course` DROP `showrecent` ");
    }
    if ($oldversion < 2004043001) {
        /// Change hiddentopics to hiddensections
        table_column("course", "hiddentopics", "hiddensections", "integer", "2", "unsigned", "0", "not null");
    }
    if ($oldversion < 2004050400) {
        /// add a visible field for events
        table_column("event", "", "visible", "tinyint", "1", "", "1", "not null", "timeduration");
        if ($events = get_records('event')) {
            foreach ($events as $event) {
                if ($moduleid = get_field('modules', 'id', 'name', $event->modulename)) {
                    if (get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $event->instance) == 0) {
                        set_field('event', 'visible', 0, 'id', $event->id);
                    }
                }
            }
        }
    }
    if ($oldversion < 2004052800) {
        /// First version tagged "1.4 development", version.php 1.227
        set_config('siteblocksadded', true);
        /// This will be used later by the block upgrade
    }
    if ($oldversion < 2004053000) {
        /// set defaults for site course
        $site = get_site();
        set_field('course', 'numsections', 0, 'id', $site->id);
        set_field('course', 'groupmodeforce', 1, 'id', $site->id);
        set_field('course', 'teacher', get_string('administrator'), 'id', $site->id);
        set_field('course', 'teachers', get_string('administrators'), 'id', $site->id);
        set_field('course', 'student', get_string('user'), 'id', $site->id);
        set_field('course', 'students', get_string('users'), 'id', $site->id);
    }
    if ($oldversion < 2004060100) {
        set_config('digestmailtime', 0);
        table_column('user', "", 'maildigest', 'tinyint', '1', '', '0', 'not null', 'mailformat');
    }
    if ($oldversion < 2004062400) {
        table_column('user_teachers', "", 'timeend', 'int', '10', 'unsigned', '0', 'not null', 'editall');
        table_column('user_teachers', "", 'timestart', 'int', '10', 'unsigned', '0', 'not null', 'editall');
    }
    if ($oldversion < 2004062401) {
        table_column('course', '', 'idnumber', 'varchar', '100', '', '', 'not null', 'shortname');
        execute_sql('UPDATE ' . $CFG->prefix . 'course SET idnumber = shortname');
        // By default
    }
    if ($oldversion < 2004062600) {
        table_column('course', '', 'cost', 'varchar', '10', '', '', 'not null', 'lang');
    }
    if ($oldversion < 2004072900) {
        table_column('course', '', 'enrolperiod', 'int', '10', 'unsigned', '0', 'not null', 'startdate');
    }
    if ($oldversion < 2004072901) {
        // Fixing error in schema
        if ($record = get_record('log_display', 'module', 'course', 'action', 'update')) {
            delete_records('log_display', 'module', 'course', 'action', 'update');
            insert_record('log_display', $record, false);
        }
    }
    if ($oldversion < 2004081200) {
        // Fixing version errors in some blocks
        set_field('blocks', 'version', 2004081200, 'name', 'admin');
        set_field('blocks', 'version', 2004081200, 'name', 'calendar_month');
        set_field('blocks', 'version', 2004081200, 'name', 'course_list');
    }
    if ($oldversion < 2004081500) {
        // Adding new "auth" field to user table to allow more flexibility
        table_column('user', '', 'auth', 'varchar', '20', '', 'manual', 'not null', 'id');
        execute_sql("UPDATE {$CFG->prefix}user SET auth = 'manual'");
        // Set everyone to 'manual' to be sure
        if ($admins = get_admins()) {
            // Set all the NON-admins to whatever the current auth module is
            $adminlist = array();
            foreach ($admins as $user) {
                $adminlist[] = $user->id;
            }
            $adminlist = implode(',', $adminlist);
            execute_sql("UPDATE {$CFG->prefix}user SET auth = '{$CFG->auth}' WHERE id NOT IN ({$adminlist})");
        }
    }
    if ($oldversion < 2004082200) {
        // Making admins teachers on site course
        $site = get_site();
        $admins = get_admins();
        foreach ($admins as $admin) {
            add_teacher($admin->id, $site->id);
        }
    }
    if ($oldversion < 2004082600) {
        //update auth-fields for external users
        // following code would not work in 1.8
        /*        include_once ($CFG->dirroot."/auth/".$CFG->auth."/lib.php");
                if (function_exists('auth_get_userlist')) {
                    $externalusers = auth_get_userlist();
                    if (!empty($externalusers)){
                        $externalusers = '\''. implode('\',\'',$externalusers).'\'';
                        execute_sql("UPDATE {$CFG->prefix}user SET auth = '$CFG->auth' WHERE username  IN ($externalusers)");
                    }
                }*/
    }
    if ($oldversion < 2004082900) {
        // Make sure guest is "manual" too.
        set_field('user', 'auth', 'manual', 'username', 'guest');
    }
    /* Commented out unused guid-field code
       if ($oldversion < 2004090300) { // Add guid-field used in user syncronization
           table_column('user', '', 'guid', 'varchar', '128', '', '', '', 'auth');
           execute_sql("ALTER TABLE {$CFG->prefix}user ADD INDEX authguid (auth, guid)");
       }
       */
    if ($oldversion < 2004091900) {
        // modify idnumber to hold longer values
        table_column('user', 'idnumber', 'idnumber', 'varchar', '64', '', '', '', '');
        execute_sql("ALTER TABLE {$CFG->prefix}user DROP INDEX user_idnumber", false);
        // added in case of conflicts with upgrade from 14stable
        execute_sql("ALTER TABLE {$CFG->prefix}user DROP INDEX user_auth", false);
        // added in case of conflicts with upgrade from 14stable
        execute_sql("ALTER TABLE {$CFG->prefix}user ADD INDEX idnumber (idnumber)");
        execute_sql("ALTER TABLE {$CFG->prefix}user ADD INDEX auth (auth)");
    }
    if ($oldversion < 2004093001) {
        // add new table for sessions storage
        execute_sql(" CREATE TABLE `{$CFG->prefix}sessions` (\n                          `sesskey` char(32) NOT null,\n                          `expiry` int(11) unsigned NOT null,\n                          `expireref` varchar(64),\n                          `data` text NOT null,\n                          PRIMARY KEY (`sesskey`), \n                          KEY (`expiry`) \n                      ) TYPE=MyISAM COMMENT='Optional database session storage, not used by default';");
    }
    if ($oldversion < 2004111500) {
        // Update any users/courses using wrongly-named lang pack
        execute_sql("UPDATE {$CFG->prefix}user SET lang = 'mi_nt' WHERE lang = 'ma_nt'");
        execute_sql("UPDATE {$CFG->prefix}course SET lang = 'mi_nt' WHERE lang = 'ma_nt'");
    }
    if ($oldversion < 2004111700) {
        // add indexes. - drop them first silently to avoid conflicts when upgrading.
        execute_sql(" ALTER TABLE `{$CFG->prefix}course` DROP INDEX idnumber;", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}course` DROP INDEX shortname;", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}user_students` DROP INDEX userid;", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}user_teachers` DROP INDEX userid;", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}course` ADD INDEX idnumber (idnumber);");
        execute_sql(" ALTER TABLE `{$CFG->prefix}course` ADD INDEX shortname (shortname);");
        execute_sql(" ALTER TABLE `{$CFG->prefix}user_students` ADD INDEX userid (userid);");
        execute_sql(" ALTER TABLE `{$CFG->prefix}user_teachers` ADD INDEX userid (userid);");
    }
    if ($oldversion < 2004111700) {
        // add an index to event for timestart and timeduration. - drop them first silently to avoid conflicts when upgrading.
        execute_sql("ALTER TABLE {$CFG->prefix}event DROP INDEX timestart;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}event DROP INDEX timeduration;", false);
        modify_database('', 'ALTER TABLE prefix_event ADD INDEX timestart (timestart);');
        modify_database('', 'ALTER TABLE prefix_event ADD INDEX timeduration (timeduration);');
    }
    if ($oldversion < 2004111700) {
        //add indexes on modules and course_modules. - drop them first silently to avoid conflicts when upgrading.
        execute_sql("ALTER TABLE {$CFG->prefix}course_modules drop key visible;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}course_modules drop key course;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}course_modules drop key module;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}course_modules drop key instance;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}course_modules drop key deleted;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}modules drop key name;", false);
        modify_database('', 'ALTER TABLE prefix_course_modules add key visible(visible);');
        modify_database('', 'ALTER TABLE prefix_course_modules add key course(course);');
        modify_database('', 'ALTER TABLE prefix_course_modules add key module(module);');
        modify_database('', 'ALTER TABLE prefix_course_modules add key instance (instance);');
        modify_database('', 'ALTER TABLE prefix_course_modules add key deleted (deleted);');
        modify_database('', 'ALTER TABLE prefix_modules add key name(name);');
    }
    if ($oldversion < 2004111700) {
        // add an index on the groups_members table. - drop them first silently to avoid conflicts when upgrading.
        execute_sql("ALTER TABLE {$CFG->prefix}groups_members DROP INDEX userid;", false);
        modify_database('', 'ALTER TABLE prefix_groups_members ADD INDEX userid (userid);');
    }
    if ($oldversion < 2004111700) {
        // add an index on user students timeaccess (used for sorting)- drop them first silently to avoid conflicts when upgrading
        execute_sql("ALTER TABLE {$CFG->prefix}user_students DROP INDEX timeaccess;", false);
        modify_database('', 'ALTER TABLE prefix_user_students ADD INDEX timeaccess (timeaccess);');
    }
    if ($oldversion < 2004111700) {
        // add indexes on faux-foreign keys. - drop them first silently to avoid conflicts when upgrading.
        execute_sql("ALTER TABLE {$CFG->prefix}scale DROP INDEX courseid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}user_admins DROP INDEX userid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}user_coursecreators DROP INDEX userid;", false);
        modify_database('', 'ALTER TABLE prefix_scale ADD INDEX courseid (courseid);');
        modify_database('', 'ALTER TABLE prefix_user_admins ADD INDEX userid (userid);');
        modify_database('', 'ALTER TABLE prefix_user_coursecreators ADD INDEX userid (userid);');
    }
    if ($oldversion < 2004111700) {
        // replace index on course
        fix_course_sortorder(0, 0, 1);
        execute_sql("ALTER TABLE `{$CFG->prefix}course` DROP KEY category", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}course` DROP KEY category_sortorder;", false);
        modify_database('', "ALTER TABLE `prefix_course` ADD UNIQUE KEY category_sortorder(category,sortorder)");
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_deleted_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_confirmed_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_firstname_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_lastname_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_city_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_country_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_lastaccess_idx;", false);
        modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_deleted_idx  (deleted)");
        modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_confirmed_idx (confirmed)");
        modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_firstname_idx (firstname)");
        modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_lastname_idx (lastname)");
        modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_city_idx (city)");
        modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_country_idx (country)");
        modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_lastaccess_idx (lastaccess)");
    }
    if ($oldversion < 2004111700) {
        // one more index for email (for sorting)
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_email_idx;", false);
        modify_database('', 'ALTER TABLE `prefix_user` ADD INDEX prefix_user_email_idx (email);');
    }
    if ($oldversion < 2004112200) {
        // new 'enrol' field for enrolment tables
        table_column('user_students', '', 'enrol', 'varchar', '20', '', '', 'not null');
        table_column('user_teachers', '', 'enrol', 'varchar', '20', '', '', 'not null');
        execute_sql("ALTER TABLE `{$CFG->prefix}user_students` ADD INDEX enrol (enrol);");
        execute_sql("ALTER TABLE `{$CFG->prefix}user_teachers` ADD INDEX enrol (enrol);");
    }
    if ($oldversion < 2004112400) {
        /// Delete duplicate enrolments
        /// and then tell the database course,userid is a unique combination
        if ($users = get_records_select("user_students", "userid > 0 GROUP BY course, userid " . "HAVING count(*) > 1", "", "max(id) as id, userid, course ,count(*)")) {
            foreach ($users as $user) {
                delete_records_select("user_students", "userid = '{$user->userid}' " . "AND course = '{$user->course}' AND id <> '{$user->id}'");
            }
        }
        flush();
        modify_database('', 'ALTER TABLE prefix_user_students DROP INDEX courseuserid;');
        modify_database('', 'ALTER TABLE prefix_user_students ADD UNIQUE INDEX courseuserid(course,userid);');
        /// Delete duplicate teacher enrolments
        /// and then tell the database course,userid is a unique combination
        if ($users = get_records_select("user_teachers", "userid > 0 GROUP BY course, userid " . "HAVING count(*) > 1", "", "max(id) as id, userid, course ,count(*)")) {
            foreach ($users as $user) {
                delete_records_select("user_teachers", "userid = '{$user->userid}' " . "AND course = '{$user->course}' AND id <> '{$user->id}'");
            }
        }
        flush();
        modify_database('', 'ALTER TABLE prefix_user_teachers DROP INDEX courseuserid;');
        modify_database('', 'ALTER TABLE prefix_user_teachers ADD UNIQUE INDEX courseuserid(course,userid);');
    }
    if ($oldversion < 2004112900) {
        table_column('user', '', 'policyagreed', 'integer', '1', 'unsigned', '0', 'not null', 'confirmed');
    }
    if ($oldversion < 2004121400) {
        table_column('groups', '', 'password', 'varchar', '50', '', '', 'not null', 'description');
    }
    if ($oldversion < 2004121500) {
        modify_database('', "CREATE TABLE prefix_dst_preset (\n            id int(10) NOT NULL auto_increment,\n            name char(48) default '' NOT NULL,\n            \n            apply_offset tinyint(3) default '0' NOT NULL,\n            \n            activate_index tinyint(1) default '1' NOT NULL,\n            activate_day tinyint(1) default '1' NOT NULL,\n            activate_month tinyint(2) default '1' NOT NULL,\n            activate_time char(5) default '03:00' NOT NULL,\n            \n            deactivate_index tinyint(1) default '1' NOT NULL,\n            deactivate_day tinyint(1) default '1' NOT NULL,\n            deactivate_month tinyint(2) default '2' NOT NULL,\n            deactivate_time char(5) default '03:00' NOT NULL,\n            \n            last_change int(10) default '0' NOT NULL,\n            next_change int(10) default '0' NOT NULL,\n            current_offset tinyint(3) default '0' NOT NULL,\n            \n            PRIMARY KEY (id))");
    }
    if ($oldversion < 2004122800) {
        execute_sql("DROP TABLE {$CFG->prefix}message", false);
        execute_sql("DROP TABLE {$CFG->prefix}message_read", false);
        execute_sql("DROP TABLE {$CFG->prefix}message_contacts", false);
        modify_database('', "CREATE TABLE `prefix_message` (\n                               `id` int(10) unsigned NOT NULL auto_increment,\n                               `useridfrom` int(10) NOT NULL default '0',\n                               `useridto` int(10) NOT NULL default '0',\n                               `message` text NOT NULL,\n                               `timecreated` int(10) NOT NULL default '0',\n                               `messagetype` varchar(50) NOT NULL default '',\n                               PRIMARY KEY  (`id`),\n                               KEY `useridfrom` (`useridfrom`),\n                               KEY `useridto` (`useridto`)\n                             ) TYPE=MyISAM COMMENT='Stores all unread messages';");
        modify_database('', "CREATE TABLE `prefix_message_read` (\n                               `id` int(10) unsigned NOT NULL auto_increment,\n                               `useridfrom` int(10) NOT NULL default '0',\n                               `useridto` int(10) NOT NULL default '0',\n                               `message` text NOT NULL,\n                               `timecreated` int(10) NOT NULL default '0',\n                               `timeread` int(10) NOT NULL default '0',\n                               `messagetype` varchar(50) NOT NULL default '',\n                               `mailed` tinyint(1) NOT NULL default '0',\n                               PRIMARY KEY  (`id`),\n                               KEY `useridfrom` (`useridfrom`),\n                               KEY `useridto` (`useridto`)\n                             ) TYPE=MyISAM COMMENT='Stores all messages that have been read';");
        modify_database('', "CREATE TABLE `prefix_message_contacts` (\n                               `id` int(10) unsigned NOT NULL auto_increment,\n                               `userid` int(10) unsigned NOT NULL default '0',\n                               `contactid` int(10) unsigned NOT NULL default '0',\n                               `blocked` tinyint(1) unsigned NOT NULL default '0',\n                               PRIMARY KEY  (`id`),\n                               UNIQUE KEY `usercontact` (`userid`,`contactid`)\n                             ) TYPE=MyISAM COMMENT='Maintains lists of relationships between users';");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'write', 'user', 'CONCAT(firstname,\" \",lastname)'); ");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'read', 'user', 'CONCAT(firstname,\" \",lastname)'); ");
    }
    if ($oldversion < 2004122801) {
        table_column('message', '', 'format', 'integer', '4', 'unsigned', '0', 'not null', 'message');
        table_column('message_read', '', 'format', 'integer', '4', 'unsigned', '0', 'not null', 'message');
    }
    if ($oldversion < 2005010100) {
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'add contact', 'user', 'CONCAT(firstname,\" \",lastname)'); ");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'remove contact', 'user', 'CONCAT(firstname,\" \",lastname)'); ");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'block contact', 'user', 'CONCAT(firstname,\" \",lastname)'); ");
        modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('message', 'unblock contact', 'user', 'CONCAT(firstname,\" \",lastname)'); ");
    }
    if ($oldversion < 2005011000) {
        // Create a .htaccess file in dataroot, just in case
        if (!file_exists($CFG->dataroot . '/.htaccess')) {
            if ($handle = fopen($CFG->dataroot . '/.htaccess', 'w')) {
                // For safety
                @fwrite($handle, "deny from all\r\nAllowOverride None\r\n");
                @fclose($handle);
                notify("Created a default .htaccess file in {$CFG->dataroot}");
            }
        }
    }
    if ($oldversion < 2005012500) {
        /*
        // add new table for meta courses.
        modify_database("","CREATE TABLE `prefix_meta_course` (
            `id` int(1) unsigned NOT NULL auto_increment,
            `parent_course` int(10) NOT NULL default 0,
            `child_course` int(10) NOT NULL default 0,
            PRIMARY KEY (`id`),
            KEY `parent_course` (parent_course),
            KEY `child_course` (child_course)
        );");
        // add flag to course field
        table_column('course','','meta_course','integer','1','','0','not null');
        */
        // taking this OUT for upgrade from 1.4 to 1.5 (those tracking head will have already seen it)
    }
    if ($oldversion < 2005012501) {
        execute_sql("DROP TABLE {$CFG->prefix}meta_course", false);
        // drop silently
        execute_sql("ALTER TABLE {$CFG->prefix}course DROP COLUMN meta_course", false);
        // drop silently
        // add new table for meta courses.
        modify_database("", "CREATE TABLE `prefix_course_meta` (\n            `id` int(10) unsigned NOT NULL auto_increment,\n            `parent_course` int(10) NOT NULL default 0,\n            `child_course` int(10) NOT NULL default 0,\n            PRIMARY KEY (`id`),\n            KEY `parent_course` (parent_course),\n            KEY `child_course` (child_course)\n        );");
        // add flag to course field
        table_column('course', '', 'metacourse', 'integer', '1', '', '0', 'not null');
    }
    if ($oldversion < 2005012800) {
        // fix a typo (int 1 becomes int 10)
        table_column('course_meta', 'id', 'id', 'integer', '10', '', '0', 'not null');
    }
    if ($oldversion < 2005020100) {
        fix_course_sortorder(0, 1, 1);
    }
    if ($oldversion < 2005020101) {
        // hopefully this is the LAST TIME we need to do this ;)
        if ($rows = count_records("course_meta")) {
            // we need to upgrade
            modify_database("", "CREATE TABLE `prefix_course_meta_tmp` (\n            `parent_course` int(10) NOT NULL default 0,\n            `child_course` int(10) NOT NULL default 0);");
            execute_sql("INSERT INTO {$CFG->prefix}course_meta_tmp (parent_course,child_course) \n               SELECT {$CFG->prefix}course_meta.parent_course, {$CFG->prefix}course_meta.child_course\n               FROM {$CFG->prefix}course_meta");
            $insertafter = true;
        }
        execute_sql("DROP TABLE {$CFG->prefix}course_meta");
        modify_database("", "CREATE TABLE `prefix_course_meta` (\n            `id` int(10) unsigned NOT NULL auto_increment,\n            `parent_course` int(10) unsigned NOT NULL default 0,\n            `child_course` int(10) unsigned NOT NULL default 0,\n            PRIMARY KEY (`id`),\n            KEY `parent_course` (parent_course),\n            KEY `child_course` (child_course));");
        if (!empty($insertafter)) {
            execute_sql("INSERT INTO {$CFG->prefix}course_meta (parent_course,child_course) \n               SELECT {$CFG->prefix}course_meta_tmp.parent_course, {$CFG->prefix}course_meta_tmp.child_course\n               FROM {$CFG->prefix}course_meta_tmp");
            execute_sql("DROP TABLE {$CFG->prefix}course_meta_tmp");
        }
    }
    if ($oldversion < 2005020800) {
        // Expand module column to max 20 chars
        table_column('log', 'module', 'module', 'varchar', '20', '', '', 'not null');
    }
    if ($oldversion < 2005021000) {
        // New fields for theme choices
        table_column('course', '', 'theme', 'varchar', '50', '', '', '', 'lang');
        table_column('groups', '', 'theme', 'varchar', '50', '', '', '', 'lang');
        table_column('user', '', 'theme', 'varchar', '50', '', '', '', 'lang');
        set_config('theme', 'standardwhite');
        // Reset to a known good theme
    }
    if ($oldversion < 2005021600) {
        // course.idnumber should be varchar(100)
        table_column('course', 'idnumber', 'idnumber', 'varchar', '100', '', '', '', '');
    }
    if ($oldversion < 2005021700) {
        table_column('user', '', 'dstpreset', 'int', '10', '', '0', 'not null', 'timezone');
    }
    if ($oldversion < 2005021800) {
        // For database debugging, not for normal use
        modify_database("", " CREATE TABLE `adodb_logsql` (\n                               `created` datetime NOT NULL,\n                               `sql0` varchar(250) NOT NULL,\n                               `sql1` text NOT NULL,\n                               `params` text NOT NULL,\n                               `tracer` text NOT NULL,\n                               `timer` decimal(16,6) NOT NULL\n                              );");
    }
    if ($oldversion < 2005022400) {
        // Add more visible digits to the fields
        table_column('dst_preset', 'activate_index', 'activate_index', 'tinyint', '2', '', '0', 'not null');
        table_column('dst_preset', 'activate_day', 'activate_day', 'tinyint', '2', '', '0', 'not null');
        // Add family and year fields
        table_column('dst_preset', '', 'family', 'varchar', '100', '', '', 'not null', 'name');
        table_column('dst_preset', '', 'year', 'int', '10', '', '0', 'not null', 'family');
    }
    if ($oldversion < 2005030501) {
        table_column('user', '', 'msn', 'varchar', '50', '', '', '', 'icq');
        table_column('user', '', 'aim', 'varchar', '50', '', '', '', 'icq');
        table_column('user', '', 'yahoo', 'varchar', '50', '', '', '', 'icq');
        table_column('user', '', 'skype', 'varchar', '50', '', '', '', 'icq');
    }
    if ($oldversion < 2005032300) {
        table_column('user', 'dstpreset', 'timezonename', 'varchar', '100');
        execute_sql('UPDATE `' . $CFG->prefix . 'user` SET timezonename = \'\'');
    }
    if ($oldversion < 2005032600) {
        execute_sql('DROP TABLE ' . $CFG->prefix . 'dst_preset', false);
        modify_database('', "CREATE TABLE `prefix_timezone` (\n                              `id` int(10) NOT NULL auto_increment,\n                              `name` varchar(100) NOT NULL default '',\n                              `year` int(11) NOT NULL default '0',\n                              `rule` varchar(20) NOT NULL default '',\n                              `gmtoff` int(11) NOT NULL default '0',\n                              `dstoff` int(11) NOT NULL default '0',\n                              `dst_month` tinyint(2) NOT NULL default '0',\n                              `dst_startday` tinyint(3) NOT NULL default '0',\n                              `dst_weekday` tinyint(3) NOT NULL default '0',\n                              `dst_skipweeks` tinyint(3) NOT NULL default '0',\n                              `dst_time` varchar(5) NOT NULL default '00:00',\n                              `std_month` tinyint(2) NOT NULL default '0',\n                              `std_startday` tinyint(3) NOT NULL default '0',\n                              `std_weekday` tinyint(3) NOT NULL default '0',\n                              `std_skipweeks` tinyint(3) NOT NULL default '0',\n                              `std_time` varchar(5) NOT NULL default '00:00',\n                              PRIMARY KEY (`id`)\n                            ) TYPE=MyISAM COMMENT='Rules for calculating local wall clock time for users';");
    }
    if ($oldversion < 2005032800) {
        execute_sql("CREATE TABLE `{$CFG->prefix}grade_category` (\n            `id` int(10) unsigned NOT NULL auto_increment,\n            `name` varchar(64) NOT NULL default '',\n            `courseid` int(10) unsigned NOT NULL default '0',\n            `drop_x_lowest` int(10) unsigned NOT NULL default '0',\n            `bonus_points` int(10) unsigned NOT NULL default '0',\n            `hidden` int(10) unsigned NOT NULL default '0',\n            `weight` decimal(4,2) NOT NULL default '0.00',\n            PRIMARY KEY  (`id`),\n            KEY `courseid` (`courseid`)\n          ) TYPE=MyISAM ;");
        execute_sql("CREATE TABLE `{$CFG->prefix}grade_exceptions` (\n            `id` int(10) unsigned NOT NULL auto_increment,\n            `courseid` int(10) unsigned NOT NULL default '0',\n            `grade_itemid` int(10) unsigned NOT NULL default '0',\n            `userid` int(10) unsigned NOT NULL default '0',\n            PRIMARY KEY  (`id`),\n            KEY `courseid` (`courseid`)\n          ) TYPE=MyISAM ;");
        execute_sql("CREATE TABLE `{$CFG->prefix}grade_item` (\n            `id` int(10) unsigned NOT NULL auto_increment,\n            `courseid` int(10) unsigned NOT NULL default '0',\n            `category` int(10) unsigned NOT NULL default '0',\n            `modid` int(10) unsigned NOT NULL default '0',\n            `cminstance` int(10) unsigned NOT NULL default '0',\n            `scale_grade` float(11,10) default '1.0000000000',\n            `extra_credit` int(10) unsigned NOT NULL default '0',\n            `sort_order` int(10) unsigned NOT NULL default '0',\n            PRIMARY KEY  (`id`),\n            KEY `courseid` (`courseid`)\n          ) TYPE=MyISAM ;");
        execute_sql("CREATE TABLE `{$CFG->prefix}grade_letter` (\n            `id` int(10) unsigned NOT NULL auto_increment,\n            `courseid` int(10) unsigned NOT NULL default '0',\n            `letter` varchar(8) NOT NULL default 'NA',\n            `grade_high` decimal(4,2) NOT NULL default '100.00',\n            `grade_low` decimal(4,2) NOT NULL default '0.00',\n            PRIMARY KEY  (`id`),\n            KEY `courseid` (`courseid`)\n          ) TYPE=MyISAM ;");
        execute_sql("CREATE TABLE `{$CFG->prefix}grade_preferences` (\n            `id` int(10) unsigned NOT NULL auto_increment,\n            `courseid` int(10) unsigned NOT NULL default '0',\n            `preference` int(10) NOT NULL default '0',\n            `value` int(10) NOT NULL default '0',\n            PRIMARY KEY  (`id`),\n            UNIQUE KEY `courseidpreference` (`courseid`,`preference`)\n          ) TYPE=MyISAM ;");
    }
    if ($oldversion < 2005033100) {
        // Get rid of defunct field from course modules table
        delete_records('course_modules', 'deleted', 1);
        // Delete old records we don't need any more
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'course_modules` DROP INDEX `deleted`');
        // Old index
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'course_modules` DROP `deleted`');
        // Old field
    }
    if ($oldversion < 2005040800) {
        table_column('user', 'timezone', 'timezone', 'varchar', '100', '', '99');
        execute_sql(" ALTER TABLE `{$CFG->prefix}user` DROP `timezonename` ");
    }
    if ($oldversion < 2005041101) {
        require_once $CFG->libdir . '/filelib.php';
        if (is_readable($CFG->dirroot . '/lib/timezones.txt')) {
            // Distribution file
            if ($timezones = get_records_csv($CFG->dirroot . '/lib/timezones.txt', 'timezone')) {
                $db->debug = false;
                update_timezone_records($timezones);
                notify(count($timezones) . ' timezones installed');
                $db->debug = true;
            }
        }
    }
    if ($oldversion < 2005041900) {
        // Copy all Dialogue entries into Messages, and hide Dialogue module
        if ($entries = get_records_sql('SELECT e.id, e.userid, c.recipientid, e.text, e.timecreated
                                          FROM ' . $CFG->prefix . 'dialogue_conversations c,
                                               ' . $CFG->prefix . 'dialogue_entries e
                                         WHERE e.conversationid = c.id')) {
            foreach ($entries as $entry) {
                $message = new object();
                $message->useridfrom = $entry->userid;
                $message->useridto = $entry->recipientid;
                $message->message = addslashes($entry->text);
                $message->format = FORMAT_HTML;
                $message->timecreated = $entry->timecreated;
                $message->messagetype = 'direct';
                insert_record('message_read', $message);
            }
        }
        set_field('modules', 'visible', 0, 'name', 'dialogue');
        notify('The Dialogue module has been disabled, and all the old Messages from it copied into the new standard Message feature.  If you really want Dialogue back, you can enable it using the "eye" icon here:  Admin >> Modules >> Dialogue');
    }
    if ($oldversion < 2005042100) {
        $result = table_column('event', '', 'repeatid', 'int', '10', 'unsigned', '0', 'not null', 'userid') && $result;
    }
    if ($oldversion < 2005042400) {
        // Add user tracking prefs field.
        table_column('user', '', 'trackforums', 'int', '4', 'unsigned', '0', 'not null', 'autosubscribe');
    }
    if ($oldversion < 2005053000) {
        // Add config_plugins table
        // this table was created on the MOODLE_15_STABLE branch
        // so it may already exist.
        $result = execute_sql("CREATE TABLE IF NOT EXISTS `{$CFG->prefix}config_plugins` (\n                                  `id`         int(10) unsigned NOT NULL auto_increment,\n                                  `plugin`     varchar(100) NOT NULL default 'core',\n                                  `name`       varchar(100) NOT NULL default '',\n                                  `value`      text NOT NULL default '',\n                                  PRIMARY KEY  (`id`),\n                                           UNIQUE KEY `plugin_name` (`plugin`, `name`)\n                                  ) TYPE=MyISAM \n                                  COMMENT='Moodle modules and plugins configuration variables';");
    }
    if ($oldversion < 2005060200) {
        // migrate some config items to config_plugins table
        // NOTE: this block is in both postgres AND mysql upgrade
        // files. If you edit either, update the otherone.
        $user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");
        if (!empty($CFG->auth)) {
            // if we have no auth, just pass
            foreach ($user_fields as $field) {
                $suffixes = array('', '_editlock', '_updateremote', '_updatelocal');
                foreach ($suffixes as $suffix) {
                    $key = 'auth_user_' . $field . $suffix;
                    if (isset($CFG->{$key})) {
                        // translate keys & values
                        // to the new convention
                        // this should support upgrading
                        // even 1.5dev installs
                        $newkey = $key;
                        $newval = $CFG->{$key};
                        if ($suffix === '') {
                            $newkey = 'field_map_' . $field;
                        } elseif ($suffix === '_editlock') {
                            $newkey = 'field_lock_' . $field;
                            $newval = $newval == 1 ? 'locked' : 'unlocked';
                            // translate 0/1 to locked/unlocked
                        } elseif ($suffix === '_updateremote') {
                            $newkey = 'field_updateremote_' . $field;
                        } elseif ($suffix === '_updatelocal') {
                            $newkey = 'field_updatelocal_' . $field;
                            $newval = $newval == 1 ? 'onlogin' : 'oncreate';
                            // translate 0/1 to locked/unlocked
                        }
                        if (!(set_config($newkey, addslashes($newval), 'auth/' . $CFG->auth) && delete_records('config', 'name', $key))) {
                            notify("Error updating Auth configuration {$key} to {$CFG->auth} {$newkey} .");
                            $result = false;
                        }
                    }
                    // end if isset key
                }
                // end foreach suffix
            }
            // end foreach field
        }
    }
    if ($oldversion < 2005060201) {
        // Close down the Attendance module, we are removing it from CVS.
        if (!file_exists($CFG->dirroot . '/mod/attendance/lib.php')) {
            if (count_records('attendance')) {
                // We have some data, so should keep it
                set_field('modules', 'visible', 0, 'name', 'attendance');
                notify('The Attendance module has been discontinued.  If you really want to 
                        continue using it, you should download it individually from 
                        http://download.moodle.org/modules and install it, then 
                        reactivate it from Admin >> Configuration >> Modules.  
                        None of your existing data has been deleted, so all existing 
                        Attendance activities should re-appear.');
            } else {
                // No data, so do a complete delete
                execute_sql('DROP TABLE ' . $CFG->prefix . 'attendance', false);
                delete_records('modules', 'name', 'attendance');
                notify("The Attendance module has been discontinued and removed from your site.  \n                        You weren't using it anyway.  ;-)");
            }
        }
    }
    if ($oldversion < 2005071700) {
        // Close down the Dialogue module, we are removing it from CVS.
        if (!file_exists($CFG->dirroot . '/mod/dialogue/lib.php')) {
            if (count_records('dialogue')) {
                // We have some data, so should keep it
                set_field('modules', 'visible', 0, 'name', 'dialogue');
                notify('The Dialogue module has been discontinued.  If you really want to 
                        continue using it, you should download it individually from 
                        http://download.moodle.org/modules and install it, then 
                        reactivate it from Admin >> Configuration >> Modules.  
                        None of your existing data has been deleted, so all existing 
                        Dialogue activities should re-appear.');
            } else {
                // No data, so do a complete delete
                execute_sql('DROP TABLE ' . $CFG->prefix . 'dialogue', false);
                delete_records('modules', 'name', 'dialogue');
                notify("The Dialogue module has been discontinued and removed from your site.  \n                        You weren't using it anyway.  ;-)");
            }
        }
    }
    if ($oldversion < 2005072000) {
        // Add a couple fields to mdl_event to work towards iCal import/export
        table_column('event', '', 'uuid', 'char', '36', '', '', 'not null', 'visible');
        table_column('event', '', 'sequence', 'integer', '10', 'unsigned', '1', 'not null', 'uuid');
    }
    if ($oldversion < 2005072100) {
        // run the online assignment cleanup code
        include $CFG->dirroot . '/' . $CFG->admin . '/oacleanup.php';
        if (function_exists('online_assignment_cleanup')) {
            online_assignment_cleanup();
        }
    }
    if ($oldversion < 2005072200) {
        // fix the mistakenly-added currency stuff from enrol/authorize
        execute_sql("DROP TABLE {$CFG->prefix}currencies", false);
        // drop silently
        execute_sql("ALTER TABLE {$CFG->prefix}course DROP currency", false);
        $defaultcurrency = empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency;
        table_column('course', '', 'currency', 'char', '3', '', $defaultcurrency, 'not null', 'cost');
    }
    if ($oldversion < 2005081600) {
        //set up the course requests table
        modify_database('', "CREATE TABLE `prefix_course_request`  (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `fullname` varchar(254) NOT NULL default '',\n          `shortname` varchar(15) NOT NULL default '',\n          `summary` text NOT NULL,\n          `reason` text NOT NULL,\n          `requester` int(10) NOT NULL default 0,\n          PRIMARY KEY (`id`),\n          KEY `shortname` (`shortname`)\n        ) TYPE=MyISAM;");
        table_column('course', '', 'requested');
    }
    if ($oldversion < 2005081601) {
        modify_database('', "CREATE TABLE `prefix_course_allowed_modules` (\n         `id` int(10) unsigned NOT NULL auto_increment,\n         `course` int(10) unsigned NOT NULL default 0,\n         `module` int(10) unsigned NOT NULL default 0,\n         PRIMARY KEY (`id`),\n         KEY `course` (`course`),\n         KEY `module` (`module`)\n      ) TYPE=MyISAM;");
        table_column('course', '', 'restrictmodules', 'int', '1', '', '0', 'not null');
    }
    if ($oldversion < 2005081700) {
        table_column('course_categories', '', 'depth', 'integer');
        table_column('course_categories', '', 'path', 'varchar', '255');
    }
    if ($oldversion < 2005090100) {
        modify_database("", "CREATE TABLE `prefix_stats_daily` (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `courseid` int(10) unsigned NOT NULL default 0,\n          `timeend` int(10) unsigned NOT NULL default 0,\n          `students` int(10) unsigned NOT NULL default 0,\n          `teachers` int(10) unsigned NOT NULL default 0,\n          `activestudents` int(10) unsigned NOT NULL default 0,\n          `activeteachers` int(10) unsigned NOT NULL default 0,\n          `studentreads` int(10) unsigned NOT NULL default 0,\n          `studentwrites` int(10) unsigned NOT NULL default 0,\n          `teacherreads` int(10) unsigned NOT NULL default 0,\n          `teacherwrites` int(10) unsigned NOT NULL default 0,\n          `logins` int(10) unsigned NOT NULL default 0,\n          `uniquelogins` int(10) unsigned NOT NULL default 0,\n          PRIMARY KEY (`id`),\n          KEY `courseid` (`courseid`),\n          KEY `timeend` (`timeend`)\n       );");
        modify_database("", "CREATE TABLE prefix_stats_weekly (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `courseid` int(10) unsigned NOT NULL default 0,\n          `timeend` int(10) unsigned NOT NULL default 0,\n          `students` int(10) unsigned NOT NULL default 0,\n          `teachers` int(10) unsigned NOT NULL default 0,\n          `activestudents` int(10) unsigned NOT NULL default 0,\n          `activeteachers` int(10) unsigned NOT NULL default 0,\n          `studentreads` int(10) unsigned NOT NULL default 0,\n          `studentwrites` int(10) unsigned NOT NULL default 0,\n          `teacherreads` int(10) unsigned NOT NULL default 0,\n          `teacherwrites` int(10) unsigned NOT NULL default 0,\n          `logins` int(10) unsigned NOT NULL default 0,\n          `uniquelogins` int(10) unsigned NOT NULL default 0,\n          PRIMARY KEY (`id`),\n          KEY `courseid` (`courseid`),\n          KEY `timeend` (`timeend`)\n       );");
        modify_database("", "CREATE TABLE prefix_stats_monthly (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `courseid` int(10) unsigned NOT NULL default 0,\n          `timeend` int(10) unsigned NOT NULL default 0,\n          `students` int(10) unsigned NOT NULL default 0,\n          `teachers` int(10) unsigned NOT NULL default 0,\n          `activestudents` int(10) unsigned NOT NULL default 0,\n          `activeteachers` int(10) unsigned NOT NULL default 0,\n          `studentreads` int(10) unsigned NOT NULL default 0,\n          `studentwrites` int(10) unsigned NOT NULL default 0,\n          `teacherreads` int(10) unsigned NOT NULL default 0,\n          `teacherwrites` int(10) unsigned NOT NULL default 0,\n          `logins` int(10) unsigned NOT NULL default 0,\n          `uniquelogins` int(10) unsigned NOT NULL default 0,\n          PRIMARY KEY (`id`),\n          KEY `courseid` (`courseid`),\n          KEY `timeend` (`timeend`)\n       );");
        modify_database("", "CREATE TABLE prefix_stats_user_daily (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `courseid` int(10) unsigned NOT NULL default 0,\n          `userid` int(10) unsigned NOT NULL default 0,\n          `roleid` int(10) unsigned NOT NULL default 0,\n          `timeend` int(10) unsigned NOT NULL default 0,\n          `statsreads` int(10) unsigned NOT NULL default 0,\n          `statswrites` int(10) unsigned NOT NULL default 0,\n          `stattype` varchar(30) NOT NULL default '',\n          PRIMARY KEY (`id`),\n          KEY `courseid` (`courseid`),\n          KEY `userid` (`userid`),\n          KEY `roleid` (`roleid`),\n          KEY `timeend` (`timeend`)\n       );");
        modify_database("", "CREATE TABLE prefix_stats_user_weekly (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `courseid` int(10) unsigned NOT NULL default 0,\n          `userid` int(10) unsigned NOT NULL default 0,\n          `roleid` int(10) unsigned NOT NULL default 0,\n          `timeend` int(10) unsigned NOT NULL default 0,\n          `statsreads` int(10) unsigned NOT NULL default 0,\n          `statswrites` int(10) unsigned NOT NULL default 0,\n          `stattype` varchar(30) NOT NULL default '',\n          PRIMARY KEY (`id`),\n          KEY `courseid` (`courseid`),\n          KEY `userid` (`userid`),\n          KEY `roleid` (`roleid`),\n          KEY `timeend` (`timeend`)\n       );");
        modify_database("", "CREATE TABLE prefix_stats_user_monthly (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `courseid` int(10) unsigned NOT NULL default 0,\n          `userid` int(10) unsigned NOT NULL default 0,\n          `roleid` int(10) unsigned NOT NULL default 0,\n          `timeend` int(10) unsigned NOT NULL default 0,\n          `statsreads` int(10) unsigned NOT NULL default 0,\n          `statswrites` int(10) unsigned NOT NULL default 0,\n          `stattype` varchar(30) NOT NULL default '',\n          PRIMARY KEY (`id`),\n          KEY `courseid` (`courseid`),\n          KEY `userid` (`userid`),\n          KEY `roleid` (`roleid`),\n          KEY `timeend` (`timeend`)\n       );");
    }
    if ($oldversion < 2005100300) {
        table_column('course', '', 'expirynotify', 'tinyint', '1');
        table_column('course', '', 'expirythreshold', 'int', '10');
        table_column('course', '', 'notifystudents', 'tinyint', '1');
        $new = new stdClass();
        $new->name = 'lastexpirynotify';
        $new->value = 0;
        insert_record('config', $new);
    }
    if ($oldversion < 2005100400) {
        table_column('course', '', 'enrollable', 'tinyint', '1', 'unsigned', '1');
        table_column('course', '', 'enrolstartdate', 'int');
        table_column('course', '', 'enrolenddate', 'int');
    }
    if ($oldversion < 2005101200) {
        // add enrolment key to course_request.
        table_column('course_request', '', 'password', 'varchar', 50);
    }
    if ($oldversion < 2006030800) {
        # add extra indexes to log (see bug #4112)
        modify_database('', "ALTER TABLE prefix_log ADD INDEX userid (userid);");
        modify_database('', "ALTER TABLE prefix_log ADD INDEX info (info);");
    }
    if ($oldversion < 2006030900) {
        table_column('course', '', 'enrol', 'varchar', '20', '', '');
        if ($CFG->enrol == 'internal' || $CFG->enrol == 'manual') {
            set_config('enrol_plugins_enabled', 'manual');
            set_config('enrol', 'manual');
        } else {
            set_config('enrol_plugins_enabled', 'manual,' . $CFG->enrol);
        }
        require_once "{$CFG->dirroot}/enrol/enrol.class.php";
        $defaultenrol = enrolment_factory::factory($CFG->enrol);
        if (!method_exists($defaultenrol, 'print_entry')) {
            // switch enrollable to off for all courses in this case
            modify_database('', 'UPDATE prefix_course SET enrollable = 0');
        }
        execute_sql("UPDATE {$CFG->prefix}user_students SET enrol='manual' WHERE enrol='' OR enrol='internal'");
        execute_sql("UPDATE {$CFG->prefix}user_teachers SET enrol='manual' WHERE enrol=''");
    }
    if ($oldversion < 2006031000) {
        modify_database("", "CREATE TABLE prefix_post (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `userid` int(10) unsigned NOT NULL default '0',\n          `courseid` int(10) unsigned NOT NULL default'0',\n          `groupid` int(10) unsigned NOT NULL default'0',\n          `moduleid` int(10) unsigned NOT NULL default'0',\n          `coursemoduleid` int(10) unsigned NOT NULL default'0',\n          `subject` varchar(128) NOT NULL default '',\n          `summary` longtext,\n          `content` longtext,\n          `uniquehash` varchar(128) NOT NULL default '',\n          `rating` int(10) unsigned NOT NULL default'0',\n          `format` int(10) unsigned NOT NULL default'0',\n          `publishstate` enum('draft','site','public') NOT NULL default 'draft',\n          `lastmodified` int(10) unsigned NOT NULL default '0',\n          `created` int(10) unsigned NOT NULL default '0',\n          PRIMARY KEY  (`id`),\n          UNIQUE KEY `id_user_idx` (`id`, `userid`),\n          KEY `post_lastmodified_idx` (`lastmodified`),\n          KEY `post_subject_idx` (`subject`)\n        ) TYPE=MyISAM  COMMENT='New moodle post table. Holds data posts such as forum entries or blog entries.';");
        modify_database("", "CREATE TABLE prefix_tags (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `type` varchar(255) NOT NULL default 'official',\n          `userid` int(10) unsigned NOT NULL default'0',\n          `text` varchar(255) NOT NULL default '',\n          PRIMARY KEY  (`id`)\n        ) TYPE=MyISAM COMMENT ='tags structure for moodle.';");
        modify_database("", "CREATE TABLE prefix_blog_tag_instance (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `entryid` int(10) unsigned NOT NULL default'0',\n          `tagid` int(10) unsigned NOT NULL default'0',\n          `groupid` int(10) unsigned NOT NULL default'0',\n          `courseid` int(10) unsigned NOT NULL default'0',\n          `userid` int(10) unsigned NOT NULL default'0',\n          PRIMARY KEY  (`id`)\n          ) TYPE=MyISAM COMMENT ='tag instance for blogs.';");
    }
    if ($oldversion < 2006031400) {
        require_once "{$CFG->dirroot}/enrol/enrol.class.php";
        $defaultenrol = enrolment_factory::factory($CFG->enrol);
        if (!method_exists($defaultenrol, 'print_entry')) {
            set_config('enrol', 'manual');
        }
    }
    if ($oldversion < 2006031600) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}grade_category` CHANGE `weight` `weight` decimal(5,2) default '0.00';");
    }
    if ($oldversion < 2006032000) {
        table_column('post', '', 'module', 'varchar', '20', '', '', 'not null', 'id');
        modify_database('', "ALTER TABLE prefix_post ADD INDEX post_module_idx (module);");
        modify_database('', "UPDATE prefix_post SET module = 'blog';");
    }
    if ($oldversion < 2006032001) {
        table_column('blog_tag_instance', '', 'timemodified', 'integer', '10', 'unsigned', '0', 'not null', 'userid');
        modify_database('', "ALTER TABLE prefix_blog_tag_instance ADD INDEX bti_entryid_idx (entryid);");
        modify_database('', "ALTER TABLE prefix_blog_tag_instance ADD INDEX bti_tagid_idx (tagid);");
        modify_database('', "UPDATE prefix_blog_tag_instance SET timemodified = '" . time() . "';");
    }
    if ($oldversion < 2006040500) {
        // Add an index to course_sections that was never upgraded (bug 5100)
        execute_sql(" CREATE INDEX coursesection ON {$CFG->prefix}course_sections (course,section) ", false);
    }
    /// change all the int(11) to int(10) for blogs and tags
    if ($oldversion < 2006041000) {
        table_column('post', 'id', 'id', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('post', 'userid', 'userid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('post', 'courseid', 'courseid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('post', 'groupid', 'groupid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('post', 'moduleid', 'moduleid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('post', 'coursemoduleid', 'coursemoduleid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('post', 'rating', 'rating', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('post', 'format', 'format', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('tags', 'id', 'id', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('tags', 'userid', 'userid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('blog_tag_instance', 'id', 'id', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('blog_tag_instance', 'entryid', 'entryid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('blog_tag_instance', 'tagid', 'tagid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('blog_tag_instance', 'groupid', 'groupid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('blog_tag_instance', 'courseid', 'courseid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('blog_tag_instance', 'userid', 'userid', 'integer', '10', 'unsigned', '0', 'not null');
    }
    if ($oldversion < 2006041001) {
        table_column('cache_text', 'formattedtext', 'formattedtext', 'longblob', '', '', '', 'not null');
    }
    if ($oldversion < 2006041100) {
        table_column('course_modules', '', 'visibleold', 'integer', '1', 'unsigned', '1', 'not null', 'visible');
    }
    if ($oldversion < 2006041801) {
        // forgot auto_increments for ids
        modify_database('', "ALTER TABLE prefix_post CHANGE id id INT UNSIGNED NOT NULL AUTO_INCREMENT");
        modify_database('', "ALTER TABLE prefix_tags CHANGE id id INT UNSIGNED NOT NULL AUTO_INCREMENT");
        modify_database('', "ALTER TABLE prefix_blog_tag_instance CHANGE id id INT UNSIGNED NOT NULL AUTO_INCREMENT");
    }
    // changed user->firstname, user->lastname, course->shortname to varchar(100)
    if ($oldversion < 2006041900) {
        table_column('course', 'shortname', 'shortname', 'varchar', '100', '', '', 'not null');
        table_column('user', 'firstname', 'firstname', 'varchar', '100', '', '', 'not null');
        table_column('user', 'lastname', 'lastname', 'varchar', '100', '', '', 'not null');
    }
    if ($oldversion < 2006042400) {
        // Look through table log_display and get rid of duplicates.
        $rs = get_recordset_sql('SELECT DISTINCT * FROM ' . $CFG->prefix . 'log_display');
        // Drop the log_display table and create it back with an id field.
        execute_sql("DROP TABLE {$CFG->prefix}log_display", false);
        modify_database('', "CREATE TABLE prefix_log_display (\n                               `id` int(10) unsigned NOT NULL auto_increment,\n                               `module` varchar(30),\n                               `action` varchar(40),\n                               `mtable` varchar(30),\n                               `field` varchar(50),\n                               PRIMARY KEY (`id`)\n                               ) TYPE=MyISAM");
        // Add index to ensure that module and action combination is unique.
        modify_database('', "ALTER TABLE prefix_log_display ADD UNIQUE `moduleaction`(`module` , `action`)");
        // Insert the records back in, sans duplicates.
        if ($rs && $rs->RecordCount() > 0) {
            while (!$rs->EOF) {
                $sql = "INSERT INTO {$CFG->prefix}log_display " . "VALUES('', '" . $rs->fields['module'] . "', " . "'" . $rs->fields['action'] . "', " . "'" . $rs->fields['mtable'] . "', " . "'" . $rs->fields['field'] . "')";
                execute_sql($sql, false);
                $rs->MoveNext();
            }
        }
    }
    // change tags->type to varchar(20), adding 2 indexes for tags table.
    if ($oldversion < 2006042401) {
        table_column('tags', 'type', 'type', 'varchar', '20', '', '', 'not null');
        modify_database('', "ALTER TABLE prefix_tags ADD INDEX tags_typeuserid_idx (type(20), userid)");
        modify_database('', "ALTER TABLE prefix_tags ADD INDEX tags_text_idx(text(255))");
    }
    /***************************************************
     * The following is an effort to change all the    *
     * default NULLs to NOT NULL defaut '' in all      *
     * mysql tables, to prevent 5303 and be consistent *
     ***************************************************/
    if ($oldversion < 2006042800) {
        execute_sql("UPDATE {$CFG->prefix}grade_category SET name='' WHERE name IS NULL");
        table_column('grade_category', 'name', 'name', 'varchar', '64', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}grade_category SET weight='0' WHERE weight IS NULL");
        execute_sql("ALTER TABLE {$CFG->prefix}grade_category change weight weight decimal(5,2) NOT NULL default 0.00");
        execute_sql("UPDATE {$CFG->prefix}grade_item SET courseid='0' WHERE courseid IS NULL");
        table_column('grade_item', 'courseid', 'courseid', 'int', '10', 'unsigned', '0', 'not null');
        execute_sql("UPDATE {$CFG->prefix}grade_item SET category='0' WHERE category IS NULL");
        table_column('grade_item', 'category', 'category', 'int', '10', 'unsigned', '0', 'not null');
        execute_sql("UPDATE {$CFG->prefix}grade_item SET modid='0' WHERE modid IS NULL");
        table_column('grade_item', 'modid', 'modid', 'int', '10', 'unsigned', '0', 'not null');
        execute_sql("UPDATE {$CFG->prefix}grade_item SET cminstance='0' WHERE cminstance IS NULL");
        table_column('grade_item', 'cminstance', 'cminstance', 'int', '10', 'unsigned', '0', 'not null');
        execute_sql("UPDATE {$CFG->prefix}grade_item SET scale_grade='0' WHERE scale_grade IS NULL");
        execute_sql("ALTER TABLE {$CFG->prefix}grade_item change scale_grade scale_grade float(11,10) NOT NULL default 1.0000000000");
        execute_sql("UPDATE {$CFG->prefix}grade_preferences SET courseid='0' WHERE courseid IS NULL");
        table_column('grade_preferences', 'courseid', 'courseid', 'int', '10', 'unsigned', '0', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET idnumber='' WHERE idnumber IS NULL");
        table_column('user', 'idnumber', 'idnumber', 'varchar', '64', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET icq='' WHERE icq IS NULL");
        table_column('user', 'icq', 'icq', 'varchar', '15', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET skype='' WHERE skype IS NULL");
        table_column('user', 'skype', 'skype', 'varchar', '50', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET yahoo='' WHERE yahoo IS NULL");
        table_column('user', 'yahoo', 'yahoo', 'varchar', '50', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET aim='' WHERE aim IS NULL");
        table_column('user', 'aim', 'aim', 'varchar', '50', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET msn='' WHERE msn IS NULL");
        table_column('user', 'msn', 'msn', 'varchar', '50', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET phone1='' WHERE phone1 IS NULL");
        table_column('user', 'phone1', 'phone1', 'varchar', '20', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET phone2='' WHERE phone2 IS NULL");
        table_column('user', 'phone2', 'phone2', 'varchar', '20', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET institution='' WHERE institution IS NULL");
        table_column('user', 'institution', 'institution', 'varchar', '40', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET department='' WHERE department IS NULL");
        table_column('user', 'department', 'department', 'varchar', '30', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET address='' WHERE address IS NULL");
        table_column('user', 'address', 'address', 'varchar', '70', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET city='' WHERE city IS NULL");
        table_column('user', 'city', 'city', 'varchar', '20', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET country='' WHERE country IS NULL");
        table_column('user', 'country', 'country', 'char', '2', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET lang='' WHERE lang IS NULL");
        table_column('user', 'lang', 'lang', 'varchar', '10', '', 'en', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET lastIP='' WHERE lastIP IS NULL");
        table_column('user', 'lastIP', 'lastIP', 'varchar', '15', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET secret='' WHERE secret IS NULL");
        table_column('user', 'secret', 'secret', 'varchar', '15', '', '', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET picture='0' WHERE picture IS NULL");
        table_column('user', 'picture', 'picture', 'tinyint', '1', '', '0', 'not null');
        execute_sql("UPDATE {$CFG->prefix}user SET url='' WHERE url IS NULL");
        table_column('user', 'url', 'url', 'varchar', '255', '', '', 'not null');
    }
    if ($oldversion < 2006050400) {
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_deleted_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_confirmed_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_firstname_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_lastname_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_city_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_country_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_lastaccess_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` DROP INDEX {$CFG->prefix}user_email_idx;", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` ADD INDEX user_deleted (deleted)", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` ADD INDEX user_confirmed (confirmed)", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` ADD INDEX user_firstname (firstname)", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` ADD INDEX user_lastname (lastname)", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` ADD INDEX user_city (city)", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` ADD INDEX user_country (country)", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` ADD INDEX user_lastaccess (lastaccess)", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}user` ADD INDEX user_email (email)", false);
    }
    if ($oldversion < 2006050500) {
        table_column('log', 'action', 'action', 'varchar', '40', '', '', 'not null');
    }
    if ($oldversion < 2006050501) {
        table_column('sessions', 'data', 'data', 'mediumtext', '', '', '', 'not null');
    }
    // renaming of reads and writes for stats_user_xyz
    if ($oldversion < 2006052400) {
        // change this later
        // we are using this because we want silent updates
        execute_sql("ALTER TABLE `{$CFG->prefix}stats_user_daily` CHANGE `reads` statsreads int(10) unsigned  NOT NULL default 0", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}stats_user_daily` CHANGE `writes` statswrites int(10) unsigned  NOT NULL default 0", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}stats_user_weekly` CHANGE `reads` statsreads int(10) unsigned  NOT NULL default 0", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}stats_user_weekly` CHANGE `writes` statswrites int(10) unsigned  NOT NULL default 0", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}stats_user_monthly` CHANGE `reads` statsreads int(10) unsigned  NOT NULL default 0", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}stats_user_monthly` CHANGE `writes` statswrites int(10) unsigned  NOT NULL default 0", false);
    }
    // Adding some missing log actions
    if ($oldversion < 2006060400) {
        // But only if they doesn't exist (because this was introduced after branch and we could be duplicating!)
        if (!record_exists('log_display', 'module', 'course', 'action', 'report log')) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'report log', 'course', 'fullname')");
        }
        if (!record_exists('log_display', 'module', 'course', 'action', 'report live')) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'report live', 'course', 'fullname')");
        }
        if (!record_exists('log_display', 'module', 'course', 'action', 'report outline')) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'report outline', 'course', 'fullname')");
        }
        if (!record_exists('log_display', 'module', 'course', 'action', 'report participation')) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'report participation', 'course', 'fullname')");
        }
        if (!record_exists('log_display', 'module', 'course', 'action', 'report stats')) {
            execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'report stats', 'course', 'fullname')");
        }
    }
    //Renaming lastIP to lastip (all fields lowercase)
    if ($oldversion < 2006060900) {
        //Only if it exists
        $fields = $db->MetaColumnNames($CFG->prefix . 'user');
        if (in_array('lastIP', $fields)) {
            table_column("user", "lastIP", "lastip", "varchar", "15", "", "", "not null", "currentlogin");
        }
    }
    // Change in MySQL 5.0.3 concerning how decimals are stored. Mimic from 16_STABLE
    // this isn't dangerous because it's a simple type change, but be careful with
    // versions and duplicate work in order to provide smooth upgrade paths.
    if ($oldversion < 2006071800) {
        table_column('grade_letter', 'grade_high', 'grade_high', 'decimal(5,2)', '', '', '100.00', 'not null', '');
        table_column('grade_letter', 'grade_low', 'grade_low', 'decimal(5,2)', '', '', '0.00', 'not null', '');
    }
    if ($oldversion < 2006080400) {
        execute_sql("CREATE TABLE {$CFG->prefix}role (\n                              `id` int(10) unsigned NOT NULL auto_increment,\n                              `name` varchar(255) NOT NULL default '',\n                              `shortname` varchar(100) NOT NULL default '',\n                              `description` text NOT NULL default '',\n                              `sortorder` int(10) unsigned NOT NULL default '0',\n                              PRIMARY KEY  (`id`)\n                            )", true);
        execute_sql("CREATE TABLE {$CFG->prefix}context (\n                              `id` int(10) unsigned NOT NULL auto_increment,\n                              `level` int(10) unsigned NOT NULL default '0',\n                              `instanceid` int(10) unsigned NOT NULL default '0',\n                              PRIMARY KEY  (`id`)\n                            )", true);
        execute_sql("CREATE TABLE {$CFG->prefix}role_assignments (\n                              `id` int(10) unsigned NOT NULL auto_increment,\n                              `roleid` int(10) unsigned NOT NULL default '0',\n                              `contextid` int(10) unsigned NOT NULL default '0',\n                              `userid` int(10) unsigned NOT NULL default '0',\n                              `hidden` int(1) unsigned NOT NULL default '0',\n                              `timestart` int(10) unsigned NOT NULL default '0',\n                              `timeend` int(10) unsigned NOT NULL default '0',\n                              `timemodified` int(10) unsigned NOT NULL default '0',\n                              `modifierid` int(10) unsigned NOT NULL default '0',\n                              `enrol` varchar(20) NOT NULL default '',\n                              `sortorder` int(10) unsigned NOT NULL default '0',\n                              PRIMARY KEY  (`id`)\n                            )", true);
        execute_sql("CREATE TABLE {$CFG->prefix}role_capabilities (\n                              `id` int(10) unsigned NOT NULL auto_increment,\n                              `contextid` int(10) unsigned NOT NULL default '0',\n                              `roleid` int(10) unsigned NOT NULL default '0',\n                              `capability` varchar(255) NOT NULL default '',\n                              `permission` int(10) unsigned NOT NULL default '0',\n                              `timemodified` int(10) unsigned NOT NULL default '0',\n                              `modifierid` int(10) unsigned NOT NULL default '0',\n                              PRIMARY KEY (`id`)\n                            )", true);
        execute_sql("CREATE TABLE {$CFG->prefix}role_deny_grant (\n                              `id` int(10) unsigned NOT NULL auto_increment,\n                              `roleid` int(10) unsigned NOT NULL default '0',\n                              `unviewableroleid` int(10) unsigned NOT NULL default '0',\n                              PRIMARY KEY (`id`)\n                            )", true);
        execute_sql("CREATE TABLE {$CFG->prefix}capabilities ( \n                              `id` int(10) unsigned NOT NULL auto_increment, \n                              `name` varchar(255) NOT NULL default '', \n                              `captype` varchar(50) NOT NULL default '', \n                              `contextlevel` int(10) unsigned NOT NULL default '0', \n                              `component` varchar(100) NOT NULL default '', \n                              PRIMARY KEY (`id`) \n                            )", true);
        execute_sql("CREATE TABLE {$CFG->prefix}role_names ( \n                              `id` int(10) unsigned NOT NULL auto_increment, \n                              `roleid` int(10) unsigned NOT NULL default '0',\n                              `contextid` int(10) unsigned NOT NULL default '0', \n                              `text` text NOT NULL default '',\n                              PRIMARY KEY (`id`) \n                            )", true);
    }
    if ($oldversion < 2006081000) {
        execute_sql("ALTER TABLE `{$CFG->prefix}role` ADD INDEX `sortorder` (`sortorder`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}context` ADD INDEX `instanceid` (`instanceid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}context` ADD UNIQUE INDEX `level-instanceid` (`level`, `instanceid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_assignments` ADD INDEX `roleid` (`roleid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_assignments` ADD INDEX `contextid` (`contextid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_assignments` ADD INDEX `userid` (`userid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_assignments` ADD UNIQUE INDEX `contextid-roleid-userid` (`contextid`, `roleid`, `userid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_assignments` ADD INDEX `sortorder` (`sortorder`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_capabilities` ADD INDEX `roleid` (`roleid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_capabilities` ADD INDEX `contextid` (`contextid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_capabilities` ADD INDEX `modifierid` (`modifierid`)", true);
        // MDL-10640  adding missing index from upgrade
        execute_sql("ALTER TABLE `{$CFG->prefix}role_capabilities` ADD INDEX `capability` (`capability`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_capabilities` ADD UNIQUE INDEX `roleid-contextid-capability` (`roleid`, `contextid`, `capability`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_deny_grant` ADD INDEX `roleid` (`roleid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_deny_grant` ADD INDEX `unviewableroleid` (`unviewableroleid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_deny_grant` ADD UNIQUE INDEX `roleid-unviewableroleid` (`roleid`, `unviewableroleid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}capabilities` ADD UNIQUE INDEX `name` (`name`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_names` ADD INDEX `roleid` (`roleid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_names` ADD INDEX `contextid` (`contextid`)", true);
        execute_sql("ALTER TABLE `{$CFG->prefix}role_names` ADD UNIQUE INDEX `roleid-contextid` (`roleid`, `contextid`)", true);
    }
    if ($oldversion < 2006081600) {
        execute_sql("ALTER TABLE `{$CFG->prefix}role_capabilities` CHANGE permission permission int(10) NOT NULL default '0'", true);
    }
    // drop role_deny_grant table, and create 2 new ones
    if ($oldversion < 2006081700) {
        execute_sql("DROP TABLE `{$CFG->prefix}role_deny_grant`", true);
        execute_sql("CREATE TABLE {$CFG->prefix}role_allow_assign (\n                    `id` int(10) unsigned NOT NULL auto_increment,\n                    `roleid` int(10) unsigned NOT NULL default '0',\n                    `allowassign` int(10) unsigned NOT NULL default '0',\n                    KEY `roleid` (`roleid`),\n                    KEY `allowassign` (`allowassign`),\n                    UNIQUE KEY `roleid-allowassign` (`roleid`, `allowassign`),\n                    PRIMARY KEY (`id`)\n                    )", true);
        execute_sql("CREATE TABLE {$CFG->prefix}role_allow_override (\n                    `id` int(10) unsigned NOT NULL auto_increment,\n                    `roleid` int(10) unsigned NOT NULL default '0',\n                    `allowoverride` int(10) unsigned NOT NULL default '0',\n                    KEY `roleid` (`roleid`),\n                    KEY `allowoverride` (`allowoverride`),\n                    UNIQUE KEY `roleid-allowoverride` (`roleid`, `allowoverride`),\n                    PRIMARY KEY (`id`)\n                    )", true);
    }
    if ($oldversion < 2006082100) {
        execute_sql("ALTER TABLE `{$CFG->prefix}context` DROP INDEX `level-instanceid`;", false);
        table_column('context', 'level', 'aggregatelevel', 'int', '10', 'unsigned', '0', 'not null', '');
        execute_sql("ALTER TABLE `{$CFG->prefix}context` ADD UNIQUE INDEX `aggregatelevel-instanceid` (`aggregatelevel`, `instanceid`)", false);
    }
    if ($oldversion < 2006082200) {
        table_column('timezone', 'rule', 'tzrule', 'varchar', '20', '', '', 'not null', '');
    }
    if ($oldversion < 2006082800) {
        table_column('user', '', 'ajax', 'integer', '1', 'unsigned', '1', 'not null', 'htmleditor');
    }
    if ($oldversion < 2006082900) {
        execute_sql("DROP TABLE {$CFG->prefix}sessions", true);
        execute_sql("\n            CREATE TABLE {$CFG->prefix}sessions2 (\n                sesskey VARCHAR(64) NOT NULL default '',\n                expiry DATETIME NOT NULL,\n                expireref VARCHAR(250),\n                created DATETIME NOT NULL,\n                modified DATETIME NOT NULL,\n                sessdata TEXT,\n                CONSTRAINT  PRIMARY KEY (sesskey)\n            ) COMMENT='Optional database session storage in new format, not used by default';", true);
        execute_sql("\n            CREATE INDEX {$CFG->prefix}sess_exp_ix ON {$CFG->prefix}sessions2 (expiry);", true);
        execute_sql("\n            CREATE INDEX {$CFG->prefix}sess_exp2_ix ON {$CFG->prefix}sessions2 (expireref);", true);
    }
    if ($oldversion < 2006083001) {
        table_column('sessions2', 'sessdata', 'sessdata', 'LONGTEXT', '', '', '', '', '');
    }
    if ($oldversion < 2006083002) {
        table_column('capabilities', '', 'riskbitmask', 'INTEGER', '10', 'unsigned', '0', 'not null', '');
    }
    if ($oldversion < 2006083100) {
        execute_sql("ALTER TABLE {$CFG->prefix}course CHANGE modinfo modinfo longtext NULL AFTER showgrades");
    }
    if ($oldversion < 2006083101) {
        execute_sql("ALTER TABLE {$CFG->prefix}course_categories CHANGE description description text NULL AFTER name");
    }
    if ($oldversion < 2006083102) {
        execute_sql("ALTER TABLE {$CFG->prefix}user CHANGE description description text NULL AFTER url");
    }
    if ($oldversion < 2006090200) {
        execute_sql("ALTER TABLE {$CFG->prefix}course_sections CHANGE summary summary text NULL AFTER section");
        execute_sql("ALTER TABLE {$CFG->prefix}course_sections CHANGE sequence sequence text NULL AFTER section");
    }
    // table to keep track of course page access times, used in online participants block, and participants list
    if ($oldversion < 2006091200) {
        execute_sql("CREATE TABLE {$CFG->prefix}user_lastaccess ( \n                    `id` int(10) unsigned NOT NULL auto_increment, \n                    `userid` int(10) unsigned NOT NULL default '0',\n                    `courseid` int(10) unsigned NOT NULL default '0', \n                    `timeaccess` int(10) unsigned NOT NULL default '0', \n                    KEY `userid` (`userid`),\n                    KEY `courseid` (`courseid`),\n                    UNIQUE KEY `userid-courseid` (`userid`, `courseid`),\n                    PRIMARY KEY (`id`) \n                    )TYPE=MYISAM COMMENT ='time user last accessed any page in a course';", true);
    }
    if ($oldversion < 2006091212) {
        // Reload the guest roles completely with new defaults
        if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
            delete_records('capabilities');
            $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
            foreach ($guestroles as $guestrole) {
                delete_records('role_capabilities', 'roleid', $guestrole->id);
                assign_capability('moodle/legacy:guest', CAP_ALLOW, $guestrole->id, $sitecontext->id);
            }
        }
    }
    if ($oldversion < 2006091700) {
        table_column('course', '', 'defaultrole', 'integer', '10', 'unsigned', '0', 'not null');
    }
    if ($oldversion < 2006091800) {
        delete_records('config', 'name', 'showsiteparticipantslist');
        delete_records('config', 'name', 'requestedteachername');
        delete_records('config', 'name', 'requestedteachersname');
        delete_records('config', 'name', 'requestedstudentname');
        delete_records('config', 'name', 'requestedstudentsname');
    }
    if ($oldversion < 2006091901) {
        if ($roles = get_records('role')) {
            $first = array_shift($roles);
            if (!empty($first->shortname)) {
                // shortnames already exist
            } else {
                table_column('role', '', 'shortname', 'varchar', '100', '', '', 'not null', 'name');
                $legacy_names = array('admin', 'coursecreator', 'editingteacher', 'teacher', 'student', 'guest');
                foreach ($legacy_names as $name) {
                    if ($roles = get_roles_with_capability('moodle/legacy:' . $name, CAP_ALLOW)) {
                        $i = '';
                        foreach ($roles as $role) {
                            if (empty($role->shortname)) {
                                $updated = new object();
                                $updated->id = $role->id;
                                $updated->shortname = $name . $i;
                                update_record('role', $updated);
                                $i++;
                            }
                        }
                    }
                }
            }
        }
    }
    /// Tables for customisable user profile fields
    if ($oldversion < 2006092000) {
        execute_sql("CREATE TABLE {$CFG->prefix}user_info_field (\n                        id BIGINT(10) NOT NULL auto_increment,\n                        name VARCHAR(255) NOT NULL default '',\n                        datatype VARCHAR(255) NOT NULL default '',\n                        categoryid BIGINT(10) unsigned NOT NULL default 0,\n                        sortorder BIGINT(10) unsigned NOT NULL default 0,\n                        required TINYINT(2) unsigned NOT NULL default 0,\n                        locked TINYINT(2) unsigned NOT NULL default 0,\n                        visible SMALLINT(4) unsigned NOT NULL default 0,\n                        defaultdata LONGTEXT,\n                        CONSTRAINT  PRIMARY KEY (id));", true);
        execute_sql("ALTER TABLE {$CFG->prefix}user_info_field COMMENT='Customisable user profile fields';", true);
        execute_sql("CREATE TABLE {$CFG->prefix}user_info_category (\n                        id BIGINT(10) NOT NULL auto_increment,\n                        name VARCHAR(255) NOT NULL default '',\n                        sortorder BIGINT(10) unsigned NOT NULL default 0,\n                        CONSTRAINT  PRIMARY KEY (id));", true);
        execute_sql("ALTER TABLE {$CFG->prefix}user_info_category COMMENT='Customisable fields categories';", true);
        execute_sql("CREATE TABLE {$CFG->prefix}user_info_data (\n                        id BIGINT(10) NOT NULL auto_increment,\n                        userid BIGINT(10) unsigned NOT NULL default 0,\n                        fieldid BIGINT(10) unsigned NOT NULL default 0,\n                        data LONGTEXT NOT NULL,\n                        CONSTRAINT  PRIMARY KEY (id));", true);
        execute_sql("ALTER TABLE {$CFG->prefix}user_info_data COMMENT='Data for the customisable user fields';", true);
    }
    if ($oldversion < 2006092200) {
        table_column('context', 'aggregatelevel', 'contextlevel', 'int', '10', 'unsigned', '0', 'not null', '');
        /*        execute_sql("ALTER TABLE `{$CFG->prefix}context` DROP INDEX `aggregatelevel-instanceid`;",false);
                execute_sql("ALTER TABLE `{$CFG->prefix}context` ADD UNIQUE INDEX `contextlevel-instanceid` (`contextlevel`, `instanceid`)",false);   // see 2006092409 below  */
    }
    if ($oldversion < 2006092201) {
        execute_sql('TRUNCATE TABLE ' . $CFG->prefix . 'cache_text', true);
        table_column('cache_text', 'formattedtext', 'formattedtext', 'longtext', '', '', '', 'not null');
    }
    if ($oldversion < 2006092302) {
        // fix sortorder first if needed
        if ($roles = get_all_roles()) {
            $i = 0;
            foreach ($roles as $rolex) {
                if ($rolex->sortorder != $i) {
                    $r = new object();
                    $r->id = $rolex->id;
                    $r->sortorder = $i;
                    update_record('role', $r);
                }
                $i++;
            }
        }
        /*        execute_sql("ALTER TABLE {$CFG->prefix}role DROP INDEX {$CFG->prefix}role_sor_ix;", false);
                execute_sql("ALTER TABLE {$CFG->prefix}role ADD UNIQUE INDEX {$CFG->prefix}role_sor_uix (sortorder)", false);*/
    }
    if ($oldversion < 2006092400) {
        table_column('user', '', 'trustbitmask', 'INTEGER', '10', 'unsigned', '0', 'not null', '');
    }
    if ($oldversion < 2006092409) {
        // ok, once more and now correctly!
        execute_sql("DROP INDEX `aggregatelevel-instanceid` ON {$CFG->prefix}context ;", false);
        execute_sql("DROP INDEX `contextlevel-instanceid` ON {$CFG->prefix}context ;", false);
        execute_sql("CREATE UNIQUE INDEX {$CFG->prefix}cont_conins_uix ON {$CFG->prefix}context (contextlevel, instanceid);", false);
        execute_sql("DROP INDEX {$CFG->prefix}role_sor_ix ON {$CFG->prefix}role ;", false);
        execute_sql("DROP INDEX {$CFG->prefix}role_sor_uix ON {$CFG->prefix}role ;", false);
        execute_sql("CREATE UNIQUE INDEX {$CFG->prefix}role_sor_uix ON {$CFG->prefix}role (sortorder);", false);
    }
    if ($oldversion < 2006092601) {
        table_column('log_display', 'field', 'field', 'varchar', '200', '', '', 'not null', '');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return $result;
}
示例#26
0
function hotpot_create_table($table)
{
    global $CFG;
    static $sql;
    static $xmldb_file;
    // check table does not already exist
    if (hotpot_db_table_exists($table)) {
        return true;
    }
    if (!isset($xmldb_file)) {
        // first time only
        if (class_exists('XMLDBFile')) {
            $xmldb_file = new XMLDBFile("{$CFG->dirroot}/mod/hotpot/db/install.xml");
            if (!$xmldb_file->fileExists() || !$xmldb_file->loadXMLStructure() || !$xmldb_file->isLoaded()) {
                unset($xmldb_file);
            }
        }
        if (empty($xmldb_file)) {
            $xmldb_file = false;
        }
    }
    if ($xmldb_file) {
        // Moodle 1.8 (and later)
        $ok = false;
        foreach ($xmldb_file->xmldb_structure->tables as $xmldb_table) {
            if ($xmldb_table->name == $table) {
                $ok = create_table($xmldb_table);
                break;
            }
        }
        return $ok;
    }
    // Moodle 1.7 (and earlier)
    if (!isset($sql)) {
        // first time only
        $sqlfilepath = "{$CFG->dirroot}/mod/hotpot/db/{$CFG->dbtype}.sql";
        if (file_exists($sqlfilepath)) {
            if (function_exists('file_get_contents')) {
                $sql = file_get_contents($sqlfilepath);
            } else {
                // PHP < 4.3
                $sql = file($sqlfilepath);
                if (is_array($sql)) {
                    $sql = implode('', $sql);
                }
            }
        }
        if (empty($sql)) {
            $sql = '';
        }
    }
    // extract and execute all CREATE statements relating to this table
    if (preg_match_all("/CREATE (TABLE|INDEX)(\\s[^;]*)? prefix_{$table}(\\s[^;]*)?;/s", $sql, $strings)) {
        $ok = true;
        foreach ($strings[0] as $string) {
            $ok = $ok && modify_database('', $string);
        }
        return $ok;
    }
    // table could not be created
    return false;
}
示例#27
0
function rss_client_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    global $CFG;
    if ($oldversion < 2005111400) {
        // title and description should be TEXT as we don't have control over their length.
        table_column('block_rss_client', 'title', 'title', 'text');
        table_column('block_rss_client', 'description', 'description', 'text');
    }
    if ($oldversion < 2005090201) {
        modify_database('', 'ALTER TABLE prefix_block_rss_client
            ALTER COLUMN title SET DEFAULT \'\',
            ALTER COLUMN description SET DEFAULT \'\'');
    }
    if ($oldversion < 2006091100) {
        // We need a new field to store whether an RSS feed is shared or private.
        table_column('block_rss_client', '', 'shared', 'integer');
        // Admin feeds used to be displayed to everybody (shared feeds).
        $admins = get_admins();
        if (!empty($admins)) {
            $count = 0;
            foreach ($admins as $admin) {
                if (!$count) {
                    $adminsql = 'userid = ' . $admin->id;
                } else {
                    $adminsql .= ' OR userid = ' . $admin->id;
                }
                $count++;
            }
            if ($rssfeeds = get_records_select('block_rss_client', $adminsql)) {
                foreach ($rssfeeds as $rssfeed) {
                    if (!set_field('block_rss_client', 'shared', 1)) {
                        notice('Could not set ' . $rssfeed->title . ' as a shared RSS feed.');
                    }
                }
            }
        }
    }
    /// see MDL-6707 for more info about problem that was here
    if ($oldversion < 2006100101) {
        // Upgrade block to use the Roles System.
        $block = get_record('block', 'name', 'rss_client');
        if ($blockinstances = get_records('block_instance', 'blockid', $block->id)) {
            if (!($adminroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW))) {
                notice('Default student role was not found. Roles and permissions ' . 'for all your Remote RSS Feed blocks will have to be ' . 'manually set after this upgrade.');
            }
            if (!($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW))) {
                notice('Default teacher role was not found. Roles and permissions ' . 'for all your Remote RSS Feed blocks will have to be ' . 'manually set after this upgrade.');
            }
            if (!($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW))) {
                notice('Default student role was not found. Roles and permissions ' . 'for all your Remote RSS Feed blocks will have to be ' . 'manually set after this upgrade.');
            }
            foreach ($blockinstances as $bi) {
                $context = get_context_instance(CONTEXT_BLOCK, $bi->id);
                if ($bi->pagetype == 'course-view' && $bi->pageid == SITEID) {
                    // Only the admin was allowed to manage the RSS feed block
                    // on the site home page.
                    // Since this is already the default behavior set in
                    // blocks/rss_client/db/access.php, we don't need to
                    // specifically assign the capabilities here.
                } else {
                    // Who can add shared feeds? This was defined in lib/rsslib.php
                    // for config var block_rss_client_submitters.
                    switch ($CFG->block_rss_client_submitters) {
                        case 0:
                            // SUBMITTERS_ALL_ACCOUNT_HOLDERS
                            foreach ($adminroles as $adminrole) {
                                assign_capability('block/rss_client:createsharedfeeds', CAP_ALLOW, $adminrole->id, $context->id);
                            }
                            foreach ($teacherroles as $teacherrole) {
                                assign_capability('block/rss_client:createsharedfeeds', CAP_ALLOW, $teacherrole->id, $context->id);
                            }
                            foreach ($studentroles as $studentrole) {
                                assign_capability('block/rss_client:createsharedfeeds', CAP_ALLOW, $studentrole->id, $context->id);
                            }
                            break;
                        case 1:
                            // SUBMITTERS_ADMIN_ONLY
                            // Since this is already the default behavior set in
                            // blocks/rss_client/db/access.php, we don't need to
                            // specifically assign the capabilities here.
                            break;
                        case 2:
                            // SUBMITTERS_ADMIN_AND_TEACHER
                            foreach ($adminroles as $adminrole) {
                                assign_capability('block/rss_client:createsharedfeeds', CAP_ALLOW, $adminrole->id, $context->id);
                            }
                            foreach ($teacherroles as $teacherrole) {
                                assign_capability('block/rss_client:createsharedfeeds', CAP_ALLOW, $teacherrole->id, $context->id);
                            }
                            foreach ($studentroles as $studentrole) {
                                assign_capability('block/rss_client:createsharedfeeds', CAP_PREVENT, $studentrole->id, $context->id);
                            }
                            break;
                    }
                    // End switch.
                }
            }
        }
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
示例#28
0
function assignment_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    if ($oldversion < 2002080500) {
        execute_sql("\n        CREATE TABLE `assignment` (\n          `id` int(10) unsigned NOT NULL auto_increment,\n          `course` int(10) unsigned NOT NULL default '0',\n          `name` varchar(255) NOT NULL default '',\n          `description` text NOT NULL,\n          `type` int(10) unsigned NOT NULL default '1',\n          `maxbytes` int(10) unsigned NOT NULL default '100000',\n          `timedue` int(10) unsigned NOT NULL default '0',\n          `grade` int(10) NOT NULL default '0',\n          `timemodified` int(10) unsigned NOT NULL default '0',\n          PRIMARY KEY  (`id`)\n        ) COMMENT='Defines assignments'\n        ");
        execute_sql("\n        CREATE TABLE `assignment_submissions` (\n          `id` int(10) unsigned NOT NULL default '0',\n          `assignment` int(10) unsigned NOT NULL default '0',\n          `user` int(10) unsigned NOT NULL default '0',\n          `timecreated` int(10) unsigned NOT NULL default '0',\n          `timemodified` int(10) unsigned NOT NULL default '0',\n          `numfiles` int(10) unsigned NOT NULL default '0',\n          `grade` int(11) NOT NULL default '0',\n          `comment` text NOT NULL,\n          `teacher` int(10) unsigned NOT NULL default '0',\n          `timemarked` int(10) unsigned NOT NULL default '0',\n          `mailed` tinyint(1) unsigned NOT NULL default '0',\n          PRIMARY KEY  (`id`)\n        ) COMMENT='Info about submitted assignments'\n        ");
        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'view', 'assignment', 'name') ");
        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'add', 'assignment', 'name') ");
        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'update', 'assignment', 'name') ");
        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'view submissions', 'assignment', 'name') ");
        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'upload', 'assignment', 'name') ");
    }
    if ($oldversion < 2002080701) {
        execute_sql(" ALTER TABLE `assignment_submissions` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ");
    }
    if ($oldversion < 2002082806) {
        // assignment file area was moved, so rename all the directories in existing courses
        notify("Moving location of assignment files...");
        $basedir = opendir("{$CFG->dataroot}");
        while (false !== ($dir = readdir($basedir))) {
            if ($dir == "." || $dir == ".." || $dir == "users") {
                continue;
            }
            if (filetype("{$CFG->dataroot}/{$dir}") != "dir") {
                continue;
            }
            $coursedir = "{$CFG->dataroot}/{$dir}";
            if (!($coursemoddata = make_mod_upload_directory($dir))) {
                echo "Error: could not create mod upload directory: {$coursemoddata}";
                continue;
            }
            if (file_exists("{$coursedir}/assignment")) {
                if (!rename("{$coursedir}/assignment", "{$coursemoddata}/assignment")) {
                    echo "Error: could not move {$coursedir}/assignment to {$coursemoddata}/assignment\n";
                }
            }
        }
    }
    if ($oldversion < 2002101600) {
        execute_sql(" ALTER TABLE `assignment` ADD `format` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `description` ");
    }
    if ($oldversion < 2002110302) {
        execute_sql(" UPDATE `assignment` SET `type` = '1'");
    }
    if ($oldversion < 2002111500) {
        execute_sql(" ALTER TABLE `assignment` ADD `resubmit` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `format` ");
    }
    if ($oldversion < 2002122300) {
        execute_sql("ALTER TABLE `assignment_submissions` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
    }
    if ($oldversion < 2004021700) {
        set_field("log_display", "action", "view submission", "module", "assignment", "action", "view submissions");
    }
    if ($oldversion < 2004040100) {
        include_once "{$CFG->dirroot}/mod/assignment/lib.php";
        assignment_refresh_events();
    }
    if ($oldversion < 2004111200) {
        execute_sql("ALTER TABLE {$CFG->prefix}assignment DROP INDEX course;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}assignment_submissions DROP INDEX assignment;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}assignment_submissions DROP INDEX userid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}assignment_submissions DROP INDEX mailed;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}assignment_submissions DROP INDEX timemarked;", false);
        modify_database('', 'ALTER TABLE prefix_assignment ADD INDEX course (course);');
        modify_database('', 'ALTER TABLE prefix_assignment_submissions ADD INDEX assignment(assignment);');
        modify_database('', 'ALTER TABLE prefix_assignment_submissions ADD INDEX userid (userid);');
        modify_database('', 'ALTER TABLE prefix_assignment_submissions ADD INDEX mailed (mailed);');
        modify_database('', 'ALTER TABLE prefix_assignment_submissions ADD INDEX timemarked (timemarked);');
    }
    if ($oldversion < 2005010500) {
        // New field for sending out mail to teachers
        table_column('assignment', '', 'emailteachers', 'integer', '2', 'unsigned', 0, 'not null', 'resubmit');
    }
    if ($oldversion < 2005041100) {
        // replace wiki-like with markdown
        include_once "{$CFG->dirroot}/lib/wiki_to_markdown.php";
        $wtm = new WikiToMarkdown();
        $wtm->update('assignment', 'description', 'format');
    }
    if ($oldversion < 2005041400) {
        // Add new fields for the new refactored version of assignment
        table_column('assignment', '', 'timeavailable', 'integer', '10', 'unsigned', 0, 'not null', 'timedue');
        table_column('assignment', '', 'assignmenttype', 'varchar', '50', '', '', 'not null', 'format');
        execute_sql("UPDATE {$CFG->prefix}assignment SET assignmenttype = 'offline' WHERE type = '0';");
        execute_sql("UPDATE {$CFG->prefix}assignment SET assignmenttype = 'uploadsingle' WHERE type = '1';");
        execute_sql('ALTER TABLE ' . $CFG->prefix . 'assignment DROP type;');
    }
    if ($oldversion < 2005041501) {
        // Add two new fields for general data handling,
        // so most assignment types won't need new fields and backups stay simple
        table_column('assignment_submissions', '', 'data2', 'MEDIUMTEXT', '', '', '', 'not null', 'numfiles');
        table_column('assignment_submissions', '', 'data1', 'MEDIUMTEXT', '', '', '', 'not null', 'numfiles');
    }
    if ($oldversion < 2005041600) {
        // Add five new fields for general assignment parameters
        // so most assignment types won't need new fields and backups stay simple
        table_column('assignment', '', 'var5', 'integer', '10', '', 0, 'null', 'emailteachers');
        table_column('assignment', '', 'var4', 'integer', '10', '', 0, 'null', 'emailteachers');
        table_column('assignment', '', 'var3', 'integer', '10', '', 0, 'null', 'emailteachers');
        table_column('assignment', '', 'var2', 'integer', '10', '', 0, 'null', 'emailteachers');
        table_column('assignment', '', 'var1', 'integer', '10', '', 0, 'null', 'emailteachers');
    }
    if ($oldversion < 2005041700) {
        // Allow comments to have a formatting
        table_column('assignment_submissions', '', 'format', 'integer', '4', 'unsigned', '0', 'not null', 'comment');
    }
    if ($oldversion < 2005041800) {
        // Prevent late submissions?  (default no)
        table_column('assignment', '', 'preventlate', 'integer', '2', 'unsigned', '0', 'not null', 'resubmit');
    }
    if ($oldversion < 2005060100) {
        include_once "{$CFG->dirroot}/mod/assignment/lib.php";
        assignment_refresh_events();
    }
    if ($oldversion < 2006092100) {
        table_column('assignment_submissions', 'comment', 'submissioncomment', 'text', '', '', '');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
示例#29
0
function main_upgrade($oldversion = 0)
{
    global $CFG, $db;
    $result = true;
    if ($oldversion < 0) {
        modify_database('', "CREATE TABLE {$CFG->prefix}datalists (\r\n                              ident SERIAL PRIMARY KEY,\r\n                              name varchar(32) NOT NULL default '',\r\n                              value text NOT NULL\r\n                            );");
        modify_database('', "CREATE INDEX {$CFG->prefix}datalists_name_idx ON {$CFG->prefix}datalists (name);");
    }
    if ($oldversion < 2006010600) {
        execute_sql("\r\n            CREATE TABLE {$CFG->prefix}weblog_watchlist (\r\n              ident SERIAL PRIMARY KEY,\r\n              owner integer NOT NULL default '0',\r\n              weblog_post integer NOT NULL default '0'\r\n            ) ;\r\n\r\n            CREATE INDEX {$CFG->prefix}weblog_watchlist_owner_idx ON {$CFG->prefix}weblog_watchlist (owner,weblog_post);");
        execute_sql("DROP INDEX {$CFG->prefix}friends_owner_idx ;");
        execute_sql("CREATE INDEX {$CFG->prefix}friends_owner_idx ON {$CFG->prefix}friends (owner) ;");
        execute_sql("CREATE INDEX {$CFG->prefix}friends_friend_idx ON {$CFG->prefix}friends (friend) ;");
        table_column('friends', '', 'status', 'varchar', '4', '', 'perm');
        execute_sql("CREATE INDEX {$CFG->prefix}friends_status_idx ON {$CFG->prefix}friends (status);");
        table_column('users', '', 'moderation', 'varchar', '4', '', 'no');
        execute_sql("CREATE INDEX {$CFG->prefix}users_moderation_idx ON {$CFG->prefix}users (moderation);");
    }
    if ($oldversion < 2006010601) {
        execute_sql("DROP INDEX {$CFG->prefix}file_folders_owner_idx ;");
        execute_sql("CREATE INDEX {$CFG->prefix}file_folders_files_owner_idx ON {$CFG->prefix}file_folders (files_owner);");
        execute_sql("CREATE INDEX {$CFG->prefix}file_folders_owner_idx ON {$CFG->prefix}file_folders (owner);");
        execute_sql("CREATE INDEX {$CFG->prefix}file_folders_access_idx ON {$CFG->prefix}file_folders (access);");
        execute_sql("CREATE INDEX {$CFG->prefix}file_folders_name_idx ON {$CFG->prefix}file_folders (name);");
        execute_sql("DROP INDEX {$CFG->prefix}icons_owner_idx ;");
        execute_sql("CREATE INDEX {$CFG->prefix}icons_owner_idx ON {$CFG->prefix}icons (owner) ;");
        execute_sql("DROP INDEX {$CFG->prefix}invitations_name_idx ;");
        execute_sql("CREATE INDEX {$CFG->prefix}invitations_code_idx ON {$CFG->prefix}invitations (code);");
        execute_sql("CREATE INDEX {$CFG->prefix}invitations_email_idx ON {$CFG->prefix}invitations (email);");
        execute_sql("CREATE INDEX {$CFG->prefix}invitations_added_idx ON {$CFG->prefix}invitations (added);");
        execute_sql("DROP INDEX {$CFG->prefix}tags_tag_idx ;");
        execute_sql("DROP INDEX {$CFG->prefix}tags_tag_2_idx ;");
        execute_sql("CREATE INDEX {$CFG->prefix}tags_tagtype_ref_idx ON {$CFG->prefix}tags (tagtype,ref);");
        execute_sql("CREATE INDEX {$CFG->prefix}tags_tag_idx ON {$CFG->prefix}tags (tag);");
    }
    if ($oldversion < 2006012600) {
        modify_database('', "CREATE TABLE {$CFG->prefix}users_alias (\r\n                               ident SERIAL PRIMARY KEY,\r\n                               installid varchar(32) NOT NULL default '',\r\n                               username varchar(32) NOT NULL default '',\r\n                               firstname varchar(64) NOT NULL default '',\r\n                               lastname varchar(64) NOT NULL default '',\r\n                               email varchar(128) NOT NULL default '',\r\n                               user_id integer NOT NULL default 0\r\n                             );");
        modify_database('', "CREATE INDEX {$CFG->prefix}users_alias_username_idx ON {$CFG->prefix}users_alias (username);");
        modify_database('', "CREATE INDEX {$CFG->prefix}users_alias_installid_idx ON {$CFG->prefix}users_alias (installid);");
        modify_database('', "CREATE INDEX {$CFG->prefix}users_alias_user_id_idx ON {$CFG->prefix}users_alias (user_id);");
    }
    if ($oldversion < 2006021400) {
        modify_database('', "CREATE TABLE {$CFG->prefix}files_incoming (\r\n                               ident SERIAL PRIMARY KEY,\r\n                               installid varchar(32) NOT NULL default '',\r\n                               intentiondate integer NOT NULL default 0,\r\n                               size bigint NOT NULL default 0,\r\n                               foldername varchar(128) NOT NULL default '',\r\n                               user_id integer NOT NULL default 0\r\n                            );");
        modify_database('', "CREATE INDEX {$CFG->prefix}files_incoming_user_id_idx ON {$CFG->prefix}files_incoming (user_id);");
    }
    if ($oldversion < 2006022000) {
        modify_database('', "CREATE TABLE {$CFG->prefix}feed_posts (\r\n                              ident SERIAL PRIMARY KEY,\r\n                              posted varchar(64) NOT NULL default '',\r\n                              added integer NOT NULL default 0,\r\n                              feed integer NOT NULL default 0,\r\n                              title text NOT NULL,\r\n                              body text NOT NULL,\r\n                              url varchar(128) NOT NULL default ''\r\n                            );");
        modify_database('', "CREATE INDEX {$CFG->prefix}feed_posts_url_idx ON {$CFG->prefix}feed_posts (url);");
        modify_database('', "CREATE INDEX {$CFG->prefix}feed_posts_feed_idx ON {$CFG->prefix}feed_posts (feed);");
        modify_database('', "CREATE INDEX {$CFG->prefix}feed_posts_posted_idx ON {$CFG->prefix}feed_posts (posted,added);");
        modify_database('', "CREATE TABLE {$CFG->prefix}feed_subscriptions (\r\n                              ident SERIAL PRIMARY KEY,\r\n                              user_id integer NOT NULL default 0,\r\n                              feed_id integer NOT NULL default 0,\r\n                              autopost varchar(3) NOT NULL default 'no' check (autopost in ('yes', 'no')),\r\n                              autopost_tag varchar(128) NOT NULL default ''\r\n                            );");
        modify_database('', "CREATE INDEX {$CFG->prefix}feed_subscriptions_feed_idx ON {$CFG->prefix}feed_subscriptions (feed_id);");
        modify_database('', "CREATE INDEX {$CFG->prefix}feed_subscriptions_user_idx ON {$CFG->prefix}feed_subscriptions (user_id);");
        modify_database('', "CREATE INDEX {$CFG->prefix}feed_subscriptions_autopost_idx ON {$CFG->prefix}feed_subscriptions (autopost);");
        modify_database('', "CREATE TABLE {$CFG->prefix}feeds (\r\n                              ident SERIAL PRIMARY KEY,\r\n                              url varchar(128) NOT NULL default '',\r\n                              feedtype varchar(16) NOT NULL default '',\r\n                              name text NOT NULL,\r\n                              tagline varchar(128) NOT NULL default '',\r\n                              siteurl varchar(128) NOT NULL default '',\r\n                              last_updated integer NOT NULL default 0\r\n                            );");
        modify_database('', "CREATE INDEX {$CFG->prefix}feeds_url_idx ON {$CFG->prefix}feeds (url,feedtype);");
        modify_database('', "CREATE INDEX {$CFG->prefix}feeds_last_updated_idx ON {$CFG->prefix}feeds (last_updated);");
        modify_database('', "CREATE INDEX {$CFG->prefix}feeds_siteurl_idx ON {$CFG->prefix}feeds (siteurl);");
        modify_database('', "CREATE INDEX {$CFG->prefix}feeds_tagline_idx ON {$CFG->prefix}feeds (tagline);");
    }
    if ($oldversion < 2006022100) {
        modify_database('', "CREATE TABLE {$CFG->prefix}friends_requests (\r\n                              ident SERIAL PRIMARY KEY,\r\n                              owner integer NOT NULL default 0,\r\n                              friend integer NOT NULL default 0\r\n                            ) ;");
        modify_database('', "CREATE INDEX {$CFG->prefix}friends_requests_owner_idx ON {$CFG->prefix}friends_requests (owner);");
    }
    if ($oldversion < 2006022200) {
        modify_database('', "INSERT INTO {$CFG->prefix}template_elements (name,content,template_id) VALUES ('pageshell', '<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<title>{{title}}</title>\r\n{{metatags}}\r\n</head>\r\n<body>\r\n<!-- elgg banner and logo -->\r\n<div id=\"container\"><!-- start container -->\r\n    <div id=\"statusbar\"><!-- start statusbar -->\r\n        <div id=\"welcome\"><!-- start welcome -->\r\n            <p>Welcome {{userfullname}}</p>\r\n        </div><!-- end welcome -->\r\n        {{topmenu}}\r\n    </div><!-- end statusbar -->\r\n    <div id=\"header\"><!-- start header -->\r\n        <h1>Elgg</h1>\r\n            <h2>Community learning space</h2>\r\n            <ul id=\"navigation\">\r\n                {{menu}}\r\n            </ul>\r\n    </div><!-- end header -->\r\n    <div id=\"content_holder\"><!-- start contentholder -->\r\n        <div id=\"maincontent_container\"><!-- start main content -->\r\n            {{messageshell}}\r\n            {{mainbody}}\r\n        </div><!-- end main content -->\r\n        <div id=\"sidebar_container\">\r\n            <div id=\"sidebar\"><!-- start sidebar -->\r\n                <ul><!-- open sidebar lists -->\r\n                {{sidebar}}\r\n                </ul>\r\n            </div><!-- end sidebar -->\r\n        </div><!-- end sidebar_container -->\r\n    </div><!-- end contentholder -->\r\n    <div class=\"clearall\" />\r\n    <div id=\"footer\"><!-- start footer -->\r\n               Using the <a href=\"http://www.ifelse.co.uk/gentle-calm\">Gentle Calm theme</a> designed by <a href=\"http://www.ifelse.co.uk\">Phu Ly</a>.<br />\r\n        <a href=\"http://elgg.net\"><img src=\"http://development.apcala.com/_templates/elgg_powered.png\" alt=\"Powered by Elgg\" title=\"Powered by Elgg\" border=\"0\" /></a>\r\n    </div><!-- end footer -->\r\n</div><!-- end container -->\r\n</body>\r\n</html>', 5);");
        modify_database('', "INSERT INTO {$CFG->prefix}template_elements (name,content,template_id) VALUES ( 'css', '/* \r\nTheme Name: Connections\r\nTheme URI: http://wpthemes.info\r\nVersion: 1.0\r\nDescription: A Theme from wpthemes.Info\r\nAuthor: Patricia Muller\r\nAuthor URI: http://www.vanillamist.com/blog/\r\n*/\r\nbody {\r\n    margin:0;\r\n    padding:0;\r\n    font-family: ''Trebuchet MS'',Georgia, Times, Times New Roman, sans-serif;\r\n    font-size: 80%;\r\n    text-align:center;\r\n    color:#29303B;\r\n    line-height:1.3em;\r\n    background: #F3F6ED;\r\n}\r\na {\r\n    color: #909D73;    \r\n    text-decoration:none;\r\n    font-size:100%;\r\n}\r\na:visited {\r\n    color: #8a3207;\r\n}\r\na:hover {\r\n    color: #753206;\r\n    text-decoration:underline;\r\n}\r\n\r\nh1 {\r\n       margin:0px 0px 15px 0px;\r\n    padding:0px;\r\n    font-size:120%;\r\n    font-weight:900;\r\n}\r\n\r\n\r\nh2, h3, h4, h5 {\r\n    margin:0px 0px 5px 0px;\r\n    padding:0px;\r\n    font-size:100%\r\n}\r\n\r\nblockquote {\r\n    /*margin: 15px 30px 0 45px;*/\r\n    padding: 0 0 0 45px;\r\n    background: url(''/_templates/connections/blockquote.gif'') no-repeat left top;\r\n    font-style:italic;\r\n}\r\n\r\n\r\nh3 {\r\n    margin: 0;\r\n    padding: 0;\r\n    font-size:1.3em;\r\n}\r\np {\r\n    margin: 0 0 1em;\r\n    padding: 0;\r\n    line-height: 1.5em;\r\n}\r\nh1, h2, h3, h4 {\r\n    font-family: Georgia, \"Lucida Sans Unicode\", lucida, Verdana, sans-serif;\r\n    font-weight: normal;\r\n    letter-spacing: 1px;\r\n}\r\n\r\ninput, textarea \r\n{\r\n    background: #F3F6ED;\r\n    border: #E1D6C6 1px solid;\r\n}\r\n\r\n#container \r\n{\r\n    background:#fff url(''/_templates/connections/rap.jpg'') center repeat-y;\r\n    width:760px;\r\n    margin:0 auto;\r\n    padding:0px 8px;\r\n    text-align:left;\r\n    font-family: Trebuchet MS,Georgia, Arial, serif;\r\n}\r\n\r\n/*-----------------------------------------\r\nTOP STATUS BAR \r\n-------------------------------------------*/\r\n#header {\r\n    background:#fff url(''/_templates/connections/top.jpg'') no-repeat bottom;     \r\n     height: 183px;\r\n    margin: 0 auto;\r\n    width:760px;\r\n    padding:0;\r\n    border:#fc9 0px solid;\r\n}\r\n\r\n#welcome {\r\n    float: left;\r\n}\r\n\r\n#welcome p{\r\n    font-weight:bold;\r\n       font-size:110%;\r\n    padding:0 0 0 4px;\r\n    margin:0px;\r\n}\r\n\r\n#global_menuoptions {\r\n    text-align: right;\r\n    padding:0 5px 0 0;\r\n    margin:0px;\r\n    float:right;\r\n}\r\n\r\n#global_menuoptions ul {\r\n    margin: 0; \r\n    padding: 0;\r\n}\r\n\r\n#global_menuoptions li {\r\n    margin: 0; \r\n    padding: 0;\r\n    display: inline;\r\n    list-style-type: none;\r\n    border: none;\r\n}\r\n\r\n#global_menuoptions a {\r\n    text-decoration: none;\r\n    font-size:80%;\r\n}\r\n\r\n#global_menuoptions a:hover{\r\n    text-decoration:underline;\r\n}\r\n\r\n    \r\n/*-------------------------------------------------\r\nnavigation\r\n-------------------------------------------------*/\r\n\r\n#navigation {\r\n    height: 21px;\r\n    margin: 0;\r\n    padding-left: 20px;\r\n    text-align:left;\r\n    padding-top:155px;\r\n}\r\n\r\n#navigation li {\r\n    margin: 0; \r\n    padding: 0;\r\n    display: inline;\r\n    list-style-type: none;\r\n    border: none;\r\n}\r\n    \r\n#navigation a:link, #navigation a:visited {\r\n\r\n    background: #524B21; /*#9BBB38;*/\r\n    font-size:85%;\r\n    font-weight: normal;\r\n    padding: 4px 6px;\r\n    margin: 0 2px 0 0;\r\n    border: 0px solid #036;\r\n    border-bottom: #9BBB38;\r\n    text-decoration: none;\r\n    color: #fff;\r\n}\r\n\r\n#navigation a:link.current, #navigation a:visited.current {\r\n    border-bottom: 0px solid #9BBB38;\r\n    background: #F5F5E7;\r\n    color: #9BBB38;\r\n    font-weight: bold;\r\n}\r\n\r\n#navigation a:hover {\r\n    color: #fff;\r\n    background: #000;\r\n}\r\n#navigation li a:hover{\r\n    background:#000;\r\n    }\r\n\r\n#content_holder \r\n{\r\n    margin:0 auto;\r\n    padding:0;\r\n    background:#000 url(''/_templates/connections/content_bg.gif'') repeat;\r\n    width:740px;\r\n}\r\n#maincontent_container {\r\n    width:510px;\r\n    float:left;\r\n    padding:5px;\r\n    margin:0;\r\n    overflow:hidden;\r\n    display:inline;\r\n}\r\n\r\n/*-----------------------------------------------------------------------\r\nDIV''s to help control look and feel - infoholder holds all the profile data\r\nand is always located in within ''maincontentdisplay''\r\n\r\n-------------------------------------------------------------------------*/\r\n\r\n/*------ holds profile data -------*/\r\n.infoholder {\r\n    border:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n    margin:0 0 5px 0;\r\n}\r\n\r\n.infoholder p {\r\n   padding:0 0 0 5px;\r\n}\r\n\r\n.infoholder .fieldname h2 {\r\n          border:0;\r\n          border-bottom:1px;\r\n          border-color:#eee;\r\n          border-style:solid;\r\n          padding:5px;\r\n          color:#666;\r\n          background:#fff;\r\n}   \r\n\r\n.infoholder_twocolumn {\r\n    padding:4px;\r\n    border:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n    margin:0 0 10px 0;\r\n }\r\n\r\n.infoholder_twocolumn .fieldname h3{\r\n    color:#666;\r\n    background:#fff;\r\n    border:0px;\r\n    border-bottom:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n}\r\n\r\n/*----------- holds administration data---------*/\r\n\r\n.admin_datatable {\r\n  border:1px;\r\n  border-color:#eee;\r\n  border-style:solid;\r\n  margin:0 0 5px 0;\r\n}\r\n\r\n.admin_datatable p {\r\n     padding:0px;\r\n     margin:0px;\r\n}\r\n\r\n.admin_datatable a {\r\n   \r\n}\r\n\r\n\r\n.admin_datatable td {\r\n   text-align:left;\r\n}\r\n\r\n.admin_datatable h3{\r\n     color:#666;\r\n     background:#fff;\r\n     font-size:85%;\r\n}\r\n\r\n.admin_datatable h5 {\r\n     padding:0px;\r\n     margin:0px;\r\n}\r\n\r\n/*---- header plus one row of content ------*/\r\n\r\n.databox_vertical {\r\n   border:1px;\r\n   border-style:solid;\r\n   border-color:#DDD;\r\n   margin:0 0 5px 0;\r\n   padding:5px;\r\n }\r\n\r\n .databox_vertical p{\r\n   padding:0px;\r\n   margin:0px;\r\n }\r\n\r\n.databox_vertical .fieldname h3 {\r\n  padding:0px;\r\n  margin:0px;\r\n  font-size:90%;\r\n}\r\n\r\n/*------- holds file content ----*/\r\n\r\n.filetable {\r\n   background-color: #F9F9F9;\r\n   color:#000;\r\n   border:1px;\r\n   border-style:solid;\r\n   border-color:#DDD;\r\n   margin:0 0 5px 0;\r\n   width:100%;\r\n }\r\n\r\n .filetable p{\r\n   padding:0px;\r\n   margin:0px;\r\n   color:#000; /*#1181AA;*/\r\n   background:#fff;\r\n }\r\n\r\n.filetable a{\r\n   \r\n }\r\n\r\n\r\n.filetable table {\r\n    text-align:left;\r\n}\r\n\r\n#edit_files h4 {\r\n     \r\n}\r\n  \r\n\r\n/*------- holds fodler content ------*/\r\n\r\n.foldertable {\r\n   background-color: #F9F9F9;\r\n   color:#000;\r\n   border:1px;\r\n   border-style:solid;\r\n   border-color:#DDD;\r\n   margin:0 0 5px 0;\r\n   width:100%;\r\n }\r\n\r\n.foldertable a{\r\n  \r\n }\r\n\r\n .foldertable p{\r\n   padding:0px;\r\n   margin:0px;\r\n   color:#1181AA;\r\n   background:#fff;\r\n }\r\n\r\n.foldertable table {\r\n    text-align:left;\r\n}\r\n\r\n/*------- holds network data ------*/\r\n\r\n.networktable {\r\n   \r\n}\r\n\r\n#sidebar {\r\n    width:186px;\r\n    float:right;\r\n    padding:0px 8px 10px 8px;\r\n    margin:0;\r\n    font-size:1em;\r\n    color:#333;\r\n    display:inline;\r\n}\r\n\r\n\r\n#header h1 \r\n{\r\n    margin: 0;    \r\n    font-size: 1.6em;    \r\n    padding:10px 20px 0 0;\r\n    text-align:right;    \r\n}\r\n#header h1 a \r\n{\r\n    color:#B5C09D;\r\n    text-decoration:none;\r\n}\r\n#header h1 a:hover \r\n{\r\n    color:#F7F3ED;\r\n}\r\n\r\n#sidebar h2 {\r\n    margin: 10px 0 0 0;\r\n    padding:2px;\r\n    font-size: 90%;\r\n    color: #676E04;\r\n    text-align:center;\r\n    background:url(''/_templates/connections/sidenav_top.jpg'') no-repeat center;\r\n    border:#ccc 0px solid;\r\n    height:22px;\r\n    font-weight:bold;\r\n}\r\n#sidebar ul {\r\n    list-style-type: none;\r\n    padding: 0px;\r\n    margin: 0;\r\n}\r\n\r\n#sidebar ul li ul{\r\n    list-style-type: none;\r\n    padding: 0;\r\n    margin: 0;\r\n    font-size: 0.9em;    \r\n    padding-bottom:3em;\r\n    background:#F3F6ED url(''/_templates/connections/sidenav_bottom.jpg'') no-repeat bottom;\r\n    border:#E1D6c6 1px solid;\r\n    border-top:#f3f6ed 1px solid;\r\n}\r\n\r\n#sidebar ul li ul li{\r\n    margin: 0.1em 0 0 0;\r\n    padding: 2px;    \r\n}\r\n#sidebar li a {\r\n    text-decoration: none;\r\n    border:none;\r\n}\r\n#sidebar li a:link {\r\n    color: #909D73;    \r\n}\r\n#sidebar li a:visited {\r\n    color: #999999;    \r\n}\r\n#sidebar li a:hover, #sidebar li a:active {\r\n    color: #990000;\r\n}\r\n\r\n/*-------------------------------------------\r\nSIDEBAR DISPLAY COMPONENTS \r\n----------------------------------------------*/\r\n\r\n#sidebar_user {\r\n}\r\n\r\n#recent_activity {\r\n}\r\n\r\n#community_owned {\r\n}\r\n\r\n#community_membership {\r\n}\r\n\r\n#sidebar_friends {\r\n}\r\n\r\n#search {\r\n}\r\n\r\n/*--- extra div''s when looking at someone else''s page ---*/\r\n\r\n#sidebar_weblog {\r\n}\r\n\r\n#sidebar_files {\r\n}\r\n\r\n#me {\r\n        padding: 0 3px 3px 3px;\r\n    min-height: 71px;\r\n    font-size: 0.9em;    \r\n    padding-bottom:3em;\r\n    background:#F3F6ED url(''/_templates/connections/sidenav_bottom.jpg'') no-repeat bottom;\r\n    border:#E1D6c6 1px solid;\r\n    border-top:#f3f6ed 1px solid;\r\n}\r\n\r\n#me a {\r\n   \r\n  }\r\n\r\n#me #icon {\r\n   margin:3px 0 0 0;\r\n   float: left; \r\n   width: 70px;\r\n}\r\n\r\n#me #contents {\r\n   margin: 0 0 0 75px;\r\n   text-align: left;\r\n}\r\n\r\n#searchform {\r\n    font-size: 0.9em;    \r\n    padding-bottom:1em;\r\n    background:#F3F6ED;\r\n    border:#E1D6c6 1px solid;\r\n    border-top:#f3f6ed 1px solid;\r\n    text-align:center;\r\n}\r\n\r\n#maincontent_holder ul {\r\n    margin-left: 0;\r\n    padding-left: 45px;\r\n    list-style-type: none;\r\n}\r\n\r\n#maincontent_holder ul li {\r\n    background: url(''img/bullet.gif'') no-repeat 0 7px;\r\n    padding-left: 1.5em;\r\n}\r\n\r\n/*-------------------------------------------\r\n  INDIVIDUAL BLOG POSTS \r\n  -------------------------------------------*/\r\n\r\n\r\n.weblog_posts {\r\n}\r\n\r\n.user {\r\n    float: left;\r\n    margin: 4px;\r\n        padding:0 0 5px 0;\r\n    width: 105px;\r\n    text-align: left;\r\n}\r\n\r\n.entry  \r\n{\r\n    font-size:0.85em;\r\n    font-family: Verdana, Arial, Sans-Serif;\r\n    margin:0 0 30px 0;\r\n    padding:0;\r\n    color:#333;\r\n}\r\n.entry  a\r\n{\r\n    color:#990000;\r\n}\r\n.entry  a:hover \r\n{\r\n    color:#000;\r\n}\r\n\r\n.weblog_title h3 {\r\n    font-family:Georgia, Arial, Serif;\r\n    font-size:1.3em;\r\n    margin:0;\r\n    font-weight:bold;\r\n        text-decoration:none;\r\n    color:#676E04;\r\n    border:0px\r\n    font-size:80%;\r\n        margin: 3px 10px 5px 0;\r\n        padding: 8px 3px;\r\n}\r\n\r\n/* .entry h3 {\r\n    color:#676E04;\r\n    font-family: Georgia,''Lucida sans ms'', Verdana, Arial, Helvetica, sans-serif;\r\n    text-align: center;\r\n    font-size:80%;\r\n    font-weight: bold;\r\n    margin: 3px 10px 5px 0;\r\n    padding: 8px 3px;\r\n    /*background: #E7EBDE;*/\r\n    line-height:1em;\r\n    border:0px;\r\n        text-decoration:none;\r\n} */\r\n\r\n.post {\r\n    padding:10px 0;\r\n    margin:3px 0;\r\n    border-top:#BBC4A3 1px solid;    \r\n    font-family: Georgia, Verdana, Arial, serif;\r\n    font-size:100%;\r\n}\r\n\r\n.info\r\n{\r\n    padding-top:20px;\r\n    background:url(''/_templates/connections/divider.gif'') no-repeat center;\r\n}\r\n\r\n.weblog_dateheader {\r\n    padding: 0px;\r\n    margin: 0px;\r\n    color: #333;\r\n    background:#fff;\r\n    font-weight: normal;\r\n       font-size:90%;\r\n    font-style: italic;\r\n    line-height: 12px;\r\n    border:0px;\r\n    border-bottom: 1px solid #ccc;\r\n}\r\n\r\n#footer {\r\n    margin:0 auto;\r\n    padding: 7px 0;\r\n    border-top:#BBC4A3 1px solid;\r\n    clear: both;\r\n    font-size: 0.8em;\r\n    color: #999;\r\n    text-align:center;\r\n    width:740px;\r\n}\r\n#footer a {\r\nborder:none;\r\ncolor:#7A7636;\r\n}\r\n\r\n.comments {\r\n    font-size:1em;\r\n    font-weight:normal;    \r\n}\r\n#comments\r\n{\r\n    margin:0 0 0 40px;\r\n}\r\n#comments textarea {\r\n    width: 80%;\r\n}\r\n#comments p {\r\n    margin: 0 0 1em;\r\n}\r\n#comments,#respond {\r\n    text-transform: uppercase;\r\n    margin: 3em 0 1em 40px;\r\n    color: #676E04;\r\n    font: 0.9em verdana, helvetica, sans-serif;\r\n}\r\n#comments li \r\n{\r\n    margin:5px 0;\r\n    padding:10px 10px 20px 10px;\r\n    background:#F3F6ED url(_template/connections/comments_bottom.jpg) repeat-x bottom;\r\n    border:#E1D6C6 1px solid;\r\n}\r\n#comments .alt \r\n{\r\n\r\n}\r\n\r\n#global_menuoptions \r\n{\r\n    list-style:none;\r\n    font-size:0.9em;\r\n    margin:0 auto;    \r\n    padding:12px 20px 0 0;\r\n    text-align:right;    \r\n    font-family:Verdana, Arial, Sans-Serif;\r\n}\r\n#global_menuoptions li \r\n{\r\n    list-style:none;\r\n    display:inline;\r\n    padding:0;\r\n    margin:0;\r\n    font-weight:bold;\r\n}\r\n\r\n#global_menuoptions li a:link, #global_menuoptions li a:visited\r\n{\r\n    text-decoration:none;    \r\n    color:#BBC4A3;\r\n}\r\n#global_menuoptions li a:hover, #global_menuoptions li a:active\r\n{\r\n    color:#F7F3ED;    \r\n}\r\n\r\n/*-------------------------------------\r\n  Input forms\r\n--------------------------------------*/\r\n\r\n.textarea{\r\n    border: 1px solid #7F9DB9;\r\n    color:#71717B;\r\n    width: 95%;\r\n       height:200px;\r\n    padding:3px;\r\n    -moz-border-radius: 3px;\r\n}\r\n\r\n.medium_textarea {\r\n   width:95%;\r\n   height:100px;\r\n}\r\n\r\n.small_textarea {\r\n    width:95%;\r\n}\r\n\r\n.keywords_textarea {\r\n    width:95%;\r\n    height:100px;\r\n}', 4);");
        modify_database('', "INSERT INTO {$CFG->prefix}template_elements (name,content,template_id) VALUES ( 'css', '/*\r\n    Theme Name: Gentle Calm\r\n    Theme URI: http://ifelse.co.uk/gentlecalm\r\n    Description: Liquid Serenity\r\n    Version: 1.0\r\n    Author: Phu Ly\r\n    Author URI: http://ifelse.co.uk/\r\n*/\r\n\r\n/************************************************\r\n *    Main structure                                                            *\r\n ************************************************/\r\nbody {\r\n  margin:0px;\r\n  padding:0px;\r\n  text-align:center;\r\n  font:11px \"Lucida Grande\", \"Lucida Sans Unicode\", Verdana, Helvetica, Arial, sans-serif;\r\n    color: #474E44;\r\n    background:#F3F4EC;\r\n}\r\n\r\n/*-------------------------------------------------\r\nSTATUS BAR\r\n-------------------------------------------------*/\r\n\r\n#statusbar {\r\n    padding: 3px 10px 2px 0;\r\n    margin: 0px;\r\n    text-align: bottom;\r\n    height:15px;\r\n}\r\n\r\n\r\n#welcome {\r\n    float: left;\r\n}\r\n\r\n#welcome p{\r\n    font-weight:bold;\r\n       font-size:110%;\r\n    padding:0 0 0 4px;\r\n    margin:0px;\r\n}\r\n\r\n#global_menuoptions {\r\n    text-align: right;\r\n    padding:0 5px 0 0;\r\n    margin:0px;\r\n    float:right;\r\n}\r\n\r\n#global_menuoptions a:hover{\r\n    text-decoration:underline;\r\n}\r\n\r\n#global_menuoptions ul {\r\n    margin: 0; \r\n    padding: 0;\r\n}\r\n\r\n#global_menuoptions li {\r\n    margin: 0; \r\n    padding: 0;\r\n    display: inline;\r\n    list-style-type: none;\r\n    border: none;\r\n}\r\n\r\n#global_menuoptions a {\r\n    text-decoration: none;\r\n}\r\n\r\n#global_menuoptions a:hover{\r\n    text-decoration:underline;\r\n}\r\n\r\n#maincontent_container {\r\n  width:72%;\r\n  float:left;\r\n}\r\n#maincontent_container .col {\r\n    padding-bottom: 0.5em;\r\n    padding-left:2.5em;\r\n    padding-right:8.5em;\r\n    line-height:1.6em;\r\n}\r\n#sidebar {\r\n    padding:0.5em;\r\n    padding-top: 2em;\r\n    clear:right;\r\n    width:25%;\r\n  right:0px;\r\n    float:right;\r\n  font-size:1em; \r\n}\r\n#content_holder {    \r\n width:80%;\r\n text-align:left;\r\n margin-left: auto;\r\n display:block;\r\n margin-right: auto;\r\n padding-bottom:0;\r\n}\r\n\r\n#content_holder:after {\r\n    content: \".\"; \r\n    display: block; \r\n    height: 0; \r\n    clear: both; \r\n    visibility: hidden;\r\n}\r\n#footer{\r\n    border-top:1px solid #324031;\r\n    border-bottom:1px solid #324031;\r\n    color: #eee;\r\n    background: #87a284;\r\n    clear:both;\r\n    padding: 0.8em;\r\n    text-align:center;\r\n    margin-left: auto;\r\n    display:block;\r\n  margin-right: auto;\r\n  font-size: 0.9em;\r\n  margin-top:5em;\r\n}\r\n#footer a{\r\n    color: #fff;\r\n    font-weight:bold;\r\n}\r\na{\r\n    color: #3C657B;\r\n    text-decoration: none;\r\n}\r\na:hover {\r\n    text-decoration:underline;\r\n}\r\n/************************************************\r\n *    Header                                                                            *\r\n ************************************************/\r\n#header {\r\n    padding: 0px;    \r\n    margin-top: 0.3em;\r\n    padding-top:1em;    \r\n    padding-bottom:1em;\r\n    margin-bottom:0px;\r\n    border-bottom: 1px solid #bab1b1;\r\n    background: #CCCFBC;\r\n    text-align:right;\r\n    padding-right:2em;\r\n    padding-left:-.5em;\r\n}\r\n\r\n#header h1{\r\n    padding:0px;\r\n    margin: 0px;\r\n    font-size: 1.6em;\r\n    letter-spacing:0.2em;\r\n}\r\n#header h1 {\r\n    color:#5B7B57;\r\n}\r\n#header h1 a:hover {\r\n    text-decoration:none;\r\n    color: #bb4444;\r\n    \r\n}\r\n#header img {\r\n    border:none;\r\n}\r\n#header h2 {\r\n    margin-bottom:0.3em;\r\n    font-size: 0.8em;\r\n    text-transform:uppercase;\r\n    color:#A37B45;\r\n}\r\n\r\n/*-------------------------------------------------\r\nnavigation\r\n-------------------------------------------------*/\r\n\r\n#navigation {\r\n    height: 21px;\r\n    margin: 0;\r\n    padding: 0 0 0 20px;\r\n    text-align:left;\r\n}\r\n\r\n#navigation li {\r\n    margin: 0; \r\n    padding: 0;\r\n    display: inline;\r\n    list-style-type: none;\r\n    border: none;\r\n}\r\n    \r\n#navigation a:link, #navigation a:visited {\r\n\r\n    background: #524B21; /*#9BBB38;*/\r\n    font-size:85%;\r\n    font-weight: normal;\r\n    padding: 4px 6px;\r\n    margin: 0 2px 0 0;\r\n    border: 0px solid #036;\r\n    border-bottom: #9BBB38;\r\n    text-decoration: none;\r\n    color: #fff;\r\n}\r\n\r\n#navigation a:link.current, #navigation a:visited.current {\r\n    border-bottom: 0px solid #9BBB38;\r\n    background: #F5F5E7;\r\n    color: #9BBB38;\r\n    font-weight: bold;\r\n}\r\n\r\n#navigation a:hover {\r\n    color: #fff;\r\n    background: #000;\r\n}\r\n#navigation li a:hover{\r\n    background:#000;\r\n    }\r\n\r\n/************************************************\r\n *    Content                                                                            *\r\n ************************************************/\r\nh1, h2, h3, h4 {\r\n    font-family:\"Century Gothic\", \"Lucida Grande\", \"Lucida Sans Unicode\", Verdana, Helvetica, Arial, sans-serif;\r\n}\r\nh1 {\r\n  font-size:130%;\r\n  padding:10px 0 0 0;\r\n }\r\nh3 {\r\n  font-size:100%;\r\n }\r\n\r\nh4 {\r\n  font-size:100%;\r\n }\r\n\r\nh2 {\r\n    font-size: 1.2em;\r\n    margin-bottom:0.5em;\r\n}\r\nh2.entrydate{\r\n    margin-bottom:0.3em;\r\n    font-size: 1.8em;\r\n    font-weight:normal;\r\n    color:#86942A;\r\n    text-transform:uppercase;\r\n}\r\n.entrymeta{\r\n    font-weight:bold;\r\n    color:#99A879;\r\n}\r\nh3.entrytitle a{\r\n    color: #507642;\r\n}\r\nh3.weblog_title{\r\n    margin-top:0px;\r\n    margin-bottom:0.1em;\r\n    font-size: 1.8em;\r\n}\r\n\r\n.user {\r\n    float: left;\r\n    margin: 4px;\r\n        padding:0 0 5px 0;\r\n    width: 105px;\r\n    text-align: left;\r\n}\r\n\r\n.post p {\r\n    margin-top:0.8em;\r\n    margin-bottom:1.6em;\r\n}\r\n.weblog_posts{\r\n    padding-bottom: 2em;\r\n    font-family:\"Trebuchet MS\",\"Lucida Grande\", \"Lucida Sans Unicode\", Verdana, Helvetica, Arial, sans-serif;\r\n}\r\n/************************************************\r\n *    Navigation Sidebar                                                    *\r\n ************************************************/\r\nul {\r\n margin:0 0 1em 0;\r\n padding-left:0px;\r\n list-style-type:none;\r\n}\r\n/************************************************\r\n *    Comments                                                    *\r\n ************************************************/\r\nh2#comments{\r\n    text-align:center;\r\n    border-top:1px solid #9ba1aa;\r\n    background:#E2ECD5;\r\n    padding:0.7em;\r\n    border-bottom:1px solid #9ba1aa;\r\n    margin-bottom:1em;\r\n    margin-top:8em;\r\n}\r\nol#commentlist {\r\n    margin-top:0px;\r\n    padding: 0.5em;\r\n    margin-left: 0px;\r\n    color: #9b9b9b;\r\n    list-style-type: none;\r\n    font-size:0.9em;\r\n}\r\n#comments li  p{\r\n    padding: 0px;\r\n    margin: 0px;\r\n}\r\n.commentname {\r\n    float: left;\r\n    margin: 0;\r\n    padding: 0 0 0.2em 0;\r\n}\r\n.commentinfo{\r\n    width: 20em;\r\n    float: right;\r\n    text-align: right;\r\n}\r\n.commenttext {\r\n    clear: both;\r\n    padding-top: 0px;\r\n    margin-top: 0px;\r\n    margin-bottom: 3em;\r\n    border-top: 1px solid #ebebeb;\r\n    line-height:1.2em;\r\n    color: #5b5b5b;\r\n}\r\n#commentsformheader{\r\n    padding-left:1.5em;\r\n    font-size: 1.4em;\r\n}\r\n#commentsform{\r\n    margin-top:none;\r\n    text-align:center;\r\n    border:1px solid #ddd;\r\n    background:#ecefdf;\r\n    padding:0em 1em;\r\n}\r\n#commentsform form{\r\n    text-align:left;\r\n    margin:0px;\r\n}\r\n#commentsform p{\r\n    margin:0.5em;\r\n}\r\n#commentsform form textarea{\r\n    width:100%;\r\n}\r\n/************************************************\r\n *    Extra                                                                                *\r\n ************************************************/\r\ncode{\r\n    font-family: ''lucida console'', ''Courier New'', monospace;\r\n    font-size: 0.8em;\r\n    display:block;\r\n    padding:0.5em;\r\n    background-color: #E5EaE4;\r\n    border: 1px solid #d2d8d1;\r\n}\r\ninput[type=\"text\"], textarea {\r\n    padding:0.3em;\r\n    border: 1px solid #CCCFBC;\r\n    color: #656F5C;\r\n    -moz-border-radius: 0.5em;\r\n}\r\ninput[type=\"submit\"]{\r\n    padding:0.2em;\r\n    font-size: 1.25em;\r\n    border: 1px solid #CCCFBC;\r\n    color: #353F2f;\r\n    background: #fefff8;\r\n    -moz-border-radius: 0.5em;\r\n}\r\nblockquote {\r\n    border-left: 3px solid #686868;\r\n    color: #888;\r\n    padding-left: 0.8em;\r\n    margin-left: 2.5em;\r\n}\r\na img {\r\n    border:none;\r\n}\r\n.imgborder img{\r\n    border: 1px solid #87a284;\r\n    background:#CCCFBC;\r\n    padding:0.3em;\r\n}\r\n.imgborder{\r\n    text-align: center;\r\n}\r\n\r\n#system_message{ \r\n    border:1px solid #5B7B57;\r\n    background:#CCCFBC;\r\n    margin:20px 0 0 0;\r\n}\r\n\r\n#system_message p{\r\n   padding:0px;\r\n   margin:2px;\r\n }\r\n\r\n /*-------------------------------------\r\n  Input forms\r\n--------------------------------------*/\r\n\r\n.textarea{\r\n    border: 1px solid #7F9DB9;\r\n    color:#71717B;\r\n    width: 95%;\r\n       height:200px;\r\n    padding:3px;\r\n    -moz-border-radius: 3px;\r\n}\r\n\r\n.medium_textarea {\r\n   width:95%;\r\n   height:100px;\r\n}\r\n\r\n.small_textarea {\r\n    width:95%;\r\n}\r\n\r\n.keywords_textarea {\r\n    width:95%;\r\n    height:100px;\r\n}\r\n\r\n/*-----------------------------------------------------------------------\r\nDIV''s to help control look and feel - infoholder holds all the profile data\r\nand is always located in within ''maincontentdisplay''\r\n\r\n-------------------------------------------------------------------------*/\r\n\r\n/*------ holds profile data -------*/\r\n.infoholder {\r\n    border:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n    margin:0 0 5px 0;\r\n}\r\n\r\n.infoholder p {\r\n   padding:0 0 0 5px;\r\n}\r\n\r\n.infoholder .fieldname h2 {\r\n          border:0;\r\n          border-bottom:1px;\r\n          border-color:#eee;\r\n          border-style:solid;\r\n          padding:5px;\r\n}   \r\n\r\n.infoholder_twocolumn {\r\n    padding:4px;\r\n    border:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n    margin:0 0 10px 0;\r\n }\r\n\r\n.infoholder_twocolumn .fieldname h3{\r\n    border:0px;\r\n    border-bottom:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n}', 5);");
        modify_database('', "INSERT INTO {$CFG->prefix}template_elements  (name,content,template_id) VALUES ( 'pageshell', '<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<title>{{title}}</title>\r\n{{metatags}}\r\n</head>\r\n<body>\r\n <!-- elgg banner and logo -->\r\n<div id=\"container\"><!-- start container -->\r\n<div id=\"header\"><!-- start header -->\r\n             {{topmenu}}\r\n        <ul id=\"navigation\">\r\n          {{menu}}\r\n         </ul>\r\n</div><!-- end header -->\r\n<div id=\"content_holder\"><!-- start contentholder -->\r\n<div id=\"maincontent_container\"><!-- start main content -->\r\n        {{messageshell}}\r\n      {{mainbody}}\r\n</div><!-- end main content -->\r\n<div id=\"sidebar_container\">\r\n<div id=\"sidebar\"><!-- start sidebar -->\r\n    <ul><!-- open sidebar lists -->\r\n        {{sidebar}}\r\n    </ul>\r\n</div><!-- end sidebar -->\r\n</div>\r\n</div><!-- end contentholder -->\r\n<div class=\"clearall\" />\r\n <div id=\"footer\"><!-- start footer -->\r\n        <a href=\"http://elgg.net\"><img src=\"/_templates/elgg_powered.png\" border=\"0\"></a>\r\n </div><!-- end footer -->\r\n</div><!-- end container -->\r\n </body>\r\n </html>', 4);");
        modify_database('', "INSERT INTO {$CFG->prefix}template_elements  (name,content,template_id) VALUES ( 'css', '/*\r\nTheme Name: Northern-Web-Coders\r\nTheme URI: http://www.northern-web-coders.de/\r\nDescription: Northern-Web-Coders Theme\r\nVersion: 1.0\r\n\r\nAuthor: Kai Ackermann\r\n*/\r\n\r\nbody\r\n{\r\nbackground: #d8d8d3;\r\nfont-family: Lucida Grande, Verdana, sans-serif;\r\nmargin: 0;\r\npadding: 0;\r\nfont-size:80%;\r\ntext-align: center;\r\n}\r\n\r\na\r\n{\r\nfont-size:100%;\r\ncolor: #495865;\r\n}\r\n\r\na:hover\r\n{\r\ncolor: #6F6F6F;\r\n}\r\n\r\nh2, h3, h4, h5 {\r\n    margin:0px 0px 5px 0px;\r\n    padding:0px;\r\n    font-size:100%\r\n}\r\n\r\n#container\r\n{\r\nbackground: #FFFFFF;\r\nmargin: 0 auto 0 auto;\r\nwidth: 769px;\r\ntext-align: left;\r\nborder: 2px solid #5F707A;\r\n}\r\n\r\n/*-----------------------------------------\r\nSTATUS BAR \r\n-------------------------------------------*/\r\n\r\n#statusbar {\r\n    padding: 3px 5px 0 0;\r\n    margin: 0px;\r\n    height:16px;\r\n    background:#eee;\r\n    color: #333;\r\n    font-size:80%;\r\n}\r\n\r\n#statusbar a {\r\n    color: #666;\r\n    background:#eee;\r\n}\r\n\r\n#welcome {\r\n    float: left;\r\n}\r\n\r\n#welcome p{\r\n    font-weight:bold;\r\n    padding:0 0 0 4px;\r\n    margin:0px;\r\n}\r\n\r\n#global_menuoptions {\r\n    text-align: right;\r\n    padding:0px;\r\n    margin:0px;\r\n    float:right;\r\n}\r\n\r\n#global_menuoptions ul {\r\n    margin: 0; \r\n    padding: 0;\r\n}\r\n\r\n#global_menuoptions li {\r\n    margin: 0; \r\n    padding: 0;\r\n    display: inline;\r\n    list-style-type: none;\r\n    border: none;\r\n}\r\n\r\n#global_menuoptions a {\r\n    text-decoration: none;\r\n}\r\n\r\n#global_menuoptions a:hover{\r\n    text-decoration:underline;\r\n}\r\n\r\n/*--------------------------------------------\r\n  Header\r\n  -------------------------------------------*/\r\n\r\n#header\r\n{\r\nbackground: url(/_templates/northern/totems_2.jpg);\r\nwidth: 769px;\r\nheight: 200px;\r\nmargin: 0;\r\npadding: 0;\r\ntext-align: right;\r\n}\r\n\r\n#header h1 {\r\n    padding:0 5px 0 5px;\r\n    margin:0px;\r\n    color:#fff;\r\n    }\r\n\r\n#header h2 {\r\n    padding:0 5px 0 5px;\r\n    margin:0px;\r\n    color:#fff;\r\n    }\r\n\r\n/*--------------------------------------------\r\nNAVIGATION \r\n----------------------------------------------*/\r\n\r\n#navigation ul\r\n{\r\npadding: 0;\r\nmargin: 0;\r\nbackground: #5F707A;\r\nborder-top: 1px solid #DFDFDF;\r\nborder-bottom: 0px solid #DFDFDF;\r\nfloat: left;\r\nwidth: 769px;\r\nfont-family: arial, helvetica, sans-serif;\r\n}\r\n\r\n\r\n\r\n#navigation ul li { display: inline; }\r\n\r\n#navigation ul li a\r\n{\r\npadding: 10px 14px 11px 14px;\r\nbackground: #9C9D95;\r\ncolor: #ffffff;\r\ntext-decoration: none;\r\nfont-weight: bold;\r\nfloat: left;\r\nfont-size:85%;\r\nborder-right: 1px solid #FFFFFF;\r\n}\r\n\r\n#navigation ul li a:hover\r\n{\r\ncolor: #990000;\r\nbackground: #C9C0B0;\r\n}\r\n\r\n#navigation a:link.current, #navigation a:visited.current\r\n{\r\npadding: 10px 14px 11px 14px;\r\nbackground: #C9C0B0;\r\ncolor: #990000;\r\ntext-decoration: none;\r\nfont-weight: bold;\r\nfloat: left;\r\nborder-right: 1px solid #DFDFDF;\r\n}\r\n\r\n#navigation a:link.current, #navigation a:visited.current a:hover\r\n{\r\nbackground: #6F6F6F;\r\n}\r\n\r\n\r\n/*-------------------------------------------------\r\nHOLDS THE MAIN CONTENT E.G. BLOG, PROFILE ETC \r\n----------------------------------------------------*/\r\n\r\n#maincontent_container\r\n{\r\nposition: relative;\r\nleft: 20px;\r\nfloat: left;\r\npadding: 0;\r\nwidth: 68%;\r\ncolor: #495865;\r\nfont-size:85%;\r\n}\r\n\r\n/*#maincontent_container h2\r\n{\r\nborder-bottom: 1px solid #6F6F6F;\r\ncolor: #5F707A;\r\nmargin: 20px 0 5px 0;\r\npadding: 0 0 3px 3px;\r\ntext-align: right;\r\n}*/\r\n\r\n/*-------------------------------------------------------------\r\nTHIS DISPLAYS THE ACTUAL CONTENT WITHIN maincontent_container\r\n--------------------------------------------------------------*/\r\n\r\n#maincontent_display h1 {\r\n    padding-bottom: 2px;\r\n    border-bottom: 1px solid #666;\r\n    margin: 10px 0 0 0;\r\n    font-size:120%;\r\n    color: #666;\r\n}\r\n\r\n#maincontent_display #sub_menu {\r\n    font-family: verdana;\r\n    padding: 2px 0 0 0;\r\n    margin: 0 0 15px 0;\r\n    font-weight: normal;\r\n    color: #990000;\r\n}\r\n\r\n#maincontent_display #sub_menu a {\r\n    font-weight:bold;\r\n    margin:0px;\r\n    padding:0px;\r\n    color: #990000;\r\n}\r\n\r\n#maincontent_display #sub_menu a:hover {\r\n    text-decoration: underline;\r\n}\r\n\r\n#maincontent_display #sub_menu p {\r\n      margin:0px;\r\n      padding:0px;\r\n}\r\n\r\n/*-----------------------------------------\r\n  SIDEBAR\r\n  ----------------------------------------*/\r\n\r\n#sidebar\r\n{\r\nclear: right;\r\nfloat: left;\r\nposition: relative;\r\ntop: 10px;\r\nleft: 50px;\r\nmargin: 0 0 10px 0;\r\nwidth: 30%;\r\nfont-size:90%;\r\n}\r\n\r\n#sidebar ul\r\n{\r\nlist-style-type: none;\r\nmargin: 10px 0;\r\npadding: 0;\r\n}\r\n\r\n#sidebar ul li\r\n{\r\ncolor: #5F5F5F;\r\nmargin: 0;\r\npadding: 0;\r\n}\r\n\r\n#sidebar ul li p\r\n{\r\nwidth: 190px;\r\nfont-weight: bold;\r\n}\r\n\r\n#sidebar ul li h2\r\n{\r\nborder-bottom: 1px solid;\r\nwidth: 190px;\r\nfont-weight: bold;\r\nmargin: 0;\r\npadding: 0;\r\n}\r\n\r\n#sidebar ul li ul\r\n{\r\n/*margin: 5px 0 15px 10px;*/\r\n}\r\n\r\n#sidebar ul li ul li\r\n{\r\nfont-weight: normal;\r\nmargin: 0 0 3px 0;\r\npadding: 0;\r\nline-height: 12px\r\n}\r\n\r\n#sidebar ul li#winamp ul li\r\n{\r\nwidth: 190px\r\n}\r\n\r\n#sidebar ul li ul li a\r\n{\r\ncolor: #5F5F5F;\r\ntext-decoration: none;\r\n}\r\n\r\n#sidebar ul li ul li a:hover\r\n{\r\nfont-weight: bold;\r\ntext-decoration: none\r\n}\r\n\r\n/*-------------------------------------------\r\nSIDEBAR DISPLAY COMPONENTS \r\n----------------------------------------------*/\r\n\r\n#sidebar_user {\r\n}\r\n\r\n#recent_activity {\r\n}\r\n\r\n#community_owned {\r\n}\r\n\r\n#community_membership {\r\n}\r\n\r\n#sidebar_friends {\r\n}\r\n\r\n#search {\r\n}\r\n\r\n#me {\r\n     padding: 3px;\r\n     margin:0;\r\n}\r\n\r\n#me p{\r\n   font-weight:normal;\r\n   font-weight: normal;\r\n   margin:0;\r\n }\r\n\r\n#sidebar #sidebar_user p {\r\n  padding:4px 0 0 0;\r\n  font-weight: normal;\r\n }\r\n\r\n\r\n/*--- extra div''s when looking at someone else''s page ---*/\r\n\r\n#sidebar_weblog {\r\n}\r\n\r\n#sidebar_files {\r\n}\r\n\r\n#searchform\r\n{\r\nmargin: 2px 0 15px 0;\r\n}\r\n\r\n#searchform input\r\n{\r\nbackground: #FFFFFF;\r\nborder: 1px solid #6F6F6F;\r\nfont-size: 11px;\r\nmargin-top: 3px;\r\npadding: 2px;\r\n}\r\n\r\n/*--------------------------------------\r\n  FOOTER\r\n  --------------------------------------*/\r\n\r\n#footer\r\n{\r\ncolor: #FFFFFF;\r\nbackground: #5F707A;\r\nborder-top: 1px solid #DFDFDF;\r\nclear: both;\r\nmargin: 0 auto 0 auto;\r\npadding: 16px 0 17px 0;\r\ntext-align: center;\r\nwidth: 769px;\r\n}\r\n\r\n#footer a\r\n{\r\ncolor: #ffffff\r\n}\r\n\r\n/*-------------------------------------\r\n  Blog classes\r\n  ------------------------------------*/\r\n\r\n.weblog_posts {\r\n    margin:0 0 30px 0;\r\n}\r\n\r\n.weblog_posts .entry h3 {\r\n   color:#1181AA;\r\n   background:#fff;\r\n   padding: 0 0 10px 110px;\r\n}\r\n\r\n.user {\r\n    float: left;\r\n    margin: 0px;\r\n    /* padding: 0.3em 2em 2em 0; */\r\n    width: 105px;\r\n    text-align: left;\r\n}\r\n\r\n.post {\r\n    margin: 0 0 0 77px;\r\n    padding:0 0 0 40px;\r\n    font-family: arial;\r\n}\r\n\r\n.post p {\r\n    padding: 0;\r\n    margin: 3px 0 10px 0;\r\n    line-height: 16px;\r\n}\r\n\r\n.post ol, .post ul {\r\n    margin: 3px 0 10px 0;\r\n    padding: 0;\r\n}\r\n\r\n.post li {\r\n    margin: 0 0 0 30px;\r\n    line-height: 16px;\r\n}\r\n\r\n.post ul li {\r\n    list-style-type: square;\r\n}\r\n\r\n.post .blog_edit_functions p {\r\n      \r\n}\r\n\r\n.post .blog_edit_functions a {\r\n      \r\n}\r\n\r\n.post .weblog_keywords p {\r\n     \r\n}\r\n\r\n.post .weblog_keywords a {\r\n     \r\n}\r\n\r\n.info p {\r\n    padding: 0px;\r\n    margin: 0 0 5px 0;\r\n    color: #666;\r\n    background:#fff;\r\n    font-family: verdana;\r\n    font-weight: normal;\r\n    line-height: 14px;\r\n    text-align: left;\r\n}\r\n\r\n.info p a {\r\n    color: #666;\r\n    background:#fff;\r\n    text-decoration: none;\r\n    border-bottom: 1px dotted #666;\r\n    padding-bottom: 0;\r\n}\r\n\r\n#comments ol, #comments ul {\r\n    margin: 3px 0 10px 0;\r\n    padding: 0;\r\n}\r\n\r\n#comments li {\r\n    margin: 0 0 0 30px;\r\n    line-height: 16px;\r\n}\r\n\r\n#comments ul li {\r\n    list-style-type: square;\r\n}\r\n\r\n#comments h4 {\r\n    color:#1181AA;\r\n}\r\n\r\n.weblog_dateheader {\r\n    padding: 0px;\r\n    margin: 0 0 5px 0;\r\n    color: #333;\r\n       background:#fff;\r\n    font-weight: normal;\r\n    font-style: italic;\r\n    line-height: 12px;\r\n       border:0px;\r\n    border-bottom: 1px solid #ccc;\r\n}\r\n\r\n.clearing{clear:both;}\r\n\r\n.post p, post li\r\n{\r\nfont-family: Lucida Grande, Verdana, sans-serif;\r\nline-height: 130%;\r\n}\r\n\r\n.post blockquote\r\n{\r\nbackground: #fef7e9;\r\nborder: 1px solid #e6ddcb;\r\nborder-left: 2px solid #6F6F6F;\r\nfont-family: Georgia, Times New Roman, serif;\r\npadding: 4px 4px 4px 7px;\r\n}\r\n\r\n/*-------------------------------------\r\n  Input forms\r\n--------------------------------------*/\r\n\r\n.textarea {\r\n    border: 1px solid #7F9DB9;\r\n    color:#71717B;\r\n    width: 95%;\r\n    height:200px;\r\n    padding:3px;\r\n}\r\n\r\n.medium_textarea {\r\n    width:95%;\r\n    height:100px;\r\n}\r\n\r\n.small_textarea {\r\n    width:95%;\r\n}\r\n\r\n.keywords_textarea {\r\n    width:95%;\r\n    height:100px;\r\n}\r\n\r\n/*----- System Messages ------*/\r\n\r\n#system_message { \r\n    border:1px solid #D3322A;\r\n    background:#F7DAD8;\r\n    padding:3px 50px;\r\n    margin:5px 0 0 0;    \r\n}\r\n\r\n#system_message p{\r\n   padding:0px;\r\n   margin:2px;\r\n }\r\n\r\n/*-----------------------------------------------------------------------\r\nDIV''s to help control look and feel - infoholder holds all the profile data\r\nand is always located in within ''maincontentdisplay''\r\n\r\n-------------------------------------------------------------------------*/\r\n\r\n/*------ holds profile data -------*/\r\n.infoholder {\r\n    border:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n    margin:0 0 5px 0;\r\n}\r\n\r\n.infoholder p {\r\n   padding:0 0 0 5px;\r\n}\r\n\r\n.infoholder .fieldname {\r\n        /*  border:0;\r\n          margin:0;\r\n          border-bottom:1px;\r\n          border-color:#eee;\r\n          border-style:solid;\r\n          padding:5px;\r\n          color:#666;\r\n          background:#fff; */\r\ncolor: #5F707A;\r\nmargin: 0px 0 5px 0;\r\npadding: 0 0 0px 3px;\r\ntext-align: left;\r\nborder:0px;\r\n}   \r\n\r\n.infoholder_twocolumn {\r\n    padding:4px;\r\n    border:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n    margin:0 0 10px 0;\r\n }\r\n\r\n.infoholder_twocolumn .fieldname h3{\r\n    color:#666;\r\n    background:#fff;\r\n    border:0px;\r\n    border-bottom:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n}\r\n\r\n/*----------- holds administration data---------*/\r\n\r\n.admin_datatable {\r\n  border:1px;\r\n  border-color:#eee;\r\n  border-style:solid;\r\n  margin:0 0 5px 0;\r\n}\r\n\r\n.admin_datatable p {\r\n     padding:0px;\r\n     margin:0px;\r\n}\r\n\r\n.admin_datatable a {\r\n   \r\n}\r\n\r\n\r\n.admin_datatable td {\r\n   text-align:left;\r\n}\r\n\r\n.admin_datatable h3{\r\n     color:#666;\r\n     background:#fff;\r\n}\r\n\r\n.admin_datatable h4 {\r\n}\r\n\r\n/*---- header plus one row of content ------*/\r\n\r\n.databox_vertical {\r\n   background-color: #F9F9F9;\r\n   color:#000;\r\n   border:1px;\r\n   border-style:solid;\r\n   border-color:#DDD;\r\n   margin:0 0 5px 0;\r\n   padding:5px;\r\n }\r\n\r\n .databox_vertical p{\r\n   padding:0px;\r\n   margin:0px;\r\n   color:#1181AA;\r\n   background:#fff;\r\n }\r\n\r\n.databox_vertical .fieldname h3 {\r\n  padding:0px;\r\n  margin:0px;\r\n  color:#1181AA;\r\n  background:#fff;\r\n}\r\n\r\n/*------- holds file content ----*/\r\n\r\n.filetable {\r\n   background-color: #F9F9F9;\r\n   color:#000;\r\n   border:1px;\r\n   border-style:solid;\r\n   border-color:#DDD;\r\n   margin:0 0 5px 0;\r\n   width:100%;\r\n }\r\n\r\n .filetable p{\r\n   padding:0px;\r\n   margin:0px;\r\n   color:#000; /*#1181AA;*/\r\n   background:#fff;\r\n }\r\n\r\n.filetable a{\r\n   \r\n }\r\n\r\n\r\n.filetable table {\r\n    text-align:left;\r\n}\r\n\r\n#edit_files h4 {\r\n     \r\n}\r\n  \r\n\r\n/*------- holds fodler content ------*/\r\n\r\n.foldertable {\r\n   background-color: #F9F9F9;\r\n   color:#000;\r\n   border:1px;\r\n   border-style:solid;\r\n   border-color:#DDD;\r\n   margin:0 0 5px 0;\r\n   width:100%;\r\n }\r\n\r\n.foldertable a{\r\n  \r\n }\r\n\r\n .foldertable p{\r\n   padding:0px;\r\n   margin:0px;\r\n   color:#1181AA;\r\n   background:#fff;\r\n }\r\n\r\n.foldertable table {\r\n    text-align:left;\r\n}\r\n\r\n/*------- holds network data ------*/\r\n\r\n.networktable {\r\n   \r\n}\r\n\r\n/*---------------------------------------------\r\n  Your Resources\r\n-----------------------------------------------*/\r\n\r\n.feeds {\r\n  border-bottom: 1px dotted #aaaaaa;\r\n  background: transparent url(\"//_templates/sunflower.jpg\") bottom right no-repeat;\r\n}\r\n\r\n.feed_content a {\r\n    color:black;\r\n    border:0px;\r\n}\r\n\r\n.feed_content a:hover{\r\n    background:#fff;\r\n    }\r\n\r\n.feed_content img {\r\n  border: 1px solid #666666;\r\n  padding:5px;\r\n}\r\n\r\n.feed_content h3 {\r\n      padding:0 0 4px 0;\r\n      margin:0px;\r\n}\r\n\r\n.feed_content h3 a{\r\n     color:black;\r\n     border:0px;\r\n     border-bottom:1px;\r\n     border-style:dotted;\r\n     border-color:grey;\r\n}\r\n\r\n.feed_content h3 a:hover{\r\n    background:#FCD63F;\r\n       color:#000;\r\n    }\r\n\r\n.feed_date {\r\n    line-height: 21px;\r\n  font-weight: bold;\r\n  padding: 5px 10px 4px 5px;\r\n  margin:0 0 10px 0;\r\n  background-color: #D0DEDF;\r\n  color:#000;\r\n  text-decoration:none;\r\n}\r\n\r\n.via a {\r\n    color:#1181AA;\r\n    background:#fff;\r\n    border:0px;\r\n}\r\n\r\n.via a:hover {\r\n    background:#ffc;\r\n    color:#1181AA;\r\n}', 3);");
        modify_database('', "INSERT INTO {$CFG->prefix}template_elements (name,content,template_id) VALUES ( 'pageshell', '<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<title>{{title}}</title>\r\n{{metatags}}\r\n</head>\r\n<body>\r\n <!-- elgg banner and logo -->\r\n<div id=\"container\"><!-- start container -->\r\n<div id=\"statusbar\"><!-- start statusbar -->\r\n    <div id=\"welcome\"><!-- start welcome -->\r\n        <p>Welcome {{userfullname}}</p>\r\n    </div><!-- end welcome -->\r\n         {{topmenu}}\r\n</div><!-- end statusbar -->\r\n<div id=\"header\"><!-- start header -->\r\n             <h1>Elgg</h1>\r\n               <h2>Community learning space</h2>\r\n</div><!-- end header -->\r\n<div id=\"navigation\">\r\n   <ul>\r\n       {{menu}}\r\n   </ul>\r\n</div>\r\n<div id=\"content_holder\"><!-- start contentholder -->\r\n<div id=\"maincontent_container\"><!-- start main content -->\r\n        {{messageshell}}\r\n      {{mainbody}}\r\n</div><!-- end main content -->\r\n<div id=\"sidebar_container\">\r\n<div id=\"sidebar\"><!-- start sidebar -->\r\n    <ul><!-- open sidebar lists -->\r\n        {{sidebar}}\r\n    </ul>\r\n</div><!-- end sidebar -->\r\n</div>\r\n</div><!-- end contentholder -->\r\n<div class=\"clearall\" />\r\n <div id=\"footer\"><!-- start footer -->\r\n        <a href=\"http://elgg.net\"><img src=\"/_templates/elgg_powered.png\" border=\"0\"></a>\r\n </div><!-- end footer -->\r\n</div><!-- end container -->\r\n </body>\r\n </html>', 3);");
        modify_database('', "INSERT INTO {$CFG->prefix}templates VALUES (4, 'Connections', 1, 'yes');");
        modify_database('', "INSERT INTO {$CFG->prefix}templates VALUES (3, 'Northern', 1, 'yes');");
        modify_database('', "INSERT INTO {$CFG->prefix}templates VALUES (5, 'Gentle Calm', 1, 'yes');");
        // because this is postgres, we need to reset the sequence since we're hard coding the ids
        // that were used in the template_elements table. yuk.
        modify_database('', "SELECT setval('{$CFG->prefix}templates_ident_seq', (select max(ident) from {$CFG->prefix}templates))");
    }
    if ($oldversion < 2006022300) {
        // Display errors
        error_reporting(E_ERROR | E_WARNING | E_PARSE);
        // Set time limit to 60 minutes
        @set_time_limit(3600);
        if ($users = get_records('users')) {
            foreach ($users as $user) {
                $ident = $user->ident;
                echo "<p>" . sprintf(gettext("Publishing RSS for user %d"), $ident) . "</p>";
                $rssresult = run("weblogs:rss:publish", array($ident, false));
                $rssresult = run("files:rss:publish", array($ident, false));
                $rssresult = run("profile:rss:publish", array($ident, false));
            }
        }
    }
    if ($oldversion < 2006022301) {
        // This handles upgrades from _files/data to $CFG->dataroot too...
        // Alter file repository to remove path information
        echo "<h2>" . gettext("Adjusting file repository information") . "</h2>";
        // Get all files with path in the location
        $tostrip = $CFG->dirroot . '_files/data/';
        if ($files = get_records_select('files', 'location LIKE ?', array($tostrip . '%'))) {
            foreach ($files as $file) {
                $ident = $file->ident;
                $filename = str_replace($tostrip, "files/", $file->location);
                set_field('files', 'location', $filename, 'ident', $ident);
                echo "<p>" . sprintf(gettext("Updating file %d: %s"), $ident, $filename) . "</p>";
            }
        }
        // Get all files that start with _files
        $tostrip = '_files/data/';
        if ($files = get_records_select('files', 'location LIKE ?', array($tostrip . '%'))) {
            foreach ($files as $file) {
                $ident = $file->ident;
                $filename = str_replace($tostrip, "files/", $file->location);
                set_field('files', 'location', $filename, 'ident', $ident);
                echo "<p>" . sprintf(gettext("Updating file %d: %s"), $ident, $filename) . "</p>";
            }
        }
        // copy the files across.
        if ($dir = opendir($CFG->dirroot . '_files/data/')) {
            while ($file = readdir($dir)) {
                if ($file == "." || $file == ".." || $file == '.htaccess') {
                    continue;
                }
                copy_file($CFG->dirroot . "_files/data/{$file}", $CFG->dataroot . "files/{$file}");
            }
        }
        // now the profile images.. this is harder.
        if ($icons = get_records_sql("SELECT i.*,u.username FROM {$CFG->prefix}icons i JOIN {$CFG->prefix}users u ON i.owner = u.ident")) {
            foreach ($icons as $icon) {
                $upload_folder = $textlib->substr($icon->username, 0, 1);
                $fromfile = $CFG->dirroot . '_icons/data/' . $icon->filename;
                $tofile = $CFG->dataroot . 'icons/' . $upload_folder . '/' . $icon->username . '/' . $icon->filename;
                copy_file($fromfile, $tofile);
            }
        }
    }
    if ($oldversion < 2006052100) {
        // add some missing indexes
        modify_database('', 'CREATE INDEX {$CFG->prefix}tags_access_idx ON {$CFG->prefix}tags (access)');
    }
    if ($oldversion < 2006052200) {
        // homogenise access field, shortest one was vc16, longest vc255
        table_column('file_folders', 'access', 'access', 'varchar', 20, '', 'PUBLIC');
        table_column('files', 'access', 'access', 'varchar', 20, '', 'PUBLIC');
        table_column('groups', 'access', 'access', 'varchar', 20, '', 'PUBLIC');
        table_column('profile_data', 'access', 'access', 'varchar', 20, '', 'PUBLIC');
        table_column('tags', 'access', 'access', 'varchar', 20, '', 'PUBLIC');
        table_column('weblog_posts', 'access', 'access', 'varchar', 20, '', 'PUBLIC');
    }
    if ($oldversion < 2006052300) {
        // shorten another keyword field
        table_column('tags', 'tagtype', 'tagtype', 'varchar', 20);
    }
    if ($oldversion < 2006052400) {
        // purge owner=0 watchlist entries from watchlist-on-comment bug
        delete_records('weblog_watchlist', 'owner', 0);
    }
    if ($oldversion < 2006060600) {
        modify_database('', 'CREATE INDEX {$CFG->prefix}feed_posts_added_idx ON {$CFG->prefix}feed_posts (added)');
    }
    if ($oldversion < 2006061600) {
        modify_database('', 'DROP INDEX {$CFG->prefix}feed_posts_url_idx');
        table_column('feed_posts', 'url', 'url', 'varchar', 255, '', '');
    }
    if ($oldversion < 2006061700) {
        modify_database('', 'DROP INDEX {$CFG->prefix}weblog_watchlist_owner_idx');
        modify_database('', 'CREATE INDEX {$CFG->prefix}weblog_watchlist_owner_idx ON {$CFG->prefix}weblog_watchlist (owner)');
        modify_database('', 'CREATE INDEX {$CFG->prefix}weblog_watchlist_weblog_post_idx ON {$CFG->prefix}weblog_watchlist (weblog_post)');
    }
    if ($oldversion < 2006081000) {
        // Add old Elgg default template as Classic Elgg
        $template = new StdClass();
        $template->name = "Classic Elgg";
        $template->owner = 1;
        $template->public = "yes";
        $template_id = insert_record('templates', $template);
        execute_sql("INSERT INTO `{$CFG->prefix}template_elements` (`name`,`content`,`template_id`) VALUES ('pageshell', '<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<title>{{title}}</title>\r\n{{metatags}}\r\n</head>\r\n<body>\r\n<!-- elgg banner and logo -->\r\n<div id=\"container\"><!-- start container -->\r\n    <div id=\"statusbar\"><!-- start statusbar -->\r\n        <div id=\"welcome\"><!-- start welcome -->\r\n            <p>Welcome {{userfullname}}</p>\r\n        </div><!-- end welcome -->\r\n        {{topmenu}}\r\n    </div><!-- end statusbar -->\r\n    <div id=\"header\"><!-- start header -->\r\n        <h1>{{sitename}}</h1>\r\n            <h2>Personal Learning Landscape</h2>\r\n            <ul id=\"navigation\">\r\n                {{menu}}\r\n            </ul>\r\n    </div><!-- end header -->\r\n    <div id=\"content_holder\"><!-- start contentholder -->\r\n        <div id=\"maincontent_container\"><!-- start main content -->\r\n            {{messageshell}}\r\n            {{mainbody}}\r\n        </div><!-- end main content -->\r\n        <div id=\"sidebar_container\">\r\n            <div id=\"sidebar\"><!-- start sidebar -->\r\n                <ul><!-- open sidebar lists -->\r\n                {{sidebar}}\r\n                </ul>\r\n            </div><!-- end sidebar -->\r\n        </div><!-- end sidebar_container -->\r\n    </div><!-- end contentholder -->\r\n    <div class=\"clearall\" />\r\n    <div id=\"footer\"><!-- start footer -->\r\n        <a href=\"http://elgg.net/\"><img src=\"{{url}}_templates/elgg_powered.png\" alt=\"Powered by Elgg\" title=\"Powered by Elgg\" border=\"0\" /></a>\r\n    </div><!-- end footer -->\r\n</div><!-- end container -->\r\n</body>\r\n</html>', {$template_id})");
        execute_sql("INSERT INTO `{$CFG->prefix}template_elements` (`name`,`content`,`template_id`) VALUES ('css', '/*\r\n    CSS for Elgg Classic default\r\n*/\r\n\r\nbody{\r\n    padding: 0;\r\n    font-family: arial, verdana, helvetica, sans-serif;\r\n    color: #333;\r\n       background: #eee;\r\n    width:97%;\r\n    margin:auto;\r\n       font-size:80%;\r\n    }\r\n\r\na {\r\n        text-decoration: none;\r\n        color: #7289AF;\r\n        background: #fff;\r\n        font-family:verdana, arial, helvetica, sans-serif;\r\n        font-size:100%;\r\n\r\n    }\r\n\r\np {\r\n    font-size: 100%;    \r\n}\r\n\r\nh1 {\r\n       margin:0px 0px 15px 0px;\r\n    padding:0px;\r\n    font-size:120%;\r\n    font-weight:900;\r\n}\r\n\r\n\r\nh2 {\r\n    margin:0px 0px 5px 0px;\r\n    padding:0px;\r\n    font-size:100%\r\n}\r\n\r\n\r\nh3 {\r\n    margin:0px 0px 5px 0px;\r\n    padding:0px;\r\n    font-size:100%\r\n}\r\n\r\nh4 {\r\n    margin:0px 0px 5px 0px;\r\n    padding:0px;\r\n    font-size:100%\r\n}\r\n\r\nh5 {\r\n    margin:0px 0px 5px 0px;\r\n    padding:0px;\r\n    color:#1181AA;\r\n       background:#fff;\r\n    font-size:100%\r\n}\r\n\r\nblockquote {\r\n    padding: 0 1pc 1pc 1pc;\r\n    border: 1px solid #ddd;\r\n    background-color: #F0F0F0;\r\n       color:#000;\r\n    background-image: url(\"{{url}}_templates/double-quotes.png\");\r\n    background-repeat: no-repeat;\r\n    background-position: -10px -7px;\r\n}\r\n\r\n/*---------------------------------------\r\nWraps the entire page \r\n-----------------------------------------*/\r\n\r\n#container {\r\n    margin: 0 auto;\r\n    text-align: center;\r\n    width: 100%;\r\n    min-width: 750px;\r\n    }\r\n\r\n\r\n/*-----------------------------------------\r\nTOP STATUS BAR \r\n-------------------------------------------*/\r\n\r\n#statusbar {\r\n    padding: 3px 0px 2px 0;\r\n    margin: 0px;\r\n    height:19px;\r\n    background:#eee;\r\n    color: #333;\r\n   font-size:85%;\r\n}\r\n\r\n#statusbar a {\r\n    color: #666;\r\n    background:#eee;\r\n}\r\n\r\n#welcome {\r\n    float: left;\r\n}\r\n\r\n#welcome p{\r\n    font-weight:bold;\r\n       font-size:110%;\r\n    padding:0 0 0 4px;\r\n    margin:0px;\r\n}\r\n\r\n#global_menuoptions {\r\n    text-align: right;\r\n    padding:0px;\r\n    margin:0px;\r\n    float:right;\r\n}\r\n\r\n#global_menuoptions ul {\r\n    margin: 0; \r\n    padding: 0;\r\n}\r\n\r\n#global_menuoptions li {\r\n    margin: 0; \r\n    padding: 0 8px 0 0;\r\n    display: inline;\r\n    list-style-type: none;\r\n    border: none;\r\n}\r\n\r\n#global_menuoptions a {\r\n    text-decoration: none;\r\n}\r\n\r\n#global_menuoptions a:hover{\r\n    text-decoration:underline;\r\n}\r\n\r\n\r\n/*---------------------------------------------\r\nHEADER \r\n------------------------------------------------*/\r\n\r\n#header {\r\n    width: 100%;\r\n    background: #1181AA;\r\n    color:#fff;\r\n    border: 1px solid #ccc;\r\n    border-bottom: none;\r\n    padding: 0px;\r\n    margin: 0px;\r\n    text-align: left;\r\n    }\r\n\r\n#header h1 {\r\n    padding: 0 0 4px 0;\r\n    margin: 7px 0 0 20px;\r\n    color: #FAC83D;\r\n    background: #1181AA;\r\n    text-align: left;\r\n       font-size:140%;\r\n       font-weight:normal;\r\n    }    \r\n\r\n#header h2 {\r\n    padding: 0 0 7px 0;\r\n    margin: 0 0 0 20px;\r\n    font-weight: normal;\r\n    color: #fff;\r\n    background: #1181AA;\r\n    border: none;\r\n    font-family: \"Lucida Grande\", arial, sans-serif;\r\n       font-size:120%;\r\n    }    \r\n\r\n/*--------------------------------------------\r\nNAVIGATION \r\n----------------------------------------------*/\r\n\r\n#navigation {\r\n    height: 19px;\r\n    margin: 0;\r\n    padding-left: 20px;\r\n    text-align:left;\r\n}\r\n\r\n#navigation li {\r\n    margin: 0; \r\n    padding: 0;\r\n    display: inline;\r\n    list-style-type: none;\r\n    border: none;\r\n}\r\n\r\n#navigation a:link, #navigation a:visited {\r\n\r\n    background: #eaeac7;\r\n    font-weight: normal;\r\n    padding: 5px;\r\n    margin: 0 2px 0 0;\r\n    border: 0px solid #036;\r\n    text-decoration: none;\r\n    color: #333;\r\n       font-size:85%;\r\n}\r\n\r\n#navigation a:link.selected, #navigation a:visited.selected {\r\n    border-bottom: 1px solid #fff;\r\n    background: #fff;\r\n    color: #393;\r\n    font-weight: bold;\r\n}\r\n\r\n#navigation a:hover {\r\n    color: #000;\r\n    background: #ffc;\r\n}\r\n\r\n#navigation li a:hover{\r\n    background:#FCD63F;\r\n       color: #000;\r\n    }\r\n\r\n\r\n/*-----------------------------------------------\r\nSITE CONTENT WRAPPER \r\n-------------------------------------------------*/\r\n\r\n#content_holder {\r\n    margin: 0;\r\n    padding: 20px 0;\r\n    width: 100%;\r\n    text-align: left;\r\n    float: left;\r\n    border: 1px solid #ccc;\r\n    border-top: none;\r\n    background-color: #fff;\r\n    color:#000;\r\n}\r\n\r\n/*-------------------------------------------------\r\nHOLDS THE MAIN CONTENT E.G. BLOG, PROFILE ETC \r\n----------------------------------------------------*/\r\n\r\n#maincontent_container {\r\n    margin: 0;\r\n    padding: 5px;\r\n    text-align: left;\r\n    width: 65%;\r\n    float: left;\r\n    }\r\n\r\n#maincontent_container h2 {\r\n    padding-bottom: 5px;\r\n    padding-top: 5px;\r\n    margin: 0;\r\n    /*color: #666;\r\n    background-color:#fff;*/\r\n}\r\n\r\n#maincontent_container h1 {\r\n    padding-bottom: 5px;\r\n    padding-top: 5px;\r\n    margin: 0;\r\n    color: #666;\r\n    background-color:#fff;\r\n}\r\n\r\n#maincontent_container h3 {\r\n    padding-bottom: 5px;\r\n    padding-top: 5px;\r\n    margin: 0;\r\n    /*color: #666;\r\n    background-color:#fff;*/\r\n}\r\n\r\n#Footer .performanceinfo {\r\n    color: #000;\r\n}\r\n\r\n/*-------------------------------------------------------------\r\nTHIS DISPLAYS THE ACTUAL CONTENT WITHIN maincontent_container\r\n--------------------------------------------------------------*/\r\n\r\n#maincontent_display {\r\n    margin: 0;\r\n    padding: 0 0 20px 20px;\r\n    width: 100%;\r\n    text-align: left;\r\n    float: left;\r\n    background-color: #fff;\r\n    color:#000;\r\n}\r\n\r\n#maincontent_display h1 {\r\n    padding-bottom: 2px;\r\n    border-bottom: 1px solid #666;\r\n    margin: 0;\r\n    font-size:130%;\r\n    color: #666;\r\n    background-color: #fff;\r\n}\r\n\r\n/*---- Sub Menu attributes ----*/\r\n\r\n#maincontent_display #sub_menu {\r\n    font-family: verdana;\r\n    padding: 0px;\r\n    margin: 5px 0 20px 0;\r\n    color: #000;\r\n    background-color:#fff;\r\n}\r\n\r\n#maincontent_display #sub_menu a {\r\n    font-weight:bold;\r\n    margin:0px;\r\n    padding:0px;\r\n}\r\n\r\n#maincontent_display #sub_menu a:hover {\r\n    text-decoration: underline;\r\n}\r\n\r\n#maincontent_display #sub_menu p {\r\n      margin:0px;\r\n      padding:0px;\r\n}\r\n\r\n/*-----------------------------------------------------------------------\r\nDIV''s to help control look and feel - infoholder holds all the profile data\r\nand is always located in within ''maincontentdisplay''\r\n\r\n-------------------------------------------------------------------------*/\r\n\r\n/*------ holds profile data -------*/\r\n.infoholder {\r\n    border:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n    margin:0 0 5px 0;\r\n}\r\n\r\n.infoholder p {\r\n   padding:0 0 0 5px;\r\n}\r\n\r\n.infoholder .fieldname h2 {\r\n          border:0;\r\n          border-bottom:1px;\r\n          border-color:#eee;\r\n          border-style:solid;\r\n          padding:5px;\r\n          color:#666;\r\n          background:#fff;\r\n}   \r\n\r\n.infoholder_twocolumn {\r\n    padding:4px;\r\n    border:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n    margin:0 0 10px 0;\r\n }\r\n\r\n.infoholder_twocolumn .fieldname h3{\r\n    color:#666;\r\n    background:#fff;\r\n    border:0px;\r\n    border-bottom:1px;\r\n    border-color:#eee;\r\n    border-style:solid;\r\n}\r\n\r\n/*----------- holds administration data---------*/\r\n\r\n.admin_datatable {\r\n  border:1px;\r\n  border-color:#eee;\r\n  border-style:solid;\r\n  margin:0 0 5px 0;\r\n}\r\n\r\n.admin_datatable p {\r\n     padding:0px;\r\n     margin:0px;\r\n}\r\n\r\n.admin_datatable a {\r\n   \r\n}\r\n\r\n\r\n.admin_datatable td {\r\n   text-align:left;\r\n}\r\n\r\n.admin_datatable h3{\r\n     color:#666;\r\n     background:#fff;\r\n}\r\n\r\n.admin_datatable h4 {\r\n}\r\n\r\n/*---- header plus one row of content ------*/\r\n\r\n.databox_vertical {\r\n   background-color: #F9F9F9;\r\n   color:#000;\r\n   border:1px;\r\n   border-style:solid;\r\n   border-color:#DDD;\r\n   margin:0 0 5px 0;\r\n   padding:5px;\r\n }\r\n\r\n .databox_vertical p{\r\n   padding:0px;\r\n   margin:0px;\r\n   color:#1181AA;\r\n   background:#fff;\r\n }\r\n\r\n.databox_vertical .fieldname h3 {\r\n  padding:0px;\r\n  margin:0px;\r\n  color:#1181AA;\r\n  background:#fff;\r\n}\r\n\r\n/*------- holds file content ----*/\r\n\r\n.filetable {\r\n   background-color: #F9F9F9;\r\n   color:#000;\r\n   border:1px;\r\n   border-style:solid;\r\n   border-color:#DDD;\r\n   margin:0 0 5px 0;\r\n   width:100%;\r\n }\r\n\r\n .filetable p{\r\n   padding:0px;\r\n   margin:0px;\r\n   color:#000; /*#1181AA;*/\r\n   background:#fff;\r\n }\r\n\r\n.filetable a{\r\n   \r\n }\r\n\r\n\r\n.filetable table {\r\n    text-align:left;\r\n}\r\n\r\n#edit_files h4 {\r\n     \r\n}\r\n  \r\n\r\n/*------- holds fodler content ------*/\r\n\r\n.foldertable {\r\n   background-color: #F9F9F9;\r\n   color:#000;\r\n   border:1px;\r\n   border-style:solid;\r\n   border-color:#DDD;\r\n   margin:0 0 5px 0;\r\n   width:100%;\r\n }\r\n\r\n.foldertable a{\r\n  \r\n }\r\n\r\n .foldertable p{\r\n   padding:0px;\r\n   margin:0px;\r\n   color:#1181AA;\r\n   background:#fff;\r\n }\r\n\r\n.foldertable table {\r\n    text-align:left;\r\n}\r\n\r\n/*------- holds network data ------*/\r\n\r\n.networktable {\r\n   \r\n}\r\n\r\n\r\n/*-------------------------------------------\r\nSIDEBAR CONTAINER \r\n---------------------------------------------*/\r\n\r\n#sidebar_container {\r\n    margin: 0px;\r\n    text-align: left;\r\n    float: right;\r\n    width: 26%;\r\n       min-width: 100px;\r\n    border-left: 1px dotted #dcdcdc;\r\n    padding: 0 10px;\r\n  /*width:220px;*/\r\n      /*overflow: hidden;*/\r\n    }\r\n\r\n/*-----------------------------------------\r\nACTUAL SIDEBAR CONTENT\r\n-------------------------------------------*/\r\n\r\n#sidebar {\r\nmin-width: 100px;\r\n    padding: 0 10px;\r\n    }\r\n\r\n#sidebar ul {\r\n    margin: 0;\r\n    padding: 0;\r\n    list-style: none;\r\n}\r\n\r\n#sidebar ul li ul {\r\n    \r\n}\r\n\r\n#sidebar ul li {\r\n    margin: 10px 0;\r\n    padding-left: 5px;\r\n}\r\n\r\n\r\n#sidebar h2 {\r\n    font-family: \"Lucida Grande\", arial, sans-serif;\r\n    font-weight: bold;\r\n    color: #333;\r\n       background:#fff;\r\n    margin: 20px 0 3px 0;\r\n    padding: 0;\r\n    border: none;\r\n}\r\n\r\n#sidebar h2 {\r\n    border-bottom: 1px solid #666; \r\n}\r\n\r\n/*-------------------------------------------\r\nSIDEBAR DISPLAY COMPONENTS \r\n----------------------------------------------*/\r\n\r\n#sidebar_user {\r\n}\r\n\r\n#recent_activity {\r\n}\r\n\r\n#community_owned {\r\n}\r\n\r\n#community_membership {\r\n}\r\n\r\n#sidebar_friends {\r\n}\r\n\r\n#search {\r\n}\r\n\r\n#me {\r\n        padding: 0 3px 3px 3px;\r\n     background-color:#FAC83D;\r\n     min-height: 71px;\r\n}\r\n\r\n#me a {\r\n   background-color:#FAC83D;\r\n   color: #7289AF;\r\n  }\r\n\r\n#me #icon {\r\n   margin:3px 0 0 0;\r\n   float: left; \r\n   width: 70px;\r\n}\r\n\r\n#me #contents {\r\n   margin: 0 0 0 75px;\r\n   text-align: left;\r\n}\r\n\r\n\r\n/*--- extra div''s when looking at someone else''s page ---*/\r\n\r\n#sidebar_weblog {\r\n}\r\n\r\n#sidebar_files {\r\n}\r\n\r\n\r\n\r\n/*------------------------------------------\r\n  FOOTER \r\n  ------------------------------------------*/\r\n\r\n#footer {\r\n    margin: 10px 0 20px 20px;\r\n    text-align: center;\r\n    padding:5px;\r\n}\r\n\r\n#footer a:link, #footer a:visited {\r\n    text-align:right;\r\n}\r\n\r\n\r\n/*-------------------------------------------\r\n  INDIVIDUAL BLOG POSTS \r\n  -------------------------------------------*/\r\n\r\n\r\n/*------ wraps all blog components ------*/\r\n\r\n.weblog_posts {\r\n}\r\n\r\n.weblog_posts .entry h3 {\r\n   color:#1181AA;\r\n   background:#fff;\r\n   padding: 0 0 10px 110px;\r\n}\r\n\r\n.user {\r\n    float: left;\r\n    margin: 0px;\r\n    padding:0 0 5px 0;\r\n    width: 105px;\r\n    text-align: left;\r\n}\r\n\r\n.user a {\r\n    \r\n}\r\n\r\n.post {\r\n    margin: 0 0 10px 0;\r\n    padding: 0 0 20px 110px;\r\n    font-family: arial;\r\n}\r\n\r\n.post p {\r\n    padding: 0;\r\n    margin: 3px 0 10px 0;\r\n    line-height: 16px;\r\n}\r\n\r\n.post ol, .post ul {\r\n    margin: 3px 0 10px 0;\r\n    padding: 0;\r\n}\r\n\r\n.post li {\r\n    margin: 0 0 0 30px;\r\n    line-height: 16px;\r\n}\r\n\r\n.post ul li {\r\n    list-style-type: square;\r\n}\r\n\r\n.post .blog_edit_functions p {\r\n      \r\n}\r\n\r\n.post .blog_edit_functions a {\r\n      \r\n}\r\n\r\n.post .weblog_keywords p {\r\n     \r\n}\r\n\r\n.post .weblog_keywords a {\r\n     \r\n}\r\n\r\n.info p {\r\n    padding: 0px;\r\n    margin: 0 0 5px 0;\r\n    color: #666;\r\n    background:#fff;\r\n    font-family: verdana;\r\n    font-weight: normal;\r\n    line-height: 14px;\r\n    text-align: left;\r\n}\r\n\r\n.info p a {\r\n    color: #666;\r\n    background:#fff;\r\n    text-decoration: none;\r\n    border-bottom: 1px dotted #666;\r\n    padding-bottom: 0;\r\n}\r\n\r\n#comments ol, #comments ul {\r\n    margin: 3px 0 10px 0;\r\n    padding: 0;\r\n}\r\n\r\n#comments li {\r\n    margin: 10px 0 10px 30px;\r\n    line-height: 16px;\r\n}\r\n\r\n#comments ul li {\r\n    list-style-type: square;\r\n}\r\n\r\n#comments h4 {\r\n    color:#1181AA;\r\n}\r\n\r\n.comment_owner {\r\n    border:1px solid #eee;\r\n\tbackground:#f2f7fb;\r\n\tpadding:5px;\r\n\theight:50px;\r\n}\r\n\r\n.comment_owner img {\r\n   margin:0px 5px 0px 0px;\r\n}\r\n\r\n.comment_owner a {\r\n   background:#f2f7fb;\r\n}\r\n\r\n.comment_owner p {\r\n  padding:0;\r\n  margin:0 0 10px 0;\r\n}\r\n\r\n.weblog_dateheader {\r\n    padding: 0px;\r\n    margin: 0 0 5px 0;\r\n    color: #333;\r\n       background:#fff;\r\n    font-weight: normal;\r\n    font-style: italic;\r\n    line-height: 12px;\r\n       border:0px;\r\n    border-bottom: 1px solid #ccc;\r\n}\r\n\r\n.clearing{clear:both;}\r\n\r\n/*---------------------------------------------\r\n  Your Resources\r\n-----------------------------------------------*/\r\n\r\n.feeds {\r\n  border-bottom: 1px dotted #aaaaaa;\r\n  background: transparent url(\"{{url}}_templates/sunflower.jpg\") bottom right no-repeat;\r\n}\r\n\r\n.feed_content a {\r\n    color:black;\r\n    border:0px;\r\n    border-bottom:1px;\r\n    border-style:dotted;\r\n    border-color:#eee;\r\n}\r\n\r\n.feed_content a:hover{\r\n    background:#fff;\r\n    }\r\n\r\n.feed_content img {\r\n  border: 1px solid #666666;\r\n  padding:5px;\r\n}\r\n\r\n.feed_content h3 {\r\n      padding:0 0 4px 0;\r\n      margin:0px;\r\n}\r\n\r\n.feed_content h3 a{\r\n     color:black;\r\n     border:0px;\r\n     border-bottom:1px;\r\n     border-style:dotted;\r\n     border-color:#eee;\r\n}\r\n\r\n.feed_content h3 a:hover{\r\n    background:#FCD63F;\r\n       color:#000;\r\n    }\r\n\r\n.feed_date h2 {\r\n    font-size:13px;\r\n    line-height: 21px;\r\n  font-weight: bold;\r\n  padding: 5px 10px 5px 5px;\r\n  background: #D0DEDF;\r\n  color:#000;\r\n  text-decoration:none;\r\n}\r\n\r\n.via a {\r\n    font-size:80%;\r\n    color:#1181AA;\r\n    background:#fff;\r\n    border:0px;\r\n    border-bottom:1px;\r\n    border-style:dashed;\r\n    border-color:#ebebeb;\r\n}\r\n\r\n.via a:hover {\r\n    background:#ffc;\r\n    color:#1181AA;\r\n}\r\n\r\n\r\n/*---------------------------------------\r\n  SYSTEM MESSAGES \r\n  ---------------------------------------*/\r\n\r\n#system_message{ \r\n    border:1px solid #D3322A;\r\n    background:#F7DAD8;\r\n    color:#000;\r\n    padding:3px 50px;\r\n    margin:0 0 0 20px;\r\n}\r\n\r\n#system_message p{\r\n   padding:0px;\r\n   margin:2px;\r\n }\r\n\r\n\r\n/* -------------  help files -------------*/\r\n\r\n.helpfiles ul {\r\n    font-family: arial, helvetica, Tahoma;\r\n    color: #000000;\r\n    background:#fff;\r\n}\r\n\r\n.helpfiles h4 {\r\n \r\n}\r\n\r\n/*------ site news for home.php ---------*/\r\n\r\n.sitenews {\r\n     background:#ebebeb;\r\n     color:#000;\r\n}\r\n\r\n.sitenews h2 {\r\n     background:#1181AA;\r\n     color:#FAC83D;\r\n     padding:0 0 5px 0;\r\n}\r\n\r\n/*-------------------------------------\r\n  Input forms\r\n--------------------------------------*/\r\n\r\n.textarea {\r\n    border: 1px solid #7F9DB9;\r\n    color:#71717B;\r\n    width: 95%;\r\n       height:200px;\r\n    padding:3px;\r\n}\r\n\r\n.medium_textarea {\r\n   width:95%;\r\n   height:100px;\r\n}\r\n\r\n.small_textarea {\r\n    width:95%;\r\n}\r\n\r\n.keywords_textarea {\r\n    width:95%;\r\n    height:100px;\r\n}\r\n\r\n\r\n/*--------------------------------------\r\n   MISC \r\n--------------------------------------*/\r\n\r\n.clearall {\r\n    padding: 0px;\r\n    clear: both;\r\n    font-size: 0px;\r\n    }\r\n\r\n.flagcontent {\r\n   background:#eee;\r\n   color:#000;\r\n   border:1px;\r\n   border-color:#000;\r\n   border-style:solid;\r\n   padding:3px;\r\n}\r\n\r\n.flagcontent h5 {\r\n  background:#eee;\r\n  color:#1181AA;\r\n}', {$template_id})");
        // Clean up slashes
        execute_sql("update {$CFG->prefix}weblog_posts set title = replace(title,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}weblog_posts set title = replace(title,'\\\"','\"')");
        execute_sql("update {$CFG->prefix}weblog_posts set body = replace(body,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}weblog_posts set body = replace(body,'\\\"','\"')");
        execute_sql("update {$CFG->prefix}weblog_comments set body = replace(body,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}weblog_comments set body = replace(body,'\\\"','\"')");
        execute_sql("update {$CFG->prefix}weblog_comments set postedname = replace(postedname,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}weblog_comments set postedname = replace(postedname,'\\\"','\"')");
        execute_sql("update {$CFG->prefix}tags set tag = replace(tag,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}tags set tag = replace(tag,'\\\"','\"')");
        execute_sql("update {$CFG->prefix}files set title = replace(title,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}files set title = replace(title,'\\\"','\"')");
        execute_sql("update {$CFG->prefix}files set description = replace(description,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}files set description = replace(description,'\\\"','\"')");
        execute_sql("update {$CFG->prefix}file_folders set name = replace(name,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}file_folders set name = replace(name,'\\\"','\"')");
        execute_sql("update {$CFG->prefix}profile_data set value = replace(value,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}profile_data set value = replace(value,'\\\"','\"')");
        execute_sql("update {$CFG->prefix}users set name = replace(name,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}users set name = replace(name,'\\\"','\"')");
        execute_sql("update {$CFG->prefix}groups set name = replace(name,'\\\\'','\\'')");
        execute_sql("update {$CFG->prefix}groups set name = replace(name,'\\\"','\"')");
    }
    return $result;
}
示例#30
-1
function forum_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG, $db;
    if ($oldversion < 2002073008) {
        execute_sql("DELETE FROM modules WHERE name = 'discuss' ");
        execute_sql("ALTER TABLE `discuss` RENAME `forum_discussions` ");
        execute_sql("ALTER TABLE `discuss_posts` RENAME `forum_posts` ");
        execute_sql("ALTER TABLE `discuss_ratings` RENAME `forum_ratings` ");
        execute_sql("ALTER TABLE `forum` CHANGE `intro` `intro` TEXT NOT NULL ");
        execute_sql("ALTER TABLE `forum` ADD `forcesubscribe` TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL AFTER `assessed`");
        execute_sql("ALTER TABLE `forum` CHANGE `type` `type` ENUM( 'single', 'news', 'social', 'general', \n                             'eachuser', 'teacher' ) DEFAULT 'general' NOT NULL ");
        execute_sql("ALTER TABLE `forum_posts` CHANGE `discuss` `discussion` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ");
        execute_sql("INSERT INTO log_display (module, action, mtable, field) VALUES ('forum', 'add', 'forum', 'name') ");
        execute_sql("INSERT INTO log_display (module, action, mtable, field) VALUES ('forum', 'add discussion', 'forum_discussions', 'name') ");
        execute_sql("INSERT INTO log_display (module, action, mtable, field) VALUES ('forum', 'add post', 'forum_posts', 'subject') ");
        execute_sql("INSERT INTO log_display (module, action, mtable, field) VALUES ('forum', 'update post', 'forum_posts', 'subject') ");
        execute_sql("INSERT INTO log_display (module, action, mtable, field) VALUES ('forum', 'view discussion', 'forum_discussions', 'name') ");
        execute_sql("DELETE FROM log_display WHERE module = 'discuss' ");
        execute_sql("UPDATE log SET action = 'view discussion' WHERE module = 'discuss' AND action = 'view' ");
        execute_sql("UPDATE log SET action = 'add discussion' WHERE module = 'discuss' AND action = 'add' ");
        execute_sql("UPDATE log SET module = 'forum' WHERE module = 'discuss' ");
        notify("Renamed all the old discuss tables (now part of forum) and created new forum_types");
    }
    if ($oldversion < 2002080100) {
        execute_sql("INSERT INTO log_display (module, action, mtable, field) VALUES ('forum', 'view subscribers', 'forum', 'name') ");
        execute_sql("INSERT INTO log_display (module, action, mtable, field) VALUES ('forum', 'update', 'forum', 'name') ");
    }
    if ($oldversion < 2002082900) {
        execute_sql(" ALTER TABLE `forum_posts` ADD `attachment` VARCHAR(100) NOT NULL AFTER `message` ");
    }
    if ($oldversion < 2002091000) {
        if (!execute_sql(" ALTER TABLE `forum_posts` ADD `attachment` VARCHAR(100) NOT NULL AFTER `message` ")) {
            echo "<p>Don't worry about this error - your server already had this upgrade applied";
        }
    }
    if ($oldversion < 2002100300) {
        execute_sql(" ALTER TABLE `forum` CHANGE `open` `open` TINYINT(2) UNSIGNED DEFAULT '2' NOT NULL ");
        execute_sql(" UPDATE `forum` SET `open` = 2 WHERE `open` = 1 ");
        execute_sql(" UPDATE `forum` SET `open` = 1 WHERE `open` = 0 ");
    }
    if ($oldversion < 2002101001) {
        execute_sql(" ALTER TABLE `forum_posts` ADD `format` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `message` ");
    }
    if ($oldversion < 2002122300) {
        execute_sql("ALTER TABLE `forum_posts` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
        execute_sql("ALTER TABLE `forum_ratings` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
        execute_sql("ALTER TABLE `forum_subscriptions` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
    }
    if ($oldversion < 2003042402) {
        execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('forum', 'move discussion', 'forum_discussions', 'name')");
    }
    if ($oldversion < 2003081403) {
        table_column("forum", "assessed", "assessed", "integer", "10", "unsigned", "0");
    }
    if ($oldversion < 2003082500) {
        table_column("forum", "", "assesstimestart", "integer", "10", "unsigned", "0", "", "assessed");
        table_column("forum", "", "assesstimefinish", "integer", "10", "unsigned", "0", "", "assesstimestart");
    }
    if ($oldversion < 2003082502) {
        table_column("forum", "scale", "scale", "integer", "10", "", "0");
        execute_sql("UPDATE {$CFG->prefix}forum SET scale = (- scale)");
    }
    if ($oldversion < 2003100600) {
        table_column("forum", "", "maxbytes", "integer", "10", "unsigned", "0", "", "scale");
    }
    if ($oldversion < 2004010100) {
        table_column("forum", "", "assesspublic", "integer", "4", "unsigned", "0", "", "assessed");
    }
    if ($oldversion < 2004011404) {
        table_column("forum_discussions", "", "userid", "integer", "10", "unsigned", "0", "", "firstpost");
        if ($discussions = get_records_sql("SELECT d.id, p.userid\n                                            FROM {$CFG->prefix}forum_discussions as d, \n                                                 {$CFG->prefix}forum_posts as p\n                                           WHERE d.firstpost = p.id")) {
            foreach ($discussions as $discussion) {
                update_record("forum_discussions", $discussion);
            }
        }
    }
    if ($oldversion < 2004012200) {
        table_column("forum_discussions", "", "groupid", "integer", "10", "unsigned", "0", "", "userid");
    }
    if ($oldversion < 2004013000) {
        table_column("forum_posts", "mailed", "mailed", "tinyint", "2");
    }
    if ($oldversion < 2004020600) {
        table_column("forum_discussions", "", "usermodified", "integer", "10", "unsigned", "0", "", "timemodified");
    }
    if ($oldversion < 2004050300) {
        table_column("forum", "", "rsstype", "tinyint", "2", "unsigned", "0", "", "forcesubscribe");
        table_column("forum", "", "rssarticles", "tinyint", "2", "unsigned", "0", "", "rsstype");
        set_config("forum_enablerssfeeds", 0);
    }
    if ($oldversion < 2004060100) {
        modify_database('', "CREATE TABLE `prefix_forum_queue` (\n                                `id` int(11) unsigned NOT NULL auto_increment,\n                                `userid` int(11) unsigned default 0 NOT NULL,\n                                `discussionid` int(11) unsigned default 0 NOT NULL,\n                                `postid` int(11) unsigned default 0 NOT NULL,\n                                PRIMARY KEY  (`id`),\n                                KEY `user` (userid),\n                                KEY `post` (postid)\n                              ) TYPE=MyISAM COMMENT='For keeping track of posts that will be mailed in digest form';");
    }
    if ($oldversion < 2004070700) {
        // This may be redoing it from STABLE but that's OK
        table_column("forum_discussions", "groupid", "groupid", "integer", "10", "", "0", "");
    }
    if ($oldversion < 2004111700) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` DROP INDEX {$CFG->prefix}forum_posts_parent_idx;", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` DROP INDEX {$CFG->prefix}forum_posts_discussion_idx;", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` DROP INDEX {$CFG->prefix}forum_posts_userid_idx;", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` DROP INDEX {$CFG->prefix}forum_discussions_forum_idx;", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` DROP INDEX {$CFG->prefix}forum_discussions_userid_idx;", false);
        execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` ADD INDEX {$CFG->prefix}forum_posts_parent_idx (parent) ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` ADD INDEX {$CFG->prefix}forum_posts_discussion_idx (discussion) ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` ADD INDEX {$CFG->prefix}forum_posts_userid_idx (userid) ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` ADD INDEX {$CFG->prefix}forum_discussions_forum_idx (forum) ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` ADD INDEX {$CFG->prefix}forum_discussions_userid_idx (userid) ");
    }
    if ($oldversion < 2004111700) {
        execute_sql("ALTER TABLE {$CFG->prefix}forum DROP INDEX course;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}forum_ratings DROP INDEX userid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}forum_ratings DROP INDEX post;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}forum_subscriptions DROP INDEX userid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}forum_subscriptions DROP INDEX forum;", false);
        modify_database('', 'ALTER TABLE prefix_forum ADD INDEX course (course);');
        modify_database('', 'ALTER TABLE prefix_forum_ratings ADD INDEX userid (userid);');
        modify_database('', 'ALTER TABLE prefix_forum_ratings ADD INDEX post (post);');
        modify_database('', 'ALTER TABLE prefix_forum_subscriptions ADD INDEX userid (userid);');
        modify_database('', 'ALTER TABLE prefix_forum_subscriptions ADD INDEX forum (forum);');
    }
    if ($oldversion < 2005011500) {
        modify_database('', 'CREATE TABLE prefix_forum_read (
                  `id` int(10) unsigned NOT NULL auto_increment, 
                  `userid` int(10) NOT NULL default \'0\',
                  `forumid` int(10) NOT NULL default \'0\',
                  `discussionid` int(10) NOT NULL default \'0\',
                  `postid` int(10) NOT NULL default \'0\',
                  `firstread` int(10) NOT NULL default \'0\',
                  `lastread` int(10) NOT NULL default \'0\',
                  PRIMARY KEY  (`id`),
                  KEY `prefix_forum_user_forum_idx` (`userid`,`forumid`),
                  KEY `prefix_forum_user_discussion_idx` (`userid`,`discussionid`),
                  KEY `prefix_forum_user_post_idx` (`userid`,`postid`)
                  ) COMMENT=\'Tracks each users read posts\';');
        set_config('upgrade', 'forumread');
        // The upgrade of this table will be done later by admin/upgradeforumread.php
    }
    if ($oldversion < 2005032900) {
        modify_database('', 'ALTER TABLE prefix_forum_posts ADD INDEX prefix_form_posts_created_idx (created);');
        modify_database('', 'ALTER TABLE prefix_forum_posts ADD INDEX prefix_form_posts_mailed_idx (mailed);');
    }
    if ($oldversion < 2005041100) {
        // replace wiki-like with markdown
        include_once "{$CFG->dirroot}/lib/wiki_to_markdown.php";
        $wtm = new WikiToMarkdown();
        $sql = "select course from {$CFG->prefix}forum_discussions, {$CFG->prefix}forum_posts ";
        $sql .= "where {$CFG->prefix}forum_posts.discussion = {$CFG->prefix}forum_discussions.id ";
        $sql .= "and {$CFG->prefix}forum_posts.id = ";
        $wtm->update('forum_posts', 'message', 'format', $sql);
    }
    if ($oldversion < 2005042300) {
        // Add tracking prefs table
        modify_database('', 'CREATE TABLE prefix_forum_track_prefs (
                  `id` int(10) unsigned NOT NULL auto_increment, 
                  `userid` int(10) NOT NULL default \'0\',
                  `forumid` int(10) NOT NULL default \'0\',
                  PRIMARY KEY  (`id`),
                  KEY `user_forum_idx` (`userid`,`forumid`)
                  ) COMMENT=\'Tracks each users untracked forums.\';');
    }
    if ($oldversion < 2005042500) {
        table_column('forum', '', 'trackingtype', 'tinyint', '2', 'unsigned', '1', '', 'forcesubscribe');
    }
    if ($oldversion < 2005111100) {
        table_column('forum_discussions', '', 'timestart', 'integer');
        table_column('forum_discussions', '', 'timeend', 'integer');
    }
    if ($oldversion < 2006011600) {
        execute_sql("alter table " . $CFG->prefix . "forum change column type type enum('single','news','general','social','eachuser','teacher','qanda') not null default 'general'");
    }
    if ($oldversion < 2006011601) {
        table_column('forum', '', 'warnafter');
        table_column('forum', '', 'blockafter');
        table_column('forum', '', 'blockperiod');
    }
    if ($oldversion < 2006011700) {
        table_column('forum_posts', '', 'mailnow', 'integer');
    }
    if ($oldversion < 2006011702) {
        execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('forum', 'user report', 'user', 'CONCAT(firstname,\\' \\',lastname)')");
    }
    if ($oldversion < 2006081800) {
        // Upgrades for new roles and capabilities support.
        require_once $CFG->dirroot . '/mod/forum/lib.php';
        $forummod = get_record('modules', 'name', 'forum');
        if ($forums = get_records('forum')) {
            if (!($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW))) {
                notify('Default teacher role was not found. Roles and permissions ' . 'for all your forums will have to be manually set after ' . 'this upgrade.');
            }
            if (!($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW))) {
                notify('Default student role was not found. Roles and permissions ' . 'for all your forums will have to be manually set after ' . 'this upgrade.');
            }
            if (!($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW))) {
                notify('Default guest role was not found. Roles and permissions ' . 'for teacher forums will have to be manually set after ' . 'this upgrade.');
            }
            foreach ($forums as $forum) {
                if (!forum_convert_to_roles($forum, $forummod->id, $teacherroles, $studentroles, $guestroles)) {
                    notify('Forum with id ' . $forum->id . ' was not upgraded');
                }
            }
            // We need to rebuild all the course caches to refresh the state of
            // the forum modules.
            include_once "{$CFG->dirroot}/course/lib.php";
            rebuild_course_cache();
        }
        // End if.
        // Drop column forum.open.
        modify_database('', 'ALTER TABLE prefix_forum DROP COLUMN open;');
        // Drop column forum.assesspublic.
        modify_database('', 'ALTER TABLE prefix_forum DROP COLUMN assesspublic;');
    }
    if ($oldversion < 2006082700) {
        $sql = "UPDATE {$CFG->prefix}forum_posts SET message = REPLACE(message, '" . TRUSTTEXT . "', '');";
        $likecond = sql_ilike() . " '%" . TRUSTTEXT . "%'";
        while (true) {
            if (!count_records_select('forum_posts', "message {$likecond}")) {
                break;
            }
            execute_sql($sql);
        }
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}