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