From 0572e4291dcf669cf5d18d0a9df008f7f97c7745 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Thu, 11 Oct 2007 05:22:49 +0000 Subject: [PATCH] MDL-10353, calender redirection broken when editting and exporting --- calendar/export.php | 33 +++++++++++++++++++-------------- calendar/lib.php | 2 +- calendar/view.php | 5 ++++- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/calendar/export.php b/calendar/export.php index 94778be5bd1..66fd4f026ac 100644 --- a/calendar/export.php +++ b/calendar/export.php @@ -9,13 +9,8 @@ $action = optional_param('action', '', PARAM_ALPHA); $day = optional_param('cal_d', 0, PARAM_INT); $mon = optional_param('cal_m', 0, PARAM_INT); $yr = optional_param('cal_y', 0, PARAM_INT); - -if (isset($SESSION->cal_course_referer)) { - $course = $SESSION->cal_course_referer; -} else { - $course = optional_param('course', 0, PARAM_INT); -} - +$courseid = optional_param('course', 0, PARAM_INT); + require_login(); if(!$site = get_site()) { @@ -27,7 +22,7 @@ calendar_session_vars(); $pagetitle = get_string('export', 'calendar'); $now = usergetdate(time()); -$nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL.'view.php?view=upcoming&course='.$course.'&', $now['mday'], $now['mon'], $now['year']).' -> '.$pagetitle; +$nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL.'view.php?view=upcoming&course='.$courseid.'&', $now['mday'], $now['mon'], $now['year']).' -> '.$pagetitle; if(!checkdate($mon, $day, $yr)) { $day = intval($now['mday']); @@ -36,13 +31,23 @@ if(!checkdate($mon, $day, $yr)) { } $time = make_timestamp($yr, $mon, $day); -$SESSION->cal_courses_shown = calendar_get_default_courses(true); -calendar_set_referring_course(0); +if ($courseid) { + if ($course = get_record('course', 'id', $courseid)) { + if ($course->id == SITEID) { + // If coming from the home page, show all courses + $SESSION->cal_courses_shown = calendar_get_default_courses(true); + calendar_set_referring_course(0); + } else { + // Otherwise show just this one + $SESSION->cal_courses_shown = $course->id; + calendar_set_referring_course($SESSION->cal_courses_shown); + } + } +} if (empty($USER->id) or isguest()) { $defaultcourses = calendar_get_default_courses(); calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses); - } else { calendar_set_filters($courses, $groups, $users); } @@ -99,13 +104,13 @@ list($nextmon, $nextyr) = calendar_add_month($mon, $yr); $getvars = 'cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering echo '
'; -echo calendar_top_controls('display', array('id' => $course, 'm' => $prevmon, 'y' => $prevyr)); +echo calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr)); echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr); echo '
'; -echo calendar_top_controls('display', array('id' => $course, 'm' => $mon, 'y' => $yr)); +echo calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr)); echo calendar_get_mini($courses, $groups, $users, $mon, $yr); echo '
'; -echo calendar_top_controls('display', array('id' => $course, 'm' => $nextmon, 'y' => $nextyr)); +echo calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr)); echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr); echo '
'; diff --git a/calendar/lib.php b/calendar/lib.php index b6636d1a118..bda9e211ff6 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -490,7 +490,7 @@ function calendar_print_event($event) { if (!empty($event->calendarcourseid)) { $calendarcourseid = '&course='.$event->calendarcourseid; } - + if (empty($event->cmid)) { $editlink = CALENDAR_URL.'event.php?action=edit&id='.$event->id.$calendarcourseid; $deletelink = CALENDAR_URL.'event.php?action=delete&id='.$event->id.$calendarcourseid; diff --git a/calendar/view.php b/calendar/view.php index 09eedb655c3..c0326bd1eec 100644 --- a/calendar/view.php +++ b/calendar/view.php @@ -161,7 +161,7 @@ //Link to calendar export page echo '
'; - print_single_button('export.php', false, get_string('exportcalendar', 'calendar')); + print_single_button('export.php', array('course'=>$courseid), get_string('exportcalendar', 'calendar')); if (!empty($USER->id)) { $authtoken = sha1($USER->username . $USER->password); @@ -259,6 +259,8 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) { // First, print details about events that start today foreach ($events as $event) { + $event->calendarcourseid = $courseid; + if ($event->timestart >= $starttime && $event->timestart <= $endtime) { // Print it now @@ -578,6 +580,7 @@ function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $ if ($events) { echo '
'; foreach ($events as $event) { + $event->calendarcourseid = $courseid; calendar_print_event($event); } echo '
';