random course generator: Helpful comment at the top of the file.
[moodle.git] / group / members.php
CommitLineData
acf000b0 1<?php // $Id$
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');
14require_js('group/clientlib.js');
62d63838 15
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
27require_login($course);
28$context = get_context_instance(CONTEXT_COURSE, $courseid);
29require_capability('moodle/course:managegroups', $context);
30
62d63838 31$returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid.'&group='.$group->id;
32
97873016 33if (optional_param('cancel', false, PARAM_BOOL)) {
34 redirect($returnurl);
35}
62d63838 36
97873016 37$groupmembersselector = new group_members_selector('removeselect',
38 array('groupid' => $groupid, 'courseid' => $course->id));
39$groupmembersselector->set_extra_fields(array());
40$potentialmembersselector = new group_non_members_selector('addselect',
41 array('groupid' => $groupid, 'courseid' => $course->id));
42$potentialmembersselector->set_extra_fields(array());
43
44if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
45 $userstoadd = $potentialmembersselector->get_selected_users();
46 if (!empty($userstoadd)) {
47 foreach ($userstoadd as $user) {
48 if (!groups_add_member($groupid, $user->id)) {
62d63838 49 print_error('erroraddremoveuser', 'group', $returnurl);
50 }
97873016 51 $groupmembersselector->invalidate_selected_users();
52 $potentialmembersselector->invalidate_selected_users();
62d63838 53 }
62d63838 54 }
62d63838 55}
56
97873016 57if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
58 $userstoremove = $groupmembersselector->get_selected_users();
59 if (!empty($userstoremove)) {
60 foreach ($userstoremove as $user) {
61 if (!groups_remove_member($groupid, $user->id)) {
62 print_error('erroraddremoveuser', 'group', $returnurl);
e254aa34 63 }
97873016 64 $groupmembersselector->invalidate_selected_users();
65 $potentialmembersselector->invalidate_selected_users();
62d63838 66 }
62d63838 67 }
68}
69
70// Print the page and form
71$strgroups = get_string('groups');
72$strparticipants = get_string('participants');
0be6f678 73$stradduserstogroup = get_string('adduserstogroup', 'group');
acf000b0 74$strusergroupmembership = get_string('usergroupmembership', 'group');
62d63838 75
76$groupname = format_string($group->name);
77
0be6f678 78$navlinks = array();
79$navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$courseid", 'type' => 'misc');
80$navlinks[] = array('name' => $strgroups, 'link' => "$CFG->wwwroot/group/index.php?id=$courseid", 'type' => 'misc');
81$navlinks[] = array('name' => $stradduserstogroup, 'link' => null, 'type' => 'misc');
82$navigation = build_navigation($navlinks);
83
84print_header("$course->shortname: $strgroups", $course->fullname, $navigation, '', '', true, '', user_login_string($course, $USER));
97873016 85check_theme_arrows();
62d63838 86?>
acf000b0 87
62d63838 88<div id="addmembersform">
89 <h3 class="main"><?php print_string('adduserstogroup', 'group'); echo ": $groupname"; ?></h3>
90
91 <form id="assignform" method="post" action="members.php">
92 <div>
93 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
94 <input type="hidden" name="group" value="<?php echo $groupid; ?>" />
95
97873016 96 <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
62d63838 97 <tr>
97873016 98 <td id='memberscell'>
acf000b0 99 <p>
97873016 100 <label for="removeselect"><?php print_string('groupmembers', 'group'); ?></label>
acf000b0 101 </p>
97873016 102 <?php $groupmembersselector->display(); ?>
103 </td>
104 <td id='buttonscell'>
62d63838 105 <p class="arrow_button">
d3789c64 106 <input name="add" id="add" type="submit" value="<?php echo $THEME->larrow.'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
107 <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$THEME->rarrow; ?>" title="<?php print_string('remove'); ?>" />
62d63838 108 </p>
109 </td>
97873016 110 <td id='nonmemberscell'>
acf000b0 111 <p>
97873016 112 <label for="addselect"><?php print_string('potentialmembs', 'group'); ?></label>
acf000b0 113 </p>
97873016 114 <?php $potentialmembersselector->display(); ?>
115 </td>
62d63838 116 </tr>
97873016 117 <tr><td colspan="3" id='backcell'>
62d63838 118 <input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
119 </td></tr>
120 </table>
121 </div>
122 </form>
123</div>
124
125<?php
97873016 126 print_js_call('init_add_remove_members_page');
62d63838 127 print_footer($course);
128?>