Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/feedback/show_entries.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 $userid = optional_param('userid', false, PARAM_INT);
00034 $do_show = required_param('do_show', PARAM_ALPHA);
00035 $perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT);  // how many per page
00036 $showall = optional_param('showall', false, PARAM_INT);  // should we show all users
00037 // $SESSION->feedback->current_tab = $do_show;
00038 $current_tab = $do_show;
00039 
00041 //get the objects
00043 
00044 if ($userid) {
00045     $formdata->userid = intval($userid);
00046 }
00047 
00048 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
00049     print_error('invalidcoursemodule');
00050 }
00051 
00052 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
00053     print_error('coursemisconf');
00054 }
00055 
00056 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
00057     print_error('invalidcoursemodule');
00058 }
00059 
00060 $url = new moodle_url('/mod/feedback/show_entries.php', array('id'=>$cm->id, 'do_show'=>$do_show));
00061 
00062 $PAGE->set_url($url);
00063 
00064 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
00065         print_error('badcontext');
00066 }
00067 
00068 require_login($course->id, true, $cm);
00069 
00070 if (($formdata = data_submitted()) AND !confirm_sesskey()) {
00071     print_error('invalidsesskey');
00072 }
00073 
00074 require_capability('mod/feedback:viewreports', $context);
00075 
00077 //get the responses of given user
00079 if ($do_show == 'showoneentry') {
00080     //get the feedbackitems
00081     $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id), 'position');
00082 
00083     $params = array('feedback'=>$feedback->id,
00084                     'userid'=>$userid,
00085                     'anonymous_response'=>FEEDBACK_ANONYMOUS_NO);
00086 
00087     $feedbackcompleted = $DB->get_record('feedback_completed', $params); //arb
00088 }
00089 
00091 $strfeedbacks = get_string("modulenameplural", "feedback");
00092 $strfeedback  = get_string("modulename", "feedback");
00093 
00094 $PAGE->set_heading(format_string($course->fullname));
00095 $PAGE->set_title(format_string($feedback->name));
00096 echo $OUTPUT->header();
00097 
00098 require('tabs.php');
00099 
00104 
00108 if ($do_show == 'showentries') {
00109     //print the link to analysis
00110     if (has_capability('mod/feedback:viewreports', $context)) {
00111         //get the effective groupmode of this course and module
00112         if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
00113             $groupmode =  $cm->groupmode;
00114         } else {
00115             $groupmode = $course->groupmode;
00116         }
00117 
00118         $groupselect = groups_print_activity_menu($cm, $url->out(), true);
00119         $mygroupid = groups_get_activity_group($cm);
00120 
00121         // preparing the table for output
00122         $baseurl = new moodle_url('/mod/feedback/show_entries.php');
00123         $baseurl->params(array('id'=>$id, 'do_show'=>$do_show, 'showall'=>$showall));
00124 
00125         $tablecolumns = array('userpic', 'fullname', 'completed_timemodified');
00126         $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('date'));
00127 
00128         if (has_capability('mod/feedback:deletesubmissions', $context)) {
00129             $tablecolumns[] = 'deleteentry';
00130             $tableheaders[] = '';
00131         }
00132 
00133         $table = new flexible_table('feedback-showentry-list-'.$course->id);
00134 
00135         $table->define_columns($tablecolumns);
00136         $table->define_headers($tableheaders);
00137         $table->define_baseurl($baseurl);
00138 
00139         $table->sortable(true, 'lastname', SORT_DESC);
00140         $table->set_attribute('cellspacing', '0');
00141         $table->set_attribute('id', 'showentrytable');
00142         $table->set_attribute('class', 'generaltable generalbox');
00143         $table->set_control_variables(array(
00144                     TABLE_VAR_SORT    => 'ssort',
00145                     TABLE_VAR_IFIRST  => 'sifirst',
00146                     TABLE_VAR_ILAST   => 'silast',
00147                     TABLE_VAR_PAGE    => 'spage'
00148                     ));
00149         $table->setup();
00150 
00151         if ($table->get_sql_sort()) {
00152             $sort = $table->get_sql_sort();
00153         } else {
00154             $sort = '';
00155         }
00156 
00157         list($where, $params) = $table->get_sql_where();
00158         if ($where) {
00159             $where .= ' AND';
00160         }
00161 
00162         //get students in conjunction with groupmode
00163         if ($groupmode > 0) {
00164             if ($mygroupid > 0) {
00165                 $usedgroupid = $mygroupid;
00166             } else {
00167                 $usedgroupid = false;
00168             }
00169         } else {
00170             $usedgroupid = false;
00171         }
00172 
00173         $matchcount = feedback_count_complete_users($cm, $usedgroupid);
00174         $table->initialbars(true);
00175 
00176         if ($showall) {
00177             $startpage = false;
00178             $pagecount = false;
00179         } else {
00180             $table->pagesize($perpage, $matchcount);
00181             $startpage = $table->get_page_start();
00182             $pagecount = $table->get_page_size();
00183         }
00184 
00185         $students = feedback_get_complete_users($cm, $usedgroupid, $where, $params, $sort, $startpage, $pagecount);
00186         $str_analyse = get_string('analysis', 'feedback');
00187         $str_complete = get_string('completed_feedbacks', 'feedback');
00188         $str_course = get_string('course');
00189 
00190         $completed_fb_count = feedback_get_completeds_group_count($feedback, $mygroupid);
00191         if ($feedback->course == SITEID) {
00192             $analysisurl = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id, 'courseid'=>$courseid));
00193             echo $OUTPUT->box_start('mdl-align');
00194             echo '<a href="'.$analysisurl->out().'">';
00195             echo $str_course.' '.$str_analyse.' ('.$str_complete.': '.intval($completed_fb_count).')';
00196             echo '</a>';
00197             echo $OUTPUT->help_icon('viewcompleted', 'feedback');
00198             echo $OUTPUT->box_end();
00199         } else {
00200             $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid));
00201             echo $OUTPUT->box_start('mdl-align');
00202             echo '<a href="'.$analysisurl->out().'">';
00203             echo $str_analyse.' ('.$str_complete.': '.intval($completed_fb_count).')';
00204             echo '</a>';
00205             echo $OUTPUT->box_end();
00206         }
00207     }
00208 
00209     //####### viewreports-start
00210     if (has_capability('mod/feedback:viewreports', $context)) {
00211         //print the list of students
00212         echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
00213         echo isset($groupselect) ? $groupselect : '';
00214         echo '<div class="clearer"></div>';
00215         echo $OUTPUT->box_start('mdl-align');
00216         if (!$students) {
00217             if ($courseid != SITEID) {
00218                 echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
00219             }
00220         } else {
00221             echo print_string('non_anonymous_entries', 'feedback');
00222             echo ' ('.count($students).')<hr />';
00223 
00224             foreach ($students as $student) {
00225                 $params = array('userid'=>$student->id,
00226                                 'feedback'=>$feedback->id,
00227                                 'anonymous_response'=>FEEDBACK_ANONYMOUS_NO);
00228 
00229                 $completed_count = $DB->count_records('feedback_completed', $params);
00230                 if ($completed_count > 0) {
00231 
00232                     //userpicture and link to the profilepage
00233                     $fullname_url = $CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id;
00234                     $profilelink = '<strong><a href="'.$fullname_url.'">'.fullname($student).'</a></strong>';
00235                     $data = array ($OUTPUT->user_picture($student, array('courseid'=>$course->id)), $profilelink);
00236 
00237                     //link to the entry of the user
00238                     $params = array('feedback'=>$feedback->id,
00239                                     'userid'=>$student->id,
00240                                     'anonymous_response'=>FEEDBACK_ANONYMOUS_NO);
00241 
00242                     $feedbackcompleted = $DB->get_record('feedback_completed', $params);
00243                     $showentryurl_params = array('userid'=>$student->id, 'do_show'=>'showoneentry');
00244                     $showentryurl = new moodle_url($url, $showentryurl_params);
00245                     $showentrylink = '<a href="'.$showentryurl->out().'">'.userdate($feedbackcompleted->timemodified).'</a>';
00246                     $data[] = $showentrylink;
00247 
00248                     //link to delete the entry
00249                     if (has_capability('mod/feedback:deletesubmissions', $context)) {
00250                         $delete_url_params = array('id' => $cm->id,
00251                                             'completedid' => $feedbackcompleted->id,
00252                                             'do_show' => 'showoneentry');
00253 
00254                         $deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', $delete_url_params);
00255                         $deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.
00256                                                 get_string('delete_entry', 'feedback').
00257                                             '</a>';
00258                         $data[] = $deleteentrylink;
00259                     }
00260                     $table->add_data($data);
00261                 }
00262             }
00263             $table->print_html();
00264 
00265             $allurl = new moodle_url($baseurl);
00266 
00267             if ($showall) {
00268                 $allurl->param('showall', 0);
00269                 echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
00270                                         array(),
00271                                         'showall');
00272 
00273             } else if ($matchcount > 0 && $perpage < $matchcount) {
00274                 $allurl->param('showall', 1);
00275                 echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)),
00276                                         array(),
00277                                         'showall');
00278             }
00279         }
00280         ?>
00281         <hr />
00282         <table width="100%">
00283             <tr>
00284                 <td align="left" colspan="2">
00285                     <?php
00286                     $params = array('feedback' => $feedback->id,
00287                                     'anonymous_response' => FEEDBACK_ANONYMOUS_YES);
00288 
00289                     $feedback_completeds_count = $DB->count_records('feedback_completed', $params);
00290                     print_string('anonymous_entries', 'feedback');
00291                     echo '&nbsp;('.$feedback_completeds_count.')';
00292                     ?>
00293                 </td>
00294                 <td align="right">
00295                     <?php
00296                         $url_params = array('sesskey'=>sesskey(),
00297                                         'userid'=>0,
00298                                         'do_show'=>'showoneentry',
00299                                         'id'=>$id);
00300                         $aurl = new moodle_url('show_entries_anonym.php', $url_params);
00301                         echo $OUTPUT->single_button($aurl, get_string('show_entries', 'feedback'));
00302                     ?>
00303                 </td>
00304             </tr>
00305         </table>
00306         <?php
00307         echo $OUTPUT->box_end();
00308         echo $OUTPUT->box_end();
00309     }
00310 
00311 }
00315 if ($do_show == 'showoneentry') {
00316     echo $OUTPUT->heading(format_text($feedback->name));
00317 
00318     //print the items
00319     if (is_array($feedbackitems)) {
00320         $align = right_to_left() ? 'right' : 'left';
00321         $usr = $DB->get_record('user', array('id'=>$userid));
00322 
00323         if ($feedbackcompleted) {
00324             echo $OUTPUT->heading(userdate($feedbackcompleted->timemodified).' ('.fullname($usr).')', 3);
00325         } else {
00326             echo $OUTPUT->heading(get_string('not_completed_yet', 'feedback'), 3);
00327         }
00328 
00329         echo $OUTPUT->box_start('feedback_items');
00330         $itemnr = 0;
00331         foreach ($feedbackitems as $feedbackitem) {
00332             //get the values
00333             $params = array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id);
00334             $value = $DB->get_record('feedback_value', $params);
00335             echo $OUTPUT->box_start('feedback_item_box_'.$align);
00336             if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
00337                 $itemnr++;
00338                 echo $OUTPUT->box_start('feedback_item_number_'.$align);
00339                 echo $itemnr;
00340                 echo $OUTPUT->box_end();
00341             }
00342 
00343             if ($feedbackitem->typ != 'pagebreak') {
00344                 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
00345                 if (isset($value->value)) {
00346                     feedback_print_item_show_value($feedbackitem, $value->value);
00347                 } else {
00348                     feedback_print_item_show_value($feedbackitem, false);
00349                 }
00350                 echo $OUTPUT->box_end();
00351             }
00352             echo $OUTPUT->box_end();
00353         }
00354         echo $OUTPUT->box_end();
00355     }
00356     echo $OUTPUT->continue_button(new moodle_url($url, array('do_show'=>'showentries')));
00357 }
00362 
00363 echo $OUTPUT->footer();
00364 
 All Data Structures Namespaces Files Functions Variables Enumerations