2001-11-22 06:23:56 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
|
|
|
// Lists all the users within a given course
|
|
|
|
|
2005-06-03 23:20:01 +00:00
|
|
|
require_once('../config.php');
|
2005-04-27 18:30:02 +00:00
|
|
|
require_once($CFG->libdir.'/tablelib.php');
|
2004-01-10 16:41:29 +00:00
|
|
|
|
|
|
|
define('USER_SMALL_CLASS', 20); // Below this is considered small
|
|
|
|
define('USER_LARGE_CLASS', 200); // Above this is considered large
|
2005-06-03 23:20:01 +00:00
|
|
|
define('DEFAULT_PAGE_SIZE', 20);
|
2006-09-15 14:32:35 +00:00
|
|
|
define('SHOW_ALL_PAGE_SIZE', 5000);
|
2007-11-23 00:23:39 +00:00
|
|
|
define('MODE_BRIEF', 0);
|
|
|
|
define('MODE_USERDETAILS', 1);
|
|
|
|
define('MODE_ENROLDETAILS', 2);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2005-06-03 23:20:01 +00:00
|
|
|
$page = optional_param('page', 0, PARAM_INT); // which page to show
|
|
|
|
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // how many per page
|
2007-11-23 00:23:39 +00:00
|
|
|
$mode = optional_param('mode', NULL); // use the MODE_ constants
|
2008-04-18 08:35:16 +00:00
|
|
|
$accesssince = optional_param('accesssince',0,PARAM_INT); // filter by last access. -1 = never
|
2005-11-19 13:19:34 +00:00
|
|
|
$search = optional_param('search','',PARAM_CLEAN);
|
2008-04-18 08:35:16 +00:00
|
|
|
$roleid = optional_param('roleid', 0, PARAM_INT); // optional roleid, -1 means all site users on frontpage
|
2006-08-14 08:38:49 +00:00
|
|
|
|
2008-04-18 08:35:16 +00:00
|
|
|
$contextid = optional_param('contextid', 0, PARAM_INT); // one of this or
|
|
|
|
$courseid = optional_param('id', 0, PARAM_INT); // this are required
|
2009-08-18 05:19:25 +00:00
|
|
|
|
2009-07-28 02:45:13 +00:00
|
|
|
$PAGE->set_url('user/index.php', compact('page', 'perpage', 'mode', 'accesssince', 'search', 'roleid', 'contextid', 'courseid'));
|
2005-11-17 03:09:07 +00:00
|
|
|
|
2006-08-14 08:38:49 +00:00
|
|
|
if ($contextid) {
|
|
|
|
if (! $context = get_context_instance_by_id($contextid)) {
|
2008-07-21 07:18:58 +00:00
|
|
|
print_error('invalidcontext');
|
2006-08-14 08:38:49 +00:00
|
|
|
}
|
2008-05-31 11:13:21 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id'=>$context->instanceid))) {
|
2008-07-21 07:18:58 +00:00
|
|
|
print_error('invalidcourseid');
|
2006-08-14 08:38:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-05-31 11:13:21 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id'=>$courseid))) {
|
2008-07-21 07:18:58 +00:00
|
|
|
print_error('invalidcourseid');
|
2006-08-14 08:38:49 +00:00
|
|
|
}
|
|
|
|
if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {
|
2008-07-21 07:18:58 +00:00
|
|
|
print_error('invalidcontext');
|
2006-08-14 08:38:49 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2006-10-01 19:55:47 +00:00
|
|
|
// not needed anymore
|
|
|
|
unset($contextid);
|
|
|
|
unset($courseid);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2007-03-05 20:13:16 +00:00
|
|
|
require_login($course);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2008-07-28 07:17:34 +00:00
|
|
|
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
2007-10-02 03:37:30 +00:00
|
|
|
$frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID);
|
2007-03-05 20:13:16 +00:00
|
|
|
|
2007-10-02 03:37:30 +00:00
|
|
|
if ($context->id != $frontpagectx->id) {
|
2007-12-20 15:11:05 +00:00
|
|
|
require_capability('moodle/course:viewparticipants', $context);
|
2007-10-02 03:37:30 +00:00
|
|
|
} else {
|
2008-07-28 07:17:34 +00:00
|
|
|
require_capability('moodle/site:viewparticipants', $systemcontext);
|
2008-04-18 08:35:16 +00:00
|
|
|
// override the default on frontpage
|
|
|
|
$roleid = optional_param('roleid', -1, PARAM_INT);
|
2006-11-20 20:47:17 +00:00
|
|
|
}
|
|
|
|
|
2007-10-02 03:37:30 +00:00
|
|
|
/// front page course is different
|
2006-11-20 20:47:17 +00:00
|
|
|
$rolenames = array();
|
2007-03-30 16:01:44 +00:00
|
|
|
$avoidroles = array();
|
2006-11-20 20:47:17 +00:00
|
|
|
|
2009-08-10 03:40:04 +00:00
|
|
|
$rolenamesurl = new moodle_url("$CFG->wwwroot/user/index.php?contextid=$context->id&sifirst=&silast=");
|
|
|
|
|
2006-11-20 20:47:17 +00:00
|
|
|
if ($roles = get_roles_used_in_context($context, true)) {
|
2007-08-17 19:09:11 +00:00
|
|
|
// We should ONLY allow roles with moodle/course:view because otherwise we get little niggly issues
|
2007-03-30 16:01:44 +00:00
|
|
|
// like MDL-8093
|
2007-08-17 19:09:11 +00:00
|
|
|
// We should further exclude "admin" users (those with "doanything" at site level) because
|
2006-11-20 20:47:17 +00:00
|
|
|
// Otherwise they appear in every participant list
|
|
|
|
|
2007-03-30 16:01:44 +00:00
|
|
|
$canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
|
2008-07-28 07:17:34 +00:00
|
|
|
$doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $systemcontext);
|
2006-08-25 08:27:27 +00:00
|
|
|
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($context->id == $frontpagectx->id) {
|
|
|
|
//we want admins listed on frontpage too
|
|
|
|
foreach ($doanythingroles as $dar) {
|
|
|
|
$canviewroles[$dar->id] = $dar;
|
|
|
|
}
|
|
|
|
$doanythingroles = array();
|
|
|
|
}
|
|
|
|
|
2006-08-25 08:27:27 +00:00
|
|
|
foreach ($roles as $role) {
|
2007-03-30 16:01:44 +00:00
|
|
|
if (!isset($canviewroles[$role->id])) { // Avoid this role (eg course creator)
|
|
|
|
$avoidroles[] = $role->id;
|
|
|
|
unset($roles[$role->id]);
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-20 20:47:17 +00:00
|
|
|
if (isset($doanythingroles[$role->id])) { // Avoid this role (ie admin)
|
2007-03-30 16:01:44 +00:00
|
|
|
$avoidroles[] = $role->id;
|
2006-11-20 20:47:17 +00:00
|
|
|
unset($roles[$role->id]);
|
|
|
|
continue;
|
|
|
|
}
|
2007-03-22 08:11:30 +00:00
|
|
|
$rolenames[$role->id] = strip_tags(role_get_name($role, $context)); // Used in menus etc later on
|
2006-08-25 08:27:27 +00:00
|
|
|
}
|
2006-11-20 20:47:17 +00:00
|
|
|
}
|
|
|
|
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($context->id == $frontpagectx->id and $CFG->defaultfrontpageroleid) {
|
|
|
|
// default frontpage role is assigned to all site users
|
|
|
|
unset($rolenames[$CFG->defaultfrontpageroleid]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// no roles to display yet?
|
2007-10-02 03:37:30 +00:00
|
|
|
// frontpage course is an exception, on the front page course we should display all users
|
|
|
|
if (empty($rolenames) && $context->id != $frontpagectx->id) {
|
2007-08-31 08:21:16 +00:00
|
|
|
if (has_capability('moodle/role:assign', $context)) {
|
2006-10-01 19:55:47 +00:00
|
|
|
redirect($CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id);
|
2006-08-25 08:27:27 +00:00
|
|
|
} else {
|
2008-07-21 07:18:58 +00:00
|
|
|
print_error('noparticipants');
|
2006-08-25 08:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-03 23:20:01 +00:00
|
|
|
add_to_log($course->id, 'user', 'view all', 'index.php?id='.$course->id, '');
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2006-09-28 06:41:07 +00:00
|
|
|
$bulkoperations = has_capability('moodle/course:bulkmessaging', $context);
|
2005-11-17 03:09:07 +00:00
|
|
|
|
2005-04-27 18:30:02 +00:00
|
|
|
$countries = get_list_of_countries();
|
|
|
|
|
2005-06-03 23:20:01 +00:00
|
|
|
$strnever = get_string('never');
|
2005-04-27 18:30:02 +00:00
|
|
|
|
2007-02-15 03:14:40 +00:00
|
|
|
$datestring->year = get_string('year');
|
|
|
|
$datestring->years = get_string('years');
|
2005-06-03 23:20:01 +00:00
|
|
|
$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');
|
2002-09-22 14:06:38 +00:00
|
|
|
|
2005-03-22 16:04:10 +00:00
|
|
|
if ($mode !== NULL) {
|
2007-11-23 00:23:39 +00:00
|
|
|
$mode = (int)$mode;
|
|
|
|
$SESSION->userindexmode = $mode;
|
2005-03-22 16:04:10 +00:00
|
|
|
} else if (isset($SESSION->userindexmode)) {
|
2007-11-23 00:23:39 +00:00
|
|
|
$mode = (int)$SESSION->userindexmode;
|
2005-03-22 16:04:10 +00:00
|
|
|
} else {
|
2007-11-23 00:23:39 +00:00
|
|
|
$mode = MODE_BRIEF;
|
2005-03-22 16:04:10 +00:00
|
|
|
}
|
|
|
|
|
2008-05-28 15:01:50 +00:00
|
|
|
/// Check to see if groups are being used in this course
|
2005-03-22 16:04:10 +00:00
|
|
|
/// and if so, set $currentgroup to reflect the current group
|
|
|
|
|
2007-09-08 20:53:05 +00:00
|
|
|
$groupmode = groups_get_course_groupmode($course); // Groups are being used
|
|
|
|
$currentgroup = groups_get_course_group($course, true);
|
2005-03-22 16:04:10 +00:00
|
|
|
|
2005-06-03 23:20:01 +00:00
|
|
|
if (!$currentgroup) { // To make some other functions work better later
|
|
|
|
$currentgroup = NULL;
|
|
|
|
}
|
2005-03-22 16:04:10 +00:00
|
|
|
|
2009-04-09 07:58:49 +00:00
|
|
|
$isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context));
|
2004-01-31 04:08:10 +00:00
|
|
|
|
2007-08-17 19:09:11 +00:00
|
|
|
if ($isseparategroups and (!$currentgroup) ) {
|
|
|
|
$navlinks = array();
|
|
|
|
$navlinks[] = array('name' => get_string('participants'), 'link' => null, 'type' => 'misc');
|
|
|
|
$navigation = build_navigation($navlinks);
|
|
|
|
|
|
|
|
print_header("$course->shortname: ".get_string('participants'), $course->fullname, $navigation, "", "", true, " ", navmenu($course));
|
2009-08-06 08:15:05 +00:00
|
|
|
echo $OUTPUT->heading(get_string("notingroup"));
|
2009-08-06 14:08:20 +00:00
|
|
|
echo $OUTPUT->footer();
|
2005-03-22 16:04:10 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2005-06-03 23:20:01 +00:00
|
|
|
// Should use this variable so that we don't break stuff every time a variable is added or changed.
|
2009-08-10 03:40:04 +00:00
|
|
|
$baseurl = new moodle_url($CFG->wwwroot.'/user/index.php', array(
|
|
|
|
'contextid' => $context->id,
|
|
|
|
'roleid' => $roleid,
|
|
|
|
'id' => $course->id,
|
|
|
|
'perpage' => $perpage,
|
|
|
|
'accesssince' => $accesssince,
|
|
|
|
'search' => s($search)));
|
2005-03-22 16:04:10 +00:00
|
|
|
|
|
|
|
/// Print headers
|
2004-01-31 04:08:10 +00:00
|
|
|
|
2007-08-17 19:09:11 +00:00
|
|
|
$navlinks = array();
|
|
|
|
$navlinks[] = array('name' => get_string('participants'), 'link' => null, 'type' => 'misc');
|
|
|
|
$navigation = build_navigation($navlinks);
|
2006-03-09 09:09:20 +00:00
|
|
|
|
2007-08-17 19:09:11 +00:00
|
|
|
print_header("$course->shortname: ".get_string('participants'), $course->fullname, $navigation, "", "", true, " ", navmenu($course));
|
2007-03-30 16:01:44 +00:00
|
|
|
|
2007-03-05 20:13:16 +00:00
|
|
|
/// setting up tags
|
2006-08-14 08:38:49 +00:00
|
|
|
if ($course->id == SITEID) {
|
2006-03-09 09:09:20 +00:00
|
|
|
$filtertype = 'site';
|
2006-08-14 08:38:49 +00:00
|
|
|
} else if ($course->id && !$currentgroup) {
|
2006-03-09 09:09:20 +00:00
|
|
|
$filtertype = 'course';
|
2006-08-14 08:38:49 +00:00
|
|
|
$filterselect = $course->id;
|
2006-03-09 09:09:20 +00:00
|
|
|
} else {
|
|
|
|
$filtertype = 'group';
|
|
|
|
$filterselect = $currentgroup;
|
|
|
|
}
|
|
|
|
$currenttab = 'participants';
|
|
|
|
$user = $USER;
|
2008-07-28 07:17:34 +00:00
|
|
|
$userindexpage = true;
|
2006-03-09 09:09:20 +00:00
|
|
|
|
|
|
|
require_once($CFG->dirroot .'/user/tabs.php');
|
|
|
|
|
|
|
|
|
2005-11-20 21:29:59 +00:00
|
|
|
/// Get the hidden field list
|
2007-03-05 20:13:16 +00:00
|
|
|
if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
|
2005-11-20 21:29:59 +00:00
|
|
|
$hiddenfields = array(); // teachers and admins are allowed to see everything
|
|
|
|
} else {
|
|
|
|
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
|
|
|
|
}
|
|
|
|
|
2008-12-01 20:45:46 +00:00
|
|
|
if (isset($hiddenfields['lastaccess'])) {
|
|
|
|
// do not allow access since filtering
|
|
|
|
$accesssince = 0;
|
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2005-03-22 16:04:10 +00:00
|
|
|
/// Print settings and things in a table across the top
|
|
|
|
|
2005-06-03 23:20:01 +00:00
|
|
|
echo '<table class="controls" cellspacing="0"><tr>';
|
2005-03-22 16:04:10 +00:00
|
|
|
|
2006-08-25 08:54:22 +00:00
|
|
|
/// Print my course menus
|
2006-09-13 05:05:17 +00:00
|
|
|
if ($mycourses = get_my_courses($USER->id)) {
|
|
|
|
echo '<td class="left">';
|
|
|
|
$courselist = array();
|
2009-08-10 03:40:04 +00:00
|
|
|
$popupurl = new moodle_url($CFG->wwwroot.'/user/index.php?roleid='.$roleid.'&sifirst=&silast=');
|
2006-09-13 05:05:17 +00:00
|
|
|
foreach ($mycourses as $mycourse) {
|
2007-03-15 15:46:53 +00:00
|
|
|
$courselist[$mycourse->id] = format_string($mycourse->shortname);
|
2006-09-13 05:05:17 +00:00
|
|
|
}
|
2008-07-28 07:17:34 +00:00
|
|
|
if (has_capability('moodle/site:viewparticipants', $systemcontext)) {
|
2008-04-18 08:35:16 +00:00
|
|
|
unset($courselist[SITEID]);
|
|
|
|
$courselist = array(SITEID => format_string($SITE->shortname)) + $courselist;
|
|
|
|
}
|
2009-08-10 08:38:45 +00:00
|
|
|
$select = html_select::make_popup_form($popupurl, 'id', $courselist, 'courseform', $course->id);
|
2009-08-10 03:40:04 +00:00
|
|
|
$select->set_label(get_string('mycourses'));
|
|
|
|
echo $OUTPUT->select($select);
|
2006-09-13 05:05:17 +00:00
|
|
|
echo '</td>';
|
|
|
|
}
|
2006-10-01 19:55:47 +00:00
|
|
|
|
2007-05-22 02:08:22 +00:00
|
|
|
echo '<td class="left">';
|
2009-08-10 03:40:04 +00:00
|
|
|
groups_print_course_menu($course, $baseurl->out());
|
2007-05-22 02:08:22 +00:00
|
|
|
echo '</td>';
|
2005-03-22 16:04:10 +00:00
|
|
|
|
2008-12-01 20:45:46 +00:00
|
|
|
if (!isset($hiddenfields['lastaccess'])) {
|
|
|
|
// get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
|
|
|
|
// we need to make it diferently for normal courses and site course
|
|
|
|
if ($context->id != $frontpagectx->id) {
|
|
|
|
$minlastaccess = $DB->get_field_sql('SELECT min(timeaccess)
|
|
|
|
FROM {user_lastaccess}
|
|
|
|
WHERE courseid = ?
|
|
|
|
AND timeaccess != 0', array($course->id));
|
|
|
|
$lastaccess0exists = $DB->record_exists('user_lastaccess', array('courseid'=>$course->id, 'timeaccess'=>0));
|
|
|
|
} else {
|
|
|
|
$minlastaccess = $DB->get_field_sql('SELECT min(lastaccess)
|
|
|
|
FROM {user}
|
|
|
|
WHERE lastaccess != 0');
|
|
|
|
$lastaccess0exists = $DB->record_exists('user', array('lastaccess'=>0));
|
|
|
|
}
|
2008-04-02 06:35:49 +00:00
|
|
|
|
2008-12-01 20:45:46 +00:00
|
|
|
$now = usergetmidnight(time());
|
|
|
|
$timeaccess = array();
|
2009-08-10 03:40:04 +00:00
|
|
|
$baseurl->remove_params('accesssince');
|
2006-10-01 19:55:47 +00:00
|
|
|
|
2008-12-01 20:45:46 +00:00
|
|
|
// makes sense for this to go first.
|
|
|
|
$timeoptions[0] = get_string('selectperiod');
|
2006-10-01 19:55:47 +00:00
|
|
|
|
2008-12-01 20:45:46 +00:00
|
|
|
// days
|
|
|
|
for ($i = 1; $i < 7; $i++) {
|
|
|
|
if (strtotime('-'.$i.' days',$now) >= $minlastaccess) {
|
|
|
|
$timeoptions[strtotime('-'.$i.' days',$now)] = get_string('numdays','moodle',$i);
|
|
|
|
}
|
2006-06-15 21:37:20 +00:00
|
|
|
}
|
2008-12-01 20:45:46 +00:00
|
|
|
// weeks
|
|
|
|
for ($i = 1; $i < 10; $i++) {
|
|
|
|
if (strtotime('-'.$i.' weeks',$now) >= $minlastaccess) {
|
|
|
|
$timeoptions[strtotime('-'.$i.' weeks',$now)] = get_string('numweeks','moodle',$i);
|
|
|
|
}
|
2006-06-15 21:37:20 +00:00
|
|
|
}
|
2008-12-01 20:45:46 +00:00
|
|
|
// 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');
|
2005-11-17 02:46:27 +00:00
|
|
|
}
|
2006-10-01 19:55:47 +00:00
|
|
|
|
2008-12-01 20:45:46 +00:00
|
|
|
if (!empty($lastaccess0exists)) {
|
|
|
|
$timeoptions[-1] = get_string('never');
|
|
|
|
}
|
2006-10-01 19:55:47 +00:00
|
|
|
|
2008-12-01 20:45:46 +00:00
|
|
|
if (count($timeoptions) > 1) {
|
|
|
|
echo '<td class="left">';
|
2009-08-10 08:38:45 +00:00
|
|
|
$select = html_select::make_popup_form($baseurl, 'accesssince', $timeoptions, 'timeoptions', $accesssince);
|
2009-08-10 03:40:04 +00:00
|
|
|
$select->set_label(get_string('usersnoaccesssince'));
|
|
|
|
echo $OUTPUT->select($select);
|
2008-12-01 20:45:46 +00:00
|
|
|
echo '</td>';
|
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
2006-10-01 19:55:47 +00:00
|
|
|
|
2007-11-23 00:23:39 +00:00
|
|
|
// Decide wheteher we will fetch extra enrolment/groups data.
|
|
|
|
//
|
|
|
|
// MODE_ENROLDETAILS is expensive, and only suitable where the listing is small
|
|
|
|
// (at or below DEFAULT_PAGE_SIZE) and $USER can enrol/unenrol
|
|
|
|
// (will take 1 extra DB query - 2 on Oracle)
|
|
|
|
//
|
2008-07-21 07:18:58 +00:00
|
|
|
if ($course->id != SITEID && $perpage <= DEFAULT_PAGE_SIZE
|
2007-11-23 00:23:39 +00:00
|
|
|
&& has_capability('moodle/role:assign',$context)) {
|
|
|
|
$allowenroldetails=true;
|
|
|
|
} else {
|
|
|
|
$allowenroldetails=false;
|
|
|
|
}
|
|
|
|
if ($mode === MODE_ENROLDETAILS && !($allowenroldetails)) {
|
|
|
|
// conditions haven't been met - reset
|
|
|
|
$mode = MODE_BRIEF;
|
|
|
|
}
|
2005-11-17 02:46:27 +00:00
|
|
|
|
2005-06-03 23:20:01 +00:00
|
|
|
echo '<td class="right">';
|
2007-11-23 00:23:39 +00:00
|
|
|
$formatmenu = array( '0' => get_string('brief'),
|
|
|
|
'1' => get_string('userdetails'));
|
|
|
|
if ($allowenroldetails) {
|
|
|
|
$formatmenu['2']= get_string('enroldetails');
|
|
|
|
}
|
2009-08-10 08:38:45 +00:00
|
|
|
$select = html_select::make_popup_form($baseurl, 'mode', $formatmenu, 'formatmenu', $mode);
|
2009-08-10 03:40:04 +00:00
|
|
|
$select->nothinglabel = false;
|
|
|
|
$select->set_label(get_string('userlist'));
|
|
|
|
echo $OUTPUT->select($select);
|
2005-03-22 16:04:10 +00:00
|
|
|
echo '</td></tr></table>';
|
|
|
|
|
2007-03-05 20:13:16 +00:00
|
|
|
if ($currentgroup and (!$isseparategroups or has_capability('moodle/site:accessallgroups', $context))) { /// Display info about the group
|
2007-09-08 20:53:05 +00:00
|
|
|
if ($group = groups_get_group($currentgroup)) {
|
2006-10-01 19:55:47 +00:00
|
|
|
if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) {
|
2005-03-22 16:04:10 +00:00
|
|
|
echo '<table class="groupinfobox"><tr><td class="left side picture">';
|
|
|
|
print_group_picture($group, $course->id, true, false, false);
|
|
|
|
echo '</td><td class="content">';
|
|
|
|
echo '<h3>'.$group->name;
|
2007-03-05 20:13:16 +00:00
|
|
|
if (has_capability('moodle/course:managegroups', $context)) {
|
2007-08-15 20:33:17 +00:00
|
|
|
echo ' <a title="'.get_string('editgroupprofile').'" href="'.$CFG->wwwroot.'/group/group.php?id='.$group->id.'&courseid='.$group->courseid.'">';
|
2009-07-02 11:09:15 +00:00
|
|
|
echo '<img src="'.$OUTPUT->old_icon_url('t/edit') . '" alt="'.get_string('editgroupprofile').'" />';
|
2005-05-03 18:11:34 +00:00
|
|
|
echo '</a>';
|
|
|
|
}
|
2005-03-22 16:04:10 +00:00
|
|
|
echo '</h3>';
|
|
|
|
echo format_text($group->description);
|
|
|
|
echo '</td></tr></table>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-28 06:41:07 +00:00
|
|
|
/// Define a table showing a list of users in the current role selection
|
|
|
|
|
2006-11-13 03:43:12 +00:00
|
|
|
$tablecolumns = array('userpic', 'fullname');
|
2008-03-19 08:49:23 +00:00
|
|
|
$tableheaders = array(get_string('userpic'), get_string('fullnameuser'));
|
2007-11-23 00:23:39 +00:00
|
|
|
if ($mode === MODE_BRIEF && !isset($hiddenfields['city'])) {
|
2006-09-28 06:41:07 +00:00
|
|
|
$tablecolumns[] = 'city';
|
|
|
|
$tableheaders[] = get_string('city');
|
|
|
|
}
|
2007-11-23 00:23:39 +00:00
|
|
|
if ($mode === MODE_BRIEF && !isset($hiddenfields['country'])) {
|
2006-09-28 06:41:07 +00:00
|
|
|
$tablecolumns[] = 'country';
|
|
|
|
$tableheaders[] = get_string('country');
|
|
|
|
}
|
|
|
|
if (!isset($hiddenfields['lastaccess'])) {
|
|
|
|
$tablecolumns[] = 'lastaccess';
|
|
|
|
$tableheaders[] = get_string('lastaccess');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($course->enrolperiod) {
|
|
|
|
$tablecolumns[] = 'timeend';
|
|
|
|
$tableheaders[] = get_string('enrolmentend');
|
|
|
|
}
|
|
|
|
|
2007-11-23 00:23:39 +00:00
|
|
|
if ($mode === MODE_ENROLDETAILS) {
|
2007-11-23 00:22:56 +00:00
|
|
|
$tablecolumns[] = 'roles';
|
|
|
|
$tableheaders[] = get_string('roles');
|
2007-11-23 00:23:24 +00:00
|
|
|
if ($groupmode != 0) {
|
|
|
|
$tablecolumns[] = 'groups';
|
|
|
|
$tableheaders[] = get_string('groups');
|
|
|
|
if (!empty($CFG->enablegroupings)) {
|
|
|
|
$tablecolumns[] = 'groupings';
|
|
|
|
$tableheaders[] = get_string('groupings', 'group');
|
|
|
|
}
|
2007-11-23 00:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-28 06:41:07 +00:00
|
|
|
if ($bulkoperations) {
|
2007-11-23 00:22:56 +00:00
|
|
|
$tablecolumns[] = 'select';
|
2006-09-28 06:41:07 +00:00
|
|
|
$tableheaders[] = get_string('select');
|
|
|
|
}
|
|
|
|
|
2006-10-01 06:18:18 +00:00
|
|
|
$table = new flexible_table('user-index-participants-'.$course->id);
|
2006-09-28 06:41:07 +00:00
|
|
|
|
|
|
|
$table->define_columns($tablecolumns);
|
|
|
|
$table->define_headers($tableheaders);
|
2009-08-10 03:40:04 +00:00
|
|
|
$table->define_baseurl($baseurl->out());
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2008-12-01 20:45:46 +00:00
|
|
|
if (!isset($hiddenfields['lastaccess'])) {
|
|
|
|
$table->sortable(true, 'lastaccess', SORT_DESC);
|
|
|
|
}
|
|
|
|
|
2007-11-23 00:22:56 +00:00
|
|
|
$table->no_sorting('roles');
|
|
|
|
$table->no_sorting('groups');
|
|
|
|
$table->no_sorting('groupings');
|
|
|
|
$table->no_sorting('select');
|
2006-09-28 06:41:07 +00:00
|
|
|
|
|
|
|
$table->set_attribute('cellspacing', '0');
|
2006-10-01 06:18:18 +00:00
|
|
|
$table->set_attribute('id', 'participants');
|
2006-09-28 06:41:07 +00:00
|
|
|
$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();
|
|
|
|
|
2008-05-31 11:13:21 +00:00
|
|
|
$params = array();
|
2006-09-28 06:41:07 +00:00
|
|
|
// we are looking for all users with this role assigned in this context or higher
|
|
|
|
if ($usercontexts = get_parent_contexts($context)) {
|
|
|
|
$listofcontexts = '('.implode(',', $usercontexts).')';
|
|
|
|
} else {
|
2008-07-28 07:17:34 +00:00
|
|
|
$listofcontexts = '('.$systemcontext->id.')'; // must be site
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($roleid > 0) {
|
2008-05-31 11:13:21 +00:00
|
|
|
$selectrole = " AND r.roleid = :roleid ";
|
|
|
|
$params['roleid'] = $roleid;
|
2006-09-28 06:41:07 +00:00
|
|
|
} else {
|
|
|
|
$selectrole = " ";
|
|
|
|
}
|
2008-04-18 08:35:16 +00:00
|
|
|
|
2007-10-02 03:37:30 +00:00
|
|
|
if ($context->id != $frontpagectx->id) {
|
2007-10-02 06:18:30 +00:00
|
|
|
$select = 'SELECT DISTINCT u.id, u.username, u.firstname, u.lastname,
|
2007-09-19 07:55:00 +00:00
|
|
|
u.email, u.city, u.country, u.picture,
|
|
|
|
u.lang, u.timezone, u.emailstop, u.maildisplay, u.imagealt,
|
|
|
|
COALESCE(ul.timeaccess, 0) AS lastaccess,
|
|
|
|
r.hidden,
|
|
|
|
ctx.id AS ctxid, ctx.path AS ctxpath,
|
2008-04-18 08:35:16 +00:00
|
|
|
ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel ';
|
2007-10-02 03:37:30 +00:00
|
|
|
$select .= $course->enrolperiod?', r.timeend ':'';
|
|
|
|
} else {
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($roleid >= 0) {
|
|
|
|
$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.imagealt,
|
|
|
|
u.lastaccess, r.hidden,
|
|
|
|
ctx.id AS ctxid, ctx.path AS ctxpath,
|
|
|
|
ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel ';
|
|
|
|
} 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, u.imagealt,
|
|
|
|
u.lastaccess,
|
|
|
|
ctx.id AS ctxid, ctx.path AS ctxpath,
|
|
|
|
ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel ';
|
|
|
|
}
|
2007-10-02 03:37:30 +00:00
|
|
|
}
|
2007-09-19 07:55:00 +00:00
|
|
|
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($context->id != $frontpagectx->id or $roleid >= 0) {
|
2008-05-31 11:13:21 +00:00
|
|
|
$from = "FROM {user} u
|
|
|
|
LEFT OUTER JOIN {context} ctx
|
|
|
|
ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.")
|
|
|
|
JOIN {role_assignments} r
|
|
|
|
ON u.id=r.userid
|
|
|
|
LEFT OUTER JOIN {user_lastaccess} ul
|
|
|
|
ON (r.userid=ul.userid and ul.courseid = :courseid) ";
|
|
|
|
$params['courseid'] = $course->id;
|
2007-10-02 03:37:30 +00:00
|
|
|
} else {
|
2008-04-18 08:35:16 +00:00
|
|
|
// on frontpage and we want all registered users
|
2008-05-31 11:13:21 +00:00
|
|
|
$from = "FROM {user} u
|
|
|
|
LEFT OUTER JOIN {context} ctx
|
|
|
|
ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.") ";
|
2007-10-02 03:37:30 +00:00
|
|
|
}
|
2008-04-18 08:35:16 +00:00
|
|
|
|
2007-08-17 19:09:11 +00:00
|
|
|
$hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 ';
|
2006-12-04 03:05:40 +00:00
|
|
|
|
2007-03-30 16:01:44 +00:00
|
|
|
// exclude users with roles we are avoiding
|
|
|
|
if ($avoidroles) {
|
2006-12-08 04:28:58 +00:00
|
|
|
$adminroles = 'AND r.roleid NOT IN (';
|
2007-03-30 16:01:44 +00:00
|
|
|
$adminroles .= implode(',', $avoidroles);
|
2006-12-04 03:05:40 +00:00
|
|
|
$adminroles .= ')';
|
|
|
|
} else {
|
|
|
|
$adminroles = '';
|
|
|
|
}
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2006-10-05 08:54:35 +00:00
|
|
|
// join on 2 conditions
|
|
|
|
// otherwise we run into the problem of having records in ul table, but not relevant course
|
|
|
|
// and user record is not pulled out
|
2008-04-18 08:35:16 +00:00
|
|
|
|
2007-10-02 03:37:30 +00:00
|
|
|
if ($context->id != $frontpagectx->id) {
|
|
|
|
$where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
|
2008-05-31 11:13:21 +00:00
|
|
|
AND u.deleted = 0 $selectrole
|
|
|
|
AND (ul.courseid = $course->id OR ul.courseid IS NULL)
|
|
|
|
AND u.username != 'guest'
|
|
|
|
$adminroles
|
|
|
|
$hiddensql ";
|
2008-04-02 06:35:49 +00:00
|
|
|
$where .= get_course_lastaccess_sql($accesssince);
|
2007-10-02 03:37:30 +00:00
|
|
|
} else {
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($roleid >= 0) {
|
|
|
|
$where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
|
2008-05-31 11:13:21 +00:00
|
|
|
AND u.deleted = 0 $selectrole
|
|
|
|
AND u.username != 'guest'";
|
|
|
|
$where .= get_user_lastaccess_sql($accesssince);
|
2008-04-18 08:35:16 +00:00
|
|
|
} else {
|
|
|
|
$where = "WHERE u.deleted = 0
|
|
|
|
AND u.username != 'guest'";
|
|
|
|
$where .= get_user_lastaccess_sql($accesssince);
|
|
|
|
}
|
2007-10-02 03:37:30 +00:00
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
$wheresearch = '';
|
|
|
|
|
|
|
|
if (!empty($search)) {
|
2008-05-31 11:13:21 +00:00
|
|
|
$LIKE = $DB->sql_ilike();
|
|
|
|
$fullname = $DB->sql_fullname('u.firstname','u.lastname');
|
|
|
|
$wheresearch .= " AND ($fullname $LIKE :search1 OR email $LIKE :search2 OR idnumber $LIKE :search3) ";
|
|
|
|
$params['search1'] = "%$search%";
|
|
|
|
$params['search2'] = "%$search%";
|
|
|
|
$params['search3'] = "%$search%";
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($currentgroup) { // Displaying a group by choice
|
|
|
|
// FIX: TODO: This will not work if $currentgroup == 0, i.e. "those not in a group"
|
2008-05-31 11:13:21 +00:00
|
|
|
$from .= 'LEFT JOIN {groups_members} gm ON u.id = gm.userid ';
|
|
|
|
$where .= ' AND gm.groupid = :currentgroup';
|
2008-11-18 02:49:09 +00:00
|
|
|
$params['currentgroup'] = $currentgroup;
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
|
|
|
|
2008-05-31 11:13:21 +00:00
|
|
|
$totalcount = $DB->count_records_sql("SELECT COUNT(distinct u.id) $from $where", $params); // Each user could have > 1 role
|
2006-09-28 06:41:07 +00:00
|
|
|
|
|
|
|
if ($table->get_sql_where()) {
|
|
|
|
$where .= ' AND '.$table->get_sql_where();
|
|
|
|
}
|
|
|
|
|
2008-03-15 21:57:25 +00:00
|
|
|
/// Always add r.hidden to sort in order to guarantee hiddens to "win"
|
|
|
|
/// in the resolution of duplicates later - MDL-13935
|
2008-03-24 01:29:30 +00:00
|
|
|
/// Only exception is frontpage that doesn't have such r.hidden info
|
|
|
|
/// because it retrieves ALL users (without role checking) - MDL-14034
|
2006-09-28 06:41:07 +00:00
|
|
|
if ($table->get_sql_sort()) {
|
2008-03-24 01:29:30 +00:00
|
|
|
$sort = ' ORDER BY '.$table->get_sql_sort();
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($context->id != $frontpagectx->id or $roleid >= 0) {
|
2008-03-24 01:29:30 +00:00
|
|
|
$sort .= ', r.hidden DESC';
|
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
} else {
|
2008-03-24 01:29:30 +00:00
|
|
|
$sort = '';
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($context->id != $frontpagectx->id or $roleid >= 0) {
|
2008-03-24 01:29:30 +00:00
|
|
|
$sort .= ' ORDER BY r.hidden DESC';
|
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
|
|
|
|
2008-05-31 11:13:21 +00:00
|
|
|
$matchcount = $DB->count_records_sql("SELECT COUNT(distinct u.id) $from $where $wheresearch", $params);
|
2006-09-28 06:41:07 +00:00
|
|
|
|
2007-12-20 17:43:19 +00:00
|
|
|
$table->initialbars(true);
|
2006-09-28 06:41:07 +00:00
|
|
|
$table->pagesize($perpage, $matchcount);
|
|
|
|
|
2008-05-31 11:13:21 +00:00
|
|
|
$userlist = $DB->get_recordset_sql("$select $from $where $wheresearch $sort", $params,
|
2006-09-28 06:41:07 +00:00
|
|
|
$table->get_page_start(), $table->get_page_size());
|
2006-09-28 06:04:39 +00:00
|
|
|
|
2007-11-23 00:22:56 +00:00
|
|
|
//
|
|
|
|
// The SELECT behind get_participants_extra() is cheaper if we pass an array
|
|
|
|
// if IDs. We could pass the SELECT we did before (with the limit bits - tricky!)
|
|
|
|
// but this is much cheaper. And in any case, it is only doable with limited numbers
|
|
|
|
// of rows anyway. On a large course it will explode badly...
|
|
|
|
//
|
2007-11-23 00:23:39 +00:00
|
|
|
if ($mode===MODE_ENROLDETAILS) {
|
2008-10-29 07:16:49 +00:00
|
|
|
if ($context->id != $frontpagectx->id) {
|
|
|
|
$userids = $DB->get_fieldset_sql("SELECT DISTINCT u.id $from $where $wheresearch", $params,
|
|
|
|
$table->get_page_start(), $table->get_page_size());
|
|
|
|
} else {
|
|
|
|
$userids = $DB->get_fieldset_sql("SELECT u.id $from $where $wheresearch", $params,
|
|
|
|
$table->get_page_start(), $table->get_page_size());
|
|
|
|
}
|
2007-11-23 00:22:56 +00:00
|
|
|
$userlist_extra = get_participants_extra($userids, $avoidroles, $course, $context);
|
|
|
|
}
|
|
|
|
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($context->id == $frontpagectx->id) {
|
|
|
|
$strallsiteusers = get_string('allsiteusers', 'role');
|
|
|
|
if ($CFG->defaultfrontpageroleid) {
|
2008-05-31 11:13:21 +00:00
|
|
|
if ($fprole = $DB->get_record('role', array('id'=>$CFG->defaultfrontpageroleid))) {
|
2008-04-18 08:35:16 +00:00
|
|
|
$fprole = role_get_name($fprole, $frontpagectx);
|
|
|
|
$strallsiteusers = "$strallsiteusers ($fprole)";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$rolenames = array(-1 => $strallsiteusers) + $rolenames;
|
|
|
|
}
|
2006-09-28 06:04:39 +00:00
|
|
|
|
2008-04-18 08:35:16 +00:00
|
|
|
/// If there are multiple Roles in the course, then show a drop down menu for switching
|
2006-11-20 20:47:17 +00:00
|
|
|
if (count($rolenames) > 1) {
|
2006-09-28 06:41:07 +00:00
|
|
|
echo '<div class="rolesform">';
|
2008-04-18 08:35:16 +00:00
|
|
|
echo '<label for="rolesform_jump">'.get_string('currentrole', 'role').' </label>';
|
|
|
|
if ($context->id != $frontpagectx->id) {
|
2009-08-10 03:40:04 +00:00
|
|
|
$rolenames = array('0' => get_string('all')) + $rolenames;
|
2008-04-18 08:35:16 +00:00
|
|
|
} else {
|
|
|
|
if (!$CFG->defaultfrontpageroleid) {
|
|
|
|
// we do not want "All users with role" - we already have all users in defualt frontpage role option
|
2009-08-10 03:40:04 +00:00
|
|
|
$rolenames = array('0' => get_string('userswithrole', 'role')) + $rolenames;
|
2008-04-18 08:35:16 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-10 08:38:45 +00:00
|
|
|
$select = html_select::make_popup_form($rolenamesurl, 'roleid', $rolenames, 'rolesform', $roleid);
|
2009-08-10 03:40:04 +00:00
|
|
|
$select->nothinglabel = false;
|
|
|
|
echo $OUTPUT->select($select);
|
2007-07-31 20:10:05 +00:00
|
|
|
echo '</div>';
|
2008-04-18 08:35:16 +00:00
|
|
|
|
|
|
|
} else if (count($rolenames) == 1) {
|
|
|
|
// when all users with the same role - print its name
|
|
|
|
echo '<div class="rolesform">';
|
|
|
|
echo get_string('role').': ';
|
|
|
|
$rolename = reset($rolenames);
|
|
|
|
echo $rolename;
|
|
|
|
echo '</div>';
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
2006-09-28 06:04:39 +00:00
|
|
|
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($roleid > 0) {
|
2008-05-31 11:13:21 +00:00
|
|
|
if (!$currentrole = $DB->get_record('role', array('id'=>$roleid))) {
|
2008-07-21 07:18:58 +00:00
|
|
|
print_error('invalidroleid');
|
2006-08-14 08:38:49 +00:00
|
|
|
}
|
2006-09-28 04:45:39 +00:00
|
|
|
$a->number = $totalcount;
|
2007-11-19 04:13:15 +00:00
|
|
|
// MDL-12217, use course specific rolename
|
|
|
|
if (isset($rolenames[$currentrole->id])){
|
|
|
|
$a->role = $rolenames[$currentrole->id];
|
2008-04-18 08:35:16 +00:00
|
|
|
}else{
|
2007-11-19 04:13:15 +00:00
|
|
|
$a->role = $currentrole->name;//safety net
|
|
|
|
}
|
2008-04-18 08:35:16 +00:00
|
|
|
$heading = format_string(get_string('xuserswiththerole', 'role', $a));
|
2008-03-13 12:13:26 +00:00
|
|
|
|
|
|
|
if ($currentgroup and $group) {
|
|
|
|
$a->group = $group->name;
|
2008-04-18 08:35:16 +00:00
|
|
|
$heading .= ' ' . format_string(get_string('ingroup', 'role', $a));
|
|
|
|
}
|
2008-03-13 12:13:26 +00:00
|
|
|
|
|
|
|
if ($accesssince) {
|
|
|
|
$a->timeperiod = $timeoptions[$accesssince];
|
2008-04-18 08:35:16 +00:00
|
|
|
$heading .= ' ' . format_string(get_string('inactiveformorethan', 'role', $a));
|
2008-03-13 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$heading .= ": $a->number";
|
2006-09-06 08:55:23 +00:00
|
|
|
if (user_can_assign($context, $roleid)) {
|
2006-09-28 06:04:39 +00:00
|
|
|
$heading .= ' <a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?roleid='.$roleid.'&contextid='.$context->id.'">';
|
2009-07-02 11:09:15 +00:00
|
|
|
$heading .= '<img src="'.$OUTPUT->old_icon_url('i/edit') . '" class="icon" alt="" /></a>';
|
2006-09-28 06:04:39 +00:00
|
|
|
}
|
2009-08-06 08:55:02 +00:00
|
|
|
echo $OUTPUT->heading($heading, 3);
|
2006-09-28 06:04:39 +00:00
|
|
|
} else {
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($course->id != SITEID && has_capability('moodle/role:assign', $context)) {
|
2008-02-29 04:30:27 +00:00
|
|
|
$editlink = ' <a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">';
|
2009-07-02 11:09:15 +00:00
|
|
|
$editlink .= '<img src="'.$OUTPUT->old_icon_url('i/edit') . '" class="icon" alt="" /></a>';
|
2008-02-29 04:30:27 +00:00
|
|
|
} else {
|
|
|
|
$editlink = '';
|
|
|
|
}
|
2008-04-18 08:35:16 +00:00
|
|
|
if ($course->id == SITEID and $roleid < 0) {
|
|
|
|
$strallparticipants = get_string('allsiteusers', 'role');
|
|
|
|
} else {
|
|
|
|
$strallparticipants = get_string('allparticipants');
|
|
|
|
}
|
2006-10-31 01:21:48 +00:00
|
|
|
if ($matchcount < $totalcount) {
|
2009-08-06 08:15:05 +00:00
|
|
|
echo $OUTPUT->heading($strallparticipants.': '.$matchcount.'/'.$totalcount . $editlink, 3);
|
2006-10-31 01:21:48 +00:00
|
|
|
} else {
|
2009-08-06 08:15:05 +00:00
|
|
|
echo $OUTPUT->heading($strallparticipants.': '.$matchcount . $editlink, 3);
|
2006-10-31 01:21:48 +00:00
|
|
|
}
|
2006-09-28 06:04:39 +00:00
|
|
|
}
|
|
|
|
|
2006-09-28 06:41:07 +00:00
|
|
|
|
|
|
|
if ($bulkoperations) {
|
2009-07-02 04:02:40 +00:00
|
|
|
$PAGE->requires->js('user/user.js');
|
2007-01-06 14:07:00 +00:00
|
|
|
echo '<form action="action_redir.php" method="post" id="participantsform" onsubmit="return checksubmit(this);">';
|
|
|
|
echo '<div>';
|
2009-01-02 10:36:25 +00:00
|
|
|
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
2008-04-11 05:34:23 +00:00
|
|
|
echo '<input type="hidden" name="returnto" value="'.s(me()).'" />';
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($CFG->longtimenosee > 0 && $CFG->longtimenosee < 1000 && $totalcount > 0) {
|
|
|
|
echo '<p id="longtimenosee">('.get_string('unusedaccounts', '', $CFG->longtimenosee).')</p>';
|
|
|
|
}
|
|
|
|
|
2007-11-23 00:23:39 +00:00
|
|
|
if ($mode===MODE_USERDETAILS) { // Print simple listing
|
2006-09-28 06:41:07 +00:00
|
|
|
if ($totalcount < 1) {
|
2009-08-06 08:15:05 +00:00
|
|
|
echo $OUTPUT->heading(get_string('nothingtodisplay'));
|
2006-09-28 06:41:07 +00:00
|
|
|
} else {
|
|
|
|
if ($totalcount > $perpage) {
|
|
|
|
|
|
|
|
$firstinitial = $table->get_initial_first();
|
|
|
|
$lastinitial = $table->get_initial_last();
|
|
|
|
$strall = get_string('all');
|
|
|
|
$alpha = explode(',', get_string('alphabet'));
|
|
|
|
|
|
|
|
// Bar of first initials
|
|
|
|
|
|
|
|
echo '<div class="initialbar firstinitial">'.get_string('firstname').' : ';
|
|
|
|
if(!empty($firstinitial)) {
|
2009-08-10 03:40:04 +00:00
|
|
|
echo '<a href="'.$baseurl->out().'&sifirst=">'.$strall.'</a>';
|
2006-09-28 06:41:07 +00:00
|
|
|
} else {
|
|
|
|
echo '<strong>'.$strall.'</strong>';
|
|
|
|
}
|
|
|
|
foreach ($alpha as $letter) {
|
|
|
|
if ($letter == $firstinitial) {
|
|
|
|
echo ' <strong>'.$letter.'</strong>';
|
2006-08-09 13:53:12 +00:00
|
|
|
} else {
|
2009-08-10 03:40:04 +00:00
|
|
|
echo ' <a href="'.$baseurl->out().'&sifirst='.$letter.'">'.$letter.'</a>';
|
2006-08-09 13:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
// Bar of last initials
|
|
|
|
|
|
|
|
echo '<div class="initialbar lastinitial">'.get_string('lastname').' : ';
|
|
|
|
if(!empty($lastinitial)) {
|
2009-08-10 03:40:04 +00:00
|
|
|
echo '<a href="'.$baseurl->out().'&silast=">'.$strall.'</a>';
|
2006-09-28 06:41:07 +00:00
|
|
|
} else {
|
|
|
|
echo '<strong>'.$strall.'</strong>';
|
|
|
|
}
|
|
|
|
foreach ($alpha as $letter) {
|
|
|
|
if ($letter == $lastinitial) {
|
|
|
|
echo ' <strong>'.$letter.'</strong>';
|
|
|
|
} else {
|
2009-08-10 03:40:04 +00:00
|
|
|
echo ' <a href="'.$baseurl->out().'&silast='.$letter.'">'.$letter.'</a>';
|
2006-08-09 13:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
echo '</div>';
|
|
|
|
|
2009-08-07 00:29:44 +00:00
|
|
|
$pagingbar = moodle_paging_bar::make($matchcount, intval($table->get_page_start() / $perpage), $perpage, $baseurl);
|
|
|
|
$pagingbar->pagevar = 'spage';
|
|
|
|
echo $OUTPUT->paging_bar($pagingbar);
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($matchcount > 0) {
|
2008-03-15 21:57:25 +00:00
|
|
|
$usersprinted = array();
|
2008-05-31 11:13:21 +00:00
|
|
|
foreach ($userlist as $user) {
|
2008-03-15 21:57:25 +00:00
|
|
|
if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$usersprinted[] = $user->id; /// Add new user to the array of users printed
|
|
|
|
|
2007-09-19 07:55:00 +00:00
|
|
|
$user = make_context_subobj($user);
|
2009-08-05 02:03:50 +00:00
|
|
|
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
if (isset($user->context->id)) {
|
|
|
|
$usercontext = $user->context;
|
|
|
|
} else {
|
|
|
|
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
$countries = get_list_of_countries();
|
|
|
|
|
|
|
|
/// Get the hidden field list
|
|
|
|
if (has_capability('moodle/course:viewhiddenuserfields', $context)) {
|
|
|
|
$hiddenfields = array();
|
|
|
|
} else {
|
|
|
|
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
|
|
|
|
}
|
|
|
|
$table = new html_table();
|
|
|
|
$table->add_class('userinfobox');
|
|
|
|
|
|
|
|
$row = new html_table_row();
|
|
|
|
$row->cells[0] = new html_table_cell();
|
|
|
|
$row->cells[0]->add_class('left side');
|
2009-08-20 08:50:22 +00:00
|
|
|
|
|
|
|
$row->cells[0]->text = $OUTPUT->user_picture(moodle_user_picture::make($user, $course->id));
|
2009-08-05 02:03:50 +00:00
|
|
|
$row->cells[1] = new html_table_cell();
|
|
|
|
$row->cells[1]->add_class('content');
|
|
|
|
|
|
|
|
$row->cells[1]->text = $OUTPUT->container(fullname($user, has_capability('moodle/site:viewfullnames', $context)), 'username');
|
|
|
|
$row->cells[1]->text .= $OUTPUT->container_start('info');
|
|
|
|
|
|
|
|
if (!empty($user->role)) {
|
|
|
|
$row->cells[1]->text .= get_string('role') .': '. $user->role .'<br />';
|
|
|
|
}
|
|
|
|
if ($user->maildisplay == 1 or ($user->maildisplay == 2 and ($course->id != SITEID) and !isguest()) or
|
|
|
|
has_capability('moodle/course:viewhiddenuserfields', $context)) {
|
|
|
|
$link = new html_link();
|
|
|
|
$link->url = "mailto:$user->email";
|
|
|
|
$link->text = $user->email;
|
|
|
|
$row->cells[1]->text .= get_string('email') .': ' . $OUTPUT->link($link) . '<br />';
|
|
|
|
}
|
|
|
|
if (($user->city or $user->country) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
|
|
|
|
$row->cells[1]->text .= get_string('city') .': ';
|
|
|
|
if ($user->city && !isset($hiddenfields['city'])) {
|
|
|
|
$row->cells[1]->text .= $user->city;
|
|
|
|
}
|
|
|
|
if (!empty($countries[$user->country]) && !isset($hiddenfields['country'])) {
|
|
|
|
if ($user->city && !isset($hiddenfields['city'])) {
|
|
|
|
$row->cells[1]->text .= ', ';
|
|
|
|
}
|
|
|
|
$row->cells[1]->text .= $countries[$user->country];
|
|
|
|
}
|
|
|
|
$row->cells[1]->text .= '<br />';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($hiddenfields['lastaccess'])) {
|
|
|
|
if ($user->lastaccess) {
|
|
|
|
$row->cells[1]->text .= get_string('lastaccess') .': '. userdate($user->lastaccess);
|
|
|
|
$row->cells[1]->text .= ' ('. format_time(time() - $user->lastaccess, $datestring) .')';
|
|
|
|
} else {
|
|
|
|
$row->cells[1]->text .= get_string('lastaccess') .': '. get_string('never');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$row->cells[1]->text .= $OUTPUT->container_end();
|
2009-08-18 05:19:25 +00:00
|
|
|
|
2009-08-05 02:03:50 +00:00
|
|
|
$row->cells[2] = new html_table_cell();
|
|
|
|
$row->cells[2]->add_class('links');
|
|
|
|
$row->cells[2]->text = '';
|
2009-08-18 05:19:25 +00:00
|
|
|
|
2009-08-05 02:03:50 +00:00
|
|
|
$links = array();
|
|
|
|
|
|
|
|
if ($CFG->bloglevel > 0) {
|
|
|
|
$links[] = html_link::make(new moodle_url($CFG->wwwroot.'/blog/index.php?userid='.$user->id), get_string('blogs','blog'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($CFG->enablenotes) and (has_capability('moodle/notes:manage', $context) || has_capability('moodle/notes:view', $context))) {
|
|
|
|
$links[] = html_link::make(new moodle_url($CFG->wwwroot.'/notes/index.php?course=' . $course->id. '&user='.$user->id), get_string('notes','notes'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_capability('moodle/site:viewreports', $context) or has_capability('moodle/user:viewuseractivitiesreport', $usercontext)) {
|
|
|
|
$links[] = html_link::make(new moodle_url($CFG->wwwroot.'/course/user.php?id='. $course->id .'&user='. $user->id), get_string('activity'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_capability('moodle/role:assign', $context) and get_user_roles($context, $user->id, false)) { // I can unassign and user has some role
|
|
|
|
$links[] = html_link::make(new moodle_url($CFG->wwwroot.'/course/unenrol.php?id='. $course->id .'&user='. $user->id), get_string('unenrol'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($USER->id != $user->id && !session_is_loggedinas() && has_capability('moodle/user:loginas', $context) &&
|
|
|
|
! has_capability('moodle/site:doanything', $context, $user->id, false)) {
|
|
|
|
$links[] = html_link::make(new moodle_url($CFG->wwwroot.'/course/loginas.php?id='. $course->id .'&user='. $user->id .'&sesskey='. sesskey()), get_string('loginas'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$links[] = html_link::make(new moodle_url($CFG->wwwroot.'/user/view.php?id='. $user->id .'&course='. $course->id), get_string('fullprofile') . '...');
|
2009-08-18 05:19:25 +00:00
|
|
|
|
2009-08-05 02:03:50 +00:00
|
|
|
foreach ($links as $link) {
|
|
|
|
$row->cells[2]->text .= $OUTPUT->link($link);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($messageselect)) {
|
|
|
|
$row->cells[2]->text .= '<br /><input type="checkbox" name="user'.$user->id.'" /> ';
|
|
|
|
}
|
|
|
|
$table->data = array($row);
|
2009-08-10 03:40:04 +00:00
|
|
|
echo $OUTPUT->table($table);
|
2006-08-09 13:53:12 +00:00
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
|
|
|
|
} else {
|
2009-08-06 08:15:05 +00:00
|
|
|
echo $OUTPUT->heading(get_string('nothingtodisplay'));
|
2006-08-09 13:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$countrysort = (strpos($sort, 'country') !== false);
|
|
|
|
$timeformat = get_string('strftimedate');
|
2006-11-15 04:28:18 +00:00
|
|
|
|
|
|
|
|
2007-10-10 12:19:27 +00:00
|
|
|
if ($userlist) {
|
2007-11-23 00:22:56 +00:00
|
|
|
|
|
|
|
// only show the plugin if multiple enrolment plugins
|
|
|
|
// are enabled...
|
|
|
|
if (strpos($CFG->enrol_plugins_enabled, ',')=== false) {
|
|
|
|
$showenrolplugin = true;
|
|
|
|
} else {
|
|
|
|
$showenrolplugin = false;
|
|
|
|
}
|
2008-03-15 21:57:25 +00:00
|
|
|
|
|
|
|
$usersprinted = array();
|
2008-05-31 11:13:21 +00:00
|
|
|
foreach ($userlist as $user) {
|
2008-03-15 21:57:25 +00:00
|
|
|
if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$usersprinted[] = $user->id; /// Add new user to the array of users printed
|
|
|
|
|
2007-09-19 07:55:00 +00:00
|
|
|
$user = make_context_subobj($user);
|
2007-12-15 23:30:38 +00:00
|
|
|
if ( !empty($user->hidden) ) {
|
2006-11-15 04:28:18 +00:00
|
|
|
// if the assignment is hidden, display icon
|
2009-07-03 06:19:25 +00:00
|
|
|
$hidden = " <img src=\"" . $OUTPUT->old_icon_url('t/show') . "\" title=\"".get_string('userhashiddenassignments', 'role')."\" alt=\"".get_string('hiddenassign')."\" class=\"hide-show-image\"/>";
|
2006-11-15 04:28:18 +00:00
|
|
|
} else {
|
2007-08-17 19:09:11 +00:00
|
|
|
$hidden = '';
|
2006-11-15 04:28:18 +00:00
|
|
|
}
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2006-10-01 06:18:18 +00:00
|
|
|
if ($user->lastaccess) {
|
|
|
|
$lastaccess = format_time(time() - $user->lastaccess, $datestring);
|
2006-09-28 06:41:07 +00:00
|
|
|
} else {
|
|
|
|
$lastaccess = $strnever;
|
|
|
|
}
|
|
|
|
|
2006-10-01 06:18:18 +00:00
|
|
|
if (empty($user->country)) {
|
2006-09-28 06:41:07 +00:00
|
|
|
$country = '';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if($countrysort) {
|
2006-10-01 06:18:18 +00:00
|
|
|
$country = '('.$user->country.') '.$countries[$user->country];
|
2006-08-09 13:53:12 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-10-01 06:18:18 +00:00
|
|
|
$country = $countries[$user->country];
|
2006-08-09 13:53:12 +00:00
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2007-09-19 07:55:00 +00:00
|
|
|
if (!isset($user->context)) {
|
|
|
|
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
|
|
|
|
} else {
|
|
|
|
$usercontext = $user->context;
|
|
|
|
}
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2008-02-08 03:59:38 +00:00
|
|
|
if ($piclink = ($USER->id == $user->id || has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext))) {
|
2006-12-07 06:14:52 +00:00
|
|
|
$profilelink = '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user).'</a></strong>';
|
|
|
|
} else {
|
2007-08-17 19:09:11 +00:00
|
|
|
$profilelink = '<strong>'.fullname($user).'</strong>';
|
2006-12-07 06:14:52 +00:00
|
|
|
}
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2009-08-20 08:50:22 +00:00
|
|
|
$userpic = moodle_user_picture::make($user, $course->id);
|
|
|
|
$userpic->link = $piclink;
|
|
|
|
$data = array ($OUTPUT->user_picture($userpic), $profilelink . $hidden);
|
2006-12-07 06:14:52 +00:00
|
|
|
|
2007-11-23 00:23:39 +00:00
|
|
|
if ($mode === MODE_BRIEF && !isset($hiddenfields['city'])) {
|
2006-10-01 06:18:18 +00:00
|
|
|
$data[] = $user->city;
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
2007-11-23 00:23:39 +00:00
|
|
|
if ($mode === MODE_BRIEF && !isset($hiddenfields['country'])) {
|
2006-09-28 06:41:07 +00:00
|
|
|
$data[] = $country;
|
|
|
|
}
|
|
|
|
if (!isset($hiddenfields['lastaccess'])) {
|
|
|
|
$data[] = $lastaccess;
|
|
|
|
}
|
|
|
|
if ($course->enrolperiod) {
|
2006-10-01 06:18:18 +00:00
|
|
|
if ($user->timeend) {
|
|
|
|
$data[] = userdate($user->timeend, $timeformat);
|
2006-09-28 06:41:07 +00:00
|
|
|
} else {
|
|
|
|
$data[] = get_string('unlimited');
|
2006-08-09 13:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-23 00:22:56 +00:00
|
|
|
|
|
|
|
if (isset($userlist_extra) && isset($userlist_extra[$user->id])) {
|
|
|
|
$ras = $userlist_extra[$user->id]['ra'];
|
|
|
|
$rastring = '';
|
|
|
|
foreach ($ras AS $key=>$ra) {
|
|
|
|
$rolename = $rolenames [ $ra['roleid'] ] ;
|
|
|
|
if ($ra['ctxlevel'] == CONTEXT_COURSECAT) {
|
2007-11-23 00:23:39 +00:00
|
|
|
$rastring .= $rolename. ' @ ' . '<a href="'.$CFG->wwwroot.'/course/category.php?id='.$ra['ctxinstanceid'].'">'.s($ra['ccname']).'</a>';
|
2007-11-23 00:22:56 +00:00
|
|
|
} elseif ($ra['ctxlevel'] == CONTEXT_SYSTEM) {
|
2007-11-23 00:23:39 +00:00
|
|
|
$rastring .= $rolename. ' - ' . get_string('globalrole','role');
|
2007-11-23 00:22:56 +00:00
|
|
|
} else {
|
|
|
|
$rastring .= $rolename;
|
|
|
|
}
|
|
|
|
if ($showenrolplugin) {
|
|
|
|
$rastring .= '<br />';
|
|
|
|
} else {
|
|
|
|
$rastring .= ' ('. $ra['enrolplugin'] .')<br />';
|
|
|
|
}
|
|
|
|
}
|
2008-07-21 07:18:58 +00:00
|
|
|
$data[] = $rastring;
|
2007-11-23 00:23:24 +00:00
|
|
|
if ($groupmode != 0) {
|
2007-11-23 00:22:56 +00:00
|
|
|
// htmlescape with s() and implode the array
|
|
|
|
$data[] = implode(', ', array_map('s',$userlist_extra[$user->id]['group']));
|
2007-11-23 00:23:24 +00:00
|
|
|
if (!empty($CFG->enablegroupings)) {
|
|
|
|
$data[] = implode(', ', array_map('s', $userlist_extra[$user->id]['gping']));
|
|
|
|
}
|
2007-11-23 00:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-28 06:41:07 +00:00
|
|
|
if ($bulkoperations) {
|
2006-10-01 06:18:18 +00:00
|
|
|
$data[] = '<input type="checkbox" name="user'.$user->id.'" />';
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
|
|
|
$table->add_data($data);
|
2006-08-09 13:53:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2006-09-28 04:45:39 +00:00
|
|
|
|
2006-09-28 06:41:07 +00:00
|
|
|
$table->print_html();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bulkoperations) {
|
2007-01-06 14:07:00 +00:00
|
|
|
echo '<br /><div class="buttons">';
|
2006-09-28 06:41:07 +00:00
|
|
|
echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> ';
|
|
|
|
echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> ';
|
2007-03-14 01:50:54 +00:00
|
|
|
$displaylist = array();
|
2007-11-21 07:53:42 +00:00
|
|
|
$displaylist['messageselect.php'] = get_string('messageselectadd');
|
2008-08-26 05:45:07 +00:00
|
|
|
if (!empty($CFG->enablenotes) && has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) {
|
2007-07-05 06:53:17 +00:00
|
|
|
$displaylist['addnote.php'] = get_string('addnewnote', 'notes');
|
|
|
|
$displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes');
|
|
|
|
}
|
2007-11-21 07:53:42 +00:00
|
|
|
|
2007-10-02 03:37:30 +00:00
|
|
|
if ($context->id != $frontpagectx->id) {
|
|
|
|
$displaylist['extendenrol.php'] = get_string('extendenrol');
|
|
|
|
$displaylist['groupextendenrol.php'] = get_string('groupextendenrol');
|
|
|
|
}
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2009-08-18 05:19:25 +00:00
|
|
|
echo $OUTPUT->help_icon(moodle_help_icon::make("participantswithselectedusers", get_string("withselectedusers")));
|
2009-08-10 08:38:45 +00:00
|
|
|
$select = new html_select();
|
2009-08-04 02:05:32 +00:00
|
|
|
$select->options = $displaylist;
|
|
|
|
$select->name = "formaction";
|
|
|
|
$select->label = get_string("withselectedusers");
|
|
|
|
$select->add_action('change', 'conditionalsubmit', array('formid' => 'participantsform'));
|
|
|
|
echo $OUTPUT->select($select);
|
2006-09-28 06:48:50 +00:00
|
|
|
echo '<input type="hidden" name="id" value="'.$course->id.'" />';
|
2008-05-08 02:44:50 +00:00
|
|
|
echo '<div id="noscriptparticipantsform" style="display: inline;">';
|
|
|
|
echo '<input type="submit" value="'.get_string('ok').'" /></div>';
|
2009-07-02 04:02:40 +00:00
|
|
|
$PAGE->requires->js_function_call('hide_item', Array('noscriptparticipantsform'));
|
2007-01-06 14:07:00 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '</div>';
|
|
|
|
echo '</form>';
|
2007-03-26 09:28:58 +00:00
|
|
|
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
2006-09-28 04:45:39 +00:00
|
|
|
|
2006-09-28 06:41:07 +00:00
|
|
|
if ($bulkoperations && $totalcount > ($perpage*3)) {
|
2009-02-04 09:15:12 +00:00
|
|
|
echo '<form action="index.php" class="searchform"><div><input type="hidden" name="id" value="'.$course->id.'" />'.get_string('search').': '."\n";
|
2007-07-04 08:31:54 +00:00
|
|
|
echo '<input type="text" name="search" value="'.s($search).'" /> <input type="submit" value="'.get_string('search').'" /></div></form>'."\n";
|
2006-09-28 06:41:07 +00:00
|
|
|
}
|
2006-09-28 04:45:39 +00:00
|
|
|
|
2009-08-10 03:40:04 +00:00
|
|
|
$perpageurl = clone($baseurl);
|
|
|
|
$perpageurl->remove_params('perpage');
|
2006-09-28 06:41:07 +00:00
|
|
|
if ($perpage == SHOW_ALL_PAGE_SIZE) {
|
2009-08-10 03:40:04 +00:00
|
|
|
$perpageurl->param('perpage', DEFAULT_PAGE_SIZE);
|
|
|
|
echo '<div id="showall"><a href="'.$perpageurl->out().'">'.get_string('showperpage', '', DEFAULT_PAGE_SIZE).'</a></div>';
|
2006-09-28 06:41:07 +00:00
|
|
|
|
|
|
|
} else if ($matchcount > 0 && $perpage < $matchcount) {
|
2009-08-10 03:40:04 +00:00
|
|
|
$perpageurl->param('perpage', SHOW_ALL_PAGE_SIZE);
|
|
|
|
echo '<div id="showall"><a href="'.$perpageurl.'">'.get_string('showall', '', $matchcount).'</a></div>';
|
2006-09-28 04:45:39 +00:00
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
|
2009-08-06 14:08:20 +00:00
|
|
|
echo $OUTPUT->footer();
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2007-10-10 12:19:27 +00:00
|
|
|
if ($userlist) {
|
2008-05-31 11:13:21 +00:00
|
|
|
$userlist->close();
|
2007-10-10 12:19:27 +00:00
|
|
|
}
|
2006-09-28 06:41:07 +00:00
|
|
|
|
|
|
|
|
2008-04-02 06:35:49 +00:00
|
|
|
function get_course_lastaccess_sql($accesssince='') {
|
2005-11-17 02:46:27 +00:00
|
|
|
if (empty($accesssince)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if ($accesssince == -1) { // never
|
2006-09-12 07:39:25 +00:00
|
|
|
return ' AND ul.timeaccess = 0';
|
2005-11-17 02:46:27 +00:00
|
|
|
} else {
|
2008-04-02 06:35:49 +00:00
|
|
|
return ' AND ul.timeaccess != 0 AND ul.timeaccess < '.$accesssince;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_user_lastaccess_sql($accesssince='') {
|
|
|
|
if (empty($accesssince)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if ($accesssince == -1) { // never
|
|
|
|
return ' AND u.lastaccess = 0';
|
|
|
|
} else {
|
|
|
|
return ' AND u.lastaccess != 0 AND u.lastaccess < '.$accesssince;
|
2005-11-17 02:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-23 00:22:56 +00:00
|
|
|
function get_participants_extra ($userids, $avoidroles, $course, $context) {
|
2008-05-31 11:13:21 +00:00
|
|
|
global $CFG, $DB;
|
2007-11-23 00:22:56 +00:00
|
|
|
|
|
|
|
if (count($userids) === 0 || count($avoidroles) === 0) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2008-05-31 11:13:21 +00:00
|
|
|
$params = array();
|
|
|
|
|
2007-11-23 00:22:56 +00:00
|
|
|
$userids = implode(',', $userids);
|
|
|
|
|
|
|
|
// turn the path into a list of context ids
|
|
|
|
$contextids = substr($context->path, 1); // kill leading slash
|
|
|
|
$contextids = str_replace('/', ',', $contextids);;
|
|
|
|
|
|
|
|
if (count($avoidroles) > 0) {
|
|
|
|
$avoidroles = implode(',', $avoidroles);
|
|
|
|
$avoidrolescond = " AND ra.roleid NOT IN ($avoidroles) ";
|
|
|
|
} else {
|
|
|
|
$avoidrolescond = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($CFG->enablegroupings)) {
|
2008-05-31 11:13:21 +00:00
|
|
|
$gpjoin = "LEFT OUTER JOIN {groupings_groups} gpg
|
|
|
|
ON gpg.groupid=g.id
|
|
|
|
LEFT OUTER JOIN {groupings} gp
|
|
|
|
ON (gp.courseid={$course->id} AND gp.id=gpg.groupingid)";
|
2007-11-23 00:22:56 +00:00
|
|
|
$gpselect = ',gp.id AS gpid, gp.name AS gpname ';
|
|
|
|
} else {
|
|
|
|
$gpjoin = '';
|
|
|
|
$gpselect = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: this returns strange redundant rows, perhaps
|
|
|
|
// due to the multiple OUTER JOINs. If we can tweak the
|
|
|
|
// JOINs to avoid it ot
|
2008-07-21 07:18:58 +00:00
|
|
|
$sql = "SELECT DISTINCT ra.userid,
|
|
|
|
ctx.id AS ctxid, ctx.path AS ctxpath, ctx.depth AS ctxdepth,
|
2007-11-23 00:22:56 +00:00
|
|
|
ctx.contextlevel AS ctxlevel, ctx.instanceid AS ctxinstanceid,
|
2008-07-21 07:18:58 +00:00
|
|
|
cc.name AS ccname,
|
2007-11-23 00:22:56 +00:00
|
|
|
ra.roleid AS roleid,
|
|
|
|
ra.enrol AS enrolplugin,
|
|
|
|
g.id AS gid, g.name AS gname
|
|
|
|
$gpselect
|
2008-05-31 11:13:21 +00:00
|
|
|
FROM {role_assignments} ra
|
|
|
|
JOIN {context} ctx
|
|
|
|
ON (ra.contextid=ctx.id)
|
|
|
|
LEFT JOIN {course_categories} cc
|
|
|
|
ON (ctx.contextlevel=40 AND ctx.instanceid=cc.id)
|
2007-11-23 00:22:56 +00:00
|
|
|
|
|
|
|
/* only if groups active */
|
2008-05-31 11:13:21 +00:00
|
|
|
LEFT JOIN {groups_members} gm
|
|
|
|
ON (ra.userid=gm.userid)
|
|
|
|
LEFT JOIN {groups} g
|
|
|
|
ON (gm.groupid=g.id AND g.courseid={$course->id})
|
2007-11-23 00:22:56 +00:00
|
|
|
/* and if groupings is enabled... */
|
|
|
|
$gpjoin
|
|
|
|
|
2008-07-21 07:18:58 +00:00
|
|
|
WHERE ra.userid IN ( $userids )
|
|
|
|
AND ra.contextid in ( $contextids )
|
2008-05-31 11:13:21 +00:00
|
|
|
$avoidrolescond
|
2007-11-23 00:22:56 +00:00
|
|
|
|
2008-05-31 11:13:21 +00:00
|
|
|
ORDER BY ra.userid, ctx.depth DESC";
|
2007-11-23 00:22:56 +00:00
|
|
|
|
2008-05-31 11:13:21 +00:00
|
|
|
$rs = $DB->get_recordset_sql($sql, $params);
|
2007-11-23 00:22:56 +00:00
|
|
|
$extra = array();
|
|
|
|
|
|
|
|
// Data structure -
|
|
|
|
// $extra [ $userid ] [ 'group' ] [ $groupid => 'group name']
|
|
|
|
// [ 'gping' ] [ $gpingid => 'gping name']
|
|
|
|
// [ 'ra' ] [ [ "$ctxid:$roleid" => [ctxid => $ctxid
|
2008-07-21 07:18:58 +00:00
|
|
|
// ctxdepth => $ctxdepth,
|
2007-11-23 00:22:56 +00:00
|
|
|
// ctxpath => $ctxpath,
|
|
|
|
// ctxname => 'name' (categories only)
|
2008-07-21 07:18:58 +00:00
|
|
|
// ctxinstid =>
|
2007-11-23 00:22:56 +00:00
|
|
|
// roleid => $roleid
|
|
|
|
// enrol => $pluginname
|
|
|
|
//
|
|
|
|
// Might be interesting to add to RA timestart, timeend, timemodified,
|
|
|
|
// and modifierid (with an outer join to mdl_user!
|
|
|
|
//
|
|
|
|
|
2008-05-31 11:13:21 +00:00
|
|
|
foreach ($rs as $rec) {
|
2007-11-23 00:22:56 +00:00
|
|
|
$userid = $rec->userid;
|
|
|
|
|
|
|
|
// Prime an initial user rec...
|
|
|
|
if (!isset($extra[$userid])) {
|
|
|
|
$extra[$userid] = array( 'group' => array(),
|
|
|
|
'gping' => array(),
|
|
|
|
'ra' => array() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($rec->gid)) {
|
|
|
|
$extra[$userid]['group'][$rec->gid]= $rec->gname;
|
|
|
|
}
|
|
|
|
if (!empty($rec->gpid)) {
|
|
|
|
$extra[$userid]['gping'][$rec->gpid]= $rec->gpname;
|
|
|
|
}
|
|
|
|
$rakey = $rec->ctxid . ':' . $rec->roleid;
|
|
|
|
if (!isset($extra[$userid]['ra'][$rakey])) {
|
|
|
|
$extra[$userid]['ra'][$rakey] = array('ctxid' => $rec->ctxid,
|
|
|
|
'ctxlevel' => $rec->ctxlevel,
|
|
|
|
'ctxinstanceid' => $rec->ctxinstanceid,
|
|
|
|
'ccname' => $rec->ccname,
|
|
|
|
'roleid' => $rec->roleid,
|
|
|
|
'enrolplugin' => $rec->enrolplugin);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2008-05-31 11:13:21 +00:00
|
|
|
$rs->close();
|
2007-11-23 00:22:56 +00:00
|
|
|
return $extra;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
?>
|