"MDL-20985, fixed typo, merged from 1.9"
[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');
81$PAGE->requires->js_function_call('init_add_remove_members_page');
b87573d7 82$PAGE->navbar->add($strparticipants, new moodle_url($CFG->wwwroot.'/user/index.php', array('id'=>$courseid)));
83$PAGE->navbar->add($strgroups, new moodle_url($CFG->wwwroot.'/group/index.php', array('id'=>$courseid)));
84$PAGE->navbar->add($stradduserstogroup);
85
86/// Print header
87$PAGE->set_title("$course->shortname: $strgroups");
88$PAGE->set_heading($course->fullname);
89$PAGE->set_headingmenu(user_login_string($course, $USER));
90echo $OUTPUT->header();
97873016 91check_theme_arrows();
62d63838 92?>
acf000b0 93
62d63838 94<div id="addmembersform">
95 <h3 class="main"><?php print_string('adduserstogroup', 'group'); echo ": $groupname"; ?></h3>
96
aa9671c9 97 <form id="assignform" method="post" action="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
62d63838 98 <div>
99 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
62d63838 100
97873016 101 <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
62d63838 102 <tr>
6cab02ac 103 <td id='existingcell'>
acf000b0 104 <p>
97873016 105 <label for="removeselect"><?php print_string('groupmembers', 'group'); ?></label>
acf000b0 106 </p>
97873016 107 <?php $groupmembersselector->display(); ?>
108 </td>
109 <td id='buttonscell'>
62d63838 110 <p class="arrow_button">
d3789c64 111 <input name="add" id="add" type="submit" value="<?php echo $THEME->larrow.'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
112 <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$THEME->rarrow; ?>" title="<?php print_string('remove'); ?>" />
62d63838 113 </p>
114 </td>
6cab02ac 115 <td id='potentialcell'>
acf000b0 116 <p>
97873016 117 <label for="addselect"><?php print_string('potentialmembs', 'group'); ?></label>
acf000b0 118 </p>
97873016 119 <?php $potentialmembersselector->display(); ?>
120 </td>
62d63838 121 </tr>
97873016 122 <tr><td colspan="3" id='backcell'>
62d63838 123 <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
124 </td></tr>
125 </table>
126 </div>
127 </form>
128</div>
129
130<?php
653468d4 131 echo $OUTPUT->footer();