return false;
}
$orderby = 'visible DESC, sortorder ASC';
- $options = array();
+ $options = array(0 => get_string('site'));
if ($courses = get_user_capability_course('tool/monitor:subscribe', null, true, 'fullname', $orderby)) {
foreach ($courses as $course) {
$options[$course->id] = format_string($course->fullname, true,
array('context' => \context_course::instance($course->id)));
}
}
- // If there are no options to display, then don't display anything.
- if (count($options) === 0) {
- return false;
- }
$url = new \moodle_url('/admin/tool/monitor/index.php');
$select = new \single_select($url, 'courseid', $options, $this->courseid);
$select->set_label(get_string('selectacourse', 'tool_monitor'));
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
-$courseid = optional_param('courseid', SITEID, PARAM_INT);
+$courseid = optional_param('courseid', 0, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
$cmid = optional_param('cmid', 0, PARAM_INT);
$ruleid = optional_param('ruleid', 0, PARAM_INT);
$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.
+// Validate course id.
if (empty($courseid)) {
- $courseid = SITEID;
+ require_login();
+} else {
+ // They might want to see rules for this course.
+ $course = get_course($courseid);
+ require_login($course);
+ $coursecontext = context_course::instance($course->id);
+ // Check for caps.
+ require_capability('tool/monitor:subscribe', $coursecontext);
+ $coursename = format_string($course->fullname, true, array('context' => $coursecontext));
}
-$coursecontext = context_course::instance($courseid);
-
if (!get_config('tool_monitor', 'enablemonitor')) {
// This should never happen as the this page does not appear in navigation when the tool is disabled.
throw new coding_exception('Event monitoring is disabled');
}
+// Set the main context to a system context.
+$systemcontext = context_system::instance();
+$sitename = format_string($SITE->fullname, true, array('context' => $systemcontext));
+// Use the user context here so that the header shows user information.
$PAGE->set_context(context_user::instance($USER->id));
// Set up the page.
} else {
$subscription = \tool_monitor\subscription_manager::get_subscription($subscriptionid);
echo $OUTPUT->header();
- echo $OUTPUT->confirm(get_string('subareyousure', 'tool_monitor', $subscription->get_name($coursecontext)),
+ echo $OUTPUT->confirm(get_string('subareyousure', 'tool_monitor', $subscription->get_name($systemcontext)),
$confirmurl, $cancelurl);
echo $OUTPUT->footer();
exit();
}
// Render the potential rules list.
-// Check the capability here before displaying any rules to subscribe to.
-if (has_capability('tool/monitor:subscribe', $coursecontext)) {
- echo $OUTPUT->heading(get_string('rulescansubscribe', 'tool_monitor'), 3);
- echo $renderer->render($rules);
-}
+echo $OUTPUT->heading(get_string('rulescansubscribe', 'tool_monitor'), 3);
+echo $renderer->render($rules);
// Check if the user can manage the course rules we are viewing.
-$canmanagerules = has_capability('tool/monitor:managerules', $coursecontext);
+if (empty($courseid)) {
+ $canmanagerules = has_capability('tool/monitor:managerules', $systemcontext);
+} else {
+ $canmanagerules = has_capability('tool/monitor:managerules', $coursecontext);
+}
if (empty($totalrules)) {
// No rules present. Show a link to manage rules page if permissions permit.
// Don't show the setting if the event monitor isn't turned on. No access to other peoples subscriptions.
if (get_config('tool_monitor', 'enablemonitor') && $USER->id == $user->id) {
- // 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));
+ $url = new moodle_url('/admin/tool/monitor/index.php');
$subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url,
navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', ''));