3 // Lists all the users within a given course
5 require_once('../config.php');
6 require_once($CFG->libdir
.'/tablelib.php');
7 require_once($CFG->libdir
.'/filelib.php');
9 define('USER_SMALL_CLASS', 20); // Below this is considered small
10 define('USER_LARGE_CLASS', 200); // Above this is considered large
11 define('DEFAULT_PAGE_SIZE', 20);
12 define('SHOW_ALL_PAGE_SIZE', 5000);
13 define('MODE_BRIEF', 0);
14 define('MODE_USERDETAILS', 1);
16 $page = optional_param('page', 0, PARAM_INT
); // which page to show
17 $perpage = optional_param('perpage', DEFAULT_PAGE_SIZE
, PARAM_INT
); // how many per page
18 $mode = optional_param('mode', NULL, PARAM_INT
); // use the MODE_ constants
19 $accesssince = optional_param('accesssince',0,PARAM_INT
); // filter by last access. -1 = never
20 $search = optional_param('search','',PARAM_RAW
); // make sure it is processed with p() or s() when sending to output!
21 $roleid = optional_param('roleid', 0, PARAM_INT
); // optional roleid, 0 means all enrolled users (or all on the frontpage)
23 $contextid = optional_param('contextid', 0, PARAM_INT
); // one of this or
24 $courseid = optional_param('id', 0, PARAM_INT
); // this are required
26 $PAGE->set_url('/user/index.php', array(
28 'perpage' => $perpage,
30 'accesssince' => $accesssince,
33 'contextid' => $contextid,
34 'courseid' => $courseid));
37 $context = get_context_instance_by_id($contextid, MUST_EXIST
);
38 if ($context->contextlevel
!= CONTEXT_COURSE
) {
39 print_error('invalidcontext');
41 $course = $DB->get_record('course', array('id'=>$context->instanceid
), '*', MUST_EXIST
);
43 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST
);
44 $context = get_context_instance(CONTEXT_COURSE
, $course->id
, MUST_EXIST
);
50 require_login($course);
52 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
53 $isfrontpage = ($course->id
== SITEID
);
55 $frontpagectx = get_context_instance(CONTEXT_COURSE
, SITEID
);
58 $PAGE->set_pagelayout('admin');
59 require_capability('moodle/site:viewparticipants', $systemcontext);
61 $PAGE->set_pagelayout('incourse');
62 require_capability('moodle/course:viewparticipants', $context);
65 $rolenamesurl = new moodle_url("$CFG->wwwroot/user/index.php?contextid=$context->id&sifirst=&silast=");
67 $allroles = get_all_roles();
68 $roles = get_profile_roles($context);
69 $allrolenames = array();
71 $rolenames = array(0=>get_string('allsiteusers', 'role'));
73 $rolenames = array(0=>get_string('allparticipants'));
76 foreach ($allroles as $role) {
77 $allrolenames[$role->id
] = strip_tags(role_get_name($role, $context)); // Used in menus etc later on
78 if (isset($roles[$role->id
])) {
79 $rolenames[$role->id
] = $allrolenames[$role->id
];
83 // make sure other roles may not be selected by any means
84 if (empty($rolenames[$roleid])) {
85 print_error('noparticipants');
88 // no roles to display yet?
89 // frontpage course is an exception, on the front page course we should display all users
90 if (empty($rolenames) && !$isfrontpage) {
91 if (has_capability('moodle/role:assign', $context)) {
92 redirect($CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$context->id
);
94 print_error('noparticipants');
98 add_to_log($course->id
, 'user', 'view all', 'index.php?id='.$course->id
, '');
100 $bulkoperations = has_capability('moodle/course:bulkmessaging', $context);
102 $countries = get_string_manager()->get_list_of_countries();
104 $strnever = get_string('never');
106 $datestring->year
= get_string('year');
107 $datestring->years
= get_string('years');
108 $datestring->day
= get_string('day');
109 $datestring->days
= get_string('days');
110 $datestring->hour
= get_string('hour');
111 $datestring->hours
= get_string('hours');
112 $datestring->min
= get_string('min');
113 $datestring->mins
= get_string('mins');
114 $datestring->sec
= get_string('sec');
115 $datestring->secs
= get_string('secs');
117 if ($mode !== NULL) {
119 $SESSION->userindexmode
= $mode;
120 } else if (isset($SESSION->userindexmode
)) {
121 $mode = (int)$SESSION->userindexmode
;
126 /// Check to see if groups are being used in this course
127 /// and if so, set $currentgroup to reflect the current group
129 $groupmode = groups_get_course_groupmode($course); // Groups are being used
130 $currentgroup = groups_get_course_group($course, true);
132 if (!$currentgroup) { // To make some other functions work better later
133 $currentgroup = NULL;
136 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $context));
138 if ($course->id
===SITEID
) {
139 $PAGE->navbar
->ignore_active();
142 $PAGE->navbar
->add(get_string('participants'));
143 $PAGE->set_title("$course->shortname: ".get_string('participants'));
144 $PAGE->set_heading($course->fullname
);
145 $PAGE->set_pagetype('course-view-' . $course->format
);
146 $PAGE->add_body_class('path-user'); // So we can style it independently
147 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
149 echo $OUTPUT->header();
151 echo '<div class="userlist">';
153 if ($isseparategroups and (!$currentgroup) ) {
154 // The user is not in the group so show message and exit
155 echo $OUTPUT->heading(get_string("notingroup"));
156 echo $OUTPUT->footer();
161 // Should use this variable so that we don't break stuff every time a variable is added or changed.
162 $baseurl = new moodle_url('/user/index.php', array(
163 'contextid' => $context->id
,
166 'perpage' => $perpage,
167 'accesssince' => $accesssince,
168 'search' => s($search)));
171 if ($course->id
== SITEID
) {
172 $filtertype = 'site';
173 } else if ($course->id
&& !$currentgroup) {
174 $filtertype = 'course';
175 $filterselect = $course->id
;
177 $filtertype = 'group';
178 $filterselect = $currentgroup;
183 /// Get the hidden field list
184 if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
185 $hiddenfields = array(); // teachers and admins are allowed to see everything
187 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
190 if (isset($hiddenfields['lastaccess'])) {
191 // do not allow access since filtering
195 /// Print settings and things in a table across the top
196 $controlstable = new html_table();
197 $controlstable->attributes
['class'] = 'controls';
198 $controlstable->cellspacing
= 0;
199 $controlstable->data
[] = new html_table_row();
201 /// Print my course menus
202 if ($mycourses = enrol_get_my_courses()) {
203 $courselist = array();
204 $popupurl = new moodle_url('/user/index.php?roleid='.$roleid.'&sifirst=&silast=');
205 foreach ($mycourses as $mycourse) {
206 $courselist[$mycourse->id
] = format_string($mycourse->shortname
);
208 if (has_capability('moodle/site:viewparticipants', $systemcontext)) {
209 unset($courselist[SITEID
]);
210 $courselist = array(SITEID
=> format_string($SITE->shortname
)) +
$courselist;
212 $select = new single_select($popupurl, 'id', $courselist, $course->id
, array(''=>'choosedots'), 'courseform');
213 $select->set_label(get_string('mycourses'));
214 $controlstable->data
[0]->cells
[] = $OUTPUT->render($select);
217 $controlstable->data
[0]->cells
[] = groups_print_course_menu($course, $baseurl->out(), true);
219 if (!isset($hiddenfields['lastaccess'])) {
220 // get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
221 // we need to make it diferently for normal courses and site course
223 $minlastaccess = $DB->get_field_sql('SELECT min(timeaccess)
224 FROM {user_lastaccess}
226 AND timeaccess != 0', array($course->id
));
227 $lastaccess0exists = $DB->record_exists('user_lastaccess', array('courseid'=>$course->id
, 'timeaccess'=>0));
229 $minlastaccess = $DB->get_field_sql('SELECT min(lastaccess)
231 WHERE lastaccess != 0');
232 $lastaccess0exists = $DB->record_exists('user', array('lastaccess'=>0));
235 $now = usergetmidnight(time());
236 $timeaccess = array();
237 $baseurl->remove_params('accesssince');
239 // makes sense for this to go first.
240 $timeoptions[0] = get_string('selectperiod');
243 for ($i = 1; $i < 7; $i++
) {
244 if (strtotime('-'.$i.' days',$now) >= $minlastaccess) {
245 $timeoptions[strtotime('-'.$i.' days',$now)] = get_string('numdays','moodle',$i);
249 for ($i = 1; $i < 10; $i++
) {
250 if (strtotime('-'.$i.' weeks',$now) >= $minlastaccess) {
251 $timeoptions[strtotime('-'.$i.' weeks',$now)] = get_string('numweeks','moodle',$i);
255 for ($i = 2; $i < 12; $i++
) {
256 if (strtotime('-'.$i.' months',$now) >= $minlastaccess) {
257 $timeoptions[strtotime('-'.$i.' months',$now)] = get_string('nummonths','moodle',$i);
261 if (strtotime('-1 year',$now) >= $minlastaccess) {
262 $timeoptions[strtotime('-1 year',$now)] = get_string('lastyear');
265 if (!empty($lastaccess0exists)) {
266 $timeoptions[-1] = get_string('never');
269 if (count($timeoptions) > 1) {
270 $select = new single_select($baseurl, 'accesssince', $timeoptions, $accesssince, null, 'timeoptions');
271 $select->set_label(get_string('usersnoaccesssince'));
272 $controlstable->data
[0]->cells
[] = $OUTPUT->render($select);
276 $formatmenu = array( '0' => get_string('brief'),
277 '1' => get_string('userdetails'));
278 $select = new single_select($baseurl, 'mode', $formatmenu, $mode, null, 'formatmenu');
279 $select->set_label(get_string('userlist'));
280 $userlistcell = new html_table_cell();
281 $userlistcell->attributes
['class'] = 'right';
282 $userlistcell->text
= $OUTPUT->render($select);
283 $controlstable->data
[0]->cells
[] = $userlistcell;
285 echo html_writer
::table($controlstable);
287 if ($currentgroup and (!$isseparategroups or has_capability('moodle/site:accessallgroups', $context))) { /// Display info about the group
288 if ($group = groups_get_group($currentgroup)) {
289 if (!empty($group->description
) or (!empty($group->picture
) and empty($group->hidepicture
))) {
290 $groupinfotable = new html_table();
291 $groupinfotable->attributes
['class'] = 'groupinfobox';
292 $picturecell = new html_table_cell();
293 $picturecell->attributes
['class'] = 'left side picture';
294 $picturecell->text
= print_group_picture($group, $course->id
, true, true, false);
296 $contentcell = new html_table_cell();
297 $contentcell->attributes
['class'] = 'content';
299 $contentheading = $group->name
;
300 if (has_capability('moodle/course:managegroups', $context)) {
301 $aurl = new moodle_url('/group/group.php', array('id' => $group->id
, 'courseid' => $group->courseid
));
302 $contentheading .= ' ' . $OUTPUT->action_icon($aurl, new pix_icon('t/edit', get_string('editgroupprofile')));
305 $group->description
= file_rewrite_pluginfile_urls($group->description
, 'pluginfile.php', $context->id
, 'group', 'description', $group->id
);
306 if (!isset($group->descriptionformat
)) {
307 $group->descriptionformat
= FORMAT_MOODLE
;
309 $options = array('overflowdiv'=>true);
310 $contentcell->text
= $OUTPUT->heading($contentheading, 3) . format_text($group->description
, $group->descriptionformat
, $options);
311 $groupinfotable->data
[] = new html_table_row(array($picturecell, $contentcell));
312 echo html_writer
::table($groupinfotable);
317 /// Define a table showing a list of users in the current role selection
319 $tablecolumns = array('userpic', 'fullname');
320 $tableheaders = array(get_string('userpic'), get_string('fullnameuser'));
321 if ($mode === MODE_BRIEF
&& !isset($hiddenfields['city'])) {
322 $tablecolumns[] = 'city';
323 $tableheaders[] = get_string('city');
325 if ($mode === MODE_BRIEF
&& !isset($hiddenfields['country'])) {
326 $tablecolumns[] = 'country';
327 $tableheaders[] = get_string('country');
329 if (!isset($hiddenfields['lastaccess'])) {
330 $tablecolumns[] = 'lastaccess';
331 $tableheaders[] = get_string('lastaccess');
334 if ($bulkoperations) {
335 $tablecolumns[] = 'select';
336 $tableheaders[] = get_string('select');
339 $table = new flexible_table('user-index-participants-'.$course->id
);
341 $table->define_columns($tablecolumns);
342 $table->define_headers($tableheaders);
343 $table->define_baseurl($baseurl->out());
345 if (!isset($hiddenfields['lastaccess'])) {
346 $table->sortable(true, 'lastaccess', SORT_DESC
);
349 $table->no_sorting('roles');
350 $table->no_sorting('groups');
351 $table->no_sorting('groupings');
352 $table->no_sorting('select');
354 $table->set_attribute('cellspacing', '0');
355 $table->set_attribute('id', 'participants');
356 $table->set_attribute('class', 'generaltable generalbox');
358 $table->set_control_variables(array(
359 TABLE_VAR_SORT
=> 'ssort',
360 TABLE_VAR_HIDE
=> 'shide',
361 TABLE_VAR_SHOW
=> 'sshow',
362 TABLE_VAR_IFIRST
=> 'sifirst',
363 TABLE_VAR_ILAST
=> 'silast',
364 TABLE_VAR_PAGE
=> 'spage'
368 // we are looking for all users with this role assigned in this context or higher
369 $contextlist = get_related_contexts_string($context);
371 list($esql, $params) = get_enrolled_sql($context, NULL, $currentgroup, true);
372 $joins = array("FROM {user} u");
376 $select = "SELECT u.id, u.username, u.firstname, u.lastname,
377 u.email, u.city, u.country, u.picture,
378 u.lang, u.timezone, u.maildisplay, u.imagealt,
380 $joins[] = "JOIN ($esql) e ON e.id = u.id"; // everybody on the frontpage usually
382 $wheres[] = get_user_lastaccess_sql($accesssince);
386 $select = "SELECT u.id, u.username, u.firstname, u.lastname,
387 u.email, u.city, u.country, u.picture,
388 u.lang, u.timezone, u.maildisplay, u.imagealt,
389 COALESCE(ul.timeaccess, 0) AS lastaccess";
390 $joins[] = "JOIN ($esql) e ON e.id = u.id"; // course enrolled users only
391 $joins[] = "LEFT JOIN {user_lastaccess} ul ON (ul.userid = u.id AND ul.courseid = :courseid)"; // not everybody accessed course yet
392 $params['courseid'] = $course->id
;
394 $wheres[] = get_course_lastaccess_sql($accesssince);
398 // performance hacks - we preload user contexts together with accounts
399 list($ccselect, $ccjoin) = context_instance_preload_sql('u.id', CONTEXT_USER
, 'ctx');
400 $select .= $ccselect;
404 // limit list to users with some role only
406 $wheres[] = "u.id IN (SELECT userid FROM {role_assignments} WHERE roleid = :roleid AND contextid $contextlist)";
407 $params['roleid'] = $roleid;
410 $from = implode("\n", $joins);
412 $where = "WHERE " . implode(" AND ", $wheres);
417 $totalcount = $DB->count_records_sql("SELECT COUNT(u.id) $from $where", $params);
419 if (!empty($search)) {
420 $fullname = $DB->sql_fullname('u.firstname','u.lastname');
421 $wheres[] = "(". $DB->sql_like($fullname, ':search1', false, false) .
422 " OR ". $DB->sql_like('email', ':search2', false, false) .
423 " OR ". $DB->sql_like('idnumber', ':search3', false, false) .") ";
424 $params['search1'] = "%$search%";
425 $params['search2'] = "%$search%";
426 $params['search3'] = "%$search%";
429 list($twhere, $tparams) = $table->get_sql_where();
432 $params = array_merge($params, $tparams);
435 $from = implode("\n", $joins);
437 $where = "WHERE " . implode(" AND ", $wheres);
442 if ($table->get_sql_sort()) {
443 $sort = ' ORDER BY '.$table->get_sql_sort();
448 $matchcount = $DB->count_records_sql("SELECT COUNT(u.id) $from $where", $params);
450 $table->initialbars(true);
451 $table->pagesize($perpage, $matchcount);
453 // list of users at the current visible page - paging makes it relatively short
454 $userlist = $DB->get_recordset_sql("$select $from $where $sort", $params, $table->get_page_start(), $table->get_page_size());
456 /// If there are multiple Roles in the course, then show a drop down menu for switching
457 if (count($rolenames) > 1) {
458 echo '<div class="rolesform">';
459 echo '<label for="rolesform_jump">'.get_string('currentrole', 'role').' </label>';
460 echo $OUTPUT->single_select($rolenamesurl, 'roleid', $rolenames, $roleid, null, 'rolesform');
463 } else if (count($rolenames) == 1) {
464 // when all users with the same role - print its name
465 echo '<div class="rolesform">';
466 echo get_string('role').get_string('labelsep', 'langconfig');
467 $rolename = reset($rolenames);
473 $a->number
= $totalcount;
474 $a->role
= $rolenames[$roleid];
475 $heading = format_string(get_string('xuserswiththerole', 'role', $a));
477 if ($currentgroup and $group) {
478 $a->group
= $group->name
;
479 $heading .= ' ' . format_string(get_string('ingroup', 'role', $a));
483 $a->timeperiod
= $timeoptions[$accesssince];
484 $heading .= ' ' . format_string(get_string('inactiveformorethan', 'role', $a));
487 $heading .= ": $a->number";
488 if (user_can_assign($context, $roleid)) {
489 $heading .= ' <a href="'.$CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?roleid='.$roleid.'&contextid='.$context->id
.'">';
490 $heading .= '<img src="'.$OUTPUT->pix_url('i/edit') . '" class="icon" alt="" /></a>';
492 echo $OUTPUT->heading($heading, 3);
494 if ($course->id
!= SITEID
&& has_capability('moodle/course:enrolreview', $context)) {
495 $editlink = $OUTPUT->action_icon(new moodle_url('/enrol/users.php', array('id' => $course->id
)),
496 new pix_icon('i/edit', get_string('edit')));
500 if ($course->id
== SITEID
and $roleid < 0) {
501 $strallparticipants = get_string('allsiteusers', 'role');
503 $strallparticipants = get_string('allparticipants');
505 if ($matchcount < $totalcount) {
506 echo $OUTPUT->heading($strallparticipants.get_string('labelsep', 'langconfig').$matchcount.'/'.$totalcount . $editlink, 3);
508 echo $OUTPUT->heading($strallparticipants.get_string('labelsep', 'langconfig').$matchcount . $editlink, 3);
513 if ($bulkoperations) {
514 echo '<form action="action_redir.php" method="post" id="participantsform">';
516 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
517 echo '<input type="hidden" name="returnto" value="'.s(me()).'" />';
520 if ($mode === MODE_USERDETAILS
) { // Print simple listing
521 if ($totalcount < 1) {
522 echo $OUTPUT->heading(get_string('nothingtodisplay'));
524 if ($totalcount > $perpage) {
526 $firstinitial = $table->get_initial_first();
527 $lastinitial = $table->get_initial_last();
528 $strall = get_string('all');
529 $alpha = explode(',', get_string('alphabet', 'langconfig'));
531 // Bar of first initials
533 echo '<div class="initialbar firstinitial">'.get_string('firstname').' : ';
534 if(!empty($firstinitial)) {
535 echo '<a href="'.$baseurl->out().'&sifirst=">'.$strall.'</a>';
537 echo '<strong>'.$strall.'</strong>';
539 foreach ($alpha as $letter) {
540 if ($letter == $firstinitial) {
541 echo ' <strong>'.$letter.'</strong>';
543 echo ' <a href="'.$baseurl->out().'&sifirst='.$letter.'">'.$letter.'</a>';
548 // Bar of last initials
550 echo '<div class="initialbar lastinitial">'.get_string('lastname').' : ';
551 if(!empty($lastinitial)) {
552 echo '<a href="'.$baseurl->out().'&silast=">'.$strall.'</a>';
554 echo '<strong>'.$strall.'</strong>';
556 foreach ($alpha as $letter) {
557 if ($letter == $lastinitial) {
558 echo ' <strong>'.$letter.'</strong>';
560 echo ' <a href="'.$baseurl->out().'&silast='.$letter.'">'.$letter.'</a>';
565 $pagingbar = new paging_bar($matchcount, intval($table->get_page_start() / $perpage), $perpage, $baseurl);
566 $pagingbar->pagevar
= 'spage';
567 echo $OUTPUT->render($pagingbar);
570 if ($matchcount > 0) {
571 $usersprinted = array();
572 foreach ($userlist as $user) {
573 if (in_array($user->id
, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
576 $usersprinted[] = $user->id
; /// Add new user to the array of users printed
578 context_instance_preload($user);
580 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
581 $usercontext = get_context_instance(CONTEXT_USER
, $user->id
);
583 $countries = get_string_manager()->get_list_of_countries();
585 /// Get the hidden field list
586 if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
587 $hiddenfields = array();
589 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields
));
591 $table = new html_table();
592 $table->attributes
['class'] = 'userinfobox';
594 $row = new html_table_row();
595 $row->cells
[0] = new html_table_cell();
596 $row->cells
[0]->attributes
['class'] = 'left side';
598 $row->cells
[0]->text
= $OUTPUT->user_picture($user, array('size' => 100, 'courseid'=>$course->id
));
599 $row->cells
[1] = new html_table_cell();
600 $row->cells
[1]->attributes
['class'] = 'content';
602 $row->cells
[1]->text
= $OUTPUT->container(fullname($user, has_capability('moodle/site:viewfullnames', $context)), 'username');
603 $row->cells
[1]->text
.= $OUTPUT->container_start('info');
605 if (!empty($user->role
)) {
606 $row->cells
[1]->text
.= get_string('role').get_string('labelsep', 'langconfig').$user->role
.'<br />';
608 if ($user->maildisplay
== 1 or ($user->maildisplay
== 2 and ($course->id
!= SITEID
) and !isguestuser()) or
609 has_capability('moodle/course:viewhiddenuserfields', $context)) {
610 $row->cells
[1]->text
.= get_string('email').get_string('labelsep', 'langconfig').html_writer
::link("mailto:$user->email", $user->email
) . '<br />';
612 if (($user->city
or $user->country
) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
613 $row->cells
[1]->text
.= get_string('city').get_string('labelsep', 'langconfig');
614 if ($user->city
&& !isset($hiddenfields['city'])) {
615 $row->cells
[1]->text
.= $user->city
;
617 if (!empty($countries[$user->country
]) && !isset($hiddenfields['country'])) {
618 if ($user->city
&& !isset($hiddenfields['city'])) {
619 $row->cells
[1]->text
.= ', ';
621 $row->cells
[1]->text
.= $countries[$user->country
];
623 $row->cells
[1]->text
.= '<br />';
626 if (!isset($hiddenfields['lastaccess'])) {
627 if ($user->lastaccess
) {
628 $row->cells
[1]->text
.= get_string('lastaccess').get_string('labelsep', 'langconfig').userdate($user->lastaccess
);
629 $row->cells
[1]->text
.= ' ('. format_time(time() - $user->lastaccess
, $datestring) .')';
631 $row->cells
[1]->text
.= get_string('lastaccess').get_string('labelsep', 'langconfig').get_string('never');
635 $row->cells
[1]->text
.= $OUTPUT->container_end();
637 $row->cells
[2] = new html_table_cell();
638 $row->cells
[2]->attributes
['class'] = 'links';
639 $row->cells
[2]->text
= '';
643 if ($CFG->bloglevel
> 0) {
644 $links[] = html_writer
::link(new moodle_url('/blog/index.php?userid='.$user->id
), get_string('blogs','blog'));
647 if (!empty($CFG->enablenotes
) and (has_capability('moodle/notes:manage', $context) ||
has_capability('moodle/notes:view', $context))) {
648 $links[] = html_writer
::link(new moodle_url('/notes/index.php?course=' . $course->id
. '&user='.$user->id
), get_string('notes','notes'));
651 if (has_capability('moodle/site:viewreports', $context) or has_capability('moodle/user:viewuseractivitiesreport', $usercontext)) {
652 $links[] = html_writer
::link(new moodle_url('/course/user.php?id='. $course->id
.'&user='. $user->id
), get_string('activity'));
655 if ($USER->id
!= $user->id
&& !session_is_loggedinas() && has_capability('moodle/user:loginas', $context) && !is_siteadmin($user->id
)) {
656 $links[] = html_writer
::link(new moodle_url('/course/loginas.php?id='. $course->id
.'&user='. $user->id
.'&sesskey='. sesskey()), get_string('loginas'));
659 $links[] = html_writer
::link(new moodle_url('/user/view.php?id='. $user->id
.'&course='. $course->id
), get_string('fullprofile') . '...');
661 $row->cells
[2]->text
.= implode('', $links);
663 if (!empty($messageselect)) {
664 $row->cells
[2]->text
.= '<br /><input type="checkbox" name="user'.$user->id
.'" /> ';
666 $table->data
= array($row);
667 echo html_writer
::table($table);
671 echo $OUTPUT->heading(get_string('nothingtodisplay'));
676 $countrysort = (strpos($sort, 'country') !== false);
677 $timeformat = get_string('strftimedate');
682 $usersprinted = array();
683 foreach ($userlist as $user) {
684 if (in_array($user->id
, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
687 $usersprinted[] = $user->id
; /// Add new user to the array of users printed
689 context_instance_preload($user);
691 if ($user->lastaccess
) {
692 $lastaccess = format_time(time() - $user->lastaccess
, $datestring);
694 $lastaccess = $strnever;
697 if (empty($user->country
)) {
702 $country = '('.$user->country
.') '.$countries[$user->country
];
705 $country = $countries[$user->country
];
709 $usercontext = get_context_instance(CONTEXT_USER
, $user->id
);
711 if ($piclink = ($USER->id
== $user->id ||
has_capability('moodle/user:viewdetails', $context) ||
has_capability('moodle/user:viewdetails', $usercontext))) {
712 $profilelink = '<strong><a href="'.$CFG->wwwroot
.'/user/view.php?id='.$user->id
.'&course='.$course->id
.'">'.fullname($user).'</a></strong>';
714 $profilelink = '<strong>'.fullname($user).'</strong>';
717 $data = array ($OUTPUT->user_picture($user, array('size' => 35, 'courseid'=>$course->id
)), $profilelink);
719 if ($mode === MODE_BRIEF
&& !isset($hiddenfields['city'])) {
720 $data[] = $user->city
;
722 if ($mode === MODE_BRIEF
&& !isset($hiddenfields['country'])) {
725 if (!isset($hiddenfields['lastaccess'])) {
726 $data[] = $lastaccess;
729 if (isset($userlist_extra) && isset($userlist_extra[$user->id
])) {
730 $ras = $userlist_extra[$user->id
]['ra'];
732 foreach ($ras AS $key=>$ra) {
733 $rolename = $allrolenames[$ra['roleid']] ;
734 if ($ra['ctxlevel'] == CONTEXT_COURSECAT
) {
735 $rastring .= $rolename. ' @ ' . '<a href="'.$CFG->wwwroot
.'/course/category.php?id='.$ra['ctxinstanceid'].'">'.s($ra['ccname']).'</a>';
736 } elseif ($ra['ctxlevel'] == CONTEXT_SYSTEM
) {
737 $rastring .= $rolename. ' - ' . get_string('globalrole','role');
739 $rastring .= $rolename;
743 if ($groupmode != 0) {
744 // htmlescape with s() and implode the array
745 $data[] = implode(', ', array_map('s',$userlist_extra[$user->id
]['group']));
746 $data[] = implode(', ', array_map('s', $userlist_extra[$user->id
]['gping']));
750 if ($bulkoperations) {
751 $data[] = '<input type="checkbox" class="usercheckbox" name="user'.$user->id
.'" />';
753 $table->add_data($data);
758 $table->print_html();
762 if ($bulkoperations) {
763 echo '<br /><div class="buttons">';
764 echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> ';
765 echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> ';
766 $displaylist = array();
767 $displaylist['messageselect.php'] = get_string('messageselectadd');
768 if (!empty($CFG->enablenotes
) && has_capability('moodle/notes:manage', $context) && $context->id
!= $frontpagectx->id
) {
769 $displaylist['addnote.php'] = get_string('addnewnote', 'notes');
770 $displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes');
773 echo $OUTPUT->help_icon('withselectedusers');
774 echo html_writer
::tag('label', get_string("withselectedusers"), array('for'=>'formactionid'));
775 echo html_writer
::select($displaylist, 'formaction', '', array(''=>'choosedots'), array('id'=>'formactionid'));
777 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
778 echo '<noscript style="display:inline">';
779 echo '<div><input type="submit" value="'.get_string('ok').'" /></div>';
784 $module = array('name'=>'core_user', 'fullpath'=>'/user/module.js');
785 $PAGE->requires
->js_init_call('M.core_user.init_participation', null, false, $module);
788 if (has_capability('moodle/site:viewparticipants', $context) && $totalcount > ($perpage*3)) {
789 echo '<form action="index.php" class="searchform"><div><input type="hidden" name="id" value="'.$course->id
.'" />'.get_string('search').': '."\n";
790 echo '<input type="text" name="search" value="'.s($search).'" /> <input type="submit" value="'.get_string('search').'" /></div></form>'."\n";
793 $perpageurl = clone($baseurl);
794 $perpageurl->remove_params('perpage');
795 if ($perpage == SHOW_ALL_PAGE_SIZE
) {
796 $perpageurl->param('perpage', DEFAULT_PAGE_SIZE
);
797 echo $OUTPUT->container(html_writer
::link($perpageurl, get_string('showperpage', '', DEFAULT_PAGE_SIZE
)), array(), 'showall');
799 } else if ($matchcount > 0 && $perpage < $matchcount) {
800 $perpageurl->param('perpage', SHOW_ALL_PAGE_SIZE
);
801 echo $OUTPUT->container(html_writer
::link($perpageurl, get_string('showall', '', $matchcount)), array(), 'showall');
804 echo '</div>'; // userlist
806 echo $OUTPUT->footer();
813 function get_course_lastaccess_sql($accesssince='') {
814 if (empty($accesssince)) {
817 if ($accesssince == -1) { // never
818 return 'ul.timeaccess = 0';
820 return 'ul.timeaccess != 0 AND ul.timeaccess < '.$accesssince;
824 function get_user_lastaccess_sql($accesssince='') {
825 if (empty($accesssince)) {
828 if ($accesssince == -1) { // never
829 return 'u.lastaccess = 0';
831 return 'u.lastaccess != 0 AND u.lastaccess < '.$accesssince;