From f3a493debe9ec7de0ee17c7ea46d623850ee8691 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Thu, 9 Apr 2015 11:00:20 +0800 Subject: [PATCH] MDL-49412 tool_monitor: Minor fixes to stop errors. Part of MDL-45774. --- admin/tool/monitor/index.php | 6 ++++++ admin/tool/monitor/lib.php | 27 +++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/admin/tool/monitor/index.php b/admin/tool/monitor/index.php index 16ac05fe7c7..478cbe0a8b8 100644 --- a/admin/tool/monitor/index.php +++ b/admin/tool/monitor/index.php @@ -33,6 +33,12 @@ $subscriptionid = optional_param('subscriptionid', 0, PARAM_INT); $confirm = optional_param('confirm', false, PARAM_BOOL); require_login(); + +// We need to explicitly check that the course id is something legitimate. +if (empty($courseid)) { + $courseid = SITEID; +} + $coursecontext = context_course::instance($courseid); if (!get_config('tool_monitor', 'enablemonitor')) { diff --git a/admin/tool/monitor/lib.php b/admin/tool/monitor/lib.php index c18b8aed8a4..dd56e0f689f 100644 --- a/admin/tool/monitor/lib.php +++ b/admin/tool/monitor/lib.php @@ -77,18 +77,21 @@ function tool_monitor_extend_navigation_frontpage($navigation, $course, $context function tool_monitor_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext) { global $USER, $SITE; - // The $course->id will always be the course that corresponds to the current context. - $courseid = $course->id; - // A $course->id of $SITE->id might either be the frontpage or the site. So if we get the site ID back, check the... - // ...courseid parameter passed to the page so we can know if we are looking at the frontpage rules or site level rules. - if ($course->id == $SITE->id && optional_param('courseid', $course->id, PARAM_INT) == 0) { - $courseid = 0; - } - $url = new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $courseid)); - $subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url, - navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', '')); + // Don't show the setting if the event monitor isn't turned on. + if (get_config('tool_monitor', 'enablemonitor')) { + // The $course->id will always be the course that corresponds to the current context. + $courseid = $course->id; + // A $course->id of $SITE->id might either be the frontpage or the site. So if we get the site ID back, check the... + // ...courseid parameter passed to the page so we can know if we are looking at the frontpage rules or site level rules. + if ($course->id == $SITE->id && optional_param('courseid', $course->id, PARAM_INT) == 0) { + $courseid = 0; + } + $url = new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $courseid)); + $subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url, + navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', '')); - if (isset($subsnode) && !empty($navigation)) { - $navigation->add_node($subsnode); + if (isset($subsnode) && !empty($navigation)) { + $navigation->add_node($subsnode); + } } }