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