<?php
/**
- * GForge Survey Facility
+ * Survey Facility
*
* Portions Copyright 1999-2001 (c) VA Linux Systems
* The rest Copyright 2002-2004 (c) GForge Team
+ * Copyright 2014, Franck Villaume - TrivialDev
* http://fusionforge.org/
*
* This file is part of FusionForge.
require_once $gfcommon.'survey/SurveyResponseFactory.class.php';
require_once $gfwww.'survey/include/SurveyHTML.class.php';
+global $HTML;
+
$group_id = getIntFromRequest('group_id');
$survey_id = getIntFromRequest('survey_id');
$graph = getStringFromRequest('graph');
/* We need a group_id */
if (!$group_id) {
- exit_no_group();
+ exit_no_group();
}
$g = group_get_object($group_id);
if (!$g || !is_object($g) || $g->isError()) {
- exit_no_group();
+ exit_no_group();
}
-$is_admin_page='y';
-$sh = new SurveyHtml();
-
-$is_admin_page='y';
+$sh = new SurveyHTML();
-if (!session_loggedin() || !user_ismember($group_id,'A')) {
- echo '<p class="error">'._('Permission denied.').'</p>';
- $sh->footer(array());
+if (!session_loggedin() || !forge_check_perm('project_admin', $group_id)) {
+ echo $HTML->error_msg(_('Permission denied.'));
+ $sh->footer();
exit;
}
if ($survey_id) {
- $s = new Survey($g, $survey_id);
-
- /* Get questions of this survey */
- $questions = & $s->getQuestionInstances();
- foreach ($questions as $cur_question){
- $qid = $cur_question->getId();
- $lib = $cur_question->getQuestion();
- $type = $cur_question->getQuestionType();
- $header[$qid]=$lib;
- $types[$qid]=$type;
+ $s = new Survey($g, $survey_id);
+
+ /* Get questions of this survey */
+ $questions = & $s->getQuestionInstances();
+ foreach ($questions as $cur_question) {
+ $qid = $cur_question->getID();
+ $lib = $cur_question->getQuestion();
+ $type = $cur_question->getQuestionType();
+ $header[$qid]=$lib;
+ $types[$qid]=$type;
}
- $one_question = $questions[0];
- $srf = new SurveyResponseFactory($s, $one_question);
- if (!$srf || !is_object($srf)) {
- echo '<p class="error">'._("Error"). ' ' . _('Cannot get Survey Response Factory') ."</p>";
- } elseif ( $srf->isError()) {
- echo '<p class="error">'._("Error"). $srf->getErrorMessage() ."</p>";
- } else {
+ $one_question = $questions[0];
+ $srf = new SurveyResponseFactory($s, $one_question);
+ if (!$srf || !is_object($srf)) {
+ echo $HTML->error_msg(_('Error').' '._('Cannot get Survey Response Factory'));
+ } elseif ( $srf->isError()) {
+ echo $HTML->error_msg(_('Error').' '.$srf->getErrorMessage());
+ } else {
$s2=$srf->getDetailResults();
- if ($html) {
+ if ($html) {
$sh->header(array());
print "\n".'<table border="1">'."\n";
print "<tr>";
//print "<td>User</td>";
- foreach ($header as $id=>$col){
+ foreach ($header as $id=>$col) {
print "<td>$col</td>";
}
print "</tr>\n";
- foreach ($s2 as $k=>$val){
+ foreach ($s2 as $k=>$val) {
print "<tr>";
//print "<td>$k</td>";
$val = array_reverse($val);
- foreach ($val as $k1=>$val1){
+ foreach ($val as $k1=>$val1) {
$res = format($val1,$types[$k1]);
print "<td>$res</td>";
- }
+ }
print "</tr>\n";
}
print "</table>";
- $sh->footer(array());
- } else {
+ $sh->footer();
+ } else {
+ $sysdebug_enable = false;
// CSV mode
- header('Content-type: text/csv');
- list($year, $month) = explode('-', date('Y-m'));
- header('Content-disposition: filename="survey-'.$year.'-'.$month.'.csv"');
+ header('Content-type: text/csv');
+ list($year, $month) = explode('-', date('Y-m'));
+ header('Content-disposition: filename="survey-'.$year.'-'.$month.'.csv"');
- foreach ($header as $id=>$col){
+ foreach ($header as $id=>$col){
echo '"'.fix4csv($col).'";';
- }
+ }
- foreach ($s2 as $k=>$val){
+ foreach ($s2 as $k=>$val){
echo "\n";
foreach ($header as $id=>$col){
- $res = format($val[$id],$types[$id]);
- echo '"'.$res.'";';
+ $res = format($val[$id],$types[$id]);
+ echo '"'.$res.'";';
}
- }
+ }
}
- }
+ }
}
/*
*/
function format ($f,$type) {
-//$radio_button = array("","5 (hight)", "4 (good)", "3 (mean)", "2 (low)", "1 (low)");
-$radio_button = array( "", "1 (low)", "2 (low)", "3 (mean)", "4 (good)", "5 (hight)" );
+// $radio_button = array("","5 (hight)", "4 (good)", "3 (mean)", "2 (low)", "1 (low)");
+// $radio_button = array( "", "1 (low)", "2 (low)", "3 (mean)", "4 (good)", "5 (hight)" );
$yes_no = array("","Yes","","","","No");
if($type == 1){
if($f < 0 OR $f > 5){ return ""; }