file ongoing.html was added on branch MOODLE_15_STABLE on 2005-07-07 16:14:36 +0000
[moodle.git] / mod / quiz / index.php
blobe7a4d09bcf34ac91291e9f0c65a9c31d1a5a7ee7
1 <?php // $Id$
2 /**
3 * This page lists all the instances of quiz in a particular course
5 * @version $Id$
6 * @author Martin Dougiamas and many others.
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package quiz
9 */
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", "");
25 // Print the header
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>"
36 : "";
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");
46 die;
49 // Print the list of instances (your module will probably extend this)
51 $timenow = time();
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;
62 } else {
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, "", "", "");
74 } else {
75 $table->head = array ($strname, $strquizcloses, $gradecol);
76 $table->align = array ("left", "left", "left");
77 $table->size = array ("", "", "");
80 $currentsection = "";
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>";
86 } else {
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);
93 $printsection = "";
94 if ($quiz->section !== $currentsection) {
95 if ($quiz->section) {
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&amp;q=$quiz->id\">$strviewallreports ($usercount $strusers)</a>";
111 } else {
112 $answercount = 0;
113 $gradecol = "";
115 } else {
116 if ($bestgrade === NULL || $quiz->grade == 0) {
117 $gradecol = "";
118 } else {
119 $gradecol = "$bestgrade / $quiz->grade";
123 if ($course->format == "weeks" or $course->format == "topics") {
124 $table->data[] = array ($printsection, $link, $closequiz, $gradecol);
125 } else {
126 $table->data[] = array ($link, $closequiz, $gradecol);
130 echo "<br />";
132 print_table($table);
134 // Finish the page
136 print_footer($course);