MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / quiz / index.php
blobe3bed8b6d50cea4fd136478ccd18e8433070ad3b
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 $editqcontexts = new question_edit_contexts($coursecontext);
25 if ($editqcontexts->have_one_edit_tab_cap('questions')) {
26 $streditquestions =
27 "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/question/edit.php\">
28 <div>
29 <input type=\"hidden\" name=\"courseid\" value=\"$course->id\" />
30 <input type=\"submit\" value=\"".get_string("editquestions", "quiz")."\" />
31 </div>
32 </form>";
34 $navlinks = array();
35 $navlinks[] = array('name' => $strquizzes, 'link' => '', 'type' => 'activity');
36 $navigation = build_navigation($navlinks);
38 print_header_simple($strquizzes, '', $navigation,
39 '', '', true, $streditquestions, navmenu($course));
41 // Get all the appropriate data
42 if (!$quizzes = get_all_instances_in_course("quiz", $course)) {
43 notice("There are no quizzes", "../../course/view.php?id=$course->id");
44 die;
47 // Configure table for displaying the list of instances.
48 $headings = array(get_string('name'), get_string('quizcloses', 'quiz'));
49 $align = array('left', 'left');
50 $colsize = array('', '');
51 if ($course->format == "weeks" || $course->format == "weekscss") {
52 array_unshift($headings, get_string('week'));
53 array_unshift($align, 'center');
54 array_unshift($colsize, 10);
55 } else if ($course->format == "topics") {
56 array_unshift($headings, get_string('topic'));
57 array_unshift($align, 'center');
58 array_unshift($colsize, 10);
61 if (has_capability('mod/quiz:viewreports', $coursecontext)) {
62 array_push($headings, get_string('attempts', 'quiz'));
63 array_push($align, 'left');
64 array_push($colsize, '');
65 $showing = 'stats';
66 } else if (has_capability('mod/quiz:attempt', $coursecontext)) {
67 array_push($headings, get_string('bestgrade', 'quiz'), get_string('feedback', 'quiz'));
68 array_push($align, 'left', 'left');
69 array_push($colsize, '', '');
70 $showing = 'scores';
73 $table->head = $headings;
74 $table->align = $align;
75 $table->size = $colsize;
77 // Poplate the table with the list of instances.
78 $currentsection = '';
79 foreach ($quizzes as $quiz) {
81 $cm = get_coursemodule_from_instance('quiz', $quiz->id);
82 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
83 $data = array();
85 // Section number if necessary.
86 $strsection = '';
87 if ($course->format == "weeks" || $course->format == "weekscss" || $course->format == "topics") {
88 if ($quiz->section !== $currentsection) {
89 if ($quiz->section) {
90 $strsection = $quiz->section;
92 if ($currentsection !== "") {
93 $table->data[] = 'hr';
95 $currentsection = $quiz->section;
98 $data[] = $strsection;
100 // Link to the instance.
101 $class = '';
102 if (!$quiz->visible) {
103 $class = ' class="dimmed"';
105 $data[] = "<a$class href=\"view.php?id=$quiz->coursemodule\">" . format_string($quiz->name, true) . '</a>';
107 // Close date.
108 if ($quiz->timeclose) {
109 $data[] = userdate($quiz->timeclose);
110 } else {
111 $data[] = '';
114 if ($showing == 'stats') {
116 // Number of students who have attempted this quiz.
117 if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) {
118 $a->studentnum = count_records_select('quiz_attempts',
119 "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
120 $a->studentstring = $course->students;
121 $data[] = "<a href=\"report.php?mode=overview&amp;q=$quiz->id\">" .
122 get_string('numattempts', 'quiz', $a) . '</a>';
123 } else {
124 $data[] = '';
126 } else if ($showing = 'scores') {
128 // Grade and feedback.
129 $bestgrade = quiz_get_best_grade($quiz, $USER->id);
130 $attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'all');
131 list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);
133 $grade = '';
134 $feedback = '';
135 if ($quiz->grade && !is_null($bestgrade)) {
136 if ($alloptions->scores) {
137 $grade = "$bestgrade / $quiz->grade";
139 if ($alloptions->overallfeedback) {
140 $feedback = quiz_feedback_for_grade($bestgrade, $quiz->id);
143 $data[] = $grade;
144 $data[] = $feedback;
147 $table->data[] = $data;
148 } // End of loop over quiz instances.
150 // Display the table.
151 echo '<br />';
152 print_table($table);
154 // Finish the page
155 print_footer($course);