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
|
|
|
|
2005-02-09 15:31:47 +00:00
|
|
|
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
|
|
|
|
$q = optional_param('q', 0, PARAM_INT); // quiz ID
|
2005-02-09 15:30:15 +00:00
|
|
|
$edit = optional_param('edit', '');
|
2002-10-04 02:59:05 +00:00
|
|
|
|
|
|
|
if ($id) {
|
|
|
|
if (! $cm = get_record("course_modules", "id", $id)) {
|
|
|
|
error("Course Module ID was incorrect");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $cm->course)) {
|
|
|
|
error("Course is misconfigured");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $quiz = get_record("quiz", "id", $cm->instance)) {
|
|
|
|
error("Course module is incorrect");
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2002-10-06 03:23:34 +00:00
|
|
|
if (! $quiz = get_record("quiz", "id", $q)) {
|
2002-10-04 02:59:05 +00:00
|
|
|
error("Course module is incorrect");
|
|
|
|
}
|
|
|
|
if (! $course = get_record("course", "id", $quiz->course)) {
|
|
|
|
error("Course is misconfigured");
|
|
|
|
}
|
|
|
|
if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
|
|
|
|
error("Course Module ID was incorrect");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
require_login($course->id, false, $cm);
|
2005-01-02 07:15:19 +00:00
|
|
|
|
|
|
|
// if no questions have been set up yet redirect to edit.php
|
|
|
|
if (!$quiz->questions and isteacheredit($course->id)) {
|
|
|
|
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
|
|
|
|
|
2005-02-01 07:16:19 +00:00
|
|
|
if (!empty($edit) && $PAGE->user_allowed_editing()) {
|
|
|
|
if ($edit == 'on') {
|
|
|
|
$USER->editing = true;
|
|
|
|
} else if ($edit == 'off') {
|
|
|
|
$USER->editing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-09 15:08:51 +00:00
|
|
|
$PAGE->print_header($course->shortname.': %fullname%');
|
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
|
|
|
|
2002-10-13 13:51:56 +00:00
|
|
|
if (isteacher($course->id)) {
|
2003-12-17 13:49:51 +00:00
|
|
|
$attemptcount = count_records_select("quiz_attempts", "quiz = '$quiz->id' AND timefinish > 0");
|
2005-04-20 11:32:29 +00:00
|
|
|
$a->count = count_records("quiz_grades", "quiz", "$quiz->id");
|
|
|
|
$a->items = get_string('users');
|
|
|
|
$strusers = get_string('counteditems', '', $a);
|
2003-12-17 13:49:51 +00:00
|
|
|
$strviewallanswers = get_string("viewallanswers","quiz",$attemptcount);
|
2005-04-20 11:32:29 +00:00
|
|
|
echo "<div class=\"reportlink\"><a href=\"report.php?id=$cm->id\">$strviewallanswers ($strusers)</a></div>";
|
2003-05-15 18:03:22 +00:00
|
|
|
} else if (!$cm->visible) {
|
|
|
|
notice(get_string("activityiscurrentlyhidden"));
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
2002-10-04 02:59:05 +00:00
|
|
|
|
2004-11-11 02:22:08 +00:00
|
|
|
$available = ($quiz->timeopen < $timenow and $timenow < $quiz->timeclose) || isteacher($course->id);
|
2002-10-20 10:13:04 +00:00
|
|
|
|
2002-10-04 02:59:05 +00:00
|
|
|
// Print the main part of the page
|
|
|
|
|
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))) {
|
2005-03-13 16:17:55 +00:00
|
|
|
print_simple_box(format_text($quiz->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
|
2004-08-23 12:35:13 +00:00
|
|
|
}
|
2002-10-06 03:23:34 +00:00
|
|
|
|
|
|
|
|
2002-10-20 10:13:04 +00:00
|
|
|
if (isguest()) {
|
|
|
|
print_heading(get_string("guestsno", "quiz"));
|
|
|
|
print_footer($course);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-10-13 13:51:56 +00:00
|
|
|
if ($quiz->attempts > 1) {
|
2004-09-12 17:34:35 +00:00
|
|
|
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>";
|
2002-10-15 12:54:11 +00:00
|
|
|
} else {
|
2003-07-24 16:48:10 +00:00
|
|
|
echo "<br />";
|
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");
|
2005-02-11 19:51:29 +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-02-14 19:41:52 +00:00
|
|
|
$mygrade = quiz_get_best_grade($quiz, $USER->id);
|
2003-01-01 14:47:11 +00:00
|
|
|
|
2002-10-06 03:23:34 +00:00
|
|
|
if ($numattempts) {
|
2005-02-11 19:51:29 +00:00
|
|
|
if ($quiz->grade and $quiz->sumgrades) {
|
|
|
|
if ($quiz->grade <> $quiz->sumgrades) {
|
|
|
|
$table->head = array($strattempt, $strtimetaken, $strtimecompleted, "$strmarks / $quiz->sumgrades", "$strgrade / $quiz->grade");
|
|
|
|
$table->align = array("center", "center", "left", "right", "right");
|
|
|
|
$table->size = array("", "", "", "", "");
|
|
|
|
} else {
|
|
|
|
$table->head = array($strattempt, $strtimetaken, $strtimecompleted, "$strgrade / $quiz->grade");
|
|
|
|
$table->align = array("center", "center", "left", "right");
|
|
|
|
$table->size = array("", "", "", "");
|
|
|
|
}
|
2003-09-10 05:02:39 +00:00
|
|
|
} else { // No grades are being used
|
|
|
|
$table->head = array($strattempt, $strtimetaken, $strtimecompleted);
|
|
|
|
$table->align = array("center", "center", "left");
|
2003-09-10 14:00:18 +00:00
|
|
|
$table->size = array("", "", "");
|
2003-09-10 05:02:39 +00:00
|
|
|
}
|
2002-10-06 03:23:34 +00:00
|
|
|
foreach ($attempts as $attempt) {
|
2002-10-22 06:52:23 +00:00
|
|
|
if ($timetaken = ($attempt->timefinish - $attempt->timestart)) {
|
|
|
|
$timetaken = format_time($timetaken);
|
|
|
|
} else {
|
|
|
|
$timetaken = "-";
|
|
|
|
}
|
2004-12-29 09:22:33 +00:00
|
|
|
if ($quiz->grade and $quiz->sumgrades) {
|
2005-02-15 01:39:12 +00:00
|
|
|
$attemptmark = '';
|
2005-02-14 19:41:52 +00:00
|
|
|
$attemptgrade = format_float(($attempt->sumgrades/$quiz->sumgrades)*$quiz->grade,$quiz->decimalpoints);
|
2003-09-10 05:02:39 +00:00
|
|
|
if ($attemptgrade == $mygrade) {
|
2004-09-12 17:34:35 +00:00
|
|
|
$attemptgrade = "<span class=\"highlight\">$attemptgrade</span>";
|
2003-09-10 05:02:39 +00:00
|
|
|
}
|
2005-01-02 07:15:19 +00:00
|
|
|
if (quiz_review_allowed($quiz)) {
|
2005-02-11 19:51:29 +00:00
|
|
|
$attemptmark = "<a href=\"review.php?q=$quiz->id&attempt=$attempt->id\">$attempt->sumgrades</a>";
|
2004-09-16 17:13:57 +00:00
|
|
|
$attemptgrade = "<a href=\"review.php?q=$quiz->id&attempt=$attempt->id\">$attemptgrade</a>";
|
2005-01-02 07:15:19 +00:00
|
|
|
$attempt->attempt = "<a href=\"review.php?q=$quiz->id&attempt=$attempt->id\">#$attempt->attempt</a>";
|
2003-09-10 05:02:39 +00:00
|
|
|
}
|
2005-02-11 19:51:29 +00:00
|
|
|
if ($quiz->grade <> $quiz->sumgrades) {
|
|
|
|
$table->data[] = array( $attempt->attempt,
|
|
|
|
format_time($attempt->timefinish - $attempt->timestart),
|
|
|
|
userdate($attempt->timefinish),
|
|
|
|
$attemptmark, $attemptgrade);
|
|
|
|
} else {
|
|
|
|
$table->data[] = array( $attempt->attempt,
|
|
|
|
format_time($attempt->timefinish - $attempt->timestart),
|
|
|
|
userdate($attempt->timefinish),
|
|
|
|
$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)) {
|
|
|
|
$attempt->attempt = "<a href=\"review.php?q=$quiz->id&attempt=$attempt->id\">#$attempt->attempt</a>";
|
2003-09-10 05:02:39 +00:00
|
|
|
}
|
|
|
|
$table->data[] = array( $attempt->attempt,
|
|
|
|
format_time($attempt->timefinish - $attempt->timestart),
|
|
|
|
userdate($attempt->timefinish));
|
2003-01-01 14:47:11 +00:00
|
|
|
}
|
2002-10-06 03:23:34 +00:00
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
}
|
|
|
|
|
2002-10-21 13:13:33 +00:00
|
|
|
if ($available) {
|
2004-06-21 12:36:13 +00:00
|
|
|
if ($quiz->timelimit) {
|
|
|
|
echo "<p align=\"center\">".get_string("quiztimelimit","quiz", format_time($quiz->timelimit * 60))."</p>";
|
|
|
|
}
|
2004-06-02 18:03:05 +00:00
|
|
|
echo "<p align=\"center\">".get_string("quizavailable", "quiz", userdate($quiz->timeclose));
|
2002-10-21 13:13:33 +00:00
|
|
|
} else if ($timenow < $quiz->timeopen) {
|
2004-06-02 18:03:05 +00:00
|
|
|
echo "<p align=\"center\">".get_string("quiznotavailable", "quiz", userdate($quiz->timeopen));
|
2002-10-21 13:13:33 +00:00
|
|
|
} else {
|
2004-06-02 18:03:05 +00:00
|
|
|
echo "<p align=\"center\">".get_string("quizclosed", "quiz", userdate($quiz->timeclose));
|
2002-10-21 13:13:33 +00:00
|
|
|
}
|
|
|
|
|
2002-10-06 03:23:34 +00:00
|
|
|
|
2002-10-15 12:54:11 +00:00
|
|
|
if (!$quiz->questions) {
|
|
|
|
print_heading(get_string("noquestions", "quiz"));
|
|
|
|
} else {
|
|
|
|
if ($numattempts < $quiz->attempts or !$quiz->attempts) {
|
|
|
|
if ($available) {
|
|
|
|
$options["id"] = $cm->id;
|
2003-09-10 05:02:39 +00:00
|
|
|
if ($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
|
|
|
}
|
2004-06-02 18:03:05 +00:00
|
|
|
$strconfirmstartattempt = addslashes(get_string("confirmstartattempt","quiz"));
|
|
|
|
echo "<br />";
|
2004-11-11 12:07:08 +00:00
|
|
|
echo "</p>";
|
2004-06-02 18:03:05 +00:00
|
|
|
echo "<div align=\"center\">";
|
2004-12-16 08:05:23 +00:00
|
|
|
|
|
|
|
include("view_js.php");
|
|
|
|
|
2004-06-02 18:03:05 +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"));
|
2003-09-10 05:02:39 +00:00
|
|
|
if ($quiz->grade) {
|
|
|
|
print_heading(get_string("yourfinalgradeis", "quiz", "$mygrade / $quiz->grade"));
|
|
|
|
}
|
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-01-02 07:15:19 +00:00
|
|
|
|
|
|
|
function quiz_review_allowed($quiz) {
|
|
|
|
if (!$quiz->review) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ((time() < $quiz->timeclose) and ($quiz->review == QUIZ_REVIEW_AFTER)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ((time() > $quiz->timeclose) and ($quiz->review == QUIZ_REVIEW_BEFORE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2002-10-04 02:59:05 +00:00
|
|
|
|
|
|
|
?>
|