]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10048 General calendar view enhancements as per spec with regard to event highlig...
authordwoolhead <dwoolhead>
Tue, 12 Jun 2007 16:26:38 +0000 (16:26 +0000)
committerdwoolhead <dwoolhead>
Tue, 12 Jun 2007 16:26:38 +0000 (16:26 +0000)
calendar/lib.php
calendar/view.php
lang/en_utf8/calendar.php

index bd166dd3540fe2172f8fad1e345ed164a5e7950e..f94f3618a5535ae57803a8aa08e7fe5b68632fca 100644 (file)
@@ -148,6 +148,15 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y
         $events = get_records_select('event', $whereclause, 'timestart');
     }
 
+    // Set event course class for course events
+    if (!empty($events)) {
+        foreach ($events as $event) {
+            if($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) {
+                $event->class = 'event_course'.array_search($event->courseid, $courses) % 3;
+            }
+        }
+    }
+
     // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
     // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
     // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra
@@ -283,6 +292,21 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y
             $class .= ' duration_user';
         }
 
+        // If event has a class set then add it to the table day <td> tag
+        // Note: only one colour for minicalendar
+        if(isset($eventsbyday[$day])) {
+            foreach($eventsbyday[$day] as $eventid) {
+                if (!isset($events[$eventid])) {
+                    continue;
+                }
+                $event = $events[$eventid];
+                if (!empty($event->class)) {
+                    $class .= ' '.$event->class;
+                }
+                break;
+            }
+        }
+
         // Special visual fx for today
         //Accessibility: hidden text for today, and popup.
         if($display->thismonth && $day == $d) {
@@ -481,7 +505,14 @@ function calendar_print_event($event) {
 
     echo '</td></tr>';
     echo '<tr><td class="side">&nbsp;</td>';
-    echo '<td class="description '.$event->cssclass.'">';
+
+    // If event has a class set then add it to the event <td> tag
+    $eventclass='';
+    if (!empty($event->class)) {
+        $eventclass = ' '.$event->class;
+    }
+
+    echo '<td class="description '.$event->cssclass.$eventclass.'">';
     echo format_text($event->description, FORMAT_HTML);
     if (calendar_edit_event_allowed($event)) {
         echo '<div class="commands">';
@@ -580,7 +611,7 @@ function calendar_sql_where($tstart, $tend, $users, $groups, $courses, $withdura
     }
 
     if($withduration) {
-        $timeclause = 'timestart + timeduration >= '.$tstart.' AND timestart <= '.$tend;
+        $timeclause = '(timestart >= '.$tstart.' OR timestart + timeduration > '.$tstart.') AND timestart <= '.$tend;
     }
     else {
         $timeclause = 'timestart >= '.$tstart.' AND timestart <= '.$tend;
@@ -689,7 +720,7 @@ function calendar_top_controls($type, $data) {
     return $content;
 }
 
-function calendar_filter_controls($type, $vars = NULL, $course = NULL) {
+function calendar_filter_controls($type, $vars = NULL, $course = NULL, $courses = NULL) {
     global $CFG, $SESSION, $USER;
 
     $groupevents = true;
@@ -725,51 +756,113 @@ function calendar_filter_controls($type, $vars = NULL, $course = NULL) {
     $content .= '<tr>';
     if($SESSION->cal_show_global) {
         $content .= '<td class="event_global" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" /></td>';
-        $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showglobal'.$getvars.'" title="'.get_string('tt_hideglobal', 'calendar').'">'.get_string('globalevents', 'calendar').'</a></td>'."\n";
+        $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showglobal'.$getvars.'" title="'.get_string('tt_hideglobal', 'calendar').'">'.get_string('global', 'calendar').'</a></td>'."\n";
     }
     else {
         $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('show').'" /></td>';
-        $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showglobal'.$getvars.'" title="'.get_string('tt_showglobal', 'calendar').'">'.get_string('globalevents', 'calendar').'</a></td>'."\n";
-    }
-    if($SESSION->cal_show_course) {
-        $content .= '<td class="event_course" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" /></td>';
-        $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showcourses'.$getvars.'" title="'.get_string('tt_hidecourse', 'calendar').'">'.get_string('courseevents', 'calendar').'</a></td>'."\n";
-    }
-    else {
-        $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('hide').'" /></td>';
-        $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showcourses'.$getvars.'" title="'.get_string('tt_showcourse', 'calendar').'">'.get_string('courseevents', 'calendar').'</a></td>'."\n";
+        $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showglobal'.$getvars.'" title="'.get_string('tt_showglobal', 'calendar').'">'.get_string('global', 'calendar').'</a></td>'."\n";
     }
+    $tr = '';
 
     if(!empty($USER->id) && !isguest()) {
-        $content .= "</tr>\n<tr>";
-
         if($groupevents) {
+
+            $content .= $tr;
+            $tr = $tr ? '' : "</tr>\n<tr>";
+
             // This course MIGHT have group events defined, so show the filter
             if($SESSION->cal_show_groups) {
                 $content .= '<td class="event_group" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" /></td>';
-                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showgroups'.$getvars.'" title="'.get_string('tt_hidegroups', 'calendar').'">'.get_string('groupevents', 'calendar').'</a></td>'."\n";
+                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showgroups'.$getvars.'" title="'.get_string('tt_hidegroups', 'calendar').'">'.get_string('group', 'calendar').'</a></td>'."\n";
             } else {
                 $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('show').'" /></td>';
-                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showgroups'.$getvars.'" title="'.get_string('tt_showgroups', 'calendar').'">'.get_string('groupevents', 'calendar').'</a></td>'."\n";
+                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showgroups'.$getvars.'" title="'.get_string('tt_showgroups', 'calendar').'">'.get_string('group', 'calendar').'</a></td>'."\n";
             }
+
+            $content .= $tr;
+            $tr = $tr ? '' : "</tr>\n<tr>";
+
             if ($SESSION->cal_show_user) {
                 $content .= '<td class="event_user" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" /></td>';
-                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_hideuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
+                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_hideuser', 'calendar').'">'.get_string('user', 'calendar').'</a></td>'."\n";
             } else {
                 $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('show').'" /></td>';
-                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_showuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
+                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_showuser', 'calendar').'">'.get_string('user', 'calendar').'</a></td>'."\n";
             }
 
         } else {
+
+            $content .= $tr;
+            $tr = $tr ? '' : "</tr>\n<tr>";
+
             // This course CANNOT have group events, so lose the filter
             $content .= '<td style="width: 11px;"></td><td>&nbsp;</td>'."\n";
 
+            $content .= $tr;
+            $tr = $tr ? '' : "</tr>\n<tr>";
+
             if($SESSION->cal_show_user) {
                 $content .= '<td class="event_user" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" /></td>';
-                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_hideuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
+                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_hideuser', 'calendar').'">'.get_string('user', 'calendar').'</a></td>'."\n";
             } else {
                 $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('show').'" /></td>';
-                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_showuser', 'calendar').'">'.get_string('userevents', 'calendar').'</a></td>'."\n";
+                $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_showuser', 'calendar').'">'.get_string('user', 'calendar').'</a></td>'."\n";
+            }
+        }
+    }
+
+    // Remove global SITE ID from courses array as do not want to display this
+    if (!empty($courses)) {
+        $key = array_search(SITEID, $courses);
+        if ($key !== false) {
+            unset($courses[$key]);
+        }
+    }
+
+    if (empty($courses) || count($courses) == 1) {
+
+        // If not multiple courses then just display default single course colour highlighting
+        $content .= $tr;
+        $tr = $tr ? '' : "</tr>\n<tr>";
+
+        if($SESSION->cal_show_course) {
+            $content .= '<td class="event_course" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" /></td>';
+            $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showcourses'.$getvars.'" title="'.get_string('tt_hidecourse', 'calendar').'">'.get_string('course', 'calendar').'</a></td>'."\n";
+        }
+        else {
+            $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('hide').'" /></td>';
+            $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showcourses'.$getvars.'" title="'.get_string('tt_showcourse', 'calendar').'">'.get_string('course', 'calendar').'</a></td>'."\n";
+        }
+    } else {
+
+        // Otherwise display list of course shortnames and relevant colours
+        // Get list of course shortnames (Limit to 12 for now - who would have more than that?)
+        $select = 'id in ('.implode(',', $courses).')';
+        $sort = 'id';
+        $fields = 'id, shortname';
+        $courseshortnames = get_records_select('course', $select, $sort, $fields, 0, 12);
+
+        for ($i = 0; $i < 3; $i++) {
+
+            // Concatenate shortnames if there are more than 3 courses
+            $strshortnames = '';
+            for ($j = $i; $j < count($courses); $j += 3) {
+                $strshortnames .= ', '.(!empty($courseshortnames[$courses[$j]]->shortname) ? $courseshortnames[$courses[$j]]->shortname : $courses[$j]);
+            }
+
+            if (!empty($strshortnames)) {
+        
+                $content .= $tr;
+                $tr = $tr ? '' : "</tr>\n<tr>";
+        
+                if($SESSION->cal_show_course) {
+                    $content .= '<td class="event_course'.$i.'" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" /></td>';
+                    $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showcourses'.$getvars.'" title="'.get_string('tt_hidecourse', 'calendar').'">'.substr($strshortnames, 2).'</a></td>'."\n";
+                }
+                else {
+                    $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('hide').'" /></td>';
+                    $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showcourses'.$getvars.'" title="'.get_string('tt_showcourse', 'calendar').'">'.substr($strshortnames, 2).'</a></td>'."\n";
+                }
             }
         }
     }
@@ -948,10 +1041,18 @@ function calendar_events_by_day($events, $month, $year, &$eventsbyday, &$duratio
         return;
     }
 
+    // Define array of course id's
+    $courseids = array();
+
     foreach($events as $event) {
 
         $startdate = usergetdate($event->timestart);
-        $enddate   = usergetdate($event->timestart + $event->timeduration);
+        // Set end date = start date if no duration
+        if ($event->timeduration) {
+            $enddate   = usergetdate($event->timestart + $event->timeduration - 1);
+        } else {
+            $enddate = $startdate;
+        }
 
         // Simple arithmetic: $year * 13 + $month is a distinct integer for each distinct ($year, $month) pair
         if(!($startdate['year'] * 13 + $startdate['mon'] <= $year * 13 + $month) && ($enddate['year'] * 13 + $enddate['mon'] >= $year * 13 + $month)) {
@@ -968,15 +1069,26 @@ function calendar_events_by_day($events, $month, $year, &$eventsbyday, &$duratio
             // Mark the day as having such an event
             if($event->courseid == SITEID && $event->groupid == 0) {
                 $typesbyday[$eventdaystart]['startglobal'] = true;
+                // Set event class for global event
+                $events[$event->id]->class = 'event_global';
             }
             else if($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) {
                 $typesbyday[$eventdaystart]['startcourse'] = true;
+                // Set event class for course event
+                if (!in_array($event->courseid, $courseids)) {
+                    $courseids[] = $event->courseid;
+                }
+                $events[$event->id]->class = 'event_course'.array_search($event->courseid, $courseids) % 3;
             }
             else if($event->groupid) {
                 $typesbyday[$eventdaystart]['startgroup'] = true;
+                // Set event class for group event
+                $events[$event->id]->class = 'event_group';
             }
             else if($event->userid) {
                 $typesbyday[$eventdaystart]['startuser'] = true;
+                // Set event class for user event
+                $events[$event->id]->class = 'event_user';
             }
         }
 
@@ -1066,9 +1178,11 @@ function calendar_session_vars() {
     if(!isset($SESSION->cal_show_user)) {
         $SESSION->cal_show_user = true;
     }
-   // if(empty($SESSION->cal_courses_shown)) {
+    // 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)) {
         $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
@@ -1294,7 +1408,7 @@ function calendar_preferences_button() {
            "<div><input type=\"submit\" value=\"".get_string("preferences", "calendar")." ...\" /></div></form>";
 }
 
-function calendar_format_event_time($event, $now, $morehref, $usecommonwords = true) {
+function calendar_format_event_time($event, $now, $morehref, $usecommonwords = true, $showtime=0) {
     $startdate = usergetdate($event->timestart);
     $enddate = usergetdate($event->timestart + $event->timeduration);
     $usermidnightstart = usergetmidnight($event->timestart);
@@ -1310,47 +1424,70 @@ function calendar_format_event_time($event, $now, $morehref, $usecommonwords = t
     // OK, now to get a meaningful display...
     // First of all we have to construct a human-readable date/time representation
 
-    if($event->timestart + $event->timeduration < $now) {
-        // It has expired, so we don't care about duration
-        $day = calendar_day_representation($event->timestart + $event->timeduration, $now, $usecommonwords);
-        $time = calendar_time_representation($event->timestart + $event->timeduration);
-
-        // This var always has the printable time representation
-        $eventtime = '<span class="dimmed_text"><a class="dimmed" href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).'">'.$day.'</a> ('.$time.')</span>';
-
-    }
-    else if($event->timeduration) {
+    if($event->timeduration) {
         // It has a duration
-        if($usermidnightstart == $usermidnightend) {
+        if($usermidnightstart == $usermidnightend ||
+           ($event->timestart == $usermidnightstart) && ($event->timeduration == 86400 || $event->timeduration == 86399) ||
+           ($event->timestart + $event->timeduration <= $usermidnightstart + 86400)) {
             // But it's all on the same day
-            $day = calendar_day_representation($event->timestart, $now, $usecommonwords);
             $timestart = calendar_time_representation($event->timestart);
             $timeend = calendar_time_representation($event->timestart + $event->timeduration);
+            $time = $timestart.' <strong>&raquo;</strong> '.$timeend;
+
+            if ($event->timestart == $usermidnightstart && ($event->timeduration == 86400 || $event->timeduration == 86399)) {
+                $time = get_string('allday', 'calendar');
+            }
 
             // Set printable representation
-            $eventtime = calendar_get_link_tag($day, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).
-                ' ('.$timestart.' <strong>&raquo;</strong> '.$timeend.')';
-        }
-        else {
+            if (!$showtime) {
+                $day = calendar_day_representation($event->timestart, $now, $usecommonwords);
+                $eventtime = calendar_get_link_tag($day, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).', '.$time;
+            } else {
+                $eventtime = $time;
+            }
+        } else {
             // It spans two or more days
-            $daystart = calendar_day_representation($event->timestart, $now, $usecommonwords);
-            $dayend = calendar_day_representation($event->timestart + $event->timeduration, $now, $usecommonwords);
+            $daystart = calendar_day_representation($event->timestart, $now, $usecommonwords).', ';
+            if ($showtime == $usermidnightstart) {
+                $daystart = '';
+            }
             $timestart = calendar_time_representation($event->timestart);
+            $dayend = calendar_day_representation($event->timestart + $event->timeduration, $now, $usecommonwords).', ';
+            if ($showtime == $usermidnightend) {
+                $dayend = '';
+            }
             $timeend = calendar_time_representation($event->timestart + $event->timeduration);
 
             // Set printable representation
-            $eventtime = calendar_get_link_tag($daystart, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $startdate['mday'], $startdate['mon'], $startdate['year']).
-                ' ('.$timestart.') <strong>&raquo;</strong> '.calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).
-                ' ('.$timeend.')';
+            if ($now >= $usermidnightstart && $now < ($usermidnightstart + 86400)) {
+                $eventtime = $timestart.' <strong>&raquo;</strong> '.calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).
+                $timeend;
+            } else {
+                $eventtime = calendar_get_link_tag($daystart, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $startdate['mday'], $startdate['mon'], $startdate['year']).
+                $timestart.' <strong>&raquo;</strong> '.calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).
+                $timeend;
+            }
         }
-    }
-    else {
+    } else {
         // It's an "instantaneous" event
-        $day = calendar_day_representation($event->timestart, $now, $usecommonwords);
-        $time = calendar_time_representation($event->timestart);
+        if ($event->timestart != usergetmidnight($event->timestart)) {
+            $time = ', '.calendar_time_representation($event->timestart);
+        } else {
+            $time = ' ';
+        }
 
         // Set printable representation
-        $eventtime = calendar_get_link_tag($day, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $startdate['mday'], $startdate['mon'], $startdate['year']).' ('.$time.')';
+        if (!$showtime) {
+            $day = calendar_day_representation($event->timestart, $now, $usecommonwords);
+            $eventtime = calendar_get_link_tag($day, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $startdate['mday'], $startdate['mon'], $startdate['year']).trim($time);
+        } else {
+            $eventtime = $time;
+        }
+    }
+
+    if($event->timestart + $event->timeduration < $now) {
+        // It has expired
+        $eventtime = '<span class="dimmed_text">'.str_replace(' href=', ' class="dimmed" href=', $eventtime).'</span>';
     }
 
     return $eventtime;
index 6b6cc440abb093aa558689781cd42f1569e3af7d..01e465a53f0b01f1fa516ab2e459e9a0b3b3a134 100644 (file)
         calendar_set_filters($courses, $groups, $users);
     }
 
+    // Sort courses for consistent colour highlighting
+    // Effectively ignoring SITEID as setting as last course id
+    // Consider inside calendar_set_filters() and SITEID always last
+    $key = array_search(SITEID, $courses);
+    if ($key !== false) {
+        unset($courses[$key]);
+        sort($courses);
+        $courses[] = SITEID;
+    } else {
+        sort($courses);
+    }
+
     // 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 != SITEID &&
@@ -273,7 +285,13 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users) {
                 echo calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).' ('.$timeend.')';
 */
                 //unset($event->time);
-                $event->time = calendar_format_event_time($event, time(), '', false);
+
+                // Set event course class if a course event
+                if($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) {
+                    $event->class = 'event_course'.array_search($event->courseid, $courses) % 3;
+                }
+
+                $event->time = calendar_format_event_time($event, time(), '', false, $starttime);
                 calendar_print_event($event);
 
             } else {                                                                 // Save this for later
@@ -285,7 +303,7 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users) {
         if (!empty($underway)) {
             echo '<h3>'.get_string('spanningevents', 'calendar').':</h3>';
             foreach ($underway as $event) {
-                $event->time = calendar_format_event_time($event, time(), '', false);
+                $event->time = calendar_format_event_time($event, time(), '', false, $starttime);
                 calendar_print_event($event);
             }
         }
@@ -400,7 +418,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
 
     // Paddding (the first week may have blank days in the beginning)
     for($i = $display->minwday; $i < $startwday; ++$i) {
-        echo '<td>&nbsp;</td>'."\n";
+        echo '<td class="nottoday">&nbsp;</td>'."\n";
     }
 
     // Now display all the calendar
@@ -427,18 +445,6 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
 
         // Special visual fx if an event is defined
         if(isset($eventsbyday[$day])) {
-            if(isset($typesbyday[$day]['startglobal'])) {
-                $class .= ' event_global';
-            }
-            else if(isset($typesbyday[$day]['startcourse'])) {
-                $class .= ' event_course';
-            }
-            else if(isset($typesbyday[$day]['startgroup'])) {
-                $class .= ' event_group';
-            }
-            else if(isset($typesbyday[$day]['startuser'])) {
-                $class .= ' event_user';
-            }
             if(count($eventsbyday[$day]) == 1) {
                 $title = get_string('oneevent', 'calendar');
             }
@@ -468,6 +474,8 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
         // Special visual fx for today
         if($display->thismonth && $day == $d) {
             $class .= ' today';
+        } else {
+            $class .= ' nottoday';
         }
 
         // Just display it
@@ -479,7 +487,14 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
         if(isset($eventsbyday[$day])) {
             echo '<ul class="events-new">';
             foreach($eventsbyday[$day] as $eventindex) {
-                echo '<li><a href="'.$dayhref.'#event_'.$events[$eventindex]->id.'">'.format_string($events[$eventindex]->name, true).'</a></li>';
+
+                // If event has a class set then add it to the event <li> tag
+                $eventclass = '';
+                if (!empty($events[$eventindex]->class)) {
+                    $eventclass = ' class="'.$events[$eventindex]->class.'"';
+                }
+
+                echo '<li'.$eventclass.'><a href="'.$dayhref.'#event_'.$events[$eventindex]->id.'">'.format_string($events[$eventindex]->name, true).'</a></li>';
             }
             echo '</ul>';
         }
@@ -495,61 +510,12 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
 
     // Paddding (the last week may have blank days at the end)
     for($i = $dayweek; $i <= $display->maxwday; ++$i) {
-        echo '<td>&nbsp;</td>';
+        echo '<td class="nottoday">&nbsp;</td>';
     }
     echo "</tr>\n"; // Last row ends
 
     echo "</table>\n"; // Tabular display of days ends
 
-    // OK, now for the filtering display
-    echo '<div class="filters"><table><tr>';
-
-    // Global events
-    if($SESSION->cal_show_global) {
-        echo '<td class="event_global" style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
-        echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
-    }
-    else {
-        echo '<td style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
-        echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
-    }
-
-    // Course events
-    if(!empty($SESSION->cal_show_course)) {
-        echo '<td class="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 {
-        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";
-    }
-
-    echo "</tr>\n";
-
-    if(!empty($USER->id) && !isguest()) {
-        echo '<tr>';
-        // Group events
-        if($SESSION->cal_show_groups) {
-            echo '<td class="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="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 '</table></div>';
 }
 
 function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $maxevents) {
@@ -577,8 +543,23 @@ function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $
     echo '<div class="header">'.$text.'</div>';
 
     if ($events) {
+
+        // Sort courses for consistent colour highlighting (ignoring SITEID)
+        $courseids = $courses;
+        $key = array_search(SITEID, $courseids);
+        if ($key !== false) {
+            unset($courseids[$key]);
+        }
+        sort($courseids);
+
         echo '<div class="eventlist">';
         foreach ($events as $event) {
+
+            // Set event course class if a course event
+            if($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) {
+                $event->class = 'event_course'.array_search($event->courseid, $courseids) % 3;
+            }
+
             calendar_print_event($event);
         }
         echo '</div>';
index eb9679c399d1a3f8afaddb46e9f2f9a970681a4f..2518b0f58ba888cd04c7898813d49369185e6dcd 100644 (file)
@@ -1,6 +1,7 @@
 <?PHP // $Id$ 
       // calendar.php - created with Moodle 1.7 beta + (2006101003)
 
+$string['allday'] = 'All day';
 $string['advancedoptions'] = 'Advanced options';
 $string['calendar'] = 'Calendar';
 $string['calendarheading'] = '$a Calendar';