MDL-30851 - Syntax error in analysis_course.php
[moodle.git] / mod / feedback / analysis_course.php
CommitLineData
84973212 1<?php
9c5bc7a5
AG
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
84973212 16
c70ad9f7 17/**
9c5bc7a5
AG
18 * shows an analysed view of a feedback on the mainsite
19 *
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package feedback
23 */
c70ad9f7 24
84973212 25require_once("../../config.php");
26require_once("lib.php");
27
84973212 28$current_tab = 'analysis';
29
30$id = required_param('id', PARAM_INT); //the POST dominated the GET
31$coursefilter = optional_param('coursefilter', '0', PARAM_INT);
32$courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT);
33$courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM);
84973212 34$searchcourse = optional_param('searchcourse', '', PARAM_RAW);
35$courseid = optional_param('courseid', false, PARAM_INT);
36
a6855934 37$url = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id));
84973212 38if ($courseid !== false) {
39 $url->param('courseid', $courseid);
40}
41if ($coursefilter !== '0') {
42 $url->param('coursefilter', $coursefilter);
43}
44if ($courseitemfilter !== '0') {
45 $url->param('courseitemfilter', $courseitemfilter);
46}
47if ($courseitemfiltertyp !== '0') {
48 $url->param('courseitemfiltertyp', $courseitemfiltertyp);
49}
50if ($searchcourse !== '') {
51 $url->param('searchcourse', $searchcourse);
52}
53$PAGE->set_url($url);
54
9c5bc7a5 55if (($searchcourse OR $courseitemfilter OR $coursefilter) AND !confirm_sesskey()) {
84973212 56 print_error('invalidsesskey');
57}
58
b6f26001
AG
59if (! $cm = get_coursemodule_from_id('feedback', $id)) {
60 print_error('invalidcoursemodule');
61}
62
63if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
64 print_error('coursemisconf');
65}
66
67if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
68 print_error('invalidcoursemodule');
84973212 69}
c987dbad
AG
70
71if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
72 print_error('badcontext');
73}
84973212 74
75require_login($course->id, true, $cm);
76
9c5bc7a5 77if (!($feedback->publish_stats OR has_capability('mod/feedback:viewreports', $context))) {
84973212 78 print_error('error');
79}
80
81/// Print the page header
82$strfeedbacks = get_string("modulenameplural", "feedback");
83$strfeedback = get_string("modulename", "feedback");
84
9d092aa9 85$PAGE->set_heading(format_string($course->fullname));
84973212 86$PAGE->set_title(format_string($feedback->name));
84973212 87echo $OUTPUT->header();
88
89/// print the tabs
9c5bc7a5 90require('tabs.php');
84973212 91
92//print the analysed items
93echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
94
9c5bc7a5 95if (has_capability('mod/feedback:viewreports', $context)) {
84973212 96 //button "export to excel"
97 echo $OUTPUT->container_start('mdl-align');
9c5bc7a5
AG
98 $aurl = new moodle_url('analysis_to_excel.php',
99 array('sesskey' => sesskey(),
100 'id' => $id,
101 'coursefilter' => $coursefilter));
102
5c2ed7e2 103 echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
84973212 104 echo $OUTPUT->container_end();
105}
106
107//get the groupid
108//lstgroupid is the choosen id
109$mygroupid = false;
110//get completed feedbacks
111$completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $coursefilter);
112
113//show the count
114echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';
115
116// get the items of the feedback
9c5bc7a5
AG
117$params = array('feedback' => $feedback->id, 'hasvalue' => 1);
118$items = $DB->get_records('feedback_item', $params, 'position');
84973212 119//show the count
9c5bc7a5
AG
120if (is_array($items)) {
121 echo '<b>'.get_string('questions', 'feedback').': ' .count($items). ' </b><hr />';
122 echo '<a href="analysis_course.php?id=' . $id . '&courseid='.$courseid.'">';
123 echo get_string('show_all', 'feedback');
124 echo '</a>';
84973212 125} else {
126 $items=array();
127}
128
129echo '<form name="report" method="post" id="analysis-form">';
130echo '<div class="mdl-align"><table width="80%" cellpadding="10">';
131if ($courseitemfilter > 0) {
132 $avgvalue = 'avg(value)';
133 if ($DB->get_dbfamily() == 'postgres') { // TODO: this should be moved to standard sql DML function ;-)
134 $avgvalue = 'avg(cast (value as integer))';
c70ad9f7 135 }
9c5bc7a5
AG
136
137 $sql = "SELECT fv.course_id, c.shortname, $avgvalue AS avgvalue
138 FROM {feedback_value} fv, {course} c, {feedback_item} fi
139 WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
140 GROUP BY course_id, shortname
141 ORDER BY avgvalue desc";
142
143 if ($courses = $DB->get_records_sql($sql, array($courseitemfiltertyp, $courseitemfilter))) {
8ebbb06a
SH
144 $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
145 echo '<tr><th colspan="2">'.$item->name.'</th></tr>';
146 echo '<tr><td><table align="left">';
147 echo '<tr><th>Course</th><th>Average</th></tr>';
148 $sep_dec = get_string('separator_decimal', 'feedback');
149 $sep_thous = get_string('separator_thousand', 'feedback');
150
151 foreach ($courses as $c) {
9c5bc7a5
AG
152 $coursecontext = get_context_instance(CONTEXT_COURSE, $c->course_id);
153 $shortname = format_string($c->shortname, true, array('context' => $coursecontext));
154
155 echo '<tr>';
156 echo '<td>'.$shortname.'</td>';
0f61fb72 157 echo '<td align="right">';
9c5bc7a5
AG
158 echo number_format(($c->avgvalue), 2, $sep_dec, $sep_thous);
159 echo '</td>';
160 echo '</tr>';
8ebbb06a 161 }
84973212 162 echo '</table></td></tr>';
c70ad9f7 163 } else {
84973212 164 echo '<tr><td>'.get_string('noresults').'</td></tr>';
c70ad9f7 165 }
84973212 166} else {
167
168 echo get_string('search_course', 'feedback') . ': ';
9c5bc7a5
AG
169 echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> ';
170 echo '<input type="submit" value="'.get_string('search').'"/>';
84973212 171 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
172 echo '<input type="hidden" name="id" value="'.$id.'" />';
173 echo '<input type="hidden" name="courseitemfilter" value="'.$courseitemfilter.'" />';
174 echo '<input type="hidden" name="courseitemfiltertyp" value="'.$courseitemfiltertyp.'" />';
175 echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
c17f05fb 176 echo html_writer::script('', $CFG->wwwroot.'/mod/feedback/feedback.js');
31c0fa53 177 $sql = 'select DISTINCT c.id, c.shortname from {course} c, '.
84973212 178 '{feedback_value} fv, {feedback_item} fi '.
179 'where c.id = fv.course_id and fv.item = fi.id '.
31c0fa53 180 'and fi.feedback = ? '.
84973212 181 'and
0f1b6a5e
PS
182 ('.$DB->sql_like('c.shortname', '?', false).'
183 OR '.$DB->sql_like('c.fullname', '?', false).')';
84973212 184 $params = array($feedback->id, "%$searchcourse%", "%$searchcourse%");
185
186 if ($courses = $DB->get_records_sql_menu($sql, $params)) {
187
188 echo ' ' . get_string('filter_by_course', 'feedback') . ': ';
0f1b6a5e 189
9c5bc7a5
AG
190 echo html_writer::select($courses, 'coursefilter', $coursefilter,
191 null, array('id'=>'coursefilterid'));
192
193 $PAGE->requires->js_init_call('M.util.init_select_autosubmit',
194 array('analysis-form', 'coursefilterid', false));
84973212 195 }
196 echo '<hr />';
197 $itemnr = 0;
198 //print the items in an analysed form
199 echo '<tr><td>';
9c5bc7a5
AG
200 foreach ($items as $item) {
201 if ($item->hasvalue == 0) {
202 continue;
203 }
84973212 204 echo '<table width="100%" class="generalbox">';
205 //get the class from item-typ
6cc1599e 206 $itemobj = feedback_get_item_class($item->typ);
84973212 207 $itemnr++;
9c5bc7a5 208 if ($feedback->autonumbering) {
84973212 209 $printnr = $itemnr.'.';
c70ad9f7 210 } else {
84973212 211 $printnr = '';
c70ad9f7 212 }
84973212 213 $itemobj->print_analysed($item, $printnr, $mygroupid, $coursefilter);
214 if (preg_match('/rated$/i', $item->typ)) {
9c5bc7a5
AG
215 $onclick = 'onclick="setcourseitemfilter'.
216 "(".$item->id.",'".$item->typ."');".
217 ' return false;"';
218
219 $anker = '<a href="#" '.$onclick.'>'.
220 get_string('sort_by_course', 'feedback').
221 '</a>';
222
223 echo '<tr><td colspan="2">'.$anker.'</td></tr>';
c70ad9f7 224 }
84973212 225 echo '</table>';
c70ad9f7 226 }
84973212 227 echo '</td></tr>';
228}
229echo '</table></div>';
230echo '</form>';
231echo $OUTPUT->box_end();
d4b1d58c 232
84973212 233echo $OUTPUT->footer();
c70ad9f7 234