MDL-64506 templates: Move BS2 btns' to BS4 btns'
[moodle.git] / mod / feedback / view.php
CommitLineData
84973212 1<?php
9c5bc7a5
AG
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.
13//
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/>.
c70ad9f7 16
84973212 17/**
18 * the first page to view the feedback
19 *
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9714baa1 22 * @package mod_feedback
84973212 23 */
97d71cbc
MG
24require_once(__DIR__ . '/../../config.php');
25require_once($CFG->dirroot . '/mod/feedback/lib.php');
84973212 26
27$id = required_param('id', PARAM_INT);
28$courseid = optional_param('courseid', false, PARAM_INT);
29
84973212 30$current_tab = 'view';
31
97d71cbc
MG
32list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
33require_course_login($course, true, $cm);
34$feedback = $PAGE->activityrecord;
84973212 35
97d71cbc 36$feedbackcompletion = new mod_feedback_completion($feedback, $cm, $courseid);
84973212 37
2c979976 38$context = context_module::instance($cm->id);
c987dbad 39
2a94a2f6 40if ($course->id == SITEID) {
2a94a2f6
MG
41 $PAGE->set_pagelayout('incourse');
42}
ed724aac 43$PAGE->set_url('/mod/feedback/view.php', array('id' => $cm->id));
2a94a2f6
MG
44$PAGE->set_title($feedback->name);
45$PAGE->set_heading($course->fullname);
46
97d71cbc
MG
47// Check access to the given courseid.
48if ($courseid AND $courseid != SITEID) {
49 require_course_login(get_course($courseid)); // This overwrites the object $COURSE .
2a94a2f6
MG
50}
51
97d71cbc
MG
52// Check whether the feedback is mapped to the given courseid.
53if (!has_capability('mod/feedback:edititems', $context) &&
54 !$feedbackcompletion->check_course_is_mapped()) {
55 echo $OUTPUT->header();
56 echo $OUTPUT->notification(get_string('cannotaccess', 'mod_feedback'));
57 echo $OUTPUT->footer();
58 exit;
84973212 59}
60
3f6fd941 61// Trigger module viewed event.
f4dba175 62$feedbackcompletion->trigger_module_viewed();
84973212 63
64/// Print the page header
84973212 65echo $OUTPUT->header();
66
84973212 67/// Print the main part of the page
68///////////////////////////////////////////////////////////////////////////
69///////////////////////////////////////////////////////////////////////////
70///////////////////////////////////////////////////////////////////////////
71
38b5a5e2 72$previewimg = $OUTPUT->pix_icon('t/preview', get_string('preview'));
846cebe5 73$previewlnk = new moodle_url('/mod/feedback/print.php', array('id' => $id));
4832a0b3
MG
74if ($courseid) {
75 $previewlnk->param('courseid', $courseid);
76}
846cebe5 77$preview = html_writer::link($previewlnk, $previewimg);
84973212 78
846cebe5
RW
79echo $OUTPUT->heading(format_string($feedback->name) . $preview);
80
81// Print the tabs.
82require('tabs.php');
38b5a5e2 83
ed724aac
MG
84// Show description.
85echo $OUTPUT->box_start('generalbox feedback_description');
86$options = (object)array('noclean' => true);
87echo format_module_intro('feedback', $feedback, $cm->id);
88echo $OUTPUT->box_end();
89
38b5a5e2 90//show some infos to the feedback
9c5bc7a5 91if (has_capability('mod/feedback:edititems', $context)) {
ed724aac
MG
92
93 echo $OUTPUT->heading(get_string('overview', 'feedback'), 3);
94
38b5a5e2 95 //get the groupid
9c5bc7a5 96 $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id, true);
38b5a5e2
AG
97 $mygroupid = groups_get_activity_group($cm);
98
38b5a5e2 99 echo $groupselect.'<div class="clearer">&nbsp;</div>';
1e3de9d8
MG
100 $summary = new mod_feedback\output\summary($feedbackcompletion, $mygroupid, true);
101 echo $OUTPUT->render_from_template('mod_feedback/summary', $summary->export_for_template($OUTPUT));
abd2899c 102
97d71cbc
MG
103 if ($pageaftersubmit = $feedbackcompletion->page_after_submit()) {
104 echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 3);
105 echo $OUTPUT->box($pageaftersubmit, 'generalbox feedback_after_submit');
106 }
84973212 107}
c70ad9f7 108
ed724aac 109if (!has_capability('mod/feedback:viewreports', $context) &&
97d71cbc 110 $feedbackcompletion->can_view_analysis()) {
ed724aac
MG
111 $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id' => $id));
112 echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
113 echo get_string('completed_feedbacks', 'feedback').'</a>';
114 echo '</div>';
84973212 115}
c70ad9f7 116
ed724aac
MG
117if (has_capability('mod/feedback:mapcourse', $context) && $feedback->course == SITEID) {
118 echo $OUTPUT->box_start('generalbox feedback_mapped_courses');
119 echo $OUTPUT->heading(get_string("mappedcourses", "feedback"), 3);
120 echo '<p>' . get_string('mapcourse_help', 'feedback') . '</p>';
121 $mapurl = new moodle_url('/mod/feedback/mapcourse.php', array('id' => $id));
122 echo '<p class="mdl-align">' . html_writer::link($mapurl, get_string('mapcourses', 'feedback')) . '</p>';
123 echo $OUTPUT->box_end();
84973212 124}
9c5bc7a5 125
97d71cbc
MG
126if ($feedbackcompletion->can_complete()) {
127 echo $OUTPUT->box_start('generalbox boxaligncenter');
128 if (!$feedbackcompletion->is_open()) {
129 // Feedback is not yet open or is already closed.
846cebe5 130 echo $OUTPUT->notification(get_string('feedback_is_not_open', 'feedback'));
97d71cbc
MG
131 echo $OUTPUT->continue_button(course_get_url($courseid ?: $course->id));
132 } else if ($feedbackcompletion->can_submit()) {
133 // Display a link to complete feedback or resume.
134 $completeurl = new moodle_url('/mod/feedback/complete.php',
135 ['id' => $id, 'courseid' => $courseid]);
136 if ($startpage = $feedbackcompletion->get_resume_page()) {
137 $completeurl->param('gopage', $startpage);
138 $label = get_string('continue_the_form', 'feedback');
9c5bc7a5 139 } else {
97d71cbc 140 $label = get_string('complete_the_form', 'feedback');
84973212 141 }
29551c4b 142 echo html_writer::div(html_writer::link($completeurl, $label, array('class' => 'btn btn-secondary')), 'complete-feedback');
9c5bc7a5 143 } else {
97d71cbc 144 // Feedback was already submitted.
846cebe5 145 echo $OUTPUT->notification(get_string('this_feedback_is_already_submitted', 'feedback'));
97d71cbc 146 $OUTPUT->continue_button(course_get_url($courseid ?: $course->id));
c70ad9f7 147 }
84973212 148 echo $OUTPUT->box_end();
149}
c70ad9f7 150
84973212 151echo $OUTPUT->footer();
c70ad9f7 152