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 |
* print the single entries
|
|
|
19 |
*
|
|
|
20 |
* @author Andreas Grabs
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
22 |
* @package mod_feedback
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once("../../config.php");
|
|
|
26 |
require_once("lib.php");
|
|
|
27 |
require_once($CFG->libdir.'/tablelib.php');
|
|
|
28 |
|
|
|
29 |
////////////////////////////////////////////////////////
|
|
|
30 |
//get the params
|
|
|
31 |
////////////////////////////////////////////////////////
|
|
|
32 |
$id = required_param('id', PARAM_INT);
|
|
|
33 |
$subject = optional_param('subject', '', PARAM_CLEANHTML);
|
|
|
34 |
$message = optional_param_array('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 |
$perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT); // how many per page
|
|
|
39 |
$showall = optional_param('showall', false, PARAM_INT); // should we show all users
|
|
|
40 |
// $SESSION->feedback->current_tab = $do_show;
|
|
|
41 |
$current_tab = 'nonrespondents';
|
|
|
42 |
|
|
|
43 |
////////////////////////////////////////////////////////
|
|
|
44 |
//get the objects
|
|
|
45 |
////////////////////////////////////////////////////////
|
|
|
46 |
|
|
|
47 |
if ($message) {
|
|
|
48 |
$message = $message['text'];
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
list ($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
|
|
|
52 |
if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
|
|
|
53 |
throw new \moodle_exception('invalidcoursemodule');
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
//this page only can be shown on nonanonymous feedbacks in courses
|
|
|
57 |
//we should never reach this page
|
|
|
58 |
if ($feedback->anonymous != FEEDBACK_ANONYMOUS_NO OR $feedback->course == SITEID) {
|
|
|
59 |
throw new \moodle_exception('error');
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
$url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm->id));
|
|
|
63 |
|
|
|
64 |
$PAGE->set_url($url);
|
|
|
65 |
|
|
|
66 |
$context = context_module::instance($cm->id);
|
|
|
67 |
|
|
|
68 |
//we need the coursecontext to allow sending of mass mails
|
|
|
69 |
$coursecontext = context_course::instance($course->id);
|
|
|
70 |
|
|
|
71 |
require_login($course, true, $cm);
|
|
|
72 |
|
|
|
73 |
$actionbar = new \mod_feedback\output\responses_action_bar($cm->id, $url);
|
|
|
74 |
|
|
|
75 |
require_capability('mod/feedback:viewreports', $context);
|
|
|
76 |
|
11 |
efrain |
77 |
$currentgroup = groups_get_activity_group($cm, true);
|
|
|
78 |
$incompleteusers = feedback_get_incomplete_users($cm, $currentgroup);
|
|
|
79 |
|
1 |
efrain |
80 |
$canbulkmessaging = has_capability('moodle/course:bulkmessaging', $coursecontext);
|
11 |
efrain |
81 |
if ($action == 'sendmessage' && $canbulkmessaging) {
|
|
|
82 |
require_sesskey();
|
|
|
83 |
|
1 |
efrain |
84 |
$shortname = format_string($course->shortname,
|
|
|
85 |
true,
|
|
|
86 |
array('context' => $coursecontext));
|
|
|
87 |
$strfeedbacks = get_string("modulenameplural", "feedback");
|
|
|
88 |
|
|
|
89 |
$htmlmessage = "<body id=\"email\">";
|
|
|
90 |
|
|
|
91 |
$link1 = $CFG->wwwroot.'/course/view.php?id='.$course->id;
|
|
|
92 |
$link2 = $CFG->wwwroot.'/mod/feedback/index.php?id='.$course->id;
|
|
|
93 |
$link3 = $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id;
|
|
|
94 |
|
|
|
95 |
$htmlmessage .= '<div class="navbar">'.
|
|
|
96 |
'<a target="_blank" href="'.$link1.'">'.$shortname.'</a> » '.
|
|
|
97 |
'<a target="_blank" href="'.$link2.'">'.$strfeedbacks.'</a> » '.
|
|
|
98 |
'<a target="_blank" href="'.$link3.'">'.format_string($feedback->name, true).'</a>'.
|
|
|
99 |
'</div>';
|
|
|
100 |
|
|
|
101 |
$htmlmessage .= $message;
|
|
|
102 |
$htmlmessage .= '</body>';
|
|
|
103 |
|
|
|
104 |
$good = 1;
|
|
|
105 |
if (is_array($messageuser)) {
|
11 |
efrain |
106 |
|
|
|
107 |
// Ensure selected users are part of the "incomplete users" set.
|
|
|
108 |
$messageuser = array_intersect($messageuser, $incompleteusers);
|
|
|
109 |
|
1 |
efrain |
110 |
foreach ($messageuser as $userid) {
|
|
|
111 |
$senduser = $DB->get_record('user', array('id'=>$userid));
|
|
|
112 |
$eventdata = new \core\message\message();
|
|
|
113 |
$eventdata->courseid = $course->id;
|
|
|
114 |
$eventdata->name = 'message';
|
|
|
115 |
$eventdata->component = 'mod_feedback';
|
|
|
116 |
$eventdata->userfrom = $USER;
|
|
|
117 |
$eventdata->userto = $senduser;
|
|
|
118 |
$eventdata->subject = $subject;
|
|
|
119 |
$eventdata->fullmessage = html_to_text($htmlmessage);
|
|
|
120 |
$eventdata->fullmessageformat = FORMAT_PLAIN;
|
|
|
121 |
$eventdata->fullmessagehtml = $htmlmessage;
|
|
|
122 |
$eventdata->smallmessage = '';
|
|
|
123 |
$eventdata->courseid = $course->id;
|
|
|
124 |
$eventdata->contexturl = $link3;
|
|
|
125 |
$eventdata->contexturlname = $feedback->name;
|
|
|
126 |
$good = $good && message_send($eventdata);
|
|
|
127 |
}
|
|
|
128 |
if (!empty($good)) {
|
|
|
129 |
$msg = $OUTPUT->heading(get_string('messagedselectedusers'));
|
|
|
130 |
} else {
|
|
|
131 |
$msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
|
|
|
132 |
}
|
|
|
133 |
redirect($url, $msg, 4);
|
|
|
134 |
exit;
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
////////////////////////////////////////////////////////
|
|
|
139 |
//get the responses of given user
|
|
|
140 |
////////////////////////////////////////////////////////
|
|
|
141 |
|
|
|
142 |
/// Print the page header
|
|
|
143 |
$PAGE->set_heading($course->fullname);
|
|
|
144 |
$PAGE->set_title($feedback->name);
|
|
|
145 |
$PAGE->set_secondary_active_tab('responses');
|
|
|
146 |
if ($responsesnode = $PAGE->settingsnav->find('responses', navigation_node::TYPE_CUSTOM)) {
|
|
|
147 |
$responsesnode->make_active();
|
|
|
148 |
}
|
|
|
149 |
$PAGE->activityheader->set_attrs([
|
|
|
150 |
'hidecompletion' => true,
|
|
|
151 |
'description' => ''
|
|
|
152 |
]);
|
|
|
153 |
echo $OUTPUT->header();
|
|
|
154 |
|
|
|
155 |
/** @var \mod_feedback\output\renderer $renderer */
|
|
|
156 |
$renderer = $PAGE->get_renderer('mod_feedback');
|
|
|
157 |
echo $renderer->main_action_bar($actionbar);
|
|
|
158 |
|
|
|
159 |
/// Print the main part of the page
|
|
|
160 |
///////////////////////////////////////////////////////////////////////////
|
|
|
161 |
///////////////////////////////////////////////////////////////////////////
|
|
|
162 |
///////////////////////////////////////////////////////////////////////////
|
|
|
163 |
|
|
|
164 |
////////////////////////////////////////////////////////
|
|
|
165 |
/// Print the users with no responses
|
|
|
166 |
////////////////////////////////////////////////////////
|
|
|
167 |
$groupselect = groups_print_activity_menu($cm, $url->out(), true);
|
|
|
168 |
|
|
|
169 |
// preparing the table for output
|
|
|
170 |
$baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
|
|
|
171 |
$baseurl->params(array('id'=>$id, 'showall'=>$showall));
|
|
|
172 |
|
|
|
173 |
$tablecolumns = array('userpic', 'fullname', 'status');
|
|
|
174 |
$tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
|
|
|
175 |
|
|
|
176 |
if ($canbulkmessaging) {
|
|
|
177 |
$tablecolumns[] = 'select';
|
|
|
178 |
|
|
|
179 |
// Build the select/deselect all control.
|
|
|
180 |
$selectallid = 'selectall-non-respondents';
|
|
|
181 |
$mastercheckbox = new \core\output\checkbox_toggleall('feedback-non-respondents', true, [
|
|
|
182 |
'id' => $selectallid,
|
|
|
183 |
'name' => $selectallid,
|
|
|
184 |
'value' => 1,
|
|
|
185 |
'label' => get_string('select'),
|
|
|
186 |
// Consistent label to prevent the select column from resizing.
|
|
|
187 |
'selectall' => get_string('select'),
|
|
|
188 |
'deselectall' => get_string('select'),
|
|
|
189 |
'labelclasses' => 'm-0',
|
|
|
190 |
]);
|
|
|
191 |
$tableheaders[] = $OUTPUT->render($mastercheckbox);
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
$table = new flexible_table('feedback-shownonrespondents-'.$course->id);
|
|
|
195 |
|
|
|
196 |
$table->define_columns($tablecolumns);
|
|
|
197 |
$table->define_headers($tableheaders);
|
|
|
198 |
$table->define_baseurl($baseurl);
|
|
|
199 |
|
|
|
200 |
$table->sortable(true, 'lastname', SORT_DESC);
|
|
|
201 |
$table->set_attribute('cellspacing', '0');
|
|
|
202 |
$table->set_attribute('id', 'showentrytable');
|
|
|
203 |
$table->set_attribute('class', 'generaltable generalbox');
|
|
|
204 |
$table->set_control_variables(array(
|
|
|
205 |
TABLE_VAR_SORT => 'ssort',
|
|
|
206 |
TABLE_VAR_IFIRST => 'sifirst',
|
|
|
207 |
TABLE_VAR_ILAST => 'silast',
|
|
|
208 |
TABLE_VAR_PAGE => 'spage'
|
|
|
209 |
));
|
|
|
210 |
|
|
|
211 |
$table->no_sorting('select');
|
|
|
212 |
$table->no_sorting('status');
|
|
|
213 |
|
|
|
214 |
$table->setup();
|
|
|
215 |
|
|
|
216 |
if ($table->get_sql_sort()) {
|
|
|
217 |
$sort = $table->get_sql_sort();
|
|
|
218 |
} else {
|
|
|
219 |
$sort = '';
|
|
|
220 |
}
|
|
|
221 |
|
11 |
efrain |
222 |
$matchcount = count($incompleteusers);
|
1 |
efrain |
223 |
$table->initialbars(false);
|
|
|
224 |
|
|
|
225 |
if ($showall) {
|
|
|
226 |
$startpage = false;
|
|
|
227 |
$pagecount = false;
|
|
|
228 |
} else {
|
|
|
229 |
$table->pagesize($perpage, $matchcount);
|
|
|
230 |
$startpage = $table->get_page_start();
|
|
|
231 |
$pagecount = $table->get_page_size();
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
// Return students record including if they started or not the feedback.
|
11 |
efrain |
235 |
$students = feedback_get_incomplete_users($cm, $currentgroup, $sort, $startpage, $pagecount, true);
|
1 |
efrain |
236 |
//####### viewreports-start
|
|
|
237 |
//print the list of students
|
|
|
238 |
echo $OUTPUT->heading(get_string('non_respondents_students', 'feedback', $matchcount), 4);
|
|
|
239 |
echo isset($groupselect) ? $groupselect : '';
|
|
|
240 |
echo '<div class="clearer"></div>';
|
|
|
241 |
|
|
|
242 |
if (empty($students)) {
|
|
|
243 |
echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
|
|
|
244 |
} else {
|
|
|
245 |
|
|
|
246 |
if ($canbulkmessaging) {
|
|
|
247 |
echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
foreach ($students as $student) {
|
|
|
251 |
//userpicture and link to the profilepage
|
|
|
252 |
$profileurl = $CFG->wwwroot.'/user/view.php?id='.$student->id.'&course='.$course->id;
|
|
|
253 |
$profilelink = '<strong><a href="'.$profileurl.'">'.fullname($student).'</a></strong>';
|
|
|
254 |
$data = array($OUTPUT->user_picture($student, array('courseid' => $course->id)), $profilelink);
|
|
|
255 |
|
|
|
256 |
if ($student->feedbackstarted) {
|
|
|
257 |
$data[] = get_string('started', 'feedback');
|
|
|
258 |
} else {
|
|
|
259 |
$data[] = get_string('not_started', 'feedback');
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
//selections to bulk messaging
|
|
|
263 |
if ($canbulkmessaging) {
|
|
|
264 |
$checkbox = new \core\output\checkbox_toggleall('feedback-non-respondents', false, [
|
|
|
265 |
'id' => 'messageuser-' . $student->id,
|
|
|
266 |
'name' => 'messageuser[]',
|
|
|
267 |
'classes' => 'mr-1',
|
|
|
268 |
'value' => $student->id,
|
|
|
269 |
'label' => get_string('includeuserinrecipientslist', 'mod_feedback', fullname($student)),
|
|
|
270 |
'labelclasses' => 'accesshide',
|
|
|
271 |
]);
|
|
|
272 |
$data[] = $OUTPUT->render($checkbox);
|
|
|
273 |
}
|
|
|
274 |
$table->add_data($data);
|
|
|
275 |
}
|
|
|
276 |
$table->print_html();
|
|
|
277 |
|
|
|
278 |
$allurl = new moodle_url($baseurl);
|
|
|
279 |
|
|
|
280 |
if ($showall) {
|
|
|
281 |
$allurl->param('showall', 0);
|
|
|
282 |
echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
|
|
|
283 |
array(), 'showall');
|
|
|
284 |
|
|
|
285 |
} else if ($matchcount > 0 && $perpage < $matchcount) {
|
|
|
286 |
$allurl->param('showall', 1);
|
|
|
287 |
echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
|
|
|
288 |
}
|
|
|
289 |
if ($canbulkmessaging) {
|
|
|
290 |
echo '<fieldset class="clearfix">';
|
|
|
291 |
echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
|
|
|
292 |
echo '<div>';
|
|
|
293 |
echo '<label for="feedback_subject">'.get_string('subject', 'feedback').' </label>';
|
|
|
294 |
echo '<input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.s($subject).'" />';
|
|
|
295 |
echo '</div>';
|
|
|
296 |
echo $OUTPUT->print_textarea('message', 'edit-message', $message, 15, 25);
|
|
|
297 |
print_string('formathtml');
|
|
|
298 |
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
|
|
|
299 |
echo '<br /><div class="buttons">';
|
|
|
300 |
echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" class="btn btn-secondary" />';
|
|
|
301 |
echo '</div>';
|
|
|
302 |
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
|
|
303 |
echo '<input type="hidden" name="action" value="sendmessage" />';
|
|
|
304 |
echo '<input type="hidden" name="id" value="'.$id.'" />';
|
|
|
305 |
echo '</fieldset>';
|
|
|
306 |
echo '</form>';
|
|
|
307 |
}
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
/// Finish the page
|
|
|
311 |
///////////////////////////////////////////////////////////////////////////
|
|
|
312 |
///////////////////////////////////////////////////////////////////////////
|
|
|
313 |
///////////////////////////////////////////////////////////////////////////
|
|
|
314 |
|
|
|
315 |
echo $OUTPUT->footer();
|
|
|
316 |
|