]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10084 propogate course id through calendar pages to ensure consistent display...
authordwoolhead <dwoolhead>
Thu, 21 Jun 2007 15:46:04 +0000 (15:46 +0000)
committerdwoolhead <dwoolhead>
Thu, 21 Jun 2007 15:46:04 +0000 (15:46 +0000)
calendar/event.php
calendar/lib.php
calendar/set.php
calendar/view.php

index ca4df2a0af038e89833986809693467658acf29d..660d97e9db344b03d33387ea6d1b3ed6e6bf07be 100644 (file)
 
     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);
     $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&amp;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&amp;', $now['mday'], $now['mon'], $now['year']);
+    $nav = calendar_get_link_tag($strcalendar, CALENDAR_URL.'view.php?view=upcoming&amp;course='.$urlcourse.'&amp;', $now['mday'], $now['mon'], $now['year']);
     $day = intval($now['mday']);
     $mon = intval($now['mon']);
     $yr = intval($now['year']);
                     }
 
                     // 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&amp;course='.$urlcourse.'&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr);
                 }
                 else {
                     foreach ($err as $key => $value) {
                         }
                     }
                     // 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&amp;course='.$urlcourse.'&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr);
                 }
                 else {
                     foreach ($err as $key => $value) {
                     }
                 }
 
-                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&amp;course='.$urlcourse.'&cal_d='.$_REQUEST['d'].'&cal_m='.$_REQUEST['m'].'&cal_y='.$_REQUEST['y']);
 
             }
             else {
     echo '<div class="sideblock">';
     echo '<div class="header">'.get_string('monthlyview', 'calendar').'</div>';
     echo '<div class="minicalendarblock minicalendartop">';
-    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 '</div><div class="minicalendarblock">';
-    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 '</div><div class="minicalendarblock">';
-    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 '</div>';
     echo '</div>';
index aef7a5d6f7bb3eed1bdcc17cf6524c6f0ce8cdea..68202713f58a82248b1ae0ca2fb2e71c52597506 100644 (file)
@@ -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 = '&amp;course='.$data['id'];
+    }
+
     if(!checkdate($data['m'], $data['d'], $data['y'])) {
         $time = time();
     }
@@ -678,10 +685,10 @@ function calendar_top_controls($type, $data) {
             $content .= "<span class=\"clearer\"><!-- --></span></div>\n";
         break;
         case 'upcoming':
-            $content .= '<div style="text-align: center;"><a href="'.CALENDAR_URL.'view.php?view=upcoming">'.userdate($time, get_string('strftimemonthyear'))."</a></div>\n";
+            $content .= '<div style="text-align: center;"><a href="'.CALENDAR_URL.'view.php?view=upcoming"'.$courseid.'>'.userdate($time, get_string('strftimemonthyear'))."</a></div>\n";
         break;
         case 'display':
-            $content .= '<div style="text-align: center;"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month&amp;', 1, $data['m'], $data['y']).'">'.userdate($time, get_string('strftimemonthyear'))."</a></div>\n";
+            $content .= '<div style="text-align: center;"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month'.$courseid.'&amp;', 1, $data['m'], $data['y']).'">'.userdate($time, get_string('strftimemonthyear'))."</a></div>\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".'<div class="calendar-controls">';
-            $content .= calendar_get_link_previous(userdate($prevdate, get_string('strftimemonthyear')), 'view.php?view=month&amp;', 1, $prevmonth, $prevyear);
+            $content .= calendar_get_link_previous(userdate($prevdate, get_string('strftimemonthyear')), 'view.php?view=month'.$courseid.'&amp;', 1, $prevmonth, $prevyear);
             $content .= '<span class="hide"> | </span><span class="current">'.userdate($time, get_string('strftimemonthyear'))."</span>\n";
