Merge branch 'm24_MDL-38545_PHP_Strict_error' of https://github.com/scara/moodle...
[moodle.git] / group / assign.php
blobe42a1315e52972ea08885a6065a52787ccc97763
1 <?php
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.
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/>.
18 /**
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
23 * @package core_group
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 = context_course::instance($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)) {
52 redirect($returnurl);
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');
96 } else {
97 $currentmembersoptions .= '<option>&nbsp;</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 ++;
107 } else {
108 $potentialmembersoptions .= '<option>&nbsp;</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);
125 /// Print header
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="">
135 <div>
136 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
138 <table summary="" cellpadding="5" cellspacing="0">
139 <tr>
140 <td valign="top">
141 <label for="removeselect"><?php print_string('existingmembers', 'group', $currentmemberscount); ?></label>
142 <br />
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 ?>
148 </select></td>
149 <td valign="top">
151 <p class="arrow_button">
152 <input name="add" id="add" type="submit" value="<?php echo '&nbsp;'.$OUTPUT->larrow().' &nbsp; &nbsp; '.get_string('add'); ?>" title="<?php print_string('add'); ?>" />
153 <br />
154 <input name="remove" id="remove" type="submit" value="<?php echo '&nbsp; '.$OUTPUT->rarrow().' &nbsp; &nbsp; '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" />
155 </p>
156 </td>
157 <td valign="top">
158 <label for="addselect"><?php print_string('potentialmembers', 'group', $potentialmemberscount); ?></label>
159 <br />
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 ?>
165 </select>
166 <br />
167 </td>
168 </tr>
169 <tr><td>
170 <input type="submit" name="cancel" value="<?php print_string('backtogroupings', 'group'); ?>" />
171 </td></tr>
172 </table>
173 </div>
174 </form>
175 </div>
177 <?php
178 echo $OUTPUT->footer();