Much better look for user index
[moodle.git] / user / index.php
1 <?PHP // $Id$
3 //  Lists all the users within a given course
5     require("../config.php");
6     require("../lib/countries.php");
7     require("lib.php");
9     require_variable($id);   //course
10     optional_variable($sort, "u.lastaccess");  //how to sort students
11     optional_variable($dir,"DESC");   //how to sort students
13     if (! $course = get_record("course", "id", $id)) {
14         error("Course ID is incorrect");
15     }
17     require_login($course->id);
19     add_to_log($course->id, "user", "view all", "index.php?id=$course->id", "");
21     if ($course->category) {
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"), "");
25     } else {
26         print_header("$course->shortname: ".get_string("participants"), "$course->fullname", 
27                       get_string("participants"), "");
28     }
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");
37     $string->role        = get_string("role");
38     $string->never       = get_string("never");
39     $string->name        = get_string("name");
41     if ( $teachers = get_course_teachers($course->id)) {
42         echo "<H2 align=center>$course->teachers</H2>";
43         foreach ($teachers as $teacher) {
44             if ($teacher->authority > 0) {    // Don't print teachers with no authority
45                 print_user($teacher, $course, $string);
46             }
47         }
48     }
50     if ($students = get_course_students($course->id, "$sort $dir")) {
51         $numstudents = count($students);
52         echo "<H2 align=center>$numstudents $course->students</H2>";
53         if ($numstudents > 30) {
54             foreach ($students as $student) {
55                 print_user($student, $course, $string);
56             }
57         } else {  // Print one big table with abbreviated info
58             $table->head = array ("&nbsp;",
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>");
62             $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT");
63             $table->size = array ("35", "*", "*", "*");
64             
65             foreach ($students as $student) {
66                 if ($student->lastaccess) {
67                     $lastaccess = userdate($student->lastaccess);
68                     $lastaccess .= "&nbsp (".format_time(time() - $student->lastaccess).")";
69                 } else {
70                     $lastaccess = $string->never;
71                 }
73                 $table->data[] = array (print_user_picture($student->id, $course->id, $student->picture, false, true),
74                     "<B><A HREF=\"$CFG->wwwroot/user/view.php?id=$student->id&course=$course->id\">$student->firstname $student->lastname</A></B>",
75                     "$student->city, ".$COUNTRIES["$student->country"],
76                     "$lastaccess");
77             }
78             print_table($table, 2, 0);
79         }
80     } 
82     print_footer($course);
84 ?>