3 * This page lists all the instances of quiz in a particular course
6 * @author Martin Dougiamas and many others.
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 require_once("../../config.php");
12 require_once("locallib.php");
14 require_variable($id); // course
16 if (! $course = get_record("course", "id", $id)) {
17 error("Course ID is incorrect");
20 require_login($course->id
);
22 add_to_log($course->id
, "quiz", "view all", "index.php?id=$course->id", "");
27 $strquizzes = get_string("modulenameplural", "quiz");
28 $streditquestions = isteacheredit($course->id
)
29 ?
"<form target=\"_parent\" method=\"get\" "
30 ." action=\"$CFG->wwwroot/mod/quiz/edit.php\">"
31 ."<input type=\"hidden\" name=\"courseid\" "
32 ." value=\"$course->id\" />"
33 ."<input type=\"submit\" "
34 ." value=\"".get_string("editquestions", "quiz")."\" /></form>"
37 $strquiz = get_string("modulename", "quiz");
39 print_header_simple("$strquizzes", "", "$strquizzes",
40 "", "", true, $streditquestions, navmenu($course));
42 // Get all the appropriate data
44 if (! $quizzes = get_all_instances_in_course("quiz", $course)) {
45 notice("There are no quizzes", "../../course/view.php?id=$course->id");
49 // Print the list of instances (your module will probably extend this)
52 $strname = get_string("name");
53 $strweek = get_string("week");
54 $strtopic = get_string("topic");
55 $strbestgrade = get_string("bestgrade", "quiz");
56 $strquizcloses = get_string("quizcloses", "quiz");
57 $strattempts = get_string("attempts", "quiz");
58 $strusers = $course->students
;
60 if (isteacher($course->id
)) {
61 $gradecol = $strattempts;
63 $gradecol = $strbestgrade;
66 if ($course->format
== "weeks") {
67 $table->head
= array ($strweek, $strname, $strquizcloses, $gradecol);
68 $table->align
= array ("center", "left", "left", "left");
69 $table->size
= array (10, "", "", "");
70 } else if ($course->format
== "topics") {
71 $table->head
= array ($strtopic, $strname, $strquizcloses, $gradecol);
72 $table->align
= array ("center", "left", "left", "left");
73 $table->size
= array (10, "", "", "");
75 $table->head
= array ($strname, $strquizcloses, $gradecol);
76 $table->align
= array ("left", "left", "left");
77 $table->size
= array ("", "", "");
82 foreach ($quizzes as $quiz) {
83 if (!$quiz->visible
) {
84 //Show dimmed if the mod is hidden
85 $link = "<a class=\"dimmed\" href=\"view.php?id=$quiz->coursemodule\">".format_string($quiz->name
,true)."</a>";
87 //Show normal if the mod is visible
88 $link = "<a href=\"view.php?id=$quiz->coursemodule\">".format_string($quiz->name
,true)."</a>";
91 $bestgrade = quiz_get_best_grade($quiz, $USER->id
);
94 if ($quiz->section
!== $currentsection) {
96 $printsection = $quiz->section
;
98 if ($currentsection !== "") {
99 $table->data
[] = 'hr';
101 $currentsection = $quiz->section
;
104 $closequiz = userdate($quiz->timeclose
);
106 if (isteacher($course->id
)) {
107 if ($usercount = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)')) {
108 $attemptcount = count_records('quiz_attempts', 'quiz', $quiz->id
, 'preview', 0);
109 $strviewallreports = get_string('viewallreports', 'quiz', $attemptcount);
110 $gradecol = "<a href=\"report.php?mode=overview&q=$quiz->id\">$strviewallreports ($usercount $strusers)</a>";
116 if ($bestgrade === NULL ||
$quiz->grade
== 0) {
119 $gradecol = "$bestgrade / $quiz->grade";
123 if ($course->format
== "weeks" or $course->format
== "topics") {
124 $table->data
[] = array ($printsection, $link, $closequiz, $gradecol);
126 $table->data
[] = array ($link, $closequiz, $gradecol);
136 print_footer($course);