libdir.'/blocklib.php'); require_once('pagelib.php'); $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or $q = optional_param('q', 0, PARAM_INT); // quiz ID $edit = optional_param('edit', ''); if ($id) { if (! $cm = get_record("course_modules", "id", $id)) { error("There is no coursemodule with id $id"); } if (! $course = get_record("course", "id", $cm->course)) { error("Course is misconfigured"); } if (! $quiz = get_record("quiz", "id", $cm->instance)) { error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing"); } } else { if (! $quiz = get_record("quiz", "id", $q)) { error("There is no quiz with id $q"); } if (! $course = get_record("course", "id", $quiz->course)) { error("The course with id $quiz->course that the quiz with id $q belongs to is missing"); } if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) { error("The course module for the quiz with id $q is missing"); } } require_login($course->id, false, $cm); $isteacher = isteacher($course->id); // 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); } add_to_log($course->id, "quiz", "view", "view.php?id=$cm->id", $quiz->id, $cm->id); $timenow = time(); // Initialize $PAGE, compute blocks $PAGE = page_create_instance($quiz->id); $pageblocks = blocks_setup($PAGE); $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210); // Print the page header if (!empty($edit) && $PAGE->user_allowed_editing()) { if ($edit == 'on') { $USER->editing = true; } else if ($edit == 'off') { $USER->editing = false; } } $PAGE->print_header($course->shortname.': %fullname%'); echo '
'; blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); echo ' | '; } echo '';
$available = ($quiz->timeopen < $timenow and ($timenow < $quiz->timeclose or !$quiz->timeclose)) || $isteacher;
// Print the main part of the page
// Print heading and tabs for teacher
if ($isteacher) {
$currenttab = 'info';
include('tabs.php');
}
print_heading(format_string($quiz->name));
if (trim(strip_tags($quiz->intro))) {
print_simple_box(format_text($quiz->intro), "center");
}
if ($quiz->attempts > 1) {
echo " ".get_string("attemptsallowed", "quiz").": $quiz->attempts "; echo "".get_string("grademethod", "quiz").": ".$QUIZ_GRADE_METHOD[$quiz->grademethod]." "; } else { echo ""; } if ($available) { if ($quiz->timelimit) { echo " ".get_string("quiztimelimit","quiz", format_time($quiz->timelimit * 60))." "; } quiz_view_dates($quiz); } else if ($timenow < $quiz->timeopen) { echo "".get_string("quiznotavailable", "quiz", userdate($quiz->timeopen)); } else { echo " ".get_string("quizclosed", "quiz", userdate($quiz->timeclose)); } // This is all the teacher will get if ($isteacher) { if ($attemptcount = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) { $strviewallanswers = get_string("viewallanswers", "quiz", $attemptcount); $usercount = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)'); $strusers = $course->students; notify("id\">$strviewallanswers ($usercount $strusers)"); } echo ' |