$a->course: course information added. Merged from stable.
[moodle.git] / user / index.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3// Lists all the users within a given course
4
cc038b47 5 require_once('../config.php');
68b38e8d 6 require_once($CFG->libdir.'/tablelib.php');
951b22a8 7
8 define('USER_SMALL_CLASS', 20); // Below this is considered small
9 define('USER_LARGE_CLASS', 200); // Above this is considered large
cc038b47 10 define('DEFAULT_PAGE_SIZE', 20);
f9903ed0 11
cc038b47 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?
31b71336 18 $accesssince = optional_param('accesssince',0,PARAM_INT); // filter by last access. -1 = never
ac17ef11 19 $search = optional_param('search','',PARAM_CLEAN);
f1e24e7a 20
21 $showteachers = $showteachers && empty($search); // if we're searching, we just want students.
cc038b47 22
23 if (! $course = get_record('course', 'id', $id)) {
f9903ed0 24 error("Course ID is incorrect");
25 }
26
27 require_login($course->id);
28
4bc162b7 29 if (!$course->category) {
30 if (!$CFG->showsiteparticipantslist and !isteacher(SITEID)) {
31 notice(get_string('sitepartlist0'));
32 }
9407d456 33 if ($CFG->showsiteparticipantslist < 2 and !isteacherinanycourse()) {
4bc162b7 34 notice(get_string('sitepartlist1'));
35 }
36 }
37
cc038b47 38 add_to_log($course->id, 'user', 'view all', 'index.php?id='.$course->id, '');
f9903ed0 39
951b22a8 40 $isteacher = isteacher($course->id);
4969ad74 41
f1e24e7a 42 if (empty($isteacher)) {
43 $search = false;
44 }
45
68b38e8d 46 $countries = get_list_of_countries();
47
cc038b47 48 $strnever = get_string('never');
68b38e8d 49
cc038b47 50 $datestring->day = get_string('day');
51 $datestring->days = get_string('days');
52 $datestring->hour = get_string('hour');
53 $datestring->hours = get_string('hours');
54 $datestring->min = get_string('min');
55 $datestring->mins = get_string('mins');
56 $datestring->sec = get_string('sec');
57 $datestring->secs = get_string('secs');
d578afc8 58
ff3caf30 59 if ($mode !== NULL) {
60 $SESSION->userindexmode = $fullmode = ($mode == 1);
61 } else if (isset($SESSION->userindexmode)) {
62 $fullmode = $SESSION->userindexmode;
63 } else {
64 $fullmode = false;
65 }
66
ff3caf30 67/// Check to see if groups are being used in this forum
68/// and if so, set $currentgroup to reflect the current group
69
ff3caf30 70 $groupmode = groupmode($course); // Groups are being used
cc038b47 71 $currentgroup = get_and_set_current_group($course, $groupmode, $group);
ff3caf30 72
cc038b47 73 if (!$currentgroup) { // To make some other functions work better later
74 $currentgroup = NULL;
75 }
ff3caf30 76
4bc162b7 77 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and
2cb2ce61 78 !isteacheredit($course->id));
79
ff3caf30 80 if ($isseparategroups and (!$currentgroup) ) { //XXX
81 print_heading(get_string("notingroup", "forum"));
82 print_footer($course);
83 exit;
84 }
85
cc038b47 86 // Should use this variable so that we don't break stuff every time a variable is added or changed.
e4103b6a 87 $baseurl = $CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$currentgroup.'&amp;perpage='.$perpage.'&amp;teachers='.$showteachers.'&amp;accesssince='.$accesssince.'&amp;search='.$search;
ff3caf30 88
89/// Print headers
2cb2ce61 90
4969ad74 91 if ($course->category) {
cc038b47 92 print_header("$course->shortname: ".get_string('participants'), $course->fullname,
031c49fa 93 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> -> ".
cc038b47 94 get_string('participants'), "", "", true, "&nbsp;", navmenu($course));
dc0dc7d5 95 } else {
cc038b47 96 print_header("$course->shortname: ".get_string('participants'), $course->fullname,
97 get_string('participants'), "", "", true, "&nbsp;", navmenu($course));
4969ad74 98 }
99
1242eb8f 100
101 //setting up tags
102 if ($id == SITEID) {
103 $filtertype = 'site';
104 } else if ($id && !$currentgroup) {
105 $filtertype = 'course';
106 $filterselect = $id;
107 } else {
108 $filtertype = 'group';
109 $filterselect = $currentgroup;
110 }
111 $currenttab = 'participants';
112 $user = $USER;
113
114 require_once($CFG->dirroot .'/user/tabs.php');
115
116
3468d58a 117/// Get the hidden field list
118 if ($isteacher || isadmin()) {
119 $hiddenfields = array(); // teachers and admins are allowed to see everything
120 } else {
121 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
122 }
123
ff3caf30 124/// Print settings and things in a table across the top
125
cc038b47 126 echo '<table class="controls" cellspacing="0"><tr>';
ff3caf30 127
1242eb8f 128 //print my course menus
129 echo '<td class="left">';
130 print_string('mycourses');
131 echo ': ';
132 $mycourses = get_my_courses($USER->id);
133 foreach ($mycourses as $mycourse) {
134 $my_course[$mycourse->id] = $mycourse->shortname;
135 }
136 //choose_from_menu($my_course, 'id', $course->id, '', 'courseform.submit()');
137 popup_form($CFG->wwwroot.'/user/index.php?id=',$my_course,'courseform',$course->id);
138 echo '</td></tr>';
139
ff3caf30 140 if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
141 if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
142 echo '<td class="left">';
cc038b47 143 print_group_menu($groups, $groupmode, $currentgroup, $baseurl);
ff3caf30 144 echo '</td>';
145 }
146 }
147
31b71336 148 // get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
149 $minlastaccess = get_field_sql('SELECT min(timeaccess) FROM '.$CFG->prefix.'user_students WHERE course = '.$course->id.' AND timeaccess != 0');
150
151 $lastaccess0exists = record_exists('user_students','course',$course->id,'timeaccess',0);
152 $now = usergetmidnight(time());
153 $timeaccess = array();
154
155 // makes sense for this to go first.
156 $timeoptions[0] = get_string('selectperiod');
157
158 // days
159 for ($i = 1; $i < 7; $i++) {
160 if (strtotime('-'.$i.' days',$now) >= $minlastaccess) {
161 $timeoptions[strtotime('-'.$i.' days',$now)] = get_string('numdays','moodle',$i);
162 }
163 }
164 // weeks
165 for ($i = 1; $i < 10; $i++) {
166 if (strtotime('-'.$i.' weeks',$now) >= $minlastaccess) {
167 $timeoptions[strtotime('-'.$i.' weeks',$now)] = get_string('numweeks','moodle',$i);
168 }
169 }
170 // months
171 for ($i = 2; $i < 12; $i++) {
172 if (strtotime('-'.$i.' months',$now) >= $minlastaccess) {
173 $timeoptions[strtotime('-'.$i.' months',$now)] = get_string('nummonths','moodle',$i);
174 }
175 }
176 // try a year
177 if (strtotime('-1 year',$now) >= $minlastaccess) {
178 $timeoptions[strtotime('-1 year',$now)] = get_string('lastyear');
179 }
180
181 if (!empty($lastaccess0exists)) {
182 $timeoptions[-1] = get_string('never');
183 }
184
185 if (count($timeoptions) > 1) {
186 echo '<td class="left">';
187 echo get_string('usersnoaccesssince').': ';
188 $baseurl = preg_replace('/&amp;accesssince='.$accesssince.'/','',$baseurl);
189 echo popup_form($baseurl.'&amp;accesssince=',$timeoptions,'timeoptions',$accesssince,'','','',true);
190 echo '</td>';
191 }
192
cc038b47 193 echo '<td class="right">';
4bc162b7 194 echo get_string('userlist').': ';
ff3caf30 195 $formatmenu = array( '0' => get_string('detailedless'),
196 '1' => get_string('detailedmore'));
cc038b47 197 echo popup_form($baseurl.'&amp;mode=', $formatmenu, 'formatmenu', $fullmode, '', '', '', true);
ff3caf30 198 echo '</td></tr></table>';
199
200 if ($currentgroup and (!$isseparategroups or isteacheredit($course->id))) { /// Display info about the group
201 if ($group = get_record('groups', 'id', $currentgroup)) {
202 if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) {
203 echo '<table class="groupinfobox"><tr><td class="left side picture">';
204 print_group_picture($group, $course->id, true, false, false);
205 echo '</td><td class="content">';
206 echo '<h3>'.$group->name;
2c27cd19 207 if (isteacheredit($course->id)) {
208 echo '&nbsp;<a title="'.get_string('editgroupprofile').'" href="../course/groups.php?id='.$course->id.'&amp;group='.$group->id.'">';
209 echo '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="" border="0">';
210 echo '</a>';
211 }
ff3caf30 212 echo '</h3>';
213 echo format_text($group->description);
214 echo '</td></tr></table>';
215 }
216 }
217 }
218
4bc162b7 219
cc038b47 220 $exceptions = array(); // This will be an array of userids that are shown as teachers and thus
221 // do not have to be shown as users as well. Only relevant on site course.
68b38e8d 222
9a0f8502 223 if ($isteacher) {
224 echo '
225<script Language="JavaScript">
226<!--
227function checksubmit(form) {
228 var destination = form.formaction.options[form.formaction.selectedIndex].value;
229 if (destination == "" || !checkchecked(form)) {
230 form.formaction.selectedIndex = 0;
231 return false;
232 } else {
233 return true;
234 }
235}
236
237function checkchecked(form) {
238 var inputs = document.getElementsByTagName(\'INPUT\');
239 var checked = false;
240 inputs = filterByParent(inputs, function() {return form;});
241 for(var i = 0; i < inputs.length; ++i) {
242 if(inputs[i].type == \'checkbox\' && inputs[i].checked) {
243 checked = true;
244 }
245 }
246 return checked;
247}
248//-->
249</script>
250';
251 echo '<form action="action_redir.php" method="post" name="studentsform" onSubmit="return checksubmit(this);">';
252 echo '<input type="hidden" name="id" value="'.$id.'" />';
253 echo '<input type="hidden" name="returnto" value="'.$_SERVER['REQUEST_URI'].'" />';
254 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
255 }
256
68b38e8d 257 if($showteachers) {
258
3468d58a 259 $tablecolumns = array('picture', 'fullname');
260 $tableheaders = array('', get_string('fullname'));
261 if (!isset($hiddenfields['city'])) {
262 $tablecolumns[] = 'city';
263 $tableheaders[] = get_string('city');
264 }
265 if (!isset($hiddenfields['country'])) {
266 $tablecolumns[] = 'country';
267 $tableheaders[] = get_string('country');
268 }
269 if (!isset($hiddenfields['lastaccess'])) {
270 $tablecolumns[] = 'lastaccess';
271 $tableheaders[] = get_string('lastaccess');
272 }
68b38e8d 273
9a0f8502 274 if ($isteacher) {
275 $tablecolumns[] = '';
276 $tableheaders[] = get_string('select');
277 }
278
e5ada99f 279 $table = new flexible_table('user-index-teachers-'.$course->id);
68b38e8d 280
281 $table->define_columns($tablecolumns);
282 $table->define_headers($tableheaders);
cc038b47 283 $table->define_baseurl($baseurl);
68b38e8d 284
a5a3f48a 285 $table->sortable(true, 'lastaccess', SORT_DESC);
68b38e8d 286
287 $table->set_attribute('cellspacing', '0');
288 $table->set_attribute('id', 'teachers');
289 $table->set_attribute('class', 'generaltable generalbox');
290
291 $table->setup();
292
293 if($whereclause = $table->get_sql_where()) {
294 $whereclause .= ' AND ';
295 }
296
297 $teachersql = "SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest,
cc038b47 298 u.email, u.maildisplay, u.city, u.country, u.lastlogin, u.picture, u.lang, u.timezone,
68b38e8d 299 u.emailstop, t.authority,t.role,t.editall,t.timeaccess as lastaccess, m.groupid
300 FROM {$CFG->prefix}user u
301 LEFT JOIN {$CFG->prefix}user_teachers t ON t.userid = u.id
302 LEFT JOIN {$CFG->prefix}groups_members m ON m.userid = u.id ";
303
304 if($isseparategroups) {
305 $whereclause .= '(t.editall OR groupid = '.$currentgroup.') AND ';
306 }
307 else if ($currentgroup) { // Displaying a group by choice
308 $whereclause .= 'groupid = '.$currentgroup.' AND ';
309 }
310
9a0f8502 311 $teachersql .= 'WHERE '.$whereclause.' t.course = '.$course->id.' AND u.deleted = 0 AND u.confirmed = 1';
312 if (!$isteacher) {
313 $teachersql .= ' AND t.authority > 0';
314 }
68b38e8d 315
31b71336 316 $teachersql .= get_lastaccess_sql($accesssince);
317
68b38e8d 318 if($sortclause = $table->get_sql_sort()) {
319 $teachersql .= ' ORDER BY '.$sortclause;
320 }
321
322 $teachers = get_records_sql($teachersql);
323
324 if(!empty($teachers)) {
325
cc038b47 326 echo '<h2>'.$course->teachers;
327 echo ' <a href="'.$baseurl.'&amp;teachers=0">';
328 echo '<img src="'.$CFG->pixpath.'/i/hide.gif" height="16" width="16" alt="'.get_string('hide').'" /></a>';
ec99b88e 329 if (isadmin() or ($course->category and (iscreator() or (isteacheredit($course->id) and !empty($CFG->teacherassignteachers))))) {
cc038b47 330 echo ' <a href="'.$CFG->wwwroot.'/course/teacher.php?id='.$course->id.'">';
331 echo '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="'.get_string('edit').'" /></a>';
03f191ad 332 }
333 echo '</h2>';
480dda61 334
cc038b47 335 $exceptions = array_keys($teachers);
68b38e8d 336
ff3caf30 337 if ($fullmode) {
338 foreach ($teachers as $key => $teacher) {
9a0f8502 339 print_user($teacher, $course, true);
4969ad74 340 }
ff3caf30 341 } else {
bf845f2b 342 $countrysort = (strpos($sortclause, 'country') !== false);
68b38e8d 343 foreach ($teachers as $teacher) {
344
345 if ($teacher->lastaccess) {
346 $lastaccess = format_time(time() - $teacher->lastaccess, $datestring);
347 } else {
348 $lastaccess = $strnever;
349 }
bf845f2b 350
351 if (empty($teacher->country)) {
352 $country = '';
353 }
354 else {
355 if($countrysort) {
356 $country = '('.$teacher->country.') '.$countries[$teacher->country];
357 }
358 else {
359 $country = $countries[$teacher->country];
360 }
361 }
68b38e8d 362
9a0f8502 363 $data = array (
68b38e8d 364 print_user_picture($teacher->id, $course->id, $teacher->picture, false, true),
3468d58a 365 '<strong><a'.($teacher->authority?'':' class="dimmed"').' href="'.$CFG->wwwroot.'/user/view.php?id='.$teacher->id.'&amp;course='.$course->id.'">'.fullname($teacher, $isteacher).'</a></strong>');
366 if (!isset($hiddenfields['city'])) {
367 $data[] = $teacher->city;
368 }
369 if (!isset($hiddenfields['country'])) {
370 $data[] = $country;
371 }
372 if (!isset($hiddenfields['lastaccess'])) {
373 $data[] = $lastaccess;
374 }
9a0f8502 375 if ($isteacher) {
376 $data[] = '<input type="checkbox" name="teacher'.$teacher->id.'" />';
377 }
378 $table->add_data($data);
68b38e8d 379 }
cc038b47 380
381 $table->print_html();
4969ad74 382 }
383 }
dc0dc7d5 384 }
cc038b47 385 else {
386 // Don't show teachers
387 echo '<h2>'.$course->teachers;
388 echo ' <a href="'.$baseurl.'&amp;teachers=1">';
389 echo '<img src="'.$CFG->pixpath.'/i/show.gif" height="16" width="16" alt="'.get_string('show').'" /></a>';
390 if (isadmin() or ($course->category and (iscreator() or (isteacheredit($course->id) and !empty($CFG->teacherassignteachers))))) {
391 echo ' <a href="'.$CFG->wwwroot.'/course/teacher.php?id='.$course->id.'">';
392 echo '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="'.get_string('edit').'" /></a>';
62b80756 393 }
cc038b47 394 echo '</h2>';
2cb2ce61 395 }
a328425d 396
cc038b47 397 $guest = get_guest();
398 $exceptions[] = $guest->id;
399
3468d58a 400 $tablecolumns = array('picture', 'fullname');
401 $tableheaders = array('', get_string('fullname'));
402 if (!isset($hiddenfields['city'])) {
403 $tablecolumns[] = 'city';
404 $tableheaders[] = get_string('city');
405 }
406 if (!isset($hiddenfields['country'])) {
407 $tablecolumns[] = 'country';
408 $tableheaders[] = get_string('country');
409 }
410 if (!isset($hiddenfields['lastaccess'])) {
411 $tablecolumns[] = 'lastaccess';
412 $tableheaders[] = get_string('lastaccess');
413 }
6746bb8a 414
415 if ($course->enrolperiod) {
416 $tablecolumns[] = 'timeend';
417 $tableheaders[] = get_string('enrolmentend');
418 }
419
420 if ($isteacher) {
421 $tablecolumns[] = '';
422 $tableheaders[] = get_string('select');
423 }
cc038b47 424
e5ada99f 425 $table = new flexible_table('user-index-students-'.$course->id);
cc038b47 426
427 $table->define_columns($tablecolumns);
428 $table->define_headers($tableheaders);
429 $table->define_baseurl($baseurl);
430
a5a3f48a 431 $table->sortable(true, 'lastaccess', SORT_DESC);
cc038b47 432
433 $table->set_attribute('cellspacing', '0');
434 $table->set_attribute('id', 'students');
435 $table->set_attribute('class', 'generaltable generalbox');
436
437 $table->set_control_variables(array(
438 TABLE_VAR_SORT => 'ssort',
439 TABLE_VAR_HIDE => 'shide',
440 TABLE_VAR_SHOW => 'sshow',
441 TABLE_VAR_IFIRST => 'sifirst',
442 TABLE_VAR_ILAST => 'silast',
443 TABLE_VAR_PAGE => 'spage'
444 ));
445 $table->setup();
446
447 if(SITEID == $course->id) {
448 $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country,
449 u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, u.lastaccess ';
450 $from = 'FROM '.$CFG->prefix.'user u ';
451 $where = 'WHERE confirmed = 1 AND u.deleted = 0 ';
03f191ad 452 }
cc038b47 453 else {
454 $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country,
455 u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, s.timeaccess AS lastaccess ';
6746bb8a 456 $select .= $course->enrolperiod?', s.timeend ':'';
cc038b47 457 $from = 'FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'user_students s ON s.userid = u.id ';
458 $where = 'WHERE s.course = '.$course->id.' AND u.deleted = 0 ';
69ec0a8b 459 }
460
31b71336 461 $where .= get_lastaccess_sql($accesssince);
ac17ef11 462 $wheresearch = '';
31b71336 463
f1e24e7a 464 if (!empty($search)) {
465 $LIKE = sql_ilike();
466 $fullname = sql_fullname('u.firstname','u.lastname');
f0cb18e6 467 $wheresearch .= ' AND ('. $fullname .' '. $LIKE .'\'%'. $search .'%\' OR email '. $LIKE .'\'%'. $search .'%\' OR idnumber '.$LIKE.' \'%'.$search.'%\') ';
f1e24e7a 468
469 }
470
cc038b47 471 if ($currentgroup) { // Displaying a group by choice
472 // FIX: TODO: This will not work if $currentgroup == 0, i.e. "those not in a group"
473 $from .= 'LEFT JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid ';
474 $where .= ' AND gm.groupid = '.$currentgroup;
475 }
4969ad74 476
cc038b47 477 if($course->id == SITEID) {
478 $where .= ' AND u.id NOT IN ('.implode(',', $exceptions).')';
479 }
a328425d 480
cc038b47 481 $totalcount = count_records_sql('SELECT COUNT(*) '.$from.$where);
a328425d 482
cc038b47 483 if($table->get_sql_where()) {
484 $where .= ' AND '.$table->get_sql_where();
a328425d 485 }
486
cc038b47 487 if($table->get_sql_sort()) {
cc038b47 488 $sort = ' ORDER BY '.$table->get_sql_sort();
489 }
490 else {
491 $sort = '';
492 }
a328425d 493
f1e24e7a 494 $matchcount = count_records_sql('SELECT COUNT(*) '.$from.$where.$wheresearch);
ff3caf30 495
cc038b47 496 $table->initialbars($totalcount > $perpage);
497 $table->pagesize($perpage, $matchcount);
4bc162b7 498
cc038b47 499 if($table->get_page_start() !== '' && $table->get_page_size() !== '') {
500 $limit = ' '.sql_paging_limit($table->get_page_start(), $table->get_page_size());
4bc162b7 501 }
cc038b47 502 else {
503 $limit = '';
504 }
505
f1e24e7a 506 $students = get_records_sql($select.$from.$where.$wheresearch.$sort.$limit);
cbb0fee0 507
cc038b47 508 $a->count = $totalcount;
509 $a->items = $totalcount == 1 ? $course->student : $course->students;
510 echo '<h2>'.get_string('counteditems', '', $a);
511 if (isteacheredit($course->id)) {
512 echo ' <a href="../course/student.php?id='.$course->id.'">';
513 echo '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="" /></a>';
514 }
515 echo '</h2>';
ff3caf30 516
cc038b47 517 if ($CFG->longtimenosee > 0 && $CFG->longtimenosee < 1000 && $totalcount > 0) {
518 echo '<p id="longtimenosee">('.get_string('unusedaccounts', '', $CFG->longtimenosee).')</p>';
519 }
4bc162b7 520
cc038b47 521 if ($fullmode) { // Print simple listing
522 if ($totalcount < 1) {
523 print_heading(get_string("nostudentsfound", "", $course->students));
68b38e8d 524 }
cc038b47 525 else {
526
527 if($totalcount > $perpage) {
528
529 $firstinitial = $table->get_initial_first();
530 $lastinitial = $table->get_initial_last();
531 $strall = get_string('all');
532 $alpha = explode(',', get_string('alphabet'));
533
534 // Bar of first initials
535
536 echo '<div class="initialbar firstinitial">'.get_string('firstname').' : ';
537 if(!empty($firstinitial)) {
538 echo '<a href="'.$baseurl.'&amp;sifirst=">'.$strall.'</a>';
d578afc8 539 } else {
cc038b47 540 echo '<strong>'.$strall.'</strong>';
d578afc8 541 }
cc038b47 542 foreach ($alpha as $letter) {
543 if ($letter == $firstinitial) {
544 echo ' <strong>'.$letter.'</strong>';
545 } else {
546 echo ' <a href="'.$baseurl.'&amp;sifirst='.$letter.'">'.$letter.'</a>';
547 }
548 }
549 echo '</div>';
550
551 // Bar of last initials
552
553 echo '<div class="initialbar lastinitial">'.get_string('lastname').' : ';
554 if(!empty($lastinitial)) {
555 echo '<a href="'.$baseurl.'&amp;silast=">'.$strall.'</a>';
d578afc8 556 } else {
cc038b47 557 echo '<strong>'.$strall.'</strong>';
558 }
559 foreach ($alpha as $letter) {
560 if ($letter == $lastinitial) {
561 echo ' <strong>'.$letter.'</strong>';
562 } else {
563 echo ' <a href="'.$baseurl.'&amp;silast='.$letter.'">'.$letter.'</a>';
564 }
d578afc8 565 }
cc038b47 566 echo '</div>';
567
568 print_paging_bar($matchcount, intval($table->get_page_start() / $perpage), $perpage, $baseurl.'&amp;', 'spage');
569
32b4b974 570 }
d578afc8 571
cc038b47 572 if($matchcount > 0) {
573 foreach ($students as $student) {
f19570d0 574 print_user($student, $course, true);
cc038b47 575 }
adcb3ac5 576 }
cc038b47 577 else {
578 print_heading(get_string('nothingtodisplay'));
adcb3ac5 579 }
4969ad74 580 }
cc038b47 581 }
582 else {
583 $countrysort = (strpos($sort, 'country') !== false);
6746bb8a 584 $timeformat = get_string('strftimedate');
cc038b47 585 if (!empty($students)) {
586 foreach ($students as $student) {
587 if ($student->lastaccess) {
588 $lastaccess = format_time(time() - $student->lastaccess, $datestring);
589 } else {
590 $lastaccess = $strnever;
591 }
592
593 if (empty($student->country)) {
594 $country = '';
595 }
596 else {
597 if($countrysort) {
598 $country = '('.$student->country.') '.$countries[$student->country];
599 }
600 else {
601 $country = $countries[$student->country];
602 }
603 }
adcb3ac5 604
6746bb8a 605 $data = array (
cc038b47 606 print_user_picture($student->id, $course->id, $student->picture, false, true),
3468d58a 607 '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id.'">'.fullname($student).'</a></strong>');
608 if (!isset($hiddenfields['city'])) {
609 $data[] = $student->city;
610 }
611 if (!isset($hiddenfields['country'])) {
612 $data[] = $country;
613 }
614 if (!isset($hiddenfields['lastaccess'])) {
615 $data[] = $lastaccess;
616 }
6746bb8a 617 if ($course->enrolperiod) {
8ab5ca2f 618 if ($student->timeend) {
619 $data[] = userdate($student->timeend, $timeformat);
620 } else {
621 $data[] = get_string('unlimited');
622 }
6746bb8a 623 }
624 if ($isteacher) {
625 $data[] = '<input type="checkbox" name="user'.$student->id.'" />';
626 }
627 $table->add_data($data);
f19570d0 628
4969ad74 629 }
cc038b47 630 }
dc0dc7d5 631
cc038b47 632 $table->print_html();
6b281f1f 633
cc038b47 634 }
eca1c454 635
f19570d0 636 if ($isteacher) {
6746bb8a 637 echo '<br /><center>';
0f24c257 638 echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> ';
639 echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> ';
6746bb8a 640 $displaylist['messageselect.php'] = get_string('messageselectadd');
641 if ($course->enrolperiod) {
642 $displaylist['extendenrol.php'] = get_string('extendenrol');
643 }
5e2c3024 644 choose_from_menu ($displaylist, "formaction", "", get_string("withselectedusers"), "if(checksubmit(this.form))this.form.submit();", "");
df1b52e8 645 helpbutton("participantswithselectedusers", get_string("withselectedusers"));
6746bb8a 646 echo '<input type="submit" value="' . get_string('ok') . '"';
f19570d0 647 echo '</center></form>';
648 }
649
f1e24e7a 650 if ($isteacher && $totalcount > ($perpage*3)) {
651 echo '<form action="index.php"><p align="center"><input type="hidden" name="id" value="'.$course->id.'" />'.get_string('search').':&nbsp;'."\n";
652 echo '<input type="text" name="search" value="'.$search.'" />&nbsp;<input type="submit" value="'.get_string('search').'" /></p></form>'."\n";
653 }
654
cc038b47 655 if ($perpage == 99999) {
656 echo '<div id="showall"><a href="'.$baseurl.'&amp;perpage='.DEFAULT_PAGE_SIZE.'">'.get_string('showperpage', '', DEFAULT_PAGE_SIZE).'</a></div>';
657 }
658 else if ($matchcount > 0 && $perpage < $matchcount) {
659 echo '<div id="showall"><a href="'.$baseurl.'&amp;perpage=99999">'.get_string('showall', '', $matchcount).'</a></div>';
660 }
661
662 print_footer($course);
f9903ed0 663
31b71336 664
665function get_lastaccess_sql($accesssince='') {
666 if (empty($accesssince)) {
667 return '';
668 }
669 if ($accesssince == -1) { // never
670 return ' AND timeaccess = 0';
671 } else {
672 return ' AND timeaccess != 0 AND timeaccess < '.$accesssince;
673 }
674}
675
f9903ed0 676?>