From f21ed0f3fcb0c31d56cfe6da12e9245c2492abcd Mon Sep 17 00:00:00 2001 From: dwoolhead Date: Thu, 21 Jun 2007 15:46:04 +0000 Subject: [PATCH] MDL-10084 propogate course id through calendar pages to ensure consistent display for site front page, my moodle and courses --- calendar/event.php | 24 ++++++++++++------------ calendar/lib.php | 25 +++++++++++++++---------- calendar/set.php | 13 ++++++++++--- calendar/view.php | 29 ++++++++++++++++------------- 4 files changed, 53 insertions(+), 38 deletions(-) diff --git a/calendar/event.php b/calendar/event.php index ca4df2a0af..660d97e9db 100644 --- a/calendar/event.php +++ b/calendar/event.php @@ -45,11 +45,6 @@ require_login(); - if(isguest()) { - // Guests cannot do anything with events - redirect(CALENDAR_URL.'view.php?view=upcoming'); - } - $action = required_param('action', PARAM_ALPHA); $eventid = optional_param('id', 0, PARAM_INT); $eventtype = optional_param('type', 'select', PARAM_ALPHA); @@ -58,6 +53,11 @@ $cal_m = optional_param('cal_m'); $cal_d = optional_param('cal_d'); + if(isguest()) { + // Guests cannot do anything with events + redirect(CALENDAR_URL.'view.php?view=upcoming&course='.$urlcourse); + } + $focus = ''; if(!$site = get_site()) { @@ -70,7 +70,7 @@ calendar_session_vars(); $now = usergetdate(time()); - $nav = calendar_get_link_tag($strcalendar, CALENDAR_URL.'view.php?view=upcoming&', $now['mday'], $now['mon'], $now['year']); + $nav = calendar_get_link_tag($strcalendar, CALENDAR_URL.'view.php?view=upcoming&course='.$urlcourse.'&', $now['mday'], $now['mon'], $now['year']); $day = intval($now['mday']); $mon = intval($now['mon']); $yr = intval($now['year']); @@ -175,7 +175,7 @@ } // OK, now redirect to day view - redirect(CALENDAR_URL.'view.php?view=day&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr); + redirect(CALENDAR_URL.'view.php?view=day&course='.$urlcourse.'&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr); } else { foreach ($err as $key => $value) { @@ -241,7 +241,7 @@ } } // OK, now redirect to day view - redirect(CALENDAR_URL.'view.php?view=day&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr); + redirect(CALENDAR_URL.'view.php?view=day&course='.$urlcourse.'&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr); } else { foreach ($err as $key => $value) { @@ -297,7 +297,7 @@ } } - redirect(CALENDAR_URL.'view.php?view=day&cal_d='.$_REQUEST['d'].'&cal_m='.$_REQUEST['m'].'&cal_y='.$_REQUEST['y']); + redirect(CALENDAR_URL.'view.php?view=day&course='.$urlcourse.'&cal_d='.$_REQUEST['d'].'&cal_m='.$_REQUEST['m'].'&cal_y='.$_REQUEST['y']); } else { @@ -545,13 +545,13 @@ echo '
'; echo '
'.get_string('monthlyview', 'calendar').'
'; echo '
'; - echo calendar_top_controls('display', array('m' => $prevmon, 'y' => $prevyr)); + echo calendar_top_controls('display', array('id' => $urlcourse, 'm' => $prevmon, 'y' => $prevyr)); echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr); echo '
'; - echo calendar_top_controls('display', array('m' => $mon, 'y' => $yr)); + echo calendar_top_controls('display', array('id' => $urlcourse, 'm' => $mon, 'y' => $yr)); echo calendar_get_mini($courses, $groups, $users, $mon, $yr); echo '
'; - echo calendar_top_controls('display', array('m' => $nextmon, 'y' => $nextyr)); + echo calendar_top_controls('display', array('id' => $urlcourse, 'm' => $nextmon, 'y' => $nextyr)); echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr); echo '
'; echo '
'; diff --git a/calendar/lib.php b/calendar/lib.php index aef7a5d6f7..68202713f5 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -641,6 +641,13 @@ function calendar_top_controls($type, $data) { $data['d'] = 1; } + // Ensure course id passed if relevant + // Required due to changes in view/lib.php mainly (calendar_session_vars()) + $courseid = ''; + if (!empty($data['id'])) { + $courseid = '&course='.$data['id']; + } + if(!checkdate($data['m'], $data['d'], $data['y'])) { $time = time(); } @@ -678,10 +685,10 @@ function calendar_top_controls($type, $data) { $content .= "\n"; break; case 'upcoming': - $content .= '
'.userdate($time, get_string('strftimemonthyear'))."
\n"; + $content .= '
'.userdate($time, get_string('strftimemonthyear'))."
\n"; break; case 'display': - $content .= '
'.userdate($time, get_string('strftimemonthyear'))."
\n"; + $content .= '
'.userdate($time, get_string('strftimemonthyear'))."
\n"; break; case 'month': list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']); @@ -689,9 +696,9 @@ function calendar_top_controls($type, $data) { $prevdate = make_timestamp($prevyear, $prevmonth, 1); $nextdate = make_timestamp($nextyear, $nextmonth, 1); $content .= "\n".'
'; - $content .= calendar_get_link_previous(userdate($prevdate, get_string('strftimemonthyear')), 'view.php?view=month&', 1, $prevmonth, $prevyear); + $content .= calendar_get_link_previous(userdate($prevdate, get_string('strftimemonthyear')), 'view.php?view=month'.$courseid.'&', 1, $prevmonth, $prevyear); $content .= ' | '.userdate($time, get_string('strftimemonthyear'))."\n"; - $content .= ' | '.calendar_get_link_next(userdate($nextdate, get_string('strftimemonthyear')), 'view.php?view=month&', 1, $nextmonth, $nextyear); + $content .= ' | '.calendar_get_link_next(userdate($nextdate, get_string('strftimemonthyear')), 'view.php?view=month'.$courseid.'&', 1, $nextmonth, $nextyear); $content .= "
\n"; break; case 'day': @@ -701,7 +708,7 @@ function calendar_top_controls($type, $data) { $prevname = calendar_wday_name($CALENDARDAYS[$prevdate['wday']]); $nextname = calendar_wday_name($CALENDARDAYS[$nextdate['wday']]); $content .= "\n".'
'; - $content .= calendar_get_link_previous($prevname, 'view.php?view=day&', $prevdate['mday'], $prevdate['mon'], $prevdate['year']); + $content .= calendar_get_link_previous($prevname, 'view.php?view=day'.$courseid.'&', $prevdate['mday'], $prevdate['mon'], $prevdate['year']); // Get the format string $text = get_string('strftimedaydate'); @@ -715,7 +722,7 @@ function calendar_top_controls($type, $data) { // Print the actual thing $content .= ' | '.$text.''; - $content .= ' | '. calendar_get_link_next($nextname, 'view.php?view=day&', $nextdate['mday'], $nextdate['mon'], $nextdate['year']); + $content .= ' | '. calendar_get_link_next($nextname, 'view.php?view=day'.$courseid.'&', $nextdate['mday'], $nextdate['mon'], $nextdate['year']); $content .= "
\n"; break; } @@ -1168,11 +1175,9 @@ function calendar_session_vars() { if(!isset($SESSION->cal_show_user)) { $SESSION->cal_show_user = true; } - // Version 1.76 to version 1.77 change, which commented out following if - // statement prevented individual course from being selected! Investigate - if(empty($SESSION->cal_courses_shown)) { + // if(empty($SESSION->cal_courses_shown)) { $SESSION->cal_courses_shown = calendar_get_default_courses(true); - } + //} if(empty($SESSION->cal_users_shown)) { // The empty() instead of !isset() here makes a whole world of difference, // as it will automatically change to the user's id when the user first logs diff --git a/calendar/set.php b/calendar/set.php index 9835770e5f..9beba6a2cc 100644 --- a/calendar/set.php +++ b/calendar/set.php @@ -52,6 +52,13 @@ // Initialize the session variables calendar_session_vars(); + // Ensure course id passed if relevant + // Required due to changes in view/lib.php mainly (calendar_session_vars()) + $courseid = ''; + if (!empty($id)) { + $courseid = '&course='.$id; + } + switch($var) { case 'setuser': // Not implemented yet (or possibly at all) @@ -101,13 +108,13 @@ redirect(CALENDAR_URL.'event.php?action='.$action.'&type='.$type.'&id='.intval($id)); break; case 'month': - redirect(CALENDAR_URL.'view.php?view=month&cal_d='.$cal_d.'&cal_m='.$cal_m.'&cal_y='.$cal_y); + redirect(CALENDAR_URL.'view.php?view=month'.$courseid.'&cal_d='.$cal_d.'&cal_m='.$cal_m.'&cal_y='.$cal_y); break; case 'upcoming': - redirect(CALENDAR_URL.'view.php?view=upcoming'); + redirect(CALENDAR_URL.'view.php?view=upcoming'.$courseid); break; case 'day': - redirect(CALENDAR_URL.'view.php?view=day&cal_d='.$cal_d.'&cal_m='.$cal_m.'&cal_y='.$cal_y); + redirect(CALENDAR_URL.'view.php?view=day'.$courseid.'&cal_d='.$cal_d.'&cal_m='.$cal_m.'&cal_y='.$cal_y); break; case 'course': redirect($CFG->wwwroot.'/course/view.php?id='.intval($id)); diff --git a/calendar/view.php b/calendar/view.php index a617d18168..b12d827eea 100644 --- a/calendar/view.php +++ b/calendar/view.php @@ -149,13 +149,13 @@ switch($view) { case 'day': - calendar_show_day($day, $mon, $yr, $courses, $groups, $users); + calendar_show_day($day, $mon, $yr, $courses, $groups, $users, $courseid); break; case 'month': - calendar_show_month_detailed($mon, $yr, $courses, $groups, $users); + calendar_show_month_detailed($mon, $yr, $courses, $groups, $users, $courseid); break; case 'upcoming': - calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS)); + calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS), $courseid); break; } @@ -184,7 +184,7 @@ echo ''; list($prevmon, $prevyr) = calendar_sub_month($mon, $yr); list($nextmon, $nextyr) = calendar_add_month($mon, $yr); - $getvars = 'cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering + $getvars = 'id='.$courseid.'&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering echo '
'; echo '
'.get_string('eventskey', 'calendar').'
'; @@ -197,13 +197,13 @@ echo '
'.get_string('monthlyview', 'calendar').'
'; echo '
'; - echo calendar_top_controls('display', array('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('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('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 '
'; echo '
'; @@ -216,7 +216,7 @@ -function calendar_show_day($d, $m, $y, $courses, $groups, $users) { +function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) { global $CFG, $USER; if (!checkdate($m, $d, $y)) { @@ -237,6 +237,7 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users) { $text.= '
'; $text.= '
'; $text.= ''; + $text.= ''; $text.= ''; $text.= ''; $text.= ''; @@ -248,7 +249,7 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users) { echo '
'.$text.'
'; - echo '
'.calendar_top_controls('day', array('d' => $d, 'm' => $m, 'y' => $y)).'
'; + echo '
'.calendar_top_controls('day', array('id' => $courseid, 'd' => $d, 'm' => $m, 'y' => $y)).'
'; if (empty($events)) { // There is nothing to display today. @@ -302,7 +303,7 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users) { } } -function calendar_show_month_detailed($m, $y, $courses, $groups, $users) { +function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) { global $CFG, $SESSION, $USER, $CALENDARDAYS; global $day, $mon, $yr; @@ -375,6 +376,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) { $text.= '
'; $text.= '
'; $text.= ''; + $text.= ''; $text.= ''; $text.= ''; $text.= ''; @@ -386,7 +388,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) { echo '
'.$text.'
'; echo '
'; - echo calendar_top_controls('month', array('m' => $m, 'y' => $y)); + echo calendar_top_controls('month', array('id' => $courseid, 'm' => $m, 'y' => $y)); echo '
'; // Start calendar display @@ -421,7 +423,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) { // Reset vars $cell = ''; - $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&', $day, $m, $y); + $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&course='.$courseid.'&', $day, $m, $y); if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) { // Weekend. This is true no matter what the exact range is. @@ -507,7 +509,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) { } -function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $maxevents) { +function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $maxevents, $courseid) { global $USER; $events = calendar_get_upcoming($courses, $groups, $users, $futuredays, $maxevents); @@ -519,6 +521,7 @@ function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $ $text.= ''; $text.= '
'; $text.= ''; + $text.= ''; /* $text.= ''; $text.= ''; -- 2.39.5