diff --git a/lib/datalib.php b/lib/datalib.php
index e39da3a5db0..6bde0664b36 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -1114,16 +1114,27 @@ function get_recent_enrolments($courseid, $timestart) {
*
* @param type description
*/
-function get_course_students($courseid, $sort="u.lastaccess DESC") {
+function get_course_students($courseid, $sort="u.lastaccess", $dir="ASC", $page=1, $recordsperpage=20) {
global $CFG;
+ switch ($CFG->dbtype) {
+ case "mysql":
+ $limit = "LIMIT $page,$recordsperpage";
+ break;
+ case "postgres7":
+ $limit = "LIMIT $recordsperpage OFFSET ".($page);
+ break;
+ default:
+ $limit = "LIMIT $recordsperpage,$page";
+ }
+
return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat,
u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_students s
WHERE s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0'
- ORDER BY $sort");
+ ORDER BY $sort $dir $limit");
}
/**
diff --git a/user/index.php b/user/index.php
index 2af4c3428b5..a72fbd79a09 100644
--- a/user/index.php
+++ b/user/index.php
@@ -8,8 +8,9 @@
require_variable($id); //course
optional_variable($sort, "lastaccess"); //how to sort students
- optional_variable($dir,"DESC"); //how to sort students
- optional_variable($showall,""); //show all of the students?
+ optional_variable($dir,"desc"); //how to sort students
+ optional_variable($page, "0"); // which page to show
+ optional_variable($perpage, "20"); // how many per page
if (! $course = get_record("course", "id", $id)) {
@@ -20,17 +21,6 @@
add_to_log($course->id, "user", "view all", "index.php?id=$course->id", "");
- $loggedinas = "
".user_login_string($course, $USER)."
";
-
- if ($course->category) {
- print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
- "id>$course->shortname -> ".
- get_string("participants"), "", "", true, " ", $loggedinas);
- } else {
- print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
- get_string("participants"), "", "", true, " ", $loggedinas);
- }
-
$string->email = get_string("email");
$string->location = get_string("location");
$string->lastaccess = get_string("lastaccess");
@@ -50,30 +40,42 @@
$string->sec = get_string("sec");
$string->secs = get_string("secs");
- if ( $teachers = get_course_teachers($course->id)) {
- echo "$course->teachers
";
- foreach ($teachers as $teacher) {
- if ($teacher->authority > 0) { // Don't print teachers with no authority
- print_user($teacher, $course, $string);
+ $loggedinas = "".user_login_string($course, $USER)."
";
+
+ $showteachers = ($page == 0 and $sort == "lastaccess" and $dir == "desc");
+
+ if ($showteachers) {
+ $participantslink = get_string("participants");
+ } else {
+ $participantslink = "id\">".get_string("participants")."";
+ }
+
+ if ($course->category) {
+ print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
+ "id>$course->shortname -> ".
+ "$participantslink", "", "", true, " ", $loggedinas);
+ } else {
+ print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
+ "$participantslink", "", "", true, " ", $loggedinas);
+ }
+
+
+ if ($showteachers) {
+ if ( $teachers = get_course_teachers($course->id)) {
+ echo "$course->teachers
";
+ foreach ($teachers as $teacher) {
+ if ($teacher->authority > 0) { // Don't print teachers with no authority
+ print_user($teacher, $course, $string);
+ }
}
}
}
- if ($sort == "name") {
- $dsort = "u.firstname";
- } else {
- $dsort = "u.$sort";
- }
+ $dsort = "u.$sort";
- if (!$showall) {
- $limit = "LIMIT ".USER_LARGE_CLASS;
- } else {
- $limit = "";
- }
+ $totalcount = count_records("user_students", "course", $course->id);
- $numstudentsall = count_records("user_students", "course", $course->id);
-
- echo "$numstudentsall $course->students
";
+ echo "$totalcount $course->students
";
if ($CFG->longtimenosee < 500) {
echo "(";
@@ -81,83 +83,93 @@
echo ")
";
}
- if ($students = get_course_students($course->id, "$dsort $dir $limit")) {
- $numstudents = count($students);
- if ($numstudents < USER_SMALL_CLASS) {
- foreach ($students as $student) {
- print_user($student, $course, $string);
- }
-
- } else { // Print one big table with abbreviated info
- $columns = array("name", "city", "country", "lastaccess");
-
- foreach ($columns as $column) {
- $colname[$column] = get_string($column);
- $columnsort = $column;
- if ($column == "lastaccess") {
- $columndir = "DESC";
- } else {
- $columndir = "ASC";
- }
- if ($columnsort == $sort) {
- $$column = $colname["$column"];
- } else {
- $$column = "id&sort=$columnsort&dir=$columndir&showall=$showall\">".$colname["$column"]."";
- }
- }
-
- foreach ($students as $key => $student) {
- $students[$key]->country = $COUNTRIES[$student->country];
- }
- if ($sort == "country") { // Need to re-sort by full country name, not code
- foreach ($students as $student) {
- $sstudents[$student->id] = $student->country;
- }
- asort($sstudents);
- foreach ($sstudents as $key => $value) {
- $nstudents[] = $students[$key];
- }
- $students = $nstudents;
- }
-
- $table->head = array (" ", $name, $city, $country, $lastaccess);
- $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT");
- $table->size = array ("10", "*", "*", "*", "*");
- $table->size = array ("10", "*", "*", "*", "*");
- $table->cellpadding = 2;
- $table->cellspacing = 0;
-
- foreach ($students as $student) {
-
- if ($student->lastaccess) {
- $lastaccess = format_time(time() - $student->lastaccess, $string);
- } else {
- $lastaccess = $string->never;
- }
-
- if ($showall and $numstudents > USER_LARGE_CLASS) { // Don't show pictures
- $picture = "";
- } else {
- $picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
- }
-
- $table->data[] = array ($picture,
- "wwwroot/user/view.php?id=$student->id&course=$course->id\">$student->firstname $student->lastname",
- "$student->city",
- "$student->country",
- "$lastaccess");
- }
- print_table($table);
-
- if ($numstudents < $numstudentsall and !$showall) {
- $moreinfo->count = $numstudents;
- $moreinfo->things = strtolower($course->students);
- echo "".get_string("displayingfirst", "", $moreinfo);
- echo " (id&sort=$sort&dir=$dir&showall=1\">".get_string("showall", "", $numstudentsall).")";
- echo "
";
- }
+ if (0 < $totalcount and $totalcount < USER_SMALL_CLASS) { // Print simple listing
+ foreach ($students as $student) {
+ print_user($student, $course, $string);
}
+
+ } else if ($students = get_course_students($course->id, $dsort, $dir, $page*$perpage, $perpage)) {
+
+ print_paging_bar($totalcount, $page, $perpage,
+ "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&");
+
+ // Print one big table with abbreviated info
+ $columns = array("firstname", "lastname", "city", "country", "lastaccess");
+
+ foreach ($columns as $column) {
+ $colname[$column] = get_string($column);
+ if ($sort != $column) {
+ $columnicon = "";
+ if ($column == "lastaccess") {
+ $columndir = "desc";
+ } else {
+ $columndir = "asc";
+ }
+ } else {
+ $columndir = $dir == "asc" ? "desc":"asc";
+ if ($column == "lastaccess") {
+ $columnicon = $dir == "asc" ? "up":"down";
+ } else {
+ $columnicon = $dir == "asc" ? "down":"up";
+ }
+ $columnicon = " pixpath/t/$columnicon.gif\" />";
+ }
+ $$column = "id&sort=$column&dir=$columndir\">".$colname["$column"]."$columnicon";
+ }
+
+ foreach ($students as $key => $student) {
+ $students[$key]->country = $COUNTRIES[$student->country];
+ }
+ if ($sort == "country") { // Need to re-sort by full country name, not code
+ foreach ($students as $student) {
+ $sstudents[$student->id] = $student->country;
+ }
+ asort($sstudents);
+ foreach ($sstudents as $key => $value) {
+ $nstudents[] = $students[$key];
+ }
+ $students = $nstudents;
+ }
+
+ $table->head = array (" ", "$firstname / $lastname", $city, $country, $lastaccess);
+ $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT");
+ $table->size = array ("10", "*", "*", "*", "*");
+ $table->size = array ("10", "*", "*", "*", "*");
+ $table->cellpadding = 2;
+ $table->cellspacing = 0;
+
+ foreach ($students as $student) {
+
+ if ($student->lastaccess) {
+ $lastaccess = format_time(time() - $student->lastaccess, $string);
+ } else {
+ $lastaccess = $string->never;
+ }
+
+ if ($showall and $numstudents > USER_LARGE_CLASS) { // Don't show pictures
+ $picture = "";
+ } else {
+ $picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
+ }
+
+ $table->data[] = array ($picture,
+ "wwwroot/user/view.php?id=$student->id&course=$course->id\">$student->firstname $student->lastname",
+ "$student->city",
+ "$student->country",
+ "$lastaccess");
+ }
+ print_table($table);
+
+ print_paging_bar($totalcount, $page, $perpage,
+ "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&");
+
+ if ($perpage != 99999) {
+ echo "";
+ echo "id&sort=$sort&dir=$dir&perpage=99999\">".get_string("showall", "", $totalcount)."";
+ echo "
";
+ }
+
}
print_footer($course);