92a3d82dbfb53478ff3e6e4da0f05d00c638c0a2
[moodle.git] / mod / feedback / show_nonrespondents.php
1 <?php
3     /**
4      * print the single entries
5      *
6      * @author Andreas Grabs
7      * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8      * @package feedback
9      */
11     require_once("../../config.php");
12     require_once("lib.php");
13     require_once($CFG->libdir.'/tablelib.php');
15     ////////////////////////////////////////////////////////
16     //get the params
17     ////////////////////////////////////////////////////////
18     $id = required_param('id', PARAM_INT);
19     $subject = optional_param('subject','',PARAM_CLEANHTML);
20     $message = optional_param('message','',PARAM_CLEANHTML);
21     $format = optional_param('format',FORMAT_MOODLE,PARAM_INT);
22     $messageuser = optional_param('messageuser', false, PARAM_INT);
23     $action = optional_param('action', '',PARAM_ALPHA);
24     $perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT);  // how many per page
25     $showall = optional_param('showall', false, PARAM_INT);  // should we show all users
26     // $SESSION->feedback->current_tab = $do_show;
27     $current_tab = 'nonrespondents';
29     ////////////////////////////////////////////////////////
30     //get the objects
31     ////////////////////////////////////////////////////////
32     if (! $cm = get_coursemodule_from_id('feedback', $id)) {
33         print_error('invalidcoursemodule');
34     }
36     if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
37         print_error('coursemisconf');
38     }
40     if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
41         print_error('invalidcoursemodule');
42     }
44     //this page only can be shown on nonanonymous feedbacks in courses
45     //we should never reach this page
46     if($feedback->anonymous != FEEDBACK_ANONYMOUS_NO OR $feedback->course == SITEID) {
47         print_error('error');
48     }
50     $url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm->id));
52     $PAGE->set_url($url);
54     if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
55             print_error('badcontext');
56     }
58     //we need the coursecontext to allow sending of mass mails
59     if (!$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id)) {
60             print_error('badcontext');
61     }
63     require_login($course->id, true, $cm);
65     if(($formdata = data_submitted()) AND !confirm_sesskey()) {
66         print_error('invalidsesskey');
67     }
69     require_capability('mod/feedback:viewreports', $context);
71     if($action == 'sendmessage' AND has_capability('moodle/course:bulkmessaging', $coursecontext)) {
72         // require_once($CFG->dirroot.'/message/lib.php');
73         $good = 1;
74         if(is_array($messageuser)) {
75             foreach ($messageuser as $userid) {
76                 $senduser = $DB->get_record('user', array('id'=>$userid));
77                 $eventdata = new stdClass();
78                 $eventdata->name             = 'message';
79                 $eventdata->component        = 'mod_feedback';
80                 $eventdata->userfrom         = $USER;
81                 $eventdata->userto           = $senduser;
82                 $eventdata->subject          = $subject;
83                 $eventdata->fullmessage      = $message;
84                 $eventdata->fullmessageformat = FORMAT_PLAIN;
85                 $eventdata->fullmessagehtml  = '';
86                 $eventdata->smallmessage     = '';
87                 $good = $good && message_send($eventdata);
88             }
89             if (!empty($good)) {
90                 $msg = $OUTPUT->heading(get_string('messagedselectedusers'));
91             } else {
92                 $msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
93             }
94             redirect($url, $msg, 4);
95             exit;
96         }
97     }
99     ////////////////////////////////////////////////////////
100     //get the responses of given user
101     ////////////////////////////////////////////////////////
103     /// Print the page header
104     $strfeedbacks = get_string("modulenameplural", "feedback");
105     $strfeedback  = get_string("modulename", "feedback");
107     $PAGE->navbar->add(get_string('show_nonrespondents','feedback'));
108     $PAGE->set_heading(format_string($course->fullname));
109     $PAGE->set_title(format_string($feedback->name));
110     echo $OUTPUT->header();
112     include('tabs.php');
114     /// Print the main part of the page
115     ///////////////////////////////////////////////////////////////////////////
116     ///////////////////////////////////////////////////////////////////////////
117     ///////////////////////////////////////////////////////////////////////////
119     ////////////////////////////////////////////////////////
120     /// Print the users with no responses
121     ////////////////////////////////////////////////////////
122     //get the effective groupmode of this course and module
123     if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
124         $groupmode =  $cm->groupmode;
125     } else {
126         $groupmode = $course->groupmode;
127     }
129     $groupselect = groups_print_activity_menu($cm, $url->out(), true);
130     $mygroupid = groups_get_activity_group($cm);
132     // preparing the table for output
133     $baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
134     $baseurl->params(array('id'=>$id, 'showall'=>$showall));
136     $tablecolumns = array('userpic', 'fullname', 'status');
137     $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
139     if(has_capability('moodle/course:bulkmessaging', $coursecontext)) {
140         $tablecolumns[] = 'select';
141         $tableheaders[] = get_string('select');
142     }
144     $table = new flexible_table('feedback-shownonrespondents-'.$course->id);
146     $table->define_columns($tablecolumns);
147     $table->define_headers($tableheaders);
148     $table->define_baseurl($baseurl);
150     $table->sortable(true, 'lastname', SORT_DESC);
151     $table->set_attribute('cellspacing', '0');
152     $table->set_attribute('id', 'showentrytable');
153     $table->set_attribute('class', 'generaltable generalbox');
154     $table->set_control_variables(array(
155                 TABLE_VAR_SORT    => 'ssort',
156                 TABLE_VAR_IFIRST  => 'sifirst',
157                 TABLE_VAR_ILAST   => 'silast',
158                 TABLE_VAR_PAGE    => 'spage'
159                 ));
161     $table->no_sorting('select');
162     $table->no_sorting('status');
164     $table->setup();
166     if($table->get_sql_sort()) {
167         $sort = $table->get_sql_sort();
168     }else {
169         $sort = '';
170     }
172     //get students in conjunction with groupmode
173     if($groupmode > 0) {
174         if($mygroupid > 0) {
175             $usedgroupid = $mygroupid;
176         } else {
177             $usedgroupid = false;
178         }
179     }else {
180         $usedgroupid = false;
181     }
183     $matchcount = feedback_count_incomplete_users($cm, $usedgroupid);
184     $table->initialbars(false);
186     if($showall) {
187         $startpage = false;
188         $pagecount = false;
189     }else {
190         $table->pagesize($perpage, $matchcount);
191         $startpage = $table->get_page_start();
192         $pagecount = $table->get_page_size();
193     }
195     $students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount);
196     //####### viewreports-start
197     //print the list of students
198     echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
199     echo isset($groupselect) ? $groupselect : '';
200     echo '<div class="clearer"></div>';
201     echo $OUTPUT->box_start('mdl-align');
202     // echo '<table><tr><td width="400">';
203     if (!$students) {
204         echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
205     } else{
206         echo print_string('non_respondents_students', 'feedback');
207         echo ' ('.$matchcount.')<hr />';
209         if(has_capability('moodle/course:bulkmessaging', $coursecontext)) {
210             echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
211         }
212         foreach ($students as $student){
213             $user = $DB->get_record('user', array('id'=>$student));
214             //userpicture and link to the profilepage
215             $profilelink = '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.fullname($user).'</a></strong>';
216             $data = array ($OUTPUT->user_picture($user, array('courseid'=>$course->id)), $profilelink);
218             if($DB->record_exists('feedback_completedtmp', array('userid'=>$user->id))) {
219                 $data[] = get_string('started', 'feedback');
220             }else {
221                 $data[] = get_string('not_started', 'feedback');
222             }
224             //selections to bulk messaging
225             if(has_capability('moodle/course:bulkmessaging', $coursecontext)) {
226                 $data[] = '<input type="checkbox" class="usercheckbox" name="messageuser[]" value="'.$user->id.'" />';
227             }
228             $table->add_data($data);
229         }
230         $table->print_html();
232         $allurl = new moodle_url($baseurl);
234         if ($showall) {
235             $allurl->param('showall', 0);
236             echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)), array(), 'showall');
237         } else if ($matchcount > 0 && $perpage < $matchcount) {
238             $allurl->param('showall', 1);
239             echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
240         }
241         if(has_capability('moodle/course:bulkmessaging', $coursecontext)) {
242             $usehtmleditor = can_use_html_editor();
243             echo '<br /><div class="buttons">';
244             echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> ';
245             echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> ';
246             echo '</div';
247             echo '<fieldset class="clearfix">';
248             echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
249             echo '<div><label for="feedback_subject">'.get_string('subject', 'feedback').'&nbsp;</label><input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.$subject.'" /></div>';
250             print_textarea($usehtmleditor, 15, 25, 30, 10, "message", $message);
251             if ($usehtmleditor) {
252                 print_string('formathtml');
253                 echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
254             } else {
255                 choose_from_menu(format_text_menu(), "format", $format, "");
256             }
257             echo '<br /><div class="buttons">';
258             echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" />';
259             echo '</div>';
260             echo '</fieldset>';
261             echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
262             echo '<input type="hidden" name="action" value="sendmessage" />';
263             echo '<input type="hidden" name="id" value="'.$id.'" />';
264             echo '</form>';
265             //include the needed js
266             $module = array('name'=>'mod_feedback', 'fullpath'=>'/mod/feedback/feedback.js');
267             $PAGE->requires->js_init_call('M.mod_feedback.init_sendmessage', null, false, $module);
268         }
269     }
270     echo $OUTPUT->box_end();
271     echo $OUTPUT->box_end();
273     /// Finish the page
274     ///////////////////////////////////////////////////////////////////////////
275     ///////////////////////////////////////////////////////////////////////////
276     ///////////////////////////////////////////////////////////////////////////
278     echo $OUTPUT->footer();
280 ?>