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 |
* Show the non-respondents to a questionnaire.
|
|
|
19 |
* @author Joseph Rézeau (copied from feedback plugin show_nonrespondents by original author Andreas Grabs)
|
|
|
20 |
* @copyright 2016 Mike Churchward (mike.churchward@poetopensource.org)
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
22 |
* @package mod_questionnaire
|
|
|
23 |
*
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
require_once("../../config.php");
|
|
|
27 |
require_once($CFG->dirroot.'/mod/questionnaire/locallib.php');
|
|
|
28 |
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
|
|
|
29 |
require_once($CFG->libdir.'/tablelib.php');
|
|
|
30 |
|
|
|
31 |
// Get the params.
|
|
|
32 |
$id = required_param('id', PARAM_INT);
|
|
|
33 |
$subject = optional_param('subject', '', PARAM_CLEANHTML);
|
|
|
34 |
$message = optional_param('message', '', PARAM_CLEANHTML);
|
|
|
35 |
$format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
|
|
|
36 |
$messageuser = optional_param_array('messageuser', false, PARAM_INT);
|
|
|
37 |
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
38 |
$selectedanonymous = optional_param('selectedanonymous', '', PARAM_ALPHA);
|
|
|
39 |
$perpage = optional_param('perpage', QUESTIONNAIRE_DEFAULT_PAGE_COUNT, PARAM_INT); // How many per page.
|
|
|
40 |
$showall = optional_param('showall', false, PARAM_INT); // Should we show all users?
|
|
|
41 |
$sid = optional_param('sid', 0, PARAM_INT);
|
|
|
42 |
$qid = optional_param('qid', 0, PARAM_INT);
|
|
|
43 |
$currentgroupid = optional_param('group', 0, PARAM_INT); // Groupid.
|
|
|
44 |
|
|
|
45 |
if (!isset($SESSION->questionnaire)) {
|
|
|
46 |
$SESSION->questionnaire = new stdClass();
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
$SESSION->questionnaire->current_tab = 'nonrespondents';
|
|
|
50 |
|
|
|
51 |
// Get the objects.
|
|
|
52 |
|
|
|
53 |
if ($id) {
|
|
|
54 |
if (! $cm = get_coursemodule_from_id('questionnaire', $id)) {
|
|
|
55 |
throw new \moodle_exception('invalidcoursemodule', 'mod_questionnaire');
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
|
|
|
59 |
throw new \moodle_exception('coursemisconf', 'mod_questionnaire');
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
if (! $questionnaire = $DB->get_record("questionnaire", array("id" => $cm->instance))) {
|
|
|
63 |
throw new \moodle_exception('invalidcoursemodule', 'mod_questionnaire');
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
if (!$context = context_module::instance($cm->id)) {
|
|
|
68 |
throw new \moodle_exception('badcontext', 'mod_questionnaire');
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
// We need the coursecontext to allow sending of mass mails.
|
|
|
72 |
if (!$coursecontext = context_course::instance($course->id)) {
|
|
|
73 |
throw new \moodle_exception('badcontext', 'mod_questionnaire');
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
require_course_login($course, true, $cm);
|
|
|
77 |
|
|
|
78 |
$url = new moodle_url('/mod/questionnaire/show_nonrespondents.php', array('id' => $cm->id));
|
|
|
79 |
$PAGE->set_url($url);
|
|
|
80 |
|
|
|
81 |
$questionnaire = new questionnaire($course, $cm, $sid, $questionnaire);
|
|
|
82 |
|
|
|
83 |
// Add renderer and page objects to the questionnaire object for display use.
|
|
|
84 |
$questionnaire->add_renderer($PAGE->get_renderer('mod_questionnaire'));
|
|
|
85 |
$questionnaire->add_page(new \mod_questionnaire\output\nonrespondentspage());
|
|
|
86 |
|
|
|
87 |
$resume = $questionnaire->resume;
|
|
|
88 |
$fullname = $questionnaire->respondenttype == 'fullname';
|
|
|
89 |
$sid = $questionnaire->sid;
|
|
|
90 |
|
|
|
91 |
if (($formdata = data_submitted()) && !confirm_sesskey()) {
|
|
|
92 |
throw new \moodle_exception('invalidsesskey', 'mod_questionnaire');
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
require_capability('mod/questionnaire:viewsingleresponse', $context);
|
|
|
96 |
|
|
|
97 |
// Anonymous questionnaire.
|
|
|
98 |
if (!$fullname) {
|
|
|
99 |
$nonrespondents = questionnaire_get_incomplete_users($cm, $sid);
|
|
|
100 |
$countnonrespondents = count($nonrespondents);
|
|
|
101 |
if ($resume) {
|
|
|
102 |
$countstarted = 0;
|
|
|
103 |
$countnotstarted = 0;
|
|
|
104 |
$params = ['questionnaireid' => $questionnaire->id, 'complete' => 'n'];
|
|
|
105 |
if ($startedusers = $DB->get_records('questionnaire_response', $params, '', 'userid')) {
|
|
|
106 |
$startedusers = array_keys($startedusers);
|
|
|
107 |
$countstarted = count($startedusers);
|
|
|
108 |
$countnotstarted = $countnonrespondents - $countstarted;
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
if ($action == 'sendmessage' && !empty($subject) && !empty($message)) {
|
|
|
114 |
if (!$fullname) {
|
|
|
115 |
switch ($selectedanonymous) {
|
|
|
116 |
case 'none':
|
|
|
117 |
$messageuser = '';
|
|
|
118 |
break;
|
|
|
119 |
case 'all':
|
|
|
120 |
$messageuser = $nonrespondents;
|
|
|
121 |
break;
|
|
|
122 |
case 'started':
|
|
|
123 |
$messageuser = $startedusers;
|
|
|
124 |
break;
|
|
|
125 |
case 'notstarted':
|
|
|
126 |
$messageuser = array_diff($nonrespondents, $startedusers);
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
$shortname = format_string($course->shortname,
|
|
|
131 |
true,
|
|
|
132 |
array('context' => context_course::instance($course->id)));
|
|
|
133 |
$strquestionnaires = get_string("modulenameplural", "questionnaire");
|
|
|
134 |
|
|
|
135 |
$htmlmessage = "<body id=\"email\">";
|
|
|
136 |
|
|
|
137 |
$link1 = $CFG->wwwroot.'/mod/questionnaire/view.php?id='.$cm->id;
|
|
|
138 |
|
|
|
139 |
$htmlmessage .= '<div class="navbar">'.
|
|
|
140 |
'<a target="_blank" href="'.$link1.'">'.format_string($questionnaire->name, true).'</a>'.
|
|
|
141 |
'</div>';
|
|
|
142 |
|
|
|
143 |
$htmlmessage .= $message;
|
|
|
144 |
$htmlmessage .= '</body>';
|
|
|
145 |
|
|
|
146 |
$good = 1;
|
|
|
147 |
|
|
|
148 |
if (is_array($messageuser)) {
|
|
|
149 |
foreach ($messageuser as $userid) {
|
|
|
150 |
$senduser = $DB->get_record('user', array('id' => $userid));
|
|
|
151 |
$eventdata = new \core\message\message();
|
|
|
152 |
$eventdata->courseid = $course->id;
|
|
|
153 |
$eventdata->name = 'message';
|
|
|
154 |
$eventdata->component = 'mod_questionnaire';
|
|
|
155 |
$eventdata->userfrom = $USER;
|
|
|
156 |
$eventdata->userto = $senduser;
|
|
|
157 |
$eventdata->subject = $subject;
|
|
|
158 |
$eventdata->fullmessage = html_to_text($htmlmessage);
|
|
|
159 |
$eventdata->fullmessageformat = FORMAT_PLAIN;
|
|
|
160 |
$eventdata->fullmessagehtml = $htmlmessage;
|
|
|
161 |
$eventdata->smallmessage = '';
|
|
|
162 |
$good = $good && message_send($eventdata);
|
|
|
163 |
}
|
|
|
164 |
if (!empty($good)) {
|
|
|
165 |
$msg = $questionnaire->renderer->heading(get_string('messagedselectedusers'));
|
|
|
166 |
} else {
|
|
|
167 |
$msg = $questionnaire->renderer->heading(get_string('messagedselectedusersfailed'));
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
$url = new moodle_url('/mod/questionnaire/view.php', array('id' => $cm->id));
|
|
|
171 |
redirect($url, $msg, 4);
|
|
|
172 |
exit;
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
// Get the responses of given user.
|
|
|
177 |
// Print the page header.
|
|
|
178 |
$PAGE->navbar->add(get_string('show_nonrespondents', 'questionnaire'));
|
|
|
179 |
$PAGE->set_heading(format_string($course->fullname));
|
|
|
180 |
$PAGE->set_title(format_string($questionnaire->name));
|
|
|
181 |
echo $questionnaire->renderer->header();
|
|
|
182 |
|
|
|
183 |
require('tabs.php');
|
|
|
184 |
|
|
|
185 |
$usedgroupid = false;
|
|
|
186 |
$sort = '';
|
|
|
187 |
$startpage = false;
|
|
|
188 |
$pagecount = false;
|
|
|
189 |
|
|
|
190 |
if ($fullname) {
|
|
|
191 |
// Print the main part of the page.
|
|
|
192 |
// Print the users with no responses
|
|
|
193 |
// Get the effective groupmode of this course and module.
|
|
|
194 |
$groupmode = groups_get_activity_groupmode($cm, $course);
|
|
|
195 |
|
|
|
196 |
$groupselect = groups_print_activity_menu($cm, $url->out(), true);
|
|
|
197 |
$mygroupid = groups_get_activity_group($cm);
|
|
|
198 |
|
|
|
199 |
// Preparing the table for output.
|
|
|
200 |
$baseurl = new moodle_url('/mod/questionnaire/show_nonrespondents.php');
|
|
|
201 |
$baseurl->params(array('id' => $cm->id, 'showall' => $showall));
|
|
|
202 |
|
|
|
203 |
$tablecolumns = array('userpic', 'fullname');
|
|
|
204 |
|
|
|
205 |
// Extra columns copied from participants view.
|
|
|
206 |
if (class_exists('\core_user\fields')) {
|
|
|
207 |
$extrafields = \core_user\fields::get_identity_fields(null, false);
|
|
|
208 |
} else {
|
|
|
209 |
$extrafields = get_extra_user_fields($context);
|
|
|
210 |
}
|
|
|
211 |
$tableheaders = array(get_string('userpic'), get_string('fullnameuser'));
|
|
|
212 |
|
|
|
213 |
if (in_array('email', $extrafields) || has_capability('moodle/course:viewhiddenuserfields', $context)) {
|
|
|
214 |
$tablecolumns[] = 'email';
|
|
|
215 |
$tableheaders[] = get_string('email');
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
if (!isset($hiddenfields['city'])) {
|
|
|
219 |
$tablecolumns[] = 'city';
|
|
|
220 |
$tableheaders[] = get_string('city');
|
|
|
221 |
}
|
|
|
222 |
if (!isset($hiddenfields['country'])) {
|
|
|
223 |
$tablecolumns[] = 'country';
|
|
|
224 |
$tableheaders[] = get_string('country');
|
|
|
225 |
}
|
|
|
226 |
if (!isset($hiddenfields['lastaccess'])) {
|
|
|
227 |
$tablecolumns[] = 'lastaccess';
|
|
|
228 |
$tableheaders[] = get_string('lastaccess');
|
|
|
229 |
}
|
|
|
230 |
if ($resume) {
|
|
|
231 |
$tablecolumns[] = 'status';
|
|
|
232 |
$tableheaders[] = get_string('status');
|
|
|
233 |
}
|
|
|
234 |
if (has_capability('mod/questionnaire:message', $context)) {
|
|
|
235 |
$tablecolumns[] = 'select';
|
|
|
236 |
$tableheaders[] = get_string('select');
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
$table = new flexible_table('questionnaire-shownonrespondents-'.$course->id);
|
|
|
240 |
|
|
|
241 |
$table->define_columns($tablecolumns);
|
|
|
242 |
$table->define_headers($tableheaders);
|
|
|
243 |
$table->define_baseurl($baseurl);
|
|
|
244 |
|
|
|
245 |
$table->sortable(true, 'lastname', SORT_DESC);
|
|
|
246 |
$table->set_attribute('cellspacing', '0');
|
|
|
247 |
$table->set_attribute('id', 'showentrytable');
|
|
|
248 |
$table->set_attribute('class', 'flexible generaltable generalbox');
|
|
|
249 |
$table->set_control_variables(array(
|
|
|
250 |
TABLE_VAR_SORT => 'ssort',
|
|
|
251 |
TABLE_VAR_IFIRST => 'sifirst',
|
|
|
252 |
TABLE_VAR_ILAST => 'silast',
|
|
|
253 |
TABLE_VAR_PAGE => 'spage'
|
|
|
254 |
));
|
|
|
255 |
|
|
|
256 |
$table->no_sorting('status');
|
|
|
257 |
$table->no_sorting('select');
|
|
|
258 |
|
|
|
259 |
$table->setup();
|
|
|
260 |
|
|
|
261 |
if ($table->get_sql_sort()) {
|
|
|
262 |
$sort = $table->get_sql_sort();
|
|
|
263 |
} else {
|
|
|
264 |
$sort = '';
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
// Get students in conjunction with groupmode.
|
|
|
268 |
if ($groupmode > 0) {
|
|
|
269 |
if ($mygroupid > 0) {
|
|
|
270 |
$usedgroupid = $mygroupid;
|
|
|
271 |
} else {
|
|
|
272 |
$usedgroupid = false;
|
|
|
273 |
}
|
|
|
274 |
} else {
|
|
|
275 |
$usedgroupid = false;
|
|
|
276 |
}
|
|
|
277 |
$nonrespondents = questionnaire_get_incomplete_users($cm, $sid, $usedgroupid);
|
|
|
278 |
if (is_array($nonrespondents) || is_object($nonrespondents)) {
|
|
|
279 |
$countnonrespondents = count($nonrespondents);
|
|
|
280 |
} else {
|
|
|
281 |
$countnonrespondents = 0;
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
$table->initialbars(false);
|
|
|
285 |
|
|
|
286 |
if ($showall) {
|
|
|
287 |
$startpage = false;
|
|
|
288 |
$pagecount = false;
|
|
|
289 |
} else {
|
|
|
290 |
$table->pagesize($perpage, $countnonrespondents);
|
|
|
291 |
$startpage = $table->get_page_start();
|
|
|
292 |
$pagecount = $table->get_page_size();
|
|
|
293 |
}
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
$nonrespondents = questionnaire_get_incomplete_users($cm, $sid, $usedgroupid, $sort, $startpage, $pagecount);
|
|
|
297 |
|
|
|
298 |
// Viewreports-start.
|
|
|
299 |
// Print the list of students.
|
|
|
300 |
|
|
|
301 |
$questionnaire->page->add_to_page('formarea', (isset($groupselect) ? $groupselect : ''));
|
|
|
302 |
$questionnaire->page->add_to_page('formarea', html_writer::tag('div', '', ['class' => 'clearer']));
|
|
|
303 |
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->box_start('left-align'));
|
|
|
304 |
|
|
|
305 |
$countries = get_string_manager()->get_list_of_countries();
|
|
|
306 |
|
|
|
307 |
$strnever = get_string('never');
|
|
|
308 |
|
|
|
309 |
$datestring = new stdClass();
|
|
|
310 |
$datestring->year = get_string('year');
|
|
|
311 |
$datestring->years = get_string('years');
|
|
|
312 |
$datestring->day = get_string('day');
|
|
|
313 |
$datestring->days = get_string('days');
|
|
|
314 |
$datestring->hour = get_string('hour');
|
|
|
315 |
$datestring->hours = get_string('hours');
|
|
|
316 |
$datestring->min = get_string('min');
|
|
|
317 |
$datestring->mins = get_string('mins');
|
|
|
318 |
$datestring->sec = get_string('sec');
|
|
|
319 |
$datestring->secs = get_string('secs');
|
|
|
320 |
|
|
|
321 |
if (!$nonrespondents) {
|
|
|
322 |
$questionnaire->page->add_to_page('formarea',
|
|
|
323 |
$questionnaire->renderer->notification(get_string('noexistingparticipants', 'enrol')));
|
|
|
324 |
} else {
|
|
|
325 |
$questionnaire->page->add_to_page('formarea', get_string('non_respondents', 'questionnaire'));
|
|
|
326 |
$questionnaire->page->add_to_page('formarea', ' ('.$countnonrespondents.')');
|
|
|
327 |
if (!$fullname) {
|
|
|
328 |
$questionnaire->page->add_to_page('formarea', ' ['.get_string('anonymous', 'questionnaire').']');
|
|
|
329 |
}
|
|
|
330 |
$questionnaire->page->add_to_page('formarea', html_writer::start_tag('form',
|
|
|
331 |
['class' => 'mform', 'action' => 'show_nonrespondents.php', 'method' => 'post', 'id' => 'questionnaire_sendmessageform']));
|
|
|
332 |
|
|
|
333 |
$buffering = false;
|
|
|
334 |
if ($fullname) {
|
|
|
335 |
// Since flexible tables only writes out directly, we need to start buffering in case anything gets written...
|
|
|
336 |
ob_start();
|
|
|
337 |
$buffering = true;
|
|
|
338 |
foreach ($nonrespondents as $nonrespondent) {
|
|
|
339 |
$user = $DB->get_record('user', array('id' => $nonrespondent));
|
|
|
340 |
// Userpicture and link to the profilepage.
|
|
|
341 |
$profileurl = $CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id;
|
|
|
342 |
$profilelink = '<strong><a href="'.$profileurl.'">'.fullname($user).'</a></strong>';
|
|
|
343 |
$data = array ($questionnaire->renderer->user_picture($user, array('courseid' => $course->id)), $profilelink);
|
|
|
344 |
if (in_array('email', $tablecolumns)) {
|
|
|
345 |
$data[] = $user->email;
|
|
|
346 |
}
|
|
|
347 |
if (!isset($hiddenfields['city'])) {
|
|
|
348 |
$data[] = $user->city;
|
|
|
349 |
}
|
|
|
350 |
if (!isset($hiddenfields['country'])) {
|
|
|
351 |
$data[] = (!empty($user->country)) ? $countries[$user->country] : '';
|
|
|
352 |
}
|
|
|
353 |
if ($user->lastaccess) {
|
|
|
354 |
$lastaccess = format_time(time() - $user->lastaccess, $datestring);
|
|
|
355 |
} else {
|
|
|
356 |
$lastaccess = get_string('never');
|
|
|
357 |
}
|
|
|
358 |
$data[] = $lastaccess;
|
|
|
359 |
if (has_capability('mod/questionnaire:message', $context)) {
|
|
|
360 |
// If questionnaire is set to "resume", look for saved (not completed) responses
|
|
|
361 |
// we use the alt attribute of the checkboxes to store the started/not started value!
|
|
|
362 |
$checkboxaltvalue = '';
|
|
|
363 |
if ($resume) {
|
|
|
364 |
if ($DB->record_exists('questionnaire_response', ['questionnaireid' => $questionnaire->id,
|
|
|
365 |
'userid' => $nonrespondent, 'complete' => 'n']) ) {
|
|
|
366 |
$data[] = get_string('started', 'questionnaire');
|
|
|
367 |
$checkboxaltvalue = 1;
|
|
|
368 |
} else {
|
|
|
369 |
$data[] = get_string('not_started', 'questionnaire');
|
|
|
370 |
$checkboxaltvalue = 0;
|
|
|
371 |
}
|
|
|
372 |
}
|
|
|
373 |
$data[] = '<input type="checkbox" class="usercheckbox" name="messageuser[]" value="'.
|
|
|
374 |
$user->id.'" alt="'.$checkboxaltvalue.'" />';
|
|
|
375 |
}
|
|
|
376 |
$table->add_data($data);
|
|
|
377 |
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
if (isset($table)) {
|
|
|
381 |
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->flexible_table($table, $buffering));
|
|
|
382 |
} else if ($buffering) {
|
|
|
383 |
ob_end_clean();
|
|
|
384 |
}
|
|
|
385 |
$allurl = new moodle_url($baseurl);
|
|
|
386 |
if ($showall) {
|
|
|
387 |
$allurl->param('showall', 0);
|
|
|
388 |
$questionnaire->page->add_to_page('formarea',
|
|
|
389 |
$questionnaire->renderer->container(html_writer::link($allurl,
|
|
|
390 |
get_string('showperpage', '', QUESTIONNAIRE_DEFAULT_PAGE_COUNT)), array(), 'showall'));
|
|
|
391 |
|
|
|
392 |
} else if ($countnonrespondents > 0 && $perpage < $countnonrespondents) {
|
|
|
393 |
$allurl->param('showall', 1);
|
|
|
394 |
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->container(html_writer::link($allurl,
|
|
|
395 |
get_string('showall', '', $countnonrespondents)), array(), 'showall'));
|
|
|
396 |
}
|
|
|
397 |
if (has_capability('mod/questionnaire:message', $context)) {
|
|
|
398 |
$questionnaire->page->add_to_page('formarea',
|
|
|
399 |
$questionnaire->renderer->box_start('mdl-align')); // Selection buttons container.
|
|
|
400 |
$questionnaire->page->add_to_page('formarea', '<div class="buttons">');
|
|
|
401 |
$questionnaire->page->add_to_page('formarea',
|
|
|
402 |
'<input type="button" id="checkall" class="btn btn-secondary" value="'.get_string('selectall').'" /> ');
|
|
|
403 |
$questionnaire->page->add_to_page('formarea',
|
|
|
404 |
'<input type="button" id="checknone" class="btn btn-secondary" value="'.get_string('deselectall').'" /> ');
|
|
|
405 |
if ($resume) {
|
|
|
406 |
if ($perpage >= $countnonrespondents) {
|
|
|
407 |
$questionnaire->page->add_to_page('formarea',
|
|
|
408 |
'<input type="button" id="checkstarted" class="btn btn-secondary" value="' .
|
|
|
409 |
get_string('checkstarted', 'questionnaire').'" />'."\n");
|
|
|
410 |
$questionnaire->page->add_to_page('formarea',
|
|
|
411 |
'<input type="button" id="checknotstarted" class="btn btn-secondary" value="'.
|
|
|
412 |
get_string('checknotstarted', 'questionnaire').'" />'."\n");
|
|
|
413 |
}
|
|
|
414 |
}
|
|
|
415 |
$questionnaire->page->add_to_page('formarea', '</div>');
|
|
|
416 |
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->box_end());
|
|
|
417 |
if ($action == 'sendmessage' && !is_array($messageuser)) {
|
|
|
418 |
$questionnaire->page->add_to_page('formarea',
|
|
|
419 |
$questionnaire->renderer->notification(get_string('nousersselected', 'questionnaire')));
|
|
|
420 |
}
|
|
|
421 |
}
|
|
|
422 |
} else {// Anonymous questionnaire.
|
|
|
423 |
if (has_capability('mod/questionnaire:message', $context)) {
|
|
|
424 |
$questionnaire->page->add_to_page('formarea', '<fieldset>');
|
|
|
425 |
$questionnaire->page->add_to_page('formarea', '<legend>'.get_string('send_message_to', 'questionnaire').'</legend>');
|
|
|
426 |
$checked = ($selectedanonymous == '' || $selectedanonymous == 'none') ? 'checked = "checked"' : '';
|
|
|
427 |
$questionnaire->page->add_to_page('formarea',
|
|
|
428 |
' <input type="radio" name="selectedanonymous" value="none" id="none" '.$checked.' />
|
|
|
429 |
<label for="none">'.get_string('none').'</label>');
|
|
|
430 |
$checked = ($selectedanonymous == 'all') ? 'checked = "checked"' : '';
|
|
|
431 |
$questionnaire->page->add_to_page('formarea',
|
|
|
432 |
'<input type="radio" name="selectedanonymous" value="all" id="nonrespondents" '.$checked.' />
|
|
|
433 |
<label for="all">'.get_string('all', 'questionnaire').'</label>');
|
|
|
434 |
if ($resume) {
|
|
|
435 |
if ($countstarted > 0) {
|
|
|
436 |
$checked = ($selectedanonymous == 'started') ? 'checked = "checked"' : '';
|
|
|
437 |
$questionnaire->page->add_to_page('formarea',
|
|
|
438 |
'<input type="radio" name="selectedanonymous" value="started" id="started" '.$checked.' />
|
|
|
439 |
<label for="started">'.get_string('status').': '.
|
|
|
440 |
get_string('started', 'questionnaire').' ('.$countstarted.')</label>');
|
|
|
441 |
}
|
|
|
442 |
if ($countnotstarted > 0) {
|
|
|
443 |
if ($selectedanonymous == 'notstarted') {
|
|
|
444 |
$checked = 'checked = "checked"';
|
|
|
445 |
} else {
|
|
|
446 |
$checked = '';
|
|
|
447 |
}
|
|
|
448 |
$checked = ($selectedanonymous == 'notstarted') ? 'checked = "checked"' : '';
|
|
|
449 |
$questionnaire->page->add_to_page('formarea',
|
|
|
450 |
'<input type="radio" name="selectedanonymous" value="notstarted" id="notstarted" '.$checked.' />
|
|
|
451 |
<label for="notstarted">'.get_string('status').': '.
|
|
|
452 |
get_string('not_started', 'questionnaire').' ('.$countnotstarted.')</label>');
|
|
|
453 |
}
|
|
|
454 |
}
|
|
|
455 |
if ($action == 'sendmessage' && $selectedanonymous == 'none') {
|
|
|
456 |
$questionnaire->page->add_to_page('formarea',
|
|
|
457 |
$questionnaire->renderer->notification(get_string('nousersselected', 'questionnaire')));
|
|
|
458 |
}
|
|
|
459 |
$questionnaire->page->add_to_page('formarea', '</fieldset>');
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
if (has_capability('mod/questionnaire:message', $context)) {
|
|
|
463 |
// Message editor.
|
|
|
464 |
// Prepare data.
|
|
|
465 |
$questionnaire->page->add_to_page('formarea', '<fieldset class="clearfix">');
|
|
|
466 |
if ($action == 'sendmessage' && (empty($subject) || empty($message))) {
|
|
|
467 |
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->notification(get_string('allfieldsrequired')));
|
|
|
468 |
}
|
|
|
469 |
$questionnaire->page->add_to_page('formarea',
|
|
|
470 |
'<legend class="ftoggler">'.get_string('send_message', 'questionnaire').'</legend>');
|
|
|
471 |
$id = 'message' . '_id';
|
|
|
472 |
$subjecteditor = ' <input type="text" id="questionnaire_subject" class="form-control" size="65"
|
|
|
473 |
maxlength="255" name="subject" value="'.$subject.'" />';
|
|
|
474 |
$format = '';
|
|
|
475 |
$editor = editors_get_preferred_editor();
|
|
|
476 |
$editor->use_editor($id, questionnaire_get_editor_options($context));
|
|
|
477 |
$texteditor = html_writer::tag('div', html_writer::tag('textarea', $message,
|
|
|
478 |
array('id' => $id, 'name' => "message", 'class' => "form-control", 'rows' => '10', 'cols' => '60')));
|
|
|
479 |
$questionnaire->page->add_to_page('formarea', '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />');
|
|
|
480 |
|
|
|
481 |
|
|
|
482 |
// Print editor.
|
|
|
483 |
$table = new html_table();
|
|
|
484 |
$table->align = array('left', 'left');
|
|
|
485 |
$table->data[] = array( '<strong>'.get_string('subject', 'questionnaire').'</strong>', $subjecteditor);
|
|
|
486 |
$table->data[] = array('<strong>'.get_string('messagebody').'</strong>', $texteditor);
|
|
|
487 |
|
|
|
488 |
$questionnaire->page->add_to_page('formarea', html_writer::table($table));
|
|
|
489 |
|
|
|
490 |
// Send button.
|
|
|
491 |
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->box_start('mdl-left'));
|
|
|
492 |
$questionnaire->page->add_to_page('formarea', '<div class="buttons">');
|
|
|
493 |
$questionnaire->page->add_to_page('formarea', '<input type="submit" name="send_message" class="btn btn-secondary" value="' .
|
|
|
494 |
get_string('send', 'questionnaire').'" />');
|
|
|
495 |
$questionnaire->page->add_to_page('formarea', '</div>');
|
|
|
496 |
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->box_end());
|
|
|
497 |
|
|
|
498 |
$questionnaire->page->add_to_page('formarea', '<input type="hidden" name="sesskey" value="'.sesskey().'" />');
|
|
|
499 |
$questionnaire->page->add_to_page('formarea', '<input type="hidden" name="action" value="sendmessage" />');
|
|
|
500 |
$questionnaire->page->add_to_page('formarea', '<input type="hidden" name="id" value="'.$cm->id.'" />');
|
|
|
501 |
|
|
|
502 |
$questionnaire->page->add_to_page('formarea', '</fieldset>');
|
|
|
503 |
|
|
|
504 |
$questionnaire->page->add_to_page('formarea', html_writer::end_tag('form'));
|
|
|
505 |
|
|
|
506 |
// Include the needed js.
|
|
|
507 |
$module = array('name' => 'mod_questionnaire', 'fullpath' => '/mod/questionnaire/module.js');
|
|
|
508 |
$PAGE->requires->js_init_call('M.mod_questionnaire.init_sendmessage', null, false, $module);
|
|
|
509 |
}
|
|
|
510 |
}
|
|
|
511 |
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->box_end());
|
|
|
512 |
|
|
|
513 |
// Finish the page.
|
|
|
514 |
echo $questionnaire->renderer->render($questionnaire->page);
|
|
|
515 |
echo $questionnaire->renderer->footer();
|
|
|
516 |
|
|
|
517 |
// Log this questionnaire show non-respondents action.
|
|
|
518 |
$context = context_module::instance($questionnaire->cm->id);
|
|
|
519 |
$anonymous = $questionnaire->respondenttype == 'anonymous';
|
|
|
520 |
|
|
|
521 |
$event = \mod_questionnaire\event\non_respondents_viewed::create(array(
|
|
|
522 |
'objectid' => $questionnaire->id,
|
|
|
523 |
'anonymous' => $anonymous,
|
|
|
524 |
'context' => $context
|
|
|
525 |
));
|
|
|
526 |
$event->trigger();
|