MDL-26243 calendar: display correct number of repeated events
[moodle.git] / mod / feedback / show_nonrespondents.php
blob9c1d16d2c5ac5f06da825d3dc96caf733e9f0729
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('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 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
69 print_error('badcontext');
72 //we need the coursecontext to allow sending of mass mails
73 if (!$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id)) {
74 print_error('badcontext');
77 require_login($course->id, true, $cm);
79 if (($formdata = data_submitted()) AND !confirm_sesskey()) {
80 print_error('invalidsesskey');
83 require_capability('mod/feedback:viewreports', $context);
85 if ($action == 'sendmessage' AND has_capability('moodle/course:bulkmessaging', $coursecontext)) {
86 $good = 1;
87 if (is_array($messageuser)) {
88 foreach ($messageuser as $userid) {
89 $senduser = $DB->get_record('user', array('id'=>$userid));
90 $eventdata = new stdClass();
91 $eventdata->name = 'message';
92 $eventdata->component = 'mod_feedback';
93 $eventdata->userfrom = $USER;
94 $eventdata->userto = $senduser;
95 $eventdata->subject = $subject;
96 $eventdata->fullmessage = $message;
97 $eventdata->fullmessageformat = FORMAT_PLAIN;
98 $eventdata->fullmessagehtml = '';
99 $eventdata->smallmessage = '';
100 $good = $good && message_send($eventdata);
102 if (!empty($good)) {
103 $msg = $OUTPUT->heading(get_string('messagedselectedusers'));
104 } else {
105 $msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
107 redirect($url, $msg, 4);
108 exit;
112 ////////////////////////////////////////////////////////
113 //get the responses of given user
114 ////////////////////////////////////////////////////////
116 /// Print the page header
117 $strfeedbacks = get_string("modulenameplural", "feedback");
118 $strfeedback = get_string("modulename", "feedback");
120 $PAGE->navbar->add(get_string('show_nonrespondents', 'feedback'));
121 $PAGE->set_heading(format_string($course->fullname));
122 $PAGE->set_title(format_string($feedback->name));
123 echo $OUTPUT->header();
125 require('tabs.php');
127 /// Print the main part of the page
128 ///////////////////////////////////////////////////////////////////////////
129 ///////////////////////////////////////////////////////////////////////////
130 ///////////////////////////////////////////////////////////////////////////
132 ////////////////////////////////////////////////////////
133 /// Print the users with no responses
134 ////////////////////////////////////////////////////////
135 //get the effective groupmode of this course and module
136 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
137 $groupmode = $cm->groupmode;
138 } else {
139 $groupmode = $course->groupmode;
142 $groupselect = groups_print_activity_menu($cm, $url->out(), true);
143 $mygroupid = groups_get_activity_group($cm);
145 // preparing the table for output
146 $baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
147 $baseurl->params(array('id'=>$id, 'showall'=>$showall));
149 $tablecolumns = array('userpic', 'fullname', 'status');
150 $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
152 if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
153 $tablecolumns[] = 'select';
154 $tableheaders[] = get_string('select');
157 $table = new flexible_table('feedback-shownonrespondents-'.$course->id);
159 $table->define_columns($tablecolumns);
160 $table->define_headers($tableheaders);
161 $table->define_baseurl($baseurl);
163 $table->sortable(true, 'lastname', SORT_DESC);
164 $table->set_attribute('cellspacing', '0');
165 $table->set_attribute('id', 'showentrytable');
166 $table->set_attribute('class', 'generaltable generalbox');
167 $table->set_control_variables(array(
168 TABLE_VAR_SORT => 'ssort',
169 TABLE_VAR_IFIRST => 'sifirst',
170 TABLE_VAR_ILAST => 'silast',
171 TABLE_VAR_PAGE => 'spage'
174 $table->no_sorting('select');
175 $table->no_sorting('status');
177 $table->setup();
179 if ($table->get_sql_sort()) {
180 $sort = $table->get_sql_sort();
181 } else {
182 $sort = '';
185 //get students in conjunction with groupmode
186 if ($groupmode > 0) {
187 if ($mygroupid > 0) {
188 $usedgroupid = $mygroupid;
189 } else {
190 $usedgroupid = false;
192 } else {
193 $usedgroupid = false;
196 $matchcount = feedback_count_incomplete_users($cm, $usedgroupid);
197 $table->initialbars(false);
199 if ($showall) {
200 $startpage = false;
201 $pagecount = false;
202 } else {
203 $table->pagesize($perpage, $matchcount);
204 $startpage = $table->get_page_start();
205 $pagecount = $table->get_page_size();
208 $students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount);
209 //####### viewreports-start
210 //print the list of students
211 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
212 echo isset($groupselect) ? $groupselect : '';
213 echo '<div class="clearer"></div>';
214 echo $OUTPUT->box_start('mdl-align');
216 if (!$students) {
217 echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
218 } else {
219 echo print_string('non_respondents_students', 'feedback');
220 echo ' ('.$matchcount.')<hr />';
222 if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
223 echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
225 foreach ($students as $student) {
226 $user = $DB->get_record('user', array('id'=>$student));
227 //userpicture and link to the profilepage
228 $profile_url = $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id;
229 $profilelink = '<strong><a href="'.$profile_url.'">'.fullname($user).'</a></strong>';
230 $data = array ($OUTPUT->user_picture($user, array('courseid'=>$course->id)), $profilelink);
232 if ($DB->record_exists('feedback_completedtmp', array('userid'=>$user->id))) {
233 $data[] = get_string('started', 'feedback');
234 } else {
235 $data[] = get_string('not_started', 'feedback');
238 //selections to bulk messaging
239 if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
240 $data[] = '<input type="checkbox" class="usercheckbox" name="messageuser[]" value="'.$user->id.'" />';
242 $table->add_data($data);
244 $table->print_html();
246 $allurl = new moodle_url($baseurl);
248 if ($showall) {
249 $allurl->param('showall', 0);
250 echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
251 array(), 'showall');
253 } else if ($matchcount > 0 && $perpage < $matchcount) {
254 $allurl->param('showall', 1);
255 echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
257 if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
258 $usehtmleditor = can_use_html_editor();
259 echo '<div class="buttons"><br />';
260 echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> ';
261 echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> ';
262 echo '</div>';
263 echo '<fieldset class="clearfix">';
264 echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
265 echo '<div>';
266 echo '<label for="feedback_subject">'.get_string('subject', 'feedback').'&nbsp;</label>';
267 echo '<input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.$subject.'" />';
268 echo '</div>';
269 print_textarea($usehtmleditor, 15, 25, 30, 10, "message", $message);
270 if ($usehtmleditor) {
271 print_string('formathtml');
272 echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
273 } else {
274 choose_from_menu(format_text_menu(), "format", $format, "");
276 echo '<br /><div class="buttons">';
277 echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" />';
278 echo '</div>';
279 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
280 echo '<input type="hidden" name="action" value="sendmessage" />';
281 echo '<input type="hidden" name="id" value="'.$id.'" />';
282 echo '</fieldset>';
283 echo '</form>';
284 //include the needed js
285 $module = array('name'=>'mod_feedback', 'fullpath'=>'/mod/feedback/feedback.js');
286 $PAGE->requires->js_init_call('M.mod_feedback.init_sendmessage', null, false, $module);
289 echo $OUTPUT->box_end();
290 echo $OUTPUT->box_end();
292 /// Finish the page
293 ///////////////////////////////////////////////////////////////////////////
294 ///////////////////////////////////////////////////////////////////////////
295 ///////////////////////////////////////////////////////////////////////////
297 echo $OUTPUT->footer();