-            $content .= '<span class="hide"> | </span>'.calendar_get_link_next(userdate($nextdate, get_string('strftimemonthyear')), 'view.php?view=month&amp;', 1, $nextmonth, $nextyear);
+            $content .= '<span class="hide"> | </span>'.calendar_get_link_next(userdate($nextdate, get_string('strftimemonthyear')), 'view.php?view=month'.$courseid.'&amp;', 1, $nextmonth, $nextyear);
             $content .= "<span class=\"clearer\"><!-- --></span></div>\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".'<div class="calendar-controls">';
-            $content .= calendar_get_link_previous($prevname, 'view.php?view=day&amp;', $prevdate['mday'], $prevdate['mon'], $prevdate['year']);
+            $content .= calendar_get_link_previous($prevname, 'view.php?view=day'.$courseid.'&amp;', $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 .= '<span class="hide"> | </span><span class="current">'.$text.'</span>';
 
-            $content .= '<span class="hide"> | </span>'. calendar_get_link_next($nextname, 'view.php?view=day&amp;', $nextdate['mday'], $nextdate['mon'], $nextdate['year']);
+            $content .= '<span class="hide"> | </span>'. calendar_get_link_next($nextname, 'view.php?view=day'.$courseid.'&amp;', $nextdate['mday'], $nextdate['mon'], $nextdate['year']);
             $content .= "<span class=\"clearer\"><!-- --></span></div>\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
index 9835770e5f19e541079ed8b703747c8ac98756dc..9beba6a2ccaf9404f9ab437cce1a1b7c8f9efcda 100644 (file)
     // 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 = '&amp;course='.$id;
+    }
+
     switch($var) {
         case 'setuser':
             // Not implemented yet (or possibly at all)
             redirect(CALENDAR_URL.'event.php?action='.$action.'&amp;type='.$type.'&amp;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));
index a617d18168b82d3951b678fe239880a104c834f2..b12d827eeac6e79a8fadac297f04e36f3161d0ca 100644 (file)
 
     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;
     }
 
     echo '<td class="sidecalendar">';
     list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
     list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
-    $getvars = 'cal_d='.$day.'&amp;cal_m='.$mon.'&amp;cal_y='.$yr; // For filtering
+    $getvars = 'id='.$courseid.'&amp;cal_d='.$day.'&amp;cal_m='.$mon.'&amp;cal_y='.$yr; // For filtering
 
     echo '<div class="sideblock">';
     echo '<div class="header">'.get_string('eventskey', 'calendar').'</div>';
     echo '<div class="header">'.get_string('monthlyview', 'calendar').'</div>';
 
     echo '<div class="minicalendarblock minicalendartop">';
-    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 '</div><div class="minicalendarblock">';
-    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 '</div><div class="minicalendarblock">';
-    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 '</div>';
     echo '</div>';
 
 
 
-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.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
         $text.= '<div>';
         $text.= '<input type="hidden" name="action" value="new" />';
+        $text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
         $text.= '<input type="hidden" name="cal_d" value="'.$d.'" />';
         $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
         $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
@@ -248,7 +249,7 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users) {
 
     echo '<div class="header">'.$text.'</div>';
 
-    echo '<div class="controls">'.calendar_top_controls('day', array('d' => $d, 'm' => $m, 'y' => $y)).'</div>';
+    echo '<div class="controls">'.calendar_top_controls('day', array('id' => $courseid, 'd' => $d, 'm' => $m, 'y' => $y)).'</div>';
 
     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.= '<div class="buttons"><form action="'.CALENDAR_URL.'event.php" method="get">';
         $text.= '<div>';
         $text.= '<input type="hidden" name="action" value="new" />';
+        $text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
         $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
         $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
         $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
@@ -386,7 +388,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
     echo '<div class="header">'.$text.'</div>';
 
     echo '<div class="controls">';
-    echo calendar_top_controls('month', array('m' => $m, 'y' => $y));
+    echo calendar_top_controls('month', array('id' => $courseid, 'm' => $m, 'y' => $y));
     echo '</div>';
 
     // 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&amp;', $day, $m, $y);
+        $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&amp;course='.$courseid.'&amp;', $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.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
         $text.= '<div>';
         $text.= '<input type="hidden" name="action" value="new" />';
+        $text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
         /*
         $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
         $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';