I needed to get the export functionality working, but couldn't get my head around the way UCCASS did things so I wrote my own export functionality. You can replace the results_csv.php file with this code. Note you will need to put the database configuration details in this script. It does not read them from UCCASS.
CODE
<?php
$db_host = 'localhost';
$db_username = '';
$db_password = '';
$db_name = '';
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-Type: text/plain;");
header("Content-Disposition: attachment; filename=Export.csv");
if (!$link = mysql_connect($db_host, $db_username, $db_password)) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db($db_name, $link)) {
echo 'Could not select database';
exit;
}
$sid = $_REQUEST['sid'];
$export_type = $_REQUEST['export_type'];
if (empty($sid) || empty($export_type)) {
die("No survey id or export type supplied");
}
//get list of questions
$query = sprintf("SELECT qid, oid, question FROM questions WHERE sid = %d AND aid != 899 ORDER BY qid", $sid);
$result = mysql_query(mysql_real_escape_string($query));
while ($row = mysql_fetch_object($result)) {
$questions[$row->oid] = str_replace("\n"," ", $row->question) ." ({$row->oid})";
$q_order[$row->qid] = $row->oid;
}
//get results (text)
$query = sprintf("SELECT rt.sequence, rt.qid, rt.answer FROM results_text rt WHERE rt.sid = %d ORDER BY rt.qid", $sid);
$result = mysql_query(mysql_real_escape_string($query)) or die(mysql_error());
while ($row = mysql_fetch_object($result)) {
$res[$row->sequence][$q_order[$row->qid]] = str_replace("\n"," ", $row->answer);
}
if ($export_type == 1 ) {
//get results (non-text)
$query = sprintf("SELECT r.sequence, r.qid, av.value FROM results r JOIN answer_values av ON r.avid = av.avid WHERE r.sid = %d ORDER BY r.qid", $sid);
$result = mysql_query(mysql_real_escape_string($query)) or die(mysql_error());
while ($row = mysql_fetch_object($result)) {
if (!isset($res[$row->sequence][$q_order[$row->qid]])) {
$res[$row->sequence][$q_order[$row->qid]] = str_replace("\n"," ", $row->value);
}
}
}
else if ($export_type == 2) {
//get results (non-text)
$query = sprintf("SELECT r.sequence, r.qid, av.numeric_value FROM results r JOIN answer_values av ON r.avid = av.avid WHERE r.sid = %d ORDER BY r.qid", $sid);
$result = mysql_query(mysql_real_escape_string($query)) or die(mysql_error());
while ($row = mysql_fetch_object($result)) {
if (!isset($res[$row->sequence][$q_order[$row->qid]])) {
$res[$row->sequence][$q_order[$row->qid]] = str_replace("\n"," ", $row->numeric_value);
}
}
}
ksort($questions);
foreach ($res as $res_row_id => $res_row) {
foreach ($questions as $oid => $question) {
$output[$res_row_id][$oid] = !empty($res_row[$oid]) ? $res_row[$oid] : ' ';
}
}
array_unshift($output, $questions);
foreach ($output as $sequence => $response) {
echo '"'. $sequence . '","'. implode('","', $response) ."\"\n";
}
?>