New help translation
[moodle.git] / user / index.php
blobe46dcd3bc9c3244acd8560fce2259702aac521ad
1 <?PHP // $Id$
3 // Lists all the users within a given course
5 require_once("../config.php");
6 require_once("lib.php");
8 require_variable($id); //course
9 optional_variable($sort, "lastaccess"); //how to sort students
10 optional_variable($dir,"desc"); //how to sort students
11 optional_variable($page, "0"); // which page to show
12 optional_variable($perpage, "20"); // how many per page
15 if (! $course = get_record("course", "id", $id)) {
16 error("Course ID is incorrect");
19 require_login($course->id);
21 add_to_log($course->id, "user", "view all", "index.php?id=$course->id", "");
23 $string->email = get_string("email");
24 $string->location = get_string("location");
25 $string->lastaccess = get_string("lastaccess");
26 $string->activity = get_string("activity");
27 $string->unenrol = get_string("unenrol");
28 $string->loginas = get_string("loginas");
29 $string->fullprofile = get_string("fullprofile");
30 $string->role = get_string("role");
31 $string->never = get_string("never");
32 $string->name = get_string("name");
33 $string->day = get_string("day");
34 $string->days = get_string("days");
35 $string->hour = get_string("hour");
36 $string->hours = get_string("hours");
37 $string->min = get_string("min");
38 $string->mins = get_string("mins");
39 $string->sec = get_string("sec");
40 $string->secs = get_string("secs");
42 $countries = get_list_of_countries();
44 $loggedinas = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>";
46 $showteachers = ($page == 0 and $sort == "lastaccess" and $dir == "desc");
48 if ($showteachers) {
49 $participantslink = get_string("participants");
50 } else {
51 $participantslink = "<a href=\"index.php?id=$course->id\">".get_string("participants")."</a>";
54 if ($course->category) {
55 print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
56 "<A HREF=../course/view.php?id=$course->id>$course->shortname</A> -> ".
57 "$participantslink", "", "", true, "&nbsp;", $loggedinas);
58 } else {
59 print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
60 "$participantslink", "", "", true, "&nbsp;", $loggedinas);
64 if ($showteachers) {
65 if ( $teachers = get_course_teachers($course->id)) {
66 echo "<h2 align=center>$course->teachers</h2>";
67 foreach ($teachers as $teacher) {
68 if ($teacher->authority > 0) { // Don't print teachers with no authority
69 print_user($teacher, $course, $string, $countries);
75 $dsort = "u.$sort";
77 $totalcount = count_records("user_students", "course", $course->id);
79 echo "<h2 align=center>$totalcount $course->students</h2>";
81 if ($CFG->longtimenosee < 500) {
82 echo "<center><p><font size=1>(";
83 print_string("unusedaccounts","",$CFG->longtimenosee);
84 echo ")</font></p></center>";
87 if (0 < $totalcount and $totalcount < USER_SMALL_CLASS) { // Print simple listing
89 if ($students = get_course_students($course->id, $dsort, $dir)) {
90 foreach ($students as $student) {
91 print_user($student, $course, $string, $countries);
95 } else if ($students = get_course_students($course->id, $dsort, $dir, $page*$perpage, $perpage)) {
97 print_paging_bar($totalcount, $page, $perpage,
98 "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&");
100 // Print one big table with abbreviated info
101 $columns = array("firstname", "lastname", "city", "country", "lastaccess");
103 foreach ($columns as $column) {
104 $colname[$column] = get_string($column);
105 if ($sort != $column) {
106 $columnicon = "";
107 if ($column == "lastaccess") {
108 $columndir = "desc";
109 } else {
110 $columndir = "asc";
112 } else {
113 $columndir = $dir == "asc" ? "desc":"asc";
114 if ($column == "lastaccess") {
115 $columnicon = $dir == "asc" ? "up":"down";
116 } else {
117 $columnicon = $dir == "asc" ? "down":"up";
119 $columnicon = " <img src=\"$CFG->pixpath/t/$columnicon.gif\" />";
121 $$column = "<a href=\"index.php?id=$course->id&sort=$column&dir=$columndir\">".$colname["$column"]."</a>$columnicon";
124 foreach ($students as $key => $student) {
125 $students[$key]->country = $countries[$student->country];
127 if ($sort == "country") { // Need to re-sort by full country name, not code
128 foreach ($students as $student) {
129 $sstudents[$student->id] = $student->country;
131 asort($sstudents);
132 foreach ($sstudents as $key => $value) {
133 $nstudents[] = $students[$key];
135 $students = $nstudents;
138 $table->head = array ("&nbsp;", "$firstname / $lastname", $city, $country, $lastaccess);
139 $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT");
140 $table->size = array ("10", "*", "*", "*", "*");
141 $table->size = array ("10", "*", "*", "*", "*");
142 $table->cellpadding = 2;
143 $table->cellspacing = 0;
145 foreach ($students as $student) {
147 if ($student->lastaccess) {
148 $lastaccess = format_time(time() - $student->lastaccess, $string);
149 } else {
150 $lastaccess = $string->never;
153 if ($showall and $numstudents > USER_LARGE_CLASS) { // Don't show pictures
154 $picture = "";
155 } else {
156 $picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
159 $table->data[] = array ($picture,
160 "<b><a href=\"$CFG->wwwroot/user/view.php?id=$student->id&course=$course->id\">$student->firstname $student->lastname</a></b>",
161 "<font size=2>$student->city</font>",
162 "<font size=2>$student->country</font>",
163 "<font size=2>$lastaccess</font>");
165 print_table($table);
167 print_paging_bar($totalcount, $page, $perpage,
168 "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&");
170 if ($perpage != 99999) {
171 echo "<center><p>";
172 echo "<a href=\"index.php?id=$course->id&sort=$sort&dir=$dir&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
173 echo "</p></center>";
178 print_footer($course);