-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.php
executable file
·116 lines (98 loc) · 3.77 KB
/
preview.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This page displays a non-completable instance of questionnaire.
require_once("../../config.php");
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
$id = optional_param('id', 0, PARAM_INT);
$sid = optional_param('sid', 0, PARAM_INT);
$popup = optional_param('popup', 0, PARAM_INT);
$qid = optional_param('qid', 0, PARAM_INT);
if ($id) {
if (! $cm = get_coursemodule_from_id('questionnaire', $id)) {
print_error('invalidcoursemodule');
}
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
print_error('coursemisconf');
}
if (! $questionnaire = $DB->get_record("questionnaire", array("id" => $cm->instance))) {
print_error('invalidcoursemodule');
}
} else {
if (! $survey = $DB->get_record("questionnaire_survey", array("id" => $sid))) {
print_error('surveynotexists', 'questionnaire');
}
if (! $course = $DB->get_record("course", array("id" => $survey->owner))) {
print_error('coursemisconf');
}
// Dummy questionnaire object.
$questionnaire = new Object();
$questionnaire->id = 0;
$questionnaire->course = $course->id;
$questionnaire->name = $survey->title;
$questionnaire->sid = $sid;
$questionnaire->resume = 0;
// Dummy cm object.
if (!empty($qid)) {
$cm = get_coursemodule_from_instance('questionnaire', $qid, $course->id);
} else {
$cm = false;
}
}
// Check login and get context.
require_login($course->id, false, $cm);
$context = $cm ? context_module::instance($cm->id) : false;
$url = new moodle_url('/mod/questionnaire/preview.php');
if ($id !== 0) {
$url->param('id', $id);
}
if ($sid) {
$url->param('sid', $sid);
}
$PAGE->set_url($url);
if (!$popup) {
$PAGE->set_context($context);
}
$questionnaire = new questionnaire($qid, $questionnaire, $course, $cm);
$owner = (trim($questionnaire->survey->owner) == trim($course->id));
$canpreview = (!isset($questionnaire->capabilities) &&
has_capability('mod/questionnaire:preview', context_course::instance($course->id))) ||
(isset($questionnaire->capabilities) && $questionnaire->capabilities->preview && $owner);
if (!$canpreview) {
// Should never happen, unless called directly by a snoop...
print_error('nopermissions', 'questionnaire', $CFG->wwwroot.'/mod/questionnaire/view.php?id='.$cm->id);
}
$SESSION->questionnaire = new stdClass();
$SESSION->questionnaire->current_tab = new stdClass();
$SESSION->questionnaire->current_tab = 'preview';
$qp = get_string('preview_questionnaire', 'questionnaire');
$pq = get_string('previewing', 'questionnaire');
// Print the page header.
if ($popup) {
$PAGE->set_pagelayout('popup');
}
$PAGE->set_title(format_string($qp));
if (!$popup) {
$PAGE->set_heading(format_string($course->fullname));
}
// Include the needed js.
$PAGE->requires->js('/mod/questionnaire/module.js');
echo $OUTPUT->header();
echo $OUTPUT->heading($pq);
$questionnaire->survey_print_render('', 'preview', $course->id, $rid = 0, $popup);
if ($popup) {
echo $OUTPUT->close_window_button();
}
echo $OUTPUT->footer($course);