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 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once '../../env.inc.php';
27 require_once $gfcommon.'include/pre.php';
28 require_once $gfcommon.'survey/Survey.class.php';
29 require_once $gfcommon.'survey/SurveyFactory.class.php';
30 require_once $gfcommon.'survey/SurveyQuestion.class.php';
31 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
32 require_once $gfcommon.'survey/SurveyResponse.class.php';
33 require_once $gfcommon.'survey/SurveyResponseFactory.class.php';
34 require_once $gfwww.'survey/include/SurveyHTML.class.php';
36 $group_id = getIntFromRequest('group_id');
37 $survey_id = getIntFromRequest('survey_id');
38 $graph = getStringFromRequest('graph');
39 $show_comment = getStringFromRequest('show_comment');
41 $html = getStringFromRequest('html');
43 /* We need a group_id */
48 $g = group_get_object($group_id);
49 if (!$g || !is_object($g) || $g->isError()) {
54 $sh = new SurveyHtml();
58 if (!session_loggedin() || !user_ismember($group_id,'A')) {
59 echo '<p class="error">'._('Permission denied.').'</p>';
65 $s = new Survey($g, $survey_id);
67 /* Get questions of this survey */
68 $questions = & $s->getQuestionInstances();
69 foreach ($questions as $cur_question){
70 $qid = $cur_question->getId();
71 $lib = $cur_question->getQuestion();
72 $type = $cur_question->getQuestionType();
77 $one_question = $questions[0];
78 $srf = new SurveyResponseFactory($s, $one_question);
79 if (!$srf || !is_object($srf)) {
80 echo '<p class="error">'._("Error"). ' ' . _('Cannot get Survey Response Factory') ."</p>";
81 } elseif ( $srf->isError()) {
82 echo '<p class="error">'._("Error"). $srf->getErrorMessage() ."</p>";
84 $s2=$srf->getDetailResults();
87 print "\n".'<table border="1">'."\n";
89 //print "<td>User</td>";
90 foreach ($header as $id=>$col){
91 print "<td>$col</td>";
94 foreach ($s2 as $k=>$val){
96 //print "<td>$k</td>";
97 $val = array_reverse($val);
98 foreach ($val as $k1=>$val1){
99 $res = format($val1,$types[$k1]);
100 print "<td>$res</td>";
105 $sh->footer(array());
108 header('Content-type: text/csv');
109 list($year, $month) = explode('-', date('Y-m'));
110 header('Content-disposition: filename="survey-'.$year.'-'.$month.'.csv"');
112 foreach ($header as $id=>$col){
113 echo '"'.fix4csv($col).'";';
116 foreach ($s2 as $k=>$val){
118 foreach ($header as $id=>$col){
119 $res = format($val[$id],$types[$id]);
128 * 1: Radio Buttons 1-5
130 * 3: Radio Buttons Yes/No
136 function format ($f,$type) {
137 //$radio_button = array("","5 (hight)", "4 (good)", "3 (mean)", "2 (low)", "1 (low)");
138 $radio_button = array( "", "1 (low)", "2 (low)", "3 (mean)", "4 (good)", "5 (hight)" );
139 $yes_no = array("","Yes","","","","No");
141 if($f < 0 OR $f > 5){ return ""; }
142 //return($radio_button[$f]);
146 if($f < 0 OR $f > 5){ return ""; }
149 if($type == 4){ // Comment only => ""
155 // 2 - Text Area :: 5: Text Field
159 function fix4csv ($value) {
160 $value =& util_unconvert_htmlspecialchars( $value );
161 $value =& str_replace("\r\n", "\n", $value);
162 $value =& str_replace('"', '""', $value);