MDL-80880 quiz: change display of previous attempts summary
[moodle.git] / mod / feedback / complete.php
blobca50e27e35e952eb24a929f1301492677dc14c03
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * prints the form so the user can fill out the feedback
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package mod_feedback
25 require_once("../../config.php");
26 require_once("lib.php");
28 feedback_init_feedback_session();
30 $id = required_param('id', PARAM_INT);
31 $courseid = optional_param('courseid', null, PARAM_INT);
32 $gopage = optional_param('gopage', 0, PARAM_INT);
33 $gopreviouspage = optional_param('gopreviouspage', null, PARAM_RAW);
35 list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
36 $feedback = $DB->get_record("feedback", array("id" => $cm->instance), '*', MUST_EXIST);
38 $urlparams = array('id' => $cm->id, 'gopage' => $gopage, 'courseid' => $courseid);
39 $PAGE->set_url('/mod/feedback/complete.php', $urlparams);
41 require_course_login($course, true, $cm);
42 $PAGE->set_activity_record($feedback);
44 $context = context_module::instance($cm->id);
45 $feedbackcompletion = new mod_feedback_completion($feedback, $cm, $courseid);
47 $courseid = $feedbackcompletion->get_courseid();
49 // Check whether the feedback is mapped to the given courseid.
50 if (!has_capability('mod/feedback:edititems', $context) &&
51 !$feedbackcompletion->check_course_is_mapped()) {
52 echo $OUTPUT->header();
53 echo $OUTPUT->notification(get_string('cannotaccess', 'mod_feedback'));
54 echo $OUTPUT->footer();
55 exit;
58 //check whether the given courseid exists
59 if ($courseid AND $courseid != SITEID) {
60 require_course_login(get_course($courseid)); // This overwrites the object $COURSE .
63 if (!$feedbackcompletion->can_complete()) {
64 throw new \moodle_exception('error');
67 $PAGE->navbar->add(get_string('feedback:complete', 'feedback'));
68 $PAGE->set_heading($course->fullname);
69 $PAGE->set_title($feedback->name);
70 $PAGE->set_pagelayout('incourse');
71 $PAGE->set_secondary_active_tab('modulepage');
72 $PAGE->add_body_class('limitedwidth');
74 // Check if the feedback is open (timeopen, timeclose).
75 if (!$feedbackcompletion->is_open()) {
76 echo $OUTPUT->header();
77 echo $OUTPUT->box_start('generalbox boxaligncenter');
78 echo $OUTPUT->notification(get_string('feedback_is_not_open', 'feedback'));
79 echo $OUTPUT->continue_button(course_get_url($courseid ?: $feedback->course));
80 echo $OUTPUT->box_end();
81 echo $OUTPUT->footer();
82 exit;
85 // Mark activity viewed for completion-tracking.
86 if (isloggedin() && !isguestuser()) {
87 $feedbackcompletion->set_module_viewed();
90 // Check if user is prevented from re-submission.
91 $cansubmit = $feedbackcompletion->can_submit();
93 // Initialise the form processing feedback completion.
94 if (!$feedbackcompletion->is_empty() && $cansubmit) {
95 // Process the page via the form.
96 $urltogo = $feedbackcompletion->process_page($gopage, $gopreviouspage);
98 if ($urltogo !== null) {
99 redirect($urltogo);
103 // Print the page header.
104 $strfeedbacks = get_string("modulenameplural", "feedback");
105 $strfeedback = get_string("modulename", "feedback");
107 echo $OUTPUT->header();
109 if ($feedbackcompletion->is_empty()) {
110 \core\notification::error(get_string('no_items_available_yet', 'feedback'));
111 } else if ($cansubmit) {
112 if ($feedbackcompletion->just_completed()) {
113 // Display information after the submit.
114 if ($feedback->page_after_submit) {
115 echo $OUTPUT->box($feedbackcompletion->page_after_submit(),
116 'generalbox boxaligncenter');
118 if (!$PAGE->has_secondary_navigation() && $feedbackcompletion->can_view_analysis()) {
119 echo '<p class="text-center">';
120 $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id' => $cm->id, 'courseid' => $courseid));
121 echo html_writer::link($analysisurl, get_string('completed_feedbacks', 'feedback'));
122 echo '</p>';
125 if ($feedback->site_after_submit) {
126 $url = feedback_encode_target_url($feedback->site_after_submit);
127 } else {
128 $url = course_get_url($courseid ?: $course->id);
130 echo $OUTPUT->continue_button($url);
131 } else {
132 // Display the form with the questions.
133 echo $feedbackcompletion->render_items();
135 } else {
136 echo $OUTPUT->box_start('generalbox boxaligncenter');
137 echo $OUTPUT->notification(get_string('this_feedback_is_already_submitted', 'feedback'));
138 echo $OUTPUT->continue_button(course_get_url($courseid ?: $course->id));
139 echo $OUTPUT->box_end();
142 echo $OUTPUT->footer();