forked from PoetOS/moodle-mod_questionnaire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqsettings.php
197 lines (169 loc) · 8.88 KB
/
qsettings.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?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 prints a particular instance of questionnaire.
require_once("../../config.php");
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
$id = required_param('id', PARAM_INT); // Course module ID.
$currentgroupid = optional_param('group', 0, PARAM_INT); // Groupid.
$cancel = optional_param('cancel', '', PARAM_ALPHA);
$submitbutton2 = optional_param('submitbutton2', '', PARAM_ALPHA);
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');
}
// Needed here for forced language courses.
require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);
$url = new moodle_url($CFG->wwwroot.'/mod/questionnaire/qsettings.php', array('id' => $id));
$PAGE->set_url($url);
$PAGE->set_context($context);
if (!isset($SESSION->questionnaire)) {
$SESSION->questionnaire = new stdClass();
}
$questionnaire = new questionnaire(0, $questionnaire, $course, $cm);
// Add renderer and page objects to the questionnaire object for display use.
$questionnaire->add_renderer($PAGE->get_renderer('mod_questionnaire'));
$questionnaire->add_page(new \mod_questionnaire\output\qsettingspage());
$SESSION->questionnaire->current_tab = 'settings';
if (!$questionnaire->capabilities->manage) {
print_error('nopermissions', 'error', 'mod:questionnaire:manage');
}
$settingsform = new \mod_questionnaire\settings_form('qsettings.php');
$sdata = clone($questionnaire->survey);
$sdata->sid = $questionnaire->survey->id;
$sdata->id = $cm->id;
$draftideditor = file_get_submitted_draft_itemid('info');
$currentinfo = file_prepare_draft_area($draftideditor, $context->id, 'mod_questionnaire', 'info',
$sdata->sid, array('subdirs' => true), $questionnaire->survey->info);
$sdata->info = array('text' => $currentinfo, 'format' => FORMAT_HTML, 'itemid' => $draftideditor);
$draftideditor = file_get_submitted_draft_itemid('thankbody');
$currentinfo = file_prepare_draft_area($draftideditor, $context->id, 'mod_questionnaire', 'thankbody',
$sdata->sid, array('subdirs' => true), $questionnaire->survey->thank_body);
$sdata->thank_body = array('text' => $currentinfo, 'format' => FORMAT_HTML, 'itemid' => $draftideditor);
$draftideditor = file_get_submitted_draft_itemid('feedbacknotes');
$currentinfo = file_prepare_draft_area($draftideditor, $context->id, 'mod_questionnaire', 'feedbacknotes',
$sdata->sid, array('subdirs' => true), $questionnaire->survey->feedbacknotes);
$sdata->feedbacknotes = array('text' => $currentinfo, 'format' => FORMAT_HTML, 'itemid' => $draftideditor);
$settingsform->set_data($sdata);
if ($settingsform->is_cancelled()) {
redirect ($CFG->wwwroot.'/mod/questionnaire/view.php?id='.$questionnaire->cm->id, '');
}
if ($settings = $settingsform->get_data()) {
$sdata = new stdClass();
$sdata->id = $settings->sid;
$sdata->name = $settings->name;
$sdata->realm = $settings->realm;
$sdata->title = $settings->title;
$sdata->subtitle = $settings->subtitle;
$sdata->infoitemid = $settings->info['itemid'];
$sdata->infoformat = $settings->info['format'];
$sdata->info = $settings->info['text'];
$sdata->info = file_save_draft_area_files($sdata->infoitemid, $context->id, 'mod_questionnaire', 'info',
$sdata->id, array('subdirs' => true), $sdata->info);
$sdata->theme = ''; // Deprecated theme field.
$sdata->thanks_page = $settings->thanks_page;
$sdata->thank_head = $settings->thank_head;
$sdata->thankitemid = $settings->thank_body['itemid'];
$sdata->thankformat = $settings->thank_body['format'];
$sdata->thank_body = $settings->thank_body['text'];
$sdata->thank_body = file_save_draft_area_files($sdata->thankitemid, $context->id, 'mod_questionnaire', 'thankbody',
$sdata->id, array('subdirs' => true), $sdata->thank_body);
$sdata->email = $settings->email;
if (isset ($settings->feedbackscores)) {
$sdata->feedbackscores = $settings->feedbackscores;
} else {
$sdata->feedbackscores = 0;
}
if (isset ($settings->feedbacknotes)) {
$sdata->fbnotesitemid = $settings->feedbacknotes['itemid'];
$sdata->fbnotesformat = $settings->feedbacknotes['format'];
$sdata->feedbacknotes = $settings->feedbacknotes['text'];
$sdata->feedbacknotes = file_save_draft_area_files($sdata->fbnotesitemid,
$context->id, 'mod_questionnaire', 'feedbacknotes',
$sdata->id, array('subdirs' => true), $sdata->feedbacknotes);
} else {
$sdata->feedbacknotes = '';
}
if (isset ($settings->feedbacksections)) {
$sdata->feedbacksections = $settings->feedbacksections;
$usergraph = get_config('questionnaire', 'usergraph');
if ($usergraph) {
if ($settings->feedbacksections == 1) {
$sdata->chart_type = $settings->chart_type_global;
} else if ($settings->feedbacksections == 2) {
$sdata->chart_type = $settings->chart_type_two_sections;
} else if ($settings->feedbacksections > 2) {
$sdata->chart_type = $settings->chart_type_sections;
}
}
} else {
$sdata->feedbacksections = '';
}
$sdata->courseid = $settings->courseid;
if (!($sid = $questionnaire->survey_update($sdata))) {
print_error('couldnotcreatenewsurvey', 'questionnaire');
} else {
if ($submitbutton2) {
$redirecturl = course_get_url($cm->course);
} else {
$redirecturl = $CFG->wwwroot.'/mod/questionnaire/view.php?id='.$questionnaire->cm->id;
}
// Save current advanced settings only.
if (isset($settings->submitbutton) || isset($settings->submitbutton2)) {
redirect ($redirecturl, get_string('settingssaved', 'questionnaire'));
}
// Delete existing section and feedback records for this questionnaire if any were previously set and None are wanted now
// or Global feedback is now wanted.
if ($sdata->feedbacksections == 0 || ($questionnaire->survey->feedbacksections > 1 && $sdata->feedbacksections == 1)) {
if ($feedbacksections = $DB->get_records('questionnaire_fb_sections',
array('survey_id' => $sid), '', 'id') ) {
foreach ($feedbacksections as $key => $feedbacksection) {
$DB->delete_records('questionnaire_feedback', array('section_id' => $key));
}
$DB->delete_records('questionnaire_fb_sections', array('survey_id' => $sid));
}
}
// Save current advanced settings and go to edit feedback page(s).
$SESSION->questionnaire->currentfbsection = 1;
switch ($settings->feedbacksections) {
// 1 fbsection means Global feedback, redirect immediately to the fb settings page.
case 1:
redirect ($CFG->wwwroot.'/mod/questionnaire/fbsettings.php?id='.$questionnaire->cm->id,
get_string('settingssaved', 'questionnaire'), 0);
break;
// More than 1 section, go to fb sections page for user to put questions inside sections.
default:
// This questionnaire has more than one feedback sections, so needs to set sections questions first
// before setting feedback messages.
redirect ($CFG->wwwroot.'/mod/questionnaire/fbsections.php?id='.$questionnaire->cm->id, '', 0);
break;
}
}
}
// Print the page header.
$PAGE->set_title(get_string('editingquestionnaire', 'questionnaire'));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->navbar->add(get_string('editingquestionnaire', 'questionnaire'));
echo $questionnaire->renderer->header();
require('tabs.php');
$questionnaire->page->add_to_page('formarea', $settingsform->render());
echo $questionnaire->renderer->render($questionnaire->page);
echo $questionnaire->renderer->footer($course);