2005-06-04 09:58:35 +00:00
< ? php // $Id$
// This script lists student attempts
require_once ( $CFG -> libdir . '/tablelib.php' );
class quiz_report extends quiz_default_report {
function display ( $quiz , $cm , $course ) { /// This function just displays the report
global $CFG , $SESSION , $db , $QUIZ_QTYPES ;
/// Define some strings
$strreallydel = addslashes ( get_string ( 'deleteattemptcheck' , 'quiz' ));
$strnoattempts = get_string ( 'noattempts' , 'quiz' );
$strtimeformat = get_string ( 'strftimedatetime' );
$strreviewquestion = get_string ( 'reviewresponse' , 'quiz' );
2005-07-22 09:43:23 +00:00
/// Only print headers if not asked to download data
if ( ! $download = optional_param ( 'download' , NULL )) {
$this -> print_header_and_tabs ( $cm , $course , $quiz , $reportmode = " overview " );
}
2005-06-04 09:58:35 +00:00
/// Deal with actions
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
$action = optional_param ( 'action' , '' );
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
switch ( $action ) {
case 'delete' : /// Some attempts need to be deleted
// the following needs to be improved to delete all associated data as well
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
$attemptids = isset ( $_POST [ 'attemptid' ]) ? $_POST [ 'attemptid' ] : array ();
if ( ! is_array ( $attemptids ) || empty ( $attemptids )) {
break ;
}
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
foreach ( $attemptids as $num => $attemptid ) {
if ( empty ( $attemptid )) {
unset ( $attemptids [ $num ]);
}
}
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
foreach ( $attemptids as $attemptid ) {
if ( $todelete = get_record ( 'quiz_attempts' , 'id' , $attemptid )) {
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
delete_records ( 'quiz_attempts' , 'id' , $attemptid );
2005-07-02 18:14:51 +00:00
delete_records ( 'quiz_states' , 'attempt' , $todelete -> uniqueid );
delete_records ( 'quiz_newest_states' , 'attemptid' , $todelete -> uniqueid );
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
// Search quiz_attempts for other instances by this user.
// If none, then delete record for this quiz, this user from quiz_grades
// else recalculate best grade
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
$userid = $todelete -> userid ;
if ( ! record_exists ( 'quiz_attempts' , 'userid' , $userid , 'quiz' , $quiz -> id )) {
delete_records ( 'quiz_grades' , 'userid' , $userid , 'quiz' , $quiz -> id );
} else {
quiz_save_best_grade ( $quiz , $userid );
}
}
}
break ;
}
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
/// Check to see if groups are being used in this quiz
if ( $groupmode = groupmode ( $course , $cm )) { // Groups are being used
2005-07-22 09:43:23 +00:00
if ( ! $download ) {
$currentgroup = setup_and_print_groups ( $course , $groupmode , " report.php?id= $cm->id &mode=overview " );
} else {
if ( isset ( $_GET [ 'group' ])) {
$changegroup = $_GET [ 'group' ]; /// 0 or higher
} else {
$changegroup = - 1 ; /// This means no group change was specified
}
2005-09-17 13:09:43 +00:00
$currentgroup = get_and_set_current_group ( $course , $groupmode , $changegroup );
2005-07-22 09:43:23 +00:00
}
2005-06-04 09:58:35 +00:00
} else {
$currentgroup = false ;
}
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
/// Set table options
if ( ! isset ( $SESSION -> quiz_overview_table )) {
2005-07-22 09:43:23 +00:00
$SESSION -> quiz_overview_table = array ( 'noattempts' => false , 'detailedmarks' => false , 'pagesize' => 10 );
2005-06-04 09:58:35 +00:00
}
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
foreach ( $SESSION -> quiz_overview_table as $option => $value ) {
$urlparam = optional_param ( $option , NULL );
if ( $urlparam === NULL ) {
$$option = $value ;
}
else {
$$option = $SESSION -> quiz_overview_table [ $option ] = $urlparam ;
}
}
2005-07-22 09:43:23 +00:00
/// Now check if asked download of data
if ( $download ) {
$filename = clean_filename ( " $course->shortname " . format_string ( $quiz -> name , true ));
$sort = '' ;
$limit = '' ;
}
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
/// Define table columns
$tablecolumns = array ( 'checkbox' , 'picture' , 'fullname' , 'timestart' , 'duration' );
$tableheaders = array ( NULL , '' , get_string ( 'fullname' ), get_string ( 'startedon' , 'quiz' ), get_string ( 'attemptduration' , 'quiz' ));
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
if ( $quiz -> grade ) {
$tablecolumns [] = 'sumgrades' ;
$tableheaders [] = get_string ( 'grade' , 'quiz' ) . '/' . $quiz -> grade ;
}
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
if ( $detailedmarks ) {
// we want to display marks for all questions
// Start by getting all questions
$questionlist = quiz_questions_in_quiz ( $quiz -> questions );
$questionids = explode ( ',' , $questionlist );
$sql = " SELECT q.*, i.grade AS maxgrade, i.id AS instance " .
" FROM { $CFG -> prefix } quiz_questions q, " .
" { $CFG -> prefix } quiz_question_instances i " .
" WHERE i.quiz = ' $quiz->id ' AND q.id = i.question " .
" AND q.id IN ( $questionlist ) " ;
if ( ! $questions = get_records_sql ( $sql )) {
error ( 'No questions found' );
}
$number = 1 ;
foreach ( $questionids as $key => $id ) {
if ( $questions [ $id ] -> length ) {
// Only print questions of non-zero length
$tablecolumns [] = '$' . $id ;
$tableheaders [] = '#' . $number ;
$questions [ $id ] -> number = $number ;
$number += $questions [ $id ] -> length ;
} else {
// get rid of zero length questions
unset ( $questions [ $id ]);
unset ( $questionids [ $key ]);
}
}
}
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
if ( ! $download ) {
// Set up the table
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
$table = new flexible_table ( 'mod-quiz-report-overview-report' );
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
$table -> define_columns ( $tablecolumns );
$table -> define_headers ( $tableheaders );
$table -> define_baseurl ( $CFG -> wwwroot . '/mod/quiz/report.php?mode=overview&id=' . $cm -> id );
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
$table -> sortable ( true );
$table -> collapsible ( true );
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
$table -> column_suppress ( 'picture' );
$table -> column_suppress ( 'fullname' );
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
$table -> column_class ( 'picture' , 'picture' );
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
$table -> set_attribute ( 'cellspacing' , '0' );
$table -> set_attribute ( 'id' , 'attempts' );
$table -> set_attribute ( 'class' , 'generaltable generalbox' );
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
// Start working -- this is necessary as soon as the niceties are over
$table -> setup ();
} elseif ( $download == 'Excel' ) {
require_once ( " $CFG->libdir /excel/Worksheet.php " );
require_once ( " $CFG->libdir /excel/Workbook.php " );
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
$filename .= " .xls " ;
2005-09-17 13:09:43 +00:00
header ( " Content-Type: application/vnd.ms-excel " );
2005-07-22 09:43:23 +00:00
header ( " Content-Disposition: attachment; filename= \" $filename\ " " );
header ( " Expires: 0 " );
header ( " Cache-Control: must-revalidate,post-check=0,pre-check=0 " );
header ( " Pragma: public " );
header ( " Content-Transfer-Encoding: binary " );
$workbook = new Workbook ( " - " );
// Creating the first worksheet
$sheettitle = get_string ( 'reportresponses' , 'quiz_responses' );
$myxls =& $workbook -> add_worksheet ( $sheettitle );
/// format types
$format =& $workbook -> add_format ();
$format -> set_bold ( 0 );
$formatbc =& $workbook -> add_format ();
$formatbc -> set_bold ( 1 );
$formatbc -> set_align ( 'center' );
$formatb =& $workbook -> add_format ();
$formatb -> set_bold ( 1 );
$formaty =& $workbook -> add_format ();
$formaty -> set_bg_color ( 'yellow' );
$formatc =& $workbook -> add_format ();
$formatc -> set_align ( 'center' );
$formatr =& $workbook -> add_format ();
$formatr -> set_bold ( 1 );
$formatr -> set_color ( 'red' );
$formatr -> set_align ( 'center' );
$formatg =& $workbook -> add_format ();
$formatg -> set_bold ( 1 );
$formatg -> set_color ( 'green' );
$formatg -> set_align ( 'center' );
// Here starts workshhet headers
2005-09-17 13:09:43 +00:00
$headers = array ( get_string ( 'fullname' ), get_string ( 'startedon' , 'quiz' ), get_string ( 'attemptduration' , 'quiz' ));
2005-07-22 09:43:23 +00:00
if ( $quiz -> grade ) {
$headers [] = get_string ( 'grade' , 'quiz' ) . '/' . $quiz -> grade ;
}
if ( $detailedmarks ) {
2005-10-28 03:54:33 +00:00
foreach ( $questionids as $key => $id ) {
$headers [] = '#' . $questions [ $id ] -> number ;
2005-07-22 09:43:23 +00:00
}
}
$colnum = 0 ;
foreach ( $headers as $item ) {
$myxls -> write ( 0 , $colnum , $item , $formatbc );
$colnum ++ ;
}
$rownum = 1 ;
} elseif ( $download == 'CSV' ) {
$filename .= " .txt " ;
2005-09-17 13:09:43 +00:00
header ( " Content-Type: application/download \n " );
2005-07-22 09:43:23 +00:00
header ( " Content-Disposition: attachment; filename= \" $filename\ " " );
header ( " Expires: 0 " );
header ( " Cache-Control: must-revalidate,post-check=0,pre-check=0 " );
header ( " Pragma: public " );
2005-09-17 13:09:43 +00:00
$headers = get_string ( 'fullname' ) . " \t " . get_string ( 'startedon' , 'quiz' ) . " \t " . get_string ( 'attemptduration' , 'quiz' );
2005-07-22 09:43:23 +00:00
if ( $quiz -> grade ) {
$headers .= " \t " . get_string ( 'grade' , 'quiz' ) . " / " . $quiz -> grade ;
}
if ( $detailedmarks ) {
foreach ( $questions as $question ) {
$headers .= " \t # " . $question -> number ;
}
}
echo $headers . " \n " ;
}
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
// Construct the SQL
2005-11-18 21:03:05 +00:00
$select = 'SELECT ' . $db -> Concat ( 'u.id' , '\'#\'' , $db -> IfNull ( 'qa.attempt' , '0' )) . ' AS uniqueid, ' .
2005-11-15 22:23:43 +00:00
'qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, ' .
2005-11-18 21:03:05 +00:00
'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ' ;
2005-11-15 22:23:43 +00:00
if ( $course -> id != SITEID ) { // this is too complicated, so just do it for each of the four cases.
if ( ! empty ( $currentgroup ) && empty ( $noattempts )) {
$from = 'FROM ' . $CFG -> prefix . 'user u JOIN ' . $CFG -> prefix . 'user_students us ON us.userid = u.id JOIN ' . $CFG -> prefix . 'groups_members gm ON u.id = gm.userid ' .
'JOIN ' . $CFG -> prefix . 'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = ' . $quiz -> id ;
$where = ' WHERE us.course = ' . $course -> id . ' AND gm.groupid = ' . $currentgroup ;
} else if ( ! empty ( $currentgroup ) && ! empty ( $noattempts )) {
$from = 'FROM ' . $CFG -> prefix . 'user u JOIN ' . $CFG -> prefix . 'user_students us ON us.userid = u.id JOIN ' . $CFG -> prefix . 'groups_members gm ON u.id = gm.userid ' .
'LEFT JOIN ' . $CFG -> prefix . 'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = ' . $quiz -> id ;
$where = ' WHERE us.course = ' . $course -> id . ' AND gm.groupid = ' . $currentgroup . ' AND qa.userid IS NULL' ;
} else if ( empty ( $currentgroup ) && empty ( $noattempts )) {
$from = 'FROM ' . $CFG -> prefix . 'user u JOIN ' . $CFG -> prefix . 'quiz_attempts qa ON u.id = qa.userid ' ;
$where = ' WHERE qa.quiz = ' . $quiz -> id ;
} else if ( empty ( $currentgroup ) && ! empty ( $noattempts )) {
$from = 'FROM ' . $CFG -> prefix . 'user u JOIN ' . $CFG -> prefix . 'user_students us ON us.userid = u.id LEFT JOIN ' . $CFG -> prefix . 'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = ' . $quiz -> id ;
$where = ' WHERE us.course = ' . $course -> id . ' AND qa.userid IS NULL' ;
}
2005-11-18 21:03:05 +00:00
$countsql = 'SELECT COUNT(DISTINCT(' . $db -> Concat ( 'u.id' , '\'#\'' , $db -> IfNull ( 'qa.attempt' , '0' )) . ')) ' . $from . $where ;
2005-11-15 22:23:43 +00:00
} else {
if ( empty ( $noattempts )) {
$from = 'FROM ' . $CFG -> prefix . 'user u JOIN ' . $CFG -> prefix . 'quiz_attempts qa ON u.id = qa.userid ' ;
$where = ' WHERE qa.quiz = ' . $quiz -> id ;
2005-11-18 21:03:05 +00:00
$countsql = 'SELECT COUNT(DISTINCT(' . $db -> Concat ( 'u.id' , '\'#\'' , $db -> IfNull ( 'qa.attempt' , '0' )) . ')) ' . $from . $where ;
2005-11-15 22:23:43 +00:00
}
2005-06-04 09:58:35 +00:00
}
2005-07-22 09:43:23 +00:00
if ( ! $download ) {
// Add extra limits due to initials bar
if ( $table -> get_sql_where ()) {
2005-11-15 22:23:43 +00:00
$where .= ' AND ' . $table -> get_sql_where ();
2005-07-22 09:43:23 +00:00
}
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
// Count the records NOW, before funky question grade sorting messes up $from
2005-11-15 22:23:43 +00:00
if ( ! empty ( $countsql )) {
$totalinitials = count_records_sql ( $countsql );
if ( $table -> get_sql_where ()) {
$countsql .= ' AND ' . $table -> get_sql_where ();
}
$total = count_records_sql ( $countsql );
}
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
// Add extra limits due to sorting by question grade
if ( $sort = $table -> get_sql_sort ()) {
$sortparts = explode ( ',' , $sort );
$newsort = array ();
$questionsort = false ;
foreach ( $sortparts as $sortpart ) {
$sortpart = trim ( $sortpart );
if ( substr ( $sortpart , 0 , 1 ) == '$' ) {
if ( ! $questionsort ) {
$qid = intval ( substr ( $sortpart , 1 ));
$select .= ', grade ' ;
$from .= 'LEFT JOIN ' . $CFG -> prefix . 'quiz_newest_states qns ON qns.attemptid = qa.attemptuniqueid ' .
'LEFT JOIN ' . $CFG -> prefix . 'quiz_states qs ON qs.id = qns.newgraded ' ;
$where .= ' AND (' . sql_isnull ( 'qns.questionid' ) . ' OR qns.questionid = ' . $qid . ')' ;
$newsort [] = 'grade ' . ( strpos ( $sortpart , 'ASC' ) ? 'ASC' : 'DESC' );
$questionsort = true ;
}
}
else {
$newsort [] = $sortpart ;
2005-06-04 09:58:35 +00:00
}
}
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
// Reconstruct the sort string
$sort = ' ORDER BY ' . implode ( ', ' , $newsort );
}
2005-09-17 13:09:43 +00:00
2005-10-28 02:22:34 +00:00
// Fix some wired sorting
if ( empty ( $sort )) {
$sort = ' ORDER BY uniqueid' ;
}
2005-09-17 13:09:43 +00:00
// Now it is time to page the data
2005-08-26 08:00:19 +00:00
if ( ! isset ( $pagesize ) || (( int ) $pagesize < 1 ) ) {
2005-07-22 09:43:23 +00:00
$pagesize = 10 ;
}
$table -> pagesize ( $pagesize , $total );
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
if ( $table -> get_page_start () !== '' && $table -> get_page_size () !== '' ) {
$limit = ' ' . sql_paging_limit ( $table -> get_page_start (), $table -> get_page_size ());
}
else {
$limit = '' ;
}
2005-06-04 09:58:35 +00:00
}
2005-07-22 09:43:23 +00:00
2005-06-04 09:58:35 +00:00
/// Fetch the attempts
2005-11-15 22:23:43 +00:00
if ( ! empty ( $from )) { // if we're in the site course and displaying no attempts, it makes no sense to do the query.
$attempts = get_records_sql ( $select . $from . $where . $sort . $limit );
} else {
$attempts = array ();
}
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
/// Build table rows
2005-09-17 13:09:43 +00:00
2005-11-15 22:23:43 +00:00
if ( ! $download ) {
$table -> initialbars ( $totalinitials > 20 );
}
if ( ! empty ( $attempts ) || ! empty ( $noattempts )) {
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
foreach ( $attempts as $attempt ) {
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
$picture = print_user_picture ( $attempt -> userid , $course -> id , $attempt -> picture , false , true );
2005-09-17 13:09:43 +00:00
// uncomment the commented lines below if you are choosing to show unenrolled users and
// have uncommented the corresponding lines earlier in this script
//if (in_array($attempt->userid, $unenrolledusers)) {
// $userlink = '<a class="dimmed" href="'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.'&course='.$course->id.'">'.fullname($attempt).'</a>';
//}
//else {
$userlink = '<a href="' . $CFG -> wwwroot . '/user/view.php?id=' . $attempt -> userid . '&course=' . $course -> id . '">' . fullname ( $attempt ) . '</a>' ;
//}
2005-07-22 09:43:23 +00:00
if ( ! $download ) {
$row = array (
'<input type="checkbox" name="attemptid[]" value="' . $attempt -> attempt . '" />' ,
$picture ,
$userlink ,
empty ( $attempt -> attempt ) ? '-' : '<a href="review.php?q=' . $quiz -> id . '&attempt=' . $attempt -> attempt . '">' . userdate ( $attempt -> timestart , $strtimeformat ) . '</a>' ,
empty ( $attempt -> attempt ) ? '-' :
( empty ( $attempt -> timefinish ) ? get_string ( 'unfinished' , 'quiz' ) :
format_time ( $attempt -> duration ))
);
2005-09-17 13:09:43 +00:00
}
2005-07-22 09:43:23 +00:00
else {
$row = array ( fullname ( $attempt ),
empty ( $attempt -> attempt ) ? '-' : userdate ( $attempt -> timestart , $strtimeformat ),
empty ( $attempt -> attempt ) ? '-' :
( empty ( $attempt -> timefinish ) ? get_string ( 'unfinished' , 'quiz' ) :
format_time ( $attempt -> duration ))
);
}
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
if ( $quiz -> grade ) {
2005-07-22 09:43:23 +00:00
if ( ! $download ) {
$row [] = $attempt -> sumgrades === NULL ? '-' : '<a href="review.php?q=' . $quiz -> id . '&attempt=' . $attempt -> attempt . '">' . round ( $attempt -> sumgrades / $quiz -> sumgrades * $quiz -> grade , $quiz -> decimalpoints ) . '</a>' ;
}
else {
$row [] = $attempt -> sumgrades === NULL ? '-' : round ( $attempt -> sumgrades / $quiz -> sumgrades * $quiz -> grade , $quiz -> decimalpoints );
}
2005-06-04 09:58:35 +00:00
}
if ( $detailedmarks ) {
if ( empty ( $attempt -> attempt )) {
foreach ( $questionids as $questionid ) {
$row [] = '-' ;
}
}
else {
foreach ( $questionids as $questionid ) {
2005-07-02 18:14:51 +00:00
if ( $gradedstateid = get_field ( 'quiz_newest_states' , 'newgraded' , 'attemptid' , $attempt -> attemptuniqueid , 'questionid' , $questionid )) {
2005-06-04 09:58:35 +00:00
$grade = round ( get_field ( 'quiz_states' , 'grade' , 'id' , $gradedstateid ), $quiz -> decimalpoints );
2005-09-17 13:09:43 +00:00
} else {
2005-06-04 09:58:35 +00:00
// This is an old-style attempt
$grade = round ( get_field ( 'quiz_states' , 'grade' , 'attempt' , $attempt -> attempt , 'question' , $questionid ), $quiz -> decimalpoints );
}
2005-07-22 09:43:23 +00:00
if ( ! $download ) {
$row [] = link_to_popup_window ( '/mod/quiz/reviewquestion.php?state=' . $gradedstateid . '&number=' . $questions [ $questionid ] -> number , 'reviewquestion' , $grade , 450 , 650 , $strreviewquestion , 'none' , true );
}
else {
$row [] = $grade ;
}
2005-06-04 09:58:35 +00:00
}
}
}
2005-07-22 09:43:23 +00:00
if ( ! $download ) {
$table -> add_data ( $row );
2005-09-17 13:09:43 +00:00
}
2005-07-22 09:43:23 +00:00
elseif ( $download == 'Excel' ) {
$colnum = 0 ;
foreach ( $row as $item ){
$myxls -> write ( $rownum , $colnum , $item , $format );
$colnum ++ ;
}
$rownum ++ ;
}
elseif ( $download == 'CSV' ) {
$text = implode ( " \t " , $row );
echo $text . " \n " ;
}
2005-06-04 09:58:35 +00:00
}
2005-09-17 13:09:43 +00:00
if ( ! $download ) {
2005-06-04 09:58:35 +00:00
/// Start form
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
echo '<div id="tablecontainer">' ;
echo '<form id="attemptsform" method="post" action="report.php" onsubmit="var menu = document.getElementById(\'menuaction\'); return (menu.options[menu.selectedIndex].value == \'delete\' ? \'' . $strreallydel . '\' : true);">' ;
echo '<input type="hidden" name="id" value="' . $cm -> id . '" />' ;
echo '<input type="hidden" name="mode" value="overview" />' ;
2005-09-17 13:09:43 +00:00
2005-06-04 09:58:35 +00:00
/// Print table
2005-09-17 13:09:43 +00:00
2005-07-22 09:43:23 +00:00
$table -> print_html ();
2005-06-04 09:58:35 +00:00
/// Print "Select all" etc.
2005-11-15 22:23:43 +00:00
if ( ! empty ( $attempts )) {
echo '<table id="commands">' ;
echo '<tr><td>' ;
echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string ( 'selectall' , 'quiz' ) . '</a> / ' ;
echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string ( 'selectnone' , 'quiz' ) . '</a> ' ;
echo ' ' ;
$options = array ( 'delete' => get_string ( 'delete' ));
echo choose_from_menu ( $options , 'action' , '' , get_string ( 'withselected' , 'quiz' ), 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');' , '' , true );
echo '<noscript id="noscriptmenuaction" style="display: inline;">' ;
echo '<input type="submit" value="' . get_string ( 'go' ) . '" /></noscript>' ;
echo '<script type="text/javascript">' . " \n <!-- \n " . 'document.getElementById("noscriptmenuaction").style.display = "none";' . " \n --> \n " . '</script>' ;
echo '</td></tr></table>' ;
}
2005-06-04 09:58:35 +00:00
/// Close form
2005-07-22 09:43:23 +00:00
echo '</form></div>' ;
/// Print display options
echo '<div class="controls">' ;
echo '<form id="options" name="options" action="report.php" method="post">' ;
echo '<p>' . get_string ( 'displayoptions' , 'quiz' ) . ': </p>' ;
echo '<input type="hidden" name="id" value="' . $cm -> id . '" />' ;
echo '<input type="hidden" name="q" value="' . $quiz -> id . '" />' ;
echo '<input type="hidden" name="mode" value="overview" />' ;
echo '<input type="hidden" name="noattempts" value="0" />' ;
echo '<input type="hidden" name="detailedmarks" value="0" />' ;
echo '<table id="overview-options" align="center">' ;
echo '<tr align="left">' ;
echo '<td><label for="pagesize">' . get_string ( 'pagesize' , 'quiz' ) . '</label></td>' ;
echo '<td><input type="text" id="pagesize" name="pagesize" size="1" value="' . $pagesize . '" /></td>' ;
echo '</tr>' ;
2005-09-17 13:09:43 +00:00
echo '<tr align="left">' ;
2005-11-16 01:38:07 +00:00
echo '<td colspan="2"><input type="checkbox" id="checknoattempts" name="noattempts" ' . ( $noattempts ? 'checked="checked" ' : '' ) . 'value="1" ' . (( $course -> id == SITEID ) ? ' disabled="disabled"' : '' ) . ' /> <label for="checknoattempts">' . get_string ( 'shownoattemptsonly' , 'quiz' ) . '</label> ' ;
2005-09-17 13:09:43 +00:00
echo '</td></tr>' ;
echo '<tr align="left">' ;
2005-11-16 01:38:07 +00:00
echo '<td colspan="2"><input type="checkbox" id="checkdetailedmarks" name="detailedmarks" ' . ( $detailedmarks ? 'checked="checked" ' : '' ) . 'value="1" /> <label for="checkdetailedmarks">' . get_string ( 'showdetailedmarks' , 'quiz' ) . '</label> ' ;
2005-09-17 13:09:43 +00:00
echo '</td></tr>' ;
2005-07-22 09:43:23 +00:00
echo '<tr><td colspan="2" align="center">' ;
echo '<input type="submit" value="' . get_string ( 'go' ) . '" />' ;
echo '</td></tr></table>' ;
echo '</form>' ;
2005-09-17 13:09:43 +00:00
echo '</div>' ;
2005-07-22 09:43:23 +00:00
echo " \n " ;
2005-11-15 22:23:43 +00:00
if ( ! empty ( $attempts )) {
echo '<table align="center"><tr>' ;
unset ( $options );
$options [ " id " ] = " $cm->id " ;
$options [ " q " ] = " $quiz->id " ;
$options [ " mode " ] = " overview " ;
$options [ 'sesskey' ] = sesskey ();
$options [ " noheader " ] = " yes " ;
echo '<td>' ;
$options [ " download " ] = " Excel " ;
print_single_button ( " report.php " , $options , get_string ( " downloadexcel " ));
echo " </td> \n " ;
echo '<td>' ;
$options [ " download " ] = " CSV " ;
print_single_button ( 'report.php' , $options , get_string ( " downloadtext " ));
echo " </td> \n " ;
echo " <td> " ;
helpbutton ( " download " , get_string ( " download " , " quiz " ), " quiz " );
echo " </td> \n " ;
echo '</tr></table>' ;
}
2005-07-22 09:43:23 +00:00
}
elseif ( $download == 'Excel' ) {
$workbook -> close ();
}
elseif ( $download == 'CSV' ) {
exit ;
}
2005-06-04 09:58:35 +00:00
}
else {
2005-07-22 09:43:23 +00:00
if ( ! $download ) {
$table -> print_html ();
}
2005-06-04 09:58:35 +00:00
}
return true ;
}
}
?>