3 * GForge Survey Facility
5 * Portions Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
7 * Copyright 2014, Franck Villaume - TrivialDev
8 * http://fusionforge.org/
10 * This file is part of FusionForge.
12 * FusionForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once '../../env.inc.php';
28 require_once $gfcommon.'include/pre.php';
29 require_once $gfcommon.'survey/Survey.class.php';
30 require_once $gfcommon.'survey/SurveyFactory.class.php';
31 require_once $gfcommon.'survey/SurveyQuestion.class.php';
32 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
33 require_once $gfcommon.'survey/SurveyResponse.class.php';
34 require_once $gfcommon.'survey/SurveyResponseFactory.class.php';
35 require_once $gfwww.'survey/include/SurveyHTML.class.php';
39 $group_id = getIntFromRequest('group_id');
40 $survey_id = getIntFromRequest('survey_id');
41 $graph = getStringFromRequest('graph');
42 $show_comment = getStringFromRequest('show_comment');
44 $html = getStringFromRequest('html');
46 /* We need a group_id */
51 $g = group_get_object($group_id);
52 if (!$g || !is_object($g) || $g->isError()) {
57 $sh = new SurveyHtml();
61 if (!session_loggedin() || !user_ismember($group_id,'A')) {
62 echo $HTML->error_msg(_('Permission denied.'));
68 $s = new Survey($g, $survey_id);
70 /* Get questions of this survey */
71 $questions = & $s->getQuestionInstances();
72 foreach ($questions as $cur_question){
73 $qid = $cur_question->getID();
74 $lib = $cur_question->getQuestion();
75 $type = $cur_question->getQuestionType();
80 $one_question = $questions[0];
81 $srf = new SurveyResponseFactory($s, $one_question);
82 if (!$srf || !is_object($srf)) {
83 echo $HTML->error_msg(_('Error').' '._('Cannot get Survey Response Factory'));
84 } elseif ( $srf->isError()) {
85 echo $HTML->error_msg(_('Error').' '.$srf->getErrorMessage());
87 $s2=$srf->getDetailResults();
90 print "\n".'<table border="1">'."\n";
92 //print "<td>User</td>";
93 foreach ($header as $id=>$col){
94 print "<td>$col</td>";
97 foreach ($s2 as $k=>$val){
99 //print "<td>$k</td>";
100 $val = array_reverse($val);
101 foreach ($val as $k1=>$val1){
102 $res = format($val1,$types[$k1]);
103 print "<td>$res</td>";
111 header('Content-type: text/csv');
112 list($year, $month) = explode('-', date('Y-m'));
113 header('Content-disposition: filename="survey-'.$year.'-'.$month.'.csv"');
115 foreach ($header as $id=>$col){
116 echo '"'.fix4csv($col).'";';
119 foreach ($s2 as $k=>$val){
121 foreach ($header as $id=>$col){
122 $res = format($val[$id],$types[$id]);
131 * 1: Radio Buttons 1-5
133 * 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);