Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / quiz / index.php
blobd7d53c4ebd11063d164446e447c07b9b5a91063d
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 */
10 require_once("../../config.php");
11 require_once("locallib.php");
13 $id = required_param('id', PARAM_INT);
14 if (!$course = get_record("course", "id", $id)) {
15 error("Course ID is incorrect");
17 $coursecontext = get_context_instance(CONTEXT_COURSE, $id);
18 require_login($course->id);
19 add_to_log($course->id, "quiz", "view all", "index.php?id=$course->id", "");
21 // Print the header
22 $strquizzes = get_string("modulenameplural", "quiz");
23 $streditquestions = '';
24 if (has_capability('moodle/question:manage', $coursecontext)) {
25 $streditquestions =
26 "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/question/edit.php\">
27 <div>
28 <input type=\"hidden\" name=\"courseid\" value=\"$course->id\" />
29 <input type=\"submit\" value=\"".get_string("editquestions", "quiz")."\" />
30 </div>
31 </form>";
33 $navlinks = array();
34 $navlinks[] = array('name' => $strquizzes, 'link' => '', 'type' => 'activity');
35 $navigation = build_navigation($navlinks);
37 print_header_simple($strquizzes, '', $navigation,
38 '', '', true, $streditquestions, navmenu($course));
40 // Get all the appropriate data
41 if (!$quizzes = get_all_instances_in_course("quiz", $course)) {
42 notice("There are no quizzes", "../../course/view.php?id=$course->id");
43 die;
46 // Configure table for displaying the list of instances.
47 $headings = array(get_string('name'), get_string('quizcloses', 'quiz'));
48 $align = array('left', 'left');
49 $colsize = array('', '');
50 if ($course->format == "weeks") {
51 array_unshift($headings, get_string('week'));
52 array_unshift($align, 'center');
53 array_unshift($colsize, 10);
54 } else if ($course->format == "topics") {
55 array_unshift($headings, get_string('topic'));
56 array_unshift($align, 'center');
57 array_unshift($colsize, 10);
60 if (has_capability('mod/quiz:viewreports', $coursecontext)) {
61 array_push($headings, get_string('attempts', 'quiz'));
62 array_push($align, 'left');
63 array_push($colsize, '');
64 $showing = 'stats';
65 } else if (has_capability('mod/quiz:attempt', $coursecontext)) {
66 array_push($headings, get_string('bestgrade', 'quiz'), get_string('feedback', 'quiz'));
67 array_push($align, 'left', 'left');
68 array_push($colsize, '', '');
69 $showing = 'scores';
72 $table->head = $headings;
73 $table->align = $align;
74 $table->size = $colsize;
76 // Poplate the table with the list of instances.
77 $currentsection = '';
78 foreach ($quizzes as $quiz) {
80 $cm = get_coursemodule_from_instance('quiz', $quiz->id);
81 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
82 $data = array();
84 // Section number if necessary.
85 $strsection = '';
86 if ($course->format == "weeks" or $course->format == "topics") {
87 if ($quiz->section !== $currentsection) {
88 if ($quiz->section) {
89 $strsection = $quiz->section;
91 if ($currentsection !== "") {
92 $table->data[] = 'hr';
94 $currentsection = $quiz->section;
97 $data[] = $strsection;
99 // Link to the instance.
100 $class = '';
101 if (!$quiz->visible) {
102 $class = ' class="dimmed"';
104 $data[] = "<a$class href=\"view.php?id=$quiz->coursemodule\">" . format_string($quiz->name, true) . '</a>';
106 // Close date.
107 if ($quiz->timeclose) {
108 $data[] = userdate($quiz->timeclose);
109 } else {
110 $data[] = '';
113 if ($showing == 'stats') {
115 // Number of students who have attempted this quiz.
116 if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) {
117 $a->studentnum = count_records_select('quiz_attempts',
118 "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
119 $a->studentstring = $course->students;
120 $data[] = "<a href=\"report.php?mode=overview&amp;q=$quiz->id\">" .
121 get_string('numattempts', 'quiz', $a) . '</a>';
123 } else if ($showing = 'scores') {
125 // Grade and feedback.
126 $bestgrade = quiz_get_best_grade($quiz, $USER->id);
127 $attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'all');
128 list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);
130 $grade = '';
131 $feedback = '';
132 if ($quiz->grade && !is_null($bestgrade)) {
133 if ($alloptions->scores) {
134 $grade = "$bestgrade / $quiz->grade";
136 if ($alloptions->overallfeedback) {
137 $feedback = quiz_feedback_for_grade($bestgrade, $quiz->id);
140 $data[] = $grade;
141 $data[] = $feedback;
144 $table->data[] = $data;
145 } // End of loop over quiz instances.
147 // Display the table.
148 echo '<br />';
149 print_table($table);
151 // Finish the page
152 print_footer($course);