2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Lists all the users within a given course.
20 * @copyright 1999 Martin Dougiamas http://dougiamas.com
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../config.php');
26 require_once($CFG->dirroot.'/user/lib.php');
27 require_once($CFG->libdir.'/tablelib.php');
28 require_once($CFG->libdir.'/filelib.php');
30 define('USER_SMALL_CLASS', 20); // Below this is considered small.
31 define('USER_LARGE_CLASS', 200); // Above this is considered large.
32 define('DEFAULT_PAGE_SIZE', 20);
33 define('SHOW_ALL_PAGE_SIZE', 5000);
35 $page = optional_param('page', 0, PARAM_INT); // Which page to show.
36 $perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // How many per page.
37 $accesssince = optional_param('accesssince', 0, PARAM_INT); // Filter by last access. -1 = never.
38 $search = optional_param('search', '', PARAM_RAW); // Make sure it is processed with p() or s() when sending to output!
39 $roleid = optional_param('roleid', 0, PARAM_INT); // Optional roleid, 0 means all enrolled users (or all on the frontpage).
40 $contextid = optional_param('contextid', 0, PARAM_INT); // One of this or.
41 $courseid = optional_param('id', 0, PARAM_INT); // This are required.
42 $selectall = optional_param('selectall', false, PARAM_BOOL); // When rendering checkboxes against users mark them all checked.
44 $PAGE->set_url('/user/index.php', array(
46 'perpage' => $perpage,
47 'accesssince' => $accesssince,
50 'contextid' => $contextid,
54 $context = context::instance_by_id($contextid, MUST_EXIST);
55 if ($context->contextlevel != CONTEXT_COURSE) {
56 print_error('invalidcontext');
58 $course = $DB->get_record('course', array('id' => $context->instanceid), '*', MUST_EXIST);
60 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
61 $context = context_course::instance($course->id, MUST_EXIST);
63 // Not needed anymore.
67 require_login($course);
69 $systemcontext = context_system::instance();
70 $isfrontpage = ($course->id == SITEID);
72 $frontpagectx = context_course::instance(SITEID);
75 $PAGE->set_pagelayout('admin');
76 require_capability('moodle/site:viewparticipants', $systemcontext);
78 $PAGE->set_pagelayout('incourse');
79 require_capability('moodle/course:viewparticipants', $context);
82 $rolenamesurl = new moodle_url("$CFG->wwwroot/user/index.php?contextid=$context->id&sifirst=&silast=");
84 $rolenames = role_fix_names(get_profile_roles($context), $context, ROLENAME_ALIAS, true);
86 $rolenames[0] = get_string('allsiteusers', 'role');
88 $rolenames[0] = get_string('allparticipants');
91 // Make sure other roles may not be selected by any means.
92 if (empty($rolenames[$roleid])) {
93 print_error('noparticipants');
96 // No roles to display yet?
97 // frontpage course is an exception, on the front page course we should display all users.
98 if (empty($rolenames) && !$isfrontpage) {
99 if (has_capability('moodle/role:assign', $context)) {
100 redirect($CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id);
102 print_error('noparticipants');
107 user_list_view($course, $context);
109 $bulkoperations = has_capability('moodle/course:bulkmessaging', $context);
111 $countries = get_string_manager()->get_list_of_countries();
113 $strnever = get_string('never');
115 $datestring = new stdClass();
116 $datestring->year = get_string('year');
117 $datestring->years = get_string('years');
118 $datestring->day = get_string('day');
119 $datestring->days = get_string('days');
120 $datestring->hour = get_string('hour');
121 $datestring->hours = get_string('hours');
122 $datestring->min = get_string('min');
123 $datestring->mins = get_string('mins');
124 $datestring->sec = get_string('sec');
125 $datestring->secs = get_string('secs');
127 // Check to see if groups are being used in this course
128 // and if so, set $currentgroup to reflect the current group.
130 $groupmode = groups_get_course_groupmode($course); // Groups are being used.
131 $currentgroup = groups_get_course_group($course, true);
133 if (!$currentgroup) { // To make some other functions work better later.
134 $currentgroup = null;
137 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context));
139 $PAGE->set_title("$course->shortname: ".get_string('participants'));
140 $PAGE->set_heading($course->fullname);
141 $PAGE->set_pagetype('course-view-' . $course->format);
142 $PAGE->add_body_class('path-user'); // So we can style it independently.
143 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
145 echo $OUTPUT->header();
146 echo $OUTPUT->heading(get_string('participants'));
148 echo '<div class="userlist">';
150 if ($isseparategroups and (!$currentgroup) ) {
151 // The user is not in the group so show message and exit.
152 echo $OUTPUT->heading(get_string("notingroup"));
153 echo $OUTPUT->footer();
158 // Should use this variable so that we don't break stuff every time a variable is added or changed.
159 $baseurl = new moodle_url('/user/index.php', array(
160 'contextid' => $context->id,
163 'perpage' => $perpage,
164 'accesssince' => $accesssince,
165 'search' => s($search)));
168 if ($course->id == SITEID) {
169 $filtertype = 'site';
170 } else if ($course->id && !$currentgroup) {
171 $filtertype = 'course';
172 $filterselect = $course->id;
174 $filtertype = 'group';
175 $filterselect = $currentgroup;
180 // Get the hidden field list.
181 if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
182 $hiddenfields = array(); // Teachers and admins are allowed to see everything.
184 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
187 if (isset($hiddenfields['lastaccess'])) {
188 // Do not allow access since filtering.
192 // Print settings and things in a table across the top.
193 $controlstable = new html_table();
194 $controlstable->attributes['class'] = 'controls';
195 $controlstable->cellspacing = 0;
196 $controlstable->data[] = new html_table_row();
198 if ($groupmenu = groups_print_course_menu($course, $baseurl->out(), true)) {
199 $controlstable->data[0]->cells[] = $groupmenu;
202 if (!isset($hiddenfields['lastaccess'])) {
203 // Get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
204 // We need to make it diferently for normal courses and site course.
206 $minlastaccess = $DB->get_field_sql('SELECT min(timeaccess)
207 FROM {user_lastaccess}
209 AND timeaccess != 0', array($course->id));
210 $lastaccess0exists = $DB->record_exists('user_lastaccess', array('courseid' => $course->id, 'timeaccess' => 0));
212 $minlastaccess = $DB->get_field_sql('SELECT min(lastaccess)
214 WHERE lastaccess != 0');
215 $lastaccess0exists = $DB->record_exists('user', array('lastaccess' => 0));
218 $now = usergetmidnight(time());
219 $timeaccess = array();
220 $baseurl->remove_params('accesssince');
222 // Makes sense for this to go first.
223 $timeoptions[0] = get_string('selectperiod');
226 for ($i = 1; $i < 7; $i++) {
227 if (strtotime('-'.$i.' days', $now) >= $minlastaccess) {
228 $timeoptions[strtotime('-'.$i.' days', $now)] = get_string('numdays', 'moodle', $i);
232 for ($i = 1; $i < 10; $i++) {
233 if (strtotime('-'.$i.' weeks', $now) >= $minlastaccess) {
234 $timeoptions[strtotime('-'.$i.' weeks', $now)] = get_string('numweeks', 'moodle', $i);
238 for ($i = 2; $i < 12; $i++) {
239 if (strtotime('-'.$i.' months', $now) >= $minlastaccess) {
240 $timeoptions[strtotime('-'.$i.' months', $now)] = get_string('nummonths', 'moodle', $i);
244 if (strtotime('-1 year', $now) >= $minlastaccess) {
245 $timeoptions[strtotime('-1 year', $now)] = get_string('lastyear');
248 if (!empty($lastaccess0exists)) {
249 $timeoptions[-1] = get_string('never');
252 if (count($timeoptions) > 1) {
253 $select = new single_select($baseurl, 'accesssince', $timeoptions, $accesssince, null, 'timeoptions');
254 $select->set_label(get_string('usersnoaccesssince'));
255 $controlstable->data[0]->cells[] = $OUTPUT->render($select);
259 echo html_writer::table($controlstable);
261 if ($currentgroup and (!$isseparategroups or has_capability('moodle/site:accessallgroups', $context))) {
262 // Display info about the group.
263 if ($group = groups_get_group($currentgroup)) {
264 if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) {
265 $groupinfotable = new html_table();
266 $groupinfotable->attributes['class'] = 'groupinfobox';
267 $picturecell = new html_table_cell();
268 $picturecell->attributes['class'] = 'left side picture';
269 $picturecell->text = print_group_picture($group, $course->id, true, true, false);
271 $contentcell = new html_table_cell();
272 $contentcell->attributes['class'] = 'content';
274 $contentheading = $group->name;
275 if (has_capability('moodle/course:managegroups', $context)) {
276 $aurl = new moodle_url('/group/group.php', array('id' => $group->id, 'courseid' => $group->courseid));
277 $contentheading .= ' ' . $OUTPUT->action_icon($aurl, new pix_icon('t/edit', get_string('editgroupprofile')));
280 $group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'group',
281 'description', $group->id);
282 if (!isset($group->descriptionformat)) {
283 $group->descriptionformat = FORMAT_MOODLE;
285 $options = array('overflowdiv' => true);
286 $formatteddesc = format_text($group->description, $group->descriptionformat, $options);
287 $contentcell->text = $OUTPUT->heading($contentheading, 3) . $formatteddesc;
288 $groupinfotable->data[] = new html_table_row(array($picturecell, $contentcell));
289 echo html_writer::table($groupinfotable);
294 // Define a table showing a list of users in the current role selection.
295 $tablecolumns = array();
296 $tableheaders = array();
297 if ($bulkoperations) {
298 $tablecolumns[] = 'select';
299 $tableheaders[] = get_string('select');
301 $tablecolumns[] = 'userpic';
302 $tablecolumns[] = 'fullname';
304 $extrafields = get_extra_user_fields($context);
305 $tableheaders[] = get_string('userpic');
306 $tableheaders[] = get_string('fullnameuser');
309 foreach ($extrafields as $field) {
310 $tablecolumns[] = $field;
311 $tableheaders[] = get_user_field_name($field);
313 if (!isset($hiddenfields['city'])) {
314 $tablecolumns[] = 'city';
315 $tableheaders[] = get_string('city');
317 if (!isset($hiddenfields['country'])) {
318 $tablecolumns[] = 'country';
319 $tableheaders[] = get_string('country');
321 if (!isset($hiddenfields['lastaccess'])) {
322 $tablecolumns[] = 'lastaccess';
323 if ($course->id == SITEID) {
324 // Exception case for viewing participants on site home.
325 $tableheaders[] = get_string('lastsiteaccess');
327 $tableheaders[] = get_string('lastcourseaccess');
331 $table = new flexible_table('user-index-participants-'.$course->id);
332 $table->define_columns($tablecolumns);
333 $table->define_headers($tableheaders);
334 $table->define_baseurl($baseurl->out());
336 if (!isset($hiddenfields['lastaccess'])) {
337 $table->sortable(true, 'lastaccess', SORT_DESC);
339 $table->sortable(true, 'firstname', SORT_ASC);
342 $table->no_sorting('roles');
343 $table->no_sorting('groups');
344 $table->no_sorting('groupings');
345 $table->no_sorting('select');
347 $table->set_attribute('cellspacing', '0');
348 $table->set_attribute('id', 'participants');
349 $table->set_attribute('class', 'generaltable generalbox');
351 $table->set_control_variables(array(
352 TABLE_VAR_SORT => 'ssort',
353 TABLE_VAR_HIDE => 'shide',
354 TABLE_VAR_SHOW => 'sshow',
355 TABLE_VAR_IFIRST => 'sifirst',
356 TABLE_VAR_ILAST => 'silast',
357 TABLE_VAR_PAGE => 'spage'
361 list($esql, $params) = get_enrolled_sql($context, null, $currentgroup, true);
362 $joins = array("FROM {user} u");
365 $userfields = array('username', 'email', 'city', 'country', 'lang', 'timezone', 'maildisplay');
366 $mainuserfields = user_picture::fields('u', $userfields);
367 $extrasql = get_extra_user_fields_sql($context, 'u', '', $userfields);
370 $select = "SELECT $mainuserfields, u.lastaccess$extrasql";
371 $joins[] = "JOIN ($esql) e ON e.id = u.id"; // Everybody on the frontpage usually.
373 $wheres[] = get_user_lastaccess_sql($accesssince);
377 $select = "SELECT $mainuserfields, COALESCE(ul.timeaccess, 0) AS lastaccess$extrasql";
378 $joins[] = "JOIN ($esql) e ON e.id = u.id"; // Course enrolled users only.
379 $joins[] = "LEFT JOIN {user_lastaccess} ul ON (ul.userid = u.id AND ul.courseid = :courseid)"; // Not everybody accessed course yet.
380 $params['courseid'] = $course->id;
382 $wheres[] = get_course_lastaccess_sql($accesssince);
386 // Performance hacks - we preload user contexts together with accounts.
387 $ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
388 $ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
389 $params['contextlevel'] = CONTEXT_USER;
390 $select .= $ccselect;
394 // Limit list to users with some role only.
396 // We want to query both the current context and parent contexts.
397 list($relatedctxsql, $relatedctxparams) = $DB->get_in_or_equal($context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'relatedctx');
399 $wheres[] = "u.id IN (SELECT userid FROM {role_assignments} WHERE roleid = :roleid AND contextid $relatedctxsql)";
400 $params = array_merge($params, array('roleid' => $roleid), $relatedctxparams);
403 $from = implode("\n", $joins);
405 $where = "WHERE " . implode(" AND ", $wheres);
410 $totalcount = $DB->count_records_sql("SELECT COUNT(u.id) $from $where", $params);
412 if (!empty($search)) {
413 $fullname = $DB->sql_fullname('u.firstname', 'u.lastname');
414 $wheres[] = "(". $DB->sql_like($fullname, ':search1', false, false) .
415 " OR ". $DB->sql_like('email', ':search2', false, false) .
416 " OR ". $DB->sql_like('idnumber', ':search3', false, false) .") ";
417 $params['search1'] = "%$search%";
418 $params['search2'] = "%$search%";
419 $params['search3'] = "%$search%";
422 list($twhere, $tparams) = $table->get_sql_where();
425 $params = array_merge($params, $tparams);
428 $from = implode("\n", $joins);
430 $where = "WHERE " . implode(" AND ", $wheres);
435 if ($table->get_sql_sort()) {
436 $sort = ' ORDER BY '.$table->get_sql_sort();
441 $matchcount = $DB->count_records_sql("SELECT COUNT(u.id) $from $where", $params);
443 $table->initialbars(true);
444 $table->pagesize($perpage, $matchcount);
446 // List of users at the current visible page - paging makes it relatively short.
447 $userlist = $DB->get_recordset_sql("$select $from $where $sort", $params, $table->get_page_start(), $table->get_page_size());
449 // If there are multiple Roles in the course, then show a drop down menu for switching.
450 if (count($rolenames) > 1) {
451 echo '<div class="rolesform">';
452 echo $OUTPUT->single_select($rolenamesurl, 'roleid', $rolenames, $roleid, null,
453 'rolesform', array('label' => get_string('currentrole', 'role')));
456 } else if (count($rolenames) == 1) {
457 // When all users with the same role - print its name.
458 echo '<div class="rolesform">';
459 echo get_string('role').get_string('labelsep', 'langconfig');
460 $rolename = reset($rolenames);
466 if ($course->id != SITEID && has_capability('moodle/course:enrolreview', $context)) {
467 $editlink = new moodle_url('/enrol/users.php', array('id' => $course->id));
472 $a->number = $totalcount;
473 $a->role = $rolenames[$roleid];
474 $heading = format_string(get_string('xuserswiththerole', 'role', $a));
476 if ($currentgroup and !empty($group)) {
477 $a->group = $group->name;
478 $heading .= ' ' . format_string(get_string('ingroup', 'role', $a));
481 if ($accesssince && !empty($timeoptions[$accesssince])) {
482 $a->timeperiod = $timeoptions[$accesssince];
483 $heading .= ' ' . format_string(get_string('inactiveformorethan', 'role', $a));
486 $heading .= ": $a->number";
488 if (!empty($editlink)) {
489 $editlink->param('role', $roleid);
490 $heading .= $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit')));
492 echo $OUTPUT->heading($heading, 3);
494 if ($course->id == SITEID and $roleid < 0) {
495 $strallparticipants = get_string('allsiteusers', 'role');
497 $strallparticipants = get_string('allparticipants');
500 if (!empty($editlink)) {
501 $editlink = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit')));
504 if ($matchcount < $totalcount) {
505 echo $OUTPUT->heading($strallparticipants.get_string('labelsep', 'langconfig').$matchcount.'/'.$totalcount . $editlink, 3);
507 echo $OUTPUT->heading($strallparticipants.get_string('labelsep', 'langconfig').$matchcount . $editlink, 3);
512 if ($bulkoperations) {
513 echo '<form action="action_redir.php" method="post" id="participantsform">';
515 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
516 echo '<input type="hidden" name="returnto" value="'.s($PAGE->url->out(false)).'" />';
519 $countrysort = (strpos($sort, 'country') !== false);
520 $timeformat = get_string('strftimedate');
524 $usersprinted = array();
525 foreach ($userlist as $user) {
526 if (in_array($user->id, $usersprinted)) { // Prevent duplicates by r.hidden - MDL-13935.
529 $usersprinted[] = $user->id; // Add new user to the array of users printed.
531 context_helper::preload_from_record($user);
533 if ($user->lastaccess) {
534 $lastaccess = format_time(time() - $user->lastaccess, $datestring);
536 $lastaccess = $strnever;
539 if (empty($user->country)) {
544 $country = '('.$user->country.') '.$countries[$user->country];
546 $country = $countries[$user->country];
550 $usercontext = context_user::instance($user->id);
552 if ($piclink = ($USER->id == $user->id || has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext))) {
553 $profilelink = '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user).'</a></strong>';
555 $profilelink = '<strong>'.fullname($user).'</strong>';
559 if ($bulkoperations) {
561 $checked = 'checked="true"';
565 $data[] = '<input type="checkbox" class="usercheckbox" name="user'.$user->id.'" ' . $checked .'/>';
567 $data[] = $OUTPUT->user_picture($user, array('size' => 35, 'courseid' => $course->id));
568 $data[] = $profilelink;
570 foreach ($extrafields as $field) {
571 $data[] = $user->{$field};
574 if (!isset($hiddenfields['city'])) {
575 $data[] = $user->city;
577 if (!isset($hiddenfields['country'])) {
580 if (!isset($hiddenfields['lastaccess'])) {
581 $data[] = $lastaccess;
584 $table->add_data($data);
588 $table->print_html();
590 $perpageurl = clone($baseurl);
591 $perpageurl->remove_params('perpage');
592 if ($perpage == SHOW_ALL_PAGE_SIZE) {
593 $perpageurl->param('perpage', DEFAULT_PAGE_SIZE);
594 echo $OUTPUT->container(html_writer::link($perpageurl, get_string('showperpage', '', DEFAULT_PAGE_SIZE)), array(), 'showall');
596 } else if ($matchcount > 0 && $perpage < $matchcount) {
597 $perpageurl->param('perpage', SHOW_ALL_PAGE_SIZE);
598 echo $OUTPUT->container(html_writer::link($perpageurl, get_string('showall', '', $matchcount)), array(), 'showall');
601 if ($bulkoperations) {
602 echo '<br /><div class="buttons">';
604 if ($matchcount > 0 && $perpage < $matchcount) {
605 $perpageurl = clone($baseurl);
606 $perpageurl->remove_params('perpage');
607 $perpageurl->param('perpage', SHOW_ALL_PAGE_SIZE);
608 $perpageurl->param('selectall', true);
609 $showalllink = $perpageurl;
611 $showalllink = false;
614 echo html_writer::start_tag('div', array('class' => 'btn-group'));
615 if ($perpage < $matchcount) {
616 // Select all users, refresh page showing all users and mark them all selected.
617 $label = get_string('selectalluserswithcount', 'moodle', $matchcount);
618 echo html_writer::tag('input', "", array('type' => 'button', 'id' => 'checkall', 'class' => 'btn btn-secondary',
619 'value' => $label, 'data-showallink' => $showalllink));
620 // Select all users, mark all users on page as selected.
621 echo html_writer::tag('input', "", array('type' => 'button', 'id' => 'checkallonpage', 'class' => 'btn btn-secondary',
622 'value' => get_string('selectallusersonpage')));
624 echo html_writer::tag('input', "", array('type' => 'button', 'id' => 'checkallonpage', 'class' => 'btn btn-secondary',
625 'value' => get_string('selectall')));
628 echo html_writer::tag('input', "", array('type' => 'button', 'id' => 'checknone', 'class' => 'btn btn-secondary',
629 'value' => get_string('deselectall')));
630 echo html_writer::end_tag('div');
631 $displaylist = array();
632 $displaylist['messageselect.php'] = get_string('messageselectadd');
633 if (!empty($CFG->enablenotes) && has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) {
634 $displaylist['addnote.php'] = get_string('addnewnote', 'notes');
635 $displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes');
638 echo $OUTPUT->help_icon('withselectedusers');
639 echo html_writer::tag('label', get_string("withselectedusers"), array('for' => 'formactionid'));
640 echo html_writer::select($displaylist, 'formaction', '', array('' => 'choosedots'), array('id' => 'formactionid'));
642 echo '<input type="hidden" name="id" value="'.$course->id.'" />';
643 echo '<noscript style="display:inline">';
644 echo '<div><input type="submit" value="'.get_string('ok').'" /></div>';
649 $module = array('name' => 'core_user', 'fullpath' => '/user/module.js');
650 $PAGE->requires->js_init_call('M.core_user.init_participation', null, false, $module);
653 // Show a search box if all participants don't fit on a single screen.
654 if ($totalcount > $perpage) {
655 echo '<form action="index.php" class="searchform"><div><input type="hidden" name="id" value="'.$course->id.'" />';
656 echo '<label for="search">' . get_string('search', 'search') . ' </label>';
657 echo '<input type="text" id="search" name="search" value="'.s($search).'" /> <input type="submit" value="'.get_string('search').'" /></div></form>'."\n";
660 echo '</div>'; // Userlist.
662 echo $OUTPUT->footer();
669 * Returns SQL that can be used to limit a query to a period where the user last accessed a course..
671 * @param string $accesssince
674 function get_course_lastaccess_sql($accesssince='') {
675 if (empty($accesssince)) {
678 if ($accesssince == -1) { // Never.
679 return 'ul.timeaccess = 0';
681 return 'ul.timeaccess != 0 AND ul.timeaccess < '.$accesssince;
686 * Returns SQL that can be used to limit a query to a period where the user last accessed the system.
688 * @param string $accesssince
691 function get_user_lastaccess_sql($accesssince='') {
692 if (empty($accesssince)) {
695 if ($accesssince == -1) { // Never.
696 return 'u.lastaccess = 0';
698 return 'u.lastaccess != 0 AND u.lastaccess < '.$accesssince;