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 |
a328425d |
12 | optional_variable($lastinitial, ""); // only show students with this last initial |
13 | optional_variable($firstinitial, ""); // only show students with this first initial |
4969ad74 |
14 | optional_variable($perpage, "20"); // how many per page |
f9903ed0 |
15 | |
55e4b5f9 |
16 | |
f9903ed0 |
17 | if (! $course = get_record("course", "id", $id)) { |
18 | error("Course ID is incorrect"); |
19 | } |
20 | |
21 | require_login($course->id); |
22 | |
eca1c454 |
23 | $isteacher = isteacher($course->id); |
24 | |
da3a08d7 |
25 | add_to_log($course->id, "user", "view all", "index.php?id=$course->id", ""); |
f9903ed0 |
26 | |
cd052f8c |
27 | $string->email = get_string("email"); |
28 | $string->location = get_string("location"); |
29 | $string->lastaccess = get_string("lastaccess"); |
30 | $string->activity = get_string("activity"); |
31 | $string->unenrol = get_string("unenrol"); |
32 | $string->loginas = get_string("loginas"); |
33 | $string->fullprofile = get_string("fullprofile"); |
40a1d986 |
34 | $string->role = get_string("role"); |
35 | $string->never = get_string("never"); |
6b281f1f |
36 | $string->name = get_string("name"); |
8dbed6be |
37 | $string->day = get_string("day"); |
38 | $string->days = get_string("days"); |
39 | $string->hour = get_string("hour"); |
40 | $string->hours = get_string("hours"); |
41 | $string->min = get_string("min"); |
42 | $string->mins = get_string("mins"); |
43 | $string->sec = get_string("sec"); |
44 | $string->secs = get_string("secs"); |
a328425d |
45 | $string->all = get_string("all"); |
f9903ed0 |
46 | |
5833a6c8 |
47 | $countries = get_list_of_countries(); |
48 | |
4969ad74 |
49 | $loggedinas = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>"; |
f9903ed0 |
50 | |
4969ad74 |
51 | $showteachers = ($page == 0 and $sort == "lastaccess" and $dir == "desc"); |
52 | |
53 | if ($showteachers) { |
54 | $participantslink = get_string("participants"); |
d578afc8 |
55 | } else { |
4969ad74 |
56 | $participantslink = "<a href=\"index.php?id=$course->id\">".get_string("participants")."</a>"; |
d578afc8 |
57 | } |
58 | |
4969ad74 |
59 | if ($course->category) { |
60 | print_header("$course->shortname: ".get_string("participants"), "$course->fullname", |
61 | "<A HREF=../course/view.php?id=$course->id>$course->shortname</A> -> ". |
62 | "$participantslink", "", "", true, " ", $loggedinas); |
dc0dc7d5 |
63 | } else { |
4969ad74 |
64 | print_header("$course->shortname: ".get_string("participants"), "$course->fullname", |
65 | "$participantslink", "", "", true, " ", $loggedinas); |
66 | } |
67 | |
68 | |
69 | if ($showteachers) { |
70 | if ( $teachers = get_course_teachers($course->id)) { |
71 | echo "<h2 align=center>$course->teachers</h2>"; |
72 | foreach ($teachers as $teacher) { |
73 | if ($teacher->authority > 0) { // Don't print teachers with no authority |
5833a6c8 |
74 | print_user($teacher, $course, $string, $countries); |
4969ad74 |
75 | } |
76 | } |
77 | } |
dc0dc7d5 |
78 | } |
79 | |
40c9e047 |
80 | if ($sort == "lastaccess") { |
4d744a22 |
81 | $dsort = "s.timeaccess"; |
82 | } else { |
83 | $dsort = "u.$sort"; |
84 | } |
4969ad74 |
85 | |
a328425d |
86 | $students = get_course_students($course->id, $dsort, $dir, $page*$perpage, |
87 | $perpage, $firstinitial, $lastinitial); |
88 | |
89 | $totalcount = $matchcount = count_records("user_students", "course", $course->id); |
81f186b4 |
90 | |
4969ad74 |
91 | echo "<h2 align=center>$totalcount $course->students</h2>"; |
dc95f4a1 |
92 | |
a328425d |
93 | if (($CFG->longtimenosee < 500) and (!$page) and ($sort == "lastaccess")) { |
69ec0a8b |
94 | echo "<center><p><font size=1>("; |
95 | print_string("unusedaccounts","",$CFG->longtimenosee); |
96 | echo ")</font></p></center>"; |
97 | } |
98 | |
a328425d |
99 | /// Print paging bars if necessary |
4969ad74 |
100 | |
a328425d |
101 | if ($totalcount > $perpage) { |
102 | $alphabet = explode(',', get_string('alphabet')); |
103 | |
104 | /// Bar of first initials |
105 | |
106 | echo "<center><p align=\"center\">"; |
107 | echo get_string("firstname")." : "; |
108 | if ($firstinitial) { |
109 | echo " <a href=\"index.php?id=$course->id&sort=firstname&dir=ASC&". |
110 | "perpage=$perpage&lastinitial=$lastinitial\">$string->all</a> "; |
111 | } else { |
112 | echo " <b>$string->all</b> "; |
113 | } |
114 | foreach ($alphabet as $letter) { |
115 | if ($letter == $firstinitial) { |
116 | echo " <b>$letter</b> "; |
117 | } else { |
118 | echo " <a href=\"index.php?id=$course->id&sort=firstname&dir=ASC&". |
119 | "perpage=$perpage&lastinitial=$lastinitial&firstinitial=$letter\">$letter</a> "; |
30bacddc |
120 | } |
4969ad74 |
121 | } |
a328425d |
122 | echo "<br />"; |
4969ad74 |
123 | |
a328425d |
124 | /// Bar of last initials |
4969ad74 |
125 | |
a328425d |
126 | echo get_string("lastname")." : "; |
127 | if ($lastinitial) { |
128 | echo " <a href=\"index.php?id=$course->id&sort=lastname&dir=ASC&". |
129 | "perpage=$perpage&firstinitial=$firstinitial\">$string->all</a> "; |
130 | } else { |
131 | echo " <b>$string->all</b> "; |
132 | } |
133 | foreach ($alphabet as $letter) { |
134 | if ($letter == $lastinitial) { |
135 | echo " <b>$letter</b> "; |
136 | } else { |
137 | echo " <a href=\"index.php?id=$course->id&sort=lastname&dir=ASC&". |
138 | "perpage=$perpage&firstinitial=$firstinitial&lastinitial=$letter\">$letter</a> "; |
139 | } |
140 | } |
141 | echo "</p>"; |
142 | echo "</center>"; |
143 | |
144 | $matchcount = count_course_students($course, "", $firstinitial, $lastinitial); |
145 | |
146 | print_paging_bar($matchcount, $page, $perpage, |
147 | "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&"); |
148 | |
149 | } |
150 | |
151 | if ($matchcount == 0) { |
152 | print_heading(get_string("nostudentsfound", "", $course->students)); |
153 | |
154 | } if (0 < $matchcount and $matchcount < USER_SMALL_CLASS) { // Print simple listing |
155 | foreach ($students as $student) { |
156 | print_user($student, $course, $string, $countries); |
157 | } |
158 | |
159 | } else if ($matchcount > 0) { |
cbb0fee0 |
160 | |
4969ad74 |
161 | // Print one big table with abbreviated info |
162 | $columns = array("firstname", "lastname", "city", "country", "lastaccess"); |
d578afc8 |
163 | |
4969ad74 |
164 | foreach ($columns as $column) { |
165 | $colname[$column] = get_string($column); |
166 | if ($sort != $column) { |
167 | $columnicon = ""; |
d578afc8 |
168 | if ($column == "lastaccess") { |
4969ad74 |
169 | $columndir = "desc"; |
d578afc8 |
170 | } else { |
4969ad74 |
171 | $columndir = "asc"; |
d578afc8 |
172 | } |
4969ad74 |
173 | } else { |
174 | $columndir = $dir == "asc" ? "desc":"asc"; |
175 | if ($column == "lastaccess") { |
176 | $columnicon = $dir == "asc" ? "up":"down"; |
d578afc8 |
177 | } else { |
4969ad74 |
178 | $columnicon = $dir == "asc" ? "down":"up"; |
d578afc8 |
179 | } |
4969ad74 |
180 | $columnicon = " <img src=\"$CFG->pixpath/t/$columnicon.gif\" />"; |
32b4b974 |
181 | } |
4969ad74 |
182 | $$column = "<a href=\"index.php?id=$course->id&sort=$column&dir=$columndir\">".$colname["$column"]."</a>$columnicon"; |
183 | } |
d578afc8 |
184 | |
4969ad74 |
185 | foreach ($students as $key => $student) { |
5833a6c8 |
186 | $students[$key]->country = $countries[$student->country]; |
4969ad74 |
187 | } |
188 | if ($sort == "country") { // Need to re-sort by full country name, not code |
189 | foreach ($students as $student) { |
190 | $sstudents[$student->id] = $student->country; |
adcb3ac5 |
191 | } |
4969ad74 |
192 | asort($sstudents); |
193 | foreach ($sstudents as $key => $value) { |
194 | $nstudents[] = $students[$key]; |
adcb3ac5 |
195 | } |
4969ad74 |
196 | $students = $nstudents; |
197 | } |
adcb3ac5 |
198 | |
a328425d |
199 | |
4969ad74 |
200 | $table->head = array (" ", "$firstname / $lastname", $city, $country, $lastaccess); |
201 | $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT"); |
202 | $table->size = array ("10", "*", "*", "*", "*"); |
203 | $table->size = array ("10", "*", "*", "*", "*"); |
1b6a4b1d |
204 | $table->cellpadding = 4; |
4969ad74 |
205 | $table->cellspacing = 0; |
206 | |
207 | foreach ($students as $student) { |
208 | |
209 | if ($student->lastaccess) { |
210 | $lastaccess = format_time(time() - $student->lastaccess, $string); |
211 | } else { |
212 | $lastaccess = $string->never; |
213 | } |
dc0dc7d5 |
214 | |
4969ad74 |
215 | if ($showall and $numstudents > USER_LARGE_CLASS) { // Don't show pictures |
216 | $picture = ""; |
217 | } else { |
218 | $picture = print_user_picture($student->id, $course->id, $student->picture, false, true); |
219 | } |
6b281f1f |
220 | |
eca1c454 |
221 | $fullname = fullname($student, $isteacher); |
222 | |
4969ad74 |
223 | $table->data[] = array ($picture, |
eca1c454 |
224 | "<b><a href=\"$CFG->wwwroot/user/view.php?id=$student->id&course=$course->id\">$fullname</a></b>", |
4969ad74 |
225 | "<font size=2>$student->city</font>", |
226 | "<font size=2>$student->country</font>", |
227 | "<font size=2>$lastaccess</font>"); |
228 | } |
229 | print_table($table); |
c69ce08b |
230 | |
a328425d |
231 | print_paging_bar($matchcount, $page, $perpage, |
959e11bf |
232 | "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&"); |
15c71521 |
233 | |
4969ad74 |
234 | if ($perpage != 99999) { |
235 | echo "<center><p>"; |
236 | echo "<a href=\"index.php?id=$course->id&sort=$sort&dir=$dir&perpage=99999\">".get_string("showall", "", $totalcount)."</a>"; |
237 | echo "</p></center>"; |
9ae472a3 |
238 | } |
a328425d |
239 | } |
f9903ed0 |
240 | |
241 | print_footer($course); |
242 | |
f9903ed0 |
243 | ?> |