/// Course Default Settings Page
/// NOTE: these settings must be applied after all other settings because they depend on them
- if (isset($CFG->maxbytes)) { // TODO: replace this hack by something better
- ///main course settings
- $temp = new admin_settingpage('coursesettings', get_string('coursesettings'));
- $temp->add(new admin_settings_coursecat_select('moodlecourse/category', get_string('category'), get_string('coursehelpcategory'), 1));
- $courseformats = get_list_of_plugins('course/format');
- $formcourseformats = array();
- foreach ($courseformats as $courseformat) {
- $formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat");
- if ($formcourseformats["$courseformat"]=="[[format$courseformat]]") {
- $formcourseformats["$courseformat"] = get_string("format$courseformat");
- }
+ ///main course settings
+ $temp = new admin_settingpage('coursesettings', get_string('coursesettings'));
+ $temp->add(new admin_settings_coursecat_select('moodlecourse/category', get_string('category'), get_string('coursehelpcategory'), 1));
+ $courseformats = get_list_of_plugins('course/format');
+ $formcourseformats = array();
+ foreach ($courseformats as $courseformat) {
+ $formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat");
+ if ($formcourseformats["$courseformat"]=="[[format$courseformat]]") {
+ $formcourseformats["$courseformat"] = get_string("format$courseformat");
}
- $temp->add(new admin_setting_configselect('moodlecourse/format', get_string('format'), get_string('coursehelpformat'), 'weeks',$formcourseformats));
- for ($i=1; $i<=52; $i++) {
- $sectionmenu[$i] = "$i";
- }
- $temp->add(new admin_setting_configselect('moodlecourse/numsections', get_string('numberweeks'), get_string('coursehelpnumberweeks'), 3,$sectionmenu));
- $choices = array();
- $choices['0'] = get_string('hiddensectionscollapsed');
- $choices['1'] = get_string('hiddensectionsinvisible');
- $temp->add(new admin_setting_configselect('moodlecourse/hiddensections', get_string('hiddensections'), get_string('coursehelphiddensections'), 0,$choices));
- $options = range(0, 10);
- $temp->add(new admin_setting_configselect('moodlecourse/newsitems', get_string('newsitemsnumber'), get_string('coursehelpnewsitemsnumber'), 5,$options));
- $temp->add(new admin_setting_configselect('moodlecourse/showgrades', get_string('showgrades'), get_string('coursehelpshowgrades'), 1,array(0 => get_string('no'), 1 => get_string('yes'))));
- $temp->add(new admin_setting_configselect('moodlecourse/showreports', get_string('showreports'), '', 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+ }
+ $temp->add(new admin_setting_configselect('moodlecourse/format', get_string('format'), get_string('coursehelpformat'), 'weeks',$formcourseformats));
+ for ($i=1; $i<=52; $i++) {
+ $sectionmenu[$i] = "$i";
+ }
+ $temp->add(new admin_setting_configselect('moodlecourse/numsections', get_string('numberweeks'), get_string('coursehelpnumberweeks'), 3,$sectionmenu));
+ $choices = array();
+ $choices['0'] = get_string('hiddensectionscollapsed');
+ $choices['1'] = get_string('hiddensectionsinvisible');
+ $temp->add(new admin_setting_configselect('moodlecourse/hiddensections', get_string('hiddensections'), get_string('coursehelphiddensections'), 0,$choices));
+ $options = range(0, 10);
+ $temp->add(new admin_setting_configselect('moodlecourse/newsitems', get_string('newsitemsnumber'), get_string('coursehelpnewsitemsnumber'), 5,$options));
+ $temp->add(new admin_setting_configselect('moodlecourse/showgrades', get_string('showgrades'), get_string('coursehelpshowgrades'), 1,array(0 => get_string('no'), 1 => get_string('yes'))));
+ $temp->add(new admin_setting_configselect('moodlecourse/showreports', get_string('showreports'), '', 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+ if (isset($CFG->maxbytes)) {
$choices = get_max_upload_sizes($CFG->maxbytes);
- $temp->add(new admin_setting_configselect('moodlecourse/maxbytes', get_string('maximumupload'), get_string('coursehelpmaximumupload'), key($choices),$choices));
- $temp->add(new admin_setting_configselect('moodlecourse/metacourse', get_string('metacourse'), get_string('coursehelpmetacourse'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
-
- ///enrolement course settings
- $temp->add(new admin_setting_heading('enrolhdr', get_string('enrolments'), ''));
- require_once($CFG->dirroot.'/enrol/enrol.class.php');
- $choices = array();
- $modules = explode(',', $CFG->enrol_plugins_enabled);
- foreach ($modules as $module) {
- $name = get_string('enrolname', "enrol_$module");
- $plugin = enrolment_factory::factory($module);
- if (method_exists($plugin, 'print_entry')) {
- $choices[$name] = $module;
- }
- }
- asort($choices);
- $choices = array_flip($choices);
- $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string('enrolname', "enrol_$CFG->enrol").')'), $choices);
- $temp->add(new admin_setting_configselect('moodlecourse/enrol', get_string('enrolmentplugins'), get_string('coursehelpenrolmentplugins'), key($choices),$choices));
- $choices = array(0 => get_string('no'), 1 => get_string('yes'), 2 => get_string('enroldate'));
- $temp->add(new admin_setting_configselect('moodlecourse/enrollable', get_string('enrollable'), get_string('coursehelpenrollable'), 1,$choices));
- $periodmenu=array();
- $periodmenu[0] = get_string('unlimited');
- for ($i=1; $i<=365; $i++) {
- $seconds = $i * 86400;
- $periodmenu[$seconds] = get_string('numdays', '', $i);
- }
- $temp->add(new admin_setting_configselect('moodlecourse/enrolperiod', get_string('enrolperiod'), '', 0,$periodmenu));
-
- ///
- $temp->add(new admin_setting_heading('expirynotifyhdr', get_string('expirynotify'), ''));
- $temp->add(new admin_setting_configselect('moodlecourse/expirynotify', get_string('notify'), get_string('coursehelpnotify'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
- $temp->add(new admin_setting_configselect('moodlecourse/notifystudents', get_string('expirynotifystudents'), get_string('coursehelpexpirynotifystudents'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
- $thresholdmenu=array();
- for ($i=1; $i<=30; $i++) {
- $seconds = $i * 86400;
- $thresholdmenu[$seconds] = get_string('numdays', '', $i);
- }
- $temp->add(new admin_setting_configselect('moodlecourse/expirythreshold', get_string('expirythreshold'), get_string('coursehelpexpirythreshold'), 10 * 86400,$thresholdmenu));
-
-
- $temp->add(new admin_setting_heading('groups', get_string('groups', 'group'), ''));
- $choices = array();
- $choices[NOGROUPS] = get_string('groupsnone', 'group');
- $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
- $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
- $temp->add(new admin_setting_configselect('moodlecourse/groupmode', get_string('groupmode'), '', key($choices),$choices));
- $temp->add(new admin_setting_configselect('moodlecourse/groupmodeforce', get_string('force'), get_string('coursehelpforce'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
-
-
- $temp->add(new admin_setting_heading('availability', get_string('availability'), ''));
- $choices = array();
- $choices['0'] = get_string('courseavailablenot');
- $choices['1'] = get_string('courseavailable');
- $temp->add(new admin_setting_configselect('moodlecourse/visible', get_string('visible'), '', 1,$choices));
- $temp->add(new admin_setting_configpasswordunmask('moodlecourse/enrolpassword', get_string('enrolmentkey'), get_string('coursehelpenrolmentkey'),''));
- $choices = array();
- $choices['0'] = get_string('guestsno');
- $choices['1'] = get_string('guestsyes');
- $choices['2'] = get_string('guestskey');
- $temp->add(new admin_setting_configselect('moodlecourse/guest', get_string('opentoguests'), '', 0,$choices));
-
-
- $temp->add(new admin_setting_heading('language', get_string('language'), ''));
- $languages=array();
- $languages[''] = get_string('forceno');
- $languages += get_list_of_languages();
- $temp->add(new admin_setting_configselect('moodlecourse/lang', get_string('forcelanguage'), '',key($languages),$languages));
-
- if(completion_info::is_enabled_for_site()) {
- $temp->add(new admin_setting_heading('progress', get_string('progress','completion'), ''));
- $temp->add(new admin_setting_configselect('moodlecourse/enablecompletion', get_string('completion','completion'), '',
- 1,array(0 => get_string('completiondisabled','completion'), 1 => get_string('completionenabled','completion'))));
+ } else {
+ $choices = get_max_upload_sizes();
+ }
+ $temp->add(new admin_setting_configselect('moodlecourse/maxbytes', get_string('maximumupload'), get_string('coursehelpmaximumupload'), key($choices), $choices));
+ $temp->add(new admin_setting_configselect('moodlecourse/metacourse', get_string('metacourse'), get_string('coursehelpmetacourse'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+
+ ///enrolement course settings
+ $temp->add(new admin_setting_heading('enrolhdr', get_string('enrolments'), ''));
+ require_once($CFG->dirroot.'/enrol/enrol.class.php');
+ $choices = array();
+ $modules = explode(',', $CFG->enrol_plugins_enabled);
+ foreach ($modules as $module) {
+ $name = get_string('enrolname', "enrol_$module");
+ $plugin = enrolment_factory::factory($module);
+ if (method_exists($plugin, 'print_entry')) {
+ $choices[$name] = $module;
}
- $ADMIN->add('courses', $temp);
}
+ asort($choices);
+ $choices = array_flip($choices);
+ $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string('enrolname', "enrol_$CFG->enrol").')'), $choices);
+ $temp->add(new admin_setting_configselect('moodlecourse/enrol', get_string('enrolmentplugins'), get_string('coursehelpenrolmentplugins'), key($choices),$choices));
+ $choices = array(0 => get_string('no'), 1 => get_string('yes'), 2 => get_string('enroldate'));
+ $temp->add(new admin_setting_configselect('moodlecourse/enrollable', get_string('enrollable'), get_string('coursehelpenrollable'), 1,$choices));
+ $periodmenu=array();
+ $periodmenu[0] = get_string('unlimited');
+ for ($i=1; $i<=365; $i++) {
+ $seconds = $i * 86400;
+ $periodmenu[$seconds] = get_string('numdays', '', $i);
+ }
+ $temp->add(new admin_setting_configselect('moodlecourse/enrolperiod', get_string('enrolperiod'), '', 0,$periodmenu));
+
+ ///
+ $temp->add(new admin_setting_heading('expirynotifyhdr', get_string('expirynotify'), ''));
+ $temp->add(new admin_setting_configselect('moodlecourse/expirynotify', get_string('notify'), get_string('coursehelpnotify'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+ $temp->add(new admin_setting_configselect('moodlecourse/notifystudents', get_string('expirynotifystudents'), get_string('coursehelpexpirynotifystudents'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+ $thresholdmenu=array();
+ for ($i=1; $i<=30; $i++) {
+ $seconds = $i * 86400;
+ $thresholdmenu[$seconds] = get_string('numdays', '', $i);
+ }
+ $temp->add(new admin_setting_configselect('moodlecourse/expirythreshold', get_string('expirythreshold'), get_string('coursehelpexpirythreshold'), 10 * 86400,$thresholdmenu));
+
+
+ $temp->add(new admin_setting_heading('groups', get_string('groups', 'group'), ''));
+ $choices = array();
+ $choices[NOGROUPS] = get_string('groupsnone', 'group');
+ $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
+ $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
+ $temp->add(new admin_setting_configselect('moodlecourse/groupmode', get_string('groupmode'), '', key($choices),$choices));
+ $temp->add(new admin_setting_configselect('moodlecourse/groupmodeforce', get_string('force'), get_string('coursehelpforce'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+
+
+ $temp->add(new admin_setting_heading('availability', get_string('availability'), ''));
+ $choices = array();
+ $choices['0'] = get_string('courseavailablenot');
+ $choices['1'] = get_string('courseavailable');
+ $temp->add(new admin_setting_configselect('moodlecourse/visible', get_string('visible'), '', 1,$choices));
+ $temp->add(new admin_setting_configpasswordunmask('moodlecourse/enrolpassword', get_string('enrolmentkey'), get_string('coursehelpenrolmentkey'),''));
+ $choices = array();
+ $choices['0'] = get_string('guestsno');
+ $choices['1'] = get_string('guestsyes');
+ $choices['2'] = get_string('guestskey');
+ $temp->add(new admin_setting_configselect('moodlecourse/guest', get_string('opentoguests'), '', 0,$choices));
+
+
+ $temp->add(new admin_setting_heading('language', get_string('language'), ''));
+ $languages=array();
+ $languages[''] = get_string('forceno');
+ $languages += get_list_of_languages();
+ $temp->add(new admin_setting_configselect('moodlecourse/lang', get_string('forcelanguage'), '',key($languages),$languages));
+
+ if(completion_info::is_enabled_for_site()) {
+ $temp->add(new admin_setting_heading('progress', get_string('progress','completion'), ''));
+ $temp->add(new admin_setting_configselect('moodlecourse/enablecompletion', get_string('completion','completion'), '',
+ 1,array(0 => get_string('completiondisabled','completion'), 1 => get_string('completionenabled','completion'))));
+ }
+ $ADMIN->add('courses', $temp);
/// "courserequests" settingpage
$temp = new admin_settingpage('courserequest', get_string('courserequest'));
'2' => get_string('gd2'))));
$temp->add(new admin_setting_configexecutable('pathtodu', get_string('pathtodu', 'admin'), get_string('configpathtodu', 'admin'), ''));
$temp->add(new admin_setting_configexecutable('aspellpath', get_string('aspellpath', 'admin'), get_string('edhelpaspellpath'), ''));
-$ADMIN->add('server', $temp, 0);
+$ADMIN->add('server', $temp);
$temp->add(new admin_setting_configtext('supportname', get_string('supportname', 'admin'), get_string('configsupportname', 'admin'), $primaryadminname, PARAM_NOTAGS));
$temp->add(new admin_setting_configtext('supportemail', get_string('supportemail', 'admin'), get_string('configsupportemail', 'admin'), $primaryadminemail, PARAM_NOTAGS));
$temp->add(new admin_setting_configtext('supportpage', get_string('supportpage', 'admin'), get_string('configsupportpage', 'admin'), '', PARAM_URL));
-$ADMIN->add('server', $temp, 100);
+$ADMIN->add('server', $temp);
$temp->add(new admin_setting_configtext('sessioncookie', get_string('sessioncookie', 'admin'), get_string('configsessioncookie', 'admin'), '', PARAM_ALPHANUM));
$temp->add(new admin_setting_configtext('sessioncookiepath', get_string('sessioncookiepath', 'admin'), get_string('configsessioncookiepath', 'admin'), '/', PARAM_LOCALURL));
$temp->add(new admin_setting_configtext('sessioncookiedomain', get_string('sessioncookiedomain', 'admin'), get_string('configsessioncookiedomain', 'admin'), '', PARAM_TEXT, 50));
-$ADMIN->add('server', $temp, 50);
+$ADMIN->add('server', $temp);
// are added to them.
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
-if (get_site()) {
- $hassiteconfig = has_capability('moodle/site:config', $systemcontext);
-} else {
+if (empty($CFG->rolesactive)) {
// installation starts - no permission checks
$hassiteconfig = true;
+} else {
+ $hassiteconfig = has_capability('moodle/site:config', $systemcontext);
}
$ADMIN->add('root', new admin_externalpage('adminnotifications', get_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php"));
}
- if(empty($CFG->loginhttps)) {
+ if (empty($CFG->loginhttps)) {
$securewwwroot = $CFG->wwwroot;
} else {
$securewwwroot = str_replace('http:','https:',$CFG->wwwroot);
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
+ /// set all core default records and default settings
+ require_once("$CFG->libdir/db/install.php");
+ xmldb_main_install($version);
+
/// Continue with the instalation
// Install the roles system.
message_update_providers();
message_update_providers('message');
- /// This is used to handle any settings that must exist in $CFG but which do not exist in
- /// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
- apply_default_exception_settings(array('auth' => 'email',
- 'auth_pop3mailbox' => 'INBOX',
- 'enrol' => 'manual',
- 'enrol_plugins_enabled' => 'manual',
- 'style' => 'default',
- 'template' => 'default',
- 'theme' => 'standardwhite',
- 'filter_multilang_converted' => 1,
- 'backup_version' => 2008111700,
- 'backup_release' => '2.0 dev',
- 'blocks_version' => 2007081300, // might be removed soon
- ));
-
- // store main version
- if (!set_config('version', $version)) {
- print_error('cannotupdateversion', 'debug');
- }
-
-
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
- // (this should only have any effect during initial install).
admin_apply_default_settings(NULL, true);
-
notify($strdatabasesuccess, 'notifysuccess');
/// do not show certificates in log ;-)
$DB->set_debug(false);
- // hack - set up mnet
- require_once $CFG->dirroot.'/mnet/lib.php';
-
print_continue("index.php?continuesetuptesttables=$setuptesttables&upgradetesttables=$upgradetesttables");
print_footer('none');
}
if ($version > $CFG->version) { // upgrade
-
require_once($CFG->libdir.'/db/upgrade.php'); // Defines upgrades
require_once($CFG->libdir.'/db/upgradelib.php'); // Upgrade-related functions
print_heading($strdatabasechecking);
$DB->set_debug(true);
/// Launch the old main upgrade (if exists)
- $status = true;
- if (function_exists('main_upgrade')) {
- $status = main_upgrade($CFG->version);
- }
- /// If succesful and exists launch the new main upgrade (XMLDB), called xmldb_main_upgrade
- if ($status && function_exists('xmldb_main_upgrade')) {
- $status = xmldb_main_upgrade($CFG->version);
- }
+ $status = xmldb_main_upgrade($CFG->version);
$DB->set_debug(false);
/// If successful, continue upgrading roles and setting everything properly
if ($status) {
if ($upgradedplugins) {
print_continue($return_url);
- print_footer();
+ print_footer('none');
die;
}
/// Check for changes to RPC functions
- require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
- upgrade_RPC_functions($return_url); // Return here afterwards
+ if ($CFG->mnet_dispatcher_mode != 'off') {
+ require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
+ upgrade_RPC_functions($return_url); // Return here afterwards
+ }
/// Check for local database customisations
/// first old *.php update and then the new upgrade.php script
// Turn xmlstrictheaders back on now.
$CFG->xmlstrictheaders = $origxmlstrictheaders;
- if (!$unittest) {
- /// Set up the blank site - to be customized later at the end of install.
- if (! $site = get_site()) {
- build_site_course();
- redirect("index.php?continuesetuptesttables=$continuesetuptesttables&upgradetesttables=$upgradetesttables");
- }
-
- // initialise default blocks on admin and site page if needed
- if (empty($CFG->adminblocks_initialised)) {
- require_once("$CFG->dirroot/$CFG->admin/pagelib.php");
- require_once($CFG->libdir.'/blocklib.php');
- page_map_class(PAGE_ADMIN, 'page_admin');
- $page = page_create_object(PAGE_ADMIN, 0); // there must be some id number
- blocks_repopulate_page($page);
-
- //add admin_tree block to site if not already present
- if ($admintree = $DB->get_record('block', array('name'=>'admin_tree'))) {
- $page = page_create_object(PAGE_COURSE_VIEW, SITEID);
- $pageblocks=blocks_get_by_page($page);
- blocks_execute_action($page, $pageblocks, 'add', (int)$admintree->id, false, false);
- if ($admintreeinstance = $DB->get_record('block_instance', array('pagetype'=>$page->type, 'pageid'=>SITEID, 'blockid'=>$admintree->id))) {
- $pageblocks=blocks_get_by_page($page);
- blocks_execute_action($page, $pageblocks, 'moveleft', $admintreeinstance, false, false);
- }
- }
-
- set_config('adminblocks_initialised', 1);
- }
-
- /// Define the unique site ID code if it isn't already
- if (empty($CFG->siteidentifier)) { // Unique site identification code
- set_config('siteidentifier', random_string(32).$_SERVER['HTTP_HOST']);
- }
-
- /// ugly hack - if mnet is not initialised include the mnet lib, it adds needed mnet records and configures config options
- /// we should not do such crazy stuff in lib functions!!!
- if (empty($CFG->mnet_localhost_id)) {
- require_once $CFG->dirroot.'/mnet/lib.php';
- }
-
- /// Check if the guest user exists. If not, create one.
- if (!$DB->record_exists('user', array('username'=>'guest'))) {
- if (! $guest = create_guest_record()) {
- notify("Could not create guest user record !!!");
- }
- }
-
- /// Set up the admin user
- if (empty($CFG->rolesactive)) {
- build_context_path(); // just in case - should not be needed
- create_admin_user();
- }
- } else {
- build_site_course();
- create_guest_record();
+/// make sure admin user is created - this is the last step because we need
+/// session to be working properly in order to edit admin account
+ if (empty($CFG->rolesactive)) {
create_admin_user();
- redirect($return_url);
}
}
-function build_site_course() {
- global $CFG, $DB, $unittest;
-
- $continuesetuptesttables= optional_param('continuesetuptesttables', $unittest, PARAM_BOOL);
-
- // We are about to create the site "course"
- require_once($CFG->libdir.'/blocklib.php');
-
- $newsite = new object();
- $newsite->fullname = "";
- $newsite->shortname = "";
- $newsite->summary = NULL;
- $newsite->newsitems = 3;
- $newsite->numsections = 0;
- $newsite->category = 0;
- $newsite->format = 'site'; // Only for this course
- $newsite->teacher = get_string("defaultcourseteacher");
- $newsite->teachers = get_string("defaultcourseteachers");
- $newsite->student = get_string("defaultcoursestudent");
- $newsite->students = get_string("defaultcoursestudents");
- $newsite->timemodified = time();
-
- if (!$newid = $DB->insert_record('course', $newsite)) {
- print_error('cannotsetupsite', 'error');
- }
- // make sure course context exists
- get_context_instance(CONTEXT_COURSE, $newid);
-
- // Site created, add blocks for it
- $page = page_create_object(PAGE_COURSE_VIEW, $newid);
- blocks_repopulate_page($page); // Return value not checked because you can always edit later
-
- // create default course category
- $cat = get_course_category();
-
-}
-
/**
* Upgrade savepoint, marks end of each upgrade block.
* It stores new main version, resets upgrade timeout
print_error('noadminrole', 'message');
}
- $sitecontext = get_context_instance(CONTEXT_SYSTEM);
+ $systemcontext = get_context_instance(CONTEXT_SYSTEM);
foreach ($adminroles as $adminrole) {
- role_assign($adminrole->id, $user->id, 0, $sitecontext->id);
+ role_assign($adminrole->id, $user->id, 0, $systemcontext->id);
}
//set default message preferences
* @return bool True if user has access, false otherwise.
*/
function check_access() {
- if (!get_site()) {
+ global $CFG;
+ if (empty($CFG->rolesactive)) {
return true; // no access check before site is fully set up
}
$context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
// see admin_externalpage
function check_access() {
- if (!get_site()) {
+ global $CFG;
+ if (empty($CFG->rolesactive)) {
return true; // no access check before site is fully set up
}
$context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
* Returns the reference to admin tree root
* @return reference
*/
-function &admin_get_root($reload=false, $requirefulltree=true) {
+function admin_get_root($reload=false, $requirefulltree=true) {
global $CFG, $DB;
static $ADMIN = NULL;
// plugins are loaded last - they may insert pages anywhere
continue;
}
- include($file);
+ require($file);
}
- include($CFG->dirroot.'/'.$CFG->admin.'/settings/plugins.php');
+ require($CFG->dirroot.'/'.$CFG->admin.'/settings/plugins.php');
if (file_exists($CFG->dirroot.'/local/settings.php')) {
- include_once($CFG->dirroot.'/local/settings.php');
+ require($CFG->dirroot.'/local/settings.php');
}
}
global $CFG;
if (is_null($node)) {
- $node =& admin_get_root(true, true);
+ $node = admin_get_root(true, true);
}
if (is_a($node, 'admin_category')) {
return $return;
}
-/**
- * Unconditionally applies default admin settings in main config table
- * @param array $defaults array of string values
- */
-function apply_default_exception_settings($defaults) {
- foreach($defaults as $key => $value) {
- set_config($key, $value, NULL);
- }
-}
-
/**
* Format admin settings
* @param string $object setting
//This function finds all available blocks and install them
//into blocks table or do all the upgrade process if newer
function upgrade_blocks_plugins() {
- global $CFG, $interactive, $DB;
+ global $CFG, $interactive, $DB, $SITE;
+
+ require_once($CFG->dirroot .'/blocks/moodleblock.class.php');
$updated_blocks = false;
- $blocktitles = array();
+ $blocktitles = array();
$invalidblocks = array();
- $validblocks = array();
- $notices = array();
+ $validblocks = array();
+ $notices = array();
//Count the number of blocks in db
$blockcount = $DB->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();
+ $first_install = ($blockcount == 0);
if (!$blocks = get_list_of_plugins('blocks') ) {
print_error('noblocks', 'debug');
}
- include_once($CFG->dirroot .'/blocks/moodleblock.class.php');
- if(!class_exists('block_base')) {
+ if (!class_exists('block_base')) {
print_error('noblockbase');
}
}
}
- // 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.
+ // Finally, if we are in the first_install of BLOCKS setup frontpage and admin page blocks
if ($first_install) {
+ require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php');
+
upgrade_log_start();
- //Iterate over each course
+ //Iterate over each course - there should be only site course here now
if ($courses = $DB->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);
+ page_map_class(PAGE_ADMIN, 'page_admin');
+ $page = page_create_object(PAGE_ADMIN, 0); // there must be some id number
blocks_repopulate_page($page);
- $DB->delete_records('config', array('name'=>'siteblocksadded'));
}
upgrade_log_finish();
*/
public static function is_enabled_for_site() {
global $CFG;
- return $CFG->enablecompletion;
+ return !empty($CFG->enablecompletion);
}
/**
--- /dev/null
+<?php //$Id$
+
+// This file is executed right after the install.xml
+//
+
+function xmldb_main_install($version) {
+ global $CFG, $DB, $SITE;
+
+/// TODO: move all statements from install.xml here
+
+
+/// make sure system context exists
+ $syscontext = get_context_instance(CONTEXT_SYSTEM);
+ if ($syscontext->id != 1) {
+ throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected system context id created!');
+ }
+
+
+// create site course
+ $newsite = new object();
+ $newsite->fullname = "";
+ $newsite->shortname = "";
+ $newsite->summary = NULL;
+ $newsite->newsitems = 3;
+ $newsite->numsections = 0;
+ $newsite->category = 0;
+ $newsite->format = 'site'; // Only for this course
+ $newsite->teacher = get_string("defaultcourseteacher");
+ $newsite->teachers = get_string("defaultcourseteachers");
+ $newsite->student = get_string("defaultcoursestudent");
+ $newsite->students = get_string("defaultcoursestudents");
+ $newsite->timemodified = time();
+
+ $DB->insert_record('course', $newsite);
+ $SITE = get_site();
+ if ($SITE->id != 1) {
+ throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected site course id created!');
+ }
+
+
+/// make sure site course context exists
+ get_context_instance(CONTEXT_COURSE, $SITE->id);
+
+/// create default course category
+ $cat = get_course_category();
+
+
+ $defaults = array('auth' => 'email',
+ 'auth_pop3mailbox' => 'INBOX',
+ 'enrol' => 'manual',
+ 'enrol_plugins_enabled' => 'manual',
+ 'style' => 'default',
+ 'template' => 'default',
+ 'theme' => 'standardwhite',
+ 'filter_multilang_converted' => 1,
+ 'siteidentifier' => random_string(32).$_SERVER['HTTP_HOST'],
+ 'backup_version' => 2008111700,
+ 'backup_release' => '2.0 dev',
+ 'blocks_version' => 2007081300, // might be removed soon
+ 'mnet_dispatcher_mode' => 'off',
+ 'sessiontimeout' => 7200, // must be present during roles installation
+
+ );
+ foreach($defaults as $key => $value) {
+ set_config($key, $value);
+ }
+
+
+/// bootstrap mnet
+ $mnethost = new object();
+ $mnethost->wwwroot = $CFG->wwwroot;
+ $mnethost->name = '';
+ $mnethost->name = '';
+ $mnethost->public_key = '';
+
+ if (empty($_SERVER['SERVER_ADDR'])) {
+ // SERVER_ADDR is only returned by Apache-like webservers
+ preg_match("@^(?:http[s]?://)?([A-Z0-9\-\.]+).*@i", $CFG->wwwroot, $matches);
+ $my_hostname = $matches[1];
+ $my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH!
+ if ($my_ip == $my_hostname) {
+ $mnethost->ip_address = 'UNKNOWN';
+ } else {
+ $mnethost->ip_address = $my_ip;
+ }
+ } else {
+ $mnethost->ip_address = $_SERVER['SERVER_ADDR'];
+ }
+
+ $mnetid = $DB->insert_record('mnet_host', $mnethost);
+ set_config('mnet_localhost_id', $mnetid);
+
+
+/// Create guest record
+ create_guest_record();
+
+
+/// everything ready - store main version :-D
+ set_config('version', $version);
+
+}
\ No newline at end of file
upgrade_main_savepoint($result, 2009010800);
}
- if ($result && $oldversion < 2009010801) {
- /// Remove unused settings
- unset_config('zip');
- unset_config('unzip');
-
- /// Main savepoint reached
- upgrade_main_savepoint($result, 2009010801);
- }
-
if ($result && $oldversion < 2009011000) {
/// Changing nullability of field configdata on table block_instance to null
upgrade_main_savepoint($result, 2009011000);
}
+ if ($result && $oldversion < 2009011100) {
+ /// Remove unused settings
+ unset_config('zip');
+ unset_config('unzip');
+ unset_config('adminblocks_initialised');
+
+ /// Main savepoint reached
+ upgrade_main_savepoint($result, 2009011100);
+ }
+
+
return $result;
}
$guest->lang = $CFG->lang;
$guest->timemodified= time();
- if (! $guest->id = $DB->insert_record('user', $guest)) {
- return false;
- }
+ $id = $DB->insert_record('user', $guest);
+ $guest = $DB->get_record('user', array('id'=>$id));
return $guest;
}
$session_has_timed_out = false;
}
-/// Check if the guest user exists. If not, create one.
- if (!$DB->record_exists('user', array('username'=>'guest', 'mnethostid'=>$CFG->mnet_localhost_id))) {
- if (! $guest = create_guest_record()) {
- notify('Could not create guest user record !!!');
- }
- }
-
// setup and verify auth settings
if (!isset($CFG->registerauth)) {
function init() {
global $CFG, $DB;
- if (empty($CFG->mnet_dispatcher_mode)) {
- set_config('mnet_dispatcher_mode', 'off');
- }
-
// Bootstrap the object data on first load.
- if (empty($CFG->mnet_localhost_id) ) {
- if (!$CFG->mnet_localhost_id = get_config(NULL, 'mnet_localhost_id')) { // Double-check db
- $this->wwwroot = $CFG->wwwroot;
- if (empty($_SERVER['SERVER_ADDR'])) {
- // SERVER_ADDR is only returned by Apache-like webservers
- $my_hostname = mnet_get_hostname_from_uri($CFG->wwwroot);
- $my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH!
- if ($my_ip == $my_hostname) {
- $this->ip_address = 'UNKNOWN';
- } else {
- $this->ip_address = $my_ip;
- }
- } else {
- $this->ip_address = $_SERVER['SERVER_ADDR'];
- }
-
- if ($existingrecord = $DB->get_record('mnet_host', array('ip_address'=>$this->ip_address))) {
- $this->id = $existingrecord->id;
- } else { // make a new one
- $this->id = $DB->insert_record('mnet_host', $this);
- }
-
- set_config('mnet_localhost_id', $this->id);
- $this->get_keypair();
- }
- } else {
- $hostobject = $DB->get_record('mnet_host', array('id'=>$CFG->mnet_localhost_id));
- if(is_object($hostobject)) {
- $temparr = get_object_vars($hostobject);
- foreach($temparr as $key => $value) {
- $this->$key = $value;
- }
- unset($hostobject, $temparr);
- } else {
- return false;
- }
+ if (!$hostobject = $DB->get_record('mnet_host', array('id'=>$CFG->mnet_localhost_id))) {
+ return false;
+ }
+ $temparr = get_object_vars($hostobject);
+ foreach($temparr as $key => $value) {
+ $this->$key = $value;
+ }
+ unset($hostobject, $temparr);
- // Unless this is an install/upgrade, generate the SSL keys.
- if(empty($this->public_key)) {
- $this->get_keypair();
- }
+ // Unless this is an install/upgrade, generate the SSL keys.
+ if (empty($this->public_key)) {
+ $this->get_keypair();
}
// We need to set up a record that represents 'all hosts'. Any rights
}
function get_keypair() {
- global $DB, $SESSION;
+ global $DB, $CFG;
// We don't generate keys on install/upgrade because we want the USER
// record to have an email address, city and country already.
- if (!empty($SESSION->upgraderunning)) return true;
+ if (empty($CFG->rolesactive)) return true;
+ if ($CFG->mnet_dispatcher_mode == 'off') return true;
if (!extension_loaded("openssl")) return true;
if (!empty($this->keypair)) return true;
$break = strpos($host.'/' , '/');
$host = substr($host, 0, $break);
- if ($result = $DB->get_record('course', array("id"=>SITEID))) {
- $organization = $result->fullname;
- } else {
- $organization = 'None';
- }
+ $site = get_site();
+ $organization = $site->fullname;
$keypair = array();
$country = 'NZ';
$province = 'Wellington';
$locality = 'Wellington';
- $email = $CFG->noreplyaddress;
+ $email = !empty($CFG->noreplyaddress) ? $CFG->noreplyaddress : 'noreply@'.$_SERVER['HTTP_HOST'];
if(!empty($USER->country)) {
$country = $USER->country;
<?PHP // $Id$
-//////////////////////////////////
-/// CONFIGURATION settings
-
-if (!isset($CFG->hotpot_showtimes)) {
- set_config("hotpot_showtimes", 0);
-}
-if (!isset($CFG->hotpot_excelencodings)) {
- set_config("hotpot_excelencodings", "");
-}
-
//////////////////////////////////
/// CONSTANTS and GLOBAL VARIABLES
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2009011000; // YYYYMMDD = date of the last version bump
+ $version = 2009011100; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20090111)'; // Human-friendly version name