3 * GForge Survey Facility
5 * Portions Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
7 * http://fusionforge.org/
9 * @version $Id: show_results.php 4561 2005-08-17 12:34:37Z danper $
11 * This file is part of FusionForge.
13 * FusionForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with FusionForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 require_once('../../env.inc.php');
29 require_once $gfcommon.'include/pre.php';
30 require_once $gfcommon.'survey/Survey.class.php';
31 require_once $gfcommon.'survey/SurveyFactory.class.php';
32 require_once $gfcommon.'survey/SurveyQuestion.class.php';
33 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
34 require_once $gfcommon.'survey/SurveyResponse.class.php';
35 require_once $gfcommon.'survey/SurveyResponseFactory.class.php';
36 require_once $gfwww.'survey/include/SurveyHTML.class.php';
38 $group_id = getIntFromRequest('group_id');
39 $survey_id = getIntFromRequest('survey_id');
40 $graph = getStringFromRequest('graph');
41 $show_comment = getStringFromRequest('show_comment');
43 $html = getStringFromRequest('html');
45 /* We need a group_id */
50 $g = group_get_object($group_id);
51 if (!$g || !is_object($g) || $g->isError()) {
56 $sh = new SurveyHtml();
60 if (!session_loggedin() || !user_ismember($group_id,'A')) {
61 echo '<p class="error">'._('Permission denied').'</p>';
67 $s = new Survey($g, $survey_id);
69 /* Get questions of this survey */
70 $questions = & $s->getQuestionInstances();
71 foreach ($questions as $cur_question){
72 $qid = $cur_question->getId();
73 $lib = $cur_question->getQuestion();
74 $type = $cur_question->getQuestionType();
79 $one_question = $questions[0];
80 $srf = new SurveyResponseFactory($s, $one_question);
81 if (!$srf || !is_object($srf)) {
82 echo '<p class="error">'._("Error"). ' ' . _('Cannot get Survey Response Factory') ."</p>";
83 } else if ( $srf->isError()) {
84 echo '<p class="error">'._("Error"). $srf->getErrorMessage() ."</p>";
86 $s2=$srf->getDetailResults();
89 print "\n".'<table border="1">'."\n";
91 //print "<td>User</td>";
92 foreach ($header as $id=>$col){
93 print "<td>$col</td>";
96 foreach ($s2 as $k=>$val){
98 //print "<td>$k</td>";
99 $val = array_reverse($val);
100 foreach ($val as $k1=>$val1){
101 $res = format($val1,$types[$k1]);
102 print "<td>$res</td>";
107 $sh->footer(array());
110 header('Content-type: text/csv');
111 list($year, $month) = explode('-', date('Y-m'));
112 header('Content-disposition: filename="survey-'.$year.'-'.$month.'.csv"');
114 foreach ($header as $id=>$col){
115 echo '"'.fix4csv($col).'";';
118 foreach ($s2 as $k=>$val){
120 foreach ($header as $id=>$col){
121 $res = format($val[$id],$types[$id]);
130 * 1: Radio Buttons 1-5
132 * 3: Radio Buttons Yes/No
139 function format ($f,$type) {
140 //$radio_button = array("","5 (hight)", "4 (good)", "3 (mean)", "2 (low)", "1 (low)");
141 $radio_button = array( "", "1 (low)", "2 (low)", "3 (mean)", "4 (good)", "5 (hight)" );
142 $yes_no = array("","Yes","","","","No");
144 if($f < 0 OR $f > 5){ return ""; }
145 //return($radio_button[$f]);
149 if($f < 0 OR $f > 5){ return ""; }
152 if($type == 4){ // Comment only => ""
158 // 2 - Text Area :: 5: Text Field
162 function fix4csv ($value) {
163 $value =& util_unconvert_htmlspecialchars( $value );
164 $value =& str_replace("\r\n", "\n", $value);
165 $value =& str_replace('"', '""', $value);