From ca74470c8d47c99ff0bd6fcf342e37737a7c4a6b Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Wed, 4 Aug 2010 07:37:02 +0000 Subject: [PATCH] MDL-23616 extremely messy hack to work around weird course handling resulting in unknown PAGE->context --- calendar/delete.php | 9 +++++---- calendar/export.php | 5 ++++- calendar/preferences.php | 1 + calendar/set.php | 1 + calendar/view.php | 8 ++++++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/calendar/delete.php b/calendar/delete.php index 56cb8be45bb..823e26ab346 100644 --- a/calendar/delete.php +++ b/calendar/delete.php @@ -50,10 +50,11 @@ $event = calendar_event::load($eventid); */ if ($event->eventtype !== 'user' && $event->eventtype !== 'site') { $courseid = $event->courseid; - $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); - require_login($course); -} else { - require_login(); +} +$course = $DB->get_record('course', array('id'=>$courseid)); +require_login($course); +if (!$course) { + $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong } // Check the user has the required capabilities to edit an event diff --git a/calendar/export.php b/calendar/export.php index 6d57e57da3d..3c9afeb0a19 100644 --- a/calendar/export.php +++ b/calendar/export.php @@ -79,7 +79,10 @@ if ($course !== NULL) { } $PAGE->set_url($url); -require_login(); +require_login($course); +if (!$course) { + $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong +} if (empty($CFG->enablecalendarexport)) { die('no export'); diff --git a/calendar/preferences.php b/calendar/preferences.php index a221b046c95..a0f7c8d1494 100644 --- a/calendar/preferences.php +++ b/calendar/preferences.php @@ -17,6 +17,7 @@ if ($course->id != SITEID) { require_login($course); } else { require_login(); + $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong } // Initialize the session variables calendar_session_vars(); diff --git a/calendar/set.php b/calendar/set.php index 3a46d570d10..039139efc40 100644 --- a/calendar/set.php +++ b/calendar/set.php @@ -70,6 +70,7 @@ if ($type !== 0) { $url->param('type', $type); } $PAGE->set_url($url); +$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong // Initialize the session variables calendar_session_vars(); diff --git a/calendar/view.php b/calendar/view.php index b84eb6485c3..173e37ff341 100644 --- a/calendar/view.php +++ b/calendar/view.php @@ -70,11 +70,15 @@ if ($yr !== 0) { } $PAGE->set_url($url); +//TODO: the courseid handling in /calendar/ is a bloody mess!!! + if ($courseid && $courseid != SITEID) { require_login($courseid); } else if ($CFG->forcelogin) { - $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); + $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong require_login(); +} else { + $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong } $calendar = new calendar_information($day, $mon, $yr); @@ -140,7 +144,7 @@ if (!isloggedin() or isguestuser()) { // but NOT for the "main page" course if ($SESSION->cal_course_referer != SITEID && ($shortname = $DB->get_field('course', 'shortname', array('id'=>$SESSION->cal_course_referer))) !== false) { - require_login(); + require_login(); //TODO: very wrong!! if (empty($course)) { $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer)); // Useful to have around }