MDL-20204 removed some forgotten legacy code
[moodle.git] / group / members.php
CommitLineData
4ca6cfbf 1<?php
62d63838 2/**
3 * Add/remove members from group.
4 *
97873016 5 * @copyright &copy; 2006 The Open University and others
62d63838 6 * @author N.D.Freear AT open.ac.uk
97873016 7 * @author J.White AT open.ac.uk and others
62d63838 8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 * @package groups
10 */
97873016 11require_once(dirname(__FILE__) . '/../config.php');
12require_once(dirname(__FILE__) . '/lib.php');
13require_once($CFG->dirroot . '/user/selector/lib.php');
558fce9c 14require_once($CFG->dirroot . '/course/lib.php');
62d63838 15
aa9671c9 16$groupid = required_param('group', PARAM_INT);
62d63838 17
dfdaabd6 18if (!$group = $DB->get_record('groups', array('id'=>$groupid))) {
b121a4ee 19 print_error('invalidgroupid');
62d63838 20}
21
dfdaabd6 22if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) {
62d63838 23 print_error('invalidcourse');
24}
25$courseid = $course->id;
26
849185ce 27$PAGE->set_url(new moodle_url($CFG->wwwroot.'/groups/members.php', array('id'=>$groupid)));
28
62d63838 29require_login($course);
30$context = get_context_instance(CONTEXT_COURSE, $courseid);
31require_capability('moodle/course:managegroups', $context);
32
62d63838 33$returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid.'&group='.$group->id;
34
97873016 35if (optional_param('cancel', false, PARAM_BOOL)) {
36 redirect($returnurl);
37}
62d63838 38
97873016 39$groupmembersselector = new group_members_selector('removeselect',
40 array('groupid' => $groupid, 'courseid' => $course->id));
41$groupmembersselector->set_extra_fields(array());
42$potentialmembersselector = new group_non_members_selector('addselect',
43 array('groupid' => $groupid, 'courseid' => $course->id));
44$potentialmembersselector->set_extra_fields(array());
6f5e0852 45
97873016 46if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
47 $userstoadd = $potentialmembersselector->get_selected_users();
48 if (!empty($userstoadd)) {
49 foreach ($userstoadd as $user) {
50 if (!groups_add_member($groupid, $user->id)) {
62d63838 51 print_error('erroraddremoveuser', 'group', $returnurl);
52 }
97873016 53 $groupmembersselector->invalidate_selected_users();
54 $potentialmembersselector->invalidate_selected_users();
62d63838 55 }
62d63838 56 }
62d63838 57}
58
97873016 59if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
60 $userstoremove = $groupmembersselector->get_selected_users();
61 if (!empty($userstoremove)) {
62 foreach ($userstoremove as $user) {
63 if (!groups_remove_member($groupid, $user->id)) {
64 print_error('erroraddremoveuser', 'group', $returnurl);
e254aa34 65 }
97873016 66 $groupmembersselector->invalidate_selected_users();
67 $potentialmembersselector->invalidate_selected_users();
62d63838 68 }
62d63838 69 }
70}
71
72// Print the page and form
73$strgroups = get_string('groups');
74$strparticipants = get_string('participants');
0be6f678 75$stradduserstogroup = get_string('adduserstogroup', 'group');
acf000b0 76$strusergroupmembership = get_string('usergroupmembership', 'group');
62d63838 77
78$groupname = format_string($group->name);
79
cf615522 80$PAGE->requires->js('group/clientlib.js');
b87573d7 81$PAGE->navbar->add($strparticipants, new moodle_url($CFG->wwwroot.'/user/index.php', array('id'=>$courseid)));
82$PAGE->navbar->add($strgroups, new moodle_url($CFG->wwwroot.'/group/index.php', array('id'=>$courseid)));
83$PAGE->navbar->add($stradduserstogroup);
84
85/// Print header
86$PAGE->set_title("$course->shortname: $strgroups");
87$PAGE->set_heading($course->fullname);
88$PAGE->set_headingmenu(user_login_string($course, $USER));
89echo $OUTPUT->header();
62d63838 90?>
acf000b0 91
62d63838 92<div id="addmembersform">
93 <h3 class="main"><?php print_string('adduserstogroup', 'group'); echo ": $groupname"; ?></h3>
94
aa9671c9 95 <form id="assignform" method="post" action="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
62d63838 96 <div>
97 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
62d63838 98
97873016 99 <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
62d63838 100 <tr>
6cab02ac 101 <td id='existingcell'>
acf000b0 102 <p>
97873016 103 <label for="removeselect"><?php print_string('groupmembers', 'group'); ?></label>
acf000b0 104 </p>
97873016 105 <?php $groupmembersselector->display(); ?>
106 </td>
107 <td id='buttonscell'>
62d63838 108 <p class="arrow_button">
d3789c64 109 <input name="add" id="add" type="submit" value="<?php echo $THEME->larrow.'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
110 <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$THEME->rarrow; ?>" title="<?php print_string('remove'); ?>" />
62d63838 111 </p>
112 </td>
6cab02ac 113 <td id='potentialcell'>
acf000b0 114 <p>
97873016 115 <label for="addselect"><?php print_string('potentialmembs', 'group'); ?></label>
acf000b0 116 </p>
97873016 117 <?php $potentialmembersselector->display(); ?>
118 </td>
bf1ac6d9
AD
119 <td>
120 <p><?php echo($strusergroupmembership) ?></p>
121 <div id="group-usersummary"></div>
122 </td>
62d63838 123 </tr>
97873016 124 <tr><td colspan="3" id='backcell'>
62d63838 125 <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
126 </td></tr>
127 </table>
128 </div>
129 </form>
130</div>
131
132<?php
bf1ac6d9
AD
133 //outputs the JS array used to display the other groups users are in
134 $potentialmembersselector->print_user_summaries($course->id);
135
4c459d6c
AD
136 //this must be after calling display() on the selectors so their setup JS executes first
137 $PAGE->requires->js_function_call('init_add_remove_members_page');
138
653468d4 139 echo $OUTPUT->footer();