# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/admin/roles/assign.php
--- moodle/admin/roles/assign.php Base (1.122)
+++ moodle/admin/roles/assign.php Locally Modified (Based On 1.122)
@@ -37,8 +37,8 @@
 
     $contextid      = required_param('contextid',PARAM_INT);
     $roleid         = optional_param('roleid', 0, PARAM_INT);
-    $userid         = optional_param('userid', 0, PARAM_INT); // needed for user tabs
-    $courseid       = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
+    $userid         = optional_param('userid', 0, PARAM_INT); // we need this for user in user context
+    $courseid       = optional_param('courseid', 0, PARAM_INT); // we need this for user in user context
     $hidden         = optional_param('hidden', 0, PARAM_BOOL); // whether this assignment is hidden
     $extendperiod   = optional_param('extendperiod', 0, PARAM_INT);
     $extendbase     = optional_param('extendbase', 3, PARAM_INT);
@@ -60,36 +60,42 @@
     if (! $context = get_context_instance_by_id($contextid)) {
         print_error('wrongcontextid', 'error');
     }
-    $isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID;
-    $PAGE->set_context($context);
-    $contextname = print_context_name($context);
 
+    $contextcheck = clone($context);
+    // Check if this is roles management for a block
+    if ($contextcheck->contextlevel == CONTEXT_BLOCK) {
+        // It is a block so load the parent context to ensure we load the correct
+        // navigational information and keep a copy of the block context to set
+        // later on in the script
+        $contextcheck = $DB->get_record_sql('SELECT ctx.* FROM {block_instances} bi LEFT JOIN {context} ctx ON ctx.id=bi.parentcontextid WHERE bi.id=?', array($context->instanceid));
+    }
+
     $inmeta = 0;
-    if ($context->contextlevel == CONTEXT_COURSE) {
-        $courseid = $context->instanceid;
-        if ($course = $DB->get_record('course', array('id'=>$courseid))) {
+    $cm = null;
+    if ($contextcheck->contextlevel == CONTEXT_COURSE) {
+        $courseid = $contextcheck->instanceid;
+        $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
             $inmeta = $course->metacourse;
+    } else if ($contextcheck->contextlevel == CONTEXT_MODULE) {
+        $cm = get_coursemodule_from_id(false, $contextcheck->instanceid, 0, false, MUST_EXIST);
+        $courseid = $cm->course;
+        $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
+    } else if (!empty($courseid)){ // we need this for user in user context
+        $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
         } else {
-            print_error('invalidcourse', 'error');
-        }
-
-    } else if (!empty($courseid)){ // we need this for user tabs in user context
-        if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-            print_error('invalidcourse', 'error');
-        }
-
-    } else {
         $courseid = SITEID;
         $course = clone($SITE);
     }
 
 /// Check login and permissions.
-    require_login($course);
+    require_login($course, true, $cm);
     require_capability('moodle/role:assign', $context);
+    // Ensure we have the correct context set (particually for block)
+    $PAGE->set_context($context);
 
-/// These are needed early because of tabs.php
     list($assignableroles, $assigncounts, $nameswithcounts) = get_assignable_roles($context, ROLENAME_BOTH, true);
-    $overridableroles = get_overridable_roles($context, ROLENAME_BOTH);
+    $isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID;
+    $contextname = print_context_name($context);
 
 /// Make sure this user can assign this role
     if ($roleid && !isset($assignableroles[$roleid])) {
@@ -99,9 +105,6 @@
         print_error('cannotassignrolehere', '', get_context_url($context), $a);
     }
 
-/// Get some language strings
-    $straction = get_string('assignroles', 'role'); // Used by tabs.php
-
 /// Work out an appropriate page title.
     if ($roleid) {
         $a = new stdClass;
@@ -255,42 +258,21 @@
         }
     }
 
-/// Print the header and tabs
-    if ($context->contextlevel == CONTEXT_USER) {
-        $user = $DB->get_record('user', array('id'=>$userid));
-        $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
-
-        /// course header
+/// Print the header
+    if ($context->contextlevel == CONTEXT_SYSTEM) {
+        admin_externalpage_setup('assignroles', '', array('contextid' => $contextid, 'roleid' => $roleid));
+        admin_externalpage_print_header();
+    } else {
         $PAGE->set_title($title);
-        if ($courseid != SITEID) {
-            if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $courseid))) {
-                $PAGE->navbar->add(get_string('participants'), new moodle_url('/user/index.php', array('id'=>$courseid)));
-            }
-            $PAGE->set_heading($fullname);
+        if ($context->contextlevel == CONTEXT_USER) {
+            $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
+            $PAGE->set_heading(fullname($user, has_capability('moodle/site:viewfullnames', $context)));
         } else {
             $PAGE->set_heading($course->fullname);
         }
-        $PAGE->navbar->add($fullname, new moodle_url("$CFG->wwwroot/user/view.php", array('id'=>$userid,'course'=>$courseid)));
-        $PAGE->navbar->add($straction);
+        $PAGE->set_cacheable(false);
+        $PAGE->set_pagelayout('standard');
         echo $OUTPUT->header();
-
-        $showroles = 1;
-        $currenttab = 'assign';
-        include_once($CFG->dirroot.'/user/tabs.php');
-
-    } else if ($context->contextlevel == CONTEXT_SYSTEM) {
-        admin_externalpage_setup('assignroles', '', array('contextid' => $contextid, 'roleid' => $roleid));
-        admin_externalpage_print_header();
-
-    } else if ($isfrontpage) {
-        admin_externalpage_setup('frontpageroles', '', array('contextid' => $contextid, 'roleid' => $roleid));
-        admin_externalpage_print_header();
-        $currenttab = 'assign';
-        include_once('tabs.php');
-
-    } else {
-        $currenttab = 'assign';
-        include_once('tabs.php');
     }
 
     /// Print heading.
Index: moodle/admin/roles/check.php
--- moodle/admin/roles/check.php Base (1.14)
+++ moodle/admin/roles/check.php Locally Modified (Based On 1.14)
@@ -34,8 +34,8 @@
     require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php');
 
     $contextid = required_param('contextid',PARAM_INT);
-    $userid = optional_param('userid', 0, PARAM_INT); // needed for user tabs
-    $courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
+    $userid = optional_param('userid', 0, PARAM_INT); // Used for user context
+    $courseid = optional_param('courseid', 0, PARAM_INT); // we need this for user in user context
     $returnurl      = optional_param('returnurl', null, PARAM_LOCALURL);
 
     $urlparams = array('contextid' => $contextid);
@@ -53,37 +53,40 @@
     if (! $context = get_context_instance_by_id($contextid)) {
         print_error('wrongcontextid', 'error');
     }
-    $isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID;
-    $contextname = print_context_name($context);
 
-    if ($context->contextlevel == CONTEXT_COURSE) {
-        $courseid = $context->instanceid;
-        if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-            print_error('invalidcourse', 'error');
+    $contextcheck = clone($context);
+    // Check if this is roles management for a block
+    if ($contextcheck->contextlevel == CONTEXT_BLOCK) {
+        // It is a block so load the parent context to ensure we load the correct
+        // navigational information and keep a copy of the block context to set
+        // later on in the script
+        $contextcheck = $DB->get_record_sql('SELECT ctx.* FROM {block_instances} bi LEFT JOIN {context} ctx ON ctx.id=bi.parentcontextid WHERE bi.id=?', array($context->instanceid));
         }
 
-    } else if (!empty($courseid)){ // we need this for user tabs in user context
-        if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-            print_error('invalidcourse', 'error');
-        }
-
+    $cm = null;
+    if ($contextcheck->contextlevel == CONTEXT_COURSE) {
+        $courseid = $contextcheck->instanceid;
+        $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
+    } else if ($contextcheck->contextlevel == CONTEXT_MODULE) {
+        $cm = get_coursemodule_from_id(false, $contextcheck->instanceid, 0, false, MUST_EXIST);
+        $courseid = $cm->course;
+        $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
+    } else if (!empty($courseid)){ // we need this for user in user context
+        $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
     } else {
         $courseid = SITEID;
         $course = clone($SITE);
     }
 
 /// Check login and permissions.
-    require_login($course);
-    $canview = has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride',
-            'moodle/role:override', 'moodle/role:manage'), $context);
+    require_login($course, true, $cm);
+    $canview = has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride','moodle/role:override', 'moodle/role:manage'), $context);
     if (!$canview) {
         print_error('nopermissions', 'error', '', get_string('checkpermissions', 'role'));
     }
+    // Ensure we have the correct context set (particually for block)
+    $PAGE->set_context($context);
 
-/// These are needed early because of tabs.php
-    $assignableroles = get_assignable_roles($context, ROLENAME_BOTH);
-    $overridableroles = get_overridable_roles($context, ROLENAME_BOTH);
-
 /// Get the user_selector we will need.
 /// Teachers within a course just get to see the same list of people they can
 /// assign roles to. Admins (people with moodle/role:manage) can run this report for any user.
@@ -96,45 +99,26 @@
     $userselector->set_multiselect(false);
     $userselector->set_rows(10);
 
+    $isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID;
+    $contextname = print_context_name($context);
 /// Work out an appropriate page title.
     $title = get_string('checkpermissionsin', 'role', $contextname);
-    $straction = get_string('checkpermissions', 'role'); // Used by tabs.php
 
-/// Print the header and tabs
-    if ($context->contextlevel == CONTEXT_USER) {
-        $user = $DB->get_record('user', array('id' => $userid));
-        $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
-
+/// Print the header
+    if ($context->contextlevel == CONTEXT_SYSTEM) {
+        admin_externalpage_setup('checkpermissions', '', array('contextid' => $contextid));
+        admin_externalpage_print_header();
+    } else {
         $PAGE->set_title($title);
-        if ($courseid != SITEID) {
-            if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $courseid))) {
-                $PAGE->navbar->add(get_string('participants'), new moodle_url('/user/index.php', array('id'=>$courseid)));
-            }
-            $PAGE->set_heading($fullname);
+        if ($context->contextlevel == CONTEXT_USER) {
+            $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
+            $PAGE->set_heading(fullname($user, has_capability('moodle/site:viewfullnames', $context)));
         } else {
             $PAGE->set_heading($course->fullname);
         }
-        $PAGE->navbar->add($fullname, new moodle_url("$CFG->wwwroot/user/view.php", array('id'=>$userid,'course'=>$courseid)));
-        $PAGE->navbar->add($straction);
+        $PAGE->set_cacheable(false);
+        $PAGE->set_pagelayout('standard');
         echo $OUTPUT->header();
-
-        $showroles = 1;
-        $currenttab = 'check';
-        include_once($CFG->dirroot.'/user/tabs.php');
-
-    } else if ($context->contextlevel == CONTEXT_SYSTEM) {
-        admin_externalpage_setup('checkpermissions', '', array('contextid' => $contextid));
-        admin_externalpage_print_header();
-
-    } else if ($context->contextlevel == CONTEXT_COURSE and $context->instanceid == SITEID) {
-        admin_externalpage_setup('frontpageroles', '', array('contextid' => $contextid), $CFG->wwwroot . '/' . $CFG->admin . '/roles/check.php');
-        admin_externalpage_print_header();
-        $currenttab = 'check';
-        include_once('tabs.php');
-
-    } else {
-        $currenttab = 'check';
-        include_once('tabs.php');
     }
 
 /// Print heading.
Index: moodle/admin/roles/override.php
--- moodle/admin/roles/override.php Base (1.79)
+++ moodle/admin/roles/override.php Locally Modified (Based On 1.79)
@@ -33,11 +33,11 @@
     require_once(dirname(__FILE__) . '/../../config.php');
     require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php');
 
-    $contextid = required_param('contextid', PARAM_INT);   // context id
-    $roleid = optional_param('roleid', 0, PARAM_INT);   // requested role id
-    $userid = optional_param('userid', 0, PARAM_INT);   // needed for user tabs
-    $courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
-    $returnurl      = optional_param('returnurl', null, PARAM_LOCALURL);
+    $contextid =    required_param('contextid', PARAM_INT);   // context id
+    $roleid =       optional_param('roleid', 0, PARAM_INT);   // requested role id
+    $userid =       optional_param('userid', 0, PARAM_INT);   // we need this for user in user context
+    $courseid =     optional_param('courseid', 0, PARAM_INT); // we need this for user in user context
+    $returnurl    = optional_param('returnurl', null, PARAM_LOCALURL);
 
 /// Get the base URL for this and related pages into a convenient variable.
     $urlparams = array('contextid' => $contextid);
@@ -57,34 +57,44 @@
     if (!$context = $DB->get_record('context', array('id'=>$contextid))) {
         print_error('wrongcontextid', 'error');
     }
-    $isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID;
-    $contextname = print_context_name($context);
 
     if ($context->contextlevel == CONTEXT_SYSTEM) {
         print_error('cannotoverridebaserole', 'error');
     }
 
