mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
index.php
252 lines (207 loc) · 8.99 KB
/
index.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?php
/**
* The main group management user interface.
*
* @copyright © 2006 The Open University
* @author N.D.Freear AT open.ac.uk
* @author J.White AT open.ac.uk
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package groups
*/
require_once('../config.php');
require_once('lib.php');
require_once($CFG->libdir.'/json/JSON.php');
require_js('yui_yahoo');
require_js('yui_dom');
require_js('yui_utilities');
require_js('yui_connection');
require_js($CFG->wwwroot.'/group/lib/clientlib.js');
$courseid = required_param('id', PARAM_INT);
$groupid = optional_param('group', false, PARAM_INT);
$userid = optional_param('user', false, PARAM_INT);
$action = groups_param_action();
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid;
// Get the course information so we can print the header and
// check the course id is valid
if (!$course = groups_get_course_info($courseid)) {
$success = false;
print_error('invalidcourse'); //'The course ID is invalid'
}
// Make sure that the user has permissions to manage groups.
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $courseid);
if (! has_capability('moodle/course:managegroups', $context)) {
redirect(); //"group.php?id=$course->id"); // Not allowed to see all groups
}
switch ($action) {
case false: //OK, display form.
break;
case 'ajax_getmembersingroup':
$members = array();
if ($memberids = groups_get_members($groupid)) {
$member_names = groups_userids_to_user_names($memberids, $courseid);
$json = new Services_JSON();
echo $json->encode($member_names);
}
die; // Client side JavaScript takes it from here.
case 'deletegroup':
redirect('group.php?delete=1&courseid='.$courseid.'&id='.$groupid);
break;
case 'showcreateorphangroupform':
redirect('group.php?courseid='.$courseid);
break;
case 'showgroupsettingsform':
redirect('group.php?courseid='.$courseid.'&id='.$groupid);
break;
case 'updategroups': //Currently reloading.
break;
case 'removemembers':
break;
case 'showaddmembersform':
redirect('assign.php?group='.$groupid);
break;
case 'updatemembers': //Currently reloading.
break;
default: //ERROR.
if (debugging()) {
error('Error, unknown button/action. Probably a user-interface bug!', $returnurl);
break;
}
}
// Print the page and form
$strgroups = get_string('groups');
$strparticipants = get_string('participants');
print_header("$course->shortname: $strgroups",
$course->fullname,
"<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
"-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
"-> $strgroups", '', '', true, '', user_login_string($course, $USER));
$disabled = 'disabled="disabled"';
$showeditgroupsettingsform_disabled = $disabled;
$deletegroup_disabled = $disabled;
$showcreategroupform_disabled = $disabled;
if (!empty($groupid)) {
$showaddmembersform_disabled = '';
$showeditgroupsettingsform_disabled = '';
$deletegroup_disabled = '';
} else {
$deletegroup_disabled = $disabled;
$showeditgroupsettingsform_disabled = $disabled;
$showaddmembersform_disabled = $disabled;
}
print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3);
echo '<form id="groupeditform" action="index.php" method="post">'."\n";
echo '<div>'."\n";
echo '<input type="hidden" name="id" value="' . $courseid . '" />'."\n";
echo '<table cellpadding="6" class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">'."\n";
echo '<tr>'."\n";
echo "<td>\n";
// NO GROUPINGS YET!
echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping"> </span></label></p>'."\n";
echo '<select name="group" id="groups" size="15" class="select" onchange="membersCombo.refreshMembers(this.options[this.selectedIndex].value);"'."\n";
echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
if ($groups = groups_get_all_groups($courseid)) {
$groupids = array_keys($groups);
} else {
$groupids = false;
}
$sel_groupid = 0;
if ($groupids) {
// Put the groups into a hash and sort them
$group_names = groups_groupids_to_group_names($groupids);
// Print out the HTML
$count = 1;
foreach ($group_names as $group) {
$select = '';
if ($groupid == $group->id) { //|| $count <= 1) ??
$select = ' selected="selected"';
$sel_groupid = $group->id;
}
echo "<option value=\"{$group->id}\"$select title=\"{$group->name}\">{$group->name}</option>\n";
$count++;
}
} else {
// Print an empty option to avoid the XHTML error of having an empty select element
echo '<option> </option>';
}
echo '</select>'."\n";
echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="'
. get_string('showmembersforgroup', 'group') . '" /></p>'."\n";
echo '<p><input type="submit" '. $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="'
. get_string('editgroupsettings', 'group') . '" /></p>'."\n";
echo '<p><input type="submit" '. $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="'
. get_string('deleteselectedgroup', 'group') . '" /></p>'."\n";
echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="'
. get_string('creategroup', 'group') . '" /></p>'."\n";
echo '</td>'."\n";
echo '<td>'."\n";
echo '<p><label for="members"><span id="memberslabel">'.get_string('membersofselectedgroup', 'group').' </span><span id="thegroup"> </span></label></p>'."\n";
//NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick.
echo '<select name="user" id="members" size="15" class="select"'."\n";
echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
$userids = false;
if ($sel_groupid) {
$userids = groups_get_members($sel_groupid);
}
if ($userids) {
// Put the groupings into a hash and sort them
$user_names = groups_userids_to_user_names($userids, $courseid);
if(empty($user_names)) {
echo '<option> </option>';
} else {
foreach ($user_names as $user) {
echo "<option value=\"{$user->id}\" title=\"{$user->name}\">{$user->name}</option>\n";
}
}
} else {
// Print an empty option to avoid the XHTML error of having an empty select element
echo '<option> </option>';
}
echo '</select>'."\n";
echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" '
. 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n";
echo '</td>'."\n";
echo '</tr>'."\n";
echo '</table>'."\n";
//<input type="hidden" name="rand" value="om" />
echo '</div>'."\n";
echo '</form>'."\n";
echo '<script type="text/javascript">'."\n";
echo '//<![CDATA['."\n";
echo 'var groupsCombo = new UpdatableGroupsCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
echo 'var membersCombo = new UpdatableMembersCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
echo '//]]>'."\n";
echo '</script>'."\n";
print_footer($course);
/**
* Returns the first button action with the given prefix, taken from
* POST or GET, otherwise returns false.
* See /lib/moodlelib.php function optional_param.
* @param $prefix 'act_' as in 'action'.
* @return string The action without the prefix, or false if no action found.
*/
function groups_param_action($prefix = 'act_') {
$action = false;
//($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/
if ($_POST) {
$form_vars = $_POST;
}
elseif ($_GET) {
$form_vars = $_GET;
}
if ($form_vars) {
foreach ($form_vars as $key => $value) {
if (preg_match("/$prefix(.+)/", $key, $matches)) {
$action = $matches[1];
break;
}
}
}
if ($action && !preg_match('/^\w+$/', $action)) {
$action = false;
error('Action had wrong type.');
}
///if (debugging()) echo 'Debug: '.$action;
return $action;
}
?>