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 );
2001-11-22 06:23:56 +00:00
2005-06-03 23:20:01 +00:00
$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
2005-11-17 02:46:27 +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 );
2006-08-09 13:53:12 +00:00
$roleid = optional_param ( 'roleid' , 0 , PARAM_INT ); // optional roleid
2006-08-14 08:38:49 +00:00
2006-09-19 06:36:54 +00:00
$contextid = optional_param ( 'contextid' , 0 , PARAM_INT ); // one of this or
$courseid = optional_param ( 'id' , 0 , PARAM_INT ); // this are required
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 )) {
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 " );
}
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
2007-03-05 20:13:16 +00:00
$sitecontext = get_context_instance ( CONTEXT_SYSTEM );
if ( ! has_capability ( 'moodle/course:viewparticipants' , $context )) {
2006-11-20 20:47:17 +00:00
print_error ( 'nopermissions' );
}
$rolenames = array ();
2007-03-30 16:01:44 +00:00
$avoidroles = array ();
2006-11-20 20:47:17 +00:00
if ( $roles = get_roles_used_in_context ( $context , true )) {
2007-03-30 16:01:44 +00:00
// We should ONLY allow roles with moodle/course:view because otherwise we get little niggly issues
// like MDL-8093
// 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 );
2006-11-20 20:47:17 +00:00
$doanythingroles = get_roles_with_capability ( 'moodle/site:doanything' , CAP_ALLOW , $sitecontext );
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
}
// no roles to display yet?
if ( empty ( $rolenames )) {
2006-08-25 08:27:27 +00:00
if ( has_capability ( 'moodle/user: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 {
2006-11-20 20:47:17 +00:00
error ( 'No participants found for this course' );
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 ) {
$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
2005-06-03 23:20:01 +00:00
$currentgroup = get_and_set_current_group ( $course , $groupmode , $group );
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
2004-09-01 13:56:12 +00:00
$isseparategroups = ( $course -> groupmode == SEPARATEGROUPS and $course -> groupmodeforce and
2007-03-05 20:13:16 +00:00
! has_capability ( 'moodle/site:accessallgroups' , $context ));
2004-01-31 04:08:10 +00:00
2006-11-08 15:30:07 +00:00
if ( $isseparategroups and ( ! $currentgroup ) ) {
print_header ( " $course->shortname : " . get_string ( 'participants' ), $course -> fullname ,
" <a href= \" $CFG->wwwroot /course/view.php?id= $course->id\ " > $course -> shortname </ a > -> " .
get_string ( 'participants' ), " " , " " , true , " " , navmenu ( $course ));
2005-03-22 16:04:10 +00:00
print_heading ( get_string ( " notingroup " , " forum " ));
print_footer ( $course );
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.
2007-07-04 08:31:54 +00:00
$baseurl = $CFG -> wwwroot . '/user/index.php?contextid=' . $context -> id . '&roleid=' . $roleid . '&id=' . $course -> id . '&group=' . $currentgroup . '&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
2006-11-12 08:55:13 +00:00
if ( $course -> id != SITEID ) {
2005-06-03 23:20:01 +00:00
print_header ( " $course->shortname : " . get_string ( 'participants' ), $course -> fullname ,
2004-09-07 08:05:25 +00:00
" <a href= \" ../course/view.php?id= $course->id\ " > $course -> shortname </ a > -> " .
2005-06-03 23:20:01 +00:00
get_string ( 'participants' ), " " , " " , true , " " , navmenu ( $course ));
2003-04-28 04:32:55 +00:00
} else {
2005-06-03 23:20:01 +00:00
print_header ( " $course->shortname : " . get_string ( 'participants' ), $course -> fullname ,
get_string ( 'participants' ), " " , " " , true , " " , navmenu ( $course ));
2003-09-18 04:46:34 +00:00
}
2006-03-09 09:09:20 +00:00
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 ;
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 ));
}
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 ();
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
}
2006-10-01 19:55:47 +00:00
popup_form ( $CFG -> wwwroot . '/user/index.php?roleid=' . $roleid . '&sifirst=&silast=&id=' ,
2007-03-05 20:13:16 +00:00
$courselist , 'courseform' , $course -> id , '' , '' , '' , false , 'self' , get_string ( 'mycourses' ));
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">' ;
setup_and_print_groups ( $course , $groupmode , $baseurl );
echo '</td>' ;
2005-03-22 16:04:10 +00:00
2006-09-28 06:41:07 +00:00
// 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 ();
2006-10-01 19:55:47 +00:00
2006-09-28 06:41:07 +00:00
// makes sense for this to go first.
$timeoptions [ 0 ] = get_string ( 'selectperiod' );
2006-10-01 19:55:47 +00:00
2006-09-28 06:41:07 +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
}
2006-09-28 06:41:07 +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
}
2006-09-28 06:41:07 +00:00
}
2006-10-01 19:55:47 +00:00
// months
2006-09-28 06:41:07 +00:00
for ( $i = 2 ; $i < 12 ; $i ++ ) {
if ( strtotime ( '-' . $i . ' months' , $now ) >= $minlastaccess ) {
$timeoptions [ strtotime ( '-' . $i . ' months' , $now )] = get_string ( 'nummonths' , 'moodle' , $i );
2005-11-17 02:46:27 +00:00
}
}
2006-09-28 06:41:07 +00:00
// try a year
if ( strtotime ( '-1 year' , $now ) >= $minlastaccess ) {
$timeoptions [ strtotime ( '-1 year' , $now )] = get_string ( 'lastyear' );
}
2006-10-01 19:55:47 +00:00
2006-09-28 06:41:07 +00:00
if ( ! empty ( $lastaccess0exists )) {
$timeoptions [ - 1 ] = get_string ( 'never' );
2006-10-01 19:55:47 +00:00
}
2006-09-28 06:41:07 +00:00
if ( count ( $timeoptions ) > 1 ) {
echo '<td class="left">' ;
$baseurl = preg_replace ( '/&accesssince=' . $accesssince . '/' , '' , $baseurl );
2007-03-05 20:13:16 +00:00
popup_form ( $baseurl . '&accesssince=' , $timeoptions , 'timeoptions' , $accesssince , '' , '' , '' , false , 'self' , get_string ( 'usersnoaccesssince' ));
2006-09-28 06:41:07 +00:00
echo '</td>' ;
}
2006-10-01 19:55:47 +00:00
2005-11-17 02:46:27 +00:00
2005-06-03 23:20:01 +00:00
echo '<td class="right">' ;
2005-03-22 16:04:10 +00:00
$formatmenu = array ( '0' => get_string ( 'detailedless' ),
'1' => get_string ( 'detailedmore' ));
2007-03-05 20:13:16 +00:00
popup_form ( $baseurl . '&mode=' , $formatmenu , 'formatmenu' , $fullmode , '' , '' , '' , false , 'self' , get_string ( 'userlist' ));
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-01-04 13:15:04 +13:00
if ( $group = groups_get_group ( $currentgroup )) { //TODO:
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-01-04 13:15:04 +13:00
echo ' <a title="' . get_string ( 'editgroupprofile' ) . '" href="' . groups_group_edit_url ( $course -> id , $group -> id ) . '">' ;
echo '<img src="' . $CFG -> pixpath . '/t/edit.gif" 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-10-01 19:55:47 +00:00
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' );
$tableheaders = array ( get_string ( 'userpic' ), get_string ( 'fullname' ));
2006-09-28 06:41:07 +00:00
if ( ! isset ( $hiddenfields [ 'city' ])) {
$tablecolumns [] = 'city' ;
$tableheaders [] = get_string ( 'city' );
}
if ( ! isset ( $hiddenfields [ 'country' ])) {
$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' );
}
if ( $bulkoperations ) {
$tablecolumns [] = '' ;
$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 );
$table -> define_baseurl ( $baseurl );
2006-11-13 03:43:12 +00:00
2006-09-28 06:41:07 +00:00
$table -> sortable ( true , 'lastaccess' , SORT_DESC );
$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 ();
// 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 {
2006-10-01 19:55:47 +00:00
$listofcontexts = '(' . $sitecontext -> id . ')' ; // must be site
2006-09-28 06:41:07 +00:00
}
2006-08-09 13:53:12 +00:00
if ( $roleid ) {
2006-09-28 06:41:07 +00:00
$selectrole = " AND r.roleid = $roleid " ;
} else {
$selectrole = " " ;
}
2006-12-06 04:54:31 +00:00
$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, ul.timeaccess AS lastaccess, r.hidden ' ; // s.lastaccess
$select .= $course -> enrolperiod ? ', r.timeend ' : '' ;
2006-09-28 06:41:07 +00:00
$from = " FROM { $CFG -> prefix } user u INNER JOIN
{ $CFG -> prefix } role_assignments r on u . id = r . userid LEFT OUTER JOIN
2006-10-05 08:54:35 +00:00
{ $CFG -> prefix } user_lastaccess ul on ( r . userid = ul . userid and ul . courseid = $course -> id ) " ;
2006-11-15 04:28:18 +00:00
2006-12-04 03:05:40 +00:00
$hiddensql = has_capability ( 'moodle/role:viewhiddenassigns' , $context ) ? '' : ' AND r.hidden = 0 ' ;
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 = '' ;
}
2006-11-15 04:28:18 +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
2006-10-01 19:55:47 +00:00
$where = " WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts )
2006-09-28 06:41:07 +00:00
AND u . deleted = 0 $selectrole
AND ( ul . courseid = $course -> id OR ul . courseid IS NULL )
2006-12-04 03:05:40 +00:00
AND u . username != 'guest'
$adminroles
2006-11-15 04:28:18 +00:00
$hiddensql " ;
2006-08-09 13:53:12 +00:00
$where .= get_lastaccess_sql ( $accesssince );
2006-09-12 07:39:25 +00:00
2006-09-28 06:41:07 +00:00
$wheresearch = '' ;
if ( ! empty ( $search )) {
$LIKE = sql_ilike ();
$fullname = sql_fullname ( 'u.firstname' , 'u.lastname' );
$wheresearch .= ' AND (' . $fullname . ' ' . $LIKE . '\'%' . $search . '%\' OR email ' . $LIKE . '\'%' . $search . '%\' OR idnumber ' . $LIKE . ' \'%' . $search . '%\') ' ;
}
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 ;
}
$totalcount = count_records_sql ( 'SELECT COUNT(distinct u.id) ' . $from . $where ); // Each user could have > 1 role
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 = '' ;
}
2006-12-06 04:54:31 +00:00
$matchcount = count_records_sql ( 'SELECT COUNT(distinct u.id) ' . $from . $where . $wheresearch );
2006-09-28 06:41:07 +00:00
$table -> initialbars ( $totalcount > $perpage );
$table -> pagesize ( $perpage , $matchcount );
2006-10-01 06:18:18 +00:00
$userlist = get_records_sql ( $select . $from . $where . $wheresearch . $sort ,
2006-09-28 06:41:07 +00:00
$table -> get_page_start (), $table -> get_page_size ());
2006-09-28 06:04:39 +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">' ;
echo get_string ( 'currentrole' , 'role' ) . ': ' ;
$rolenames = array ( 0 => get_string ( 'all' )) + $rolenames ;
2006-11-20 20:47:17 +00:00
popup_form ( " $CFG->wwwroot /user/index.php?contextid= $context->id &sifirst=&silast=&roleid= " , $rolenames ,
2006-09-28 06:41:07 +00:00
'rolesform' , $roleid , '' );
}
2006-09-28 06:04:39 +00:00
2006-09-28 06:41:07 +00:00
if ( $roleid ) {
2006-08-14 08:38:49 +00:00
if ( ! $currentrole = get_record ( 'role' , 'id' , $roleid )) {
error ( 'That role does not exist' );
}
2006-09-28 04:45:39 +00:00
$a -> number = $totalcount ;
2007-03-26 09:28:06 +00:00
$a -> role = $currentrole -> name ;
$heading = format_string ( get_string ( 'xuserswiththerole' , 'role' , $a ));
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 . '">' ;
2007-01-08 09:14:05 +00:00
$heading .= '<img src="' . $CFG -> pixpath . '/i/edit.gif" class="icon" alt="" /></a>' ;
2006-09-28 06:04:39 +00:00
}
print_heading ( $heading , 'center' , 3 );
} else {
2006-10-31 01:21:48 +00:00
if ( $matchcount < $totalcount ) {
2007-01-06 14:07:00 +00:00
print_heading ( get_string ( 'allparticipants' ) . ': ' . $matchcount . '/' . $totalcount , '' , 3 );
2006-10-31 01:21:48 +00:00
} else {
2007-01-06 14:07:00 +00:00
print_heading ( get_string ( 'allparticipants' ) . ': ' . $matchcount , '' , 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 ) {
echo '
2006-11-28 10:23:26 +00:00
< script type = " text/javascript " >
2006-12-22 04:25:00 +00:00
//<![CDATA[
2006-09-28 06:41:07 +00:00
function checksubmit ( form ) {
var destination = form . formaction . options [ form . formaction . selectedIndex ] . value ;
if ( destination == " " || ! checkchecked ( form )) {
form . formaction . selectedIndex = 0 ;
return false ;
} else {
return true ;
}
2006-08-09 13:53:12 +00:00
}
2006-09-28 06:41:07 +00:00
function checkchecked ( form ) {
var inputs = document . getElementsByTagName ( \ ' INPUT\ ' );
var checked = false ;
inputs = filterByParent ( inputs , function () { return form ;});
for ( var i = 0 ; i < inputs . length ; ++ i ) {
if ( inputs [ i ] . type == \ ' checkbox\ ' && inputs [ i ] . checked ) {
checked = true ;
}
2006-08-09 13:53:12 +00:00
}
2006-09-28 06:41:07 +00:00
return checked ;
}
2006-12-22 04:25:00 +00:00
//]]>
2006-09-28 06:41:07 +00:00
</ script >
' ;
2007-01-06 14:07:00 +00:00
echo '<form action="action_redir.php" method="post" id="participantsform" onsubmit="return checksubmit(this);">' ;
echo '<div>' ;
2006-09-28 06:41:07 +00:00
echo '<input type="hidden" name="sesskey" value="' . $USER -> sesskey . '" />' ;
2007-05-09 10:05:08 +00:00
echo '<input type="hidden" name="returnto" value="' . s ( $_SERVER [ 'REQUEST_URI' ]) . '" />' ;
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>' ;
}
if ( $fullmode ) { // Print simple listing
if ( $totalcount < 1 ) {
2006-10-01 06:18:18 +00:00
print_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 )) {
echo '<a href="' . $baseurl . '&sifirst=">' . $strall . '</a>' ;
} 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 {
2006-09-28 06:41:07 +00:00
echo ' <a href="' . $baseurl . '&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 )) {
echo '<a href="' . $baseurl . '&silast=">' . $strall . '</a>' ;
} else {
echo '<strong>' . $strall . '</strong>' ;
}
foreach ( $alpha as $letter ) {
if ( $letter == $lastinitial ) {
echo ' <strong>' . $letter . '</strong>' ;
} else {
echo ' <a href="' . $baseurl . '&silast=' . $letter . '">' . $letter . '</a>' ;
2006-08-09 13:53:12 +00:00
}
}
2006-09-28 06:41:07 +00:00
echo '</div>' ;
print_paging_bar ( $matchcount , intval ( $table -> get_page_start () / $perpage ), $perpage , $baseurl . '&' , 'spage' );
}
if ( $matchcount > 0 ) {
2006-10-01 06:18:18 +00:00
foreach ( $userlist as $user ) {
print_user ( $user , $course , $bulkoperations );
2006-08-09 13:53:12 +00:00
}
2006-09-28 06:41:07 +00:00
} else {
print_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
2006-10-01 06:18:18 +00:00
if ( ! empty ( $userlist )) {
foreach ( $userlist as $user ) {
2006-11-15 04:28:18 +00:00
if ( $user -> hidden ) {
// if the assignment is hidden, display icon
$hidden = " <img src= \" { $CFG -> pixpath } /t/hide.gif \" alt= \" " . get_string ( 'hiddenassign' ) . " \" class= \" hide-show-image \" /> " ;
} else {
$hidden = '' ;
}
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
}
2006-12-07 06:14:52 +00:00
$usercontext = get_context_instance ( CONTEXT_USER , $user -> id );
if ( $piclink = ( $USER -> id == $user -> id || has_capability ( 'moodle/user:viewdetails' , $context ) || has_capability ( 'moodle/user:viewdetails' , $context ))) {
$profilelink = '<strong><a href="' . $CFG -> wwwroot . '/user/view.php?id=' . $user -> id . '&course=' . $course -> id . '">' . fullname ( $user ) . '</a></strong>' ;
} else {
$profilelink = '<strong>' . fullname ( $user ) . '</strong>' ;
}
2006-09-28 06:41:07 +00:00
$data = array (
2006-12-07 06:14:52 +00:00
print_user_picture ( $user -> id , $course -> id , $user -> picture , false , true , $piclink ),
$profilelink );
2006-09-28 06:41:07 +00:00
if ( ! isset ( $hiddenfields [ 'city' ])) {
2006-10-01 06:18:18 +00:00
$data [] = $user -> city ;
2006-09-28 06:41:07 +00:00
}
if ( ! isset ( $hiddenfields [ 'country' ])) {
$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
}
}
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 ();
// fix for MDL-8885, only show this if user has capability
2007-06-14 04:41:33 +00:00
if ( has_capability ( 'moodle/site:readallmessages' , $context ) && ! empty ( $CFG -> messaging )) {
2007-03-14 01:50:54 +00:00
$displaylist [ 'messageselect.php' ] = get_string ( 'messageselectadd' );
}
2007-05-22 02:08:22 +00:00
$displaylist [ 'extendenrol.php' ] = get_string ( 'extendenrol' );
$displaylist [ 'groupextendenrol.php' ] = get_string ( 'groupextendenrol' );
2006-09-28 06:41:07 +00:00
helpbutton ( " participantswithselectedusers " , get_string ( " withselectedusers " ));
2007-01-06 14:07:00 +00:00
choose_from_menu ( $displaylist , " formaction " , " " , get_string ( " withselectedusers " ), " if(checksubmit(this.form))this.form.submit(); " , " " );
2006-09-28 06:48:50 +00:00
echo '<input type="hidden" name="id" value="' . $course -> id . '" />' ;
2006-09-28 06:41:07 +00:00
echo '<input type="submit" value="' . get_string ( 'ok' ) . '" />' ;
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 )) {
2007-03-01 04:30:42 +00:00
echo '<form action="index.php"><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
2007-04-15 16:09:55 +00:00
$perpageurl = preg_replace ( '/&perpage=\d*/' , '' , $baseurl );
2006-09-28 06:41:07 +00:00
if ( $perpage == SHOW_ALL_PAGE_SIZE ) {
2007-04-15 16:09:55 +00:00
echo '<div id="showall"><a href="' . $perpageurl . '&perpage=' . DEFAULT_PAGE_SIZE . '">' . get_string ( 'showperpage' , '' , DEFAULT_PAGE_SIZE ) . '</a></div>' ;
2006-09-28 06:41:07 +00:00
} else if ( $matchcount > 0 && $perpage < $matchcount ) {
2007-04-15 16:09:55 +00:00
echo '<div id="showall"><a href="' . $perpageurl . '&perpage=' . SHOW_ALL_PAGE_SIZE . '">' . get_string ( 'showall' , '' , $matchcount ) . '</a></div>' ;
2006-09-28 04:45:39 +00:00
}
2006-09-28 06:41:07 +00:00
2005-06-03 23:20:01 +00:00
print_footer ( $course );
2001-11-22 06:23:56 +00:00
2005-11-17 02:46:27 +00:00
2006-09-28 06:41:07 +00:00
2005-11-17 02:46:27 +00:00
function get_lastaccess_sql ( $accesssince = '' ) {
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 {
2006-09-13 05:05:17 +00:00
return ' AND ul.timeaccess != 0 AND timeaccess < ' . $accesssince ;
2005-11-17 02:46:27 +00:00
}
}
2001-11-22 06:23:56 +00:00
?>