MDL-41811 simplify the admin tree detection logic and fix navigation in multiple areas
This commit is contained in:
committed by
Rajesh Taneja
parent
bafcd3f17a
commit
d5814f4e22
@@ -56,10 +56,6 @@ require_capability('moodle/role:assign', $context);
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_context($context);
|
||||
|
||||
if ($isfrontpage) {
|
||||
navigation_node::require_admin_tree();
|
||||
}
|
||||
|
||||
$contextname = $context->get_context_name();
|
||||
$courseid = $course->id;
|
||||
|
||||
@@ -153,12 +149,11 @@ switch ($context->contextlevel) {
|
||||
$showroles = 1;
|
||||
break;
|
||||
case CONTEXT_COURSECAT:
|
||||
$PAGE->set_heading("$SITE->fullname: ".get_string("categories"));
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
break;
|
||||
case CONTEXT_COURSE:
|
||||
if ($isfrontpage) {
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
admin_externalpage_setup('frontpageroles', '', array('contextid' => $contextid, 'roleid' => $roleid));
|
||||
$PAGE->set_heading(get_string('frontpage', 'admin'));
|
||||
} else {
|
||||
$PAGE->set_heading($course->fullname);
|
||||
}
|
||||
|
||||
+10
-3
@@ -50,6 +50,14 @@ if (!has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride',
|
||||
print_error('nopermissions', 'error', '', get_string('checkpermissions', 'core_role'));
|
||||
}
|
||||
$PAGE->set_url($url);
|
||||
|
||||
if ($context->contextlevel == CONTEXT_USER and $USER->id != $context->instanceid) {
|
||||
$PAGE->navigation->extend_for_user($user);
|
||||
$PAGE->set_context(context_course::instance($course->id));
|
||||
} else {
|
||||
$PAGE->set_context($context);
|
||||
}
|
||||
|
||||
$PAGE->set_context($context);
|
||||
|
||||
$courseid = $course->id;
|
||||
@@ -79,12 +87,11 @@ switch ($context->contextlevel) {
|
||||
$showroles = 1;
|
||||
break;
|
||||
case CONTEXT_COURSECAT:
|
||||
$PAGE->set_heading("$SITE->fullname: ".get_string("categories"));
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
break;
|
||||
case CONTEXT_COURSE:
|
||||
if ($isfrontpage) {
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
admin_externalpage_setup('frontpageroles', '', array('contextid' => $contextid), $CFG->wwwroot . '/' . $CFG->admin . '/roles/check.php');
|
||||
$PAGE->set_heading(get_string('frontpage', 'admin'));
|
||||
} else {
|
||||
$PAGE->set_heading($course->fullname);
|
||||
}
|
||||
|
||||
@@ -53,11 +53,19 @@ if (!has_capability('moodle/role:override', $context)) {
|
||||
$safeoverridesonly = true;
|
||||
}
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
if (!$isfrontpage) {
|
||||
navigation_node::no_admin_navigation_node();
|
||||
|
||||
if ($context->contextlevel == CONTEXT_USER and $USER->id != $context->instanceid) {
|
||||
$PAGE->navigation->extend_for_user($user);
|
||||
$PAGE->set_context(context_course::instance($course->id));
|
||||
navigation_node::override_active_url(new moodle_url('/admin/roles/permissions.php',
|
||||
array('contextid'=>$context->id, 'userid'=>$context->instanceid, 'courseid'=>$course->id)));
|
||||
|
||||
} else {
|
||||
$PAGE->set_context($context);
|
||||
navigation_node::override_active_url(new moodle_url('/admin/roles/permissions.php', array('contextid'=>$context->id)));
|
||||
}
|
||||
|
||||
$courseid = $course->id;
|
||||
|
||||
$returnurl = new moodle_url('/admin/roles/permissions.php', array('contextid' => $context->id));
|
||||
@@ -93,12 +101,11 @@ switch ($context->contextlevel) {
|
||||
$showroles = 1;
|
||||
break;
|
||||
case CONTEXT_COURSECAT:
|
||||
$PAGE->set_heading("$SITE->fullname: ".get_string("categories"));
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
break;
|
||||
case CONTEXT_COURSE:
|
||||
if ($isfrontpage) {
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
admin_externalpage_setup('frontpageroles', '', array(), $PAGE->url);
|
||||
$PAGE->set_heading(get_string('frontpage', 'admin'));
|
||||
} else {
|
||||
$PAGE->set_heading($course->fullname);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,14 @@ if ($course) {
|
||||
require_login($course, false, $cm);
|
||||
require_capability('moodle/role:review', $context);
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_context($context);
|
||||
|
||||
if ($context->contextlevel == CONTEXT_USER and $USER->id != $context->instanceid) {
|
||||
$PAGE->navigation->extend_for_user($user);
|
||||
$PAGE->set_context(context_course::instance($course->id));
|
||||
} else {
|
||||
$PAGE->set_context($context);
|
||||
}
|
||||
|
||||
$courseid = $course->id;
|
||||
|
||||
|
||||
@@ -88,12 +95,11 @@ switch ($context->contextlevel) {
|
||||
$showroles = 1;
|
||||
break;
|
||||
case CONTEXT_COURSECAT:
|
||||
$PAGE->set_heading("$SITE->fullname: ".get_string("categories"));
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
break;
|
||||
case CONTEXT_COURSE:
|
||||
if ($isfrontpage) {
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
admin_externalpage_setup('frontpageroles', '', array(), $PAGE->url);
|
||||
$PAGE->set_heading(get_string('frontpage', 'admin'));
|
||||
} else {
|
||||
$PAGE->set_heading($course->fullname);
|
||||
}
|
||||
|
||||
@@ -41,11 +41,17 @@ $systemcontext = context_system::instance();
|
||||
$baseurl = new moodle_url('/admin/roles/usersroles.php', array('userid'=>$userid, 'courseid'=>$courseid));
|
||||
|
||||
$PAGE->set_url($baseurl);
|
||||
$PAGE->set_context($coursecontext);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
|
||||
// Check login and permissions.
|
||||
require_login($course);
|
||||
if ($course->id == SITEID) {
|
||||
require_login();
|
||||
$PAGE->set_context($usercontext);
|
||||
} else {
|
||||
require_login($course);
|
||||
$PAGE->set_context($coursecontext);
|
||||
}
|
||||
|
||||
$canview = has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride',
|
||||
'moodle/role:override', 'moodle/role:manage'), $usercontext);
|
||||
if (!$canview) {
|
||||
@@ -120,10 +126,10 @@ $title = get_string('xroleassignments', 'core_role', $fullname);
|
||||
|
||||
// Course header.
|
||||
$PAGE->set_title($title);
|
||||
if ($courseid != SITEID) {
|
||||
if ($courseid == SITEID) {
|
||||
$PAGE->set_heading($fullname);
|
||||
} else {
|
||||
$PAGE->set_heading($course->fullname);
|
||||
$PAGE->set_heading($course->fullname.': '.$fullname);
|
||||
}
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($title, 3);
|
||||
|
||||
@@ -69,29 +69,6 @@ if (!during_initial_install()) { //do not use during installation
|
||||
}
|
||||
$temp->add(new admin_setting_configselect('defaultfrontpageroleid', new lang_string('frontpagedefaultrole', 'admin'), '', $defaultfrontpageroleid, $options));
|
||||
|
||||
|
||||
$ADMIN->add('frontpage', $temp);
|
||||
|
||||
$ADMIN->add('frontpage', new admin_externalpage('frontpageroles', new lang_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', new lang_string('frontpagefilters', 'admin'), "$CFG->wwwroot/filter/manage.php?contextid=" . $frontpagecontext->id, 'moodle/filter:manage', false, $frontpagecontext));
|
||||
|
||||
$ADMIN->add('frontpage', new admin_externalpage('frontpagebackup', new lang_string('frontpagebackup', 'admin'), $CFG->wwwroot.'/backup/backup.php?id='.SITEID, 'moodle/backup:backupcourse', false, $frontpagecontext));
|
||||
|
||||
$ADMIN->add('frontpage', new admin_externalpage('frontpagerestore', new lang_string('frontpagerestore', 'admin'), $CFG->wwwroot.'/backup/restorefile.php?contextid='.$frontpagecontext->id, 'moodle/restore:restorecourse', false, $frontpagecontext));
|
||||
|
||||
$questioncapabilities = 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', new lang_string('frontpagequestions', 'admin'), $CFG->wwwroot.'/question/edit.php?courseid='.SITEID, $questioncapabilities, false, $frontpagecontext));
|
||||
|
||||
if (!empty($SITE->legacyfiles) and $SITE->legacyfiles === 2) {
|
||||
$ADMIN->add('frontpage', new admin_externalpage('sitefiles', new lang_string('sitelegacyfiles'), $CFG->wwwroot . '/files/index.php?id=' . SITEID, 'moodle/course:managefiles', false, $frontpagecontext));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ require(dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php');
|
||||
require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/customlang/locallib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
require_login(SITEID, false);
|
||||
require_login(null, false);
|
||||
require_capability('tool/customlang:view', context_system::instance());
|
||||
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ if ($type == BADGE_TYPE_SITE) {
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_heading($title . ': ' . $hdr);
|
||||
navigation_node::override_active_url(new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_SITE), true));
|
||||
navigation_node::override_active_url(new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_SITE)), true);
|
||||
} else {
|
||||
require_login($course);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
+1
-3
@@ -36,6 +36,7 @@ require_capability('moodle/cohort:assign', $context);
|
||||
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url('/cohort/assign.php', array('id'=>$id));
|
||||
$PAGE->set_pagelayout('admin');
|
||||
|
||||
$returnurl = new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid));
|
||||
|
||||
@@ -51,11 +52,8 @@ if (optional_param('cancel', false, PARAM_BOOL)) {
|
||||
if ($context->contextlevel == CONTEXT_COURSECAT) {
|
||||
$category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
|
||||
navigation_node::override_active_url(new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid)));
|
||||
$PAGE->set_pagelayout('report');
|
||||
|
||||
} else {
|
||||
navigation_node::override_active_url(new moodle_url('/cohort/index.php', array()));
|
||||
$PAGE->set_pagelayout('admin');
|
||||
}
|
||||
$PAGE->navbar->add(get_string('assign', 'cohort'));
|
||||
|
||||
|
||||
+1
-2
@@ -62,15 +62,14 @@ if (!empty($cohort->component)) {
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url('/cohort/edit.php', array('contextid'=>$context->id, 'id'=>$cohort->id));
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
|
||||
if ($context->contextlevel == CONTEXT_COURSECAT) {
|
||||
$category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
|
||||
navigation_node::override_active_url(new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid)));
|
||||
$PAGE->set_pagelayout('report');
|
||||
|
||||
} else {
|
||||
navigation_node::override_active_url(new moodle_url('/cohort/index.php', array()));
|
||||
$PAGE->set_pagelayout('admin');
|
||||
}
|
||||
|
||||
if ($delete and $cohort->id) {
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ if (!$manager) {
|
||||
$strcohorts = get_string('cohorts', 'cohort');
|
||||
|
||||
if ($category) {
|
||||
$PAGE->set_pagelayout('report');
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url('/cohort/index.php', array('contextid'=>$context->id));
|
||||
$PAGE->set_title($strcohorts);
|
||||
|
||||
+9
-7
@@ -28,24 +28,26 @@ require_once($CFG->dirroot . '/course/lib.php');
|
||||
$id = required_param('id', PARAM_INT); // Course ID.
|
||||
$delete = optional_param('delete', '', PARAM_ALPHANUM); // Confirmation hash.
|
||||
|
||||
$PAGE->set_url('/course/delete.php', array('id' => $id));
|
||||
$PAGE->set_context(context_system::instance());
|
||||
require_login();
|
||||
|
||||
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
if ((int)$SITE->id === (int)$course->id || !can_delete_course($id)) {
|
||||
require_login();
|
||||
|
||||
if ($SITE->id == $course->id || !can_delete_course($id)) {
|
||||
// Can not delete frontpage or don't have permission to delete the course.
|
||||
print_error('cannotdeletecourse');
|
||||
}
|
||||
|
||||
$categorycontext = context_coursecat::instance($course->category);
|
||||
$PAGE->set_url('/course/delete.php', array('id' => $id));
|
||||
$PAGE->set_context($categorycontext);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
navigation_node::override_active_url(new moodle_url('/course/management.php', array('categoryid'=>$course->category)));
|
||||
|
||||
$courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
|
||||
$coursefullname = format_string($course->fullname, true, array('context' => $coursecontext));
|
||||
$categoryurl = new moodle_url('/course/management.php', array('categoryid' => $course->category));
|
||||
|
||||
navigation_node::override_active_url(new moodle_url('/course/management.php', true));
|
||||
|
||||
// Check if we've got confirmation.
|
||||
if ($delete === md5($course->timemodified)) {
|
||||
// We do - time to delete the course.
|
||||
|
||||
@@ -45,6 +45,7 @@ if ($id) {
|
||||
$itemid = 0; // Initialise itemid, as all files in category description has item id 0.
|
||||
$title = $strtitle;
|
||||
$fullname = $coursecat->get_formatted_name();
|
||||
|
||||
} else {
|
||||
$parent = required_param('parent', PARAM_INT);
|
||||
$url->param('parent', $parent);
|
||||
@@ -54,6 +55,7 @@ if ($id) {
|
||||
} else {
|
||||
$context = context_system::instance();
|
||||
}
|
||||
navigation_node::override_active_url(new moodle_url('/course/editcategory.php', array('parent' => $parent)));
|
||||
|
||||
$category = new stdClass();
|
||||
$category->id = 0;
|
||||
@@ -66,12 +68,6 @@ if ($id) {
|
||||
|
||||
require_capability('moodle/category:manage', $context);
|
||||
|
||||
// Page "Add new category" (with "Top" as a parent) does not exist in navigation.
|
||||
// We pretend we are on course management page.
|
||||
if ($id !== 0) {
|
||||
navigation_node::override_active_url(new moodle_url('/course/management.php'), true);
|
||||
}
|
||||
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
|
||||
@@ -48,7 +48,6 @@ if ($issearching) {
|
||||
}
|
||||
|
||||
$url = new moodle_url('/course/management.php');
|
||||
navigation_node::override_active_url($url);
|
||||
$systemcontext = $context = context_system::instance();
|
||||
if ($courseid) {
|
||||
$record = get_course($courseid);
|
||||
@@ -56,13 +55,18 @@ if ($courseid) {
|
||||
$category = coursecat::get($course->category);
|
||||
$categoryid = $category->id;
|
||||
$context = context_coursecat::instance($category->id);
|
||||
$url->param('categoryid', $categoryid);
|
||||
navigation_node::override_active_url($url);
|
||||
$url->param('courseid', $course->id);
|
||||
|
||||
} else if ($categoryid) {
|
||||
$courseid = null;
|
||||
$course = null;
|
||||
$category = coursecat::get($categoryid);
|
||||
$context = context_coursecat::instance($category->id);
|
||||
$url->param('categoryid', $category->id);
|
||||
navigation_node::override_active_url($url);
|
||||
|
||||
} else {
|
||||
$course = null;
|
||||
$courseid = null;
|
||||
@@ -72,6 +76,7 @@ if ($courseid) {
|
||||
$viewmode = 'categories';
|
||||
}
|
||||
$context = $systemcontext;
|
||||
navigation_node::override_active_url($url);
|
||||
}
|
||||
|
||||
if ($page !== 0) {
|
||||
|
||||
+3
-1
@@ -126,6 +126,9 @@ if (!empty($add)) {
|
||||
$url->param('update', $update);
|
||||
$PAGE->set_url($url);
|
||||
|
||||
// Select the "Edit settings" from navigation.
|
||||
navigation_node::override_active_url(new moodle_url('/course/modedit.php', array('update'=>$update, 'return'=>1)));
|
||||
|
||||
// Check the course module exists.
|
||||
$cm = get_coursemodule_from_id('', $update, 0, false, MUST_EXIST);
|
||||
|
||||
@@ -241,7 +244,6 @@ if (!empty($type)) { //TODO: hopefully will be removed in 2.0
|
||||
}
|
||||
$PAGE->set_pagetype($pagepath);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
navigation_node::no_admin_navigation_node();
|
||||
|
||||
$modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php";
|
||||
if (file_exists($modmoodleform)) {
|
||||
|
||||
@@ -37,6 +37,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
||||
}
|
||||
|
||||
$PAGE->set_url('/course/reset.php', array('id'=>$id));
|
||||
$PAGE->set_pagelayout('admin');
|
||||
|
||||
require_login($course);
|
||||
require_capability('moodle/course:reset', context_course::instance($course->id));
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ $personalcontext = context_user::instance($user->id);
|
||||
$PAGE->set_url('/course/user.php', array('id'=>$id, 'user'=>$user->id, 'mode'=>$mode));
|
||||
|
||||
require_login();
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_pagelayout('report');
|
||||
if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !is_enrolled($coursecontext)) {
|
||||
// do not require parents to be enrolled in courses ;-)
|
||||
$PAGE->set_course($course);
|
||||
|
||||
+6
-1
@@ -26,7 +26,7 @@
|
||||
|
||||
require('../config.php');
|
||||
|
||||
$contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
|
||||
$contextid = optional_param('contextid', 0, PARAM_INT);
|
||||
$filepath = optional_param('filepath', '', PARAM_PATH);
|
||||
$filename = optional_param('filename', '', PARAM_FILE);
|
||||
// hard-coded to course legacy area
|
||||
@@ -34,7 +34,12 @@ $component = 'course';
|
||||
$filearea = 'legacy';
|
||||
$itemid = 0;
|
||||
|
||||
if (empty($contextid)) {
|
||||
$contextid = context_course::instance(SITEID)->id;
|
||||
}
|
||||
|
||||
$PAGE->set_url('/files/index.php', array('contextid'=>$contextid, 'filepath'=>$filepath, 'filename'=>$filename));
|
||||
navigation_node::override_active_url(new moodle_url('/files/index.php', array('contextid'=>$contextid)));
|
||||
|
||||
if ($filepath === '') {
|
||||
$filepath = null;
|
||||
|
||||
+6
-11
@@ -57,7 +57,7 @@ $isfrontpage = ($context->contextlevel == CONTEXT_COURSE && $context->instanceid
|
||||
$contextname = $context->get_context_name();
|
||||
|
||||
if ($context->contextlevel == CONTEXT_COURSECAT) {
|
||||
$heading = "$SITE->fullname: ".get_string("categories");
|
||||
$heading = $SITE->fullname;
|
||||
} else if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
$heading = $course->fullname;
|
||||
} else if ($context->contextlevel == CONTEXT_MODULE) {
|
||||
@@ -119,16 +119,11 @@ if ($forfilter) {
|
||||
}
|
||||
$straction = get_string('filters', 'admin'); // Used by tabs.php
|
||||
|
||||
/// Print the header and tabs
|
||||
if ($isfrontpage) {
|
||||
admin_externalpage_setup('frontpagefilters');
|
||||
echo $OUTPUT->header();
|
||||
} else {
|
||||
$PAGE->set_cacheable(false);
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
echo $OUTPUT->header();
|
||||
}
|
||||
// Print the header and tabs.
|
||||
$PAGE->set_cacheable(false);
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print heading.
|
||||
echo $OUTPUT->heading_with_help($title, 'filtersettings', 'filters');
|
||||
|
||||
@@ -145,7 +145,6 @@ $strparticipants = get_string('participants');
|
||||
$PAGE->set_title($strgroups);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
navigation_node::require_admin_tree();
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// Add tabs
|
||||
|
||||
@@ -39,6 +39,9 @@ if ($branchtype !== navigation_node::TYPE_SITE_ADMIN) {
|
||||
die('Wrong node type passed.');
|
||||
}
|
||||
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_url('/lib/ajax/getsiteadminbranch.php', array('type'=>$branchtype));
|
||||
|
||||
$sitenavigation = new settings_navigation_ajax($PAGE);
|
||||
|
||||
// Set XML headers.
|
||||
|
||||
@@ -1457,7 +1457,6 @@ class block_manager {
|
||||
redirect($this->page->url);
|
||||
|
||||
} else {
|
||||
navigation_node::no_admin_navigation_node();
|
||||
$strheading = get_string('blockconfiga', 'moodle', $block->get_title());
|
||||
$editpage->set_title($strheading);
|
||||
$editpage->set_heading($strheading);
|
||||
|
||||
@@ -4805,6 +4805,7 @@ function set_login_session_preferences() {
|
||||
$SESSION->justloggedin = true;
|
||||
|
||||
unset($SESSION->lang);
|
||||
unset($SESSION->load_navigation_admin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+40
-68
@@ -139,8 +139,6 @@ class navigation_node implements renderable {
|
||||
public static $autofindactive = true;
|
||||
/** @var bool should we load full admin tree or rely on AJAX for performance reasons */
|
||||
protected static $loadadmintree = false;
|
||||
/** @var bool no admin navigation node is added for this page */
|
||||
protected static $noadminnavigationnode = false;
|
||||
/** @var mixed If set to an int, that section will be included even if it has no activities */
|
||||
public $includesectionnum = false;
|
||||
|
||||
@@ -265,14 +263,6 @@ class navigation_node implements renderable {
|
||||
self::$loadadmintree = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses when page doesn't have admin navigation node and we need to decide if
|
||||
* site admin should be loaded.
|
||||
*/
|
||||
public static function no_admin_navigation_node() {
|
||||
self::$noadminnavigationnode = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a navigation node, ready to add it as a child using add_node
|
||||
* function. (The created node needs to be added before you can use it.)
|
||||
@@ -3329,74 +3319,77 @@ class settings_navigation extends navigation_node {
|
||||
$this->id = 'settingsnav';
|
||||
$this->context = $this->page->context;
|
||||
|
||||
$frontpagesettings = null;
|
||||
$categorysettings = null;
|
||||
$coursesettings = null;
|
||||
$modulesettings = null;
|
||||
$blocksettings = null;
|
||||
$usersettings = null;
|
||||
|
||||
$context = $this->context;
|
||||
if ($context->contextlevel == CONTEXT_BLOCK) {
|
||||
$blocksettings = $this->load_block_settings();
|
||||
$this->load_block_settings();
|
||||
$context = $context->get_parent_context();
|
||||
}
|
||||
switch ($context->contextlevel) {
|
||||
case CONTEXT_SYSTEM:
|
||||
if ($this->page->url->compare(new moodle_url('/admin/settings.php', array('section'=>'frontpagesettings')))) {
|
||||
$frontpagesettings = $this->load_front_page_settings(($context->id == $this->context->id));
|
||||
$this->load_front_page_settings(($context->id == $this->context->id));
|
||||
}
|
||||
break;
|
||||
case CONTEXT_COURSECAT:
|
||||
$categorysettings = $this->load_category_settings();
|
||||
$this->load_category_settings();
|
||||
break;
|
||||
case CONTEXT_COURSE:
|
||||
if ($this->page->course->id != $SITE->id) {
|
||||
$coursesettings = $this->load_course_settings(($context->id == $this->context->id));
|
||||
$this->load_course_settings(($context->id == $this->context->id));
|
||||
} else {
|
||||
$frontpagesettings = $this->load_front_page_settings(($context->id == $this->context->id));
|
||||
$this->load_front_page_settings(($context->id == $this->context->id));
|
||||
}
|
||||
break;
|
||||
case CONTEXT_MODULE:
|
||||
$modulesettings = $this->load_module_settings();
|
||||
$coursesettings = $this->load_course_settings();
|
||||
$this->load_module_settings();
|
||||
$this->load_course_settings();
|
||||
break;
|
||||
case CONTEXT_USER:
|
||||
if ($this->page->course->id != $SITE->id) {
|
||||
$coursesettings = $this->load_course_settings();
|
||||
$this->load_course_settings();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$usersettings = $this->load_user_settings($this->page->course->id);
|
||||
|
||||
$admin = false;
|
||||
if (isloggedin() && !isguestuser() && (!property_exists($SESSION, 'load_navigation_admin') || $SESSION->load_navigation_admin)) {
|
||||
// If admin page or user logged in, then load admin settings.
|
||||
$isadminpage = $this->is_admin_tree_needed($frontpagesettings, $categorysettings, $coursesettings, $modulesettings,
|
||||
$blocksettings, $usersettings);
|
||||
if ($isadminpage || !isset($SESSION->load_navigation_admin)) {
|
||||
$admin = $this->load_administration_settings();
|
||||
$SESSION->load_navigation_admin = ($admin->children->count() > 0);
|
||||
$adminsettings = false;
|
||||
if (isloggedin() && !isguestuser() && (!isset($SESSION->load_navigation_admin) || $SESSION->load_navigation_admin)) {
|
||||
$isadminpage = $this->is_admin_tree_needed();
|
||||
|
||||
// Don't load navigation on login, for performance reasons.
|
||||
if (!$isadminpage) {
|
||||
$admin->remove();
|
||||
$admin = false;
|
||||
if (has_capability('moodle/site:config', context_system::instance())) {
|
||||
// Make sure this works even if config capability changes on the fly
|
||||
// and also make it fast for admin right after login.
|
||||
$SESSION->load_navigation_admin = 1;
|
||||
if ($isadminpage) {
|
||||
$adminsettings = $this->load_administration_settings();
|
||||
}
|
||||
|
||||
} else if (!isset($SESSION->load_navigation_admin)) {
|
||||
$adminsettings = $this->load_administration_settings();
|
||||
$SESSION->load_navigation_admin = (int)($adminsettings->children->count() > 0);
|
||||
|
||||
} else if ($SESSION->load_navigation_admin) {
|
||||
if ($isadminpage) {
|
||||
$adminsettings = $this->load_administration_settings();
|
||||
}
|
||||
}
|
||||
|
||||
// Print empty navigation node, if needed.
|
||||
if (!$admin && $SESSION->load_navigation_admin) {
|
||||
$admin = false;
|
||||
if ($SESSION->load_navigation_admin && !$isadminpage) {
|
||||
if ($adminsettings) {
|
||||
// Do not print settings tree on pages that do not need it, this helps with performance.
|
||||
$adminsettings->remove();
|
||||
$adminsettings = false;
|
||||
}
|
||||
$siteadminnode = $this->add(get_string('administrationsite'), new moodle_url('/admin'), self::TYPE_SITE_ADMIN, null, 'siteadministration');
|
||||
$siteadminnode->id = 'expandable_branch_'.$siteadminnode->type.'_'.clean_param($siteadminnode->key, PARAM_ALPHANUMEXT);
|
||||
$this->page->requires->data_for_js('siteadminexpansion', $siteadminnode);
|
||||
}
|
||||
}
|
||||
|
||||
if ($context->contextlevel == CONTEXT_SYSTEM && $admin) {
|
||||
$admin->force_open();
|
||||
if ($context->contextlevel == CONTEXT_SYSTEM && $adminsettings) {
|
||||
$adminsettings->force_open();
|
||||
} else if ($context->contextlevel == CONTEXT_USER && $usersettings) {
|
||||
$usersettings->force_open();
|
||||
}
|
||||
@@ -3472,40 +3465,19 @@ class settings_navigation extends navigation_node {
|
||||
* Does this page require loading of full admin tree or is
|
||||
* it enough rely on AJAX?
|
||||
*
|
||||
* @param navigation_node $frontpagesettings frontpage settings navigation node.
|
||||
* @param navigation_node $categorysettings category settings navigation node.
|
||||
* @param navigation_node $coursesettings course settings navigation node.
|
||||
* @param navigation_node $modulesettings module settings navigation node.
|
||||
* @param navigation_node $blocksettings block settings navigation node.
|
||||
* @param navigation_node $usersettings user settings navigation node.
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_admin_tree_needed(navigation_node $frontpagesettings = null, navigation_node $categorysettings = null,
|
||||
navigation_node $coursesettings = null, navigation_node $modulesettings = null, navigation_node $blocksettings = null,
|
||||
navigation_node $usersettings = null) {
|
||||
|
||||
protected function is_admin_tree_needed() {
|
||||
if (self::$loadadmintree) {
|
||||
// Usually external admin page or settings page.
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->page->pagelayout === 'admin' or strpos($this->page->pagetype, 'admin-') === 0) {
|
||||
// No navigation node is added for this page, case like block editing page.
|
||||
if (self::$noadminnavigationnode) {
|
||||
// Admin settings tree is intended for system level settings and management only, use navigation for the rest!
|
||||
if ($this->page->context->contextlevel != CONTEXT_SYSTEM) {
|
||||
return false;
|
||||
}
|
||||
// Greater then course context or user context pages add there own navigation node, so don't load site admin.
|
||||
if (($this->page->context->contextlevel >= CONTEXT_COURSE) || ($this->page->context->contextlevel === CONTEXT_USER)) {
|
||||
if (($frontpagesettings && $frontpagesettings->contains_active_node()) ||
|
||||
($categorysettings && $categorysettings->contains_active_node()) ||
|
||||
($coursesettings && $coursesettings->contains_active_node()) ||
|
||||
($modulesettings && $modulesettings->contains_active_node()) ||
|
||||
($blocksettings && $blocksettings->contains_active_node()) ||
|
||||
($usersettings && $usersettings->contains_active_node())) {
|
||||
return false;
|
||||
} else {
|
||||
debugging('Greater then Course level administration should only be attached to site administration tree', DEBUG_DEVELOPER);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3862,7 +3834,7 @@ class settings_navigation extends navigation_node {
|
||||
|
||||
// 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()));
|
||||
$url = new moodle_url('/course/modedit.php', array('update' => $this->page->cm->id, 'return' => 1));
|
||||
$modulenode->add(get_string('editsettings'), $url, navigation_node::TYPE_SETTING, null, 'modedit');
|
||||
}
|
||||
// Assign local roles
|
||||
@@ -4454,7 +4426,7 @@ class settings_navigation extends navigation_node {
|
||||
// Manage files
|
||||
if ($course->legacyfiles == 2 and has_capability('moodle/course:managefiles', $this->context)) {
|
||||
//hiden in new installs
|
||||
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id, 'itemid'=>0, 'component' => 'course', 'filearea'=>'legacy'));
|
||||
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id));
|
||||
$frontpage->add(get_string('sitelegacyfiles'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/folder', ''));
|
||||
}
|
||||
return $frontpage;
|
||||
|
||||
@@ -36,8 +36,6 @@ $PAGE->https_required();
|
||||
|
||||
$PAGE->set_url('/login/change_password.php', array('id'=>$id));
|
||||
|
||||
$PAGE->set_context(context_system::instance());
|
||||
|
||||
if ($return) {
|
||||
// this redirect prevents security warning because https can not POST to http pages
|
||||
if (empty($SESSION->wantsurl)
|
||||
@@ -67,6 +65,10 @@ if (!isloggedin() or isguestuser()) {
|
||||
redirect(get_login_url());
|
||||
}
|
||||
|
||||
$PAGE->set_context(context_user::instance($USER->id));
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_course($course);
|
||||
|
||||
// do not require change own password cap if change forced
|
||||
if (!get_user_preferences('auth_forcepasswordchange', false)) {
|
||||
require_capability('moodle/user:changeownpassword', $systemcontext);
|
||||
@@ -124,8 +126,6 @@ if ($mform->is_cancelled()) {
|
||||
|
||||
$fullname = fullname($USER, true);
|
||||
|
||||
$PAGE->navbar->add($fullname, new moodle_url('/user/view.php', array('id'=>$USER->id, 'course'=>$course->id)));
|
||||
$PAGE->navbar->add($strpasswordchanged);
|
||||
$PAGE->set_title($strpasswordchanged);
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
echo $OUTPUT->header();
|
||||
@@ -143,8 +143,6 @@ $strchangepassword = get_string('changepassword');
|
||||
|
||||
$fullname = fullname($USER, true);
|
||||
|
||||
$PAGE->navbar->add($fullname, new moodle_url('/user/view.php', array('id'=>$USER->id, 'course'=>$course->id)));
|
||||
$PAGE->navbar->add($strchangepassword);
|
||||
$PAGE->set_title($strchangepassword);
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ $systemcontext = context_system::instance();
|
||||
$personalcontext = context_user::instance($user->id);
|
||||
|
||||
$PAGE->set_context($personalcontext);
|
||||
$PAGE->set_pagelayout('course');
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->requires->js_init_call('M.core_message.init_editsettings');
|
||||
|
||||
// check access control
|
||||
|
||||
@@ -90,7 +90,7 @@ if ($mode == 'singletemplate') {
|
||||
$PAGE->requires->js('/mod/data/data.js');
|
||||
$PAGE->set_title($data->name);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
$PAGE->set_pagelayout('report');
|
||||
$PAGE->set_pagelayout('admin');
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(format_string($data->name), 2);
|
||||
echo $OUTPUT->box(format_module_intro('data', $data, $cm->id), 'generalbox', 'intro');
|
||||
|
||||
@@ -111,7 +111,6 @@ if ($cmid){
|
||||
}
|
||||
$contexts = new question_edit_contexts($thiscontext);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
navigation_node::no_admin_navigation_node();
|
||||
|
||||
if (optional_param('addcancel', false, PARAM_BOOL)) {
|
||||
redirect($returnurl);
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ if ($mode === 'today') {
|
||||
|
||||
$stractivityreport = get_string('activityreport');
|
||||
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_pagelayout('report');
|
||||
$PAGE->set_url('/report/log/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$mode));
|
||||
$PAGE->navigation->extend_for_user($user);
|
||||
$PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
|
||||
|
||||
@@ -38,7 +38,12 @@ $inpopup = optional_param('inpopup', 0, PARAM_BOOL);
|
||||
|
||||
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
||||
|
||||
require_login($course);
|
||||
if ($course->id == SITEID) {
|
||||
require_login();
|
||||
$PAGE->set_context(context_system::instance());
|
||||
} else {
|
||||
require_login($course);
|
||||
}
|
||||
|
||||
$context = context_course::instance($course->id);
|
||||
require_capability('report/loglive:view', $context);
|
||||
|
||||
@@ -48,6 +48,7 @@ if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesrep
|
||||
} else {
|
||||
require_login($course);
|
||||
}
|
||||
$PAGE->set_url('/report/outline/user.php', array('id'=>$userid, 'course'=>$courseid, 'mode'=>$mode));
|
||||
|
||||
if (!report_outline_can_access_user_report($user, $course, true)) {
|
||||
require_capability('report/outline:view', $coursecontext);
|
||||
@@ -62,7 +63,7 @@ $event->trigger();
|
||||
|
||||
$stractivityreport = get_string('activityreport');
|
||||
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_pagelayout('report');
|
||||
$PAGE->set_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$mode));
|
||||
$PAGE->navigation->extend_for_user($user);
|
||||
$PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
|
||||
|
||||
@@ -66,6 +66,7 @@ $PAGE->set_url(new moodle_url('/report/stats/index.php', array('course' => $cour
|
||||
'time' => $time,
|
||||
'mode' => $mode,
|
||||
'userid' => $userid)));
|
||||
navigation_node::override_active_url(new moodle_url('/report/stats/index.php', array('course' => $course->id)));
|
||||
|
||||
// Trigger a content view event.
|
||||
$event = \report_stats\event\content_viewed::create(array('courseid' => $course->id,
|
||||
|
||||
@@ -51,7 +51,7 @@ if (!report_stats_can_access_user_report($user, $course, true)) {
|
||||
|
||||
$stractivityreport = get_string('activityreport');
|
||||
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_pagelayout('report');
|
||||
$PAGE->set_url('/report/stats/user.php', array('id'=>$user->id, 'course'=>$course->id));
|
||||
$PAGE->navigation->extend_for_user($user);
|
||||
$PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
|
||||
|
||||
+10
-1
@@ -52,7 +52,6 @@ if ($course->id != SITEID) {
|
||||
redirect(get_login_url());
|
||||
} else {
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_pagelayout('standard');
|
||||
}
|
||||
|
||||
// Guest can not edit
|
||||
@@ -105,6 +104,16 @@ if ($course->id == SITEID) {
|
||||
$systemcontext = context_system::instance();
|
||||
$personalcontext = context_user::instance($user->id);
|
||||
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_context($personalcontext);
|
||||
if ($USER->id != $user->id) {
|
||||
$PAGE->navigation->extend_for_user($user);
|
||||
} else {
|
||||
if ($node = $PAGE->navigation->find('myprofile', navigation_node::TYPE_ROOTNODE)) {
|
||||
$node->force_open();
|
||||
}
|
||||
}
|
||||
|
||||
// check access control
|
||||
if ($user->id == $USER->id) {
|
||||
//editing own profile - require_login() MUST NOT be used here, it would result in infinite loop!
|
||||
|
||||
+11
-7
@@ -45,7 +45,12 @@ if (!empty($USER->newadminuser)) {
|
||||
$PAGE->set_course($SITE);
|
||||
$PAGE->set_pagelayout('maintenance');
|
||||
} else {
|
||||
require_login($course);
|
||||
if ($course->id == SITEID) {
|
||||
require_login();
|
||||
$PAGE->set_context(context_system::instance());
|
||||
} else {
|
||||
require_login($course);
|
||||
}
|
||||
$PAGE->set_pagelayout('admin');
|
||||
}
|
||||
|
||||
@@ -70,13 +75,12 @@ if ($id == -1) {
|
||||
require_capability('moodle/user:update', $systemcontext);
|
||||
$user = $DB->get_record('user', array('id'=>$id), '*', MUST_EXIST);
|
||||
$PAGE->set_context(context_user::instance($user->id));
|
||||
if ($user->id == $USER->id) {
|
||||
if ($course->id != SITEID && $node = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE)) {
|
||||
$node->make_active();
|
||||
$PAGE->navbar->includesettingsbase = true;
|
||||
}
|
||||
} else {
|
||||
if ($user->id != $USER->id) {
|
||||
$PAGE->navigation->extend_for_user($user);
|
||||
} else {
|
||||
if ($node = $PAGE->navigation->find('myprofile', navigation_node::TYPE_ROOTNODE)) {
|
||||
$node->force_open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user