isError()) { exit_no_group(); } $is_admin_page='y'; $sh = new SurveyHtml(); $is_admin_page='y'; if (!session_loggedin() || !user_ismember($group_id,'A')) { 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; } $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) { $sh->header(array()); print "\n".''."\n"; print ""; //print ""; foreach ($header as $id=>$col){ print ""; } print "\n"; foreach ($s2 as $k=>$val){ print ""; //print ""; $val = array_reverse($val); foreach ($val as $k1=>$val1){ $res = format($val1,$types[$k1]); print ""; } print "\n"; } print "
User$col
$k$res
"; $sh->footer(); } else { // CSV mode 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){ echo '"'.fix4csv($col).'";'; } foreach ($s2 as $k=>$val){ echo "\n"; foreach ($header as $id=>$col){ $res = format($val[$id],$types[$id]); echo '"'.$res.'";'; } } } } } /* * 1: Radio Buttons 1-5 * 2: Text Area * 3: Radio Buttons Yes/No * 4: Comment Only * 5: Text Field * 6: None */ 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)" ); $yes_no = array("","Yes","","","","No"); if($type == 1){ if($f < 0 OR $f > 5){ return ""; } //return($radio_button[$f]); return($f); } if($type == 3){ if($f < 0 OR $f > 5){ return ""; } return($yes_no[$f]); } if($type == 4){ // Comment only => "" return(""); } if($type == 6){ return "None"; } // 2 - Text Area :: 5: Text Field return(fix4csv($f)); } function fix4csv ($value) { $value =& util_unconvert_htmlspecialchars( $value ); $value =& str_replace("\r\n", "\n", $value); $value =& str_replace('"', '""', $value); return $value; }