]> git.mjollnir.org Git - moodle.git/commitdiff
Major calendar overhaul:
authordefacer <defacer>
Thu, 20 May 2004 15:16:42 +0000 (15:16 +0000)
committerdefacer <defacer>
Thu, 20 May 2004 15:16:42 +0000 (15:16 +0000)
1. Much better and more intuitive handling of filters.
2. Simplified user interface for guests.
3. Feature request implemented: bug #1431
4. A number of significant bugfixes

blocks/calendar_month/block_calendar_month.php
blocks/calendar_upcoming/block_calendar_upcoming.php
calendar/i/event.gif [new file with mode: 0644]
calendar/lib.php
calendar/set.php
calendar/view.php

index 60b68c51cfc5998922e4857a10093094397cb46d..f8997f0f37ddfb35850f8c621a93375489003d67 100644 (file)
@@ -26,21 +26,16 @@ class CourseBlock_calendar_month extends MoodleBlock {
         if($this->course === NULL) {
             // Overrides: use no course at all
             $courseshown = false;
-            $defaultcourses = NULL;
+            $filtercourse = array();
         }
         else {
             $courseshown = $this->course->id;
-            $defaultcourses = array($courseshown => 1);
+            $filtercourse = array($courseshown => 1);
         }
 
         // We 'll need this later
         calendar_set_referring_course($courseshown);
 
-        if($courseshown !== false && $SESSION->cal_show_course !== false) {
-            // By default, the course filter will show this course only
-            $SESSION->cal_show_course = $courseshown;
-        }
-
         // [pj] Let's leave this in, the above may not be the final solution
         /*
         if($courseshown !== false && is_int($SESSION->cal_show_course) && $SESSION->cal_show_course != $courseshown) {
@@ -58,7 +53,7 @@ class CourseBlock_calendar_month extends MoodleBlock {
         // Be VERY careful with the format for default courses arguments!
         // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
 
-        calendar_set_filters($courses, $group, $user, $defaultcourses, $defaultcourses);
+        calendar_set_filters($courses, $group, $user, $filtercourse, $filtercourse);
 
         if($courseshown == 1) {
             // For the front page
index 01b57389d1d1159b1d04587f73769affdd339954..45ae6a750e10b2da385f2ff298d65ab838b318b6 100644 (file)
@@ -27,39 +27,20 @@ class CourseBlock_calendar_upcoming extends MoodleBlock {
         if($this->course === NULL) {
             // Overrides: use no course at all
             $courseshown = false;
-            $defaultcourses = NULL;
+            $filtercourse = array();
         }
         else {
             $courseshown = $this->course->id;
-            $defaultcourses = array($courseshown => 1);
+            $filtercourse = array($courseshown => 1);
         }
 
         // We 'll need this later
         calendar_set_referring_course($courseshown);
 
-        if($courseshown !== false && $SESSION->cal_show_course !== false) {
-            // By default, the course filter will show this course only
-            $SESSION->cal_show_course = $courseshown;
-        }
-
-        // [pj] Let's leave this in, the above may not be the final solution
-        /*
-        if($courseshown !== false && is_int($SESSION->cal_show_course) && $SESSION->cal_show_course != $courseshown) {
-            // There is a filter in action that shows events from a course other than the current
-            // Change it to show only the current course
-            $SESSION->cal_show_course = $courseshown;
-        }
-        else if($courseshown !== false && is_array($SESSION->cal_show_course) && !in_array($courseshown, $SESSION->cal_show_course)) {
-            // Same as above, only there are many courses being shown. Unfortunately, not this one.
-            // Change it to show only the current course
-            $SESSION->cal_show_course = $courseshown;
-        }
-        */
-
         // Be VERY careful with the format for default courses arguments!
         // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
 
-        calendar_set_filters($courses, $group, $user, $defaultcourses, $defaultcourses);
+        calendar_set_filters($courses, $group, $user, $filtercourse, $filtercourse, false);
 
         $this->content->text = calendar_get_sideblock_upcoming($courses, $group, $user, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS));
 
