3 // Lists all the users within a given course
5 require_once("../config.php");
7 define('USER_SMALL_CLASS', 20); // Below this is considered small
8 define('USER_LARGE_CLASS', 200); // Above this is considered large
10 require_variable($id); //course
11 optional_variable($sort, "lastaccess"); //how to sort students
12 optional_variable($dir,"desc"); //how to sort students
13 optional_variable($page, "0"); // which page to show
14 optional_variable($lastinitial, ""); // only show students with this last initial
15 optional_variable($firstinitial, ""); // only show students with this first initial
16 optional_variable($perpage, "20"); // how many per page
19 if (! $course = get_record("course", "id", $id)) {
20 error("Course ID is incorrect");
23 require_login($course->id
);
25 add_to_log($course->id
, "user", "view all", "index.php?id=$course->id", "");
27 $isteacher = isteacher($course->id
);
28 $showteachers = ($page == 0 and $sort == "lastaccess" and $dir == "desc");
31 $participantslink = get_string("participants");
33 $participantslink = "<a href=\"index.php?id=$course->id\">".get_string("participants")."</a>";
36 $isseparategroups = ($course->groupmode
== SEPARATEGROUPS
and $course->groupmodeforce
and
37 !isteacheredit($course->id
));
39 $currentgroup = $isseparategroups ?
get_current_group($course->id
) : NULL;
41 if ($course->category
) {
42 print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
43 "<A HREF=../course/view.php?id=$course->id>$course->shortname</A> -> ".
44 "$participantslink", "", "", true, " ", navmenu($course));
46 print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
47 "$participantslink", "", "", true, " ", navmenu($course));
51 if ($teachers = get_course_teachers($course->id
)) {
52 echo "<h2 align=\"center\">$course->teachers</h2>";
53 foreach ($teachers as $teacher) {
54 if ($isseparategroups) {
55 if ($teacher->editall
or ismember($currentgroup, $teacher->id
)) {
56 print_user($teacher, $course);
58 } else if ($teacher->authority
> 0) { // Don't print teachers with no authority
59 print_user($teacher, $course);
65 if ($sort == "lastaccess") {
66 $dsort = "s.timeaccess";
71 $students = get_course_students($course->id
, $dsort, $dir, $page*$perpage,
72 $perpage, $firstinitial, $lastinitial, $currentgroup);
74 $totalcount = count_course_students($course, "", "", "", $currentgroup);
76 if ($firstinitial or $lastinitial) {
77 $matchcount = count_course_students($course, "", $firstinitial, $lastinitial, $currentgroup);
79 $matchcount = $totalcount;
83 echo "<h2 align=center>$totalcount $course->students</h2>";
85 if (($CFG->longtimenosee
< 500) and (!$page) and ($sort == "lastaccess")) {
86 echo "<center><p><font size=1>(";
87 print_string("unusedaccounts","",$CFG->longtimenosee
);
88 echo ")</font></p></center>";
91 /// Print paging bars if necessary
93 if ($totalcount > $perpage) {
94 $alphabet = explode(',', get_string('alphabet'));
95 $strall = get_string("all");
98 /// Bar of first initials
100 echo "<center><p align=\"center\">";
101 echo get_string("firstname")." : ";
103 echo " <a href=\"index.php?id=$course->id&sort=firstname&dir=ASC&".
104 "perpage=$perpage&lastinitial=$lastinitial\">$strall</a> ";
106 echo " <b>$strall</b> ";
108 foreach ($alphabet as $letter) {
109 if ($letter == $firstinitial) {
110 echo " <b>$letter</b> ";
112 echo " <a href=\"index.php?id=$course->id&sort=firstname&dir=ASC&".
113 "perpage=$perpage&lastinitial=$lastinitial&firstinitial=$letter\">$letter</a> ";
118 /// Bar of last initials
120 echo get_string("lastname")." : ";
122 echo " <a href=\"index.php?id=$course->id&sort=lastname&dir=ASC&".
123 "perpage=$perpage&firstinitial=$firstinitial\">$strall</a> ";
125 echo " <b>$strall</b> ";
127 foreach ($alphabet as $letter) {
128 if ($letter == $lastinitial) {
129 echo " <b>$letter</b> ";
131 echo " <a href=\"index.php?id=$course->id&sort=lastname&dir=ASC&".
132 "perpage=$perpage&firstinitial=$firstinitial&lastinitial=$letter\">$letter</a> ";
138 print_paging_bar($matchcount, $page, $perpage,
139 "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&");
143 if ($matchcount == 0) {
144 print_heading(get_string("nostudentsfound", "", $course->students
));
146 } if (0 < $matchcount and $matchcount < USER_SMALL_CLASS
) { // Print simple listing
147 foreach ($students as $student) {
148 print_user($student, $course);
151 } else if ($matchcount > 0) {
153 // Print one big table with abbreviated info
154 $columns = array("firstname", "lastname", "city", "country", "lastaccess");
156 $countries = get_list_of_countries();
158 $strnever = get_string("never");
160 $datestring->day
= get_string("day");
161 $datestring->days
= get_string("days");
162 $datestring->hour
= get_string("hour");
163 $datestring->hours
= get_string("hours");
164 $datestring->min
= get_string("min");
165 $datestring->mins
= get_string("mins");
166 $datestring->sec
= get_string("sec");
167 $datestring->secs
= get_string("secs");
169 foreach ($columns as $column) {
170 $colname[$column] = get_string($column);
171 if ($sort != $column) {
173 if ($column == "lastaccess") {
179 $columndir = $dir == "asc" ?
"desc":"asc";
180 if ($column == "lastaccess") {
181 $columnicon = $dir == "asc" ?
"up":"down";
183 $columnicon = $dir == "asc" ?
"down":"up";
185 $columnicon = " <img src=\"$CFG->pixpath/t/$columnicon.gif\" />";
187 $
$column = "<a href=\"index.php?id=$course->id&sort=$column&dir=$columndir\">".$colname["$column"]."</a>$columnicon";
190 foreach ($students as $key => $student) {
191 $students[$key]->country
= $countries[$student->country
];
193 if ($sort == "country") { // Need to re-sort by full country name, not code
194 foreach ($students as $student) {
195 $sstudents[$student->id
] = $student->country
;
198 foreach ($sstudents as $key => $value) {
199 $nstudents[] = $students[$key];
201 $students = $nstudents;
205 $table->head
= array (" ", "$firstname / $lastname", $city, $country, $lastaccess);
206 $table->align
= array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT");
207 $table->size
= array ("10", "*", "*", "*", "*");
208 $table->size
= array ("10", "*", "*", "*", "*");
209 $table->cellpadding
= 4;
210 $table->cellspacing
= 0;
212 foreach ($students as $student) {
214 if ($student->lastaccess
) {
215 $lastaccess = format_time(time() - $student->lastaccess
, $datestring);
217 $lastaccess = $strnever;
220 $picture = print_user_picture($student->id
, $course->id
, $student->picture
, false, true);
222 $fullname = fullname($student, $isteacher);
224 $table->data
[] = array ($picture,
225 "<b><a href=\"$CFG->wwwroot/user/view.php?id=$student->id&course=$course->id\">$fullname</a></b>",
226 "<font size=2>$student->city</font>",
227 "<font size=2>$student->country</font>",
228 "<font size=2>$lastaccess</font>");
232 print_paging_bar($matchcount, $page, $perpage,
233 "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&");
235 if ($perpage != 99999) {
237 echo "<a href=\"index.php?id=$course->id&sort=$sort&dir=$dir&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
238 echo "</p></center>";
242 print_footer($course);