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);
define('SHOW_ALL_PAGE_SIZE', 5000);
$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?
$accesssince = optional_param('accesssince',0,PARAM_INT); // filter by last access. -1 = never
$search = optional_param('search','',PARAM_CLEAN);
$roleid = optional_param('roleid', 0, PARAM_INT); // optional roleid
$contextid = optional_param('contextid', PARAM_INT); // one of this or
$courseid = optional_param('id', PARAM_INT); // this are required
$showteachers = $showteachers && empty($search); // if we're searching, we just want students.
if ($contextid) {
if (! $context = get_context_instance_by_id($contextid)) {
error("Context ID is incorrect");
}
if (! $course = get_record('course', 'id', $context->instanceid)) {
error("Course ID is incorrect");
}
} else {
if (! $course = get_record('course', 'id', $courseid)) {
error("Course ID is incorrect");
}
if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {
error("Context ID is incorrect");
}
}
require_login($course->id);
if ($roles = get_roles_used_in_context($context)) {
foreach ($roles as $role) {
$options[$role->id] = $role->name;
}
} else { // no roles yet
if (has_capability('moodle/user:assign', $context)) {
redirect($CFG->wwwroot.'/admin/roles/assign.php?contextid='.$context->id);
} else {
error ('no participants found for this course');
}
}
require_capability('moodle/course:viewparticipants', $context);
if (!$course->category) {
if (!$CFG->showsiteparticipantslist and !has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
print_header("$course->shortname: ".get_string('participants'), $course->fullname,
get_string('participants'), "", "", true, " ", navmenu($course));
notice(get_string('sitepartlist0'));
}
if ($CFG->showsiteparticipantslist < 2 and !isteacherinanycourse()) {
print_header("$course->shortname: ".get_string('participants'), $course->fullname,
get_string('participants'), "", "", true, " ", navmenu($course));
notice(get_string('sitepartlist1'));
}
}
add_to_log($course->id, 'user', 'view all', 'index.php?id='.$course->id, '');
$isteacher = isteacher($course->id);
if (empty($isteacher)) {
$search = false;
}
$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
!has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $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?contextid='.$context->id.'&roleid='.$roleid.'&id='.$course->id.'&group='.$currentgroup.'&perpage='.$perpage.'&teachers='.$showteachers.'&accesssince='.$accesssince.'&search='.$search;
/// 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));
}
//setting up tags
if ($course->id == SITEID) {
$filtertype = 'site';
} else if ($course->id && !$currentgroup) {
$filtertype = 'course';
$filterselect = $course->id;
} else {
$filtertype = 'group';
$filterselect = $currentgroup;
}
$currenttab = 'participants';
$user = $USER;
require_once($CFG->dirroot .'/user/tabs.php');
/// Get the hidden field list
if (has_capability('moodle/course:viewhiddenuserfields', get_context_instance(CONTEXT_COURSE, $course->id))) {
$hiddenfields = array(); // teachers and admins are allowed to see everything
} else {
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
}
/// If there are multiple Roles in the course, then show a drop down menu for switching
if ($roles = get_roles_used_in_context($context)) {
$rolenames = array();
foreach ($roles as $role) {
$rolenames[$role->id] = $role->name;
}
if (empty($roleid)) {
$roleid = array_shift(array_keys($rolenames)); // get first element
}
echo '
';
}
/// Print settings and things in a table across the top
echo '';
/// Print my course menus
if ($mycourses = get_my_courses($USER->id)) {
echo '';
print_string('mycourses');
echo ': ';
$courselist = array();
foreach ($mycourses as $mycourse) {
$courselist[$mycourse->id] = $mycourse->shortname;
}
popup_form($CFG->wwwroot.'/user/index.php?contextid='.$context->id.'&roleid='.$roleid.'&id=',
$courselist, 'courseform',$course->id);
echo ' | ';
}
if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id)))) {
if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
echo '';
print_group_menu($groups, $groupmode, $currentgroup, $baseurl);
echo ' | ';
}
}
if (!empty($isteacher)) {
// get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
// this might not work anymore because you always going to get yourself as the most recent entry? added $USER!=$user ch
$minlastaccess = get_field_sql('SELECT min(timeaccess) FROM '.$CFG->prefix.'user_lastaccess WHERE courseid = '.$course->id.' AND timeaccess != 0 AND userid!='.$USER->id);
$lastaccess0exists = record_exists('user_lastaccess','courseid',$course->id,'timeaccess',0);
$now = usergetmidnight(time());
$timeaccess = array();
// makes sense for this to go first.
$timeoptions[0] = get_string('selectperiod');
// days
for ($i = 1; $i < 7; $i++) {
if (strtotime('-'.$i.' days',$now) >= $minlastaccess) {
$timeoptions[strtotime('-'.$i.' days',$now)] = get_string('numdays','moodle',$i);
}
}
// weeks
for ($i = 1; $i < 10; $i++) {
if (strtotime('-'.$i.' weeks',$now) >= $minlastaccess) {
$timeoptions[strtotime('-'.$i.' weeks',$now)] = get_string('numweeks','moodle',$i);
}
}
// months
for ($i = 2; $i < 12; $i++) {
if (strtotime('-'.$i.' months',$now) >= $minlastaccess) {
$timeoptions[strtotime('-'.$i.' months',$now)] = get_string('nummonths','moodle',$i);
}
}
// try a year
if (strtotime('-1 year',$now) >= $minlastaccess) {
$timeoptions[strtotime('-1 year',$now)] = get_string('lastyear');
}
if (!empty($lastaccess0exists)) {
$timeoptions[-1] = get_string('never');
}
if (count($timeoptions) > 1) {
echo '';
echo get_string('usersnoaccesssince').': ';
$baseurl = preg_replace('/&accesssince='.$accesssince.'/','',$baseurl);
echo popup_form($baseurl.'&accesssince=',$timeoptions,'timeoptions',$accesssince,'','','',true);
echo ' | ';
}
}
echo '';
echo get_string('userlist').': ';
$formatmenu = array( '0' => get_string('detailedless'),
'1' => get_string('detailedmore'));
echo popup_form($baseurl.'&mode=', $formatmenu, 'formatmenu', $fullmode, '', '', '', true);
echo ' |
';
if ($currentgroup and (!$isseparategroups or has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $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 '';
print_group_picture($group, $course->id, true, false, false);
echo ' | ';
echo ''.$group->name;
if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo ' ';
echo ' ';
echo '';
}
echo '';
echo format_text($group->description);
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 ($isteacher) {
echo '
';
echo '';
}
if ($isteacher && $totalcount > ($perpage*3)) {
echo ''."\n";
}
if ($perpage == SHOW_ALL_PAGE_SIZE) {
echo '';
}
else if ($matchcount > 0 && $perpage < $matchcount) {
echo '';
}
} // end of if ($roleid);
print_footer($course);
function get_lastaccess_sql($accesssince='') {
if (empty($accesssince)) {
return '';
}
if ($accesssince == -1) { // never
return ' AND ul.timeaccess = 0';
} else {
return ' AND ul.timeaccess != 0 AND timeaccess < '.$accesssince;
}
}
?>