Much better look for user index
[moodle.git] / user / index.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3// Lists all the users within a given course
4
5 require("../config.php");
bda8d43a 6 require("../lib/countries.php");
f9903ed0 7 require("lib.php");
8
9 require_variable($id); //course
6b281f1f 10 optional_variable($sort, "u.lastaccess"); //how to sort students
e6b9ee04 11 optional_variable($dir,"DESC"); //how to sort students
f9903ed0 12
13 if (! $course = get_record("course", "id", $id)) {
14 error("Course ID is incorrect");
15 }
16
17 require_login($course->id);
18
da3a08d7 19 add_to_log($course->id, "user", "view all", "index.php?id=$course->id", "");
f9903ed0 20
21 if ($course->category) {
fa0626c6 22 print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
23 "<A HREF=../course/view.php?id=$course->id>$course->shortname</A> -> ".
24 get_string("participants"), "");
f9903ed0 25 } else {
fa0626c6 26 print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
27 get_string("participants"), "");
f9903ed0 28 }
29
cd052f8c 30 $string->email = get_string("email");
31 $string->location = get_string("location");
32 $string->lastaccess = get_string("lastaccess");
33 $string->activity = get_string("activity");
34 $string->unenrol = get_string("unenrol");
35 $string->loginas = get_string("loginas");
36 $string->fullprofile = get_string("fullprofile");
40a1d986 37 $string->role = get_string("role");
38 $string->never = get_string("never");
6b281f1f 39 $string->name = get_string("name");
f9903ed0 40
4b232245 41 if ( $teachers = get_course_teachers($course->id)) {
b4d7002e 42 echo "<H2 align=center>$course->teachers</H2>";
f9903ed0 43 foreach ($teachers as $teacher) {
f144c305 44 if ($teacher->authority > 0) { // Don't print teachers with no authority
45 print_user($teacher, $course, $string);
46 }
f9903ed0 47 }
f9903ed0 48 }
49
6b281f1f 50 if ($students = get_course_students($course->id, "$sort $dir")) {
6abee989 51 $numstudents = count($students);
52 echo "<H2 align=center>$numstudents $course->students</H2>";
e6b9ee04 53 if ($numstudents > 30) {
6abee989 54 foreach ($students as $student) {
55 print_user($student, $course, $string);
56 }
6b281f1f 57 } else { // Print one big table with abbreviated info
6b281f1f 58 $table->head = array ("&nbsp;",
e6b9ee04 59 "$string->name <A HREF=\"index.php?id=$course->id&sort=u.firstname&dir=ASC\"><IMG BORDER=0 SRC=\"../pix/t/down.gif\"></A>",
60 "$string->location <A HREF=\"index.php?id=$course->id&sort=u.country&dir=ASC\"><IMG BORDER=0 SRC=\"../pix/t/down.gif\"></A>",
61 "$string->lastaccess <A HREF=\"index.php?id=$course->id&sort=u.lastaccess&dir=DESC\"><IMG BORDER=0 SRC=\"../pix/t/down.gif\"></A>");
6b281f1f 62 $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT");
63 $table->size = array ("35", "*", "*", "*");
64
6abee989 65 foreach ($students as $student) {
6b281f1f 66 if ($student->lastaccess) {
67 $lastaccess = userdate($student->lastaccess);
68 $lastaccess .= "&nbsp (".format_time(time() - $student->lastaccess).")";
69 } else {
70 $lastaccess = $string->never;
71 }
72
73 $table->data[] = array (print_user_picture($student->id, $course->id, $student->picture, false, true),
e6b9ee04 74 "<B><A HREF=\"$CFG->wwwroot/user/view.php?id=$student->id&course=$course->id\">$student->firstname $student->lastname</A></B>",
6b281f1f 75 "$student->city, ".$COUNTRIES["$student->country"],
76 "$lastaccess");
6abee989 77 }
6b281f1f 78 print_table($table, 2, 0);
f9903ed0 79 }
619431ba 80 }
f9903ed0 81
82 print_footer($course);
83
f9903ed0 84?>