diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index bb122e90cd4..1b04f1afb2d 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -1165,6 +1165,38 @@ function get_and_set_current_group($course, $groupmode, $groupid=0) {
}
+/**
+* A big combination function to make it easier for modules
+* to set up groups.
+*
+* Terminates if the current user shouldn't be looking at this group
+* Otherwise returns the current group if there is one
+* Otherwise returns false if groups aren't relevant
+*
+* @param type description
+*/
+function setup_and_print_groups($course, $groupmode, $urlroot) {
+
+ $currentgroup = get_and_set_current_group($course, $groupmode, $_GET['group']);
+
+ if ($currentgroup == false) {
+ return false;
+ }
+
+ if (!isteacheredit($course->id) and $groupmode and !$currentgroup) {
+ print_heading();
+ print_footer($course);
+ exit;
+ }
+
+ if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
+ if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
+ print_group_menu($groups, $groupmode, $currentgroup, $urlroot);
+ }
+ }
+
+ return $currentgroup;
+}
diff --git a/lib/weblib.php b/lib/weblib.php
index 0447de49d64..0666ce84274 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -1222,29 +1222,31 @@ function print_user($user, $course) {
function print_group_picture($group, $courseid, $large=false, $returnstring=false, $link=true) {
global $CFG;
- if ($link) {
- $output = "wwwroot/course/groupphp?id=$courseid&group=$group->id\">";
- } else {
- $output = "";
- }
- if ($large) {
- $file = "f1";
- $size = 100;
- } else {
- $file = "f2";
- $size = 35;
- }
- if ($group->picture) { // Print custom group picture
- if ($CFG->slasharguments) { // Use this method if possible for better caching
- $output .= "wwwroot/user/pixgroup.php/$group->id/$file.jpg\"".
- " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
+ $output = '';
+
+ if ($group->showpicture) {
+ if ($link) {
+ $output = "wwwroot/course/groupphp?id=$courseid&group=$group->id\">";
+ }
+ if ($large) {
+ $file = "f1";
+ $size = 100;
} else {
- $output .= "
wwwroot/user/pixgroup.php?file=/$group->id/$file.jpg\"".
- " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
+ $file = "f2";
+ $size = 35;
+ }
+ if ($group->picture) { // Print custom group picture
+ if ($CFG->slasharguments) { // Use this method if possible for better caching
+ $output .= "
wwwroot/user/pixgroup.php/$group->id/$file.jpg\"".
+ " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
+ } else {
+ $output .= "
wwwroot/user/pixgroup.php?file=/$group->id/$file.jpg\"".
+ " border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
+ }
+ }
+ if ($link) {
+ $output .= "";
}
- }
- if ($link) {
- $output .= "";
}
if ($returnstring) {
@@ -1654,6 +1656,22 @@ function update_groups_button($courseid) {
}
}
+function print_group_menu($groups, $groupmode, $currentgroup, $urlroot) {
+/// Prints an appropriate group selection menu
+
+ echo '
| '; + if ($groupmode == VISIBLEGROUPS) { + print_string('groupsvisible'); + } else { + print_string('groupsseparate'); + } + echo ':'; + echo ' | '; + popup_form($urlroot.'&group=', $groups, 'selectgroup', $currentgroup, "", "", "", false, "self"); + echo ' |