From 5048e0349c60e7d6db1dd777ded97885567499d9 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Tue, 28 Jul 2009 03:03:35 +0000 Subject: [PATCH] course MDL-19794: Fix initialisation order problems on course/index.php. --- course/index.php | 4 ++-- course/lib.php | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/course/index.php b/course/index.php index be6ecb9014..98896519c8 100644 --- a/course/index.php +++ b/course/index.php @@ -23,7 +23,7 @@ $PAGE->set_url('course/index.php'); $PAGE->set_context($systemcontext); - if (update_category_button()) { + if (can_edit_in_category()) { if ($categoryedit !== -1) { $USER->editing = $categoryedit; } @@ -90,7 +90,7 @@ } /// Everything else is editing on mode. require_once($CFG->libdir.'/adminlib.php'); - admin_externalpage_setup('coursemgmt', update_category_button()); + admin_externalpage_setup('coursemgmt'); /// Delete a category. if (!empty($delete) and confirm_sesskey()) { diff --git a/course/lib.php b/course/lib.php index e9320fad6c..95a925eae7 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1998,6 +1998,17 @@ function print_course_request_buttons($systemcontext) { } } +/** + * Does the user have permission to edit things in this category? + * + * @param integer $categoryid The id of the category we are showing, or 0 for system context. + * @return boolean has_any_capability(array(...), ...); in the appropriate context. + */ +function can_edit_in_category($categoryid = 0) { + $context = get_category_or_system_context($categoryid); + return has_any_capability(array('moodle/category:manage', 'moodle/course:create'), $context); +} + /** * Prints the turn editing on/off button on course/index.php or course/category.php. * @@ -2009,8 +2020,7 @@ function update_category_button($categoryid = 0) { global $CFG, $PAGE; // Check permissions. - $context = get_category_or_system_context($categoryid); - if (!has_any_capability(array('moodle/category:manage', 'moodle/course:create'), $context)) { + if (!can_edit_in_category($categoryid)) { return ''; } -- 2.39.5