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()) {
56 $sh = new SurveyHtml();
58 if (!session_loggedin() || !forge_check_perm('project_admin', $group_id)) {
59 echo $HTML->error_msg(_('Permission denied.'));
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 $HTML->error_msg(_('Error').' '._('Cannot get Survey Response Factory'));
81 } elseif ( $srf->isError()) {
82 echo $HTML->error_msg(_('Error').' '.$srf->getErrorMessage());
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>";
107 $sysdebug_enable = false;
109 header('Content-type: text/csv');
110 list($year, $month) = explode('-', date('Y-m'));
111 header('Content-disposition: filename="survey-'.$year.'-'.$month.'.csv"');
113 foreach ($header as $id=>$col){
114 echo '"'.fix4csv($col).'";';
117 foreach ($s2 as $k=>$val){
119 foreach ($header as $id=>$col){
120 $res = format($val[$id],$types[$id]);
129 * 1: Radio Buttons 1-5
131 * 3: Radio Buttons Yes/No
137 function format ($f,$type) {
138 // $radio_button = array("","5 (hight)", "4 (good)", "3 (mean)", "2 (low)", "1 (low)");
139 // $radio_button = array( "", "1 (low)", "2 (low)", "3 (mean)", "4 (good)", "5 (hight)" );
140 $yes_no = array("","Yes","","","","No");
142 if($f < 0 OR $f > 5){ return ""; }
143 //return($radio_button[$f]);
147 if($f < 0 OR $f > 5){ return ""; }
150 if($type == 4){ // Comment only => ""
156 // 2 - Text Area :: 5: Text Field
160 function fix4csv ($value) {
161 $value =& util_unconvert_htmlspecialchars( $value );
162 $value =& str_replace("\r\n", "\n", $value);
163 $value =& str_replace('"', '""', $value);