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