diff --git a/calendar/i/event.gif b/calendar/i/event.gif
new file mode 100644 (file)
index 0000000..a827d8b
Binary files /dev/null and b/calendar/i/event.gif differ
index 3362e6f82bd84c163864790d1a1435a9fb9c8620..5927bb7b395a1c4ac57298170d23fb907afb4e20 100644 (file)
@@ -170,7 +170,7 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y
                     $popupcontent .= '<div><img src=\\\''.$CFG->modpixpath.'/'.$events[$eventid]->modulename.'/icon.gif\\\' style=\\\'vertical-align: middle; margin-right: 4px;\\\' alt=\\\''.$events[$eventid]->modulename.'\\\' /><a href=\\\''.CALENDAR_URL.'view.php?view=event&amp;id='.$events[$eventid]->id.'\\\'>'.addslashes(htmlspecialchars($events[$eventid]->name)).'</a></div>';
                 }
                 else {
-                    $popupcontent .= '<div style=\\\'padding-left: 20px;\\\'><a href=\\\''.CALENDAR_URL.'view.php?view=event&amp;id='.$events[$eventid]->id.'\\\'>'.addslashes(htmlspecialchars($events[$eventid]->name)).'</a></div>';
+                    $popupcontent .= '<div><img src=\\\''.$CFG->wwwroot.'/calendar/i/event.gif\\\' style=\\\'vertical-align: middle; margin-right: 4px;\\\' alt=\\\'\\\' /><a href=\\\''.CALENDAR_URL.'view.php?view=event&amp;id='.$events[$eventid]->id.'\\\'>'.addslashes(htmlspecialchars($events[$eventid]->name)).'</a></div>';
                 }
             }
 
@@ -363,7 +363,7 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve
                 $eventtype = get_string($event->eventtype, $event->modulename);
                 $icon = $CFG->modpixpath.'/'.$event->modulename.'/icon.gif';
                 $output[$outkey]->referer = '<a href="'.$CFG->wwwroot.'/mod/'.$event->modulename.'/view.php?id='.$module->id.'">'.$event->name.'</a>';
-                $output[$outkey]->icon = '<img src="'.$icon.'" title="'.$modulename.'" style="vertical-align: middle;" />';
+                $output[$outkey]->icon = '<img src="'.$icon.'" alt="" title="'.$modulename.'" style="vertical-align: middle;" />';
                 $output[$outkey]->name = $event->name;
                 $output[$outkey]->time = $eventtime;
                 $output[$outkey]->description = $event->description;
@@ -372,7 +372,7 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve
                 // Global event
                 global $site;
                 $output[$outkey]->referer = '<a href="'.$CFG->wwwroot.'">'.$site->shortname.'</a>';
-                $output[$outkey]->icon = '';
+                $output[$outkey]->icon = '<img src="'.$CFG->wwwroot.'/calendar/i/event.gif" alt="" style="vertical-align: middle;" />';
                 $output[$outkey]->name = $event->name;
                 $output[$outkey]->time = $eventtime;
                 $output[$outkey]->description = $event->description;
@@ -382,21 +382,21 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve
                 calendar_get_course_cached($coursecache, $event->courseid);
 
                 $output[$outkey]->referer = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$coursecache[$event->courseid]->id.'">'.$coursecache[$event->courseid]->fullname.'</a>';
