Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/feedback/show_entries_anonym.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 
00029 $id = required_param('id', PARAM_INT);
00030 $showcompleted = optional_param('showcompleted', false, PARAM_INT);
00031 $do_show = optional_param('do_show', false, PARAM_ALPHA);
00032 $perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT);  // how many per page
00033 $showall = optional_param('showall', false, PARAM_INT);  // should we show all users
00034 
00035 $current_tab = $do_show;
00036 
00037 $url = new moodle_url('/mod/feedback/show_entries_anonym.php', array('id'=>$id));
00038 // if ($userid !== '') {
00039     // $url->param('userid', $userid);
00040 // }
00041 $PAGE->set_url($url);
00042 
00043 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
00044     print_error('invalidcoursemodule');
00045 }
00046 
00047 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
00048     print_error('coursemisconf');
00049 }
00050 
00051 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
00052     print_error('invalidcoursemodule');
00053 }
00054 
00055 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
00056         print_error('badcontext');
00057 }
00058 
00059 require_login($course->id, true, $cm);
00060 
00061 require_capability('mod/feedback:viewreports', $context);
00062 
00064 $strfeedbacks = get_string("modulenameplural", "feedback");
00065 $strfeedback  = get_string("modulename", "feedback");
00066 
00067 $PAGE->set_heading(format_string($course->fullname));
00068 $PAGE->set_title(format_string($feedback->name));
00069 echo $OUTPUT->header();
00070 
00075 require('tabs.php');
00076 
00077 echo $OUTPUT->heading(format_text($feedback->name));
00078 
00079 //print the list with anonymous completeds
00080 if (!$showcompleted) {
00081 
00082     //get the completeds
00083     // if a new anonymous record has not been assigned a random response number
00084     $params = array('feedback'=>$feedback->id,
00085                     'random_response'=>0,
00086                     'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
00087 
00088     if ($feedbackcompleteds = $DB->get_records('feedback_completed', $params, 'random_response')) {
00089         //then get all of the anonymous records and go through them
00090         $params = array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
00091         $feedbackcompleteds = $DB->get_records('feedback_completed', $params, 'id'); //arb
00092         shuffle($feedbackcompleteds);
00093         $num = 1;
00094         foreach ($feedbackcompleteds as $compl) {
00095             $compl->random_response = $num;
00096             $DB->update_record('feedback_completed', $compl);
00097             $num++;
00098         }
00099     }
00100 
00101     $params = array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES);
00102     $feedbackcompletedscount = $DB->count_records('feedback_completed', $params);
00103 
00104     // preparing the table for output
00105     $baseurl = new moodle_url('/mod/feedback/show_entries_anonym.php');
00106     $baseurl->params(array('id'=>$id, 'do_show'=>$do_show, 'showall'=>$showall));
00107 
00108     $tablecolumns = array('response', 'showresponse');
00109     $tableheaders = array('', '');
00110 
00111     if (has_capability('mod/feedback:deletesubmissions', $context)) {
00112         $tablecolumns[] = 'deleteentry';
00113         $tableheaders[] = '';
00114     }
00115 
00116     $table = new flexible_table('feedback-showentryanonym-list-'.$course->id);
00117 
00118     $table->define_columns($tablecolumns);
00119     $table->define_headers($tableheaders);
00120     $table->define_baseurl($baseurl);
00121 
00122     $table->sortable(false);
00123     $table->set_attribute('cellspacing', '0');
00124     $table->set_attribute('id', 'showentryanonymtable');
00125     $table->set_attribute('class', 'generaltable generalbox');
00126     $table->set_control_variables(array(
00127                 TABLE_VAR_SORT    => 'ssort',
00128                 TABLE_VAR_IFIRST  => 'sifirst',
00129                 TABLE_VAR_ILAST   => 'silast',
00130                 TABLE_VAR_PAGE    => 'spage'
00131                 ));
00132     $table->setup();
00133 
00134     $matchcount = $feedbackcompletedscount;
00135     $table->initialbars(true);
00136 
00137     if ($showall) {
00138         $startpage = false;
00139         $pagecount = false;
00140     } else {
00141         $table->pagesize($perpage, $matchcount);
00142         $startpage = $table->get_page_start();
00143         $pagecount = $table->get_page_size();
00144     }
00145 
00146 
00147     $feedbackcompleteds = $DB->get_records('feedback_completed',
00148                                         array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES),
00149                                         'random_response',
00150                                         'id,random_response',
00151                                         $startpage,
00152                                         $pagecount);
00153 
00154     if (is_array($feedbackcompleteds)) {
00155         echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
00156         echo $OUTPUT->heading(get_string('anonymous_entries', 'feedback'), 3);
00157         foreach ($feedbackcompleteds as $compl) {
00158             $data = array();
00159 
00160             $data[] = get_string('response_nr', 'feedback').': '. $compl->random_response;
00161 
00162             //link to the entry
00163             $showentryurl = new moodle_url($baseurl, array('showcompleted'=>$compl->id));
00164             $showentrylink = '<a href="'.$showentryurl->out().'">'.get_string('show_entry', 'feedback').'</a>';
00165             $data[] = $showentrylink;
00166 
00167             //link to delete the entry
00168             if (has_capability('mod/feedback:deletesubmissions', $context)) {
00169                 $delet_url_params = array('id'=>$cm->id,
00170                                     'completedid'=>$compl->id,
00171                                     'do_show'=>'',
00172                                     'return'=>'entriesanonym');
00173 
00174                 $deleteentryurl = new moodle_url($CFG->wwwroot.'/mod/feedback/delete_completed.php', $delet_url_params);
00175                 $deleteentrylink = '<a href="'.$deleteentryurl->out().'">'.get_string('delete_entry', 'feedback').'</a>';
00176                 $data[] = $deleteentrylink;
00177             }
00178             $table->add_data($data);
00179         }
00180         $table->print_html();
00181 
00182         $allurl = new moodle_url($baseurl);
00183 
00184         if ($showall) {
00185             $allurl->param('showall', 0);
00186             $str_showperpage = get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT);
00187             echo $OUTPUT->container(html_writer::link($allurl, $str_showperpage), array(), 'showall');
00188         } else if ($matchcount > 0 && $perpage < $matchcount) {
00189             $allurl->param('showall', 1);
00190             echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
00191         }
00192         echo $OUTPUT->box_end();
00193     }
00194 }
00195 //print the items
00196 if ($showcompleted) {
00197     $continueurl = new moodle_url('/mod/feedback/show_entries_anonym.php',
00198                                 array('id'=>$id, 'do_show'=>''));
00199 
00200     echo $OUTPUT->continue_button($continueurl);
00201 
00202     //get the feedbackitems
00203     $params = array('feedback'=>$feedback->id);
00204     $feedbackitems = $DB->get_records('feedback_item', $params, 'position');
00205     $feedbackcompleted = $DB->get_record('feedback_completed', array('id'=>$showcompleted));
00206     if (is_array($feedbackitems)) {
00207         $align = right_to_left() ? 'right' : 'left';
00208 
00209         if ($feedbackcompleted) {
00210             echo $OUTPUT->box_start('feedback_info');
00211             echo get_string('chosen_feedback_response', 'feedback');
00212             echo $OUTPUT->box_end();
00213             echo $OUTPUT->box_start('feedback_info');
00214             echo get_string('response_nr', 'feedback').': ';
00215             echo $feedbackcompleted->random_response.' ('.get_string('anonymous', 'feedback').')';
00216             echo $OUTPUT->box_end();
00217         } else {
00218             echo $OUTPUT->box_start('feedback_info');
00219             echo get_string('not_completed_yet', 'feedback');
00220             echo $OUTPUT->box_end();
00221         }
00222 
00223         echo $OUTPUT->box_start('feedback_items');
00224         $itemnr = 0;
00225         foreach ($feedbackitems as $feedbackitem) {
00226             //get the values
00227             $params = array('completed'=>$feedbackcompleted->id, 'item'=>$feedbackitem->id);
00228             $value = $DB->get_record('feedback_value', $params);
00229             echo $OUTPUT->box_start('feedback_item_box_'.$align);
00230             if ($feedbackitem->hasvalue == 1 AND $feedback->autonumbering) {
00231                 $itemnr++;
00232                 echo $OUTPUT->box_start('feedback_item_number_'.$align);
00233                 echo $itemnr;
00234                 echo $OUTPUT->box_end();
00235             }
00236             if ($feedbackitem->typ != 'pagebreak') {
00237                 echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
00238                 $itemvalue = isset($value->value) ? $value->value : false;
00239                 feedback_print_item_show_value($feedbackitem, $itemvalue);
00240                 echo $OUTPUT->box_end();
00241             }
00242             echo $OUTPUT->box_end();
00243         }
00244         echo $OUTPUT->box_end();
00245     }
00246 }
00251 
00252 echo $OUTPUT->footer();
00253 
 All Data Structures Namespaces Files Functions Variables Enumerations