### Eclipse Workspace Patch 1.0
#P 19stable
Index: calendar/view.php
===================================================================
RCS file: /cvsroot/moodle/moodle/calendar/view.php,v
retrieving revision 1.95.2.9
diff -u -r1.95.2.9 view.php
--- calendar/view.php	31 Dec 2008 15:51:28 -0000	1.95.2.9
+++ calendar/view.php	9 Mar 2009 03:56:42 -0000
@@ -116,10 +116,10 @@
 
     if (empty($USER->id) or isguest()) {
         $defaultcourses = calendar_get_default_courses();
-        calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
+        calendar_set_filters($courses, $groups, $users, $category, $defaultcourses, $defaultcourses);
 
     } else {
-        calendar_set_filters($courses, $groups, $users);
+        calendar_set_filters($courses, $groups, $users, $category);
     }
 
     // Let's see if we are supposed to provide a referring course link
@@ -153,13 +153,13 @@
 
     switch($view) {
         case 'day':
-            calendar_show_day($day, $mon, $yr, $courses, $groups, $users, $courseid);
+            calendar_show_day($day, $mon, $yr, $courses, $groups, $users, $category, $courseid);
         break;
         case 'month':
-            calendar_show_month_detailed($mon, $yr, $courses, $groups, $users, $courseid);
+            calendar_show_month_detailed($mon, $yr, $courses, $groups, $users, $category, $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), $courseid);
+            calendar_show_upcoming_events($courses, $groups, $users, $category, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS), $courseid);
         break;
     }
 
@@ -204,13 +204,13 @@
 
     echo '<div class="minicalendarblock minicalendartop">';
     echo calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
-    echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
+    echo calendar_get_mini($courses, $groups, $users, $category, $prevmon, $prevyr);
     echo '</div><div class="minicalendarblock">';
     echo calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr));
-    echo calendar_get_mini($courses, $groups, $users, $mon, $yr);
+    echo calendar_get_mini($courses, $groups, $users, $category, $mon, $yr);
     echo '</div><div class="minicalendarblock">';
     echo calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
-    echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
+    echo calendar_get_mini($courses, $groups, $users, $category, $nextmon, $nextyr);
     echo '</div>';
     echo '</div>';
 
@@ -222,7 +222,7 @@
 
 
 
-function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) {
+function calendar_show_day($d, $m, $y, $courses, $groups, $users, $category, $courseid) {
     global $CFG, $USER;
 
     if (!checkdate($m, $d, $y)) {
@@ -306,7 +306,7 @@
     }
 }
 
-function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) {
+function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $category, $courseid) {
     global $CFG, $SESSION, $USER, $CALENDARDAYS;
     global $day, $mon, $yr;
 
@@ -560,12 +560,22 @@
 	             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"; 	 
-	     } 	 
-	  	 
+	     }
+         
+             // Category events      
+             if($SESSION->cal_show_category) {   
+                 echo '<td class="event_category" style="width: 8px;"></td><td><strong>'.get_string('categoryevents', 'calendar').':</strong> ';     
+                 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcategory&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";    
+             }   
+             else {      
+                 echo '<td style="width: 8px;"></td><td><strong>'.get_string('categoryevents', 'calendar').':</strong> ';    
+                 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcategory&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, $courseid) {
+function calendar_show_upcoming_events($courses, $groups, $users, $category, $futuredays, $maxevents, $courseid) {
     global $USER;
 
     $events = calendar_get_upcoming($courses, $groups, $users, $futuredays, $maxevents);
Index: calendar/set.php
===================================================================
RCS file: /cvsroot/moodle/moodle/calendar/set.php,v
retrieving revision 1.21
diff -u -r1.21 set.php
--- calendar/set.php	22 Jun 2007 13:23:21 -0000	1.21
+++ calendar/set.php	9 Mar 2009 03:56:42 -0000
@@ -103,6 +103,10 @@
             $SESSION->cal_show_user = !$SESSION->cal_show_user;
             set_user_preference('calendar_savedflt', calendar_get_filters_status());
         break;
+        case 'showcategory':
+            $SESSION->cal_show_category = !$SESSION->cal_show_category;
+            set_user_preference('calendar_savedflt', calendar_get_filters_status());
+        break;
     }
 
     switch($from) {
Index: calendar/export.php
===================================================================
RCS file: /cvsroot/moodle/moodle/calendar/export.php,v
retrieving revision 1.7.2.6
diff -u -r1.7.2.6 export.php
--- calendar/export.php	20 Jan 2009 06:21:03 -0000	1.7.2.6
+++ calendar/export.php	9 Mar 2009 03:56:42 -0000
@@ -54,17 +54,17 @@
 
 if (empty($USER->id) or isguest()) {
     $defaultcourses = calendar_get_default_courses();
-    calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
+    calendar_set_filters($courses, $groups, $users, $category, $defaultcourses, $defaultcourses);
 } else {
-    calendar_set_filters($courses, $groups, $users);
+    calendar_set_filters($courses, $groups, $users, $category);
 }
 
 if (empty($USER->id) or isguest()) {
     $defaultcourses = calendar_get_default_courses();
-    calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
+    calendar_set_filters($courses, $groups, $users, $category, $defaultcourses, $defaultcourses);
 
 } else {
-    calendar_set_filters($courses, $groups, $users);
+    calendar_set_filters($courses, $groups, $users, $category);
 }
 
 $strcalendar = get_string('calendar', 'calendar');
Index: calendar/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/calendar/lib.php,v
retrieving revision 1.206.2.13
diff -u -r1.206.2.13 lib.php
--- calendar/lib.php	30 Apr 2008 04:45:23 -0000	1.206.2.13
+++ calendar/lib.php	9 Mar 2009 03:56:42 -0000
@@ -269,6 +269,9 @@
             else if(isset($typesbyday[$day]['startuser'])) {
                 $class .= ' event_user';
             }
+            else if(isset($typesbyday[$day]['startcategory'])) {
+                $class .= ' event_category';
+            }
             $cell = '<a href="'.$dayhref.'" '.$popup.'>'.$day.'</a>';
         }
         else {
@@ -504,6 +507,9 @@
     } else if($event->userid) {                                      // User event
         $event->icon = '<img height="16" width="16" src="'.$CFG->pixpath.'/c/user.gif" alt="'.get_string('userevent', 'calendar').'" style="vertical-align: middle;" />';
         $event->cssclass = 'event_user';
+    } else if($event->categoryid) {                                      // Category event
+        $event->icon = '<img height="16" width="16" src="'.$CFG->pixpath.'/c/category.gif" alt="'.get_string('categoryevent', 'calendar').'" style="vertical-align: middle;" />';
+        $event->cssclass = 'event_category';
     }
     return $event;
 }
