libdir.'/tablelib.php');
define('USER_SMALL_CLASS', 20); // Below this is considered small
define('USER_LARGE_CLASS', 200); // Above this is considered large
define('DEFAULT_PAGE_SIZE', 20);
$id = required_param('id', PARAM_INT); // Course id
$group = optional_param('group', -1, PARAM_INT); // Group to show
$page = optional_param('page', 0, PARAM_INT); // which page to show
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // how many per page
$mode = optional_param('mode', NULL); // '0' for less details, '1' for more
$showteachers = optional_param('teachers', 1, PARAM_INT); // do we want to see the teacher list?
if (! $course = get_record('course', 'id', $id)) {
error("Course ID is incorrect");
}
require_login($course->id);
if (!$course->category) {
if (!$CFG->showsiteparticipantslist and !isteacher(SITEID)) {
notice(get_string('sitepartlist0'));
}
if ($CFG->showsiteparticipantslist < 2 and !isteacherinanycourse()) {
notice(get_string('sitepartlist1'));
}
}
add_to_log($course->id, 'user', 'view all', 'index.php?id='.$course->id, '');
$isteacher = isteacher($course->id);
$countries = get_list_of_countries();
$strnever = get_string('never');
$datestring->day = get_string('day');
$datestring->days = get_string('days');
$datestring->hour = get_string('hour');
$datestring->hours = get_string('hours');
$datestring->min = get_string('min');
$datestring->mins = get_string('mins');
$datestring->sec = get_string('sec');
$datestring->secs = get_string('secs');
if ($mode !== NULL) {
$SESSION->userindexmode = $fullmode = ($mode == 1);
} else if (isset($SESSION->userindexmode)) {
$fullmode = $SESSION->userindexmode;
} else {
$fullmode = false;
}
/// Check to see if groups are being used in this forum
/// and if so, set $currentgroup to reflect the current group
$groupmode = groupmode($course); // Groups are being used
$currentgroup = get_and_set_current_group($course, $groupmode, $group);
if (!$currentgroup) { // To make some other functions work better later
$currentgroup = NULL;
}
$isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and
!isteacheredit($course->id));
if ($isseparategroups and (!$currentgroup) ) { //XXX
print_heading(get_string("notingroup", "forum"));
print_footer($course);
exit;
}
// Should use this variable so that we don't break stuff every time a variable is added or changed.
$baseurl = $CFG->wwwroot.'/user/index.php?id='.$course->id.'&group='.$currentgroup.'&perpage='.$perpage.'&teachers='.$showteachers;
/// Print headers
if ($course->category) {
print_header("$course->shortname: ".get_string('participants'), $course->fullname,
"id\">$course->shortname -> ".
get_string('participants'), "", "", true, " ", navmenu($course));
} else {
print_header("$course->shortname: ".get_string('participants'), $course->fullname,
get_string('participants'), "", "", true, " ", navmenu($course));
}
/// Print settings and things in a table across the top
echo '
';
if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
echo '
';
if ($currentgroup and (!$isseparategroups or isteacheredit($course->id))) { /// Display info about the group
if ($group = get_record('groups', 'id', $currentgroup)) {
if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) {
echo '
';
}
}
}
$exceptions = array(); // This will be an array of userids that are shown as teachers and thus
// do not have to be shown as users as well. Only relevant on site course.
if($showteachers) {
$tablecolumns = array('picture', 'fullname', 'city', 'country', 'lastaccess');
$tableheaders = array('', get_string('fullname'), get_string('city'), get_string('country'), get_string('lastaccess'));
$table = new flexible_table('user-index-teachers');
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($baseurl);
$table->sortable(true, 'lastaccess', SORT_DESC);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'teachers');
$table->set_attribute('class', 'generaltable generalbox');
$table->setup();
if($whereclause = $table->get_sql_where()) {
$whereclause .= ' AND ';
}
$teachersql = "SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest,
u.email, u.maildisplay, u.city, u.country, u.lastlogin, u.picture, u.lang, u.timezone,
u.emailstop, t.authority,t.role,t.editall,t.timeaccess as lastaccess, m.groupid
FROM {$CFG->prefix}user u
LEFT JOIN {$CFG->prefix}user_teachers t ON t.userid = u.id
LEFT JOIN {$CFG->prefix}groups_members m ON m.userid = u.id ";
if($isseparategroups) {
$whereclause .= '(t.editall OR groupid = '.$currentgroup.') AND ';
}
else if ($currentgroup) { // Displaying a group by choice
$whereclause .= 'groupid = '.$currentgroup.' AND ';
}
$teachersql .= 'WHERE '.$whereclause.' t.course = '.$course->id.' AND u.deleted = 0 AND u.confirmed = 1 AND t.authority > 0';
if($sortclause = $table->get_sql_sort()) {
$teachersql .= ' ORDER BY '.$sortclause;
}
$teachers = get_records_sql($teachersql);
if(!empty($teachers)) {
echo '
'.$course->teachers;
echo ' ';
echo '';
if (isadmin() or ($course->category and (iscreator() or (isteacheredit($course->id) and !empty($CFG->teacherassignteachers))))) {
echo ' ';
echo '';
}
echo '
'.$course->teachers;
echo ' ';
echo '';
if (isadmin() or ($course->category and (iscreator() or (isteacheredit($course->id) and !empty($CFG->teacherassignteachers))))) {
echo ' ';
echo '';
}
echo '
';
}
$guest = get_guest();
$exceptions[] = $guest->id;
$tablecolumns = array('picture', 'fullname', 'city', 'country', 'lastaccess');
$tableheaders = array('', get_string('fullname'), get_string('city'), get_string('country'), get_string('lastaccess'));
$table = new flexible_table('user-index-students');
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($baseurl);
$table->sortable(true, 'lastaccess', SORT_DESC);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'students');
$table->set_attribute('class', 'generaltable generalbox');
$table->set_control_variables(array(
TABLE_VAR_SORT => 'ssort',
TABLE_VAR_HIDE => 'shide',
TABLE_VAR_SHOW => 'sshow',
TABLE_VAR_IFIRST => 'sifirst',
TABLE_VAR_ILAST => 'silast',
TABLE_VAR_PAGE => 'spage'
));
$table->setup();
if(SITEID == $course->id) {
$select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country,
u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, u.lastaccess ';
$from = 'FROM '.$CFG->prefix.'user u ';
$where = 'WHERE confirmed = 1 AND u.deleted = 0 ';
}
else {
$select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country,
u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, s.timeaccess AS lastaccess ';
$from = 'FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'user_students s ON s.userid = u.id ';
$where = 'WHERE s.course = '.$course->id.' AND u.deleted = 0 ';
}
if ($currentgroup) { // Displaying a group by choice
// FIX: TODO: This will not work if $currentgroup == 0, i.e. "those not in a group"
$from .= 'LEFT JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid ';
$where .= ' AND gm.groupid = '.$currentgroup;
}
if($course->id == SITEID) {
$where .= ' AND u.id NOT IN ('.implode(',', $exceptions).')';
}
$totalcount = count_records_sql('SELECT COUNT(*) '.$from.$where);
if($table->get_sql_where()) {
$where .= ' AND '.$table->get_sql_where();
}
if($table->get_sql_sort()) {
$sort = ' ORDER BY '.$table->get_sql_sort();
}
else {
$sort = '';
}
if($table->get_sql_sort()) {
$sort = ' ORDER BY '.$table->get_sql_sort();
}
else {
$sort = '';
}
$matchcount = count_records_sql('SELECT COUNT(*) '.$from.$where);
$table->initialbars($totalcount > $perpage);
$table->pagesize($perpage, $matchcount);
if($table->get_page_start() !== '' && $table->get_page_size() !== '') {
$limit = ' '.sql_paging_limit($table->get_page_start(), $table->get_page_size());
}
else {
$limit = '';
}
$students = get_records_sql($select.$from.$where.$sort.$limit);
$a->count = $totalcount;
$a->items = $totalcount == 1 ? $course->student : $course->students;
echo '