Skip to content

Commit

Permalink
MDL-41811 simplify the admin tree detection logic and fix navigation …
Browse files Browse the repository at this point in the history
…in multiple areas
  • Loading branch information
skodak authored and Rajesh Taneja committed Oct 21, 2013
1 parent bafcd3f commit d5814f4
Show file tree
Hide file tree
Showing 35 changed files with 167 additions and 175 deletions.
9 changes: 2 additions & 7 deletions admin/roles/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@
$PAGE->set_url($url);
$PAGE->set_context($context);

if ($isfrontpage) {
navigation_node::require_admin_tree();
}

$contextname = $context->get_context_name();
$courseid = $course->id;

Expand Down Expand Up @@ -153,12 +149,11 @@
$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);
}
Expand Down
13 changes: 10 additions & 3 deletions admin/roles/check.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
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;
Expand Down Expand Up @@ -79,12 +87,11 @@
$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);
}
Expand Down
19 changes: 13 additions & 6 deletions admin/roles/override.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@
$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));
Expand Down Expand Up @@ -93,12 +101,11 @@
$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);
}
Expand Down
14 changes: 10 additions & 4 deletions admin/roles/permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@
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;


Expand Down Expand Up @@ -88,12 +95,11 @@
$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);
}
Expand Down
14 changes: 10 additions & 4 deletions admin/roles/usersroles.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@
$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) {
Expand Down Expand Up @@ -120,10 +126,10 @@

// 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);
Expand Down
23 changes: 0 additions & 23 deletions admin/settings/frontpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,6 @@
}
$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));
}
}
}
2 changes: 1 addition & 1 deletion admin/tool/customlang/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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);
Expand Down
2 changes: 1 addition & 1 deletion badges/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
$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);
Expand Down
4 changes: 1 addition & 3 deletions cohort/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

$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));

Expand All @@ -51,11 +52,8 @@
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'));

Expand Down
3 changes: 1 addition & 2 deletions cohort/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@
$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) {
Expand Down
2 changes: 1 addition & 1 deletion cohort/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
$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);
Expand Down
16 changes: 9 additions & 7 deletions course/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,26 @@
$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.
Expand Down
8 changes: 2 additions & 6 deletions course/editcategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
$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);
Expand All @@ -54,6 +55,7 @@
} 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;
Expand All @@ -66,12 +68,6 @@

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');
Expand Down
7 changes: 6 additions & 1 deletion course/management.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,25 @@
}

$url = new moodle_url('/course/management.php');
navigation_node::override_active_url($url);
$systemcontext = $context = context_system::instance();
if ($courseid) {
$record = get_course($courseid);
$course = new course_in_list($record);
$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;
Expand All @@ -72,6 +76,7 @@
$viewmode = 'categories';
}
$context = $systemcontext;
navigation_node::override_active_url($url);
}

if ($page !== 0) {
Expand Down
4 changes: 3 additions & 1 deletion course/modedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
$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);

Expand Down Expand Up @@ -241,7 +244,6 @@
}
$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)) {
Expand Down
1 change: 1 addition & 0 deletions course/reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
}

$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));
Expand Down
2 changes: 1 addition & 1 deletion course/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
$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);
Expand Down
Loading

0 comments on commit d5814f4

Please sign in to comment.