group MDL-19798 Updated print_header and build_navigation to OUTPUT and PAGE equivalents
[moodle.git] / group / assign.php
CommitLineData
f16fa0a3 1<?php // $Id$
f3f7610c 2/**
62d63838 3 * Add/remove group from grouping.
f3f7610c
ML
4 * @package groups
5 */
6require_once('../config.php');
7require_once('lib.php');
f3f7610c 8
62d63838 9$groupingid = required_param('id', PARAM_INT);
23431567 10
dfdaabd6 11if (!$grouping = $DB->get_record('groupings', array('id'=>$groupingid))) {
b121a4ee 12 print_error('invalidgroupid');
2524b0f2 13}
f3f7610c 14
dfdaabd6 15if (!$course = $DB->get_record('course', array('id'=>$grouping->courseid))) {
b39552af 16 print_error('invalidcourse');
17}
2524b0f2 18$courseid = $course->id;
f3f7610c 19
62d63838 20require_login($course);
2524b0f2 21$context = get_context_instance(CONTEXT_COURSE, $courseid);
22require_capability('moodle/course:managegroups', $context);
23
62d63838 24$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$courseid;
f3f7610c 25
2524b0f2 26
294ce987 27if ($frm = data_submitted() and confirm_sesskey()) {
f3f7610c 28
62d63838 29 if (isset($frm->cancel)) {
30 redirect($returnurl);
2524b0f2 31
62d63838 32 } else if (isset($frm->add) and !empty($frm->addselect)) {
33 foreach ($frm->addselect as $groupid) {
f16fa0a3 34 groups_assign_grouping($grouping->id, (int)$groupid);
f3f7610c 35 }
2524b0f2 36
62d63838 37 } else if (isset($frm->remove) and !empty($frm->removeselect)) {
62d63838 38 foreach ($frm->removeselect as $groupid) {
f16fa0a3 39 groups_unassign_grouping($grouping->id, (int)$groupid);
27c69abe 40 }
27c69abe 41 }
62d63838 42}
2524b0f2 43
2524b0f2 44
62d63838 45$currentmembers = array();
46$potentialmembers = array();
47
6edfb4c8 48if ($groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name')) {
dfdaabd6 49 if ($assignment = $DB->get_records('groupings_groups', array('groupingid'=>$grouping->id))) {
62d63838 50 foreach ($assignment as $ass) {
51 $currentmembers[$ass->groupid] = $groups[$ass->groupid];
52 unset($groups[$ass->groupid]);
53 }
23431567 54 }
62d63838 55 $potentialmembers = $groups;
56}
27c69abe 57
62d63838 58$currentmembersoptions = '';
59$currentmemberscount = 0;
60if ($currentmembers) {
61 foreach($currentmembers as $group) {
62 $currentmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
63 $currentmemberscount ++;
64 }
47b18c1c 65
66 // Get course managers so they can be hilited in the list
67 if ($managerroles = get_config('', 'coursemanager')) {
68 $coursemanagerroles = split(',', $managerroles);
69 foreach ($coursemanagerroles as $roleid) {
dfdaabd6 70 $role = $DB->get_record('role', array('id'=>$roleid));
690c946c 71 $canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
72 $managers = get_role_users($roleid, $context, true, 'u.id', 'u.id ASC', $canseehidden);
47b18c1c 73 }
74 }
62d63838 75} else {
76 $currentmembersoptions .= '<option>&nbsp;</option>';
77}
23431567 78
62d63838 79$potentialmembersoptions = '';
80$potentialmemberscount = 0;
81if ($potentialmembers) {
82 foreach($potentialmembers as $group) {
83 $potentialmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
84 $potentialmemberscount ++;
27c69abe 85 }
62d63838 86} else {
87 $potentialmembersoptions .= '<option>&nbsp;</option>';
88}
f3f7610c 89
62d63838 90// Print the page and form
91$strgroups = get_string('groups');
92$strparticipants = get_string('participants');
0be6f678 93$straddgroupstogroupings = get_string('addgroupstogroupings', 'group');
f3f7610c 94
62d63838 95$groupingname = format_string($grouping->name);
f3f7610c 96
b87573d7 97$PAGE->navbar->add($strparticipants, new moodle_url($CFG->wwwroot.'/user/index.php', array('id'=>$courseid)));
98$PAGE->navbar->add($strgroups, new moodle_url($CFG->wwwroot.'/group/index.php', array('id'=>$courseid)));
99$PAGE->navbar->add($straddgroupstogroupings);
100
101/// Print header
102$PAGE->set_title("$course->shortname: $strgroups");
103$PAGE->set_heading($course->fullname);
104$PAGE->set_headingmenu(user_login_string($course, $USER));
105echo $OUTPUT->header();
f3f7610c 106
f3f7610c
ML
107?>
108<div id="addmembersform">
62d63838 109 <h3 class="main"><?php print_string('addgroupstogroupings', 'group'); echo ": $groupingname"; ?></h3>
f3f7610c 110
b4e80a8b 111 <form id="assignform" method="post" action="">
112 <div>
f3f7610c 113 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
f3f7610c 114
b4e80a8b 115 <table summary="" cellpadding="5" cellspacing="0">
f3f7610c
ML
116 <tr>
117 <td valign="top">
dfdaabd6 118 <label for="removeselect"><?php print_string('existingmembers', 'group', $currentmemberscount); ?></label>
f3f7610c
ML
119 <br />
120 <select name="removeselect[]" size="20" id="removeselect" multiple="multiple"
b4e80a8b 121 onfocus="document.getElementById('assignform').add.disabled=true;
122 document.getElementById('assignform').remove.disabled=false;
123 document.getElementById('assignform').addselect.selectedIndex=-1;">
62d63838 124 <?php echo $currentmembersoptions ?>
f3f7610c
ML
125 </select></td>
126 <td valign="top">
f3f7610c
ML
127
128 <?php check_theme_arrows(); ?>
129 <p class="arrow_button">
130 <input name="add" id="add" type="submit" value="<?php echo '&nbsp;'.$THEME->larrow.' &nbsp; &nbsp; '.get_string('add'); ?>" title="<?php print_string('add'); ?>" />
131 <br />
132 <input name="remove" id="remove" type="submit" value="<?php echo '&nbsp; '.$THEME->rarrow.' &nbsp; &nbsp; '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" />
133 </p>
134 </td>
135 <td valign="top">
dfdaabd6 136 <label for="addselect"><?php print_string('potentialmembers', 'group', $potentialmemberscount); ?></label>
f3f7610c
ML
137 <br />
138 <select name="addselect[]" size="20" id="addselect" multiple="multiple"
b4e80a8b 139 onfocus="document.getElementById('assignform').add.disabled=false;
140 document.getElementById('assignform').remove.disabled=true;
141 document.getElementById('assignform').removeselect.selectedIndex=-1;">
62d63838 142 <?php echo $potentialmembersoptions ?>
f3f7610c
ML
143 </select>
144 <br />
f3f7610c
ML
145 </td>
146 </tr>
147 <tr><td>
62d63838 148 <input type="submit" name="cancel" value="<?php print_string('backtogroupings', 'group'); ?>" />
f3f7610c
ML
149 </td></tr>
150 </table>
b4e80a8b 151 </div>
f3f7610c
ML
152 </form>
153</div>
154
155<?php
653468d4 156 echo $OUTPUT->footer();
62d63838 157
158
f3f7610c 159?>