2006-04-20 22:36:22 +00:00
< ? php // $Id$
2006-03-09 08:24:10 +00:00
require_once ( '../../../config.php' );
2006-09-26 01:23:57 +00:00
require_once ( $CFG -> libdir . '/statslib.php' );
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
define ( 'DEFAULT_PAGE_SIZE' , 20 );
2006-09-15 14:32:35 +00:00
define ( 'SHOW_ALL_PAGE_SIZE' , 5000 );
2007-08-17 19:09:11 +00:00
2006-04-20 22:36:22 +00:00
$id = required_param ( 'id' , PARAM_INT ); // course id.
$moduleid = optional_param ( 'moduleid' , 0 , PARAM_INT ); // module id.
$oldmod = optional_param ( 'oldmod' , 0 , PARAM_INT );
2006-09-26 01:23:57 +00:00
$roleid = optional_param ( 'roleid' , 0 , PARAM_INT ); // which role to show
2006-04-20 22:36:22 +00:00
$instanceid = optional_param ( 'instanceid' , 0 , PARAM_INT ); // instance we're looking at.
$timefrom = optional_param ( 'timefrom' , 0 , PARAM_INT ); // how far back to look...
$action = optional_param ( 'action' , '' , PARAM_ALPHA );
2006-03-09 08:24:10 +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-08-17 19:09:11 +00:00
if ( $action != 'view' && $action != 'post' ) {
2006-03-09 08:24:10 +00:00
$action = '' ; // default to all (don't restrict)
}
// reset instance if changing module.
if ( ! empty ( $moduleid ) && ! empty ( $oldmod ) && $moduleid != $oldmod ) {
$instanceid = 0 ;
}
if ( ! $course = get_record ( 'course' , 'id' , $id )) {
print_error ( 'invalidcourse' );
}
2006-09-26 01:23:57 +00:00
if ( $roleid != 0 && ! $role = get_record ( 'role' , 'id' , $roleid )) {
print_error ( 'invalidrole' );
}
2006-03-09 08:24:10 +00:00
require_login ( $course -> id );
2006-08-25 08:30:25 +00:00
$context = get_context_instance ( CONTEXT_COURSE , $course -> id );
2007-08-17 19:09:11 +00:00
2006-08-25 08:30:25 +00:00
if ( ! has_capability ( 'moodle/site:viewreports' , $context )) {
2006-04-13 05:42:47 +00:00
print_error ( 'mustbeteacher' , '' , $CFG -> wwwroot . '/course/view.php?id=' . $course -> id );
2006-03-09 08:24:10 +00:00
}
2006-04-20 22:36:22 +00:00
2007-08-17 19:09:11 +00:00
add_to_log ( $course -> id , " course " , " report participation " , " report/participation/index.php?id= $course->id " , $course -> id );
2006-03-09 08:24:10 +00:00
$strparticipation = get_string ( 'participationreport' );
$strviews = get_string ( 'views' );
$strposts = get_string ( 'posts' );
$strview = get_string ( 'view' );
$strpost = get_string ( 'post' );
$strallactions = get_string ( 'allactions' );
$strreports = get_string ( 'reports' );
2007-08-17 19:09:11 +00:00
$navlinks = array ();
$navlinks [] = array ( 'name' => $strreports , 'link' => " ../../report.php?id= $course->id " , 'type' => 'misc' );
$navlinks [] = array ( 'name' => $strparticipation , 'link' => null , 'type' => 'misc' );
$navigation = build_navigation ( $navlinks );
print_header ( " $course->shortname : $strparticipation " , $course -> fullname , $navigation );
2006-03-09 08:24:10 +00:00
$allowedmodules = array ( 'assignment' , 'book' , 'chat' , 'choice' , 'exercise' , 'forum' , 'glossary' , 'hotpot' ,
'journal' , 'lesson' , 'questionnaire' , 'quiz' , 'resource' , 'scorm' ,
'survey' , 'wiki' , 'workshop' ); // some don't make sense here - eg 'label'
if ( ! $modules = get_records_sql ( 'SELECT DISTINCT module,name FROM ' . $CFG -> prefix . 'course_modules cm JOIN ' .
$CFG -> prefix . 'modules m ON cm.module = m.id WHERE course = ' . $course -> id )) {
2006-04-13 05:42:47 +00:00
print_error ( 'noparticipatorycms' , '' , $CFG -> wwwroot . '/course/view.php?id=' . $course -> id );
2006-03-09 08:24:10 +00:00
}
$modoptions = array ();
foreach ( $modules as $m ) {
if ( in_array ( $m -> name , $allowedmodules )) {
$modoptions [ $m -> module ] = get_string ( 'modulename' , $m -> name );
}
}
$timeoptions = array ();
// get minimum log time for this course
$minlog = get_field_sql ( 'SELECT min(time) FROM ' . $CFG -> prefix . 'log WHERE course = ' . $course -> id );
$now = usergetmidnight ( time ());
// days
for ( $i = 1 ; $i < 7 ; $i ++ ) {
if ( strtotime ( '-' . $i . ' days' , $now ) >= $minlog ) {
$timeoptions [ strtotime ( '-' . $i . ' days' , $now )] = get_string ( 'numdays' , 'moodle' , $i );
}
}
// weeks
for ( $i = 1 ; $i < 10 ; $i ++ ) {
if ( strtotime ( '-' . $i . ' weeks' , $now ) >= $minlog ) {
$timeoptions [ strtotime ( '-' . $i . ' weeks' , $now )] = get_string ( 'numweeks' , 'moodle' , $i );
}
}
2007-08-17 19:09:11 +00:00
// months
2006-03-09 08:24:10 +00:00
for ( $i = 2 ; $i < 12 ; $i ++ ) {
if ( strtotime ( '-' . $i . ' months' , $now ) >= $minlog ) {
$timeoptions [ strtotime ( '-' . $i . ' months' , $now )] = get_string ( 'nummonths' , 'moodle' , $i );
}
}
// try a year
if ( strtotime ( '-1 year' , $now ) >= $minlog ) {
$timeoptions [ strtotime ( '-1 year' , $now )] = get_string ( 'lastyear' );
}
2006-09-26 01:23:57 +00:00
$useroptions = array ();
if ( $roles = get_roles_on_exact_context ( get_context_instance ( CONTEXT_COURSE , $course -> id ))) {
foreach ( $roles as $r ) {
$useroptions [ $r -> id ] = $r -> name ;
}
}
2007-01-15 21:28:25 +00:00
$guestrole = get_guest_role ();
2007-02-27 05:09:15 +00:00
if ( empty ( $useroptions [ $guestrole -> id ])) {
2007-01-15 21:28:25 +00:00
$useroptions [ $guestrole -> id ] = $guestrole -> name ;
}
2006-03-09 08:24:10 +00:00
$actionoptions = array ( '' => $strallactions ,
'view' => $strview ,
'post' => $strpost ,
);
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
// print first controls.
2007-01-15 21:28:25 +00:00
echo '<form class="participationselectform" action="index.php" method="get"><div>' . " \n " .
'<input type="hidden" name="id" value="' . $course -> id . '" />' . " \n " .
'<input type="hidden" name="oldmod" value="' . $moduleid . '" />' . " \n " .
2007-03-20 00:27:38 +00:00
'<input type="hidden" name="instanceid" value="' . $instanceid . '" />' . " \n " ;
echo '<label for="menumoduleid">' . get_string ( 'activitymodule' ) . '</label>' . " \n " ;
2006-03-09 08:24:10 +00:00
choose_from_menu ( $modoptions , 'moduleid' , $moduleid );
2007-03-20 00:27:38 +00:00
echo '<label for="menutimefrom">' . get_string ( 'lookback' ) . '</label>' . " \n " ;
2006-03-09 08:24:10 +00:00
choose_from_menu ( $timeoptions , 'timefrom' , $timefrom );
2007-03-20 00:27:38 +00:00
echo '<label for="menuroleid">' . get_string ( 'showonly' ) . '</label>' . " \n " ;
2006-09-26 01:23:57 +00:00
choose_from_menu ( $useroptions , 'roleid' , $roleid , '' );
2007-03-20 00:27:38 +00:00
echo '<label for="menuaction">' . get_string ( 'showactions' ) . '</label>' . " \n " ;
2006-03-09 08:24:10 +00:00
choose_from_menu ( $actionoptions , 'action' , $action , '' );
helpbutton ( 'participationreport' , get_string ( 'participationreport' ));
2007-01-15 21:28:25 +00:00
echo '<input type="submit" value="' . get_string ( 'go' ) . '" />' . " \n </div></form> \n " ;
2006-03-09 08:24:10 +00:00
if ( empty ( $moduleid )) {
notify ( get_string ( 'selectamodule' ));
print_footer ();
exit ;
}
2007-08-17 19:09:11 +00:00
2006-09-26 01:23:57 +00:00
$baseurl = $CFG -> wwwroot . '/course/report/participation/index.php?id=' . $course -> id . '&roleid='
. $roleid . '&instanceid=' . $instanceid . '&timefrom=' . $timefrom . '&moduleid='
2006-12-20 02:38:10 +00:00
. $moduleid . '&action=' . $action . '&perpage=' . $perpage ;
2006-03-09 08:24:10 +00:00
// from here assume we have at least the module we're using.
$module = get_record ( 'modules' , 'id' , $moduleid );
$modulename = get_string ( 'modulename' , $module -> name );
2008-01-24 02:20:25 +00:00
include_once ( $CFG -> dirroot . '/mod/' . $module -> name . '/lib.php' );
2006-03-09 08:24:10 +00:00
$viewfun = $module -> name . '_get_view_actions' ;
$postfun = $module -> name . '_get_post_actions' ;
if ( ! function_exists ( $viewfun ) || ! function_exists ( $postfun )) {
2006-10-16 09:06:35 +00:00
error ( get_string ( 'modulemissingcode' , 'error' , $module -> name ), $baseurl );
2006-03-09 08:24:10 +00:00
}
$viewnames = $viewfun ();
$postnames = $postfun ();
// get all instances of this module in the course.
if ( ! $instances = get_all_instances_in_course ( $module -> name , $course )) {
error ( get_string ( 'noinstances' , 'error' , $modulename ));
}
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
$instanceoptions = array ();
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
foreach ( $instances as $instance ) {
$instanceoptions [ $instance -> id ] = $instance -> name ;
}
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
if ( count ( $instanceoptions ) == 1 ) { // just display it if there's only one.
$instanceid = array_pop ( array_keys ( $instanceoptions ));
}
2007-03-20 00:27:38 +00:00
echo '<form action="' . $CFG -> wwwroot . '/course/report/participation/index.php" method="post">' . " \n " .
'<div id="participationreportselector">' . " \n " .
2006-03-09 08:24:10 +00:00
'<input type="hidden" name="id" value="' . $course -> id . '" />' . " \n " .
'<input type="hidden" name="oldmod" value="' . $moduleid . '" />' . " \n " .
'<input type="hidden" name="timefrom" value="' . $timefrom . '" />' . " \n " .
'<input type="hidden" name="action" value="' . $action . '" />' . " \n " .
2006-09-26 01:23:57 +00:00
'<input type="hidden" name="roleid" value="' . $roleid . '" />' . " \n " .
2007-03-20 00:27:38 +00:00
'<input type="hidden" name="moduleid" value="' . $moduleid . '" />' . " \n " ;
2006-03-09 08:24:10 +00:00
choose_from_menu ( $instanceoptions , 'instanceid' , $instanceid );
2007-03-20 00:27:38 +00:00
echo '<input type="submit" value="' . get_string ( 'go' ) . '" />' . " \n " .
'</div>' . " \n " .
2006-03-09 08:24:10 +00:00
" </form> \n " ;
2007-08-17 19:09:11 +00:00
2006-09-26 01:23:57 +00:00
if ( ! empty ( $instanceid ) && ! empty ( $roleid )) {
2006-03-09 08:24:10 +00:00
if ( ! $cm = get_coursemodule_from_instance ( $module -> name , $instanceid , $course -> id )) {
print_error ( 'cmunknown' );
}
require_once ( $CFG -> dirroot . '/lib/tablelib.php' );
2006-09-26 01:23:57 +00:00
$table = new flexible_table ( 'course-participation-' . $course -> id . '-' . $cm -> id . '-' . $roleid );
2006-03-09 08:24:10 +00:00
$table -> course = $course ;
$table -> define_columns ( array ( 'fullname' , 'count' , '' ));
$table -> define_headers ( array ( get_string ( 'user' ),(( ! empty ( $action )) ? get_string ( $action ) : get_string ( 'allactions' )), get_string ( 'select' )));
$table -> define_baseurl ( $baseurl );
$table -> set_attribute ( 'cellpadding' , '5' );
2007-03-20 00:27:38 +00:00
$table -> set_attribute ( 'class' , 'generaltable generalbox reporttable' );
2006-03-09 08:24:10 +00:00
$table -> sortable ( true , 'lastname' , 'ASC' );
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
$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 ();
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
2006-09-26 04:33:59 +00:00
$primary_roles = sql_primary_role_subselect (); // In dmllib.php
2006-09-26 01:23:57 +00:00
$sql = 'SELECT DISTINCT prs.userid, u.firstname,u.lastname,u.idnumber,count(l.action) as count FROM (' . $primary_roles . ') prs'
. ' JOIN ' . $CFG -> prefix . 'user u ON u.id = prs.userid LEFT JOIN ' . $CFG -> prefix . 'log l ON prs.userid = l.userid '
. ' AND prs.courseid = l.course AND l.time > ' . $timefrom . ' AND l.course = ' . $course -> id . ' AND l.module = \'' . $module -> name . '\' '
2006-03-09 08:24:10 +00:00
. ' AND l.cmid = ' . $cm -> id ;
switch ( $action ) {
case 'view' :
$sql .= ' AND action IN (\'' . implode ( '\',\'' , $viewnames ) . '\' )' ;
break ;
case 'post' :
$sql .= ' AND action IN (\'' . implode ( '\',\'' , $postnames ) . '\' )' ;
break ;
default :
// some modules have stuff we want to hide, ie mail blocked etc so do actually need to limit here.
2007-08-17 19:09:11 +00:00
$sql .= ' AND action IN (\'' . implode ( '\',\'' , array_merge ( $viewnames , $postnames )) . '\' )' ;
2006-03-09 08:24:10 +00:00
}
2007-08-17 19:09:11 +00:00
2006-09-26 01:23:57 +00:00
$sql .= ' WHERE prs.courseid = ' . $course -> id . ' AND prs.primary_roleid = ' . $roleid . ' AND prs.contextlevel = ' . CONTEXT_COURSE . ' AND prs.courseid = ' . $course -> id ;
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
if ( $table -> get_sql_where ()) {
2007-08-17 19:09:11 +00:00
$sql .= ' AND ' . $table -> get_sql_where (); //initial bar
2006-03-09 08:24:10 +00:00
}
2006-09-26 01:23:57 +00:00
$sql .= ' GROUP BY prs.userid,u.firstname,u.lastname,u.idnumber,l.userid' ;
2006-03-09 08:24:10 +00:00
if ( $table -> get_sql_sort ()) {
$sql .= ' ORDER BY ' . $table -> get_sql_sort ();
}
2006-09-26 01:23:57 +00:00
$countsql = 'SELECT COUNT(DISTINCT(prs.userid)) FROM (' . $primary_roles . ') prs '
2007-08-17 19:09:11 +00:00
. ' JOIN ' . $CFG -> prefix . 'user u ON u.id = prs.userid WHERE prs.courseid = ' . $course -> id
2006-09-26 01:23:57 +00:00
. ' AND prs.primary_roleid = ' . $roleid . ' AND prs.contextlevel = ' . CONTEXT_COURSE ;
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
$totalcount = count_records_sql ( $countsql );
if ( $table -> get_sql_where ()) {
$matchcount = count_records_sql ( $countsql . ' AND ' . $table -> get_sql_where ());
} else {
$matchcount = $totalcount ;
}
2007-08-17 19:09:11 +00:00
2007-03-20 00:27:38 +00:00
echo '<div id="participationreport">' . " \n " ;
echo '<p class="modulename">' . $modulename . ' ' . $strviews . ': ' . implode ( ', ' , $viewnames ) . '<br />' . " \n "
. $modulename . ' ' . $strposts . ': ' . implode ( ', ' , $postnames ) . '</p>' . " \n " ;
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
$table -> initialbars ( $totalcount > $perpage );
$table -> pagesize ( $perpage , $matchcount );
2006-10-23 23:00:18 +00:00
if ( ! $users = get_records_sql ( $sql , $table -> get_page_start (), $table -> get_page_size ())) {
2006-03-09 08:24:10 +00:00
$users = array (); // tablelib will handle saying 'Nothing to display' for us.
}
$data = array ();
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
$a -> count = $totalcount ;
2006-09-26 01:23:57 +00:00
$a -> items = $role -> name ;
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
if ( $matchcount != $totalcount ) {
$a -> items .= ' (' . get_string ( 'matched' ) . ' ' . $matchcount . ')' ;
}
2007-08-17 19:09:11 +00:00
2007-03-20 00:27:38 +00:00
echo '<h2>' . get_string ( 'counteditems' , '' , $a ) . '</h2>' . " \n " ;
2006-03-09 08:24:10 +00:00
echo '
2006-11-28 10:23:26 +00:00
< script type = " text/javascript " >
2006-12-22 04:25:00 +00:00
//<![CDATA[
2006-03-09 08:24:10 +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 ;
}
}
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 ;
}
function checknos () {
void ( d = document );
void ( el = d . getElementsByTagName ( \ ' INPUT\ ' ));
for ( i = 0 ; i < el . length ; i ++ ) {
if ( el [ i ] . value == 0 ) {
void ( el [ i ] . checked = 1 )
}
}
}
2006-12-22 04:25:00 +00:00
//]]>
2006-03-09 08:24:10 +00:00
</ script >
' ;
2007-03-20 00:27:38 +00:00
echo '<form action="' . $CFG -> wwwroot . '/user/action_redir.php" method="post" id="studentsform" onsubmit="return checksubmit(this);">' . " \n " ;
echo '<div>' . " \n " ;
echo '<input type="hidden" name="id" value="' . $id . '" />' . " \n " ;
echo '<input type="hidden" name="returnto" value="' . format_string ( $_SERVER [ 'REQUEST_URI' ]) . '" />' . " \n " ;
echo '<input type="hidden" name="sesskey" value="' . $USER -> sesskey . '" />' . " \n " ;
2006-03-09 08:24:10 +00:00
foreach ( $users as $u ) {
2007-03-20 00:27:38 +00:00
$data = array ( '<a href="' . $CFG -> wwwroot . '/user/view.php?id=' . $u -> userid . '&course=' . $course -> id . '">' . fullname ( $u , true ) . '</a>' . " \n " ,
2006-03-09 08:24:10 +00:00
(( ! empty ( $u -> count )) ? get_string ( 'yes' ) . ' (' . $u -> count . ') ' : get_string ( 'no' )),
2007-03-20 00:27:38 +00:00
'<input type="checkbox" name="user' . $u -> userid . '" value="' . $u -> count . '" />' . " \n " ,
2006-03-09 08:24:10 +00:00
);
$table -> add_data ( $data );
}
$table -> print_html ();
2006-09-15 14:32:35 +00:00
if ( $perpage == SHOW_ALL_PAGE_SIZE ) {
2007-03-20 00:27:38 +00:00
echo '<div id="showall"><a href="' . $baseurl . '&perpage=' . DEFAULT_PAGE_SIZE . '">' . get_string ( 'showperpage' , '' , DEFAULT_PAGE_SIZE ) . '</a></div>' . " \n " ;
2006-03-09 08:24:10 +00:00
}
else if ( $matchcount > 0 && $perpage < $matchcount ) {
2007-03-20 00:27:38 +00:00
echo '<div id="showall"><a href="' . $baseurl . '&perpage=' . SHOW_ALL_PAGE_SIZE . '">' . get_string ( 'showall' , '' , $matchcount ) . '</a></div>' . " \n " ;
2006-03-09 08:24:10 +00:00
}
2007-08-17 19:09:11 +00:00
2007-03-20 00:27:38 +00:00
echo '<input type="button" onclick="checkall()" value="' . get_string ( 'selectall' ) . '" /> ' . " \n " ;
echo '<input type="button" onclick="checknone()" value="' . get_string ( 'deselectall' ) . '" /> ' . " \n " ;
2006-03-09 08:24:10 +00:00
if ( $perpage >= $matchcount ) {
2007-03-20 00:27:38 +00:00
echo '<input type="button" onclick="checknos()" value="' . get_string ( 'selectnos' ) . '" />' . " \n " ;
2006-03-09 08:24:10 +00:00
}
$displaylist [ 'messageselect.php' ] = get_string ( 'messageselectadd' );
choose_from_menu ( $displaylist , " formaction " , " " , get_string ( " withselectedusers " ), " if(checksubmit(this.form))this.form.submit(); " , " " );
helpbutton ( " participantswithselectedusers " , get_string ( " withselectedusers " ));
2007-03-20 00:27:38 +00:00
echo '<input type="submit" value="' . get_string ( 'ok' ) . '" />' . " \n " ;
echo '</div>' . " \n " ;
echo '</form>' . " \n " ;
echo '</div>' . " \n " ;
2006-03-09 08:24:10 +00:00
}
2007-08-17 19:09:11 +00:00
2006-03-09 08:24:10 +00:00
print_footer ();
2006-12-22 04:25:00 +00:00
?>