+++ patched/lib/grouplib.php	2009-05-01 23:03:32.000000000 +0300
--- original/lib/grouplib.php	2008-12-27 23:52:32.000000000 +0200
@@ -336,27 +336,17 @@
 function groups_print_course_menu($course, $urlroot, $return=false) {
     global $CFG, $USER, $SESSION;
 
+    $anygroups = groups_get_all_groups($course->id, 0);
+    if (!empty($anygroups)) {
+	$groupmode = VISIBLEGROUPS;
+    } else {
+	if (!$groupmode = $course->groupmode) {
+	    if ($return) {
+		return '';
+	    } else {
+		return;
+	    }
+	}
-    if (!$groupmode = $course->groupmode) {
-        if ($return) {
-            return '';
-        } else {
-            return;
-        }
     }
 
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
     if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $context)) {
+        if (!empty($anygroups)) {
+	    // we already read groups_get_all_groups($course->id, 0) into $anygroups !
+	    $allowedgroups = $anygroups;
+	  } else {
+	    $allowedgroups = groups_get_all_groups($course->id, 0);
+	}
-        $allowedgroups = groups_get_all_groups($course->id, 0);
         // detect changes related to groups and fix active group
         if (!empty($SESSION->activegroup[$course->id][VISIBLEGROUPS][0])) {
             if (!array_key_exists($SESSION->activegroup[$course->id][VISIBLEGROUPS][0], $allowedgroups)) {
