From 64fea720ce7dcd18e0b824b7e38738c6b7d5a13e Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Tue, 22 Apr 2014 14:08:39 +1200 Subject: [PATCH] MDL-45209 course: fixed navbar when creating,editing courses --- course/edit.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/course/edit.php b/course/edit.php index b88ab774f76..f21ca884276 100644 --- a/course/edit.php +++ b/course/edit.php @@ -31,9 +31,10 @@ $categoryid = optional_param('category', 0, PARAM_INT); // Course category - can $returnto = optional_param('returnto', 0, PARAM_ALPHANUM); // Generic navigation return page switch. $PAGE->set_pagelayout('admin'); -$pageparams = array('id'=>$id); -if (empty($id)) { - $pageparams = array('category'=>$categoryid); +if ($id) { + $pageparams = array('id' => $id); +} else { + $pageparams = array('category' => $categoryid); } $PAGE->set_url('/course/edit.php', $pageparams); @@ -166,22 +167,37 @@ $stradministration = get_string("administration"); $strcategories = get_string("categories"); if (!empty($course->id)) { - $PAGE->navbar->add($streditcoursesettings); + // Navigation note: The user is editing a course, the course will exist within the navigation and settings. + // The navigation will automatically find the Edit settings page under course navigation. + $pagedesc = $streditcoursesettings; $title = $streditcoursesettings; $fullname = $course->fullname; } else { - $PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php')); - $PAGE->navbar->add($strcategories, new moodle_url('/course/index.php')); - $PAGE->navbar->add($straddnewcourse); + // The user is adding a course, this page isn't presented in the site navigation/admin. + // Adding a new course is part of course category management territory. + // We'd prefer to use the management interface URL without args. + $managementurl = new moodle_url('/course/management.php'); + // These are the caps required in order to see the management interface. + $managementcaps = array('moodle/category:manage', 'moodle/course:create'); + if ($categoryid && !has_any_capability($managementcaps, context_system::instance())) { + // If the user doesn't have either manage caps then they can only manage within the given category. + $managementurl->param('categoryid', $categoryid); + } + // Because the course category management interfaces are buried in the admin tree and that is loaded by ajax + // we need to manually tell the navigation we need it loaded. The second arg does this. + navigation_node::override_active_url($managementurl, true); + + $pagedesc = $straddnewcourse; $title = "$site->shortname: $straddnewcourse"; $fullname = $site->fullname; + $PAGE->navbar->add($pagedesc); } $PAGE->set_title($title); $PAGE->set_heading($fullname); echo $OUTPUT->header(); -echo $OUTPUT->heading($streditcoursesettings); +echo $OUTPUT->heading($pagedesc); $editform->display();