forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_nonrespondents.php
295 lines (247 loc) · 11.2 KB
/
show_nonrespondents.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?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/>.
/**
* print the single entries
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package mod_feedback
*/
require_once("../../config.php");
require_once("lib.php");
require_once($CFG->libdir.'/tablelib.php');
////////////////////////////////////////////////////////
//get the params
////////////////////////////////////////////////////////
$id = required_param('id', PARAM_INT);
$subject = optional_param('subject', '', PARAM_CLEANHTML);
$message = optional_param('message', '', PARAM_CLEANHTML);
$format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
$messageuser = optional_param_array('messageuser', false, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
$perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT); // how many per page
$showall = optional_param('showall', false, PARAM_INT); // should we show all users
// $SESSION->feedback->current_tab = $do_show;
$current_tab = 'nonrespondents';
////////////////////////////////////////////////////////
//get the objects
////////////////////////////////////////////////////////
list ($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
print_error('invalidcoursemodule');
}
//this page only can be shown on nonanonymous feedbacks in courses
//we should never reach this page
if ($feedback->anonymous != FEEDBACK_ANONYMOUS_NO OR $feedback->course == SITEID) {
print_error('error');
}
$url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm->id));
$PAGE->set_url($url);
$context = context_module::instance($cm->id);
//we need the coursecontext to allow sending of mass mails
$coursecontext = context_course::instance($course->id);
require_login($course, true, $cm);
if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey');
}
require_capability('mod/feedback:viewreports', $context);
if ($action == 'sendmessage' AND has_capability('moodle/course:bulkmessaging', $coursecontext)) {
$shortname = format_string($course->shortname,
true,
array('context' => $coursecontext));
$strfeedbacks = get_string("modulenameplural", "feedback");
$htmlmessage = "<body id=\"email\">";
$link1 = $CFG->wwwroot.'/course/view.php?id='.$course->id;
$link2 = $CFG->wwwroot.'/mod/feedback/index.php?id='.$course->id;
$link3 = $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id;
$htmlmessage .= '<div class="navbar">'.
'<a target="_blank" href="'.$link1.'">'.$shortname.'</a> » '.
'<a target="_blank" href="'.$link2.'">'.$strfeedbacks.'</a> » '.
'<a target="_blank" href="'.$link3.'">'.format_string($feedback->name, true).'</a>'.
'</div>';
$htmlmessage .= $message;
$htmlmessage .= '</body>';
$good = 1;
if (is_array($messageuser)) {
foreach ($messageuser as $userid) {
$senduser = $DB->get_record('user', array('id'=>$userid));
$eventdata = new stdClass();
$eventdata->name = 'message';
$eventdata->component = 'mod_feedback';
$eventdata->userfrom = $USER;
$eventdata->userto = $senduser;
$eventdata->subject = $subject;
$eventdata->fullmessage = html_to_text($htmlmessage);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = $htmlmessage;
$eventdata->smallmessage = '';
$good = $good && message_send($eventdata);
}
if (!empty($good)) {
$msg = $OUTPUT->heading(get_string('messagedselectedusers'));
} else {
$msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
}
redirect($url, $msg, 4);
exit;
}
}
////////////////////////////////////////////////////////
//get the responses of given user
////////////////////////////////////////////////////////
/// Print the page header
$PAGE->set_heading($course->fullname);
$PAGE->set_title($feedback->name);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($feedback->name));
require('tabs.php');
/// Print the main part of the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
/// Print the users with no responses
////////////////////////////////////////////////////////
//get the effective groupmode of this course and module
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
}
$groupselect = groups_print_activity_menu($cm, $url->out(), true);
$mygroupid = groups_get_activity_group($cm);
// preparing the table for output
$baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
$baseurl->params(array('id'=>$id, 'showall'=>$showall));
$tablecolumns = array('userpic', 'fullname', 'status');
$tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
$tablecolumns[] = 'select';
$tableheaders[] = get_string('select');
}
$table = new flexible_table('feedback-shownonrespondents-'.$course->id);
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($baseurl);
$table->sortable(true, 'lastname', SORT_DESC);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'showentrytable');
$table->set_attribute('class', 'generaltable generalbox');
$table->set_control_variables(array(
TABLE_VAR_SORT => 'ssort',
TABLE_VAR_IFIRST => 'sifirst',
TABLE_VAR_ILAST => 'silast',
TABLE_VAR_PAGE => 'spage'
));
$table->no_sorting('select');
$table->no_sorting('status');
$table->setup();
if ($table->get_sql_sort()) {
$sort = $table->get_sql_sort();
} else {
$sort = '';
}
//get students in conjunction with groupmode
if ($groupmode > 0) {
if ($mygroupid > 0) {
$usedgroupid = $mygroupid;
} else {
$usedgroupid = false;
}
} else {
$usedgroupid = false;
}
$matchcount = feedback_count_incomplete_users($cm, $usedgroupid);
$table->initialbars(false);
if ($showall) {
$startpage = false;
$pagecount = false;
} else {
$table->pagesize($perpage, $matchcount);
$startpage = $table->get_page_start();
$pagecount = $table->get_page_size();
}
$students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount);
//####### viewreports-start
//print the list of students
echo $OUTPUT->heading(get_string('non_respondents_students', 'feedback', $matchcount), 4);
echo isset($groupselect) ? $groupselect : '';
echo '<div class="clearer"></div>';
if (!$students) {
echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
} else {
if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
}
foreach ($students as $student) {
$user = $DB->get_record('user', array('id'=>$student));
//userpicture and link to the profilepage
$profile_url = $CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id;
$profilelink = '<strong><a href="'.$profile_url.'">'.fullname($user).'</a></strong>';
$data = array ($OUTPUT->user_picture($user, array('courseid'=>$course->id)), $profilelink);
if ($DB->record_exists('feedback_completedtmp', array('userid'=>$user->id))) {
$data[] = get_string('started', 'feedback');
} else {
$data[] = get_string('not_started', 'feedback');
}
//selections to bulk messaging
if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
$data[] = '<input type="checkbox" class="usercheckbox" name="messageuser[]" value="'.$user->id.'" />';
}
$table->add_data($data);
}
$table->print_html();
$allurl = new moodle_url($baseurl);
if ($showall) {
$allurl->param('showall', 0);
echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
array(), 'showall');
} else if ($matchcount > 0 && $perpage < $matchcount) {
$allurl->param('showall', 1);
echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
}
if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
echo '<div class="buttons"><br />';
echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> ';
echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> ';
echo '</div>';
echo '<fieldset class="clearfix">';
echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
echo '<div>';
echo '<label for="feedback_subject">'.get_string('subject', 'feedback').' </label>';
echo '<input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.$subject.'" />';
echo '</div>';
print_textarea(true, 15, 25, 30, 10, "message", $message);
print_string('formathtml');
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
echo '<br /><div class="buttons">';
echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" />';
echo '</div>';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="action" value="sendmessage" />';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '</fieldset>';
echo '</form>';
//include the needed js
$module = array('name'=>'mod_feedback', 'fullpath'=>'/mod/feedback/feedback.js');
$PAGE->requires->js_init_call('M.mod_feedback.init_sendmessage', null, false, $module);
}
}
/// Finish the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->footer();