Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/feedback/show_nonrespondents.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00025 require_once("../../config.php");
00026 require_once("lib.php");
00027 require_once($CFG->libdir.'/tablelib.php');
00028 
00030 //get the params
00032 $id = required_param('id', PARAM_INT);
00033 $subject = optional_param('subject', '', PARAM_CLEANHTML);
00034 $message = optional_param('message', '', PARAM_CLEANHTML);
00035 $format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
00036 $messageuser = optional_param('messageuser', false, PARAM_INT);
00037 $action = optional_param('action', '', PARAM_ALPHA);
00038 $perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT);  // how many per page
00039 $showall = optional_param('showall', false, PARAM_INT);  // should we show all users
00040 // $SESSION->feedback->current_tab = $do_show;
00041 $current_tab = 'nonrespondents';
00042 
00044 //get the objects
00046 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
00047     print_error('invalidcoursemodule');
00048 }
00049 
00050 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
00051     print_error('coursemisconf');
00052 }
00053 
00054 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
00055     print_error('invalidcoursemodule');
00056 }
00057 
00058 //this page only can be shown on nonanonymous feedbacks in courses
00059 //we should never reach this page
00060 if ($feedback->anonymous != FEEDBACK_ANONYMOUS_NO OR $feedback->course == SITEID) {
00061     print_error('error');
00062 }
00063 
00064 $url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm->id));
00065 
00066 $PAGE->set_url($url);
00067 
00068 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
00069         print_error('badcontext');
00070 }
00071 
00072 //we need the coursecontext to allow sending of mass mails
00073 if (!$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id)) {
00074         print_error('badcontext');
00075 }
00076 
00077 require_login($course->id, true, $cm);
00078 
00079 if (($formdata = data_submitted()) AND !confirm_sesskey()) {
00080     print_error('invalidsesskey');
00081 }
00082 
00083 require_capability('mod/feedback:viewreports', $context);
00084 
00085 if ($action == 'sendmessage' AND has_capability('moodle/course:bulkmessaging', $coursecontext)) {
00086     $good = 1;
00087     if (is_array($messageuser)) {
00088         foreach ($messageuser as $userid) {
00089             $senduser = $DB->get_record('user', array('id'=>$userid));
00090             $eventdata = new stdClass();
00091             $eventdata->name             = 'message';
00092             $eventdata->component        = 'mod_feedback';
00093             $eventdata->userfrom         = $USER;
00094             $eventdata->userto           = $senduser;
00095             $eventdata->subject          = $subject;
00096             $eventdata->fullmessage      = $message;
00097             $eventdata->fullmessageformat = FORMAT_PLAIN;
00098             $eventdata->fullmessagehtml  = '';
00099             $eventdata->smallmessage     = '';
00100             $good = $good && message_send($eventdata);
00101         }
00102         if (!empty($good)) {
00103             $msg = $OUTPUT->heading(get_string('messagedselectedusers'));
00104         } else {
00105             $msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
00106         }
00107         redirect($url, $msg, 4);
00108         exit;
00109     }
00110 }
00111 
00113 //get the responses of given user
00115 
00117 $strfeedbacks = get_string("modulenameplural", "feedback");
00118 $strfeedback  = get_string("modulename", "feedback");
00119 
00120 $PAGE->navbar->add(get_string('show_nonrespondents', 'feedback'));
00121 $PAGE->set_heading(format_string($course->fullname));
00122 $PAGE->set_title(format_string($feedback->name));
00123 echo $OUTPUT->header();
00124 
00125 require('tabs.php');
00126 
00131 
00135 //get the effective groupmode of this course and module
00136 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
00137     $groupmode =  $cm->groupmode;
00138 } else {
00139     $groupmode = $course->groupmode;
00140 }
00141 
00142 $groupselect = groups_print_activity_menu($cm, $url->out(), true);
00143 $mygroupid = groups_get_activity_group($cm);
00144 
00145 // preparing the table for output
00146 $baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
00147 $baseurl->params(array('id'=>$id, 'showall'=>$showall));
00148 
00149 $tablecolumns = array('userpic', 'fullname', 'status');
00150 $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
00151 
00152 if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
00153     $tablecolumns[] = 'select';
00154     $tableheaders[] = get_string('select');
00155 }
00156 
00157 $table = new flexible_table('feedback-shownonrespondents-'.$course->id);
00158 
00159 $table->define_columns($tablecolumns);
00160 $table->define_headers($tableheaders);
00161 $table->define_baseurl($baseurl);
00162 
00163 $table->sortable(true, 'lastname', SORT_DESC);
00164 $table->set_attribute('cellspacing', '0');
00165 $table->set_attribute('id', 'showentrytable');
00166 $table->set_attribute('class', 'generaltable generalbox');
00167 $table->set_control_variables(array(
00168             TABLE_VAR_SORT    => 'ssort',
00169             TABLE_VAR_IFIRST  => 'sifirst',
00170             TABLE_VAR_ILAST   => 'silast',
00171             TABLE_VAR_PAGE    => 'spage'
00172             ));
00173 
00174 $table->no_sorting('select');
00175 $table->no_sorting('status');
00176 
00177 $table->setup();
00178 
00179 if ($table->get_sql_sort()) {
00180     $sort = $table->get_sql_sort();
00181 } else {
00182     $sort = '';
00183 }
00184 
00185 //get students in conjunction with groupmode
00186 if ($groupmode > 0) {
00187     if ($mygroupid > 0) {
00188         $usedgroupid = $mygroupid;
00189     } else {
00190         $usedgroupid = false;
00191     }
00192 } else {
00193     $usedgroupid = false;
00194 }
00195 
00196 $matchcount = feedback_count_incomplete_users($cm, $usedgroupid);
00197 $table->initialbars(false);
00198 
00199 if ($showall) {
00200     $startpage = false;
00201     $pagecount = false;
00202 } else {
00203     $table->pagesize($perpage, $matchcount);
00204     $startpage = $table->get_page_start();
00205     $pagecount = $table->get_page_size();
00206 }
00207 
00208 $students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount);
00209 //####### viewreports-start
00210 //print the list of students
00211 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
00212 echo isset($groupselect) ? $groupselect : '';
00213 echo '<div class="clearer"></div>';
00214 echo $OUTPUT->box_start('mdl-align');
00215 
00216 if (!$students) {
00217     echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
00218 } else {
00219     echo print_string('non_respondents_students', 'feedback');
00220     echo ' ('.$matchcount.')<hr />';
00221 
00222     if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
00223         echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
00224     }
00225     foreach ($students as $student) {
00226         $user = $DB->get_record('user', array('id'=>$student));
00227         //userpicture and link to the profilepage
00228         $profile_url = $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id;
00229         $profilelink = '<strong><a href="'.$profile_url.'">'.fullname($user).'</a></strong>';
00230         $data = array ($OUTPUT->user_picture($user, array('courseid'=>$course->id)), $profilelink);
00231 
00232         if ($DB->record_exists('feedback_completedtmp', array('userid'=>$user->id))) {
00233             $data[] = get_string('started', 'feedback');
00234         } else {
00235             $data[] = get_string('not_started', 'feedback');
00236         }
00237 
00238         //selections to bulk messaging
00239         if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
00240             $data[] = '<input type="checkbox" class="usercheckbox" name="messageuser[]" value="'.$user->id.'" />';
00241         }
00242         $table->add_data($data);
00243     }
00244     $table->print_html();
00245 
00246     $allurl = new moodle_url($baseurl);
00247 
00248     if ($showall) {
00249         $allurl->param('showall', 0);
00250         echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
00251                                     array(), 'showall');
00252 
00253     } else if ($matchcount > 0 && $perpage < $matchcount) {
00254         $allurl->param('showall', 1);
00255         echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
00256     }
00257     if (has_capability('moodle/course:bulkmessaging', $coursecontext)) {
00258         $usehtmleditor = can_use_html_editor();
00259         echo '<div class="buttons"><br />';
00260         echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> ';
00261         echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> ';
00262         echo '</div>';
00263         echo '<fieldset class="clearfix">';
00264         echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
00265         echo '<div>';
00266         echo '<label for="feedback_subject">'.get_string('subject', 'feedback').'&nbsp;</label>';
00267         echo '<input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.$subject.'" />';
00268         echo '</div>';
00269         print_textarea($usehtmleditor, 15, 25, 30, 10, "message", $message);
00270         if ($usehtmleditor) {
00271             print_string('formathtml');
00272             echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
00273         } else {
00274             choose_from_menu(format_text_menu(), "format", $format, "");
00275         }
00276         echo '<br /><div class="buttons">';
00277         echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" />';
00278         echo '</div>';
00279         echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
00280         echo '<input type="hidden" name="action" value="sendmessage" />';
00281         echo '<input type="hidden" name="id" value="'.$id.'" />';
00282         echo '</fieldset>';
00283         echo '</form>';
00284         //include the needed js
00285         $module = array('name'=>'mod_feedback', 'fullpath'=>'/mod/feedback/feedback.js');
00286         $PAGE->requires->js_init_call('M.mod_feedback.init_sendmessage', null, false, $module);
00287     }
00288 }
00289 echo $OUTPUT->box_end();
00290 echo $OUTPUT->box_end();
00291 
00296 
00297 echo $OUTPUT->footer();
00298 
 All Data Structures Namespaces Files Functions Variables Enumerations