2004-09-12 17:34:35 +00:00
< ? php // $Id$
2002-10-04 02:59:05 +00:00
// This page prints a particular instance of quiz
2003-01-05 14:19:20 +00:00
require_once ( " ../../config.php " );
2005-01-08 20:06:00 +00:00
require_once ( " locallib.php " );
2005-02-10 01:59:11 +00:00
require_once ( $CFG -> libdir . '/blocklib.php' );
require_once ( 'pagelib.php' );
2002-10-04 02:59:05 +00:00
2006-04-23 20:58:06 +00:00
$id = optional_param ( 'id' , 0 , PARAM_INT ); // Course Module ID, or
$q = optional_param ( 'q' , 0 , PARAM_INT ); // quiz ID
$edit = optional_param ( 'edit' , - 1 , PARAM_BOOL );
2006-03-21 09:24:47 +00:00
2002-10-04 02:59:05 +00:00
if ( $id ) {
2006-08-08 22:09:55 +00:00
if ( ! $cm = get_coursemodule_from_id ( 'quiz' , $id )) {
2005-06-04 09:58:35 +00:00
error ( " There is no coursemodule with id $id " );
2002-10-04 02:59:05 +00:00
}
2005-05-06 06:24:04 +00:00
2002-10-04 02:59:05 +00:00
if ( ! $course = get_record ( " course " , " id " , $cm -> course )) {
error ( " Course is misconfigured " );
}
2005-05-06 06:24:04 +00:00
2002-10-04 02:59:05 +00:00
if ( ! $quiz = get_record ( " quiz " , " id " , $cm -> instance )) {
2005-06-04 09:58:35 +00:00
error ( " The quiz with id $cm->instance corresponding to this coursemodule $id is missing " );
2002-10-04 02:59:05 +00:00
}
} else {
2002-10-06 03:23:34 +00:00
if ( ! $quiz = get_record ( " quiz " , " id " , $q )) {
2005-06-04 09:58:35 +00:00
error ( " There is no quiz with id $q " );
2002-10-04 02:59:05 +00:00
}
if ( ! $course = get_record ( " course " , " id " , $quiz -> course )) {
2005-06-04 09:58:35 +00:00
error ( " The course with id $quiz->course that the quiz with id $q belongs to is missing " );
2002-10-04 02:59:05 +00:00
}
if ( ! $cm = get_coursemodule_from_instance ( " quiz " , $quiz -> id , $course -> id )) {
2005-06-04 09:58:35 +00:00
error ( " The course module for the quiz with id $q is missing " );
2002-10-04 02:59:05 +00:00
}
}
2006-08-22 13:53:39 +00:00
2005-02-16 10:40:48 +00:00
require_login ( $course -> id , false , $cm );
2005-05-06 06:24:04 +00:00
$isteacher = isteacher ( $course -> id );
2005-01-02 07:15:19 +00:00
// if no questions have been set up yet redirect to edit.php
2006-08-22 13:53:39 +00:00
if ( ! $quiz -> questions and isteacheredit ( $course -> id )) {
2005-01-02 07:15:19 +00:00
redirect ( 'edit.php?quizid=' . $quiz -> id );
}
2002-10-04 02:59:05 +00:00
2004-01-31 15:22:04 +00:00
add_to_log ( $course -> id , " quiz " , " view " , " view.php?id= $cm->id " , $quiz -> id , $cm -> id );
2002-10-04 02:59:05 +00:00
2002-10-15 16:22:18 +00:00
$timenow = time ();
2002-10-20 10:13:04 +00:00
2005-02-01 07:16:19 +00:00
// Initialize $PAGE, compute blocks
2005-03-02 05:19:47 +00:00
$PAGE = page_create_instance ( $quiz -> id );
$pageblocks = blocks_setup ( $PAGE );
2005-02-02 02:46:06 +00:00
$blocks_preferred_width = bounded_number ( 180 , blocks_preferred_width ( $pageblocks [ BLOCK_POS_LEFT ]), 210 );
2002-10-06 03:23:34 +00:00
2002-10-04 02:59:05 +00:00
// Print the page header
2006-04-23 20:58:06 +00:00
if (( $edit != - 1 ) and $PAGE -> user_allowed_editing ()) {
$USER -> editing = $edit ;
2005-02-01 07:16:19 +00:00
}
2005-11-09 02:16:13 +00:00
//only check pop ups if the user is not a teacher, and popup is set
$bodytags = ( isteacher ( $course -> id ) or ! $quiz -> popup ) ? '' : 'onload="popupchecker(\'This section of the test is in secure mode, this means that you need to take the quiz in a secure window. Please turn off your popup blocker. Thank you.\');"' ;
$PAGE -> print_header ( $course -> shortname . ': %fullname%' , '' , $bodytags );
2002-10-13 13:51:56 +00:00
2005-02-12 11:37:09 +00:00
echo '<table id="layout-table"><tr>' ;
2005-02-01 07:16:19 +00:00
2005-03-16 03:26:21 +00:00
if ( ! empty ( $CFG -> showblocksonmodpages ) && ( blocks_have_content ( $pageblocks , BLOCK_POS_LEFT ) || $PAGE -> user_is_editing ())) {
2005-02-12 11:37:09 +00:00
echo '<td style="width: ' . $blocks_preferred_width . 'px;" id="left-column">' ;
2005-03-02 05:47:39 +00:00
blocks_print_group ( $PAGE , $pageblocks , BLOCK_POS_LEFT );
2005-02-01 07:16:19 +00:00
echo '</td>' ;
}
2005-02-12 11:37:09 +00:00
echo '<td id="middle-column">' ;
2005-02-01 07:16:19 +00:00
2005-07-07 17:16:56 +00:00
$available = ( $quiz -> timeopen < $timenow and ( $timenow < $quiz -> timeclose or ! $quiz -> timeclose )) || $isteacher ;
2002-10-20 10:13:04 +00:00
2002-10-04 02:59:05 +00:00
// Print the main part of the page
2005-05-06 06:24:04 +00:00
// Print heading and tabs for teacher
2006-08-22 13:53:39 +00:00
if ( $isteacher ) {
$currenttab = 'info' ;
include ( 'tabs.php' );
}
2005-04-03 00:19:11 +00:00
print_heading ( format_string ( $quiz -> name ));
2002-10-06 03:23:34 +00:00
2004-08-23 12:35:13 +00:00
if ( trim ( strip_tags ( $quiz -> intro ))) {
2006-01-16 06:29:51 +00:00
$formatoptions -> noclean = true ;
print_simple_box ( format_text ( $quiz -> intro , FORMAT_MOODLE , $formatoptions ), " center " );
2005-05-06 06:24:04 +00:00
}
if ( $quiz -> attempts > 1 ) {
echo " <p align= \" center \" > " . get_string ( " attemptsallowed " , " quiz " ) . " : $quiz->attempts </p> " ;
echo " <p align= \" center \" > " . get_string ( " grademethod " , " quiz " ) . " : " . $QUIZ_GRADE_METHOD [ $quiz -> grademethod ] . " </p> " ;
} else {
echo " <br /> " ;
}
if ( $available ) {
if ( $quiz -> timelimit ) {
echo " <p align= \" center \" > " . get_string ( " quiztimelimit " , " quiz " , format_time ( $quiz -> timelimit * 60 )) . " </p> " ;
}
2005-07-07 17:16:56 +00:00
quiz_view_dates ( $quiz );
2005-05-06 06:24:04 +00:00
} else if ( $timenow < $quiz -> timeopen ) {
echo " <p align= \" center \" > " . get_string ( " quiznotavailable " , " quiz " , userdate ( $quiz -> timeopen ));
} else {
echo " <p align= \" center \" > " . get_string ( " quizclosed " , " quiz " , userdate ( $quiz -> timeclose ));
2004-08-23 12:35:13 +00:00
}
2002-10-06 03:23:34 +00:00
2005-05-06 06:24:04 +00:00
// This is all the teacher will get
2006-08-22 13:53:39 +00:00
if ( $isteacher ) {
2006-04-12 23:24:58 +00:00
if ( $a -> attemptnum = count_records ( 'quiz_attempts' , 'quiz' , $quiz -> id , 'preview' , 0 )) {
$a -> studentnum = count_records_select ( 'quiz_attempts' , " quiz = ' $quiz->id ' AND preview = '0' " , 'COUNT(DISTINCT userid)' );
$a -> studentstring = $course -> students ;
2005-06-05 20:51:15 +00:00
2006-04-12 23:24:58 +00:00
notify ( " <a href= \" report.php?mode=overview&id= $cm->id\ " > " .get_string('numattempts', 'quiz', $a ).'</a>');
2005-06-05 20:51:15 +00:00
}
2006-02-13 20:27:34 +00:00
2005-07-06 00:36:36 +00:00
echo '</td></tr></table>' ;
2005-05-06 06:24:04 +00:00
print_footer ( $course );
exit ;
}
2006-08-22 13:53:39 +00:00
if ( isguest ()) {
$wwwroot = $CFG -> wwwroot . '/login/index.php' ;
if ( ! empty ( $CFG -> loginhttps )) {
$wwwroot = str_replace ( 'http:' , 'https:' , $wwwroot );
}
notice_yesno ( get_string ( 'guestsno' , 'quiz' ) . '<br /><br />' . get_string ( 'liketologin' ),
$wwwroot , $_SERVER [ 'HTTP_REFERER' ]);
print_footer ( $course );
echo '</td></tr></table>' ;
exit ;
}
2002-10-06 03:23:34 +00:00
if ( $attempts = quiz_get_user_attempts ( $quiz -> id , $USER -> id )) {
$numattempts = count ( $attempts );
} else {
$numattempts = 0 ;
}
2005-05-06 06:24:04 +00:00
$unfinished = false ;
if ( $unfinishedattempt = quiz_get_user_attempt_unfinished ( $quiz -> id , $USER -> id )) {
$attempts [] = $unfinishedattempt ;
$unfinished = true ;
2002-10-13 13:51:56 +00:00
}
2002-10-15 12:54:11 +00:00
2002-10-18 16:05:21 +00:00
$strattempt = get_string ( " attempt " , " quiz " );
$strtimetaken = get_string ( " timetaken " , " quiz " );
$strtimecompleted = get_string ( " timecompleted " , " quiz " );
$strgrade = get_string ( " grade " );
2006-03-21 09:24:47 +00:00
$strmarks = get_string ( 'marks' , 'quiz' );
2003-12-13 02:30:20 +00:00
$strbestgrade = $QUIZ_GRADE_METHOD [ $quiz -> grademethod ];
2002-10-15 12:54:11 +00:00
2005-05-08 11:24:03 +00:00
$windowoptions = " left=0, top=0, channelmode=yes, fullscreen=yes, scrollbars=yes, resizeable=no, directories=no, toolbar=no, titlebar=no, location=no, status=no, menubar=no " ;
2005-02-14 19:41:52 +00:00
$mygrade = quiz_get_best_grade ( $quiz , $USER -> id );
2003-01-01 14:47:11 +00:00
2005-05-08 11:24:03 +00:00
/// Now print table with existing attempts
2006-04-19 02:31:32 +00:00
$gradecolumn = 0 ;
$overallstats = 1 ;
2005-05-08 11:24:03 +00:00
2006-04-05 05:53:18 +00:00
if ( $attempts ) {
2006-02-13 20:27:34 +00:00
2006-04-18 22:54:10 +00:00
//step thru each attempt, checking there are any attempts
//for which the score can be displayed (need grade columns),
//and checking if overall grades can be displayed - no attempts for
//which the score cannot be displayed
foreach ( $attempts as $attempt ) {
$attemptoptions = quiz_get_reviewoptions ( $quiz , $attempt , $isteacher );
$attemptoptions -> scores ? $gradecolumn = 1 : $overallstats = 0 ;
}
2005-05-08 11:24:03 +00:00
/// prepare table header
2006-04-05 05:53:18 +00:00
$table -> head = array ( $strattempt , $strtimecompleted );
$table -> align = array ( " center " , " left " );
$table -> size = array ( " " , " " );
2006-04-18 22:54:10 +00:00
if ( $gradecolumn && $quiz -> grade and $quiz -> sumgrades ) { // Grades used so have more columns in table
2005-02-11 19:51:29 +00:00
if ( $quiz -> grade <> $quiz -> sumgrades ) {
2006-04-05 05:53:18 +00:00
$table -> head [] = " $strmarks / $quiz->sumgrades " ;
$table -> align [] = 'right' ;
$table -> size [] = '' ;
2005-02-11 19:51:29 +00:00
}
2006-04-05 05:53:18 +00:00
$table -> head [] = " $strgrade / $quiz->grade " ;
$table -> align [] = 'right' ;
$table -> size [] = '' ;
}
if ( isset ( $quiz -> showtimetaken )) {
$table -> head [] = $strtimetaken ;
$table -> align [] = 'center' ;
$table -> size [] = '' ;
2003-09-10 05:02:39 +00:00
}
2005-05-08 11:24:03 +00:00
/// One row for each attempt
2002-10-06 03:23:34 +00:00
foreach ( $attempts as $attempt ) {
2005-05-08 11:24:03 +00:00
/// prepare strings for time taken and date completed
2005-05-06 06:24:04 +00:00
$timetaken = '' ;
$datecompleted = '' ;
2005-05-08 11:24:03 +00:00
if ( $attempt -> timefinish > 0 ) { // attempt has finished
2005-05-06 06:24:04 +00:00
$timetaken = format_time ( $attempt -> timefinish - $attempt -> timestart );
$datecompleted = userdate ( $attempt -> timefinish );
2006-08-22 13:53:39 +00:00
} else if ( $available ) { // The student can continue this attempt, so put appropriate link
2005-05-06 06:24:04 +00:00
$timetaken = format_time ( time () - $attempt -> timestart );
$datecompleted = " \n " . '<script language="javascript" type="text/javascript">' ;
$datecompleted .= " \n <!-- \n " ; // -->
2006-01-09 01:25:11 +00:00
if ( ! empty ( $CFG -> usesid ) && ! isset ( $_COOKIE [ session_name ()])) {
2005-12-23 06:29:39 +00:00
$attempturl = sid_process_url ( " attempt.php?id= $cm->id " );
} else {
$attempturl = " attempt.php?id= $cm->id " ;
};
2005-05-06 06:24:04 +00:00
if ( ! empty ( $quiz -> popup )) {
$datecompleted .= " var windowoptions = 'left=0, top=0, height='+window.screen.height+
2006-07-18 16:49:33 +00:00
', width=' + window . screen . width + ', channelmode=yes, fullscreen=yes, scrollbars=yes, ' +
'resizeable=no, directories=no, toolbar=no, titlebar=no, location=no, status=no, ' +
'menubar=no' ; \n " ;
$jslink = " javascript:var popup = window.open( \\ ' $attempturl\\ ', \\ 'quizpopup \\ ', windowoptions); " ;
2005-05-06 06:24:04 +00:00
} else {
2005-12-23 06:29:39 +00:00
$jslink = $attempturl ;
2005-05-06 06:24:04 +00:00
}
$linktext = get_string ( 'continueattemptquiz' , 'quiz' );
$datecompleted .= " document.write('<a href= \" $jslink\ " alt = \ " $linktext\ " > $linktext </ a > ' ); " ;
$datecompleted .= " \n --> \n " ;
$datecompleted .= '</script>' ;
$datecompleted .= '<noscript>' ;
$datecompleted .= '<strong>' . get_string ( 'noscript' , 'quiz' ) . '</strong>' ;
$datecompleted .= '</noscript>' ;
2005-05-08 11:24:03 +00:00
} else { // attempt was not completed but is also not available any more.
2005-05-06 06:24:04 +00:00
$timetaken = format_time ( $quiz -> timeclose - $attempt -> timestart );
2005-07-07 17:16:56 +00:00
$datecompleted = $quiz -> timeclose ? userdate ( $quiz -> timeclose ) : '' ;
2002-10-22 06:52:23 +00:00
}
2005-05-06 06:24:04 +00:00
2006-04-18 22:54:10 +00:00
$attemptoptions = quiz_get_reviewoptions ( $quiz , $attempt , $isteacher );
2005-05-08 11:24:03 +00:00
/// prepare strings for attempt number, mark and grade
2006-04-18 22:54:10 +00:00
//if attempt's score is allowed to be viewed, & qz->sumgrades and qz->sumgrades defined:
if ( $attemptoptions -> scores && $quiz -> grade and $quiz -> sumgrades ) {
2005-05-07 13:48:25 +00:00
$attemptmark = round ( $attempt -> sumgrades , $quiz -> decimalpoints );
$attemptgrade = round (( $attempt -> sumgrades / $quiz -> sumgrades ) * $quiz -> grade , $quiz -> decimalpoints );
2005-05-08 11:24:03 +00:00
// highlight the highest grade if appropriate
2006-04-18 22:54:10 +00:00
if ( $overallstats && $attemptgrade == $mygrade and ( $quiz -> grademethod == QUIZ_GRADEHIGHEST )) {
2004-09-12 17:34:35 +00:00
$attemptgrade = " <span class= \" highlight \" > $attemptgrade </span> " ;
2003-09-10 05:02:39 +00:00
}
2005-05-06 06:24:04 +00:00
2005-05-08 11:24:03 +00:00
// if attempt is closed and review is allowed then make attemptnumber and
2005-05-06 06:24:04 +00:00
// mark and grade into links to review page
if ( quiz_review_allowed ( $quiz ) and $attempt -> timefinish > 0 ) {
2005-05-08 11:24:03 +00:00
if ( $quiz -> popup ) { // need to link to popup window
$attemptmark = link_to_popup_window ( " /mod/quiz/review.php?q= $quiz->id &attempt= $attempt->id " , 'quizpopup' , round ( $attempt -> sumgrades , $quiz -> decimalpoints ), '+window.screen.height+' , '+window.screen.width+' , '' , $windowoptions , true );
$attemptgrade = link_to_popup_window ( " /mod/quiz/review.php?q= $quiz->id &attempt= $attempt->id " , 'quizpopup' , $attemptgrade , '+window.screen.height+' , '+window.screen.width+' , '' , $windowoptions , true );
$attempt -> attempt = link_to_popup_window ( " /mod/quiz/review.php?q= $quiz->id &attempt= $attempt->id " , 'quizpopup' , " # $attempt->attempt " , '+window.screen.height+' , '+window.screen.width+' , '' , $windowoptions , true );
} else {
$attemptmark = " <a href= \" review.php?q= $quiz->id &attempt= $attempt->id\ " > " .round( $attempt->sumgrades , $quiz->decimalpoints ).'</a>';
$attemptgrade = " <a href= \" review.php?q= $quiz->id &attempt= $attempt->id\ " > $attemptgrade </ a > " ;
$attempt -> attempt = " <a href= \" review.php?q= $quiz->id &attempt= $attempt->id\ " > #$attempt->attempt</a>";
}
2003-09-10 05:02:39 +00:00
}
2005-05-06 06:24:04 +00:00
2005-02-11 19:51:29 +00:00
if ( $quiz -> grade <> $quiz -> sumgrades ) {
2005-05-06 06:24:04 +00:00
$table -> data [] = array ( $attempt -> attempt ,
$datecompleted ,
2005-02-11 19:51:29 +00:00
$attemptmark , $attemptgrade );
} else {
2005-05-06 06:24:04 +00:00
$table -> data [] = array ( $attempt -> attempt ,
$datecompleted ,
2005-02-11 19:51:29 +00:00
$attemptgrade );
}
2003-09-10 05:02:39 +00:00
} else { // No grades are being used
2005-01-02 07:15:19 +00:00
if ( quiz_review_allowed ( $quiz )) {
2005-05-06 06:24:04 +00:00
if ( $attempt -> timefinish > 0 ) {
$attempt -> attempt = " <a href= \" review.php?q= $quiz->id &attempt= $attempt->id\ " > #$attempt->attempt</a>";
} else {
$attempt -> attempt = " <a href= \" attempt.php?id= $id\ " > #$attempt->attempt</a>";
}
2003-09-10 05:02:39 +00:00
}
2006-04-18 22:54:10 +00:00
$helpbutton = helpbutton ( 'missing\ grade' , get_string ( 'wheregrade' , 'quiz' ), 'quiz' , true , false , '' , true );
if ( $gradecolumn ) {
$table -> data [] = array ( $attempt -> attempt ,
$datecompleted ,
$helpbutton );
} else {
$table -> data [] = array ( $attempt -> attempt ,
$datecompleted );
}
2003-01-01 14:47:11 +00:00
}
2006-04-05 05:53:18 +00:00
if ( isset ( $quiz -> showtimetaken )) {
$table -> data [] = $timetaken ;
}
2002-10-06 03:23:34 +00:00
}
print_table ( $table );
}
2002-10-15 12:54:11 +00:00
if ( ! $quiz -> questions ) {
print_heading ( get_string ( " noquestions " , " quiz " ));
} else {
2005-05-06 06:24:04 +00:00
if ( $numattempts < $quiz -> attempts or ! $quiz -> attempts ) {
2005-11-09 02:16:13 +00:00
2002-10-15 12:54:11 +00:00
if ( $available ) {
$options [ " id " ] = $cm -> id ;
2006-04-18 22:54:10 +00:00
//if overall stats are allowed (no attemps' grade not visible),
//and there is at least one attempt, and quiz->grade:
if ( $overallstats and $numattempts and $quiz -> grade ) {
2002-10-18 16:05:21 +00:00
print_heading ( " $strbestgrade : $mygrade / $quiz->grade . " );
2002-10-15 12:54:11 +00:00
}
2006-06-28 10:13:40 +00:00
2004-06-02 18:03:05 +00:00
echo " <br /> " ;
2004-11-11 12:07:08 +00:00
echo " </p> " ;
2006-07-18 16:49:33 +00:00
echo " <div align= \" center \" > " ;
2006-03-21 09:24:47 +00:00
if ( $quiz -> delay1 or $quiz -> delay2 ) {
//quiz enforced time delay
$lastattempt_obj = get_record_select ( 'quiz_attempts' , " quiz = $quiz->id AND attempt = $numattempts AND userid = $USER->id " , 'timefinish' );
if ( $lastattempt_obj ) {
$lastattempt = $lastattempt_obj -> timefinish ;
}
if ( $numattempts == 1 && $quiz -> delay1 ) {
2006-08-22 13:53:39 +00:00
if ( $timenow - $quiz -> delay1 > $lastattempt ) {
print_start_quiz_button ( $quiz , $attempts , $numattempts , $unfinished , $cm );
2006-07-18 16:49:33 +00:00
} else {
2006-03-21 09:24:47 +00:00
$notify_msg = get_string ( 'temporaryblocked' , 'quiz' ) . '<b>' . userdate ( $lastattempt + $quiz -> delay1 ) . '<b>' ;
print_simple_box ( $notify_msg , " center " );
}
2006-07-18 16:49:33 +00:00
} else if ( $numattempts > 1 && $quiz -> delay2 ) {
2006-08-22 13:53:39 +00:00
if ( $timenow - $quiz -> delay2 > $lastattempt ) {
2006-07-18 16:49:33 +00:00
print_start_quiz_button ( $quiz , $attempts , $numattempts , $unfinished , $cm );
} else {
2006-03-21 09:24:47 +00:00
$notify_msg = get_string ( 'temporaryblocked' , 'quiz' ) . '<b>' . userdate ( $lastattempt + $quiz -> delay2 ) . '<b>' ;
print_simple_box ( $notify_msg , " center " );
}
2006-08-22 13:53:39 +00:00
} else {
2006-07-18 16:49:33 +00:00
print_start_quiz_button ( $quiz , $attempts , $numattempts , $unfinished , $cm );
2006-03-21 09:24:47 +00:00
}
2006-08-22 13:53:39 +00:00
} else {
2006-07-18 16:49:33 +00:00
print_start_quiz_button ( $quiz , $attempts , $numattempts , $unfinished , $cm );
2006-03-21 09:24:47 +00:00
}
2006-07-18 16:49:33 +00:00
echo " </div> \n " ;
2002-10-13 13:51:56 +00:00
}
2002-10-15 12:54:11 +00:00
} else {
print_heading ( get_string ( " nomoreattempts " , " quiz " ));
2006-05-15 21:52:18 +00:00
//if $quiz->grade and $quiz->sumgrades, and student is allowed to
//see summary statistics (no attempt's grade is concealed),
//show the student their final grade
if ( $quiz -> grade and $quiz -> sumgrades and $overallstats ) {
2003-09-10 05:02:39 +00:00
print_heading ( get_string ( " yourfinalgradeis " , " quiz " , " $mygrade / $quiz->grade " ));
}
2005-05-06 06:24:04 +00:00
print_continue ( '../../course/view.php?id=' . $course -> id );
2002-10-06 03:23:34 +00:00
}
}
2002-10-04 02:59:05 +00:00
// Finish the page
2005-02-01 07:16:19 +00:00
echo '</td></tr></table>' ;
2002-10-04 02:59:05 +00:00
print_footer ( $course );
2005-05-06 06:24:04 +00:00
2005-01-02 07:15:19 +00:00
function quiz_review_allowed ( $quiz ) {
2005-05-06 06:24:04 +00:00
// If not even responses are to be shown in review then we
// don't allow any review
if ( ! ( $quiz -> review & QUIZ_REVIEW_RESPONSES )) {
2005-01-02 07:15:19 +00:00
return false ;
}
2005-07-07 17:16:56 +00:00
if (( ! $quiz -> timeclose or time () < $quiz -> timeclose ) and ! ( $quiz -> review & QUIZ_REVIEW_OPEN )) {
2005-01-02 07:15:19 +00:00
return false ;
}
2005-07-07 17:16:56 +00:00
if (( $quiz -> timeclose and time () > $quiz -> timeclose ) and ! ( $quiz -> review & QUIZ_REVIEW_CLOSED )) {
2005-01-02 07:15:19 +00:00
return false ;
}
return true ;
}
2006-06-28 10:13:40 +00:00
2006-07-18 16:49:33 +00:00
function print_start_quiz_button ( $quiz , $attempts , $numattempts , $unfinished , $cm ) {
$strconfirmstartattempt = '' ;
if ( $unfinished ) {
$buttontext = get_string ( 'continueattemptquiz' , 'quiz' );
} else {
if ( $numattempts ) {
$buttontext = get_string ( 'reattemptquiz' , 'quiz' );
} else {
$buttontext = get_string ( 'attemptquiznow' , 'quiz' );
}
if ( $quiz -> timelimit && $quiz -> attempts ) {
$strconfirmstartattempt = addslashes ( get_string ( 'confirmstartattempttimelimit' , 'quiz' , $quiz -> attempts ));
} else if ( $quiz -> timelimit ) {
$strconfirmstartattempt = addslashes ( get_string ( 'confirmstarttimelimit' , 'quiz' ));
} else if ( $quiz -> attempts ) {
$strconfirmstartattempt = addslashes ( get_string ( 'confirmstartattemptlimit' , 'quiz' , $quiz -> attempts ));
}
2006-06-28 10:13:40 +00:00
}
2006-07-18 16:49:33 +00:00
$buttontext = htmlspecialchars ( $buttontext , ENT_QUOTES );
if ( ! empty ( $quiz -> popup )) {
$window = 'quizpopup' ;
$windowoptions = " left=0, top=0, height='+window.screen.height+', " .
" width='+window.screen.width+', channelmode=yes, fullscreen=yes, " .
" scrollbars=yes, resizeable=no, directories=no, toolbar=no, " .
" titlebar=no, location=no, status=no, menubar=no " ;
} else {
$window = '_self' ;
$windowoptions = '' ;
}
$attempturl = " attempt.php?id= $cm->id " ;
if ( ! empty ( $CFG -> usesid ) && ! isset ( $_COOKIE [ session_name ()])) {
$attempturl = sid_process_url ( $attempturl );
}
?>
< script language = " javascript " type = " text/javascript " >
<!--
document . write ( ' < input type = " button " value = " <?php echo $buttontext ?> " onclick = " javascript: <?php
if ( $strconfirmstartattempt ) {
echo " if (confirm( \\ ' " . addslashes ( $strconfirmstartattempt ) . " \\ ')) " ;
}
?> window.open(\'<?php echo $attempturl ?>\', \'<?php echo $window ?>\', \'<?php echo $windowoptions ?>\'); " />');
// -->
</ script >
< noscript >
< strong >< ? php print_string ( 'noscript' , 'quiz' ); ?> </strong>
</ noscript >
< ? php
2006-06-28 10:13:40 +00:00
}
2002-10-04 02:59:05 +00:00
?>