f9903ed0 |
1 | <?PHP // $Id$ |
2 | |
3 | // Lists all the users within a given course |
4 | |
b0e3a925 |
5 | require_once("../config.php"); |
6 | require_once("../lib/countries.php"); |
7 | require_once("lib.php"); |
f9903ed0 |
8 | |
9 | require_variable($id); //course |
d578afc8 |
10 | optional_variable($sort, "lastaccess"); //how to sort students |
c5b6666e |
11 | optional_variable($dir,"DESC"); //how to sort students |
8b72b41b |
12 | optional_variable($showall,""); //show all of the students? |
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 | |
02e44e7c |
23 | $loggedinas = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>"; |
24 | |
f9903ed0 |
25 | if ($course->category) { |
fa0626c6 |
26 | print_header("$course->shortname: ".get_string("participants"), "$course->fullname", |
27 | "<A HREF=../course/view.php?id=$course->id>$course->shortname</A> -> ". |
02e44e7c |
28 | get_string("participants"), "", "", true, " ", $loggedinas); |
f9903ed0 |
29 | } else { |
fa0626c6 |
30 | print_header("$course->shortname: ".get_string("participants"), "$course->fullname", |
02e44e7c |
31 | get_string("participants"), "", "", true, " ", $loggedinas); |
f9903ed0 |
32 | } |
33 | |
cd052f8c |
34 | $string->email = get_string("email"); |
35 | $string->location = get_string("location"); |
36 | $string->lastaccess = get_string("lastaccess"); |
37 | $string->activity = get_string("activity"); |
38 | $string->unenrol = get_string("unenrol"); |
39 | $string->loginas = get_string("loginas"); |
40 | $string->fullprofile = get_string("fullprofile"); |
40a1d986 |
41 | $string->role = get_string("role"); |
42 | $string->never = get_string("never"); |
6b281f1f |
43 | $string->name = get_string("name"); |
8dbed6be |
44 | $string->day = get_string("day"); |
45 | $string->days = get_string("days"); |
46 | $string->hour = get_string("hour"); |
47 | $string->hours = get_string("hours"); |
48 | $string->min = get_string("min"); |
49 | $string->mins = get_string("mins"); |
50 | $string->sec = get_string("sec"); |
51 | $string->secs = get_string("secs"); |
f9903ed0 |
52 | |
4b232245 |
53 | if ( $teachers = get_course_teachers($course->id)) { |
b4d7002e |
54 | echo "<H2 align=center>$course->teachers</H2>"; |
f9903ed0 |
55 | foreach ($teachers as $teacher) { |
f144c305 |
56 | if ($teacher->authority > 0) { // Don't print teachers with no authority |
57 | print_user($teacher, $course, $string); |
58 | } |
f9903ed0 |
59 | } |
f9903ed0 |
60 | } |
61 | |
d578afc8 |
62 | if ($sort == "name") { |
63 | $dsort = "u.firstname"; |
64 | } else { |
65 | $dsort = "u.$sort"; |
66 | } |
67 | |
dc0dc7d5 |
68 | if (!$showall) { |
69 | $limit = "LIMIT ".USER_LARGE_CLASS; |
70 | } else { |
71 | $limit = ""; |
72 | } |
73 | |
81f186b4 |
74 | $numstudentsall = count_records("user_students", "course", $course->id); |
75 | |
dc95f4a1 |
76 | echo "<h2 align=center>$numstudentsall $course->students</h2>"; |
77 | |
69ec0a8b |
78 | if ($CFG->longtimenosee < 500) { |
79 | echo "<center><p><font size=1>("; |
80 | print_string("unusedaccounts","",$CFG->longtimenosee); |
81 | echo ")</font></p></center>"; |
82 | } |
83 | |
dc0dc7d5 |
84 | if ($students = get_course_students($course->id, "$dsort $dir $limit")) { |
6abee989 |
85 | $numstudents = count($students); |
dc0dc7d5 |
86 | if ($numstudents < USER_SMALL_CLASS) { |
6abee989 |
87 | foreach ($students as $student) { |
88 | print_user($student, $course, $string); |
89 | } |
cbb0fee0 |
90 | |
6b281f1f |
91 | } else { // Print one big table with abbreviated info |
d578afc8 |
92 | $columns = array("name", "city", "country", "lastaccess"); |
93 | |
94 | foreach ($columns as $column) { |
95 | $colname[$column] = get_string($column); |
96 | $columnsort = $column; |
97 | if ($column == "lastaccess") { |
98 | $columndir = "DESC"; |
99 | } else { |
100 | $columndir = "ASC"; |
101 | } |
102 | if ($columnsort == $sort) { |
103 | $$column = $colname["$column"]; |
104 | } else { |
dc95f4a1 |
105 | $$column = "<a href=\"index.php?id=$course->id&sort=$columnsort&dir=$columndir&showall=$showall\">".$colname["$column"]."</a>"; |
d578afc8 |
106 | } |
32b4b974 |
107 | } |
d578afc8 |
108 | |
adcb3ac5 |
109 | foreach ($students as $key => $student) { |
110 | $students[$key]->country = $COUNTRIES[$student->country]; |
111 | } |
112 | if ($sort == "country") { // Need to re-sort by full country name, not code |
113 | foreach ($students as $student) { |
114 | $sstudents[$student->id] = $student->country; |
115 | } |
116 | asort($sstudents); |
117 | foreach ($sstudents as $key => $value) { |
118 | $nstudents[] = $students[$key]; |
119 | } |
120 | $students = $nstudents; |
121 | } |
122 | |
d578afc8 |
123 | $table->head = array (" ", $name, $city, $country, $lastaccess); |
124 | $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT"); |
125 | $table->size = array ("10", "*", "*", "*", "*"); |
274f62e6 |
126 | $table->size = array ("10", "*", "*", "*", "*"); |
127 | $table->cellpadding = 2; |
128 | $table->cellspacing = 0; |
6b281f1f |
129 | |
6abee989 |
130 | foreach ($students as $student) { |
dc0dc7d5 |
131 | |
6b281f1f |
132 | if ($student->lastaccess) { |
8dbed6be |
133 | $lastaccess = format_time(time() - $student->lastaccess, $string); |
6b281f1f |
134 | } else { |
135 | $lastaccess = $string->never; |
136 | } |
137 | |
dc0dc7d5 |
138 | if ($showall and $numstudents > USER_LARGE_CLASS) { // Don't show pictures |
c69ce08b |
139 | $picture = ""; |
140 | } else { |
141 | $picture = print_user_picture($student->id, $course->id, $student->picture, false, true); |
142 | } |
143 | |
144 | $table->data[] = array ($picture, |
dc95f4a1 |
145 | "<b><a href=\"$CFG->wwwroot/user/view.php?id=$student->id&course=$course->id\">$student->firstname $student->lastname</a></b>", |
146 | "<font size=2>$student->city</font>", |
147 | "<font size=2>$student->country</font>", |
148 | "<font size=2>$lastaccess</font>"); |
6abee989 |
149 | } |
274f62e6 |
150 | print_table($table); |
9ae472a3 |
151 | |
81f186b4 |
152 | if ($numstudents < $numstudentsall and !$showall) { |
153 | $moreinfo->count = $numstudents; |
a625debc |
154 | $moreinfo->things = strtolower($course->students); |
155 | echo "<center><p>".get_string("displayingfirst", "", $moreinfo); |
81f186b4 |
156 | echo " (<a href=\"index.php?id=$course->id&sort=$sort&dir=$dir&showall=1\">".get_string("showall", "", $numstudentsall)."</a>)"; |
15c71521 |
157 | echo "</p></center>"; |
158 | } |
159 | |
9ae472a3 |
160 | } |
619431ba |
161 | } |
f9903ed0 |
162 | |
163 | print_footer($course); |
164 | |
f9903ed0 |
165 | ?> |