-/// Validate the courseid parameter.
-    if ($context->contextlevel == CONTEXT_COURSE) {
-        $courseid = $context->instanceid;
-        if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-            print_error('invalidcourse');
+    $contextcheck = clone($context);
+    // Check if this is roles management for a block
+    if ($contextcheck->contextlevel == CONTEXT_BLOCK) {
+        // It is a block so load the parent context to ensure we load the correct
+        // navigational information and keep a copy of the block context to set
+        // later on in the script
+        $contextcheck = $DB->get_record_sql('SELECT ctx.* FROM {block_instances} bi LEFT JOIN {context} ctx ON ctx.id=bi.parentcontextid WHERE bi.id=?', array($context->instanceid));
         }
-    } if ($courseid) { // we need this for user tabs in user context
-        if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-            print_error('invalidcourse');
-        }
+
+/// Validate the courseid parameter.
+    $cm = null;
+    if ($contextcheck->contextlevel == CONTEXT_COURSE) {
+        $courseid = $contextcheck->instanceid;
+        $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
+    } else if ($contextcheck->contextlevel == CONTEXT_MODULE) {
+        $cm = get_coursemodule_from_id(false, $contextcheck->instanceid, 0, false, MUST_EXIST);
+        $courseid = $cm->course;
+        $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
+    } else if (!empty($courseid)){ // we need this for user in user context
+        $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
     } else {
-        $course = clone($SITE);
         $courseid = SITEID;
+        $course = clone($SITE);
     }
 
 /// Check access permissions.
-    require_login($course);
+    require_login($course, true, $cm);
     $safeoverridesonly = !has_capability('moodle/role:override', $context);
     if ($safeoverridesonly) {
         require_capability('moodle/role:safeoverride', $context);
     }
+    // Ensure we have the correct context set (particually for block)
+    $PAGE->set_context($context);
 
 /// Handle the cancel button.
     if (optional_param('cancel', false, PARAM_BOOL)) {
@@ -98,9 +108,9 @@
         set_user_preference('overridepermissions_showadvanced', $showadvanced);
     }
 
-/// These are needed early because of tabs.php
-    $assignableroles  = get_assignable_roles($context, ROLENAME_BOTH);
     list($overridableroles, $overridecounts, $nameswithcounts) = get_overridable_roles($context, ROLENAME_BOTH, true);
+    $isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID;
+    $contextname = print_context_name($context);
 
 /// Make sure this user can override that role
     if ($roleid && !isset($overridableroles[$roleid])) {
@@ -142,39 +152,17 @@
         }
     }
 
-    /// Print the header and tabs
-    $straction = get_string('overrideroles', 'role'); // Used by tabs.php
-    if ($context->contextlevel == CONTEXT_USER) {
-        $user = $DB->get_record('user', array('id'=>$userid));
-        $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
-
+    /// Print the header
         $PAGE->set_title($title);
-        if ($courseid != SITEID) {
-            if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $course->id))) {
-                $PAGE->navbar->add(get_string('participants'), new moodle_url('/user/index.php', array('id'=>$course->id)));
-            }
-            $PAGE->set_heading($fullname);
+    if ($context->contextlevel == CONTEXT_USER) {
+        $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
+        $PAGE->set_heading(fullname($user, has_capability('moodle/site:viewfullnames', $context)));
         } else {
             $PAGE->set_heading($course->fullname);
         }
-        $PAGE->navbar->add($fullname, new moodle_url("$CFG->wwwroot/user/view.php", array('id'=>$userid,'course'=>$courseid)));
-        $PAGE->navbar->add($straction);
+    $PAGE->set_cacheable(false);
+    $PAGE->set_pagelayout('standard');
         echo $OUTPUT->header();
-
-        $showroles = 1;
-        $currenttab = 'override';
-        include_once($CFG->dirroot.'/user/tabs.php');
-    } else if ($context->contextlevel==CONTEXT_COURSE and $context->instanceid == SITEID) {
-        require_once($CFG->libdir.'/adminlib.php');
-        admin_externalpage_setup('frontpageroles', '', array('contextid' => $contextid, 'roleid' => $roleid), $CFG->wwwroot . '/' . $CFG->admin . '/roles/override.php');
-        admin_externalpage_print_header();
-        $currenttab = 'override';
-        include_once('tabs.php');
-    } else {
-        $currenttab = 'override';
-        include_once('tabs.php');
-    }
-
     echo $OUTPUT->heading_with_help($title, 'overrides');
 
     if ($roleid) {
Index: moodle/admin/roles/tabs.php
--- moodle/admin/roles/tabs.php Base (1.58)
+++ moodle/admin/roles/tabs.php Locally Deleted
@@ -1,240 +0,0 @@
-<?php
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.org                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/**
- * Handles headers and tabs for the roles control at any level apart from SYSTEM level
- * We assume that $currenttab, $assignableroles and $overridableroles are defined
- *
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- * @package roles
- *//** */
-
-if (!defined('MOODLE_INTERNAL')) {
-    die('Direct access to this script is forbidden.'); // It must be included from a Moodle page
-}
-
-if (!isset($availablefilters)) {
-    $availablefilters  = array();
-    if (in_array($context->contextlevel, array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE)) &&
-            !($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) &&
-            has_capability('moodle/filter:manage', $context)) {
-        $availablefilters = filter_get_available_in_context($context);
-    }
-}
-
-if ($currenttab != 'update') {
-    switch ($context->contextlevel) {
-
-        case CONTEXT_SYSTEM:
-            $stradministration = get_string('administration');
-            if (empty($title)) {
-                $title = $SITE->fullname;
-            }
-            $PAGE->navbar->add($stradministration, new moodle_url('/admin/'), navigation_node::TYPE_SETTING);
-            $PAGE->navbar->add($straction);
-            $PAGE->set_title($title);
-            $PAGE->set_heading($SITE->fullname);
-            echo $OUTPUT->header();
-            break;
-
-        case CONTEXT_USER:
-            echo $OUTPUT->header();
-            break;
-
-        case CONTEXT_COURSECAT:
-            $category = $DB->get_record('course_categories', array('id'=>$context->instanceid));
-            $strcategories = get_string("categories");
-            $strcategory = get_string("category");
-            $strcourses = get_string("courses");
-
-            if (empty($title)) {
-                $title = "$SITE->shortname: $category->name";
-            }
-
-            $PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'), navigation_node::TYPE_SETTING);
-            $PAGE->navbar->add($category->name, new moodle_url('/course/category.php', array('id'=>$category->id)), navigation_node::TYPE_SETTING);
-            $PAGE->navbar->add(get_string("roles"));
-            $PAGE->set_title($title);
-            $PAGE->set_heading("$SITE->fullname: $strcourses");
-            echo $OUTPUT->header();
-            break;
-
-        case CONTEXT_COURSE:
-            if ($context->instanceid != SITEID) {
-                $course = $DB->get_record('course', array('id'=>$context->instanceid));
-
-                require_login($course);
-                if (empty($title)) {
-                    $title = get_string("editcoursesettings");
-                }
-                $roleslink = new moodle_url("$CFG->wwwroot/$CFG->admin/roles/assign.php", array('contextid'=>$context->id));
-                $PAGE->navbar->add(get_string('roles'), $roleslink, navigation_node::TYPE_SETTING);
-                $PAGE->set_title($title);
-                $PAGE->set_heading($course->fullname);
-                echo $OUTPUT->header();
-            }
-            break;
-
-        case CONTEXT_MODULE:
-            if (!$cm = get_coursemodule_from_id('', $context->instanceid)) {
-                print_error('invalidcoursemodule', 'error');
-            }
-            if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
-                print_error('invalidcourse');
-            }
-
-            require_login($course);
-
-            $PAGE->navigation->add(get_string('roles'));
-
-            if (empty($title)) {
-                $title = get_string("editinga", "moodle", $fullmodulename);
-            }
-            $PAGE->set_title($title);
-            $PAGE->set_cacheable(false);
-            echo $OUTPUT->header();
-            break;
-
-        case CONTEXT_BLOCK:
-            if ($blockinstance = $DB->get_record('block_instances', array('id' => $context->instanceid))) {
-                $blockname = print_context_name($context);
-
-                $parentcontext = get_context_instance_by_id($blockinstance->parentcontextid);
-                switch ($parentcontext->contextlevel) {
-                    case CONTEXT_SYSTEM:
-                        break;
-
-                    case CONTEXT_COURSECAT:
-                        $PAGE->set_category_by_id($parentcontext->instanceid);
-                        break;
-
-                    case CONTEXT_COURSE:
-                        require_login($parentcontext->instanceid);
-                        break;
-
-                    case CONTEXT_MODULE:
-                        $cm = get_coursemodule_from_id('', $parentcontext->instanceid);
-                        require_login($parentcontext->instanceid, false, $cm);
-                        break;
-
-                    case CONTEXT_USER:
-                        break;
-
-                    default:
-                        throw new invalid_state_exception('Block context ' . $blockname .
-                                ' has parent context with an improper contextlevel ' . $parentcontext->contextlevel);
-
-
-                }
-                $PAGE->navbar->add($blockname);
-                $PAGE->navbar->add($straction);
-                $PAGE->set_title("$straction: $blockname");
-                $PAGE->set_heading($PAGE->course->fullname);
-                echo $OUTPUT->header();
-            }
-            break;
-
-        default:
-            print_error('unknowncontext');
-            return false;
-
-    }
-}
-
-
-$toprow = array();
-$inactive = array();
-$activetwo = array();
-
-
-if ($context->contextlevel != CONTEXT_SYSTEM) {    // Print tabs for anything except SYSTEM context
-
-    if (!empty($returnurl)) {
-        $returnurlparam = '&amp;returnurl=' . $returnurl;
-    } else {
-        $returnurlparam = '';
-    }
-
-    if ($context->contextlevel == CONTEXT_MODULE) {  // Only show update button if module
-        $toprow[] = new tabobject('update', $CFG->wwwroot.'/course/mod.php?update='.
-                        $context->instanceid.'&amp;return=true&amp;sesskey='.sesskey(), get_string('settings'));
-    }
-
-    if (!empty($assignableroles) || $currenttab=='assign') {
-        $toprow[] = new tabobject('assign',
-                $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.$returnurlparam,
-                get_string('localroles', 'role'), '', true);
-    }
-
-    if (!empty($overridableroles)) {
-        $toprow[] = new tabobject('override',
-                $CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$context->id.$returnurlparam,
-                get_string('overridepermissions', 'role'), '', true);
-    }
-
-    if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride',
-            'moodle/role:override', 'moodle/role:assign'), $context)) {
-        $toprow[] = new tabobject('check',
-                $CFG->wwwroot.'/'.$CFG->admin.'/roles/check.php?contextid='.$context->id.$returnurlparam,
-                get_string('checkpermissions', 'role'));
-    }
-
-    if (!empty($availablefilters)) {
-        $toprow[] = new tabobject('filters',
-                $CFG->wwwroot.'/filter/manage.php?contextid=' . $context->id,
-                get_string('filters', 'admin'));
-    }
-}
-
-/// Here other core tabs should go (always calling tabs.php files)
-/// All the logic to decide what to show must be self-contained in the tabs file
-/// eg:
-/// include_once($CFG->dirroot . '/grades/tabs.php');
-
-/// Finally, we support adding some 'on-the-fly' tabs here
-/// All the logic to decide what to show must be self-cointained in the tabs file
-    if (!empty($CFG->extratabs)) {
-        if ($extratabs = explode(',', $CFG->extratabs)) {
-            asort($extratabs);
-            foreach($extratabs as $extratab) {
-            /// Each extra tab must be one $CFG->dirroot relative file
-                if (file_exists($CFG->dirroot . '/' . $extratab)) {
-                    include_once($CFG->dirroot . '/' . $extratab);
-                }
-            }
-        }
-    }
-
-    $inactive[] = $currenttab;
-
-    $tabs = array($toprow);
-
-/// If there are any secondrow defined, let's introduce it
-    if (isset($secondrow) && is_array($secondrow) && !empty($secondrow)) {
-        $tabs[] = $secondrow;
-    }
-
-    print_tabs($tabs, $currenttab, $inactive, $activetwo);
-
Index: moodle/admin/roles/usersroles.php
--- moodle/admin/roles/usersroles.php Base (1.15)
+++ moodle/admin/roles/usersroles.php Locally Modified (Based On 1.15)
@@ -126,14 +126,10 @@
 $PAGE->set_title($title);
 if ($courseid != SITEID) {
     $PAGE->set_heading($fullname);
-    if (has_capability('moodle/course:viewparticipants', $coursecontext)) {
-        $PAGE->navbar->add(get_string('participants'),new moodle_url('/user/index.php', array('id'=>$courseid)));
-    }
 } else {
     $PAGE->set_heading($course->fullname);
+    $PAGE->set_pagelayout('standard');
 }
-$PAGE->navbar->add($fullname, new moodle_url("$CFG->wwwroot/user/view.php", array('id'=>$userid,'course'=>$courseid)));
-$PAGE->navbar->add($straction);
 echo $OUTPUT->header();
 
 $showroles = 1;
