f9903ed0 |
1 | <?PHP // $Id$ |
2 | |
3 | // Lists all the users within a given course |
4 | |
b0e3a925 |
5 | require_once("../config.php"); |
b0e3a925 |
6 | require_once("lib.php"); |
f9903ed0 |
7 | |
8 | require_variable($id); //course |
d578afc8 |
9 | optional_variable($sort, "lastaccess"); //how to sort students |
4969ad74 |
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 |
f9903ed0 |
13 | |
55e4b5f9 |
14 | |
f9903ed0 |
15 | if (! $course = get_record("course", "id", $id)) { |
16 | error("Course ID is incorrect"); |
17 | } |
18 | |
19 | require_login($course->id); |
20 | |
da3a08d7 |
21 | add_to_log($course->id, "user", "view all", "index.php?id=$course->id", ""); |
f9903ed0 |
22 | |
cd052f8c |
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"); |
40a1d986 |
30 | $string->role = get_string("role"); |
31 | $string->never = get_string("never"); |
6b281f1f |
32 | $string->name = get_string("name"); |
8dbed6be |
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"); |
f9903ed0 |
41 | |
5833a6c8 |
42 | $countries = get_list_of_countries(); |
43 | |
4969ad74 |
44 | $loggedinas = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>"; |
f9903ed0 |
45 | |
4969ad74 |
46 | $showteachers = ($page == 0 and $sort == "lastaccess" and $dir == "desc"); |
47 | |
48 | if ($showteachers) { |
49 | $participantslink = get_string("participants"); |
d578afc8 |
50 | } else { |
4969ad74 |
51 | $participantslink = "<a href=\"index.php?id=$course->id\">".get_string("participants")."</a>"; |
d578afc8 |
52 | } |
53 | |
4969ad74 |
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, " ", $loggedinas); |
dc0dc7d5 |
58 | } else { |
4969ad74 |
59 | print_header("$course->shortname: ".get_string("participants"), "$course->fullname", |
60 | "$participantslink", "", "", true, " ", $loggedinas); |
61 | } |
62 | |
63 | |
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 |
5833a6c8 |
69 | print_user($teacher, $course, $string, $countries); |
4969ad74 |
70 | } |
71 | } |
72 | } |
dc0dc7d5 |
73 | } |
74 | |
40c9e047 |
75 | if ($sort == "lastaccess") { |
4d744a22 |
76 | $dsort = "s.timeaccess"; |
77 | } else { |
78 | $dsort = "u.$sort"; |
79 | } |
4969ad74 |
80 | |
81 | $totalcount = count_records("user_students", "course", $course->id); |
81f186b4 |
82 | |
4969ad74 |
83 | echo "<h2 align=center>$totalcount $course->students</h2>"; |
dc95f4a1 |
84 | |
69ec0a8b |
85 | if ($CFG->longtimenosee < 500) { |
86 | echo "<center><p><font size=1>("; |
87 | print_string("unusedaccounts","",$CFG->longtimenosee); |
88 | echo ")</font></p></center>"; |
89 | } |
90 | |
4969ad74 |
91 | if (0 < $totalcount and $totalcount < USER_SMALL_CLASS) { // Print simple listing |
92 | |
30bacddc |
93 | if ($students = get_course_students($course->id, $dsort, $dir)) { |
94 | foreach ($students as $student) { |
5833a6c8 |
95 | print_user($student, $course, $string, $countries); |
30bacddc |
96 | } |
4969ad74 |
97 | } |
98 | |
99 | } else if ($students = get_course_students($course->id, $dsort, $dir, $page*$perpage, $perpage)) { |
100 | |
101 | print_paging_bar($totalcount, $page, $perpage, |
102 | "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&"); |
cbb0fee0 |
103 | |
4969ad74 |
104 | // Print one big table with abbreviated info |
105 | $columns = array("firstname", "lastname", "city", "country", "lastaccess"); |
d578afc8 |
106 | |
4969ad74 |
107 | foreach ($columns as $column) { |
108 | $colname[$column] = get_string($column); |
109 | if ($sort != $column) { |
110 | $columnicon = ""; |
d578afc8 |
111 | if ($column == "lastaccess") { |
4969ad74 |
112 | $columndir = "desc"; |
d578afc8 |
113 | } else { |
4969ad74 |
114 | $columndir = "asc"; |
d578afc8 |
115 | } |
4969ad74 |
116 | } else { |
117 | $columndir = $dir == "asc" ? "desc":"asc"; |
118 | if ($column == "lastaccess") { |
119 | $columnicon = $dir == "asc" ? "up":"down"; |
d578afc8 |
120 | } else { |
4969ad74 |
121 | $columnicon = $dir == "asc" ? "down":"up"; |
d578afc8 |
122 | } |
4969ad74 |
123 | $columnicon = " <img src=\"$CFG->pixpath/t/$columnicon.gif\" />"; |
32b4b974 |
124 | } |
4969ad74 |
125 | $$column = "<a href=\"index.php?id=$course->id&sort=$column&dir=$columndir\">".$colname["$column"]."</a>$columnicon"; |
126 | } |
d578afc8 |
127 | |
4969ad74 |
128 | foreach ($students as $key => $student) { |
5833a6c8 |
129 | $students[$key]->country = $countries[$student->country]; |
4969ad74 |
130 | } |
131 | if ($sort == "country") { // Need to re-sort by full country name, not code |
132 | foreach ($students as $student) { |
133 | $sstudents[$student->id] = $student->country; |
adcb3ac5 |
134 | } |
4969ad74 |
135 | asort($sstudents); |
136 | foreach ($sstudents as $key => $value) { |
137 | $nstudents[] = $students[$key]; |
adcb3ac5 |
138 | } |
4969ad74 |
139 | $students = $nstudents; |
140 | } |
adcb3ac5 |
141 | |
4969ad74 |
142 | $table->head = array (" ", "$firstname / $lastname", $city, $country, $lastaccess); |
143 | $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT"); |
144 | $table->size = array ("10", "*", "*", "*", "*"); |
145 | $table->size = array ("10", "*", "*", "*", "*"); |
1b6a4b1d |
146 | $table->cellpadding = 4; |
4969ad74 |
147 | $table->cellspacing = 0; |
148 | |
149 | foreach ($students as $student) { |
150 | |
151 | if ($student->lastaccess) { |
152 | $lastaccess = format_time(time() - $student->lastaccess, $string); |
153 | } else { |
154 | $lastaccess = $string->never; |
155 | } |
dc0dc7d5 |
156 | |
4969ad74 |
157 | if ($showall and $numstudents > USER_LARGE_CLASS) { // Don't show pictures |
158 | $picture = ""; |
159 | } else { |
160 | $picture = print_user_picture($student->id, $course->id, $student->picture, false, true); |
161 | } |
6b281f1f |
162 | |
4969ad74 |
163 | $table->data[] = array ($picture, |
164 | "<b><a href=\"$CFG->wwwroot/user/view.php?id=$student->id&course=$course->id\">$student->firstname $student->lastname</a></b>", |
165 | "<font size=2>$student->city</font>", |
166 | "<font size=2>$student->country</font>", |
167 | "<font size=2>$lastaccess</font>"); |
168 | } |
169 | print_table($table); |
c69ce08b |
170 | |
4969ad74 |
171 | print_paging_bar($totalcount, $page, $perpage, |
172 | "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&"); |
15c71521 |
173 | |
4969ad74 |
174 | if ($perpage != 99999) { |
175 | echo "<center><p>"; |
176 | echo "<a href=\"index.php?id=$course->id&sort=$sort&dir=$dir&perpage=99999\">".get_string("showall", "", $totalcount)."</a>"; |
177 | echo "</p></center>"; |
9ae472a3 |
178 | } |
4969ad74 |
179 | |
619431ba |
180 | } |
f9903ed0 |
181 | |
182 | print_footer($course); |
183 | |
f9903ed0 |
184 | ?> |