mod-data MDL-19806 Added set_url calls, replaced deprecated functions, and added...
[moodle.git] / mod / feedback / analysis_course.php
CommitLineData
c70ad9f7 1<?php // $Id$
2/**
3* shows an analysed view of a feedback on the mainsite
4*
5* @version $Id$
6* @author Andreas Grabs
7* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8* @package feedback
9*/
10
11 require_once("../../config.php");
12 require_once("lib.php");
d4b1d58c 13
c70ad9f7 14 // $SESSION->feedback->current_tab = 'analysis';
15 $current_tab = 'analysis';
d4b1d58c 16
c70ad9f7 17 $id = required_param('id', PARAM_INT); //the POST dominated the GET
18 $coursefilter = optional_param('coursefilter', '0', PARAM_INT);
19 $courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT);
20 $courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM);
21 // $searchcourse = optional_param('searchcourse', '', PARAM_ALPHAEXT);
22 $searchcourse = optional_param('searchcourse', '', PARAM_RAW);
23 $courseid = optional_param('courseid', false, PARAM_INT);
d4b1d58c 24
c70ad9f7 25 if(($searchcourse OR $courseitemfilter OR $coursefilter) AND !confirm_sesskey()) {
cf238eaf 26 print_error('invalidsesskey');
c70ad9f7 27 }
d4b1d58c 28
c70ad9f7 29 if ($id) {
30 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
cf238eaf 31 print_error('invalidcoursemodule');
c70ad9f7 32 }
d4b1d58c 33
0085fff8 34 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
cf238eaf 35 print_error('coursemisconf');
c70ad9f7 36 }
d4b1d58c 37
0085fff8 38 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
cf238eaf 39 print_error('invalidcoursemodule');
c70ad9f7 40 }
41 }
42 $capabilities = feedback_load_capabilities($cm->id);
43
6178c62a 44 require_login($course->id, true, $cm);
d4b1d58c 45
c70ad9f7 46 if( !( (intval($feedback->publish_stats) == 1) || $capabilities->viewreports)) {
cf238eaf 47 print_error('error');
c70ad9f7 48 }
d4b1d58c 49
c70ad9f7 50 /// Print the page header
51 $strfeedbacks = get_string("modulenameplural", "feedback");
52 $strfeedback = get_string("modulename", "feedback");
53 $buttontext = update_module_button($cm->id, $course->id, $strfeedback);
d4b1d58c 54
84f797db 55 $PAGE->navbar->add($strfeedbacks, new moodle_url($CFG->wwwroot.'/mod/feedback/index.php', array('id'=>$course->id)));
56 $PAGE->navbar->add(format_string($feedback->name));
d4b1d58c 57
84f797db 58 $PAGE->set_title(format_string($feedback->name));
59 $PAGE->set_button($buttontext);
60 echo $OUTPUT->header();
c70ad9f7 61
62 /// print the tabs
63 include('tabs.php');
64
65 //print the analysed items
d4b1d58c 66 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
c70ad9f7 67
68 if( $capabilities->viewreports ) {
69 //button "export to excel"
c3aa5bd3 70 echo $OUTPUT->container_start('mdl-align');
c70ad9f7 71 $export_button_link = 'analysis_to_excel.php';
4d933beb 72 $export_button_options = array('sesskey'=>sesskey(), 'id'=>$id, 'coursefilter'=>$coursefilter);
c70ad9f7 73 $export_button_label = get_string('export_to_excel', 'feedback');
c3aa5bd3 74 echo $OUTPUT->button(html_form::make_button($export_button_link, $export_button_options, $export_button_label));
75 echo $OUTPUT->container_end();
c70ad9f7 76 }
d4b1d58c 77
c70ad9f7 78 //get the groupid
79 //lstgroupid is the choosen id
80 $mygroupid = false;
81 //get completed feedbacks
82 $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $coursefilter);
d4b1d58c 83
c70ad9f7 84 //show the count
85 echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';
d4b1d58c 86
c70ad9f7 87 // get the items of the feedback
0085fff8 88 $items = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'hasvalue'=>1), 'position');
c70ad9f7 89 //show the count
90 if(is_array($items)){
91 echo '<b>'.get_string('questions', 'feedback').': ' .sizeof($items). ' </b><hr />';
92 echo '<a href="analysis_course.php?id=' . $id . '&courseid='.$courseid.'">'.get_string('show_all', 'feedback').'</a>';
93 } else {
94 $items=array();
95 }
96
41f08e33 97 echo '<form name="report" method="post" id="analysis-form">';
ff9b4ea4 98 echo '<div class="mdl-align"><table width="80%" cellpadding="10">';
c70ad9f7 99 if ($courseitemfilter > 0) {
100 $avgvalue = 'avg(value)';
5f501fe1 101 if ($DB->get_dbfamily() == 'postgres') { // TODO: this should be moved to standard sql DML function ;-)
c70ad9f7 102 $avgvalue = 'avg(cast (value as integer))';
103 }
0085fff8 104 if ($courses = $DB->get_records_sql ("SELECT fv.course_id, c.shortname, $avgvalue AS avgvalue
105 FROM {feedback_value} fv, {course} c, {feedback_item} fi
106 WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
107 GROUP BY course_id, shortname
108 ORDER BY avgvalue desc",
109 array($courseitemfiltertyp, $courseitemfilter))) {
110 $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
c70ad9f7 111 echo '<tr><th colspan="2">'.$item->name.'</th></tr>';
112 echo '<tr><td><table align="left">';
113 echo '<tr><th>Course</th><th>Average</th></tr>';
114 $sep_dec = get_string('separator_decimal', 'feedback');
115 $sep_thous = get_string('separator_thousand', 'feedback');
116
117 foreach ($courses as $c) {
118 echo '<tr><td>'.$c->shortname.'</td><td align="right">'.number_format(($c->avgvalue), 2, $sep_dec, $sep_thous).'</td></tr>';
119 }
120 echo '</table></td></tr>';
121 } else {
122 echo '<tr><td>'.get_string('noresults').'</td></tr>';
123 }
124 } else {
125
126 echo get_string('search_course', 'feedback') . ': ';
127 echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> <input type="submit" value="'.get_string('search').'"/>';
4d933beb 128 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
c70ad9f7 129 echo '<input type="hidden" name="id" value="'.$id.'" />';
130 echo '<input type="hidden" name="courseitemfilter" value="'.$courseitemfilter.'" />';
131 echo '<input type="hidden" name="courseitemfiltertyp" value="'.$courseitemfiltertyp.'" />';
132 echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
7747c8db 133 echo $PAGE->requires->js('mod/feedback/feedback.js')->asap();
c6307ef2 134 $sql = 'select c.id, c.shortname from {course} c, '.
135 '{feedback_value} fv, {feedback_item} fi '.
c70ad9f7 136 'where c.id = fv.course_id and fv.item = fi.id '.
c6307ef2 137 'and fi.feedback = ?'.
d4b1d58c 138 'and
c6307ef2 139 (c.shortname '.$DB->sql_ilike().' ?
140 OR c.fullname '.$DB->sql_ilike().' ?)';
141 $params = array($feedback->id, "%$searchcourse%", "%$searchcourse%");
d4b1d58c 142
c6307ef2 143 if ($courses = $DB->get_records_sql_menu($sql, $params)) {
c70ad9f7 144
145 echo ' ' . get_string('filter_by_course', 'feedback') . ': ';
7b1f2c82 146 $select = new html_select();
49c8c8d2 147 $select->options = $courses;
148 $select->name = 'coursefilter';
149 $select->selectedvalue = $coursefilter;
150 $select->add_action('change', 'submit_form_by_id', array('id' => 'analysis-form'));
151 echo $OUTPUT->select($select);
c70ad9f7 152 }
153 echo '<hr />';
154 $itemnr = 0;
155 //print the items in an analysed form
156 echo '<tr><td>';
157 foreach($items as $item) {
158 if($item->hasvalue == 0) continue;
d4b1d58c 159 echo '<table width="100%" class="generalbox">';
c70ad9f7 160 //get the class from item-typ
161 $itemclass = 'feedback_item_'.$item->typ;
162 //get the instance of the item-class
163 $itemobj = new $itemclass();
efc59167 164 $itemnr++;
165 if($feedback->autonumbering) {
166 $printnr = $itemnr.'.';
167 } else {
168 $printnr = '';
169 }
170 $itemobj->print_analysed($item, $printnr, $mygroupid, $coursefilter);
6dbcacee 171 if (preg_match('/rated$/i', $item->typ)) {
c70ad9f7 172 echo '<tr><td colspan="2"><a href="#" onclick="setcourseitemfilter('.$item->id.',\''.$item->typ.'\'); return false;">'.
d4b1d58c 173 get_string('sort_by_course', 'feedback').'</a></td></tr>';
c70ad9f7 174 }
175 echo '</table>';
176 }
177 echo '</td></tr>';
178 }
179 echo '</table></div>';
180 echo '</form>';
d4b1d58c 181 echo $OUTPUT->box_end();
182
c6ea0876 183 echo $OUTPUT->footer();
c70ad9f7 184
185?>