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 );
2001-11-22 06:23:56 +00:00
2005-06-03 23:20:01 +00:00
$id = required_param ( 'id' , PARAM_INT ); // Course id
$group = optional_param ( 'group' , - 1 , PARAM_INT ); // Group to show
$page = optional_param ( 'page' , 0 , PARAM_INT ); // which page to show
$perpage = optional_param ( 'perpage' , DEFAULT_PAGE_SIZE , PARAM_INT ); // how many per page
$mode = optional_param ( 'mode' , NULL ); // '0' for less details, '1' for more
$showteachers = optional_param ( 'teachers' , 1 , PARAM_INT ); // do we want to see the teacher list?
2005-11-17 02:46:27 +00:00
$accesssince = optional_param ( 'accesssince' , 0 , PARAM_INT ); // filter by last access. -1 = never
2005-11-17 03:09:07 +00:00
$search = optional_param ( 'search' , '' , PARAM_TEXT );
$showteachers = $showteachers && empty ( $search ); // if we're searching, we just want students.
2005-06-03 23:20:01 +00:00
if ( ! $course = get_record ( 'course' , 'id' , $id )) {
2001-11-22 06:23:56 +00:00
error ( " Course ID is incorrect " );
}
require_login ( $course -> id );
2004-09-01 13:56:12 +00:00
if ( ! $course -> category ) {
if ( ! $CFG -> showsiteparticipantslist and ! isteacher ( SITEID )) {
notice ( get_string ( 'sitepartlist0' ));
}
2005-01-23 21:38:01 +00:00
if ( $CFG -> showsiteparticipantslist < 2 and ! isteacherinanycourse ()) {
2004-09-01 13:56:12 +00:00
notice ( get_string ( 'sitepartlist1' ));
}
}
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
2004-01-10 16:41:29 +00:00
$isteacher = isteacher ( $course -> id );
2003-09-18 04:46:34 +00:00
2005-11-17 03:09:07 +00:00
if ( empty ( $isteacher )) {
$search = false ;
}
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
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
2004-01-31 04:08:10 +00:00
! isteacheredit ( $course -> id ));
2005-03-22 16:04:10 +00:00
if ( $isseparategroups and ( ! $currentgroup ) ) { //XXX
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.
2005-11-17 03:10:53 +00:00
$baseurl = $CFG -> wwwroot . '/user/index.php?id=' . $course -> id . '&group=' . $currentgroup . '&perpage=' . $perpage . '&teachers=' . $showteachers . '&accesssince=' . $accesssince . '&search=' . $search ;
2005-03-22 16:04:10 +00:00
/// Print headers
2004-01-31 04:08:10 +00:00
2003-09-18 04:46:34 +00:00
if ( $course -> category ) {
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
}
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
if ( $groupmode == VISIBLEGROUPS or ( $groupmode and isteacheredit ( $course -> id ))) {
if ( $groups = get_records_menu ( " groups " , " courseid " , $course -> id , " name ASC " , " id,name " )) {
echo '<td class="left">' ;
2005-06-03 23:20:01 +00:00
print_group_menu ( $groups , $groupmode , $currentgroup , $baseurl );
2005-03-22 16:04:10 +00:00
echo '</td>' ;
}
}
2005-11-17 02:46:27 +00:00
// get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
$minlastaccess = get_field_sql ( 'SELECT min(timeaccess) FROM ' . $CFG -> prefix . 'user_students WHERE course = ' . $course -> id . ' AND timeaccess != 0' );
$lastaccess0exists = record_exists ( 'user_students' , 'course' , $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 '<td class="left">' ;
echo get_string ( 'usersnoaccesssince' ) . ': ' ;
$baseurl = preg_replace ( '/&accesssince=' . $accesssince . '/' , '' , $baseurl );
echo popup_form ( $baseurl . '&accesssince=' , $timeoptions , 'timeoptions' , $accesssince , '' , '' , '' , true );
echo '</td>' ;
}
2005-06-03 23:20:01 +00:00
echo '<td class="right">' ;
2004-09-01 13:56:12 +00:00
echo get_string ( 'userlist' ) . ': ' ;
2005-03-22 16:04:10 +00:00
$formatmenu = array ( '0' => get_string ( 'detailedless' ),
'1' => get_string ( 'detailedmore' ));
2005-06-03 23:20:01 +00:00
echo popup_form ( $baseurl . '&mode=' , $formatmenu , 'formatmenu' , $fullmode , '' , '' , '' , true );
2005-03-22 16:04:10 +00:00
echo '</td></tr></table>' ;
if ( $currentgroup and ( ! $isseparategroups or isteacheredit ( $course -> id ))) { /// Display info about the group
if ( $group = get_record ( 'groups' , 'id' , $currentgroup )) {
if ( ! empty ( $group -> description ) or ( ! empty ( $group -> picture ) and empty ( $group -> hidepicture ))) {
echo '<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 ;
2005-05-03 18:11:34 +00:00
if ( isteacheredit ( $course -> id )) {
echo ' <a title="' . get_string ( 'editgroupprofile' ) . '" href="../course/groups.php?id=' . $course -> id . '&group=' . $group -> id . '">' ;
echo '<img src="' . $CFG -> pixpath . '/t/edit.gif" alt="" border="0">' ;
echo '</a>' ;
}
2005-03-22 16:04:10 +00:00
echo '</h3>' ;
echo format_text ( $group -> description );
echo '</td></tr></table>' ;
}
}
}
2004-09-01 13:56:12 +00:00
2005-06-03 23:20:01 +00:00
$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.
2005-04-27 18:30:02 +00:00
if ( $showteachers ) {
$tablecolumns = array ( 'picture' , 'fullname' , 'city' , 'country' , 'lastaccess' );
$tableheaders = array ( '' , get_string ( 'fullname' ), get_string ( 'city' ), get_string ( 'country' ), get_string ( 'lastaccess' ));
2005-10-21 01:18:30 +00:00
$table = new flexible_table ( 'user-index-teachers-' . $course -> id );
2005-04-27 18:30:02 +00:00
$table -> define_columns ( $tablecolumns );
$table -> define_headers ( $tableheaders );
2005-06-03 23:20:01 +00:00
$table -> define_baseurl ( $baseurl );
2005-04-27 18:30:02 +00:00
2005-06-20 03:47:19 +00:00
$table -> sortable ( true , 'lastaccess' , SORT_DESC );
2005-04-27 18:30:02 +00:00
$table -> set_attribute ( 'cellspacing' , '0' );
$table -> set_attribute ( 'id' , 'teachers' );
$table -> set_attribute ( 'class' , 'generaltable generalbox' );
$table -> setup ();
if ( $whereclause = $table -> get_sql_where ()) {
$whereclause .= ' AND ' ;
}
$teachersql = " SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest,
2005-06-03 23:20:01 +00:00
u . email , u . maildisplay , u . city , u . country , u . lastlogin , u . picture , u . lang , u . timezone ,
2005-04-27 18:30:02 +00:00
u . emailstop , t . authority , t . role , t . editall , t . timeaccess as lastaccess , m . groupid
FROM { $CFG -> prefix } user u
LEFT JOIN { $CFG -> prefix } user_teachers t ON t . userid = u . id
LEFT JOIN { $CFG -> prefix } groups_members m ON m . userid = u . id " ;
if ( $isseparategroups ) {
$whereclause .= '(t.editall OR groupid = ' . $currentgroup . ') AND ' ;
}
else if ( $currentgroup ) { // Displaying a group by choice
$whereclause .= 'groupid = ' . $currentgroup . ' AND ' ;
}
$teachersql .= 'WHERE ' . $whereclause . ' t.course = ' . $course -> id . ' AND u.deleted = 0 AND u.confirmed = 1 AND t.authority > 0' ;
2005-11-17 02:46:27 +00:00
$teachersql .= get_lastaccess_sql ( $accesssince );
2005-04-27 18:30:02 +00:00
if ( $sortclause = $table -> get_sql_sort ()) {
$teachersql .= ' ORDER BY ' . $sortclause ;
}
$teachers = get_records_sql ( $teachersql );
if ( ! empty ( $teachers )) {
2005-06-03 23:20:01 +00:00
echo '<h2>' . $course -> teachers ;
echo ' <a href="' . $baseurl . '&teachers=0">' ;
echo '<img src="' . $CFG -> pixpath . '/i/hide.gif" height="16" width="16" alt="' . get_string ( 'hide' ) . '" /></a>' ;
2005-02-13 13:23:46 +00:00
if ( isadmin () or ( $course -> category and ( iscreator () or ( isteacheredit ( $course -> id ) and ! empty ( $CFG -> teacherassignteachers ))))) {
2005-06-03 23:20:01 +00:00
echo ' <a href="' . $CFG -> wwwroot . '/course/teacher.php?id=' . $course -> id . '">' ;
echo '<img src="' . $CFG -> pixpath . '/i/edit.gif" height="16" width="16" alt="' . get_string ( 'edit' ) . '" /></a>' ;
2004-09-04 13:51:19 +00:00
}
echo '</h2>' ;
2004-09-06 08:06:55 +00:00
2005-06-03 23:20:01 +00:00
$exceptions = array_keys ( $teachers );
2005-04-27 18:30:02 +00:00
2005-03-22 16:04:10 +00:00
if ( $fullmode ) {
foreach ( $teachers as $key => $teacher ) {
print_user ( $teacher , $course );
2003-09-18 04:46:34 +00:00
}
2005-03-22 16:04:10 +00:00
} else {
2005-06-03 23:41:06 +00:00
$countrysort = ( strpos ( $sortclause , 'country' ) !== false );
2005-04-27 18:30:02 +00:00
foreach ( $teachers as $teacher ) {
if ( $teacher -> lastaccess ) {
$lastaccess = format_time ( time () - $teacher -> lastaccess , $datestring );
} else {
$lastaccess = $strnever ;
}
2005-06-03 23:41:06 +00:00
if ( empty ( $teacher -> country )) {
$country = '' ;
}
else {
if ( $countrysort ) {
$country = '(' . $teacher -> country . ') ' . $countries [ $teacher -> country ];
}
else {
$country = $countries [ $teacher -> country ];
}
}
2005-04-27 18:30:02 +00:00
$table -> add_data ( array (
//'<input type="checkbox" name="userid[]" value="'.$teacher->id.'" />',
print_user_picture ( $teacher -> id , $course -> id , $teacher -> picture , false , true ),
'<strong><a href="' . $CFG -> wwwroot . '/user/view.php?id=' . $teacher -> id . '&course=' . $course -> id . '">' . fullname ( $teacher , $isteacher ) . '</a></strong>' ,
$teacher -> city ,
2005-06-03 23:41:06 +00:00
$country ,
2005-04-27 18:30:02 +00:00
$lastaccess ));
}
2005-06-03 23:20:01 +00:00
$table -> print_html ();
2003-09-18 04:46:34 +00:00
}
}
2003-04-28 04:32:55 +00:00
}
2005-06-03 23:20:01 +00:00
else {
// Don't show teachers
echo '<h2>' . $course -> teachers ;
echo ' <a href="' . $baseurl . '&teachers=1">' ;
echo '<img src="' . $CFG -> pixpath . '/i/show.gif" height="16" width="16" alt="' . get_string ( 'show' ) . '" /></a>' ;
if ( isadmin () or ( $course -> category and ( iscreator () or ( isteacheredit ( $course -> id ) and ! empty ( $CFG -> teacherassignteachers ))))) {
echo ' <a href="' . $CFG -> wwwroot . '/course/teacher.php?id=' . $course -> id . '">' ;
echo '<img src="' . $CFG -> pixpath . '/i/edit.gif" height="16" width="16" alt="' . get_string ( 'edit' ) . '" /></a>' ;
2004-05-30 18:46:42 +00:00
}
2005-06-03 23:20:01 +00:00
echo '</h2>' ;
2004-01-31 04:08:10 +00:00
}
2003-11-04 12:09:52 +00:00
2005-06-03 23:20:01 +00:00
$guest = get_guest ();
$exceptions [] = $guest -> id ;
2005-09-29 06:30:58 +00:00
$tablecolumns = array ( 'picture' , 'fullname' , 'city' , 'country' , 'lastaccess' );
$tableheaders = array ( '' , get_string ( 'fullname' ), get_string ( 'city' ), get_string ( 'country' ), get_string ( 'lastaccess' ));
if ( $course -> enrolperiod ) {
$tablecolumns [] = 'timeend' ;
$tableheaders [] = get_string ( 'enrolmentend' );
}
if ( $isteacher ) {
$tablecolumns [] = '' ;
$tableheaders [] = get_string ( 'select' );
}
2005-06-03 23:20:01 +00:00
2005-10-21 01:18:30 +00:00
$table = new flexible_table ( 'user-index-students-' . $course -> id );
2005-06-03 23:20:01 +00:00
$table -> define_columns ( $tablecolumns );
$table -> define_headers ( $tableheaders );
$table -> define_baseurl ( $baseurl );
2005-06-20 03:47:19 +00:00
$table -> sortable ( true , 'lastaccess' , SORT_DESC );
2005-06-03 23:20:01 +00:00
$table -> set_attribute ( 'cellspacing' , '0' );
$table -> set_attribute ( 'id' , 'students' );
$table -> set_attribute ( 'class' , 'generaltable generalbox' );
$table -> set_control_variables ( array (
TABLE_VAR_SORT => 'ssort' ,
TABLE_VAR_HIDE => 'shide' ,
TABLE_VAR_SHOW => 'sshow' ,
TABLE_VAR_IFIRST => 'sifirst' ,
TABLE_VAR_ILAST => 'silast' ,
TABLE_VAR_PAGE => 'spage'
));
$table -> setup ();
if ( SITEID == $course -> id ) {
$select = ' SELECT u . id , u . username , u . firstname , u . lastname , u . email , u . city , u . country ,
u . picture , u . lang , u . timezone , u . emailstop , u . maildisplay , u . lastaccess ' ;
$from = 'FROM ' . $CFG -> prefix . 'user u ' ;
$where = 'WHERE confirmed = 1 AND u.deleted = 0 ' ;
2004-09-04 13:51:19 +00:00
}
2005-06-03 23:20:01 +00:00
else {
$select = ' SELECT u . id , u . username , u . firstname , u . lastname , u . email , u . city , u . country ,
u . picture , u . lang , u . timezone , u . emailstop , u . maildisplay , s . timeaccess AS lastaccess ' ;
2005-09-29 06:30:58 +00:00
$select .= $course -> enrolperiod ? ', s.timeend ' : '' ;
2005-06-03 23:20:01 +00:00
$from = 'FROM ' . $CFG -> prefix . 'user u LEFT JOIN ' . $CFG -> prefix . 'user_students s ON s.userid = u.id ' ;
$where = 'WHERE s.course = ' . $course -> id . ' AND u.deleted = 0 ' ;
2003-05-16 06:27:23 +00:00
}
2005-11-17 02:46:27 +00:00
$where .= get_lastaccess_sql ( $accesssince );
2005-11-17 03:09:07 +00:00
if ( ! empty ( $search )) {
$LIKE = sql_ilike ();
$fullname = sql_fullname ( 'u.firstname' , 'u.lastname' );
$wheresearch .= ' AND (' . $fullname . ' ' . $LIKE . '\'%' . $search . '%\' OR email ' . $LIKE . '\'%' . $search . '%\' OR nickname ' . $LIKE . ' \'%' . $search . '%\' OR idnumber ' . $LIKE . ' \'%' . $search . '%\') ' ;
}
2005-06-03 23:20:01 +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"
$from .= 'LEFT JOIN ' . $CFG -> prefix . 'groups_members gm ON u.id = gm.userid ' ;
$where .= ' AND gm.groupid = ' . $currentgroup ;
}
2003-09-18 04:46:34 +00:00
2005-06-03 23:20:01 +00:00
if ( $course -> id == SITEID ) {
$where .= ' AND u.id NOT IN (' . implode ( ',' , $exceptions ) . ')' ;
}
2003-11-04 12:09:52 +00:00
2005-06-03 23:20:01 +00:00
$totalcount = count_records_sql ( 'SELECT COUNT(*) ' . $from . $where );
2003-11-04 12:09:52 +00:00
2005-06-03 23:20:01 +00:00
if ( $table -> get_sql_where ()) {
$where .= ' AND ' . $table -> get_sql_where ();
2003-11-04 12:09:52 +00:00
}
2005-06-03 23:20:01 +00:00
if ( $table -> get_sql_sort ()) {
$sort = ' ORDER BY ' . $table -> get_sql_sort ();
}
else {
$sort = '' ;
}
2003-11-04 12:09:52 +00:00
2005-11-17 03:09:07 +00:00
$matchcount = count_records_sql ( 'SELECT COUNT(*) ' . $from . $where . $wheresearch );
2005-03-22 16:04:10 +00:00
2005-06-03 23:20:01 +00:00
$table -> initialbars ( $totalcount > $perpage );
$table -> pagesize ( $perpage , $matchcount );
2004-09-01 13:56:12 +00:00
2005-06-03 23:20:01 +00:00
if ( $table -> get_page_start () !== '' && $table -> get_page_size () !== '' ) {
$limit = ' ' . sql_paging_limit ( $table -> get_page_start (), $table -> get_page_size ());
2004-09-01 13:56:12 +00:00
}
2005-06-03 23:20:01 +00:00
else {
$limit = '' ;
}
2005-11-17 03:09:07 +00:00
$students = get_records_sql ( $select . $from . $where . $wheresearch . $sort . $limit );
2002-11-12 03:02:51 +00:00
2005-06-03 23:20:01 +00:00
$a -> count = $totalcount ;
$a -> items = $totalcount == 1 ? $course -> student : $course -> students ;
echo '<h2>' . get_string ( 'counteditems' , '' , $a );
if ( isteacheredit ( $course -> id )) {
echo ' <a href="../course/student.php?id=' . $course -> id . '">' ;
echo '<img src="' . $CFG -> pixpath . '/i/edit.gif" height="16" width="16" alt="" /></a>' ;
}
echo '</h2>' ;
2005-03-22 16:04:10 +00:00
2005-06-03 23:20:01 +00:00
if ( $CFG -> longtimenosee > 0 && $CFG -> longtimenosee < 1000 && $totalcount > 0 ) {
echo '<p id="longtimenosee">(' . get_string ( 'unusedaccounts' , '' , $CFG -> longtimenosee ) . ')</p>' ;
}
2004-09-01 13:56:12 +00:00
2005-08-22 05:44:13 +00:00
if ( $isteacher ) {
2005-09-29 06:30:58 +00:00
echo '
< script Language = " JavaScript " >
<!--
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 ;
}
}
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 ;
}
}
return checked ;
}
//-->
</ script >
' ;
2005-11-08 02:34:19 +00:00
echo '<form action="action_redir.php" method="post" name="studentsform" onSubmit="return checksubmit(this);">' ;
2005-08-22 05:44:13 +00:00
echo '<input type="hidden" name="id" value="' . $id . '" />' ;
echo '<input type="hidden" name="returnto" value="' . $_SERVER [ 'REQUEST_URI' ] . '" />' ;
2005-09-29 06:30:58 +00:00
echo '<input type="hidden" name="sesskey" value="' . $USER -> sesskey . '" />' ;
2005-08-22 05:44:13 +00:00
}
2005-06-03 23:20:01 +00:00
if ( $fullmode ) { // Print simple listing
if ( $totalcount < 1 ) {
print_heading ( get_string ( " nostudentsfound " , " " , $course -> students ));
2005-04-27 18:30:02 +00:00
}
2005-06-03 23:20:01 +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>' ;
2002-09-22 14:06:38 +00:00
} else {
2005-06-03 23:20:01 +00:00
echo '<strong>' . $strall . '</strong>' ;
2002-09-22 14:06:38 +00:00
}
2005-06-03 23:20:01 +00:00
foreach ( $alpha as $letter ) {
if ( $letter == $firstinitial ) {
echo ' <strong>' . $letter . '</strong>' ;
} else {
echo ' <a href="' . $baseurl . '&sifirst=' . $letter . '">' . $letter . '</a>' ;
}
}
echo '</div>' ;
// Bar of last initials
echo '<div class="initialbar lastinitial">' . get_string ( 'lastname' ) . ' : ' ;
if ( ! empty ( $lastinitial )) {
echo '<a href="' . $baseurl . '&silast=">' . $strall . '</a>' ;
2002-09-22 14:06:38 +00:00
} else {
2005-06-03 23:20:01 +00:00
echo '<strong>' . $strall . '</strong>' ;
}
foreach ( $alpha as $letter ) {
if ( $letter == $lastinitial ) {
echo ' <strong>' . $letter . '</strong>' ;
} else {
echo ' <a href="' . $baseurl . '&silast=' . $letter . '">' . $letter . '</a>' ;
}
2002-09-22 14:06:38 +00:00
}
2005-06-03 23:20:01 +00:00
echo '</div>' ;
print_paging_bar ( $matchcount , intval ( $table -> get_page_start () / $perpage ), $perpage , $baseurl . '&' , 'spage' );
2002-09-21 06:27:00 +00:00
}
2002-09-22 14:06:38 +00:00
2005-06-03 23:20:01 +00:00
if ( $matchcount > 0 ) {
foreach ( $students as $student ) {
2005-08-22 05:44:13 +00:00
print_user ( $student , $course , true );
2005-06-03 23:20:01 +00:00
}
2002-09-22 16:16:13 +00:00
}
2005-06-03 23:20:01 +00:00
else {
print_heading ( get_string ( 'nothingtodisplay' ));
2002-09-22 16:16:13 +00:00
}
2003-09-18 04:46:34 +00:00
}
2005-06-03 23:20:01 +00:00
}
else {
$countrysort = ( strpos ( $sort , 'country' ) !== false );
2005-09-29 06:30:58 +00:00
$timeformat = get_string ( 'strftimedate' );
2005-06-03 23:20:01 +00:00
if ( ! empty ( $students )) {
foreach ( $students as $student ) {
if ( $student -> lastaccess ) {
$lastaccess = format_time ( time () - $student -> lastaccess , $datestring );
} else {
$lastaccess = $strnever ;
}
if ( empty ( $student -> country )) {
$country = '' ;
}
else {
if ( $countrysort ) {
$country = '(' . $student -> country . ') ' . $countries [ $student -> country ];
}
else {
$country = $countries [ $student -> country ];
}
}
2002-09-22 16:16:13 +00:00
2005-09-29 06:30:58 +00:00
$data = array (
2005-06-03 23:20:01 +00:00
//'<input type="checkbox" name="userid[]" value="'.$teacher->id.'" />',
print_user_picture ( $student -> id , $course -> id , $student -> picture , false , true ),
'<strong><a href="' . $CFG -> wwwroot . '/user/view.php?id=' . $student -> id . '&course=' . $course -> id . '">' . fullname ( $student ) . '</a></strong>' ,
$student -> city ,
$country ,
2005-09-29 06:30:58 +00:00
$lastaccess );
if ( $course -> enrolperiod ) {
$data [] = userdate ( $student -> timeend , $timeformat );
}
if ( $isteacher ) {
$data [] = '<input type="checkbox" name="user' . $student -> id . '" />' ;
}
$table -> add_data ( $data );
2005-08-22 05:44:13 +00:00
2003-09-18 04:46:34 +00:00
}
2005-06-03 23:20:01 +00:00
}
2003-04-28 04:32:55 +00:00
2005-06-03 23:20:01 +00:00
$table -> print_html ();
2002-09-21 05:42:16 +00:00
2005-06-03 23:20:01 +00:00
}
2003-11-28 16:16:59 +00:00
2005-08-22 05:44:13 +00:00
if ( $isteacher ) {
2005-09-29 06:30:58 +00:00
echo '<br /><center>' ;
2005-10-05 22:22:03 +00:00
echo '<input type="button" onclick="checkall()" value="' . get_string ( 'selectall' ) . '" /> ' ;
echo '<input type="button" onclick="checknone()" value="' . get_string ( 'deselectall' ) . '" /> ' ;
2005-09-29 06:30:58 +00:00
$displaylist [ 'messageselect.php' ] = get_string ( 'messageselectadd' );
if ( $course -> enrolperiod ) {
$displaylist [ 'extendenrol.php' ] = get_string ( 'extendenrol' );
}
2005-10-05 21:44:03 +00:00
choose_from_menu ( $displaylist , " formaction " , " " , get_string ( " withselectedusers " ), " if(checksubmit(this.form))this.form.submit(); " , " " );
2005-09-29 06:30:58 +00:00
echo '<input type="submit" value="' . get_string ( 'ok' ) . '"' ;
2005-08-22 05:44:13 +00:00
echo '</center></form>' ;
}
2005-11-17 03:09:07 +00:00
if ( $isteacher && $totalcount > ( $perpage * 3 )) {
echo '<form action="index.php"><p align="center"><input type="hidden" name="id" value="' . $course -> id . '" />' . get_string ( 'search' ) . ': ' . " \n " ;
echo '<input type="text" name="search" value="' . $search . '" /> <input type="submit" value="' . get_string ( 'search' ) . '" /></p></form>' . " \n " ;
}
2005-06-03 23:20:01 +00:00
if ( $perpage == 99999 ) {
echo '<div id="showall"><a href="' . $baseurl . '&perpage=' . DEFAULT_PAGE_SIZE . '">' . get_string ( 'showperpage' , '' , DEFAULT_PAGE_SIZE ) . '</a></div>' ;
}
else if ( $matchcount > 0 && $perpage < $matchcount ) {
echo '<div id="showall"><a href="' . $baseurl . '&perpage=99999">' . get_string ( 'showall' , '' , $matchcount ) . '</a></div>' ;
}
print_footer ( $course );
2001-11-22 06:23:56 +00:00
2005-11-17 02:46:27 +00:00
function get_lastaccess_sql ( $accesssince = '' ) {
if ( empty ( $accesssince )) {
return '' ;
}
if ( $accesssince == - 1 ) { // never
return ' AND timeaccess = 0' ;
} else {
return ' AND timeaccess != 0 AND timeaccess < ' . $accesssince ;
}
}
2001-11-22 06:23:56 +00:00
?>