1
<?PHP // $Id: index.php,v 1.64.4.3 2004/11/03 14:11:52 moodler Exp $
1
<?PHP // $Id: index.php,v 1.88.2.3 2005/06/20 03:45:49 defacer Exp $
3
3
// Lists all the users within a given course
5
require_once("../config.php");
5
require_once('../config.php');
6
require_once($CFG->libdir.'/tablelib.php');
7
8
define('USER_SMALL_CLASS', 20); // Below this is considered small
8
9
define('USER_LARGE_CLASS', 200); // Above this is considered large
10
require_variable($id); //course
11
optional_variable($sort, "lastaccess"); //how to sort students
12
optional_variable($dir,"desc"); //how to sort students
13
optional_variable($page, "0"); // which page to show
14
optional_variable($lastinitial, ""); // only show students with this last initial
15
optional_variable($firstinitial, ""); // only show students with this first initial
16
optional_variable($perpage, "20"); // how many per page
19
if (! $course = get_record("course", "id", $id)) {
10
define('DEFAULT_PAGE_SIZE', 20);
12
$id = required_param('id', PARAM_INT); // Course id
13
$group = optional_param('group', -1, PARAM_INT); // Group to show
14
$page = optional_param('page', 0, PARAM_INT); // which page to show
15
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // how many per page
16
$mode = optional_param('mode', NULL); // '0' for less details, '1' for more
17
$showteachers = optional_param('teachers', 1, PARAM_INT); // do we want to see the teacher list?
19
if (! $course = get_record('course', 'id', $id)) {
20
20
error("Course ID is incorrect");
23
23
require_login($course->id);
25
25
if (!$course->category) {
26
26
if (!$CFG->showsiteparticipantslist and !isteacher(SITEID)) {
27
27
notice(get_string('sitepartlist0'));
29
if ($CFG->showsiteparticipantslist < 2 and !isteacher()) {
29
if ($CFG->showsiteparticipantslist < 2 and !isteacherinanycourse()) {
30
30
notice(get_string('sitepartlist1'));
34
add_to_log($course->id, "user", "view all", "index.php?id=$course->id", "");
34
add_to_log($course->id, 'user', 'view all', 'index.php?id='.$course->id, '');
36
36
$isteacher = isteacher($course->id);
37
$showteachers = ($page == 0 and $sort == "lastaccess" and $dir == "desc");
40
$participantslink = get_string("participants");
38
$countries = get_list_of_countries();
40
$strnever = get_string('never');
42
$datestring->day = get_string('day');
43
$datestring->days = get_string('days');
44
$datestring->hour = get_string('hour');
45
$datestring->hours = get_string('hours');
46
$datestring->min = get_string('min');
47
$datestring->mins = get_string('mins');
48
$datestring->sec = get_string('sec');
49
$datestring->secs = get_string('secs');
52
$SESSION->userindexmode = $fullmode = ($mode == 1);
53
} else if (isset($SESSION->userindexmode)) {
54
$fullmode = $SESSION->userindexmode;
42
$participantslink = "<a href=\"index.php?id=$course->id\">".get_string("participants")."</a>";
45
$isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and
59
/// Check to see if groups are being used in this forum
60
/// and if so, set $currentgroup to reflect the current group
62
$groupmode = groupmode($course); // Groups are being used
63
$currentgroup = get_and_set_current_group($course, $groupmode, $group);
65
if (!$currentgroup) { // To make some other functions work better later
69
$isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and
46
70
!isteacheredit($course->id));
48
$currentgroup = $isseparategroups ? get_current_group($course->id) : NULL;
72
if ($isseparategroups and (!$currentgroup) ) { //XXX
73
print_heading(get_string("notingroup", "forum"));
74
print_footer($course);
78
// Should use this variable so that we don't break stuff every time a variable is added or changed.
79
$baseurl = $CFG->wwwroot.'/user/index.php?id='.$course->id.'&group='.$currentgroup.'&perpage='.$perpage.'&teachers='.$showteachers;
50
83
if ($course->category) {
51
print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
52
"<A HREF=../course/view.php?id=$course->id>$course->shortname</A> -> ".
53
"$participantslink", "", "", true, " ", navmenu($course));
84
print_header("$course->shortname: ".get_string('participants'), $course->fullname,
85
"<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> -> ".
86
get_string('participants'), "", "", true, " ", navmenu($course));
55
print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
56
"$participantslink", "", "", true, " ", navmenu($course));
59
$exceptions = ''; // This will be a list of userids that are shown as teachers and thus
60
// do not have to be shown as users as well. Only relevant on site course.
62
if ($teachers = get_course_teachers($course->id)) {
63
echo "<h2 align=\"center\">$course->teachers</h2>";
64
foreach ($teachers as $teacher) {
65
if ($isseparategroups) {
66
if (($teacher->editall or ismember($currentgroup, $teacher->id)) and ($teacher->authority > 0)) {
67
print_user($teacher, $course);
68
$exceptions .= "$teacher->id,";
70
} else if ($teacher->authority > 0) { // Don't print teachers with no authority
88
print_header("$course->shortname: ".get_string('participants'), $course->fullname,
89
get_string('participants'), "", "", true, " ", navmenu($course));
92
/// Print settings and things in a table across the top
94
echo '<table class="controls" cellspacing="0"><tr>';
96
if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
97
if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
98
echo '<td class="left">';
99
print_group_menu($groups, $groupmode, $currentgroup, $baseurl);
104
echo '<td class="right">';
105
echo get_string('userlist').': ';
106
$formatmenu = array( '0' => get_string('detailedless'),
107
'1' => get_string('detailedmore'));
108
echo popup_form($baseurl.'&mode=', $formatmenu, 'formatmenu', $fullmode, '', '', '', true);
109
echo '</td></tr></table>';
111
if ($currentgroup and (!$isseparategroups or isteacheredit($course->id))) { /// Display info about the group
112
if ($group = get_record('groups', 'id', $currentgroup)) {
113
if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) {
114
echo '<table class="groupinfobox"><tr><td class="left side picture">';
115
print_group_picture($group, $course->id, true, false, false);
116
echo '</td><td class="content">';
117
echo '<h3>'.$group->name;
118
if (isteacheredit($course->id)) {
119
echo ' <a title="'.get_string('editgroupprofile').'" href="../course/groups.php?id='.$course->id.'&group='.$group->id.'">';
120
echo '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="" border="0">';
124
echo format_text($group->description);
125
echo '</td></tr></table>';
131
$exceptions = array(); // This will be an array of userids that are shown as teachers and thus
132
// do not have to be shown as users as well. Only relevant on site course.
136
$tablecolumns = array('picture', 'fullname', 'city', 'country', 'lastaccess');
137
$tableheaders = array('', get_string('fullname'), get_string('city'), get_string('country'), get_string('lastaccess'));
139
$table = new flexible_table('user-index-teachers');
141
$table->define_columns($tablecolumns);
142
$table->define_headers($tableheaders);
143
$table->define_baseurl($baseurl);
145
$table->sortable(true, 'lastaccess', SORT_DESC);
147
$table->set_attribute('cellspacing', '0');
148
$table->set_attribute('id', 'teachers');
149
$table->set_attribute('class', 'generaltable generalbox');
153
if($whereclause = $table->get_sql_where()) {
154
$whereclause .= ' AND ';
157
$teachersql = "SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest,
158
u.email, u.maildisplay, u.city, u.country, u.lastlogin, u.picture, u.lang, u.timezone,
159
u.emailstop, t.authority,t.role,t.editall,t.timeaccess as lastaccess, m.groupid
160
FROM {$CFG->prefix}user u
161
LEFT JOIN {$CFG->prefix}user_teachers t ON t.userid = u.id
162
LEFT JOIN {$CFG->prefix}groups_members m ON m.userid = u.id ";
164
if($isseparategroups) {
165
$whereclause .= '(t.editall OR groupid = '.$currentgroup.') AND ';
167
else if ($currentgroup) { // Displaying a group by choice
168
$whereclause .= 'groupid = '.$currentgroup.' AND ';
171
$teachersql .= 'WHERE '.$whereclause.' t.course = '.$course->id.' AND u.deleted = 0 AND u.confirmed = 1 AND t.authority > 0';
173
if($sortclause = $table->get_sql_sort()) {
174
$teachersql .= ' ORDER BY '.$sortclause;
177
$teachers = get_records_sql($teachersql);
179
if(!empty($teachers)) {
181
echo '<h2>'.$course->teachers;
182
echo ' <a href="'.$baseurl.'&teachers=0">';
183
echo '<img src="'.$CFG->pixpath.'/i/hide.gif" height="16" width="16" alt="'.get_string('hide').'" /></a>';
184
if (isadmin() or ($course->category and (iscreator() or (isteacheredit($course->id) and !empty($CFG->teacherassignteachers))))) {
185
echo ' <a href="'.$CFG->wwwroot.'/course/teacher.php?id='.$course->id.'">';
186
echo '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="'.get_string('edit').'" /></a>';
190
$exceptions = array_keys($teachers);
193
foreach ($teachers as $key => $teacher) {
71
194
print_user($teacher, $course);
72
$exceptions .= "$teacher->id,";
197
$countrysort = (strpos($sortclause, 'country') !== false);
198
foreach ($teachers as $teacher) {
200
if ($teacher->lastaccess) {
201
$lastaccess = format_time(time() - $teacher->lastaccess, $datestring);
203
$lastaccess = $strnever;
206
if (empty($teacher->country)) {
211
$country = '('.$teacher->country.') '.$countries[$teacher->country];
214
$country = $countries[$teacher->country];
218
$table->add_data(array (
219
//'<input type="checkbox" name="userid[]" value="'.$teacher->id.'" />',
220
print_user_picture($teacher->id, $course->id, $teacher->picture, false, true),
221
'<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$teacher->id.'&course='.$course->id.'">'.fullname($teacher, $isteacher).'</a></strong>',
227
$table->print_html();
232
// Don't show teachers
233
echo '<h2>'.$course->teachers;
234
echo ' <a href="'.$baseurl.'&teachers=1">';
235
echo '<img src="'.$CFG->pixpath.'/i/show.gif" height="16" width="16" alt="'.get_string('show').'" /></a>';
236
if (isadmin() or ($course->category and (iscreator() or (isteacheredit($course->id) and !empty($CFG->teacherassignteachers))))) {
237
echo ' <a href="'.$CFG->wwwroot.'/course/teacher.php?id='.$course->id.'">';
238
echo '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="'.get_string('edit').'" /></a>';
77
243
$guest = get_guest();
78
$exceptions .= $guest->id;
80
if ($sort == "lastaccess") {
81
$dsort = "s.timeaccess";
85
$students = get_course_students($course->id, $dsort, $dir, $page*$perpage,
86
$perpage, $firstinitial, $lastinitial, $currentgroup);
87
$totalcount = count_course_students($course, "", "", "", $currentgroup);
88
if ($firstinitial or $lastinitial) {
89
$matchcount = count_course_students($course, "", $firstinitial, $lastinitial, $currentgroup);
91
$matchcount = $totalcount;
95
echo "<h2 align=center>$totalcount $course->students</h2>";
97
if (($CFG->longtimenosee < 500) and (!$page) and ($sort == "lastaccess")) {
98
echo "<center><p><font size=1>(";
99
print_string("unusedaccounts","",$CFG->longtimenosee);
100
echo ")</font></p></center>";
103
/// Print paging bars if necessary
105
if ($totalcount > $perpage) {
106
$alphabet = explode(',', get_string('alphabet'));
107
$strall = get_string("all");
110
/// Bar of first initials
112
echo "<center><p align=\"center\">";
113
echo get_string("firstname")." : ";
115
echo " <a href=\"index.php?id=$course->id&sort=firstname&dir=ASC&".
116
"perpage=$perpage&lastinitial=$lastinitial\">$strall</a> ";
118
echo " <b>$strall</b> ";
120
foreach ($alphabet as $letter) {
121
if ($letter == $firstinitial) {
122
echo " <b>$letter</b> ";
124
echo " <a href=\"index.php?id=$course->id&sort=firstname&dir=ASC&".
125
"perpage=$perpage&lastinitial=$lastinitial&firstinitial=$letter\">$letter</a> ";
130
/// Bar of last initials
132
echo get_string("lastname")." : ";
134
echo " <a href=\"index.php?id=$course->id&sort=lastname&dir=ASC&".
135
"perpage=$perpage&firstinitial=$firstinitial\">$strall</a> ";
137
echo " <b>$strall</b> ";
139
foreach ($alphabet as $letter) {
140
if ($letter == $lastinitial) {
141
echo " <b>$letter</b> ";
143
echo " <a href=\"index.php?id=$course->id&sort=lastname&dir=ASC&".
144
"perpage=$perpage&firstinitial=$firstinitial&lastinitial=$letter\">$letter</a> ";
150
print_paging_bar($matchcount, $page, $perpage,
151
"index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&");
155
if ($matchcount < 1) {
156
print_heading(get_string("nostudentsfound", "", $course->students));
158
} if (0 < $matchcount and $matchcount < USER_SMALL_CLASS) { // Print simple listing
159
foreach ($students as $student) {
160
print_user($student, $course);
163
} else if ($matchcount > 0) {
165
// Print one big table with abbreviated info
166
$columns = array("firstname", "lastname", "city", "country", "lastaccess");
168
$countries = get_list_of_countries();
170
$strnever = get_string("never");
172
$datestring->day = get_string("day");
173
$datestring->days = get_string("days");
174
$datestring->hour = get_string("hour");
175
$datestring->hours = get_string("hours");
176
$datestring->min = get_string("min");
177
$datestring->mins = get_string("mins");
178
$datestring->sec = get_string("sec");
179
$datestring->secs = get_string("secs");
181
foreach ($columns as $column) {
182
$colname[$column] = get_string($column);
183
if ($sort != $column) {
185
if ($column == "lastaccess") {
191
$columndir = $dir == "asc" ? "desc":"asc";
192
if ($column == "lastaccess") {
193
$columnicon = $dir == "asc" ? "up":"down";
195
$columnicon = $dir == "asc" ? "down":"up";
197
$columnicon = " <img src=\"$CFG->pixpath/t/$columnicon.gif\" />";
199
$$column = "<a href=\"index.php?id=$course->id&sort=$column&dir=$columndir\">".$colname["$column"]."</a>$columnicon";
202
foreach ($students as $key => $student) {
203
$students[$key]->country = ($student->country) ? $countries[$student->country] : '';
205
if ($sort == "country") { // Need to re-sort by full country name, not code
244
$exceptions[] = $guest->id;
246
$tablecolumns = array('picture', 'fullname', 'city', 'country', 'lastaccess');
247
$tableheaders = array('', get_string('fullname'), get_string('city'), get_string('country'), get_string('lastaccess'));
249
$table = new flexible_table('user-index-students');
251
$table->define_columns($tablecolumns);
252
$table->define_headers($tableheaders);
253
$table->define_baseurl($baseurl);
255
$table->sortable(true, 'lastaccess', SORT_DESC);
257
$table->set_attribute('cellspacing', '0');
258
$table->set_attribute('id', 'students');
259
$table->set_attribute('class', 'generaltable generalbox');
261
$table->set_control_variables(array(
262
TABLE_VAR_SORT => 'ssort',
263
TABLE_VAR_HIDE => 'shide',
264
TABLE_VAR_SHOW => 'sshow',
265
TABLE_VAR_IFIRST => 'sifirst',
266
TABLE_VAR_ILAST => 'silast',
267
TABLE_VAR_PAGE => 'spage'
271
if(SITEID == $course->id) {
272
$select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country,
273
u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, u.lastaccess ';
274
$from = 'FROM '.$CFG->prefix.'user u ';
275
$where = 'WHERE confirmed = 1 AND u.deleted = 0 ';
278
$select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country,
279
u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, s.timeaccess AS lastaccess ';
280
$from = 'FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'user_students s ON s.userid = u.id ';
281
$where = 'WHERE s.course = '.$course->id.' AND u.deleted = 0 ';
284
if ($currentgroup) { // Displaying a group by choice
285
// FIX: TODO: This will not work if $currentgroup == 0, i.e. "those not in a group"
286
$from .= 'LEFT JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid ';
287
$where .= ' AND gm.groupid = '.$currentgroup;
290
if($course->id == SITEID) {
291
$where .= ' AND u.id NOT IN ('.implode(',', $exceptions).')';
294
$totalcount = count_records_sql('SELECT COUNT(*) '.$from.$where);
296
if($table->get_sql_where()) {
297
$where .= ' AND '.$table->get_sql_where();
300
if($table->get_sql_sort()) {
301
$sort = ' ORDER BY '.$table->get_sql_sort();
307
if($table->get_sql_sort()) {
308
$sort = ' ORDER BY '.$table->get_sql_sort();
314
$matchcount = count_records_sql('SELECT COUNT(*) '.$from.$where);
316
$table->initialbars($totalcount > $perpage);
317
$table->pagesize($perpage, $matchcount);
319
if($table->get_page_start() !== '' && $table->get_page_size() !== '') {
320
$limit = ' '.sql_paging_limit($table->get_page_start(), $table->get_page_size());
326
$students = get_records_sql($select.$from.$where.$sort.$limit);
328
$a->count = $totalcount;
329
$a->items = $totalcount == 1 ? $course->student : $course->students;
330
echo '<h2>'.get_string('counteditems', '', $a);
331
if (isteacheredit($course->id)) {
332
echo ' <a href="../course/student.php?id='.$course->id.'">';
333
echo '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="" /></a>';
337
if ($CFG->longtimenosee > 0 && $CFG->longtimenosee < 1000 && $totalcount > 0) {
338
echo '<p id="longtimenosee">('.get_string('unusedaccounts', '', $CFG->longtimenosee).')</p>';
341
if ($fullmode) { // Print simple listing
342
if ($totalcount < 1) {
343
print_heading(get_string("nostudentsfound", "", $course->students));
347
if($totalcount > $perpage) {
349
$firstinitial = $table->get_initial_first();
350
$lastinitial = $table->get_initial_last();
351
$strall = get_string('all');
352
$alpha = explode(',', get_string('alphabet'));
354
// Bar of first initials
356
echo '<div class="initialbar firstinitial">'.get_string('firstname').' : ';
357
if(!empty($firstinitial)) {
358
echo '<a href="'.$baseurl.'&sifirst=">'.$strall.'</a>';
360
echo '<strong>'.$strall.'</strong>';
362
foreach ($alpha as $letter) {
363
if ($letter == $firstinitial) {
364
echo ' <strong>'.$letter.'</strong>';
366
echo ' <a href="'.$baseurl.'&sifirst='.$letter.'">'.$letter.'</a>';
371
// Bar of last initials
373
echo '<div class="initialbar lastinitial">'.get_string('lastname').' : ';
374
if(!empty($lastinitial)) {
375
echo '<a href="'.$baseurl.'&silast=">'.$strall.'</a>';
377
echo '<strong>'.$strall.'</strong>';
379
foreach ($alpha as $letter) {
380
if ($letter == $lastinitial) {
381
echo ' <strong>'.$letter.'</strong>';
383
echo ' <a href="'.$baseurl.'&silast='.$letter.'">'.$letter.'</a>';
388
print_paging_bar($matchcount, intval($table->get_page_start() / $perpage), $perpage, $baseurl.'&', 'spage');
392
if($matchcount > 0) {
393
foreach ($students as $student) {
394
print_user($student, $course);
398
print_heading(get_string('nothingtodisplay'));
403
$countrysort = (strpos($sort, 'country') !== false);
404
if (!empty($students)) {
206
405
foreach ($students as $student) {
207
$sstudents[$student->id] = $student->country;
210
foreach ($sstudents as $key => $value) {
211
$nstudents[] = $students[$key];
213
$students = $nstudents;
217
$table->head = array (" ", "$firstname / $lastname", $city, $country, $lastaccess);
218
$table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT");
219
$table->size = array ("10", "*", "*", "*", "*");
220
$table->size = array ("10", "*", "*", "*", "*");
221
$table->cellpadding = 4;
222
$table->cellspacing = 0;
224
foreach ($students as $student) {
226
if ($student->lastaccess) {
227
$lastaccess = format_time(time() - $student->lastaccess, $datestring);
229
$lastaccess = $strnever;
232
$picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
234
$fullname = fullname($student, $isteacher);
236
$table->data[] = array ($picture,
237
"<b><a href=\"$CFG->wwwroot/user/view.php?id=$student->id&course=$course->id\">$fullname</a></b>",
238
"<font size=2>$student->city</font>",
239
"<font size=2>$student->country</font>",
240
"<font size=2>$lastaccess</font>");
244
print_paging_bar($matchcount, $page, $perpage,
245
"index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&");
247
if ($perpage != 99999) {
249
echo "<a href=\"index.php?id=$course->id&sort=$sort&dir=$dir&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
250
echo "</p></center>";
406
if ($student->lastaccess) {
407
$lastaccess = format_time(time() - $student->lastaccess, $datestring);
409
$lastaccess = $strnever;
412
if (empty($student->country)) {
417
$country = '('.$student->country.') '.$countries[$student->country];
420
$country = $countries[$student->country];
424
$table->add_data(array (
425
//'<input type="checkbox" name="userid[]" value="'.$teacher->id.'" />',
426
print_user_picture($student->id, $course->id, $student->picture, false, true),
427
'<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&course='.$course->id.'">'.fullname($student).'</a></strong>',
434
$table->print_html();
438
if ($perpage == 99999) {
439
echo '<div id="showall"><a href="'.$baseurl.'&perpage='.DEFAULT_PAGE_SIZE.'">'.get_string('showperpage', '', DEFAULT_PAGE_SIZE).'</a></div>';
441
else if ($matchcount > 0 && $perpage < $matchcount) {
442
echo '<div id="showall"><a href="'.$baseurl.'&perpage=99999">'.get_string('showall', '', $matchcount).'</a></div>';
254
445
print_footer($course);