MDL-40918 mod_lti: replaced 'view' and 'view all' add_to_log calls with events
[moodle.git] / mod / feedback / show_nonrespondents.php
blob4f3224740d83b2963ec4e3a35c17d5dd80645f10
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.
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/>.
17 /**
18 * print the single entries
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package feedback
25 require_once("../../config.php");
26 require_once("lib.php");
27 require_once($CFG->libdir.'/tablelib.php');
29 ////////////////////////////////////////////////////////
30 //get the params
31 ////////////////////////////////////////////////////////
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 $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';
43 ////////////////////////////////////////////////////////
44 //get the objects
45 ////////////////////////////////////////////////////////
46 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
47 print_error('invalidcoursemodule');
50 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
51 print_error('coursemisconf');
54 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
55 print_error('invalidcoursemodule');
58 //this page only can be shown on nonanonymous feedbacks in courses
59 //we should never reach this page
60 if ($feedback->anonymous != FEEDBACK_ANONYMOUS_NO OR $feedback->course == SITEID) {
61 print_error('error');
64 $url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm->id));
66 $PAGE->set_url($url);
68 $context = context_module::instance($cm->id);
70 //we need the coursecontext to allow sending of mass mails
71 $coursecontext = context_course::instance($course->id);
73 require_login($course, true, $cm);
75 if (($formdata = data_submitted()) AND !confirm_sesskey()) {
76 print_error('invalidsesskey');
79 require_capability('mod/feedback:viewreports', $context);
81 if ($action == 'sendmessage' AND has_capability('moodle/course:bulkmessaging', $coursecontext)) {
82 $shortname = format_string($course->shortname,
83 true,
84 array('context' => $coursecontext));
85 $strfeedbacks = get_string("modulenameplural", "feedback");
87 $htmlmessage = "<body id=\"email\">";
89 $link1 = $CFG->wwwroot.'/course/view.php?id='.$course->id;
90 $link2 = $CFG->wwwroot.'/mod/feedback/index.php?id='.$course->id;
91 $link3 = $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id;
93 $htmlmessage .= '<div class="navbar">'.
94 '<a target="_blank" href="'.$link1.'">'.$shortname.'</a> &raquo; '.
95 '<a target="_blank" href="'.$link2.'">'.$strfeedbacks.'</a> &raquo; '.
96 '<a target="_blank" href="'.$link3.'">'.format_string($feedback->name, true).'</a>'.
97 '</div>';
99 $htmlmessage .= $message;
100 $htmlmessage .= '</body>';
102 $good = 1;
103 if (is_array($messageuser)) {
104 foreach ($messageuser as $userid) {
105 $senduser = $DB->get_record('user', array('id'=>$userid));
106 $eventdata = new stdClass();
107 $eventdata->name = 'message';
108 $eventdata->component = 'mod_feedback';
109 $eventdata->userfrom = $USER;
110 $eventdata->userto = $senduser;
111 $eventdata->subject = $subject;
112 $eventdata->fullmessage = html_to_text($htmlmessage);
113 $eventdata->fullmessageformat = FORMAT_PLAIN;
114 $eventdata->fullmessagehtml = $htmlmessage;
115 $eventdata->smallmessage = '';
116 $good = $good && message_send($eventdata);
118 if (!empty($good)) {
119 $msg = $OUTPUT->heading(get_string('messagedselectedusers'));
120 } else {
121 $msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
123 redirect($url, $msg, 4);
124 exit;
128 ////////////////////////////////////////////////////////
129 //get the responses of given user
130 ////////////////////////////////////////////////////////
132 /// Print the page header
133 $PAGE->navbar->add(get_string('show_nonrespondents', 'feedback'));
134 $PAGE->set_heading(format_string($course->fullname));
135 $PAGE->set_title(format_string($feedback->name));
136 echo $OUTPUT->header();
138 require('tabs.php');
140 /// Print the main part of the page
141 ///////////////////////////////////////////////////////////////////////////
142 ///////////////////////////////////////////////////////////////////////////
143 ///////////////////////////////////////////////////////////////////////////
145 ////////////////////////////////////////////////////////
146 /// Print the users with no responses
147 ////////////////////////////////////////////////////////
148 //get the effective groupmode of this course and module
149 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
150 $groupmode = $cm->groupmode;
151 } else {
152 $groupmode = $course->groupmode;
155 $groupselect = groups_print_activity_menu($cm, $url->out(), true);
156 $mygroupid = groups_get_activity_group($cm);
158 // preparing the table for output
159 $baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
160 $baseurl->params(array('id'=>$id, 'showall'=>$showall));
162 $tablecolumns = array('userpic', 'fullname', 'status');
163 $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
165 if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
166 $tablecolumns[] = 'select';
167 $tableheaders[] = get_string('select');
170 $table = new flexible_table('feedback-shownonrespondents-'.$course->id);
172 $table->define_columns($tablecolumns);
173 $table->define_headers($tableheaders);
174 $table->define_baseurl($baseurl);
176 $table->sortable(true, 'lastname', SORT_DESC);
177 $table->set_attribute('cellspacing', '0');
178 $table->set_attribute('id', 'showentrytable');
179 $table->set_attribute('class', 'generaltable generalbox');
180 $table->set_control_variables(array(
181 TABLE_VAR_SORT => 'ssort',
182 TABLE_VAR_IFIRST => 'sifirst',
183 TABLE_VAR_ILAST => 'silast',
184 TABLE_VAR_PAGE => 'spage'
187 $table->no_sorting('select');
188 $table->no_sorting('status');
190 $table->setup();
192 if ($table->get_sql_sort()) {
193 $sort = $table->get_sql_sort();
194 } else {
195 $sort = '';
198 //get students in conjunction with groupmode
199 if ($groupmode > 0) {
200 if ($mygroupid > 0) {
201 $usedgroupid = $mygroupid;
202 } else {
203 $usedgroupid = false;
205 } else {
206 $usedgroupid = false;
209 $matchcount = feedback_count_incomplete_users($cm, $usedgroupid);
210 $table->initialbars(false);
212 if ($showall) {
213 $startpage = false;
214 $pagecount = false;
215 } else {
216 $table->pagesize($perpage, $matchcount);
217 $startpage = $table->get_page_start();
218 $pagecount = $table->get_page_size();
221 $students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount);
222 //####### viewreports-start
223 //print the list of students
224 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
225 echo isset($groupselect) ? $groupselect : '';
226 echo '<div class="clearer"></div>';
227 echo $OUTPUT->box_start('mdl-align');
229 if (!$students) {
230 echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
231 } else {
232 echo print_string('non_respondents_students', 'feedback');
233 echo ' ('.$matchcount.')<hr />';
235 if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
236 echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
238 foreach ($students as $student) {
239 $user = $DB->get_record('user', array('id'=>$student));
240 //userpicture and link to the profilepage
241 $profile_url = $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id;
242 $profilelink = '<strong><a href="'.$profile_url.'">'.fullname($user).'</a></strong>';
243 $data = array ($OUTPUT->user_picture($user, array('courseid'=>$course->id)), $profilelink);
245 if ($DB->record_exists('feedback_completedtmp', array('userid'=>$user->id))) {
246 $data[] = get_string('started', 'feedback');
247 } else {
248 $data[] = get_string('not_started', 'feedback');
251 //selections to bulk messaging
252 if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
253 $data[] = '<input type="checkbox" class="usercheckbox" name="messageuser[]" value="'.$user->id.'" />';
255 $table->add_data($data);
257 $table->print_html();
259 $allurl = new moodle_url($baseurl);
261 if ($showall) {
262 $allurl->param('showall', 0);
263 echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
264 array(), 'showall');
266 } else if ($matchcount > 0 && $perpage < $matchcount) {
267 $allurl->param('showall', 1);
268 echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
270 if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
271 echo '<div class="buttons"><br />';
272 echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> ';
273 echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> ';
274 echo '</div>';
275 echo '<fieldset class="clearfix">';
276 echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
277 echo '<div>';
278 echo '<label for="feedback_subject">'.get_string('subject', 'feedback').'&nbsp;</label>';
279 echo '<input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.$subject.'" />';
280 echo '</div>';
281 print_textarea(true, 15, 25, 30, 10, "message", $message);
282 print_string('formathtml');
283 echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
284 echo '<br /><div class="buttons">';
285 echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" />';
286 echo '</div>';
287 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
288 echo '<input type="hidden" name="action" value="sendmessage" />';
289 echo '<input type="hidden" name="id" value="'.$id.'" />';
290 echo '</fieldset>';
291 echo '</form>';
292 //include the needed js
293 $module = array('name'=>'mod_feedback', 'fullpath'=>'/mod/feedback/feedback.js');
294 $PAGE->requires->js_init_call('M.mod_feedback.init_sendmessage', null, false, $module);
297 echo $OUTPUT->box_end();
298 echo $OUTPUT->box_end();
300 /// Finish the page
301 ///////////////////////////////////////////////////////////////////////////
302 ///////////////////////////////////////////////////////////////////////////
303 ///////////////////////////////////////////////////////////////////////////
305 echo $OUTPUT->footer();