forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmembers.php
127 lines (110 loc) · 4.79 KB
/
members.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php // $Id$
/**
* Add/remove members from group.
*
* @copyright © 2006 The Open University and others
* @author N.D.Freear AT open.ac.uk
* @author J.White AT open.ac.uk and others
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package groups
*/
require_once(dirname(__FILE__) . '/../config.php');
require_once(dirname(__FILE__) . '/lib.php');
require_once($CFG->dirroot . '/user/selector/lib.php');
require_js('group/clientlib.js');
$groupid = required_param('group', PARAM_INT);
if (!$group = $DB->get_record('groups', array('id'=>$groupid))) {
print_error('invalidgroupid');
}
if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) {
print_error('invalidcourse');
}
$courseid = $course->id;
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $courseid);
require_capability('moodle/course:managegroups', $context);
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid.'&group='.$group->id;
if (optional_param('cancel', false, PARAM_BOOL)) {
redirect($returnurl);
}
$groupmembersselector = new group_members_selector('removeselect',
array('groupid' => $groupid, 'courseid' => $course->id));
$groupmembersselector->set_extra_fields(array());
$potentialmembersselector = new group_non_members_selector('addselect',
array('groupid' => $groupid, 'courseid' => $course->id));
$potentialmembersselector->set_extra_fields(array());
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoadd = $potentialmembersselector->get_selected_users();
if (!empty($userstoadd)) {
foreach ($userstoadd as $user) {
if (!groups_add_member($groupid, $user->id)) {
print_error('erroraddremoveuser', 'group', $returnurl);
}
$groupmembersselector->invalidate_selected_users();
$potentialmembersselector->invalidate_selected_users();
}
}
}
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoremove = $groupmembersselector->get_selected_users();
if (!empty($userstoremove)) {
foreach ($userstoremove as $user) {
if (!groups_remove_member($groupid, $user->id)) {
print_error('erroraddremoveuser', 'group', $returnurl);
}
$groupmembersselector->invalidate_selected_users();
$potentialmembersselector->invalidate_selected_users();
}
}
}
// Print the page and form
$strgroups = get_string('groups');
$strparticipants = get_string('participants');
$stradduserstogroup = get_string('adduserstogroup', 'group');
$strusergroupmembership = get_string('usergroupmembership', 'group');
$groupname = format_string($group->name);
$navlinks = array();
$navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$courseid", 'type' => 'misc');
$navlinks[] = array('name' => $strgroups, 'link' => "$CFG->wwwroot/group/index.php?id=$courseid", 'type' => 'misc');
$navlinks[] = array('name' => $stradduserstogroup, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: $strgroups", $course->fullname, $navigation, '', '', true, '', user_login_string($course, $USER));
check_theme_arrows();
?>
<div id="addmembersform">
<h3 class="main"><?php print_string('adduserstogroup', 'group'); echo ": $groupname"; ?></h3>
<form id="assignform" method="post" action="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
<div>
<input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
<table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
<tr>
<td id='existingcell'>
<p>
<label for="removeselect"><?php print_string('groupmembers', 'group'); ?></label>
</p>
<?php $groupmembersselector->display(); ?>
</td>
<td id='buttonscell'>
<p class="arrow_button">
<input name="add" id="add" type="submit" value="<?php echo $THEME->larrow.' '.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
<input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').' '.$THEME->rarrow; ?>" title="<?php print_string('remove'); ?>" />
</p>
</td>
<td id='potentialcell'>
<p>
<label for="addselect"><?php print_string('potentialmembs', 'group'); ?></label>
</p>
<?php $potentialmembersselector->display(); ?>
</td>
</tr>
<tr><td colspan="3" id='backcell'>
<input type="submit" name="cancel" value="<?php print_string('backtogroups', 'group'); ?>" />
</td></tr>
</table>
</div>
</form>
</div>
<?php
print_js_call('init_add_remove_members_page');
print_footer($course);
?>