From 3d8ef99d9e9c7706c0045e6bc0b0a5e2c70073c1 Mon Sep 17 00:00:00 2001 From: vinkmar Date: Fri, 18 Aug 2006 22:00:37 +0000 Subject: [PATCH] Blocks fixed in admin pagelib, and (hopefully) many notices pointed out in the general forum board no longer show up. --- admin/adminlib.php | 23 ++++++++++++++++---- admin/pagelib.php | 16 ++++++++------ admin/settings.php | 14 ++++++++++++ admin/settings/authenticationandsecurity.php | 6 ++++- admin/settings/first.php | 4 ++++ 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/admin/adminlib.php b/admin/adminlib.php index a05b7015be..3b237f9f5b 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 68513d3333..f6d3637602 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 = '' . '
'. - ''. + ''. ''. '
'; @@ -106,7 +108,7 @@ class page_admin extends page_base { $buttons = ' '; } -/*ML*/ print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection), $SITE->fullname, implode(" -> ",$this->visiblepathtosection),'', '', true, $buttons, ''); + print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection), $SITE->fullname, implode(" -> ",$this->visiblepathtosection),'', '', true, $buttons, ''); } function get_type() { diff --git a/admin/settings.php b/admin/settings.php index 284afdec4b..8bd595b666 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -15,6 +15,20 @@ if ($site = get_site()) { //d require_login(); //d } //d +$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; + } +} + // Question: what pageid should be used for this? define('TEMPORARY_ADMIN_PAGE_ID',26); //d diff --git a/admin/settings/authenticationandsecurity.php b/admin/settings/authenticationandsecurity.php index da53020ee9..07639daccd 100644 --- a/admin/settings/authenticationandsecurity.php +++ b/admin/settings/authenticationandsecurity.php @@ -2,8 +2,12 @@ // This file defines settingpages and externalpages under the "authenticationandsecurity" category +global $USER; - +// this depends on what file is including us +if (!isset($site)) { + $site = get_site(); +} // stuff under the "usermanagement" subcategory $ADMIN->add('authenticationandsecurity', new admin_category('usermanagement', get_string('usermanagement', 'admin')), 0); diff --git a/admin/settings/first.php b/admin/settings/first.php index f648f15eaa..15811e3292 100644 --- a/admin/settings/first.php +++ b/admin/settings/first.php @@ -24,6 +24,10 @@ $ADMIN->add('plugins', new admin_externalpage('modulemanagement', get_string('mo $ADMIN->add('root', new admin_category('unsorted', 'Unsorted', 999)); +if (!isset($site)) { + $site = get_site(); +} + $ADMIN->add('unsorted', new admin_externalpage('sitefiles', get_string('sitefiles'), $CFG->wwwroot . '/files/index.php?id=' . $site->id)); $ADMIN->add('unsorted', new admin_externalpage('stickyblocks', get_string('stickyblocks'), $CFG->wwwroot . '/admin/stickyblocks.php')); -- 2.39.5