diff --git a/admin/adminlib.php b/admin/adminlib.php index a05b7015be3..3b237f9f5b8 100644 --- a/admin/adminlib.php +++ b/admin/adminlib.php @@ -189,6 +189,7 @@ class admin_settingpage implements part_of_admin_tree { } function admin_settingpage($name, $visiblename, $role = 'moodle/legacy:admin') { + global $CFG; $this->settings = new stdClass(); $this->name = $name; $this->visiblename = $visiblename; @@ -1167,7 +1168,7 @@ class admin_setting_special_perfdebug extends admin_setting_configcheckbox { // N.B.: THIS FUNCTION HANDLES AUTHENTICATION function admin_externalpage_setup($section) { - global $CFG, $ADMIN, $PAGE, $_GET, $root; + global $CFG, $ADMIN, $PAGE, $_GET, $USER; require_once($CFG->libdir . '/blocklib.php'); require_once($CFG->dirroot . '/admin/pagelib.php'); @@ -1199,21 +1200,35 @@ function admin_externalpage_setup($section) { } if (!($root instanceof admin_externalpage)) { - error('Section does not exist, is invalid, or should not be accessed via this URL.'); + error(get_string('sectionerror','admin')); die; } // this eliminates our need to authenticate on the actual pages if (!($root->check_access())) { - error('Access denied.'); + error(get_string('accessdenied', 'admin')); die; } + $adminediting = optional_param('adminedit', PARAM_BOOL); + + if (!isset($USER->adminediting)) { + $USER->adminediting = true; + } + + if ($PAGE->user_allowed_editing()) { + if ($adminediting == 'on') { + $USER->adminediting = true; + } elseif ($adminediting == 'off') { + $USER->adminediting = false; + } + } + } function admin_externalpage_print_header() { - global $CFG, $ADMIN, $PAGE, $_GET, $root; + global $CFG, $ADMIN, $PAGE; $pageblocks = blocks_setup($PAGE); diff --git a/admin/pagelib.php b/admin/pagelib.php index 68513d33338..f6d3637602a 100644 --- a/admin/pagelib.php +++ b/admin/pagelib.php @@ -61,15 +61,17 @@ class page_admin extends page_base { // has to be fixed. i know there's a "proper" way to do this function user_is_editing() { global $USER; - return (($_GET["edit"] == 'on') && isadmin()); + return $USER->adminediting; } function url_get_path() { - global $ADMIN, $root; - if (!$root) { - $root = $ADMIN->locate($this->section); + global $ADMIN, $CFG; + $root = $ADMIN->locate($this->section); + if ($root instanceof admin_externalpage) { + return $root->url; + } else { + return ($CFG->admin . '/settings.php?section=' . $this->section); } - return $root->url; } function url_get_parameters() { // only handles parameters relevant to the admin pagetype @@ -98,7 +100,7 @@ class page_admin extends page_base { // should this rely on showblocksonmodpages in any way? after all, teachers aren't accessing this... if ($this->user_allowed_editing()) { $buttons = '
| ' . ' |