3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Add/remove group from grouping.
21 * @copyright 1999 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../config.php');
27 require_once('lib.php');
29 $groupingid = required_param('id', PARAM_INT
);
31 $PAGE->set_url('/group/assign.php', array('id'=>$groupingid));
33 if (!$grouping = $DB->get_record('groupings', array('id'=>$groupingid))) {
34 print_error('invalidgroupid');
37 if (!$course = $DB->get_record('course', array('id'=>$grouping->courseid
))) {
38 print_error('invalidcourse');
40 $courseid = $course->id
;
42 require_login($course);
43 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
44 require_capability('moodle/course:managegroups', $context);
46 $returnurl = $CFG->wwwroot
.'/group/groupings.php?id='.$courseid;
49 if ($frm = data_submitted() and confirm_sesskey()) {
51 if (isset($frm->cancel
)) {
54 } else if (isset($frm->add
) and !empty($frm->addselect
)) {
55 foreach ($frm->addselect
as $groupid) {
56 groups_assign_grouping($grouping->id
, (int)$groupid);
59 } else if (isset($frm->remove
) and !empty($frm->removeselect
)) {
60 foreach ($frm->removeselect
as $groupid) {
61 groups_unassign_grouping($grouping->id
, (int)$groupid);
67 $currentmembers = array();
68 $potentialmembers = array();
70 if ($groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name')) {
71 if ($assignment = $DB->get_records('groupings_groups', array('groupingid'=>$grouping->id
))) {
72 foreach ($assignment as $ass) {
73 $currentmembers[$ass->groupid
] = $groups[$ass->groupid
];
74 unset($groups[$ass->groupid
]);
77 $potentialmembers = $groups;
80 $currentmembersoptions = '';
81 $currentmemberscount = 0;
82 if ($currentmembers) {
83 foreach($currentmembers as $group) {
84 $currentmembersoptions .= '<option value="'.$group->id
.'.">'.format_string($group->name
).'</option>';
85 $currentmemberscount ++
;
88 // Get course managers so they can be highlighted in the list
89 if ($managerroles = get_config('', 'coursecontact')) {
90 $coursecontactroles = explode(',', $managerroles);
91 foreach ($coursecontactroles as $roleid) {
92 $role = $DB->get_record('role', array('id'=>$roleid));
93 $managers = get_role_users($roleid, $context, true, 'u.id', 'u.id ASC');
97 $currentmembersoptions .= '<option> </option>';
100 $potentialmembersoptions = '';
101 $potentialmemberscount = 0;
102 if ($potentialmembers) {
103 foreach($potentialmembers as $group) {
104 $potentialmembersoptions .= '<option value="'.$group->id
.'.">'.format_string($group->name
).'</option>';
105 $potentialmemberscount ++
;
108 $potentialmembersoptions .= '<option> </option>';
111 // Print the page and form
112 $strgroups = get_string('groups');
113 $strparticipants = get_string('participants');
114 $straddgroupstogroupings = get_string('addgroupstogroupings', 'group');
116 $groupingname = format_string($grouping->name
);
118 navigation_node
::override_active_url(new moodle_url('/group/index.php', array('id'=>$course->id
)));
119 $PAGE->set_pagelayout('standard');
121 $PAGE->navbar
->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
122 $PAGE->navbar
->add($strgroups, new moodle_url('/group/index.php', array('id'=>$courseid)));
123 $PAGE->navbar
->add($straddgroupstogroupings);
126 $PAGE->set_title("$course->shortname: $strgroups");
127 $PAGE->set_heading($course->fullname
);
128 echo $OUTPUT->header();
131 <div id
="addmembersform">
132 <h3
class="main"><?php
print_string('addgroupstogroupings', 'group'); echo ": $groupingname"; ?
></h3
>
134 <form id
="assignform" method
="post" action
="">
136 <input type
="hidden" name
="sesskey" value
="<?php p(sesskey()); ?>" />
138 <table summary
="" cellpadding
="5" cellspacing
="0">
141 <label
for="removeselect"><?php
print_string('existingmembers', 'group', $currentmemberscount); ?
></label
>
143 <select name
="removeselect[]" size
="20" id
="removeselect" multiple
="multiple"
144 onfocus
="document.getElementById('assignform').add.disabled=true;
145 document.getElementById('assignform').remove.disabled=false;
146 document.getElementById('assignform').addselect.selectedIndex=-1;">
147 <?php
echo $currentmembersoptions ?
>
151 <p
class="arrow_button">
152 <input name
="add" id
="add" type
="submit" value
="<?php echo ' '.$OUTPUT->larrow().' '.get_string('add'); ?>" title
="<?php print_string('add'); ?>" />
154 <input name
="remove" id
="remove" type
="submit" value
="<?php echo ' '.$OUTPUT->rarrow().' '.get_string('remove'); ?>" title
="<?php print_string('remove'); ?>" />
158 <label
for="addselect"><?php
print_string('potentialmembers', 'group', $potentialmemberscount); ?
></label
>
160 <select name
="addselect[]" size
="20" id
="addselect" multiple
="multiple"
161 onfocus
="document.getElementById('assignform').add.disabled=false;
162 document.getElementById('assignform').remove.disabled=true;
163 document.getElementById('assignform').removeselect.selectedIndex=-1;">
164 <?php
echo $potentialmembersoptions ?
>
170 <input type
="submit" name
="cancel" value
="<?php print_string('backtogroupings', 'group'); ?>" />
178 echo $OUTPUT->footer();