1 |
efrain |
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.
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* This page displays a non-completable instance of questionnaire.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_questionnaire
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
* @copyright 2016 onward Mike Churchward (mike.churchward@poetgroup.org)
|
|
|
23 |
* @author Mike Churchward
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
require_once("../../config.php");
|
|
|
27 |
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
|
|
|
28 |
|
|
|
29 |
$id = optional_param('id', 0, PARAM_INT);
|
|
|
30 |
$sid = optional_param('sid', 0, PARAM_INT);
|
|
|
31 |
$popup = optional_param('popup', 0, PARAM_INT);
|
|
|
32 |
$qid = optional_param('qid', 0, PARAM_INT);
|
|
|
33 |
$currentgroupid = optional_param('group', 0, PARAM_INT); // Groupid.
|
|
|
34 |
|
|
|
35 |
if ($id) {
|
|
|
36 |
if (! $cm = get_coursemodule_from_id('questionnaire', $id)) {
|
|
|
37 |
throw new \moodle_exception('invalidcoursemodule', 'mod_questionnaire');
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
|
|
|
41 |
throw new \moodle_exception('coursemisconf', 'mod_questionnaire');
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
if (! $questionnaire = $DB->get_record("questionnaire", array("id" => $cm->instance))) {
|
|
|
45 |
throw new \moodle_exception('invalidcoursemodule', 'mod_questionnaire');
|
|
|
46 |
}
|
|
|
47 |
} else {
|
|
|
48 |
if (! $survey = $DB->get_record("questionnaire_survey", array("id" => $sid))) {
|
|
|
49 |
throw new \moodle_exception('surveynotexists', 'mod_questionnaire');
|
|
|
50 |
}
|
|
|
51 |
if (! $course = $DB->get_record("course", ["id" => $survey->courseid])) {
|
|
|
52 |
throw new \moodle_exception('coursemisconf', 'mod_questionnaire');
|
|
|
53 |
}
|
|
|
54 |
// Dummy questionnaire object.
|
|
|
55 |
$questionnaire = new stdClass();
|
|
|
56 |
$questionnaire->id = 0;
|
|
|
57 |
$questionnaire->course = $course->id;
|
|
|
58 |
$questionnaire->name = $survey->title;
|
|
|
59 |
$questionnaire->sid = $sid;
|
|
|
60 |
$questionnaire->resume = 0;
|
|
|
61 |
// Dummy cm object.
|
|
|
62 |
if (!empty($qid)) {
|
|
|
63 |
$cm = get_coursemodule_from_instance('questionnaire', $qid, $course->id);
|
|
|
64 |
} else {
|
|
|
65 |
$cm = false;
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
// Check login and get context.
|
|
|
70 |
// Do not require login if this questionnaire is viewed from the Add questionnaire page
|
|
|
71 |
// to enable teachers to view template or public questionnaires located in a course where they are not enroled.
|
|
|
72 |
if (!$popup) {
|
|
|
73 |
require_login($course->id, false, $cm);
|
|
|
74 |
}
|
|
|
75 |
$context = $cm ? context_module::instance($cm->id) : false;
|
|
|
76 |
|
|
|
77 |
$url = new moodle_url('/mod/questionnaire/preview.php');
|
|
|
78 |
if ($id !== 0) {
|
|
|
79 |
$url->param('id', $id);
|
|
|
80 |
}
|
|
|
81 |
if ($sid) {
|
|
|
82 |
$url->param('sid', $sid);
|
|
|
83 |
}
|
|
|
84 |
$PAGE->set_url($url);
|
|
|
85 |
|
|
|
86 |
$PAGE->set_context($context);
|
|
|
87 |
$PAGE->set_cm($cm); // CONTRIB-5872 - I don't know why this is needed.
|
|
|
88 |
|
|
|
89 |
$questionnaire = new questionnaire($course, $cm, $qid, $questionnaire);
|
|
|
90 |
|
|
|
91 |
// Add renderer and page objects to the questionnaire object for display use.
|
|
|
92 |
$questionnaire->add_renderer($PAGE->get_renderer('mod_questionnaire'));
|
|
|
93 |
$questionnaire->add_page(new \mod_questionnaire\output\previewpage());
|
|
|
94 |
|
|
|
95 |
$canpreview = (!isset($questionnaire->capabilities) &&
|
|
|
96 |
has_capability('mod/questionnaire:preview', context_course::instance($course->id))) ||
|
|
|
97 |
(isset($questionnaire->capabilities) && $questionnaire->capabilities->preview);
|
|
|
98 |
if (!$canpreview && !$popup) {
|
|
|
99 |
// Should never happen, unless called directly by a snoop...
|
|
|
100 |
throw new \moodle_exception('nopermissions', 'mod_questionnaire');
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
if (!isset($SESSION->questionnaire)) {
|
|
|
104 |
$SESSION->questionnaire = new stdClass();
|
|
|
105 |
}
|
|
|
106 |
$SESSION->questionnaire->current_tab = new stdClass();
|
|
|
107 |
$SESSION->questionnaire->current_tab = 'preview';
|
|
|
108 |
|
|
|
109 |
$qp = get_string('preview_questionnaire', 'questionnaire');
|
|
|
110 |
$pq = get_string('previewing', 'questionnaire');
|
|
|
111 |
|
|
|
112 |
// Print the page header.
|
|
|
113 |
if ($popup) {
|
|
|
114 |
$PAGE->set_pagelayout('popup');
|
|
|
115 |
}
|
|
|
116 |
$PAGE->set_title(format_string($qp));
|
|
|
117 |
if (!$popup) {
|
|
|
118 |
$PAGE->set_heading(format_string($course->fullname));
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
// Include the needed js.
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
$PAGE->requires->js('/mod/questionnaire/module.js');
|
|
|
125 |
// Print the tabs.
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
echo $questionnaire->renderer->header();
|
|
|
129 |
if (!$popup) {
|
|
|
130 |
require('tabs.php');
|
|
|
131 |
}
|
|
|
132 |
$questionnaire->page->add_to_page('heading', clean_text($pq));
|
|
|
133 |
|
|
|
134 |
if ($questionnaire->capabilities->printblank) {
|
|
|
135 |
// Open print friendly as popup window.
|
|
|
136 |
|
|
|
137 |
$linkname = ' '.get_string('printblank', 'questionnaire');
|
|
|
138 |
$title = get_string('printblanktooltip', 'questionnaire');
|
|
|
139 |
$url = '/mod/questionnaire/print.php?qid='.$questionnaire->id.'&rid=0&'.'courseid='.
|
|
|
140 |
$questionnaire->course->id.'&sec=1';
|
|
|
141 |
$options = array('menubar' => true, 'location' => false, 'scrollbars' => true, 'resizable' => true,
|
|
|
142 |
'height' => 600, 'width' => 800, 'title' => $title);
|
|
|
143 |
$name = 'popup';
|
|
|
144 |
$link = new moodle_url($url);
|
|
|
145 |
$action = new popup_action('click', $link, $name, $options);
|
|
|
146 |
$class = "floatprinticon";
|
|
|
147 |
$questionnaire->page->add_to_page('printblank',
|
|
|
148 |
$questionnaire->renderer->action_link($link, $linkname, $action, array('class' => $class, 'title' => $title),
|
|
|
149 |
new pix_icon('t/print', $title)));
|
|
|
150 |
}
|
|
|
151 |
$questionnaire->survey_print_render($course->id, '', 'preview', $rid = 0, $popup);
|
|
|
152 |
if ($popup) {
|
|
|
153 |
$questionnaire->page->add_to_page('closebutton', $questionnaire->renderer->close_window_button());
|
|
|
154 |
}
|
|
|
155 |
echo $questionnaire->renderer->render($questionnaire->page);
|
|
|
156 |
echo $questionnaire->renderer->footer($course);
|
|
|
157 |
|
|
|
158 |
// Log this questionnaire preview.
|
|
|
159 |
$context = context_module::instance($questionnaire->cm->id);
|
|
|
160 |
$anonymous = $questionnaire->respondenttype == 'anonymous';
|
|
|
161 |
|
|
|
162 |
$event = \mod_questionnaire\event\questionnaire_previewed::create(array(
|
|
|
163 |
'objectid' => $questionnaire->id,
|
|
|
164 |
'anonymous' => $anonymous,
|
|
|
165 |
'context' => $context
|
|
|
166 |
));
|
|
|
167 |
$event->trigger();
|