Index: moodle/admin/settings/appearance.php
--- moodle/admin/settings/appearance.php Base (1.54)
+++ moodle/admin/settings/appearance.php Locally Modified (Based On 1.54)
@@ -146,3 +146,49 @@
 
 } // end of speedup
 
+$frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
+if ($hassiteconfig or has_any_capability(array('moodle/course:update'), $frontpagecontext)) {
+
+    // "frontpage" settingpage
+    $temp = new admin_settingpage('frontpagesettings', get_string('frontpagesettings','admin'), 'moodle/course:update', false, $frontpagecontext);
+    $temp->add(new admin_setting_sitesettext('fullname', get_string('fullsitename'), '', NULL)); // no default
+    $temp->add(new admin_setting_sitesettext('shortname', get_string('shortsitename'), '', NULL)); // no default
+    $temp->add(new admin_setting_special_frontpagedesc());
+    $temp->add(new admin_setting_courselist_frontpage(false)); // non-loggedin version of the setting (that's what the parameter is for :) )
+    $temp->add(new admin_setting_courselist_frontpage(true)); // loggedin version of the setting
+
+    $options = array();
+    $options[] = get_string('unlimited');
+    for ($i=1; $i<100; $i++) {
+        $options[$i] = $i;
+    }
+    $temp->add(new admin_setting_configselect('maxcategorydepth', get_string('configsitemaxcategorydepth','admin'), get_string('configsitemaxcategorydepthhelp','admin'), 0, $options));
+
+    $temp->add(new admin_setting_sitesetcheckbox('numsections', get_string('sitesection'), get_string('sitesectionhelp','admin'), 1));
+    $temp->add(new admin_setting_sitesetselect('newsitems', get_string('newsitemsnumber'), '', 3,
+         array('0' => '0',
+               '1' => '1',
+               '2' => '2',
+               '3' => '3',
+               '4' => '4',
+               '5' => '5',
+               '6' => '6',
+               '7' => '7',
+               '8' => '8',
+               '9' => '9',
+               '10' => '10')));
+    $temp->add(new admin_setting_configtext('coursesperpage', get_string('coursesperpage', 'admin'), get_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
+    $temp->add(new admin_setting_configcheckbox('allowvisiblecoursesinhiddencategories', get_string('allowvisiblecoursesinhiddencategories', 'admin'), get_string('configvisiblecourses', 'admin'), 0));
+
+    // front page default role
+    $roleoptions = array(0=>get_string('none')); // roles to choose from
+    if ($roles = get_all_roles()) {
+        foreach ($roles as $role) {
+            $roleoptions[$role->id] = strip_tags(format_string($role->name, true));
+        }
+    }
+    $temp->add(new admin_setting_configselect('defaultfrontpageroleid', get_string('frontpagedefaultrole', 'admin'), '', 0, $roleoptions));
+
+    $ADMIN->add('appearance', $temp);
+}
+
Index: moodle/admin/settings/frontpage.php
--- moodle/admin/settings/frontpage.php Base (1.18)
+++ moodle/admin/settings/frontpage.php Locally Deleted
@@ -1,84 +0,0 @@
-<?php
-
-// This file defines everything related to frontpage
-
-if (!during_initial_install()) { //do not use during installation
-    $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
-
-    if ($hassiteconfig or has_any_capability(array(
-            'moodle/course:update',
-            'moodle/role:assign',
-            'moodle/restore:restorecourse',
-            'moodle/backup:backupcourse',
-            'moodle/course:managefiles',
-            'moodle/question:add',
-            'moodle/question:editmine',
-            'moodle/question:editall',
-            'moodle/question:viewmine',
-            'moodle/question:viewall',
-            'moodle/question:movemine',
-            'moodle/question:moveall'), $frontpagecontext)) {
-
-        // "frontpage" settingpage
-        $temp = new admin_settingpage('frontpagesettings', get_string('frontpagesettings','admin'), 'moodle/course:update', false, $frontpagecontext);
-        $temp->add(new admin_setting_sitesettext('fullname', get_string('fullsitename'), '', NULL)); // no default
-        $temp->add(new admin_setting_sitesettext('shortname', get_string('shortsitename'), '', NULL)); // no default
-        $temp->add(new admin_setting_special_frontpagedesc());
-        $temp->add(new admin_setting_courselist_frontpage(false)); // non-loggedin version of the setting (that's what the parameter is for :) )
-        $temp->add(new admin_setting_courselist_frontpage(true)); // loggedin version of the setting
-
-        $options = array();
-        $options[] = get_string('unlimited');
-        for ($i=1; $i<100; $i++) {
-            $options[$i] = $i;
-        }
-        $temp->add(new admin_setting_configselect('maxcategorydepth', get_string('configsitemaxcategorydepth','admin'), get_string('configsitemaxcategorydepthhelp','admin'), 0, $options));
-
-        $temp->add(new admin_setting_sitesetcheckbox('numsections', get_string('sitesection'), get_string('sitesectionhelp','admin'), 1));
-        $temp->add(new admin_setting_sitesetselect('newsitems', get_string('newsitemsnumber'), '', 3,
-             array('0' => '0',
-                   '1' => '1',
-                   '2' => '2',
-                   '3' => '3',
-                   '4' => '4',
-                   '5' => '5',
-                   '6' => '6',
-                   '7' => '7',
-                   '8' => '8',
-                   '9' => '9',
-                   '10' => '10')));
-        $temp->add(new admin_setting_configtext('coursesperpage', get_string('coursesperpage', 'admin'), get_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
-        $temp->add(new admin_setting_configcheckbox('allowvisiblecoursesinhiddencategories', get_string('allowvisiblecoursesinhiddencategories', 'admin'), get_string('configvisiblecourses', 'admin'), 0));
-
-        // front page default role
-        $roleoptions = array(0=>get_string('none')); // roles to choose from
-        if ($roles = get_all_roles()) {
-            foreach ($roles as $role) {
-                $roleoptions[$role->id] = strip_tags(format_string($role->name, true));
-            }
-        }
-        $temp->add(new admin_setting_configselect('defaultfrontpageroleid', get_string('frontpagedefaultrole', 'admin'), '', 0, $roleoptions));
-
-        $ADMIN->add('frontpage', $temp);
-
-        $ADMIN->add('frontpage', new admin_externalpage('frontpageroles', get_string('frontpageroles', 'admin'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=" . $frontpagecontext->id, 'moodle/role:assign', false, $frontpagecontext));
-
-        $ADMIN->add('frontpage', new admin_externalpage('frontpagefilters', get_string('frontpagefilters', 'admin'), "$CFG->wwwroot/filter/manage.php?contextid=" . $frontpagecontext->id, 'moodle/filter:manage', false, $frontpagecontext));
-
-        $ADMIN->add('frontpage', new admin_externalpage('frontpagebackup', get_string('frontpagebackup', 'admin'), $CFG->wwwroot.'/backup/backup.php?id='.SITEID, 'moodle/backup:backupcourse', false, $frontpagecontext));
-
-        $ADMIN->add('frontpage', new admin_externalpage('frontpagerestore', get_string('frontpagerestore', 'admin'), $CFG->wwwroot.'/files/index.php?id='.SITEID.'&amp;wdir=/backupdata', 'moodle/restore:restorecourse', false, $frontpagecontext));
-
-        $questioncapabilites = array(
-                'moodle/question:add',
-                'moodle/question:editmine',
-                'moodle/question:editall',
-                'moodle/question:viewmine',
-                'moodle/question:viewall',
-                'moodle/question:movemine',
-                'moodle/question:moveall');
-        $ADMIN->add('frontpage', new admin_externalpage('frontpagequestions', get_string('frontpagequestions', 'admin'), $CFG->wwwroot.'/question/edit.php?courseid='.SITEID, $questioncapabilites, false, $frontpagecontext));
-
-        $ADMIN->add('frontpage', new admin_externalpage('sitefiles', get_string('sitefiles'), $CFG->wwwroot . '/files/index.php?id=' . SITEID, 'moodle/course:managefiles', false, $frontpagecontext));
-    }
-}
Index: moodle/course/editcategory.php
--- moodle/course/editcategory.php Base (1.31)
+++ moodle/course/editcategory.php Locally Modified (Based On 1.31)
@@ -20,6 +20,7 @@
     $PAGE->set_url('/course/editcategory.php', array('id' => $id));
     $categorycontext = get_context_instance(CONTEXT_COURSECAT, $id);
     require_capability('moodle/category:manage', $categorycontext);
+    $PAGE->set_context($categorycontext);
     $strtitle = get_string('editcategorysettings');
     $editorcontext = $categorycontext;
 } else {
@@ -30,6 +31,7 @@
             print_error('unknowcategory');
         }
         $context = get_context_instance(CONTEXT_COURSECAT, $parent);
+        $PAGE->set_context($context);
     } else {
         $context = get_system_context();
     }
@@ -96,13 +98,9 @@
 $navlinks = array();
 
 if ($id) {
-    $PAGE->navbar->add($strtitle);
     $title = $strtitle;
     $fullname = $category->name;
 } else {
-    $PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php'));
-    $PAGE->navbar->add($strcategories, new moodle_url('/course/index.php'));
-    $PAGE->navbar->add($straddnewcategory);
     $title = "$SITE->shortname: $straddnewcategory";
     $fullname = $SITE->fullname;
 }
@@ -116,4 +114,3 @@
 $mform->display();
 
 echo $OUTPUT->footer();
-
Index: moodle/course/modedit.php
--- moodle/course/modedit.php Base (1.90)
+++ moodle/course/modedit.php Locally Modified (Based On 1.90)
@@ -598,25 +598,13 @@
         $streditinga = get_string('editinga', 'moodle', $fullmodulename);
         $strmodulenameplural = get_string('modulenameplural', $module->name);
 
-        $PAGE->navbar->add($streditinga);
         $PAGE->set_heading($course->fullname);
         $PAGE->set_title($streditinga);
         $PAGE->set_focuscontrol($mform->focus());
         $PAGE->set_cacheable(false);
-        $PAGE->set_pagelayout('admin');
+        $PAGE->set_pagelayout('standard');
         echo $OUTPUT->header();
-
-        if (!empty($cm->id)) {
-            $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-            $overridableroles = get_overridable_roles($context);
-            $assignableroles  = get_assignable_roles($context);
-            $currenttab = 'update';
-            require($CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php');
-        }
-
         echo $OUTPUT->heading_with_help($pageheading, 'mods', $module->name, 'icon');
-
         $mform->display();
-
         echo $OUTPUT->footer();
     }
Index: moodle/filter/manage.php
--- moodle/filter/manage.php Base (1.11)
+++ moodle/filter/manage.php Locally Modified (Based On 1.11)
@@ -40,8 +40,8 @@
     print_error('wrongcontextid', 'error');
 }
 
-$args = array('contextid'=>$contextid);
-$baseurl = new moodle_url('/filter/manage.php', $args);
+$args = array();
+$baseurl = new moodle_url('/filter/manage.php', array('contextid'=>$contextid));
 if (!empty($forfilter)) {
     $args['filter'] = $forfilter;
 }
@@ -55,21 +55,19 @@
 $isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID;
 $contextname = print_context_name($context);
 
+$cm = null;
 if ($context->contextlevel == CONTEXT_COURSECAT) {
     $course = clone($SITE);
 } else if ($context->contextlevel == CONTEXT_COURSE) {
-    $course = $DB->get_record('course', array('id' => $context->instanceid));
+    $course = $DB->get_record('course', array('id' => $context->instanceid), '*', MUST_EXIST);
 } else {
     // Must be module context.
-    $course = $DB->get_record_sql('SELECT c.* FROM {course} c JOIN {context} ctx ON c.id = ctx.instanceid WHERE ctx.id = ?',
-            array(get_parent_contextid($context)));
+    $cm = get_coursemodule_from_id(false, $context->instanceid);
+    $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
 }
-if (!$course) {
-    print_error('invalidcourse', 'error');
-}
 
 /// Check login and permissions.
-require_login($course);
+require_login($course, true, $cm);
 require_capability('moodle/filter:manage', $context);
 
 /// Get the list of available filters.
@@ -119,16 +117,13 @@
 } else {
     $title = get_string('filtersettingsin', 'filters', $contextname);
 }
-$straction = get_string('filters', 'admin'); // Used by tabs.php
 
 /// Print the header and tabs
-if ($context->contextlevel == CONTEXT_COURSE and $context->instanceid == SITEID) {
-    admin_externalpage_setup('frontpagefilters');
-    admin_externalpage_print_header();
-} else {
-    $currenttab = 'filters';
-    include_once($CFG->dirroot . '/' . $CFG->admin . '/roles/tabs.php');
-}
+$PAGE->set_title($title);
+$PAGE->set_heading($course->fullname);
+$PAGE->set_cacheable(false);
+$PAGE->set_pagelayout('standard');
+echo $OUTPUT->header();
 
 /// Print heading.
 echo $OUTPUT->heading_with_help($title, 'localfiltersettings');
Index: moodle/lib/blocklib.php
--- moodle/lib/blocklib.php Base (1.239)
+++ moodle/lib/blocklib.php Locally Modified (Based On 1.239)
@@ -1059,6 +1059,9 @@
         $editpage = new moodle_page();
         $editpage->set_pagelayout('admin');
         $editpage->set_course($this->page->course);
+        if ($this->page->cm) {
+            $editpage->set_cm($this->page->cm);
+        }
         $editpage->set_context($block->context);
         $editurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring());
         $editurlparams = $this->page->url->params();
Index: moodle/lib/navigationlib.php
--- moodle/lib/navigationlib.php Base (1.82)
+++ moodle/lib/navigationlib.php Locally Modified (Based On 1.82)
@@ -1167,7 +1167,7 @@
      */
     protected function load_for_category($lookforid=true) {
         global $PAGE, $CFG;
-        $id = optional_param('id', null);
+        $id = optional_param('id', null, PARAM_INT);
         if ($lookforid && $id!==null) {
             if (!empty($CFG->navshowallcourses)) {
                 $this->load_categories();
@@ -2324,7 +2324,14 @@
         $output = get_accesshide(get_string('youarehere','access'), 'h2').html_writer::start_tag('ul');
 
         // Check if navigation contains the active node
-        if (!$this->ignoreactive && $this->page->navigation->contains_active_node()) {
+        if (!$this->ignoreactive && $this->page->navigation->contains_active_node() && $this->page->settingsnav->contains_active_node()) {
+            // Parse a combined navigation tree
+            $output .= $this->parse_branch_to_html($this->page->navigation->children, true, true);
+            $activenode = $this->page->settingsnav->find_active_node();
+            if ($activenode) {
+                $output .= $this->parse_branch_to_html(array($activenode), false);
+            }
+        } else if (!$this->ignoreactive && $this->page->navigation->contains_active_node()) {
             // Parse the navigation tree to get the active node
             $output .= $this->parse_branch_to_html($this->page->navigation->children, true);
         } else if (!$this->ignoreactive && $this->page->settingsnav->contains_active_node()) {
@@ -2350,7 +2357,7 @@
      * @param bool $firstnode
      * @return string HTML
      */
-    protected function parse_branch_to_html($navarray, $firstnode=true) {
+    protected function parse_branch_to_html($navarray, $firstnode=true, $morecoming=false) {
         global $CFG;
         $separator = get_separator();
         $output = '';
@@ -2391,7 +2398,7 @@
                 $navarray = $child->children;
                 // If there are not more arrays being processed after this AND this is the last element
                 // then we want to set the action to null so that it is not used
-                if (empty($this->children) && (!$child->contains_active_node() || ($child->find_active_node()==false || $child->find_active_node()->mainnavonly))) {
+                if (empty($this->children) && !$morecoming && (!$child->contains_active_node() || ($child->find_active_node()==false || $child->find_active_node()->mainnavonly))) {
                     $oldaction = $child->action;
                     $child->action = null;
                 }
@@ -2480,67 +2487,56 @@
      * by calling supporting functions to generate major parts of the tree.
      */
     public function initialise() {
+        global $DB;
+        
         if (during_initial_install()) {
             return false;
         }
         $this->id = 'settingsnav';
         $this->context = $this->page->context;
-        switch ($this->context->contextlevel) {
+
+        $context = $this->context;
+        if ($context->contextlevel == CONTEXT_BLOCK) {
+            $this->load_block_settings();
+            $context = $DB->get_record_sql('SELECT ctx.* FROM {block_instances} bi LEFT JOIN {context} ctx ON ctx.id=bi.parentcontextid WHERE bi.id=?', array($context->instanceid));
+        }
+
+        switch ($context->contextlevel) {
             case CONTEXT_SYSTEM:
-                $this->cache->volatile();
-                $adminkey = $this->load_administration_settings();
-                $settingskey = $this->load_user_settings(SITEID);
+                if ($this->page->url->compare(new moodle_url('/admin/settings.php', array('section'=>'frontpagesettings')))) {
+                    $this->load_front_page_settings(($context->id == $this->context->id));
+                }
                 break;
             case CONTEXT_COURSECAT:
-                $adminkey = $this->load_administration_settings();
-                $adminnode = $this->get($adminkey);
-                if ($adminnode!==false) {
-                    $adminnode->forceopen =  true;
-                }
-                $settingskey = $this->load_user_settings(SITEID);
+                $this->load_category_settings();
                 break;
             case CONTEXT_COURSE:
-            case CONTEXT_BLOCK:
-                if ($this->page->course->id!==SITEID) {
-                    $coursekey = $this->load_course_settings();
-                    $coursenode = $this->get($coursekey);
-                    if ($coursenode!==false) {
-                        $coursenode->forceopen =  true;
-                    }
-                    $settingskey = $this->load_user_settings($this->page->course->id);
-                    $adminkey = $this->load_administration_settings();
+                if ($this->page->course->id != SITEID) {
+                    $this->load_course_settings(($context->id == $this->context->id));
                 } else {
-                    $this->load_front_page_settings();
-                    $settingskey = $this->load_user_settings(SITEID);
-                    $adminkey = $this->load_administration_settings();
+                    $this->load_front_page_settings(($context->id == $this->context->id));
                 }
                 break;
             case CONTEXT_MODULE:
-                $modulekey = $this->load_module_settings();
-                $modulenode = $this->get($modulekey);
-                if ($modulenode!==false) {
-                    $modulenode->forceopen =  true;
-                }
-                $coursekey = $this->load_course_settings();
-                $settingskey = $this->load_user_settings($this->page->course->id);
-                $adminkey = $this->load_administration_settings();
+                $this->load_module_settings();
+                $this->load_course_settings();
                 break;
             case CONTEXT_USER:
-                $settingskey = $this->load_user_settings($this->page->course->id);
-                $settingsnode = $this->get($settingskey);
-                if ($settingsnode!==false) {
-                    $settingsnode->forceopen =  true;
-                }
                 if ($this->page->course->id!==SITEID) {
-                    $coursekey = $this->load_course_settings();
+                    $this->load_course_settings();
                 }
-                $adminkey = $this->load_administration_settings();
                 break;
-            default:
-                debugging('An unknown context has passed into settings_navigation::initialise', DEBUG_DEVELOPER);
-                break;
         }
 
+        $settingskey = $this->load_user_settings($this->page->course->id);
+        $adminkey = $this->load_administration_settings();
+
+        if ($context->contextlevel == CONTEXT_SYSTEM) {
+            $this->get($adminkey)->forceopen = true;
+        } else if ($context->contextlevel == CONTEXT_USER) {
+            $this->get($settingskey)->forceopen = true;
+        }
+
         // Check if the user is currently logged in as another user
         if (session_is_loggedinas()) {
             // Get the actual user, we need this so we can display an informative return link
@@ -2740,9 +2736,10 @@
     /**
      * This function loads the course settings that are available for the user
      *
+     * @param bool $forceopen If set to true the course node will be forced open
      * @return bool|mixed Either false of a key to access the course tree by
      */
-    protected function load_course_settings() {
+    protected function load_course_settings($forceopen = false) {
         global $CFG, $USER, $SESSION;
 
         $course = $this->page->course;
@@ -2759,10 +2756,9 @@
             return false;
         }
 
-        $coursenode = $this->page->navigation->find_child($course->id, global_navigation::TYPE_COURSE);
-
-        $coursenodekey = $this->add(get_string('courseadministration'), null, $coursenode->type, null, 'courseadmin');
+        $coursenodekey = $this->add(get_string('courseadministration'), null, self::TYPE_COURSE, null, 'courseadmin');
         $coursenode = $this->get($coursenodekey);
+        $coursenode->forceopen = ($forceopen==true);
 
         if (has_capability('moodle/course:update', $course->context)) {
             // Add the turn on/off settings
@@ -2862,14 +2858,26 @@
             $coursenode->add(get_string('settings'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
         }
 
-        // Add assign or override roles if allowed
         if (has_capability('moodle/role:assign', $course->context)) {
-            $url = new moodle_url('/admin/roles/assign.php', array('contextid'=>$course->context->id));
+            // Add assign or override roles if allowed
+            $url = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid'=>$course->context->id));
             $coursenode->add(get_string('assignroles', 'role'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/roles', ''));
-        } else if (get_overridable_roles($course->context, ROLENAME_ORIGINAL)) {
-            $url = new moodle_url('/admin/roles/override.php', array('contextid'=>$course->context->id));
-            $coursenode->add(get_string('overridepermissions', 'role'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/roles', ''));
+            // Override roles
+            if (count(get_overridable_roles($course->context))>0) {
+                $url = new moodle_url('/'.$CFG->admin.'/roles/override.php', array('contextid'=>$course->context->id));
+                $coursenode->add(get_string('overridepermissions', 'role'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/overrideroles', ''));
         }
+            // Check role permissions
+            if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride','moodle/role:override', 'moodle/role:assign'), $course->context)) {
+                $url = new moodle_url('/'.$CFG->admin.'/roles/check.php', array('contextid'=>$course->context->id));
+                $coursenode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/overrideroles', ''));
+            }
+            // Manage filters
+            if (has_capability('moodle/filter:manage', $course->context) && count(filter_get_available_in_context($course->context))>0) {
+                $url = new moodle_url('/filter/manage.php', array('contextid'=>$course->context->id));
+                $coursenode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', ''));
+            }
+        }
 
         // Add view grade report is permitted
         $reportavailable = false;
@@ -3049,7 +3057,7 @@
      * @return void|mixed The key to access the module method by
      */
     protected function load_module_settings() {
-        global $CFG;
+        global $CFG, $PAGE;
 
         if (!$this->page->cm && $this->context->contextlevel == CONTEXT_MODULE && $this->context->instanceid) {
             $cm = get_coursemodule_from_id('chat', $this->context->instanceid, 0, false, MUST_EXIST);
@@ -3065,6 +3073,35 @@
             }
         }
 
+        $modulekey = $this->add(get_string($this->page->activityname.'administration', $this->page->activityname));
+        $modulenode = $this->get($modulekey);
+        $modulenode->forceopen = true;
+        
+        // Settings for the module
+        if (has_capability('moodle/course:manageactivities', $this->page->cm->context)) {
+            $url = new moodle_url('/course/modedit.php', array('update' => $this->page->cm->id, 'return' => true, 'sesskey' => sesskey()));
+            $modulenode->add(get_string('settings'), $url, navigation_node::TYPE_SETTING);
+        }
+        // Assign local roles
+        if (count(get_assignable_roles($this->page->cm->context))>0) {
+            $url = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid'=>$this->page->cm->context->id));
+            $modulenode->add(get_string('localroles', 'role'), $url, self::TYPE_SETTING);
+        }
+        // Override roles
+        if (count(get_overridable_roles($this->page->cm->context))>0) {
+            $url = new moodle_url('/'.$CFG->admin.'/roles/override.php', array('contextid'=>$this->page->cm->context->id));
+            $modulenode->add(get_string('overridepermissions', 'role'), $url, self::TYPE_SETTING);
+        }
+        // Check role permissions
+        if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride','moodle/role:override', 'moodle/role:assign'), $this->page->cm->context)) {
+            $url = new moodle_url('/'.$CFG->admin.'/roles/check.php', array('contextid'=>$this->page->cm->context->id));
+            $modulenode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING);
+        }
+        // Manage filters
+        if (has_capability('moodle/filter:manage', $this->page->cm->context) && count(filter_get_available_in_context($this->page->cm->context))>0) {
+            $url = new moodle_url('/filter/manage.php', array('contextid'=>$this->page->cm->context->id));
+            $modulenode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING);
+        }
         $file = $CFG->dirroot.'/mod/'.$this->page->activityname.'/lib.php';
         $function = $this->page->activityname.'_extend_settings_navigation';
 
@@ -3072,11 +3109,18 @@
             require_once($file);
         }
         if (!function_exists($function)) {
-            return;
+            return $modulekey;
         }
-        return $function($this,$this->page->activityrecord);
+
+        $function($this, $modulenode);
+
+        if (empty($modulenode->children)) {
+            $this->remove_child($modulekey);
     }
 
+        return $modulekey;
+    }
+
     /**
      * Loads the user settings block of the settings nav
      *
@@ -3090,7 +3134,7 @@
      * @param int $courseid The course id of the current course
      */
     protected function load_user_settings($courseid=SITEID) {
-        global $USER, $FULLME;
+        global $USER, $FULLME, $CFG;
 
         if (isguestuser() || !isloggedin()) {
             return false;
@@ -3101,22 +3145,24 @@
         // and the key depends on the current location
         // Default to look at id
         $userkey='id';
-        if ($this->context->contextlevel >= CONTEXT_COURSECAT && strpos($FULLME, '/message/')===false && strpos($FULLME, '/mod/forum/user')===false) {
+
+        if (strpos($FULLME,'/blog/') || strpos($FULLME, $CFG->admin.'/roles/')) {
+            // And blog and roles just do thier own thing using `userid`
+            $userkey = 'userid';
+        } else if ($this->context->contextlevel >= CONTEXT_COURSECAT && strpos($FULLME, '/message/')===false && strpos($FULLME, '/mod/forum/user')===false) {
             // If we have a course context and we are not in message or forum
             // Message and forum both pick the user up from `id`
             $userkey = 'user';
-        } else if (strpos($FULLME,'/blog/') || strpos($FULLME, '/roles/')) {
-            // And blog and roles just do thier own thing using `userid`
-            $userkey = 'userid';
         }
 
         $userid = optional_param($userkey, $USER->id, PARAM_INT);
         if ($userid!=$USER->id) {
-            $this->generate_user_settings($courseid,$userid,'userviewingsettings');
+            $userkey = $this->generate_user_settings($courseid,$userid,'userviewingsettings');
             $this->generate_user_settings($courseid,$USER->id);
         } else {
-            $this->generate_user_settings($courseid,$USER->id);
+            $userkey = $this->generate_user_settings($courseid,$USER->id);
         }
+        return $userkey;
     }
 
     /**
@@ -3286,6 +3332,61 @@
         return $usersettingskey;
     }
 
+    protected function load_block_settings() {
+        global $CFG;
+
+        $blocksettingskey = $this->add(print_context_name($this->context));
+        $blocknode = $this->get($blocksettingskey);
+        $blocknode->forceopen = true;
+
+        // Assign local roles
+        $assignurl = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid'=>$this->context->id));
+        $blocknode->add(get_string('assignroles', 'role'), $assignurl, self::TYPE_SETTING);
+
+        // Override roles
+        if (count(get_overridable_roles($this->context))>0) {
+            $url = new moodle_url('/'.$CFG->admin.'/roles/override.php', array('contextid'=>$this->context->id));
+            $blocknode->add(get_string('overridepermissions', 'role'), $url, self::TYPE_SETTING);
+        }
+        // Check role permissions
+        if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride','moodle/role:override', 'moodle/role:assign'), $this->context)) {
+            $url = new moodle_url('/'.$CFG->admin.'/roles/check.php', array('contextid'=>$this->context->id));
+            $blocknode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING);
+        }
+
+        return $blocksettingskey;
+    }
+
+    protected function load_category_settings() {
+        global $CFG;
+
+        $blocksettingskey = $this->add(print_context_name($this->context));
+        $blocknode = $this->get($blocksettingskey);
+        $blocknode->forceopen = true;
+
+        if ($this->page->user_is_editing() && has_capability('moodle/category:manage', $this->context)) {
+            $blocknode->add(get_string('editcategorythis'), new moodle_url('/course/editcategory.php', array('id' => $this->context->instanceid)));
+            $blocknode->add(get_string('addsubcategory'), new moodle_url('/course/editcategory.php', array('parent' => $this->context->instanceid)));
+        }
+
+        // Assign local roles
+        $assignurl = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid'=>$this->context->id));
+        $blocknode->add(get_string('assignroles', 'role'), $assignurl, self::TYPE_SETTING);
+
+        // Override roles
+        if (count(get_overridable_roles($this->context))>0) {
+            $url = new moodle_url('/'.$CFG->admin.'/roles/override.php', array('contextid'=>$this->context->id));
+            $blocknode->add(get_string('overridepermissions', 'role'), $url, self::TYPE_SETTING);
+        }
+        // Check role permissions
+        if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride','moodle/role:override', 'moodle/role:assign'), $this->context)) {
+            $url = new moodle_url('/'.$CFG->admin.'/roles/check.php', array('contextid'=>$this->context->id));
+            $blocknode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING);
+        }
+
+        return $blocksettingskey;
+    }
+
     /**
      * Determine whether the user is assuming another role
      *
@@ -3315,20 +3416,20 @@
      * This function loads all of the front page settings into the settings navigation.
      * This function is called when the user is on the front page, or $COURSE==$SITE
      */
-    protected function load_front_page_settings() {
-        global $SITE;
+    protected function load_front_page_settings($forceopen = false) {
+        global $SITE, $CFG;
 
-        $course = $SITE;
+        $course = clone($SITE);
         if (empty($course->context)) {
             $course->context = get_context_instance(CONTEXT_COURSE, $course->id);   // Course context
         }
 
         $frontpagekey = $this->add(get_string('frontpagesettings'), null, self::TYPE_SETTING, null, 'frontpage');
         $frontpage = $this->get($frontpagekey);
+        $frontpage->forceopen = $forceopen;
+        $frontpage->id = 'frontpagesettings';
 
         if (has_capability('moodle/course:update', $course->context)) {
-            $frontpage->id = 'frontpagesettings';
-            $frontpage->forceopen = true;
 
             // Add the turn on/off settings
             $url = new moodle_url('/course/view.php', array('id'=>$course->id, 'sesskey'=>sesskey()));
@@ -3351,9 +3452,67 @@
             $url = new moodle_url('/user/index.php', array('contextid'=>$course->context->id));
             $frontpage->add(get_string('participants'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/users', ''));
         }
+
+        // Roles
+        if (has_capability('moodle/role:assign', $course->context)) {
+            // Add assign or override roles if allowed
+            $url = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid'=>$course->context->id));
+            $frontpage->add(get_string('assignroles', 'role'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/roles', ''));
+            // Override roles
+            if (count(get_overridable_roles($course->context))>0) {
+                $url = new moodle_url('/'.$CFG->admin.'/roles/override.php', array('contextid'=>$course->context->id));
+                $frontpage->add(get_string('overridepermissions', 'role'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/overrideroles', ''));
     }
+            // Check role permissions
+            if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride','moodle/role:override', 'moodle/role:assign'), $course->context)) {
+                $url = new moodle_url('/'.$CFG->admin.'/roles/check.php', array('contextid'=>$course->context->id));
+                $frontpage->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/overrideroles', ''));
+            }
+            // Manage filters
+            if (has_capability('moodle/filter:manage', $course->context) && count(filter_get_available_in_context($course->context))>0) {
+                $url = new moodle_url('/filter/manage.php', array('contextid'=>$course->context->id));
+                $frontpage->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', ''));
+            }
+        }
 
+        // Backup this course
+        if (has_capability('moodle/backup:backupcourse', $course->context)) {
+            $url = new moodle_url('/backup/backup.php', array('id'=>$course->id));
+            $frontpage->add(get_string('backup'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/backup', ''));
+        }
 
+        // Restore to this course
+        if (has_capability('moodle/restore:restorecourse', $course->context)) {
+            $url = new moodle_url('/files/index.php', array('id'=>$course->id, 'wdir'=>'/backupdata'));
+            $frontpage->add(get_string('restore'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/restore', ''));
+        }
+
+        // Manage questions
+        $questioncaps = array('moodle/question:add',
+                              'moodle/question:editmine',
+                              'moodle/question:editall',
+                              'moodle/question:viewmine',
+                              'moodle/question:viewall',
+                              'moodle/question:movemine',
+                              'moodle/question:moveall');
+        if (has_any_capability($questioncaps, $this->context)) {
+            $questionlink = $CFG->wwwroot.'/question/edit.php';
+        } else if (has_capability('moodle/question:managecategory', $this->context)) {
+            $questionlink = $CFG->wwwroot.'/question/category.php';
+        }
+        if (isset($questionlink)) {
+            $url = new moodle_url($questionlink, array('courseid'=>$course->id));
+            $frontpage->add(get_string('questions','quiz'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/questions', ''));
+        }
+
+        // Manage files
+        if (has_capability('moodle/course:managefiles', $this->context)) {
+            $url = new moodle_url('/files/index.php', array('id'=>$course->id));
+            $frontpage->add(get_string('files'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/files', ''));
+        }
+    }
+
+
     /**
      * This function removes all root branches that have no children
      */
Index: moodle/mod/assignment/lib.php
--- moodle/mod/assignment/lib.php Base (1.434)
+++ moodle/mod/assignment/lib.php Locally Modified (Based On 1.434)
@@ -3345,20 +3345,21 @@
     }
 }
 
-function assignment_extend_settings_navigation($navnode, $module) {
+/**
+ * Adds module specific settings to the settings block
+ * 
+ * @param settings_navigation $settings The settings navigation object
+ * @param navigation_node $assignmentnode The node to add module settings to
+ */
+function assignment_extend_settings_navigation(settings_navigation $settings, navigation_node $assignmentnode) {
     global $PAGE, $DB, $USER, $CFG;
 
-    $allgroups = false;
-
     $assignmentrow = $DB->get_record("assignment", array("id" => $PAGE->cm->instance));
     require_once "$CFG->dirroot/mod/assignment/type/$assignmentrow->assignmenttype/assignment.class.php";
+    
     $assignmentclass = 'assignment_'.$assignmentrow->assignmenttype;
     $assignmentinstance = new $assignmentclass($PAGE->cm->id, $assignmentrow, $PAGE->cm, $PAGE->course);
 
-    $assignmentnodekey = $navnode->add(get_string('assignmentadministration', 'assignment'));
-    $assignmentnode = $navnode->get($assignmentnodekey);
-    $assignmentnode->forceopen = true;
-
     if (!empty($USER->id) && !has_capability('moodle/legacy:guest', $PAGE->cm->context, NULL, false)) {
 
         $allgroups = false;
@@ -3382,17 +3383,5 @@
         if (is_object($assignmentinstance) && method_exists($assignmentinstance, 'extend_settings_navigation')) {
             $assignmentinstance->extend_settings_navigation($assignmentnode);
         }
-
-        // Add update this activity link
-        if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-            $modulename = get_string('modulename', 'assignment');
-            $string = get_string('updatethis', '', $modulename);
-            $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey()));
-            $assignmentnode->add($string, $url, navigation_node::TYPE_SETTING);
         }
-
-        if (count($assignmentnode->children)<1) {
-            $navnode->remove_child($assignmentnodekey);
         }
-    }
-}
Index: moodle/mod/chat/lib.php
--- moodle/mod/chat/lib.php Base (1.163)
+++ moodle/mod/chat/lib.php Locally Modified (Based On 1.163)
@@ -1231,9 +1231,11 @@
 
 function chat_extend_navigation($navigation, $course, $module, $cm) {
     global $CFG, $USER, $PAGE, $OUTPUT;
+
+    $currentgroup = groups_get_activity_group($cm, true);
+    
     if (has_capability('mod/chat:chat',$cm->context)) {
         $strenterchat    = get_string('enterchat', 'chat');
-        $currentgroup = groups_get_activity_group($cm, true);
 
         $target = $CFG->wwwroot.'/mod/chat/';
         $params = array('id'=>$cm->instance);
@@ -1281,15 +1283,19 @@
     }
 }
 
-function chat_extend_settings_navigation($settingsnav, $module) {
-    global $DB, $PAGE, $USER, $CFG;
+/**
+ * Adds module specific settings to the settings block
+ *
+ * @param settings_navigation $settings The settings navigation object
+ * @param navigation_node $chatnode The node to add module settings to
+ */
+function chat_extend_settings_navigation(settings_navigation $settings, navigation_node $chatnode) {
+    global $DB, $PAGE, $USER;
     $chat = $DB->get_record("chat", array("id" => $PAGE->cm->instance));
-    $chatnavkey = $settingsnav->add(get_string('chatadministration', 'chat'));
-    $chatnav = $settingsnav->get($chatnavkey);
-    $chatnav->forceopen = true;
+
     if ($chat->chattime && $chat->schedule) {
-        $key = $chatnav->add(get_string('nextsession', 'chat').': '.userdate($chat->chattime).' ('.usertimezone($USER->timezone));
-        $chatnav->get($key)->add_class('note');
+        $key = $chatnode->add(get_string('nextsession', 'chat').': '.userdate($chat->chattime).' ('.usertimezone($USER->timezone));
+        $chatnode->get($key)->add_class('note');
     }
 
     $currentgroup = groups_get_activity_group($PAGE->cm, true);
@@ -1301,11 +1307,7 @@
 
     if ($chat->studentlogs || has_capability('mod/chat:readlog',$PAGE->cm->context)) {
         if ($DB->get_records_select('chat_messages', "chatid = ? $groupselect", array($chat->id))) {
-            $chatnav->add(get_string('viewreport', 'chat'), new moodle_url('/mod/chat/report.php', array('id'=>$PAGE->cm->id)));
+            $chatnode->add(get_string('viewreport', 'chat'), new moodle_url('/mod/chat/report.php', array('id'=>$PAGE->cm->id)));
         }
     }
-
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $chatnav->add(get_string('updatethis', '', get_string('modulename', 'chat')), new moodle_url('/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey())));
     }
-}
Index: moodle/mod/choice/lib.php
--- moodle/mod/choice/lib.php Base (1.122)
+++ moodle/mod/choice/lib.php Locally Modified (Based On 1.122)
@@ -921,13 +921,15 @@
     }
 }
 
-function choice_extend_settings_navigation($settings, $module) {
-    global $PAGE, $OUTPUT, $CFG;
+/**
+ * Adds module specific settings to the settings block
+ *
+ * @param settings_navigation $settings The settings navigation object
+ * @param navigation_node $choicenode The node to add module settings to
+ */
+function choice_extend_settings_navigation(settings_navigation $settings, navigation_node $choicenode) {
+    global $PAGE;
 
-    $choicenavkey = $settings->add(get_string('choiceadministration', 'choice'));
-    $choicenav = $settings->get($choicenavkey);
-    $choicenav->forceopen = true;
-
     if (has_capability('mod/choice:readresponses', $PAGE->cm->context)) {
 
         $groupmode = groups_get_activity_groupmode($PAGE->cm);
@@ -945,10 +947,6 @@
                 $responsecount += count($userlist);
             }
         }
-        $choicenav->add(get_string("viewallresponses", "choice", $responsecount), new moodle_url('/mod/choice/report.php', array('id'=>$PAGE->cm->id)));
+        $choicenode->add(get_string("viewallresponses", "choice", $responsecount), new moodle_url('/mod/choice/report.php', array('id'=>$PAGE->cm->id)));
     }
-
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $choicenav->add(get_string('updatethis', '', get_string('modulename', 'choice')), new moodle_url('/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey())));
     }
-}
Index: moodle/mod/data/lib.php
--- moodle/mod/data/lib.php Base (1.261)
+++ moodle/mod/data/lib.php Locally Modified (Based On 1.261)
@@ -2855,17 +2855,19 @@
     $navigation->add(get_string('search', 'data'), new moodle_url('/mod/data/view.php', array('d'=>$cm->instance, 'mode'=>'search')));
 }
 
-function data_extend_settings_navigation($settings, $module) {
-    global $PAGE, $OUTPUT, $CFG;
+/**
+ * Adds module specific settings to the settings block
+ *
+ * @param settings_navigation $settings The settings navigation object
+ * @param navigation_node $datanode The node to add module settings to
+ */
+function data_extend_settings_navigation(settings_navigation $settings, navigation_node $datanode) {
+    global $PAGE;
 
     // We only actually need the id here for functions
     $data = new stdClass;
     $data->id = $PAGE->cm->instance;
 
-    $datanavkey = $settings->add(get_string('dataadministration', 'data'));
-    $datanav = $settings->get($datanavkey);
-    $datanav->forceopen = true;
-
     $currentgroup = groups_get_activity_group($PAGE->cm);
     $groupmode = groups_get_activity_groupmode($PAGE->cm);
 
@@ -2875,13 +2877,13 @@
         } else {
             $addstring = get_string('editentry', 'data');
         }
-        $datanav->add($addstring, new moodle_url('/mod/data/edit.php', array('d'=>$PAGE->cm->instance)));
+        $datanode->add($addstring, new moodle_url('/mod/data/edit.php', array('d'=>$PAGE->cm->instance)));
     }
 
     if (has_capability(DATA_CAP_EXPORT, $PAGE->cm->context)) {
         // The capability required to Export database records is centrally defined in 'lib.php'
         // and should be weaker than those required to edit Templates, Fields and Presets.
-        $datanav->add(get_string('export', 'data'), new moodle_url('/mod/data/export.php', array('d'=>$data->id)));
+        $datanode->add(get_string('export', 'data'), new moodle_url('/mod/data/export.php', array('d'=>$data->id)));
     }
 
     if (has_capability('mod/data:managetemplates', $PAGE->cm->context)) {
@@ -2896,19 +2898,15 @@
             $defaultemplate = 'singletemplate';
         }
 
-        $templatekey = $datanav->add(get_string('templates', 'data'));
-        $templates = $datanav->get($templatekey);
+        $templatekey = $datanode->add(get_string('templates', 'data'));
+        $templates = $datanode->get($templatekey);
 
         $templatelist = array ('listtemplate', 'singletemplate', 'asearchtemplate', 'addtemplate', 'rsstemplate', 'csstemplate', 'jstemplate');
         foreach ($templatelist as $template) {
             $templates->add(get_string($template, 'data'), new moodle_url('/mod/data/templates.php', array('d'=>$data->id,'mode'=>$template)));
         }
 
-        $datanav->add(get_string('fields', 'data'), new moodle_url('/mod/data/field.php', array('d'=>$data->id)));
-        $datanav->add(get_string('presets', 'data'), new moodle_url('/mod/data/preset.php', array('d'=>$data->id)));
+        $datanode->add(get_string('fields', 'data'), new moodle_url('/mod/data/field.php', array('d'=>$data->id)));
+        $datanode->add(get_string('presets', 'data'), new moodle_url('/mod/data/preset.php', array('d'=>$data->id)));
     }
-
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $datanav->add(get_string('updatethis', '', get_string('modulename', 'choice')), new moodle_url('/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey())));
     }
-}
Index: moodle/mod/feedback/lib.php
--- moodle/mod/feedback/lib.php Base (1.60)
+++ moodle/mod/feedback/lib.php Locally Modified (Based On 1.60)
@@ -2333,40 +2333,38 @@
     }
 }
 
-function feedback_extend_settings_navigation($settings, $module) {
-    global $PAGE, $USER, $OUTPUT, $CFG, $DB;
+/**
+ * Adds module specific settings to the settings block
+ *
+ * @param settings_navigation $settings The settings navigation object
+ * @param navigation_node $feedbacknode The node to add module settings to
+ */
+function feedback_extend_settings_navigation(settings_navigation $settings, navigation_node $feedbacknode) {
+    global $PAGE, $DB;
 
-    $feedback = $DB->get_record('feedback', array('id'=>$PAGE->cm->instance));
-    $feedbacknavkey = $settings->add(get_string('feedbackadministration', 'feedback'));
-    $feedbacknav = $settings->get($feedbacknavkey);
-    $feedbacknav->forceopen = true;
-
     $capabilities = feedback_load_capabilities($PAGE->cm->id);
 
     if($capabilities->edititems) {
-        $qkey = $feedbacknav->add(get_string('questions', 'feedback'));
-        $feedbacknav->get($qkey)->add(get_string('edit_items', 'feedback'), new moodle_url('/mod/feedback/edit.php', array('id'=>$PAGE->cm->id, 'do_show'=>'edit')));
-        $feedbacknav->get($qkey)->add(get_string('export_questions', 'feedback'), new moodle_url('/mod/feedback/export.php', array('id'=>$PAGE->cm->id, 'action'=>'exportfile')));
-        $feedbacknav->get($qkey)->add(get_string('import_questions', 'feedback'), new moodle_url('/mod/feedback/import.php', array('id'=>$PAGE->cm->id)));
-        $feedbacknav->get($qkey)->add(get_string('templates', 'feedback'), new moodle_url('/mod/feedback/edit.php', array('id'=>$PAGE->cm->id, 'do_show'=>'templates')));
+        $qkey = $feedbacknode->add(get_string('questions', 'feedback'));
+        $feedbacknode->get($qkey)->add(get_string('edit_items', 'feedback'), new moodle_url('/mod/feedback/edit.php', array('id'=>$PAGE->cm->id, 'do_show'=>'edit')));
+        $feedbacknode->get($qkey)->add(get_string('export_questions', 'feedback'), new moodle_url('/mod/feedback/export.php', array('id'=>$PAGE->cm->id, 'action'=>'exportfile')));
+        $feedbacknode->get($qkey)->add(get_string('import_questions', 'feedback'), new moodle_url('/mod/feedback/import.php', array('id'=>$PAGE->cm->id)));
+        $feedbacknode->get($qkey)->add(get_string('templates', 'feedback'), new moodle_url('/mod/feedback/edit.php', array('id'=>$PAGE->cm->id, 'do_show'=>'templates')));
     }
 
     if($capabilities->viewreports) {
+        $feedback = $DB->get_record('feedback', array('id'=>$PAGE->cm->instance));
         if($feedback->course == SITEID){
-            $feedbacknav->add(get_string('analysis', 'feedback'), new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$PAGE->cm->id, 'course'=>$PAGE->course->id,'do_show'=>'analysis')));
+            $feedbacknode->add(get_string('analysis', 'feedback'), new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$PAGE->cm->id, 'course'=>$PAGE->course->id,'do_show'=>'analysis')));
         }else {
-            $feedbacknav->add(get_string('analysis', 'feedback'), new moodle_url('/mod/feedback/analysis.php', array('id'=>$PAGE->cm->id, 'course'=>$PAGE->course->id,'do_show'=>'analysis')));
+            $feedbacknode->add(get_string('analysis', 'feedback'), new moodle_url('/mod/feedback/analysis.php', array('id'=>$PAGE->cm->id, 'course'=>$PAGE->course->id,'do_show'=>'analysis')));
         }
     }
 
     if($capabilities->viewreports) {
-        $feedbacknav->add(get_string('show_entries', 'feedback'), new moodle_url('/mod/feedback/show_entries.php', array('id'=>$PAGE->cm->id, 'do_show'=>'showentries')));
+        $feedbacknode->add(get_string('show_entries', 'feedback'), new moodle_url('/mod/feedback/show_entries.php', array('id'=>$PAGE->cm->id, 'do_show'=>'showentries')));
     }
-
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $feedbacknav->add(get_string('updatethis', '', get_string('modulename', 'feedback')), new moodle_url('/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey())));
     }
-}
 
 function feedback_init_feedback_session() {
     //initialize the feedback-Session - not nice at all!!
Index: moodle/mod/folder/lib.php
--- moodle/mod/folder/lib.php Base (1.4)
+++ moodle/mod/folder/lib.php Locally Modified (Based On 1.4)
@@ -326,32 +326,3 @@
      */
     $navigation->nodetype = navigation_node::NODETYPE_LEAF;
 }
-
-/**
- * This function extends the settings navigation block for the site.
- *
- * It is safe to rely on PAGE here as we will only ever be within the module
- * context when this is called.
- *
- * @param settings_navigation $settings
- * @param stdClass $module
- */
-function folder_extend_settings_navigation($settings, $module) {
-    global $PAGE, $CFG;
-
-    // Add a folder node to the settings navigation.
-    $foldernavkey = $settings->add(get_string('folderadministration', 'folder'));
-    $foldernav = $settings->get($foldernavkey);
-    $foldernav->forceopen = true;
-
-    // If the user has the capability add an update this module link for the folder instance
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $url = new moodle_url('/course/mod.php', array('update'=>$PAGE->cm->id, 'return'=>true, 'sesskey'=>sesskey()));
-        $foldernav->add(get_string('updatethis', '', get_string('modulename', 'folder')), $url);
-    }
-
-    // Check if any children have been added. If not remove the node to save on clutter.
-    if (count($foldernav->children)<1) {
-        $settings->remove_child($foldernavkey);
-    }
-}
Index: moodle/mod/forum/lib.php
--- moodle/mod/forum/lib.php Base (1.852)
+++ moodle/mod/forum/lib.php Locally Modified (Based On 1.852)
@@ -8020,18 +8020,13 @@
 }
 
 /**
- * This function is used to extend the settings navigation with settings for the module
- * It is called when the context for the page is a forum module
+ * Adds module specific settings to the settings block
  *
- * @param settings_navigation $settingsnav {@link settings_navigation}
- * @param stdClass $module
- * @return void|mixed The key to the modules branch
+ * @param settings_navigation $settings The settings navigation object
+ * @param navigation_node $forumnode The node to add module settings to
  */
-function forum_extend_settings_navigation($settingsnav, $module=null) {
-    global $USER, $PAGE, $FULLME, $CFG, $DB, $OUTPUT;
-    $forumkey = $settingsnav->add(get_string('forumadministration', 'forum'));
-    $forum = $settingsnav->get($forumkey);
-    $forum->forceopen = true;
+function forum_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $forumnode) {
+    global $USER, $PAGE, $CFG, $DB, $OUTPUT;
 
     $forumobject = $DB->get_record("forum", array("id" => $PAGE->cm->instance));
     if (empty($PAGE->cm->context)) {
@@ -8041,33 +8036,33 @@
         $notekey = false;
         $helpbutton = false;
         if (forum_is_forcesubscribed($forumobject)) {
-            $notekey = $forum->add(get_string("forcessubscribe", 'forum'));
+            $notekey = $forumnode->add(get_string("forcessubscribe", 'forum'));
             $string = get_string('allowchoice', 'forum');
             $helpbutton = $OUTPUT->help_icon("subscription", $string, "forum");
             if (has_capability('mod/forum:managesubscriptions', $PAGE->cm->context)) {
                 $url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'force'=>'no'));
-                $forum->add($string, $url, navigation_node::TYPE_SETTING);
+                $forumnode->add($string, $url, navigation_node::TYPE_SETTING);
             } else {
-                $forum->add(get_string('everyoneisnowsubscribed', 'forum'), null, navigation_node::TYPE_SETTING);
+                $forumnode->add(get_string('everyoneisnowsubscribed', 'forum'), null, navigation_node::TYPE_SETTING);
             }
         } else if ($forumobject->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
             $string = get_string('disallowsubscribe', 'forum');
-            $notekey = $forum->add($string);
+            $notekey = $forumnode->add($string);
             $helpbutton = $OUTPUT->help_icon("subscription", $string, "forum");
         } else {
             $string = get_string("forcesubscribe", "forum");
-            $notekey = $forum->add(get_string("allowsallsubscribe", 'forum'));
+            $notekey = $forumnode->add(get_string("allowsallsubscribe", 'forum'));
             $helpbutton = $OUTPUT->help_icon("subscription", $string, "forum");
 
             if (has_capability('mod/forum:managesubscriptions', $PAGE->cm->context)) {
                 $url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'force'=>'yes'));
-                $forum->add($string, $url, navigation_node::TYPE_SETTING);
+                $forumnode->add($string, $url, navigation_node::TYPE_SETTING);
             } else {
-                $forum->add(get_string('everyonecannowchoose', 'forum'), null, navigation_node::TYPE_SETTING);
+                $forumnode->add(get_string('everyonecannowchoose', 'forum'), null, navigation_node::TYPE_SETTING);
             }
             if(has_capability('mod/forum:viewsubscribers', $PAGE->cm->context)){
                 $url = new moodle_url('/mod/forum/subscribers.php', array('id'=>$forumobject->id));
-                $forum->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING);
+                $forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING);
             }
 
             if (forum_is_forcesubscribed($forumobject) || ($forumobject->forcesubscribe == FORUM_DISALLOWSUBSCRIBE && !has_capability('mod/forum:managesubscriptions', $PAGE->cm->context))) {
@@ -8079,7 +8074,7 @@
                     $linktext = get_string('subscribe', 'forum');
                 }
                 $url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id));
-                $forum->add($linktext, $url, navigation_node::TYPE_SETTING);
+                $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
             }
         }
 
@@ -8090,21 +8085,15 @@
                 $linktext = get_string('trackforum', 'forum');
             }
             $url = new moodle_url('/mod/forum/settracking.php', array('id'=>$forumobject->id));
-            $forum->add($linktext, $url, navigation_node::TYPE_SETTING);
+            $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
         }
         if ($notekey!==false) {
-            $forum->get($notekey)->add_class('note');
+            $forumnode->get($notekey)->add_class('note');
             if ($helpbutton!==false) {
-                $forum->get($notekey)->helpbutton = $helpbutton;
+                $forumnode->get($notekey)->helpbutton = $helpbutton;
             }
         }
-        if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-            $modulename = get_string('modulename', 'forum');
-            $string = get_string('updatethis', '', $modulename);
-            $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey()));
-            $forum->add($string, $url, navigation_node::TYPE_SETTING);
         }
-    }
 
     if (!empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds) && $forumobject->rsstype && $forumobject->rssarticles) {
 
@@ -8123,10 +8112,8 @@
             $userid = $USER->id;
         }
         $url = new moodle_url(rss_get_url($PAGE->course->id, $userid, "forum", $forumobject->id));
-        $forum->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
+        $forumnode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
     }
-
-    return $forumkey;
 }
 
 /**
Index: moodle/mod/glossary/lib.php
--- moodle/mod/glossary/lib.php Base (1.283)
+++ moodle/mod/glossary/lib.php Locally Modified (Based On 1.283)
@@ -2680,33 +2680,31 @@
     $navigation->add(get_string('authorview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id'=>$cm->id, 'mode'=>'author')));
 }
 
-function glossary_extend_settings_navigation($settings, $module) {
+/**
+ * Adds module specific settings to the settings block
+ *
+ * @param settings_navigation $settings The settings navigation object
+ * @param navigation_node $glossarynode The node to add module settings to
+ */
+function glossary_extend_settings_navigation(settings_navigation $settings, navigation_node $glossarynode) {
     global $PAGE, $DB, $CFG;
 
     $mode = optional_param('mode', '', PARAM_ALPHA);
     $hook = optional_param('hook', 'ALL', PARAM_CLEAN);
 
-    $glossarynavkey = $settings->add(get_string('glossaryadministration', 'glossary'));
-    $glossarynav = $settings->get($glossarynavkey);
-    $glossarynav->forceopen = true;
-
     if (has_capability('mod/glossary:import', $PAGE->cm->context)) {
-        $glossarynav->add(get_string('importentries', 'glossary'), new moodle_url('/mod/glossary/import.php', array('id'=>$PAGE->cm->id)));
+        $glossarynode->add(get_string('importentries', 'glossary'), new moodle_url('/mod/glossary/import.php', array('id'=>$PAGE->cm->id)));
     }
 
     if (has_capability('mod/glossary:export', $PAGE->cm->context)) {
-        $glossarynav->add(get_string('exportentries', 'glossary'), new moodle_url('/mod/glossary/export.php', array('id'=>$PAGE->cm->id, 'mode'=>$mode, 'hook'=>$hook)));
+        $glossarynode->add(get_string('exportentries', 'glossary'), new moodle_url('/mod/glossary/export.php', array('id'=>$PAGE->cm->id, 'mode'=>$mode, 'hook'=>$hook)));
     }
 
     if (has_capability('mod/glossary:approve', $PAGE->cm->context) && ($hiddenentries = $DB->count_records('glossary_entries', array('glossaryid'=>$PAGE->cm->instance, 'approved'=>0)))) {
-        $glossarynav->add(get_string('waitingapproval', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id'=>$PAGE->cm->id, 'mode'=>'approval')));
+        $glossarynode->add(get_string('waitingapproval', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id'=>$PAGE->cm->id, 'mode'=>'approval')));
     }
 
     if (has_capability('mod/glossary:write', $PAGE->cm->context)) {
-        $glossarynav->add(get_string('addentry', 'glossary'), new moodle_url('/mod/glossary/edit.php', array('cmid'=>$PAGE->cm->id)));
+        $glossarynode->add(get_string('addentry', 'glossary'), new moodle_url('/mod/glossary/edit.php', array('cmid'=>$PAGE->cm->id)));
     }
-
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $glossarynav->add(get_string('updatethis', '', get_string('modulename', 'glossary')), new moodle_url('/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey())));
     }
-}
Index: moodle/mod/hotpot/lib.php
--- moodle/mod/hotpot/lib.php Base (1.134)
+++ moodle/mod/hotpot/lib.php Locally Modified (Based On 1.134)
@@ -2998,34 +2998,3 @@
      */
     $navigation->nodetype = navigation_node::NODETYPE_LEAF;
 }
-
-/**
- * This function extends the settings navigation block for the site.
- *
- * It is safe to rely on PAGE here as we will only ever be within the module
- * context when this is called.
- *
- * @param settings_navigation $settings
- * @param stdClass $module
- */
-function hotpot_extend_settings_navigation($settings, $module) {
-    global $PAGE, $CFG, $DB;
-
-    // Load the hotpot instance from the database
-    $hotpot = $DB->get_record('hotpot', array('id'=>$PAGE->cm->instance));
-    // Add a hotpot node to the settings navigation.
-    $hotpotnavkey = $settings->add(get_string('hotpotadministration', 'hotpot'));
-    $hotpotnav = $settings->get($hotpotnavkey);
-    $hotpotnav->forceopen = true;
-
-    // If the user has the capability add an update this module link for the hotpot instance
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $url = new moodle_url('/course/mod.php', array('update'=>$PAGE->cm->id, 'return'=>true, 'sesskey'=>sesskey()));
-        $hotpotnav->add(get_string('updatethis', '', get_string('modulename', 'hotpot')), $url);
-    }
-
-    // Check if any children have been added. If not remove the node to save on clutter.
-    if (count($hotpotnav->children)<1) {
-        $settings->remove_child($hotpotnav);
-    }
-}
Index: moodle/mod/imscp/lib.php
--- moodle/mod/imscp/lib.php Base (1.4)
+++ moodle/mod/imscp/lib.php Locally Modified (Based On 1.4)
@@ -393,32 +393,3 @@
      */
     $navigation->nodetype = navigation_node::NODETYPE_LEAF;
 }
-
-/**
- * This function extends the settings navigation block for the site.
- *
- * It is safe to rely on PAGE here as we will only ever be within the module
- * context when this is called.
- *
- * @param settings_navigation $settings
- * @param stdClass $module
- */
-function imscp_extend_settings_navigation($settings, $module) {
-    global $PAGE, $CFG;
-
-    // Add a imscp node to the settings navigation.
-    $imscpnavkey = $settings->add(get_string('imscpadministration', 'imscp'));
-    $imscpnav = $settings->get($imscpnavkey);
-    $imscpnav->forceopen = true;
-
-    // If the user has the capability add an update this module link for the imscp instance
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $imscp = new moodle_url($CFG->wwwroot.'/course/mod.php', array('update'=>$PAGE->cm->id, 'return'=>true, 'sesskey'=>sesskey()));
-        $imscpnav->add(get_string('updatethis', '', get_string('modulename', 'imscp')), $imscp);
-    }
-
-    // Check if any children have been added. If not remove the node to save on clutter.
-    if (count($imscpnav->children)<1) {
-        $settings->remove_child($imscpnavkey);
-    }
-}
Index: moodle/mod/lesson/lib.php
--- moodle/mod/lesson/lib.php Base (1.84)
+++ moodle/mod/lesson/lib.php Locally Modified (Based On 1.84)
@@ -795,58 +795,42 @@
  * It is safe to rely on PAGE here as we will only ever be within the module
  * context when this is called
  *
- * @param navigation_node $settings
- * @param stdClass $module
+ * @param settings_navigation $settings
+ * @param navigation_node $lessonnode
  */
-function lesson_extend_settings_navigation($settings, $module) {
-    global $PAGE, $CFG, $USER, $OUTPUT;
+function lesson_extend_settings_navigation($settings, $lessonnode) {
+    global $PAGE, $DB;
 
-    $lessonnavkey = $settings->add(get_string('lessonadministration', 'lesson'));
-    $lessonnav = $settings->get($lessonnavkey);
-    $lessonnav->forceopen = true;
-
-    if (empty($PAGE->cm->context)) {
-        $PAGE->cm->context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->instance);
-    }
-
     $canedit = has_capability('mod/lesson:edit', $PAGE->cm->context);
 
     $url = new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id));
-    $key = $lessonnav->add(get_string('preview', 'lesson'), $url);
+    $key = $lessonnode->add(get_string('preview', 'lesson'), $url);
 
     if ($canedit) {
         $url = new moodle_url('/mod/lesson/edit.php', array('id'=>$PAGE->cm->id));
-        $key = $lessonnav->add(get_string('edit', 'lesson'), $url);
+        $key = $lessonnode->add(get_string('edit', 'lesson'), $url);
     }
 
     if (has_capability('mod/lesson:manage', $PAGE->cm->context)) {
-        $key = $lessonnav->add(get_string('reports', 'lesson'));
+        $key = $lessonnode->add(get_string('reports', 'lesson'));
         $url = new moodle_url('/mod/lesson/report.php', array('id'=>$PAGE->cm->id, 'action'=>'reportoverview'));
-        $lessonnav->get($key)->add(get_string('overview', 'lesson'), $url);
+        $lessonnode->get($key)->add(get_string('overview', 'lesson'), $url);
         $url = new moodle_url('/mod/lesson/report.php', array('id'=>$PAGE->cm->id, 'action'=>'reportdetail'));
-        $lessonnav->get($key)->add(get_string('detailedstats', 'lesson'), $url);
+        $lessonnode->get($key)->add(get_string('detailedstats', 'lesson'), $url);
     }
 
     if ($canedit) {
         $url = new moodle_url('/mod/lesson/essay.php', array('id'=>$PAGE->cm->id));
-        $lessonnav->add(get_string('manualgrading', 'lesson'), $url);
+        $lessonnode->add(get_string('manualgrading', 'lesson'), $url);
     }
 
+    $lesson = $DB->get_record('lesson', array('id'=>$PAGE->cm->instance));
     if ($lesson->highscores) {
         $url = new moodle_url('/mod/lesson/highscores.php', array('id'=>$PAGE->cm->id));
-        $lessonnav->add(get_string('highscores', 'lesson'), $url);
+        $lessonnode->add(get_string('highscores', 'lesson'), $url);
     }
-
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $url = new moodle_url('/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey()));
-        $lessonnav->add(get_string('updatethis', '', get_string('modulename', 'lesson')), $url);
     }
 
-    if (count($lessonnav->children)<1) {
-        $settings->remove_child($lessonnavkey);
-    }
-}
-
 /**
  * Get list of available import or export formats
  *
Index: moodle/mod/lesson/locallib.php
--- moodle/mod/lesson/locallib.php Base (1.103)
+++ moodle/mod/lesson/locallib.php Locally Modified (Based On 1.103)
@@ -545,7 +545,7 @@
 
     $bc = new block_contents();
     $bc->title = get_string('lessonmenu', 'lesson');
-    $bc->set_classes('menu');
+    $bc->add_class('menu');
     $bc->content = $content;
 
     return $bc;
Index: moodle/mod/page/lib.php
--- moodle/mod/page/lib.php Base (1.5)
+++ moodle/mod/page/lib.php Locally Modified (Based On 1.5)
@@ -399,32 +399,3 @@
      */
     $navigation->nodetype = navigation_node::NODETYPE_LEAF;
 }
-
-/**
- * This function extends the settings navigation block for the site.
- *
- * It is safe to rely on PAGE here as we will only ever be within the module
- * context when this is called.
- *
- * @param settings_navigation $settings
- * @param stdClass $module
- */
-function page_extend_settings_navigation($settings, $module) {
-    global $PAGE, $CFG;
-
-    // Add a page node to the settings navigation.
-    $pagenavkey = $settings->add(get_string('pageadministration', 'page'));
-    $pagenav = $settings->get($pagenavkey);
-    $pagenav->forceopen = true;
-
-    // If the user has the capability add an update this module link for the page instance
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $url = new moodle_url('/course/mod.php', array('update'=>$PAGE->cm->id, 'return'=>true, 'sesskey'=>sesskey()));
-        $pagenav->add(get_string('updatethis', '', get_string('modulename', 'page')), $url);
-    }
-
-    // Check if any children have been added. If not remove the node to save on clutter.
-    if (count($pagenav->children)<1) {
-        $settings->remove_child($pagenavkey);
-    }
-}
Index: moodle/mod/quiz/lib.php
--- moodle/mod/quiz/lib.php Base (1.355)
+++ moodle/mod/quiz/lib.php Locally Modified (Based On 1.355)
@@ -1449,46 +1449,33 @@
  * It is safe to rely on PAGE here as we will only ever be within the module
  * context when this is called
  *
- * @param navigation_node $settings
- * @param stdClass $module
+ * @param settings_navigation $settings
+ * @param navigation_node $quiznode
  */
-function quiz_extend_settings_navigation($settings, $module) {
-    global $PAGE, $CFG, $OUTPUT;
+function quiz_extend_settings_navigation($settings, $quiznode) {
+    global $PAGE, $CFG;
 
-    $quiznavkey = $settings->add(get_string('quizadministration', 'quiz'));
-    $quiznav = $settings->get($quiznavkey);
-    $quiznav->forceopen = true;
-
     if (has_capability('mod/quiz:view', $PAGE->cm->context)) {
         $url = new moodle_url('/mod/quiz/view.php', array('id'=>$PAGE->cm->id));
-        $quiznav->add(get_string('info', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/info', ''));
+        $quiznode->add(get_string('info', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/info', ''));
     }
     if (has_capability('mod/quiz:viewreports', $PAGE->cm->context)) {
         $url = new moodle_url('/mod/quiz/report.php', array('q'=>$PAGE->cm->instance));
-        $reportkey = $quiznav->add(get_string('results', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
+        $reportkey = $quiznode->add(get_string('results', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
 
         require_once($CFG->dirroot.'/mod/quiz/report/reportlib.php');
         $reportlist = quiz_report_list($PAGE->cm->context);
         foreach ($reportlist as $report) {
             $url = new moodle_url('/mod/quiz/report.php', array('q'=>$PAGE->cm->instance, 'mode'=>$report));
-            $quiznav->get($reportkey)->add(get_string($report, 'quiz_'.$report), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', ''));
+            $quiznode->get($reportkey)->add(get_string($report, 'quiz_'.$report), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', ''));
         }
     }
     if (has_capability('mod/quiz:preview', $PAGE->cm->context)) {
         $url = new moodle_url('/mod/quiz/startattempt.php', array('cmid'=>$PAGE->cm->id, 'sesskey'=>sesskey()));
-        $quiznav->add(get_string('preview', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('t/preview', ''));
+        $quiznode->add(get_string('preview', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('t/preview', ''));
     }
     if (has_capability('mod/quiz:manage', $PAGE->cm->context)) {
         $url = new moodle_url('/mod/quiz/edit.php', array('cmid'=>$PAGE->cm->id));
-        $quiznav->add(get_string('edit'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('t/edit', ''));
+        $quiznode->add(get_string('edit'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('t/edit', ''));
     }
-
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $url = new moodle_url('/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey()));
-        $quiznav->add(get_string('updatethis', '', get_string('modulename', 'quiz')), $url);
     }
-
-    if (count($quiznav->children)<1) {
-        $settings->remove_child($quiznavkey);
-    }
-}
Index: moodle/mod/scorm/lib.php
--- moodle/mod/scorm/lib.php Base (1.132)
+++ moodle/mod/scorm/lib.php Locally Modified (Based On 1.132)
@@ -955,32 +955,3 @@
      */
     $navigation->nodetype = navigation_node::NODETYPE_LEAF;
 }
-
-/**
- * This function extends the settings navigation block for the site.
- *
- * It is safe to rely on PAGE here as we will only ever be within the module
- * context when this is called.
- *
- * @param settings_navigation $settings
- * @param stdClass $module
- */
-function scorm_extend_settings_navigation($settings, $module) {
-    global $PAGE, $CFG;
-
-    // Add a scorm node to the settings navigation.
-    $scormnavkey = $settings->add(get_string('scormadministration', 'scorm'));
-    $scormnav = $settings->get($scormnavkey);
-    $scormnav->forceopen = true;
-
-    // If the user has the capability add an update this module link for the scorm instance
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $url = new moodle_url('/course/mod.php', array('update'=>$PAGE->cm->id, 'return'=>true, 'sesskey'=>sesskey()));
-        $scormnav->add(get_string('updatethis', '', get_string('modulename', 'scorm')), $url);
-    }
-
-    // Check if any children have been added. If not remove the node to save on clutter.
-    if (count($scormnav->children)<1) {
-        $settings->remove_child($scormnavkey);
-    }
-}
Index: moodle/mod/survey/lib.php
--- moodle/mod/survey/lib.php Base (1.88)
+++ moodle/mod/survey/lib.php Locally Modified (Based On 1.88)
@@ -819,56 +819,29 @@
  * context when this is called
  *
  * @param navigation_node $settings
- * @param stdClass $module
+ * @param navigation_node $surveynode
  */
-function survey_extend_settings_navigation($settings, $module) {
-    global $PAGE, $CFG, $OUTPUT;
+function survey_extend_settings_navigation($settings, $surveynode) {
+    global $PAGE;
 
-    $surveynavkey = $settings->add(get_string('surveyadministration', 'survey'));
-    $surveynav = $settings->get($surveynavkey);
-    $surveynav->forceopen = true;
-
-    $strreport = get_string("report", "survey");
-    $strsurvey = get_string("modulename", "survey");
-    $strsurveys = get_string("modulenameplural", "survey");
-    $strsummary = get_string("summary", "survey");
-    $strscales = get_string("scales", "survey");
-    $strquestion = get_string("question", "survey");
-    $strquestions = get_string("questions", "survey");
-    $strdownload = get_string("download", "survey");
-    $strallscales = get_string("allscales", "survey");
-    $strallquestions = get_string("allquestions", "survey");
-    $strselectedquestions = get_string("selectedquestions", "survey");
-    $strseemoredetail = get_string("seemoredetail", "survey");
-    $strnotes = get_string("notes", "survey");
-
     if (has_capability('mod/survey:readresponses', $PAGE->cm->context)) {
-        $key = $surveynav->add(get_string("responsereports", "survey"));
+        $key = $surveynode->add(get_string("responsereports", "survey"));
 
         $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'summary'));
-        $surveynav->get($key)->add(get_string("summary", "survey"), $url);
+        $surveynode->get($key)->add(get_string("summary", "survey"), $url);
 
         $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'scales'));
-        $surveynav->get($key)->add(get_string("scales", "survey"), $url);
+        $surveynode->get($key)->add(get_string("scales", "survey"), $url);
 
         $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'questions'));
-        $surveynav->get($key)->add(get_string("question", "survey"), $url);
+        $surveynode->get($key)->add(get_string("question", "survey"), $url);
 
         $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'students'));
-        $surveynav->get($key)->add(get_string('participants'), $url);
+        $surveynode->get($key)->add(get_string('participants'), $url);
 
         if (has_capability('mod/survey:download', $PAGE->cm->context)) {
             $url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'download'));
-            $surveynav->add(get_string('downloadresults', 'survey'), $url);
+            $surveynode->add(get_string('downloadresults', 'survey'), $url);
         }
     }
-
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $url = new moodle_url('/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey()));
-        $surveynav->add(get_string('updatethis', '', get_string('modulename', 'quiz')), $url);
     }
-
-    if (count($surveynav->children)<1) {
-        $settings->remove_child($surveynavkey);
-    }
-}
Index: moodle/mod/url/lib.php
--- moodle/mod/url/lib.php Base (1.5)
+++ moodle/mod/url/lib.php Locally Modified (Based On 1.5)
@@ -305,32 +305,3 @@
      */
     $navigation->nodetype = navigation_node::NODETYPE_LEAF;
 }
-
-/**
- * This function extends the settings navigation block for the site.
- *
- * It is safe to rely on PAGE here as we will only ever be within the module
- * context when this is called.
- *
- * @param settings_navigation $settings
- * @param stdClass $module
- */
-function url_extend_settings_navigation($settings, $module) {
-    global $PAGE, $CFG;
-
-    // Add a url node to the settings navigation.
-    $urlnavkey = $settings->add(get_string('urladministration', 'url'));
-    $urlnav = $settings->get($urlnavkey);
-    $urlnav->forceopen = true;
-
-    // If the user has the capability add an update this module link for the url instance
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $url = new moodle_url('/course/mod.php', array('update'=>$PAGE->cm->id, 'return'=>true, 'sesskey'=>sesskey()));
-        $urlnav->add(get_string('updatethis', '', get_string('modulename', 'url')), $url);
-    }
-
-    // Check if any children have been added. If not remove the node to save on clutter.
-    if (count($urlnav->children)<1) {
-        $settings->remove_child($urlnavkey);
-    }
-}
Index: moodle/mod/workshop/lib.php
--- moodle/mod/workshop/lib.php Base (1.141)
+++ moodle/mod/workshop/lib.php Locally Modified (Based On 1.141)
@@ -693,21 +693,13 @@
  * so it is safe to rely on the $PAGE.
  *
  * @param settings_navigation $settingsnav {@link settings_navigation}
- * @param stdclass $module
- * @return void|mixed The key to the modules branch
+ * @param navigation_node $workshopnode {@link navigation_node}
  */
-function workshop_extend_settings_navigation(settings_navigation $settingsnav, stdclass $module=null) {
-    global $CFG, $PAGE;
+function workshop_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $workshopnode=null) {
+    global $PAGE;
 
-    $workshopkey = $settingsnav->add(get_string('workshopadministration', 'workshop'));
-    $workshopnode = $settingsnav->get($workshopkey);
-    $workshopnode->forceopen = true;
     //$workshopobject = $DB->get_record("workshop", array("id" => $PAGE->cm->instance));
 
-    if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
-        $url = new moodle_url('/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey()));
-        $workshopnode->add(get_string('updatethis', '', get_string('modulename', 'workshop')), $url, settings_navigation::TYPE_SETTING);
-    }
     if (has_capability('mod/workshop:editdimensions', $PAGE->cm->context)) {
         $url = new moodle_url('/mod/workshop/editform.php', array('cmid' => $PAGE->cm->id));
         $workshopnode->add(get_string('editassessmentform', 'workshop'), $url, settings_navigation::TYPE_SETTING);
Index: moodle/pix/i/filter.gif
MIME: application/octet-stream; encoding: Base64; length: 199
R0lGODlhEAAQAIQTAN7e3evr65+fno6Pje7u7ujo6PLy8uTk5LW1s6+vrqqq
qKSko4mJh4ODgn1+fHh4d5mZmJSUkvX19f//////////////////////////
/////////////////////////yH5BAEKAB8ALAAAAAAQABAAAAVE4CeOZGme
aFo+TsMMESQsSoKQDyAZRFAcgOBtxALwfECArdQ6/gC1k6tXANBSr+BM9RkE
AAJu9xvmesHic1kFk4nf7xAAOw==
Index: moodle/pix/i/overrideroles.gif
MIME: application/octet-stream; encoding: Base64; length: 128
R0lGODlhEAAQAMIHAPehcnI/BGYzAJlmM8yZZv/MmQAAAP///yH5BAEKAAcA
LAAAAAAQABAAAANFeHoR+7AB4OALc7pm8TSUVy0YSGUUU3nnF2qMVmrolrEs
aBuGOMO4GyrlA/BEMFVPmOk9li+e7qlkpagKKAdiWHQb3UUCADs=
