courseid)) { print_error('invalidcourse'); } $courseid = $course->id; require_login($course); $context = get_context_instance(CONTEXT_COURSE, $courseid); require_capability('moodle/course:managegroups', $context); $returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$courseid; if ($frm = data_submitted() and confirm_sesskey()) { if (isset($frm->cancel)) { redirect($returnurl); } else if (isset($frm->add) and !empty($frm->addselect)) { foreach ($frm->addselect as $groupid) { groups_assign_grouping($grouping->id, (int)$groupid); } } else if (isset($frm->remove) and !empty($frm->removeselect)) { foreach ($frm->removeselect as $groupid) { groups_unassign_grouping($grouping->id, (int)$groupid); } } } $currentmembers = array(); $potentialmembers = array(); if ($groups = get_records('groups', 'courseid', $courseid, 'name')) { if ($assignment = get_records('groupings_groups', 'groupingid', $grouping->id)) { foreach ($assignment as $ass) { $currentmembers[$ass->groupid] = $groups[$ass->groupid]; unset($groups[$ass->groupid]); } } $potentialmembers = $groups; } $currentmembersoptions = ''; $currentmemberscount = 0; if ($currentmembers) { foreach($currentmembers as $group) { $currentmembersoptions .= ''; $currentmemberscount ++; } // Get course managers so they can be hilited in the list if ($managerroles = get_config('', 'coursemanager')) { $coursemanagerroles = split(',', $managerroles); foreach ($coursemanagerroles as $roleid) { $role = get_record('role','id',$roleid); $canseehidden = has_capability('moodle/role:viewhiddenassigns', $context); $managers = get_role_users($roleid, $context, true, 'u.id', 'u.id ASC', $canseehidden); } } } else { $currentmembersoptions .= ''; } $potentialmembersoptions = ''; $potentialmemberscount = 0; if ($potentialmembers) { foreach($potentialmembers as $group) { $potentialmembersoptions .= ''; $potentialmemberscount ++; } } else { $potentialmembersoptions .= ''; } // Print the page and form $strgroups = get_string('groups'); $strparticipants = get_string('participants'); $straddgroupstogroupings = get_string('addgroupstogroupings', 'group'); $groupingname = format_string($grouping->name); $navlinks = array(); $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$courseid", 'type' => 'misc'); $navlinks[] = array('name' => $strgroups, 'link' => "$CFG->wwwroot/group/index.php?id=$courseid", 'type' => 'misc'); $navlinks[] = array('name' => $straddgroupstogroupings, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); print_header("$course->shortname: $strgroups", $course->fullname, $navigation, '', '', true, '', user_login_string($course, $USER)); ?>