MDL-14493 First checkin of Feedback module into HEAD.
[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");
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
25 if(($searchcourse OR $courseitemfilter OR $coursefilter) AND !confirm_sesskey()) {
26 error('no sesskey defined');
27 }
28
29 if ($id) {
30 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
31 error("Course Module ID was incorrect");
32 }
33
34 if (! $course = get_record("course", "id", $cm->course)) {
35 error("Course is misconfigured");
36 }
37
38 if (! $feedback = get_record("feedback", "id", $cm->instance)) {
39 error("Course module is incorrect");
40 }
41 }
42 $capabilities = feedback_load_capabilities($cm->id);
43
44 require_login($course->id);
45
46 if( !( (intval($feedback->publish_stats) == 1) || $capabilities->viewreports)) {
47 error(get_string('error'));
48 }
49
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);
54
55 $navlinks = array();
56 $navlinks[] = array('name' => $strfeedbacks, 'link' => "index.php?id=$course->id", 'type' => 'activity');
57 $navlinks[] = array('name' => format_string($feedback->name), 'link' => "", 'type' => 'activityinstance');
58
59 $navigation = build_navigation($navlinks);
60
61 print_header_simple(format_string($feedback->name), "",
62 $navigation, "", "", true, $buttontext, navmenu($course, $cm));
63
64 /// print the tabs
65 include('tabs.php');
66
67 //print the analysed items
68 // print_simple_box_start("center", '80%');
69 print_box_start('generalbox boxaligncenter boxwidthwide');
70
71 if( $capabilities->viewreports ) {
72 //button "export to excel"
73 echo '<div align="center">';
74 $export_button_link = 'analysis_to_excel.php';
75 $export_button_options = array('sesskey'=>$USER->sesskey, 'id'=>$id);
76 $export_button_label = get_string('export_to_excel', 'feedback');
77 print_single_button($export_button_link, $export_button_options, $export_button_label, 'post');
78 echo '</div>';
79 }
80
81 //get the groupid
82 //lstgroupid is the choosen id
83 $mygroupid = false;
84 //get completed feedbacks
85 $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $coursefilter);
86
87 //show the count
88 echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';
89
90 // get the items of the feedback
91 $items = get_records_select('feedback_item', 'feedback = '. $feedback->id . ' AND hasvalue = 1', 'position');
92 //show the count
93 if(is_array($items)){
94 echo '<b>'.get_string('questions', 'feedback').': ' .sizeof($items). ' </b><hr />';
95 echo '<a href="analysis_course.php?id=' . $id . '&courseid='.$courseid.'">'.get_string('show_all', 'feedback').'</a>';
96 } else {
97 $items=array();
98 }
99
100 echo '<form name="report" method="post">';
101 echo '<div align="center"><table width="80%" cellpadding="10">';
102 if ($courseitemfilter > 0) {
103 $avgvalue = 'avg(value)';
104 if ($CFG->dbtype == 'postgres7') {
105 $avgvalue = 'avg(cast (value as integer))';
106 }
107 if ($courses = get_records_sql ('select fv.course_id, c.shortname, '.$avgvalue.' as avgvalue '.
108 'from '.$CFG->prefix.'feedback_value fv, '.$CFG->prefix.'course c, '.
109 $CFG->prefix.'feedback_item fi '.
110 'where fv.course_id = c.id '.
111 'and fi.id = fv.item and fi.typ = \''.$courseitemfiltertyp.'\' and fv.item = \''.
112 $courseitemfilter.'\' '.
113 'group by course_id, shortname order by avgvalue desc')) {
114 $item = get_record('feedback_item', 'id', $courseitemfilter);
115 echo '<tr><th colspan="2">'.$item->name.'</th></tr>';
116 echo '<tr><td><table align="left">';
117 echo '<tr><th>Course</th><th>Average</th></tr>';
118 $sep_dec = get_string('separator_decimal', 'feedback');
119 $sep_thous = get_string('separator_thousand', 'feedback');
120
121 foreach ($courses as $c) {
122 echo '<tr><td>'.$c->shortname.'</td><td align="right">'.number_format(($c->avgvalue), 2, $sep_dec, $sep_thous).'</td></tr>';
123 }
124 echo '</table></td></tr>';
125 } else {
126 echo '<tr><td>'.get_string('noresults').'</td></tr>';
127 }
128 } else {
129
130 echo get_string('search_course', 'feedback') . ': ';
131 echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> <input type="submit" value="'.get_string('search').'"/>';
132 echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
133 echo '<input type="hidden" name="id" value="'.$id.'" />';
134 echo '<input type="hidden" name="courseitemfilter" value="'.$courseitemfilter.'" />';
135 echo '<input type="hidden" name="courseitemfiltertyp" value="'.$courseitemfiltertyp.'" />';
136 echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
137 echo '<script language="javascript" type="text/javascript">
138 <!--
139 function setcourseitemfilter(item, item_typ) {
140 document.report.courseitemfilter.value = item;
141 document.report.courseitemfiltertyp.value = item_typ;
142 document.report.submit();
143 }
144 -->
145 </script>';
146
147
148 $sql = 'select c.id, c.shortname from '.$CFG->prefix.'course c, '.
149 $CFG->prefix.'feedback_value fv, '.$CFG->prefix.'feedback_item fi '.
150 'where c.id = fv.course_id and fv.item = fi.id '.
151 'and fi.feedback = '.$feedback->id.' '.
152 'and
153 (c.shortname '.sql_ilike().' \'%'.$searchcourse.'%\'
154 OR c.fullname '.sql_ilike().' \'%'.$searchcourse.'%\')';
155
156 if ($courses = get_records_sql_menu($sql)) {
157
158 echo ' ' . get_string('filter_by_course', 'feedback') . ': ';
159 choose_from_menu ($courses, 'coursefilter', $coursefilter, 'choose', 'this.form.submit()');
160 }
161 echo '<hr />';
162 $itemnr = 0;
163 //print the items in an analysed form
164 echo '<tr><td>';
165 foreach($items as $item) {
166 if($item->hasvalue == 0) continue;
167 echo '<table width="100%" class="generalbox">';
168 //get the class from item-typ
169 $itemclass = 'feedback_item_'.$item->typ;
170 //get the instance of the item-class
171 $itemobj = new $itemclass();
172 $itemnr = $itemobj->print_analysed($item, $itemnr, $mygroupid, $coursefilter);
173 if (eregi('rated$', $item->typ)) {
174 echo '<tr><td colspan="2"><a href="#" onclick="setcourseitemfilter('.$item->id.',\''.$item->typ.'\'); return false;">'.
175 get_string('sort_by_course', 'feedback').'</a></td></tr>';
176 }
177 echo '</table>';
178 }
179 echo '</td></tr>';
180 }
181 echo '</table></div>';
182 echo '</form>';
183 print_box_end();
184
185 print_footer($course);
186
187?>