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