MDL-25860 adding missing blocks to groupings page
[moodle.git] / group / assign.php
CommitLineData
bbe0bd98 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
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.
9//
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.
14//
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/>.
17
f3f7610c 18/**
62d63838 19 * Add/remove group from grouping.
bbe0bd98 20 *
21 * @copyright 1999 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
f3f7610c
ML
23 * @package groups
24 */
bbe0bd98 25
f3f7610c
ML
26require_once('../config.php');
27require_once('lib.php');
f3f7610c 28
62d63838 29$groupingid = required_param('id', PARAM_INT);
23431567 30
a6855934 31$PAGE->set_url('/group/assign.php', array('id'=>$groupingid));
bbe0bd98 32
dfdaabd6 33if (!$grouping = $DB->get_record('groupings', array('id'=>$groupingid))) {
b121a4ee 34 print_error('invalidgroupid');
2524b0f2 35}
f3f7610c 36
dfdaabd6 37if (!$course = $DB->get_record('course', array('id'=>$grouping->courseid))) {
b39552af 38 print_error('invalidcourse');
39}
2524b0f2 40$courseid = $course->id;
f3f7610c 41
62d63838 42require_login($course);
2524b0f2 43$context = get_context_instance(CONTEXT_COURSE, $courseid);
44require_capability('moodle/course:managegroups', $context);
45
62d63838 46$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$courseid;
f3f7610c 47
2524b0f2 48
294ce987 49if ($frm = data_submitted() and confirm_sesskey()) {
f3f7610c 50
62d63838 51 if (isset($frm->cancel)) {
52 redirect($returnurl);
2524b0f2 53
62d63838 54 } else if (isset($frm->add) and !empty($frm->addselect)) {
55 foreach ($frm->addselect as $groupid) {
f16fa0a3 56 groups_assign_grouping($grouping->id, (int)$groupid);
f3f7610c 57 }
2524b0f2 58
62d63838 59 } else if (isset($frm->remove) and !empty($frm->removeselect)) {
62d63838 60 foreach ($frm->removeselect as $groupid) {
f16fa0a3 61 groups_unassign_grouping($grouping->id, (int)$groupid);
27c69abe 62 }
27c69abe 63 }
62d63838 64}
2524b0f2 65
2524b0f2 66
62d63838 67$currentmembers = array();
68$potentialmembers = array();
69
6edfb4c8 70if ($groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name')) {
dfdaabd6 71 if ($assignment = $DB->get_records('groupings_groups', array('groupingid'=>$grouping->id))) {
62d63838 72 foreach ($assignment as $ass) {
73 $currentmembers[$ass->groupid] = $groups[$ass->groupid];
74 unset($groups[$ass->groupid]);
75 }
23431567 76 }
62d63838 77 $potentialmembers = $groups;
78}
27c69abe 79
62d63838 80$currentmembersoptions = '';
81$currentmemberscount = 0;
82if ($currentmembers) {
83 foreach($currentmembers as $group) {
84 $currentmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
85 $currentmemberscount ++;
86 }
47b18c1c 87
aa2f6604 88 // Get course managers so they can be highlighted in the list
df997f84 89 if ($managerroles = get_config('', 'coursecontact')) {
c71f3265 90 $coursecontactroles = explode(',', $managerroles);
df997f84 91 foreach ($coursecontactroles as $roleid) {
dfdaabd6 92 $role = $DB->get_record('role', array('id'=>$roleid));
4f0c2d00 93 $managers = get_role_users($roleid, $context, true, 'u.id', 'u.id ASC');
47b18c1c 94 }
95 }
62d63838 96} else {
97 $currentmembersoptions .= '<option>&nbsp;</option>';
98}
23431567 99
62d63838 100$potentialmembersoptions = '';
101$potentialmemberscount = 0;
102if ($potentialmembers) {
103 foreach($potentialmembers as $group) {
104 $potentialmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
105 $potentialmemberscount ++;
27c69abe 106 }
62d63838 107} else {
108 $potentialmembersoptions .= '<option>&nbsp;</option>';
109}
f3f7610c 110
62d63838 111// Print the page and form
112$strgroups = get_string('groups');
113$strparticipants = get_string('participants');
0be6f678 114$straddgroupstogroupings = get_string('addgroupstogroupings', 'group');
f3f7610c 115
62d63838 116$groupingname = format_string($grouping->name);
f3f7610c 117
7c725a24
PS
118navigation_node::override_active_url(new moodle_url('/group/index.php', array('id'=>$course->id)));
119$PAGE->set_pagelayout('standard');
120
a6855934
PS
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)));
b87573d7 123$PAGE->navbar->add($straddgroupstogroupings);
124
125/// Print header
126$PAGE->set_title("$course->shortname: $strgroups");
127$PAGE->set_heading($course->fullname);
b87573d7 128echo $OUTPUT->header();
f3f7610c 129
f3f7610c
ML
130?>
131<div id="addmembersform">
62d63838 132 <h3 class="main"><?php print_string('addgroupstogroupings', 'group'); echo ": $groupingname"; ?></h3>
f3f7610c 133
b4e80a8b 134 <form id="assignform" method="post" action="">
135 <div>
f3f7610c 136 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
f3f7610c 137
b4e80a8b 138 <table summary="" cellpadding="5" cellspacing="0">
f3f7610c
ML
139 <tr>
140 <td valign="top">
dfdaabd6 141 <label for="removeselect"><?php print_string('existingmembers', 'group', $currentmemberscount); ?></label>
f3f7610c
ML
142 <br />
143 <select name="removeselect[]" size="20" id="removeselect" multiple="multiple"
b4e80a8b 144 onfocus="document.getElementById('assignform').add.disabled=true;
145 document.getElementById('assignform').remove.disabled=false;
146 document.getElementById('assignform').addselect.selectedIndex=-1;">
62d63838 147 <?php echo $currentmembersoptions ?>
f3f7610c
ML
148 </select></td>
149 <td valign="top">
f3f7610c 150
f3f7610c 151 <p class="arrow_button">
92e01ab7 152 <input name="add" id="add" type="submit" value="<?php echo '&nbsp;'.$OUTPUT->larrow().' &nbsp; &nbsp; '.get_string('add'); ?>" title="<?php print_string('add'); ?>" />
f3f7610c 153 <br />
92e01ab7 154 <input name="remove" id="remove" type="submit" value="<?php echo '&nbsp; '.$OUTPUT->rarrow().' &nbsp; &nbsp; '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" />
f3f7610c
ML
155 </p>
156 </td>
157 <td valign="top">
dfdaabd6 158 <label for="addselect"><?php print_string('potentialmembers', 'group', $potentialmemberscount); ?></label>
f3f7610c
ML
159 <br />
160 <select name="addselect[]" size="20" id="addselect" multiple="multiple"
b4e80a8b 161 onfocus="document.getElementById('assignform').add.disabled=false;
162 document.getElementById('assignform').remove.disabled=true;
163 document.getElementById('assignform').removeselect.selectedIndex=-1;">
62d63838 164 <?php echo $potentialmembersoptions ?>
f3f7610c
ML
165 </select>
166 <br />
f3f7610c
ML
167 </td>
168 </tr>
169 <tr><td>
62d63838 170 <input type="submit" name="cancel" value="<?php print_string('backtogroupings', 'group'); ?>" />
f3f7610c
ML
171 </td></tr>
172 </table>
b4e80a8b 173 </div>
f3f7610c
ML
174 </form>
175</div>
176
177<?php
653468d4 178 echo $OUTPUT->footer();