@@ -855,6 +861,13 @@
             $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('show').'" title="'.get_string('tt_showuser', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showuser'.$getvars."'".'" /></td>';
             $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_showuser', 'calendar').'">'.get_string('user', 'calendar').'</a></td>'."\n";
         }
+        if($SESSION->cal_show_category) {
+            $content .= '<td class="eventskey event_category" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" title="'.get_string('tt_hidecategory', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showcategory'.$getvars."'".'" /></td>';
+            $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showcategory'.$getvars.'" title="'.get_string('tt_hidecategory', 'calendar').'">'.get_string('category', 'calendar').'</a></td>'."\n";
+        } else {
+            $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('show').'" title="'.get_string('tt_showcategory', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showcategory'.$getvars."'".'" /></td>';
+            $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showcategory'.$getvars.'" title="'.get_string('tt_showcategory', 'calendar').'">'.get_string('category', 'calendar').'</a></td>'."\n";
+        }
     }
     $content .= "</tr>\n</table>\n";
 
@@ -1080,6 +1093,11 @@
                 // Set event class for user event
                 $events[$event->id]->class = 'event_user';
             }
+            else if($event->categoryid) {
+                $typesbyday[$eventdaystart]['startcategory'] = true;
+                // Set event class for user event
+                $events[$event->id]->class = 'event_category';
+            }
         }
 
         if($event->timeduration == 0) {
@@ -1143,6 +1161,7 @@
         // We just logged in as someone else, update the filtering
         unset($SESSION->cal_users_shown);
         unset($SESSION->cal_courses_shown);
+        unset($SESSION->cal_categories_shown);
         $SESSION->cal_loggedinas = true;
         if(intval(get_user_preferences('calendar_persistflt', 0))) {
             calendar_set_filters_status(get_user_preferences('calendar_savedflt', 0xff));
@@ -1151,6 +1170,7 @@
     else if(!empty($USER->id) && !isset($USER->realuser) && isset($SESSION->cal_loggedinas)) {
         // We just logged back to our real self, update again
         unset($SESSION->cal_users_shown);
+        unset($SESSION->cal_categories_shown);
         unset($SESSION->cal_courses_shown);
         unset($SESSION->cal_loggedinas);
         if(intval(get_user_preferences('calendar_persistflt', 0))) {
@@ -1173,6 +1193,9 @@
     if(!isset($SESSION->cal_show_user)) {
         $SESSION->cal_show_user = true;
     }
+    if(!isset($SESSION->cal_show_category)) {
+        $SESSION->cal_show_category = true;
+    }
     if (isset($course)) {
         // speedup hack for calendar related blocks
         $SESSION->cal_courses_shown = array($course->id => $course);
@@ -1189,6 +1212,12 @@
         // Follow the white rabbit, for example if a teacher logs in as a student
         $SESSION->cal_users_shown = $USER->id;
     }
+    if(empty($SESSION->cal_categories_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
+        // in. With !isset(), it would never do that.
+        $SESSION->cal_categories_shown = !empty($COURSE->category) ? $COURSE->category : false;
+    }
 }
 
 function calendar_overlib_html() {
@@ -1201,7 +1230,7 @@
     $SESSION->cal_course_referer = intval($courseid);
 }
 
-function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NULL, $groupeventsfrom = NULL, $ignorefilters = false) {
+function calendar_set_filters(&$courses, &$group, &$user, &$category, $courseeventsfrom = NULL, $groupeventsfrom = NULL, $categoryeventsfrom = NULL, $ignorefilters = false) {
     global $SESSION, $USER, $CFG;
 
     // Insidious bug-wannabe: setting $SESSION->cal_courses_shown to $course->id would cause
@@ -1283,6 +1312,15 @@
     else {
         $user = false;
     }
+    
+    if($SESSION->cal_show_category || $ignorefilters) {
+        // This doesn't work for arrays yet (maybe someday it will)
+        $category = $SESSION->cal_categories_shown;
+    }
+    else {
+        $category = false;
+    }
+    
     if($SESSION->cal_show_groups || $ignorefilters) {
         if(is_int($groupeventsfrom)) {
             $groupcourses = array($groupeventsfrom);
@@ -1290,7 +1328,7 @@
         else if(is_array($groupeventsfrom)) {
             $groupcourses = array_keys($groupeventsfrom);
         }
-
+    
         // XXX TODO: not sure how to replace $CFG->calendar_adminseesall
         if(has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
             $group = true;
@@ -1553,6 +1591,9 @@
     if($SESSION->cal_show_user) {
         $status += 8;
     }
+    if($SESSION->cal_show_category) {
+        $status += 16;
+    }
     return $status;
 }
 
@@ -1567,6 +1608,7 @@
     $SESSION->cal_show_course = ($packed_bitfield & 2);
     $SESSION->cal_show_groups = ($packed_bitfield & 4);
     $SESSION->cal_show_user   = ($packed_bitfield & 8);
+    $SESSION->cal_show_category   = ($packed_bitfield & 16);
 
     return true;
 }
Index: calendar/event.php
===================================================================
RCS file: /cvsroot/moodle/moodle/calendar/event.php,v
retrieving revision 1.74.2.5
diff -u -r1.74.2.5 event.php
--- calendar/event.php	2 Jul 2008 07:08:22 -0000	1.74.2.5
+++ calendar/event.php	9 Mar 2009 03:56:42 -0000
@@ -530,11 +530,11 @@
     // START: Last column (3-month display)
 
     $defaultcourses = calendar_get_default_courses();
-    //calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
+    //calendar_set_filters($courses, $groups, $users, $category, $defaultcourses, $defaultcourses);
     
     // when adding an event you can not be a guest, so I think it's reasonalbe to ignore defaultcourses
     // MDL-10353
-    calendar_set_filters($courses, $groups, $users);
+    calendar_set_filters($courses, $groups, $users, $category);
     list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
     list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
 
Index: theme/standard/styles_color.css
===================================================================
RCS file: /cvsroot/moodle/moodle/theme/standard/styles_color.css,v
retrieving revision 1.149.2.19
diff -u -r1.149.2.19 styles_color.css
--- theme/standard/styles_color.css	15 Jan 2009 20:16:12 -0000	1.149.2.19
+++ theme/standard/styles_color.css	9 Mar 2009 03:56:42 -0000
@@ -552,6 +552,13 @@
   background-color:#FEE7AE;
 }
 
+#calendar .event_category,
+.minicalendar .event_category,
+.block_calendar_month .event_category {
+  border-color:#B88DBD !important; /* #A881AC */
+  background-color:#B88DBD;
+}
+
 #calendar .event_user,
 .minicalendar .event_user,
 .block_calendar_month .event_user {
Index: theme/standard/styles_moz.css
===================================================================
RCS file: /cvsroot/moodle/moodle/theme/standard/styles_moz.css,v
retrieving revision 1.35.2.1
diff -u -r1.35.2.1 styles_moz.css
--- theme/standard/styles_moz.css	19 Nov 2007 10:50:54 -0000	1.35.2.1
+++ theme/standard/styles_moz.css	9 Mar 2009 03:56:43 -0000
@@ -184,10 +184,12 @@
 #calendar .maincalendar li.event_global,
 #calendar .maincalendar li.event_user,
 #calendar .maincalendar li.event_group,
+#calendar .maincalendar li.event_category,
 #calendar .filters td.event_course,
 #calendar .filters td.event_global,
 #calendar .filters td.event_user,
-#calendar .filters td.event_group {
+#calendar .filters td.event_group,
+#calendar .filters td.event_category {
   -moz-border-radius:4px;
 }
 
Index: theme/standard/styles_layout.css
===================================================================
RCS file: /cvsroot/moodle/moodle/theme/standard/styles_layout.css,v
retrieving revision 1.516.2.75
diff -u -r1.516.2.75 styles_layout.css
--- theme/standard/styles_layout.css	16 Feb 2009 03:08:47 -0000	1.516.2.75
+++ theme/standard/styles_layout.css	9 Mar 2009 03:56:43 -0000
@@ -1665,10 +1665,12 @@
 #calendar .event_course,
 #calendar .event_group,
 #calendar .event_user,
+#calendar.event_category,
 .minicalendar .event_global,
 .minicalendar .event_course,
 .minicalendar .event_group,
-.minicalendar .event_user {
+.minicalendar .event_user,
+.minicalendar .event_category {
   border:2px solid !important;
 }
 
Index: lang/en_utf8/calendar.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/calendar.php,v
retrieving revision 1.10.4.1
diff -u -r1.10.4.1 calendar.php
--- lang/en_utf8/calendar.php	29 Nov 2007 14:40:46 -0000	1.10.4.1
+++ lang/en_utf8/calendar.php	9 Mar 2009 03:56:42 -0000
@@ -5,6 +5,9 @@
 $string['advancedoptions'] = 'Advanced options';
 $string['calendar'] = 'Calendar';
 $string['calendarheading'] = '$a Calendar';
+$string['category'] = 'Category';
+$string['categoryevent'] = 'Category event';
+$string['categoryevents'] = 'Category events';
 $string['clickhide'] = 'click to hide';
 $string['clickshow'] = 'click to show';
 $string['commontasks'] = 'Options';
@@ -106,10 +109,12 @@
 $string['tomorrow'] = 'Tomorrow';
 $string['tt_deleteevent'] = 'Delete event';
 $string['tt_editevent'] = 'Edit event';
+$string['tt_hidecategory'] = 'Category events are shown (click to hide)';
 $string['tt_hidecourse'] = 'Course events are shown (click to hide)';
 $string['tt_hideglobal'] = 'Global events are shown (click to hide)';
 $string['tt_hidegroups'] = 'Group events are shown (click to hide)';
 $string['tt_hideuser'] = 'User events are shown (click to hide)';
+$string['tt_showcategory'] = 'Category events are hidden (click to show)';
 $string['tt_showcourse'] = 'Course events are hidden (click to show)';
 $string['tt_showglobal'] = 'Global events are hidden (click to show)';
 $string['tt_showgroups'] = 'Group events are hidden (click to show)';
Index: blocks/calendar_month/block_calendar_month.php
===================================================================
RCS file: /cvsroot/moodle/moodle/blocks/calendar_month/block_calendar_month.php,v
retrieving revision 1.30.2.6
diff -u -r1.30.2.6 block_calendar_month.php
--- blocks/calendar_month/block_calendar_month.php	30 Jan 2009 06:22:16 -0000	1.30.2.6
+++ blocks/calendar_month/block_calendar_month.php	9 Mar 2009 03:56:42 -0000
@@ -59,19 +59,19 @@
     
         // 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, $filtercourse, $groupeventsfrom, false);
+        calendar_set_filters($courses, $group, $user, $category, $filtercourse, $groupeventsfrom, false);
         if ($courseshown == SITEID) {
             // For the front page
             $this->content->text .= calendar_overlib_html();
             $this->content->text .= calendar_top_controls('frontpage', array('id' => $courseshown, 'm' => $cal_m, 'y' => $cal_y));
-            $this->content->text .= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y);
+            $this->content->text .= calendar_get_mini($courses, $group, $user, $category, $cal_m, $cal_y);
             // No filters for now
 
         } else {
             // For any other course
             $this->content->text .= calendar_overlib_html();
             $this->content->text .= calendar_top_controls('course', array('id' => $courseshown, 'm' => $cal_m, 'y' => $cal_y));
-            $this->content->text .= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y);
+            $this->content->text .= calendar_get_mini($courses, $group, $user, $category, $cal_m, $cal_y);
             $this->content->text .= '<h3 class="eventskey">'.get_string('eventskey', 'calendar').'</h3>';
             $this->content->text .= '<div class="filters">'.calendar_filter_controls('course', '', $COURSE).'</div>';
             

