Cleaning up user index a bit
[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
ff3caf30 159/// Print settings and things in a table across the top
160
cc038b47 161 echo '<table class="controls" cellspacing="0"><tr>';
ff3caf30 162
a72784d3 163/// Print my course menus
7da0af9f 164 if ($mycourses = get_my_courses($USER->id)) {
165 echo '<td class="left">';
166 print_string('mycourses');
167 echo ': ';
1242eb8f 168
7da0af9f 169 $courselist = array();
170 foreach ($mycourses as $mycourse) {
171 $courselist[$mycourse->id] = $mycourse->shortname;
172 }
173 popup_form($CFG->wwwroot.'/user/index.php?contextid='.$context->id.'&amp;roleid='.$roleid.'&amp;id=',
174 $courselist, 'courseform',$course->id);
175 echo '</td>';
176 }
177
d02eeded 178 if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id)))) {
ff3caf30 179 if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
180 echo '<td class="left">';
cc038b47 181 print_group_menu($groups, $groupmode, $currentgroup, $baseurl);
ff3caf30 182 echo '</td>';
183 }
184 }
185
ca792680 186 if (!empty($isteacher)) {
187 // get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
17d6a25e 188 // this might not work anymore because you always going to get yourself as the most recent entry? added $USER!=$user ch
189 $minlastaccess = get_field_sql('SELECT min(timeaccess) FROM '.$CFG->prefix.'user_lastaccess WHERE courseid = '.$course->id.' AND timeaccess != 0 AND userid!='.$USER->id);
cbf0446d 190 $lastaccess0exists = record_exists('user_lastaccess','courseid',$course->id,'timeaccess',0);
ca792680 191 $now = usergetmidnight(time());
192 $timeaccess = array();
193
194 // makes sense for this to go first.
195 $timeoptions[0] = get_string('selectperiod');
196
197 // days
198 for ($i = 1; $i < 7; $i++) {
199 if (strtotime('-'.$i.' days',$now) >= $minlastaccess) {
200 $timeoptions[strtotime('-'.$i.' days',$now)] = get_string('numdays','moodle',$i);
201 }
31b71336 202 }
ca792680 203 // weeks
204 for ($i = 1; $i < 10; $i++) {
205 if (strtotime('-'.$i.' weeks',$now) >= $minlastaccess) {
206 $timeoptions[strtotime('-'.$i.' weeks',$now)] = get_string('numweeks','moodle',$i);
207 }
31b71336 208 }
ca792680 209 // months
210 for ($i = 2; $i < 12; $i++) {
211 if (strtotime('-'.$i.' months',$now) >= $minlastaccess) {
212 $timeoptions[strtotime('-'.$i.' months',$now)] = get_string('nummonths','moodle',$i);
213 }
214 }
215 // try a year
216 if (strtotime('-1 year',$now) >= $minlastaccess) {
217 $timeoptions[strtotime('-1 year',$now)] = get_string('lastyear');
218 }
219
220 if (!empty($lastaccess0exists)) {
221 $timeoptions[-1] = get_string('never');
222 }
223
224 if (count($timeoptions) > 1) {
225 echo '<td class="left">';
226 echo get_string('usersnoaccesssince').': ';
227 $baseurl = preg_replace('/&amp;accesssince='.$accesssince.'/','',$baseurl);
228 echo popup_form($baseurl.'&amp;accesssince=',$timeoptions,'timeoptions',$accesssince,'','','',true);
229 echo '</td>';
31b71336 230 }
31b71336 231 }
232
cc038b47 233 echo '<td class="right">';
4bc162b7 234 echo get_string('userlist').': ';
ff3caf30 235 $formatmenu = array( '0' => get_string('detailedless'),
236 '1' => get_string('detailedmore'));
cc038b47 237 echo popup_form($baseurl.'&amp;mode=', $formatmenu, 'formatmenu', $fullmode, '', '', '', true);
ff3caf30 238 echo '</td></tr></table>';
239
d02eeded 240 if ($currentgroup and (!$isseparategroups or has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id)))) { /// Display info about the group
ff3caf30 241 if ($group = get_record('groups', 'id', $currentgroup)) {
242 if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) {
243 echo '<table class="groupinfobox"><tr><td class="left side picture">';
244 print_group_picture($group, $course->id, true, false, false);
245 echo '</td><td class="content">';
246 echo '<h3>'.$group->name;
d02eeded 247 if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
2c27cd19 248 echo '&nbsp;<a title="'.get_string('editgroupprofile').'" href="../course/groups.php?id='.$course->id.'&amp;group='.$group->id.'">';
249 echo '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="" border="0">';
250 echo '</a>';
251 }
ff3caf30 252 echo '</h3>';
253 echo format_text($group->description);
254 echo '</td></tr></table>';
255 }
256 }
257 }
258
3e219038 259
260 if ($roles = get_roles_used_in_context($context)) {
261 foreach ($roles as $role) {
262 $rolenames[$role->id] = strip_tags(format_string($role->name)); // Used in menus etc later on
9a0f8502 263 }
264 }
cc038b47 265
bbbf2d40 266
b90e2f19 267/// Define a table showing a list of users in the current role.
ee4a52c5 268 if ($roleid) {
b90e2f19 269 $tablecolumns = array('picture', 'fullname');
270 $tableheaders = array('', get_string('fullname'));
271 if (!isset($hiddenfields['city'])) {
272 $tablecolumns[] = 'city';
273 $tableheaders[] = get_string('city');
274 }
275 if (!isset($hiddenfields['country'])) {
276 $tablecolumns[] = 'country';
277 $tableheaders[] = get_string('country');
278 }
279 if (!isset($hiddenfields['lastaccess'])) {
280 $tablecolumns[] = 'lastaccess';
281 $tableheaders[] = get_string('lastaccess');
282 }
283
284 if ($course->enrolperiod) {
285 $tablecolumns[] = 'timeend';
286 $tableheaders[] = get_string('enrolmentend');
287 }
288
289 if ($isteacher) {
290 $tablecolumns[] = '';
291 $tableheaders[] = get_string('select');
292 }
293
294 $table = new flexible_table('user-index-students-'.$course->id);
295
296 $table->define_columns($tablecolumns);
297 $table->define_headers($tableheaders);
298 $table->define_baseurl($baseurl);
299
300 $table->sortable(true, 'lastaccess', SORT_DESC);
301
302 $table->set_attribute('cellspacing', '0');
303 $table->set_attribute('id', 'students');
304 $table->set_attribute('class', 'generaltable generalbox');
305
306 $table->set_control_variables(array(
307 TABLE_VAR_SORT => 'ssort',
308 TABLE_VAR_HIDE => 'shide',
309 TABLE_VAR_SHOW => 'sshow',
310 TABLE_VAR_IFIRST => 'sifirst',
311 TABLE_VAR_ILAST => 'silast',
312 TABLE_VAR_PAGE => 'spage'
313 ));
314 $table->setup();
315
ee4a52c5 316
317 // we are looking for all users with this role assigned in this context or higher
0a8a95c9 318 if ($usercontexts = get_parent_contexts($context)) {
319 $listofcontexts = '('.implode(',', $usercontexts).')';
320 } else {
321 $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
322 $listofcontexts = '('.$sitecontext->id.')'; // must be site
323 }
ee4a52c5 324 $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country,
dfe60358 325 u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, ul.timeaccess AS lastaccess '; // s.lastaccess
ee4a52c5 326 //$select .= $course->enrolperiod?', s.timeend ':'';
8ca1053a 327 $from = "FROM {$CFG->prefix}user u INNER JOIN
94fb6d1d 328 {$CFG->prefix}role_assignments r on u.id=r.userid LEFT OUTER JOIN
329 {$CFG->prefix}user_lastaccess ul on r.userid=ul.userid ";
8ca1053a 330 $where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
dfe60358 331 AND u.deleted = 0
332 AND r.roleid = $roleid
b90e2f19 333 AND (ul.courseid = $course->id OR ul.courseid IS NULL)
334 AND u.username <> 'guest' ";
ee4a52c5 335 $where .= get_lastaccess_sql($accesssince);
dfe60358 336
ee4a52c5 337 $wheresearch = '';
dfe60358 338
ee4a52c5 339 if (!empty($search)) {
340 $LIKE = sql_ilike();
341 $fullname = sql_fullname('u.firstname','u.lastname');
342 $wheresearch .= ' AND ('. $fullname .' '. $LIKE .'\'%'. $search .'%\' OR email '. $LIKE .'\'%'. $search .'%\' OR idnumber '.$LIKE.' \'%'.$search.'%\') ';
343
344 }
345
346 if ($currentgroup) { // Displaying a group by choice
347 // FIX: TODO: This will not work if $currentgroup == 0, i.e. "those not in a group"
348 $from .= 'LEFT JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid ';
349 $where .= ' AND gm.groupid = '.$currentgroup;
350 }
351
ee4a52c5 352 $totalcount = count_records_sql('SELECT COUNT(distinct u.id) '.$from.$where); // 1 person can have multiple assignments
353
e957cc26 354 if ($table->get_sql_where()) {
ee4a52c5 355 $where .= ' AND '.$table->get_sql_where();
356 }
357
e957cc26 358 if ($table->get_sql_sort()) {
ee4a52c5 359 $sort = ' ORDER BY '.$table->get_sql_sort();
e957cc26 360 } else {
ee4a52c5 361 $sort = '';
362 }
363
364 $matchcount = count_records_sql('SELECT COUNT(*) '.$from.$where.$wheresearch);
365
366 $table->initialbars($totalcount > $perpage);
367 $table->pagesize($perpage, $matchcount);
368
c4121640 369 $students = get_records_sql($select.$from.$where.$wheresearch.$sort,
370 $table->get_page_start(), $table->get_page_size());
3e219038 371
372 /// If there are multiple Roles in the course, then show a drop down menu for switching
373
374 if ($rolenames) {
375 echo '<div class="rolesform">';
376 echo get_string('currentrole', 'role').': ';
377 $rolenames = array(0 => get_string('all')) + $rolenames;
378 popup_form('index.php?contextid='.$contextid.'&amp;roleid=', $rolenames, 'rolesform', $roleid, '');
379 echo '</div>';
380 }
381
382
e957cc26 383 if (!$currentrole = get_record('role','id',$roleid)) {
384 error('That role does not exist');
385 }
b90e2f19 386 $a->number = $totalcount;
387 $a->role = $currentrole->name;
3e219038 388 $heading = get_string('xuserswiththerole', 'role', $a);
d02eeded 389 if (user_can_assign($context, $roleid)) {
3e219038 390 $heading .= ' <a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?roleid='.$roleid.'&amp;contextid='.$context->id.'">';
391 $heading .= '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="" /></a>';
392 }
393 print_heading($heading, 'center', 3);
394
395
396 if ($isteacher) {
397 echo '
398<script Language="JavaScript">
399<!--
400function checksubmit(form) {
401 var destination = form.formaction.options[form.formaction.selectedIndex].value;
402 if (destination == "" || !checkchecked(form)) {
403 form.formaction.selectedIndex = 0;
404 return false;
405 } else {
406 return true;
407 }
408}
409
410function checkchecked(form) {
411 var inputs = document.getElementsByTagName(\'INPUT\');
412 var checked = false;
413 inputs = filterByParent(inputs, function() {return form;});
414 for(var i = 0; i < inputs.length; ++i) {
415 if(inputs[i].type == \'checkbox\' && inputs[i].checked) {
416 checked = true;
417 }
418 }
419 return checked;
420}
421//-->
422</script>
423';
424 echo '<form action="action_redir.php" method="post" name="studentsform" onSubmit="return checksubmit(this);">';
425 echo '<input type="hidden" name="returnto" value="'.$_SERVER['REQUEST_URI'].'" />';
426 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
ee4a52c5 427 }
ee4a52c5 428
429 if ($CFG->longtimenosee > 0 && $CFG->longtimenosee < 1000 && $totalcount > 0) {
430 echo '<p id="longtimenosee">('.get_string('unusedaccounts', '', $CFG->longtimenosee).')</p>';
431 }
432
433 if ($fullmode) { // Print simple listing
434 if ($totalcount < 1) {
435 print_heading(get_string("nostudentsfound", "", $course->students));
436 }
437 else {
438
439 if($totalcount > $perpage) {
440
441 $firstinitial = $table->get_initial_first();
442 $lastinitial = $table->get_initial_last();
443 $strall = get_string('all');
444 $alpha = explode(',', get_string('alphabet'));
445
446 // Bar of first initials
447
448 echo '<div class="initialbar firstinitial">'.get_string('firstname').' : ';
449 if(!empty($firstinitial)) {
450 echo '<a href="'.$baseurl.'&amp;sifirst=">'.$strall.'</a>';
451 } else {
452 echo '<strong>'.$strall.'</strong>';
453 }
454 foreach ($alpha as $letter) {
455 if ($letter == $firstinitial) {
456 echo ' <strong>'.$letter.'</strong>';
457 } else {
458 echo ' <a href="'.$baseurl.'&amp;sifirst='.$letter.'">'.$letter.'</a>';
459 }
460 }
461 echo '</div>';
462
463 // Bar of last initials
464
465 echo '<div class="initialbar lastinitial">'.get_string('lastname').' : ';
466 if(!empty($lastinitial)) {
467 echo '<a href="'.$baseurl.'&amp;silast=">'.$strall.'</a>';
468 } else {
469 echo '<strong>'.$strall.'</strong>';
470 }
471 foreach ($alpha as $letter) {
472 if ($letter == $lastinitial) {
473 echo ' <strong>'.$letter.'</strong>';
474 } else {
475 echo ' <a href="'.$baseurl.'&amp;silast='.$letter.'">'.$letter.'</a>';
476 }
477 }
478 echo '</div>';
479
480 print_paging_bar($matchcount, intval($table->get_page_start() / $perpage), $perpage, $baseurl.'&amp;', 'spage');
481
482 }
483
484 if($matchcount > 0) {
485 foreach ($students as $student) {
486 print_user($student, $course, true);
487 }
488 }
489 else {
490 print_heading(get_string('nothingtodisplay'));
491 }
492 }
493 }
494 else {
495 $countrysort = (strpos($sort, 'country') !== false);
496 $timeformat = get_string('strftimedate');
497 if (!empty($students)) {
498 foreach ($students as $student) {
499 if ($student->lastaccess) {
500 $lastaccess = format_time(time() - $student->lastaccess, $datestring);
501 } else {
502 $lastaccess = $strnever;
503 }
504
505 if (empty($student->country)) {
506 $country = '';
507 }
508 else {
509 if($countrysort) {
510 $country = '('.$student->country.') '.$countries[$student->country];
511 }
512 else {
513 $country = $countries[$student->country];
514 }
515 }
516
517 $data = array (
518 print_user_picture($student->id, $course->id, $student->picture, false, true),
519 '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id.'">'.fullname($student).'</a></strong>');
520 if (!isset($hiddenfields['city'])) {
521 $data[] = $student->city;
522 }
523 if (!isset($hiddenfields['country'])) {
524 $data[] = $country;
525 }
526 if (!isset($hiddenfields['lastaccess'])) {
527 $data[] = $lastaccess;
528 }
529 if ($course->enrolperiod) {
530 if ($student->timeend) {
531 $data[] = userdate($student->timeend, $timeformat);
532 } else {
533 $data[] = get_string('unlimited');
534 }
535 }
536 if ($isteacher) {
537 $data[] = '<input type="checkbox" name="user'.$student->id.'" />';
538 }
539 $table->add_data($data);
540
541 }
542 }
543
544 $table->print_html();
545
546 }
547
548 if ($isteacher) {
549 echo '<br /><center>';
550 echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> ';
551 echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> ';
552 $displaylist['messageselect.php'] = get_string('messageselectadd');
553 if ($course->enrolperiod) {
554 $displaylist['extendenrol.php'] = get_string('extendenrol');
555 }
556 choose_from_menu ($displaylist, "formaction", "", get_string("withselectedusers"), "if(checksubmit(this.form))this.form.submit();", "");
557 helpbutton("participantswithselectedusers", get_string("withselectedusers"));
558 echo '<input type="submit" value="' . get_string('ok') . '"';
559 echo '</center></form>';
560 }
561
562 if ($isteacher && $totalcount > ($perpage*3)) {
563 echo '<form action="index.php"><p align="center"><input type="hidden" name="id" value="'.$course->id.'" />'.get_string('search').':&nbsp;'."\n";
564 echo '<input type="text" name="search" value="'.$search.'" />&nbsp;<input type="submit" value="'.get_string('search').'" /></p></form>'."\n";
565 }
566
36075e09 567 if ($perpage == SHOW_ALL_PAGE_SIZE) {
ee4a52c5 568 echo '<div id="showall"><a href="'.$baseurl.'&amp;perpage='.DEFAULT_PAGE_SIZE.'">'.get_string('showperpage', '', DEFAULT_PAGE_SIZE).'</a></div>';
569 }
570 else if ($matchcount > 0 && $perpage < $matchcount) {
36075e09 571 echo '<div id="showall"><a href="'.$baseurl.'&amp;perpage='.SHOW_ALL_PAGE_SIZE.'">'.get_string('showall', '', $matchcount).'</a></div>';
ee4a52c5 572 }
b90e2f19 573
574 } else {
575/// If no role is selected, then print an overview of the roles in this course
576
577 $table->tablealign = 'center';
578 $table->cellpadding = 5;
579 $table->cellspacing = 0;
580 $table->width = '20%';
581 $table->head = array(get_string('roles', 'role'), get_string('users'));
582 $table->wrap = array('nowrap', 'nowrap');
583 $table->align = array('right', 'center');
584
585 $baseurl = $CFG->wwwroot.'/user/index.php?contextid='.$context->id;
586
587 foreach ($rolenames as $roleid => $rolename) {
588 $countusers = 0;
589 if ($contextusers = count_role_users($roleid, $context)) {
590 $countusers = count($contextusers);
591 }
592 if ($countusers) {
593 $table->data[] = array('<a href="'.$baseurl.'&amp;roleid='.$roleid.'">'.$rolename.'</a>', $countusers);
594 } else {
595 $table->data[] = array($rolename, $countusers);
596 }
597 }
598
599 print_table($table);
600
601 }
cc038b47 602
603 print_footer($course);
f9903ed0 604
31b71336 605
606function get_lastaccess_sql($accesssince='') {
607 if (empty($accesssince)) {
608 return '';
609 }
610 if ($accesssince == -1) { // never
dfe60358 611 return ' AND ul.timeaccess = 0';
31b71336 612 } else {
7da0af9f 613 return ' AND ul.timeaccess != 0 AND timeaccess < '.$accesssince;
31b71336 614 }
615}
616
f9903ed0 617?>