Skip to content

Commit

Permalink
fixed admin defaults, some warnings during install and added trmporar…
Browse files Browse the repository at this point in the history
…y hack to make $CFG->notloggedinroleid work
  • Loading branch information
skodak committed Sep 2, 2006
1 parent 73254f6 commit 35a518c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 15 deletions.
11 changes: 7 additions & 4 deletions admin/settings/userinterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@

// "languageandlocation" settingpage
$temp = new admin_settingpage('languageandlocation', get_string('languageandlocation', 'admin'));
$temp->add(new admin_setting_configselect('lang', get_string('lang', 'admin'), get_string('configlang', 'admin'), (!empty($CFG->unicodedb) ? 'en_utf8' : 'en'), get_list_of_languages()));
$temp->add(new admin_setting_configselect('lang', get_string('lang', 'admin'), get_string('configlang', 'admin'), $CFG->lang, get_list_of_languages())); // $CFG->lang might be set in installer already, default en or en_utf8 is in setup.php
$temp->add(new admin_setting_configcheckbox('langmenu', get_string('langmenu', 'admin'), get_string('configlangmenu', 'admin'), 1));
$temp->add(new admin_setting_configtext('langlist', get_string('langlist', 'admin'), get_string('configlanglist', 'admin'), '', PARAM_NOTAGS));
$temp->add(new admin_setting_configcheckbox('langcache', get_string('langcache', 'admin'), get_string('configlangcache', 'admin'), 1));
$temp->add(new admin_setting_configtext('locale', get_string('localetext', 'admin'), get_string('configlocale', 'admin'), '', PARAM_FILE));
$temp->add(new admin_setting_configselect('timezone', get_string('timezone','admin'), get_string('configtimezone', 'admin'), 99, get_list_of_timezones()));
$temp->add(new admin_setting_configselect('country', get_string('country', 'admin'), get_string('configcountry', 'admin'), '', get_list_of_countries()));
unset($options);
$options = get_list_of_timezones();
$options[99] = get_string('serverlocaltime');
$temp->add(new admin_setting_configselect('timezone', get_string('timezone','admin'), get_string('configtimezone', 'admin'), 99, $options));
$options = get_list_of_timezones();
$options[0] = get_string('choose') .'...';
$temp->add(new admin_setting_configselect('country', get_string('country', 'admin'), get_string('configcountry', 'admin'), 0, $options));
$options = get_list_of_timezones();
$options[99] = get_string('timezonenotforced', 'admin');
$temp->add(new admin_setting_configselect('forcetimezone', get_string('forcetimezone', 'admin'), get_string('helpforcetimezone', 'admin'), 99, $options));
Expand Down
5 changes: 3 additions & 2 deletions blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,11 @@ function _self_test() {
$errors[] = 'invalid_content_type';
$correct = false;
}
if ($this->get_content() === NULL) {
//following selftest was not working when roles&capabilitites were used from block
/* if ($this->get_content() === NULL) {
$errors[] = 'content_not_set';
$correct = false;
}
}*/
if ($this->get_version() === NULL) {
$errors[] = 'version_not_set';
$correct = false;
Expand Down
7 changes: 5 additions & 2 deletions blocks/site_main_menu/block_site_main_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ function get_content() {
$strcancel= get_string('cancel');
$stractivityclipboard = $USER->activitycopyname;
}

$modinfo = unserialize($course->modinfo);
if ($course->modinfo !== NULL) {
$modinfo = unserialize($course->modinfo);
} else {
$modinfo = null;
}
$editbuttons = '';

if ($ismoving) {
Expand Down
6 changes: 6 additions & 0 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ function load_notloggedin_role() {
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
// load default not logged in role capabilities when user is not logged in

// HACK ALERT!!!! - replace with proper default value!!!!!
if (empty($CFG->notloggedinroleid)) {
$guestrole = get_record('role', 'name', 'Guest');
$CFG->notloggedinroleid = $guestrole->id;
}

$SQL = "select * from {$CFG->prefix}role_capabilities where roleid=$CFG->notloggedinroleid
AND contextid = $sitecontext->id";

Expand Down
32 changes: 25 additions & 7 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1981,9 +1981,12 @@ function isadmin($userid=0) {
if (!empty($CFG->rolesactive)) {

$context = get_context_instance(CONTEXT_SYSTEM, SITEID);

if (!$userid) {
return has_capability('moodle/legacy:admin', $context, $USER->id, false);
if (empty($USER->id)) {
return false;
} else {
return has_capability('moodle/legacy:admin', $context, $USER->id, false);
}
} else {
return has_capability('moodle/legacy:admin', $context, false, $userid, false);
}
Expand Down Expand Up @@ -2043,10 +2046,13 @@ function isteacher($courseid=0, $userid=0, $includeadmin=true) {
}

if (!$userid) {

return (has_capability('moodle/legacy:teacher', $context, $USER->id, false)
if (empty($USER->id)) {
return false;
} else {
return (has_capability('moodle/legacy:teacher', $context, $USER->id, false)
or has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)
or has_capability('moodle/legacy:admin', $context, $USER->id, false));
}
} else {
return (has_capability('moodle/legacy:teacher', $context, $userid, false)
or has_capability('moodle/legacy:editingteacher', $context, $userid, false)
Expand Down Expand Up @@ -2137,8 +2143,12 @@ function isteacheredit($courseid, $userid=0, $ignorestudentview=false) {
}

if (!$userid) {
return (has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)
if (empty($USER->id)) {
return false;
} else {
return (has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)
or has_capability('moodle/legacy:admin', $context, $USER->id, false));
}
} else {
return (has_capability('moodle/legacy:editingteacher', $context, $userid, false)
or has_capability('moodle/legacy:admin', $context, $userid, false));
Expand Down Expand Up @@ -2181,8 +2191,12 @@ function iscreator ($userid=0) {
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);

if (!$userid) {
return (has_capability('moodle/legacy:coursecreator', $context, $USER->id, false)
if (empty($USER->id)) {
return false;
} else {
return (has_capability('moodle/legacy:coursecreator', $context, $USER->id, false)
or has_capability('moodle/legacy:admin', $context, $USER->id, false));
}
} else {
return (has_capability('moodle/legacy:coursecreator', $context, $userid, false)
or has_capability('moodle/legacy:admin', $context, $userid, false));
Expand Down Expand Up @@ -2227,7 +2241,11 @@ function isstudent($courseid, $userid=0) {
}

if (!$userid) {
return has_capability('moodle/legacy:student', $context, $USER->id, false);
if (empty($USER->id)) {
return false;
} else {
return has_capability('moodle/legacy:student', $context, $USER->id, false);
}
} else {
return has_capability('moodle/legacy:student', $context, $userid, false);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ class object {};

$SESSION = &$_SESSION['SESSION']; // Makes them easier to reference
$USER = &$_SESSION['USER'];
if (!isset($USER->id)) {
$USER->id = 0; // to enable proper function of $CFG->notloggedinroleid hack
}
}
else {
$SESSION = NULL;
Expand Down

0 comments on commit 35a518c

Please sign in to comment.