-                $output[$outkey]->icon = '';
+                $output[$outkey]->icon = '<img src="'.$CFG->wwwroot.'/calendar/i/event.gif" alt="" style="vertical-align: middle;" />';
                 $output[$outkey]->name = $event->name;
                 $output[$outkey]->time = $eventtime;
                 $output[$outkey]->description = $event->description;
             }
             else if($event->groupid) {
                 // Group event
-                $output[$outkey]->icon = '';
+                $output[$outkey]->icon = '<img src="'.$CFG->wwwroot.'/calendar/i/event.gif" alt="" style="vertical-align: middle;" />';
                 $output[$outkey]->name = $event->name;
                 $output[$outkey]->time = $eventtime;
                 $output[$outkey]->description = $event->description;
-        }
+            }
             else if($event->userid) {
                 // User event
-                $output[$outkey]->icon = '';
+                $output[$outkey]->icon = '<img src="'.$CFG->wwwroot.'/calendar/i/event.gif" alt="" style="vertical-align: middle;" />';
                 $output[$outkey]->name = $event->name;
                 $output[$outkey]->time = $eventtime;
                 $output[$outkey]->description = $event->description;
@@ -511,20 +511,7 @@ function calendar_top_controls($type, $data) {
             $content .= '</tr></table>';
         break;
         case 'upcoming':
-            // A quick check reveals that this is not used at all
-            /*
-            list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
-            list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
-            $prevdate = getdate(calendar_mktime_check($prevmonth, 1, $prevyear));
-            $nextdate = getdate(calendar_mktime_check($nextmonth, 1, $nextyear));
-            $prevname = calendar_month_name($prevdate['month']);
-            $nextname = calendar_month_name($nextdate['month']);
-            $content .= "<tr>\n";
-            $content .= '<td style="text-align: center"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month&amp;', 1, $prevmonth, $prevyear).'">'.$prevname.' '.$prevyear."</a></td>\n";
-            $content .= '<td style="text-align: center"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month&amp;', 1, $data['m'], $data['y']).'">'.$monthname.' '.$data['y']."</a></td>\n";
-            $content .= '<td style="text-align: center"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month&amp;', 1, $nextmonth, $nextyear).'">'.$nextname.' '.$nextyear."</a></td>\n";
-            $content .= "</tr>\n";
-            */
+            $content .= '<div style="text-align: center;"><a href="'.CALENDAR_URL.'view.php?view=upcoming">'.strftime(get_string('strftimemonthyear'), $time)."</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']).'">'.strftime(get_string('strftimemonthyear'), $time)."</a></div>\n";
@@ -568,7 +555,7 @@ function calendar_top_controls($type, $data) {
 }
 
 function calendar_filter_controls($type, $vars = NULL) {
-    global $CFG, $SESSION;
+    global $CFG, $SESSION, $USER;
 
     $groupevents = true;
 
@@ -616,31 +603,33 @@ function calendar_filter_controls($type, $vars = NULL) {
     else {
         $content .= '<td style="width: 8px;"></td><td><a href="'.CALENDAR_URL.'set.php?var=showcourses'.$getvars.'" title="'.get_string('tt_showcourse', 'calendar').'">'.get_string('courseevents', 'calendar').'</a></td>'."\n";
     }
-    $content .= "</tr>\n";
-    $content .= '<tr>';
 
-    if($groupevents) {
-        // This course MIGHT have group events defined, so show the filter
-        if($SESSION->cal_show_groups) {
-            $content .= '<td class="cal_event_group" style="width: 8px;"></td><td><a href="'.CALENDAR_URL.'set.php?var=showgroups'.$getvars.'" title="'.get_string('tt_hidegroups', 'calendar').'">'.get_string('groupevents', 'calendar').'</a></td>'."\n";
-        }
-        else {
-            $content .= '<td style="width: 8px;"></td><td><a href="'.CALENDAR_URL.'set.php?var=showgroups'.$getvars.'" title="'.get_string('clickshowgroups', 'calendar').'">'.get_string('groupevents', 'calendar').'</a></td>'."\n";
-        }
-        if($SESSION->cal_show_user) {
-            $content .= '<td class="cal_event_user" style="width: 8px;"></td><td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_hideuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
-        }
-        else {
-            $content .= '<td style="width: 8px;"></td><td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('clickshowuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
-        }
-    }
-    else {
-        // This course CANNOT have group events, so lose the filter
-        if($SESSION->cal_show_user) {
-            $content .= '<td class="cal_event_user" style="width: 8px;"></td><td colspan="3"><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_hideuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
+    if(!isguest($USER->id)) {
+        $content .= "</tr>\n<tr>";
+
+        if($groupevents) {
+            // This course MIGHT have group events defined, so show the filter
+            if($SESSION->cal_show_groups) {
+                $content .= '<td class="cal_event_group" style="width: 8px;"></td><td><a href="'.CALENDAR_URL.'set.php?var=showgroups'.$getvars.'" title="'.get_string('tt_hidegroups', 'calendar').'">'.get_string('groupevents', 'calendar').'</a></td>'."\n";
+            }
+            else {
+                $content .= '<td style="width: 8px;"></td><td><a href="'.CALENDAR_URL.'set.php?var=showgroups'.$getvars.'" title="'.get_string('tt_showgroups', 'calendar').'">'.get_string('groupevents', 'calendar').'</a></td>'."\n";
+            }
+            if($SESSION->cal_show_user) {
+                $content .= '<td class="cal_event_user" style="width: 8px;"></td><td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_hideuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
+            }
+            else {
+                $content .= '<td style="width: 8px;"></td><td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_showuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
+            }
         }
         else {
-            $content .= '<td style="width: 8px;"></td><td colspan="3"><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('clickshowuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
+            // This course CANNOT have group events, so lose the filter
+            if($SESSION->cal_show_user) {
+                $content .= '<td class="cal_event_user" style="width: 8px;"></td><td colspan="3"><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_hideuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
+            }
+            else {
+                $content .= '<td style="width: 8px;"></td><td colspan="3"><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_showuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
+            }
         }
     }
     $content .= "</tr>\n</table>\n";
@@ -767,7 +756,7 @@ function calendar_get_sideblock_upcoming($courses, $groups, $users, $daysinfutur
 
     for ($i = 0; $i < $lines; ++$i) {
         $content .= '<div class="cal_event">'.$events[$i]->icon.' ';
-        if (!empty($events[$i]->icon)) {
+        if (!empty($events[$i]->referer)) {
             // That's an activity event, so let's provide the hyperlink
             $content .= $events[$i]->referer;
         } else {
@@ -901,6 +890,9 @@ function calendar_session_vars() {
     if(!isset($SESSION->cal_show_user)) {
         $SESSION->cal_show_user = $USER->id;
     }
+    if(empty($SESSION->cal_courses_shown)) {
+        $SESSION->cal_courses_shown = calendar_get_default_courses(true);
+    }
 }
 
 function calendar_overlib_html() {
@@ -913,143 +905,43 @@ function calendar_overlib_html() {
     return $html;
 }
 
-// OBSOLETE, now that we have the blocks system in place.
-// Keeping it for a few revisions, just in case.
-/*
-function calendar_print_side_blocks($forcecourse = NULL) {
-    // WARNING: Keep in mind that using $forcecourse will override the $SESSION
-    // filters, and thus not respect the user's filter settings. Use it sparingly.
-
-    global $USER, $CFG, $SESSION, $course;
-    optional_variable($_GET['cal_m']);
-    optional_variable($_GET['cal_y']);
-
-    calendar_session_vars();
-
-    if(is_int($forcecourse)) {
-        // Overrides the course to use
-        $courseshown = $forcecourse;
-        $defaultcourses = array($courseshown => 1);
-    }
-    else if($forcecourse === false) {
-        // Overrides: use no course at all
-        $courseshown = false;
-        $defaultcourses = NULL;
-    }
-    else {
-        // Normal behavior: use displayed course, or front page if no course
-        $courseshown = ($course === NULL) ? 1 : $course->id;
-        $defaultcourses = array($courseshown => 1);
-    }
-
-    // I 'm not really sure if this belongs here...
-    calendar_set_referring_course($courseshown);
-
-    if($courseshown !== false && is_int($SESSION->cal_show_course) && $SESSION->cal_show_course != $courseshown) {
-        // There is a filter in action that shows events from a course other than the current
-        // Obviously we have to cut it out
-        $SESSION->cal_show_course = true;
-    }
-   else if($courseshown !== false && is_array($SESSION->cal_show_course) && !in_array($courseshown, $SESSION->cal_show_course)) {
-        // Same as above, only there are many courses being shown. Unfortunately, not this one.
-        $SESSION->cal_show_course = true;
-    }
-
-    // Be VERY careful with the format for default courses arguments!
-    // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
-
-    calendar_set_filters($courses, $group, $user, $defaultcourses, $defaultcourses);
-
-    if(get_user_preferences('calendar_showmonth', true)) {
-        if($courseshown == 1) {
-            // For the front page
-            echo calendar_overlib_html();
-            print_side_block_start(get_string('calendar', 'calendar'));
-            echo calendar_top_controls('frontpage', array('m' => $_GET['cal_m'], 'y' => $_GET['cal_y']));
-            echo calendar_get_mini($courses, $group, $user, $_GET['cal_m'], $_GET['cal_y']);
-            // No filters for now
-            print_side_block_end();
-        }
-        else {
-            // For any other course
-            echo calendar_overlib_html();
-            print_side_block_start(get_string('calendar', 'calendar'));
-            echo calendar_top_controls('course', array('id' => $courseshown, 'm' => $_GET['cal_m'], 'y' => $_GET['cal_y']));
-            echo calendar_get_mini($courses, $group, $user, $_GET['cal_m'], $_GET['cal_y']);
-            echo calendar_filter_controls('course');
-            print_side_block_end();
-        }
-    }
-    if(get_user_preferences('calendar_showupcoming', true)) {
-        $block = calendar_get_sideblock_upcoming($courses, $group, $user, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS));
-        if(!empty($block)) {
-            print_side_block_start(get_string('upcomingevents', 'calendar'));
-            echo $block;
-            print_side_block_end();
-        }
-    }
-}
-*/
-
 function calendar_set_referring_course($courseid) {
     global $SESSION;
     $SESSION->cal_course_referer = intval($courseid);
 }
 
-function calendar_set_filters(&$courses, &$group, &$user, $defaultcourses = NULL, $groupcourses = NULL) {
+function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NULL, $groupeventsfrom = NULL, $ignorefilters = false) {
     global $SESSION, $USER;
 
-    // WARNING: When calling this function, be VERY careful with the format for default courses arguments!
-    // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
-
-    // Insidious bug-wannabe: setting $SESSION->cal_show_course to $course->id would cause
+    // Insidious bug-wannabe: setting $SESSION->cal_courses_shown to $course->id would cause
     // the code to function incorrectly UNLESS we convert it to an integer. One case where
     // PHP's loose type system works against us.
-    if(is_string($SESSION->cal_show_course)) {
-        $SESSION->cal_show_course = intval($SESSION->cal_show_course);
+    if(is_string($SESSION->cal_courses_shown)) {
+        $SESSION->cal_courses_shown = intval($SESSION->cal_courses_shown);
     }
 
-    $showcourse = (
-        (is_int($SESSION->cal_show_course) && $SESSION->cal_show_course) ||
-        (is_array($SESSION->cal_show_course) && count($SESSION->cal_show_course)) ||
-        ($SESSION->cal_show_course === true)
-    );
-
-    if($defaultcourses === NULL) {
-        $defaultcourses = array();
-    }
-    if($groupcourses === NULL) {
-        $groupcourses = array();
+    if($courseeventsfrom === NULL) {
+        $courseeventsfrom = $SESSION->cal_courses_shown;
     }
-
-    if(is_array($defaultcourses) && array_key_exists(1, $defaultcourses)) {
-        // This should never happen, so let's be sure just in case
-        $defaultcourses = array_diff_assoc($defaultcourses, array(1 => 1));
+    if($groupeventsfrom === NULL) {
+        $groupeventsfrom = $SESSION->cal_courses_shown;
     }
 
-    if($showcourse && $SESSION->cal_show_global) {
-        if(is_int($SESSION->cal_show_course)) {
-            $courses = array(1, $SESSION->cal_show_course);
+    if(($SESSION->cal_show_course && $SESSION->cal_show_global) || $ignorefilters) {
+        if(is_int($courseeventsfrom)) {
+            $courses = array(1, $courseeventsfrom);
         }
-        else if(is_array($SESSION->cal_show_course)) {
-            $courses = array(1) + $SESSION->cal_show_course;
-
-        }
-        else {
-            $courses = array_keys($defaultcourses);
+        else if(is_array($courseeventsfrom)) {
+            $courses = array_keys($courseeventsfrom);
             $courses[] = 1;
         }
     }
-    else if($showcourse) {
-        if(is_int($SESSION->cal_show_course)) {
-            $courses = array($SESSION->cal_show_course);
+    else if($SESSION->cal_show_course) {
+        if(is_int($courseeventsfrom)) {
+            $courses = array($courseeventsfrom);
         }
-        else if(is_array($SESSION->cal_show_course)) {
-            $courses = $SESSION->cal_show_course;
-        }
-        else {
-            $courses = array_keys($defaultcourses);
-            if(empty($courses)) $courses = false;
+        else if(is_array($courseeventsfrom)) {
+            $courses = array_keys($courseeventsfrom);
         }
     }
     else if($SESSION->cal_show_global) {
@@ -1059,7 +951,7 @@ function calendar_set_filters(&$courses, &$group, &$user, $defaultcourses = NULL
         $courses = false;
     }
 
-    if($SESSION->cal_show_user) {
+    if($SESSION->cal_show_user || $ignorefilters) {
         // This ignores the "which user to see" setting
         // The functionality to do that does exist, but this was
         // the most painless way to solve bug 1323. And anyway,
@@ -1070,57 +962,35 @@ function calendar_set_filters(&$courses, &$group, &$user, $defaultcourses = NULL
     else {
         $user = false;
     }
-    if($SESSION->cal_show_groups) {
-        if(is_int($groupcourses)) {
-            // One course, whatever group the user is in that course
-            if(isteacher($groupcourses, $USER->id)) {
-                $grouprecords = get_groups($groupcourses);
-                if($grouprecords === false) {
-                    $group = false;
-                }
-                else {
-                    $group = array_keys($grouprecords);
-                }
-            }
-            else if(mygroupid($groupcourses)) {
-                $group = mygroupid($groupcourses);
-            }
-            else {
-                $group = false;
-            }
+    if($SESSION->cal_show_groups || $ignorefilters) {
+        if(is_int($groupeventsfrom)) {
+            $groupcourses = array($groupeventsfrom);
         }
-        else if(is_array($groupcourses)) {
-            // Many courses, we want all of them
-            $grouparray = array();
-
-            // For each course...
-            foreach($groupcourses as $courseid => $dummy) {
-                // If the user is an editing teacher in there,
-                if(isteacheredit($courseid, $USER->id)) {
-                    // Show events from all groups
-                    if(($grouprecords = get_groups($courseid)) !== false) {
-                        $grouparray = array_merge($grouparray, array_keys($grouprecords));
-                    }
-                }
-                // Otherwise show events from the group he is a member of
-                else if(isset($USER->groupmember[$courseid])) {
-                    $grouparray[] = $USER->groupmember[$courseid];
+        else if(is_array($groupeventsfrom)) {
+            $groupcourses = array_keys($groupeventsfrom);
+        }
+        $grouparray = array();
+
+        // We already have the courses to examine in $courses
+        // For each course...
+        foreach($groupcourses as $courseid) {
+            // If the user is an editing teacher in there,
+            if(isteacheredit($courseid, $USER->id)) {
+                // Show events from all groups
+                if(($grouprecords = get_groups($courseid)) !== false) {
+                    $grouparray = array_merge($grouparray, array_keys($grouprecords));
                 }
             }
-            if(empty($grouparray)) {
-                $group = false;
-            }
-            else {
-                $group = $grouparray;
+            // Otherwise show events from the group he is a member of
+            else if(isset($USER->groupmember[$courseid])) {
+                $grouparray[] = $USER->groupmember[$courseid];
             }
         }
-        else if(is_bool($groupcourses)) {
-            // Override
-            $group = $groupcourses;
+        if(empty($grouparray)) {
+            $group = false;
         }
         else {
-            // Sanity
-            $group = false;
+            $group = $grouparray;
         }
     }
     else {
index 5cf05ea80a244725e4eca0538724c4cf6b262d36..842ce7585217e867765acf752f274a5210c6ffed 100644 (file)
                case 'setcourse':
                        $id = intval($_GET['id']);
                        if($id == 0) {
-                               $SESSION->cal_show_course = false;
+                               $SESSION->cal_courses_shown = array();
                        }
                        else if($id == 1) {
-                               $SESSION->cal_show_course = true;
+                               $SESSION->cal_courses_shown = calendar_get_default_courses(true);
                        }
-                       else if(isstudent($id, $USER->id) || isteacher($id, $USER->id)) {
-                               $SESSION->cal_show_course = $id;
+                       else {
+                           // We don't check for membership anymore: if(isstudent($id, $USER->id) || isteacher($id, $USER->id)) {
+                               $SESSION->cal_courses_shown = $id;
                        }
                break;
                case 'showgroups':
                        $SESSION->cal_show_groups = !$SESSION->cal_show_groups;
                break;
                case 'showcourses':
-                       if(empty($SESSION->cal_show_course)) {
-                               $SESSION->cal_show_course = calendar_get_default_courses();
-                       }
-                       else {
-                               $SESSION->cal_show_course = false;
-                       }
+                   $SESSION->cal_show_course = !$SESSION->cal_show_course;
                break;
                case 'showglobal':
                        $SESSION->cal_show_global = !$SESSION->cal_show_global;
index 33704907e29b38a0adcd1b7c2279addf754e3150..16b07823e11dd219114f36e76a9203cd672acf38 100644 (file)
         break;
     }
 
+    if(isguest($USER->id)) {
+        $defaultcourses = calendar_get_default_courses();
+        calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
+    }
+    else {
+        if($_GET['view'] == 'upcoming') {
+            $defaultcourses = calendar_get_default_courses();
+            calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses, false);
+        }
+        else {
+            calendar_set_filters($courses, $groups, $users);
+        }
+    }
+
     // Let's see if we are supposed to provide a referring course link
     // but NOT for the "main page" course
     if($SESSION->cal_course_referer > 1 &&
     }
 
     $strcalendar = get_string('calendar', 'calendar');
-
     $prefsbutton = calendar_preferences_button();
 
     // Print title and header
 
     echo '<td style="vertical-align: top; width: 100%;">';
 
-    if($_GET['view'] == 'month') {
-        if(is_numeric($SESSION->cal_show_course)) {
-            $defaultcourses = array($SESSION->cal_show_course => 1);
-        }
-        else if($SESSION->cal_show_course === true) {
-            $defaultcourses = calendar_get_default_courses(true);
-        }
-        else if($SESSION->cal_show_course === false) {
-            $defaultcourses = array();
-        }
-    }
-    else {
-        $defaultcourses = calendar_get_default_courses();
-    }
-
-    $courses = array();
-
-    calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
-/*
-    // Are we left with a bad filter in effect?
-    if($_GET['view'] != 'month' && !empty($SESSION->cal_course_referer)) {
-        if(is_numeric($SESSION->cal_show_course)) {
-            if($SESSION->cal_course_referer != $SESSION->cal_show_course) {
-                $SESSION->cal_show_course = intval($SESSION->cal_course_referer);
-            }
-        }
-        if(is_array($SESSION->cal_show_course) && !in_array($SESSION->cal_course_referer, $SESSION->cal_show_course)) {
-            $SESSION->cal_show_course = intval($SESSION->cal_course_referer);
-        }
-    }
-*/
     switch($_GET['view']) {
         case 'event':
             optional_variable($_GET['id'], 0);
@@ -368,6 +350,34 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
     }
 
     print_side_block_start($text, '', 'mycalendar');
+
+    if(isadmin($USER->id)) {
+        $coursesdata = get_courses('all', 'c.shortname');
+    }
+    elseif(!isguest($USER->id)) {
+        $coursesdata = get_my_courses($USER->id, 'shortname');
+    }
+    else {
+        $coursesdata = get_record('course', 'id', $SESSION->cal_course_referer);
+    }
+    $coursesdata = array_diff_assoc($coursesdata, array(1 => 1));
+
+    if(!isguest($USER->id)) {
+        echo '<p style="text-align: center; margin: 1em;"><strong>'.get_string('eventsfromcourse', 'calendar').': ';
+        echo '<select name="course" onchange="document.location.href=\''.CALENDAR_URL.'set.php?var=setcourse&amp;'.$getvars.'&amp;id=\' + this.value;">';
+        echo '<option value="1">'.get_string('all')."</option>\n";
+        if($coursesdata !== false) {
+            foreach($coursesdata as $coursedata) {
+                echo "\n<option value='$coursedata->id'";
+                if(is_numeric($SESSION->cal_courses_shown) && $coursedata->id == $SESSION->cal_courses_shown) {
+                    echo ' selected';
+                }
+                echo '>'.$coursedata->shortname."</option>\n";
+            }
+        }
+        echo '</select></strong></p>';
+    }
+
     echo calendar_top_controls('month', array('m' => $m, 'y' => $y));
 
     // Start calendar display
@@ -502,58 +512,41 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
         echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
     }
 
-    // Course events (this is kinda... tricky... :)
-    echo '<td ';
-    if($SESSION->cal_show_course !== false) {
-        echo 'class="cal_event_course" ';
-    }
-    echo 'style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
-
-    if(isadmin($USER->id)) {
-        $coursesdata = get_courses('all', 'c.shortname');
+    // Course events
+    if(!empty($SESSION->cal_show_course)) {
+        echo '<td class="cal_event_course" style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
+        echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
     }
     else {
-        $coursesdata = get_my_courses($USER->id, 'shortname');
+        echo '<td style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
+        echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
     }
-    $coursesdata = array_diff_assoc($coursesdata, array(1 => 1));
 
-    echo '<select name="course" onchange="document.location.href=\''.CALENDAR_URL.'set.php?var=setcourse&amp;'.$getvars.'&amp;id=\' + this.value;">';
-    echo '<option value="0"'.($SESSION->cal_show_course === false?' selected':'').'>'.get_string('hidden', 'calendar')."</option>\n";
-    echo '<option value="1"'.($SESSION->cal_show_course === true?' selected':'').'>'.get_string('shown', 'calendar')."</option>\n";
-    if($coursesdata !== false) {
-        foreach($coursesdata as $coursedata) {
-            echo "\n<option value='$coursedata->id'";
-            if(is_int($SESSION->cal_show_course) && $coursedata->id == $SESSION->cal_show_course) {
-                echo ' selected';
-            }
-            echo '>'.$coursedata->shortname."</option>\n";
-        }
-    }
-    echo '</select>';
-    echo '</td>';
     echo "</tr>\n";
-    echo '<tr>';
 
-    // Group events
-    if($SESSION->cal_show_groups) {
-        echo '<td class="cal_event_group" style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
-        echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
-    }
-    else {
-        echo '<td style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
-        echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
-    }
-    // User events
-    if($SESSION->cal_show_user) {
-        echo '<td class="cal_event_user" style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
-        echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
-    }
-    else {
-        echo '<td style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
-        echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
+    if(!isguest($USER->id)) {
+        echo '<tr>';
+        // Group events
+        if($SESSION->cal_show_groups) {
+            echo '<td class="cal_event_group" style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
+            echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
+        }
+        else {
+            echo '<td style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
+            echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
+        }
+        // User events
+        if($SESSION->cal_show_user) {
+            echo '<td class="cal_event_user" style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
+            echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
+        }
+        else {
+            echo '<td style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
+            echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
+        }
+        echo "</tr>\n";
     }
 
-    echo "</tr>\n";
     echo '<tbody></table><br />';
     print_side_block_end();
 }