\n");
} //end if empty($guicross)
} //end if ($tid < 50)
$counts = array();
switch ($table) {
// -------------------------------- response_bool --------------------------------
case 'response_bool':
$counts = array(_('Yes') => 0, _('No') => 0);
$sql = "SELECT A.choice_id, COUNT(A.response_id)
FROM ".$GLOBALS['ESPCONFIG'][$table.'_table']." A
WHERE A.question_id='${qid}' AND
A.response_id ${ridstr} AND
A.choice_id != ''
GROUP BY A.choice_id";
if ($GLOBALS['ESPCONFIG']['DEBUG_RESULTS'])
echo("\n");
if ($result = execute_sql($sql)) {
while(list($ccontent,$count) = fetch_row($result)) {
$result->MoveNext();
$ccontent = htmlspecialchars($ccontent);
if ($ccontent == 'Y')
$ccontent = _('Yes');
else
$ccontent = _('No');
$counts[$ccontent] = $count;
}
db_close($result);
}
if (empty($question["result_id"]))
$question["result_id"] = 1; // default to percentages for yes/no
break;
// -------------------------------- response_single --------------------------------
// -------------------------------- response_multiple --------------------------------
case 'response_multiple':
$totals = 0;
case 'response_single':
$sql = "SELECT C.content FROM ".$GLOBALS['ESPCONFIG']['question_choice_table']." C
WHERE C.question_id='${qid}' AND C.content NOT LIKE '!other%'
ORDER BY C.id";
if ($result = execute_sql($sql)) {
for ($j = 0; $j < record_count($result); $j++) {
$result->Move($j);
$counts[htmlspecialchars($result->fields[0])] = 0;
}
db_close($result);
}
$sql = "SELECT C.content, COUNT(A.response_id) AS num
FROM ".$GLOBALS['ESPCONFIG']['question_choice_table']." C,
".$GLOBALS['ESPCONFIG'][$table.'_table']." A
WHERE C.question_id='${qid}' AND
C.content NOT LIKE '!other%' AND
A.question_id=C.question_id AND
A.choice_id=C.id AND
A.response_id ${ridstr}
GROUP BY C.id, C.content";
if ($GLOBALS['ESPCONFIG']['DEBUG_RESULTS'])
echo("\n");
if ($result = execute_sql($sql)) {
while (list($ccontent,$count) = fetch_row($result)) {
$result->MoveNext();
$ccontent = htmlspecialchars($ccontent);
$counts[$ccontent] = $count;
}
db_close($result);
}
// handle 'other...'
$sql = "SELECT A.response, C.content
FROM ".$GLOBALS['ESPCONFIG']['response_other_table']." A, ".$GLOBALS['ESPCONFIG']['question_choice_table']." C
WHERE A.question_id='${qid}' AND
A.choice_id=C.id AND
A.response_id ${ridstr}
ORDER BY C.id, A.response";
if ($GLOBALS['ESPCONFIG']['DEBUG_RESULTS']) echo("\n");
if ($result = execute_sql($sql)) {
while(list($answer,$ccontent) = fetch_row($result)) {
$result->MoveNext();
$ccontent = htmlspecialchars($ccontent);
$content = preg_replace(array('/^!other=/', '/^!other/'),
array('', 'Other:'), $ccontent);
$content .= ' ' . htmlspecialchars($answer);
$counts[$content] = (isset($counts[$content]) ? $counts[$content] : 0)+1;
}
db_close($result);
}
if (empty($question["result_id"]))
$question["result_id"] = 1; // default to percentages
break;
// -------------------------------- response_text --------------------------------
case 'response_text':
$sql = "SELECT A.response, COUNT(A.response_id) AS num
FROM ".$GLOBALS['ESPCONFIG'][$table.'_table']." A
WHERE A.question_id='${qid}' AND
A.response_id ${ridstr}
GROUP BY A.response";
if($GLOBALS['ESPCONFIG']['DEBUG_RESULTS']) echo("\n");
if($result = execute_sql($sql)) {
while(list($text, $num) = fetch_row($result)) {
$result->MoveNext();
if(!empty($text))
$counts[htmlspecialchars($text)] = $num;
}
db_close($result);
}
$question["result_id"] = 4; // force "list" type response for text fields
break;
// -------------------------------- response_date --------------------------------
case 'response_date':
$sql = "SELECT DATE_FORMAT(A.response,'".$GLOBALS['ESPCONFIG']['date_format']."'), COUNT(A.response_id) AS num
FROM ".$GLOBALS['ESPCONFIG'][$table.'_table']." A
WHERE A.question_id='${qid}' AND
A.response_id ${ridstr}
GROUP BY A.response";
if($GLOBALS['ESPCONFIG']['DEBUG_RESULTS']) echo("\n");
if($result = execute_sql($sql)) {
while(list($text, $num) = fetch_row($result)) {
$result->MoveNext();
if(!empty($text))
$counts[htmlspecialchars($text)] = $num;
}
db_close($result);
}
$question["result_id"] = 4; // force "list" type response for date fields
break;
// -------------------------------- response_rank --------------------------------
case 'response_rank':
if($tid == 8) { //Rank
$sql = "SELECT C.content FROM ".$GLOBALS['ESPCONFIG']['question_choice_table']." C
WHERE C.question_id='${qid}' AND C.content NOT LIKE '!other%'
ORDER BY C.id";
if ($result = execute_sql($sql)) {
for ($j = 0; $j < record_count($result); $j++) {
$result->Move($j);
$counts[htmlspecialchars($result->fields[0])] = null;
}
db_close($result);
}
$sql = "SELECT C.content, AVG(A.rank+1) AS average
FROM ".$GLOBALS['ESPCONFIG']['question_choice_table']." C, ".$GLOBALS['ESPCONFIG'][$table.'_table']." A
WHERE C.question_id='${qid}' AND
A.question_id='${qid}' AND
A.choice_id=C.id AND
A.rank>=0 AND
A.response_id ${ridstr}
GROUP BY C.id, C.content";
if($GLOBALS['ESPCONFIG']['DEBUG_RESULTS']) echo("\n");
if($result = execute_sql($sql)) {
while(list($ccontent,$avg) = fetch_row($result)) {
$result->MoveNext();
$ccontent = htmlspecialchars($ccontent);
$counts[$ccontent] = $avg;
}
db_close($result);
}
$question["result_id"] = 99; // force to rank
} else {
$sql = "SELECT A.rank, COUNT(A.response_id) AS num
FROM ".$GLOBALS['ESPCONFIG'][$table.'_table']." A
WHERE A.question_id='${qid}' AND
A.response_id ${ridstr}
GROUP BY A.rank";
if($result = execute_sql($sql)) {
while(list($rank, $num) = fetch_row($result)) {
$result->MoveNext();
if($rank == -1) { $rank = "N/A"; }
$counts[_($rank)] += $num;
}
db_close($result);
}
if(empty($question["result_id"]))
$question["result_id"] = 2; // default to rank
}
break;
}
// ---------------------------------------------------------------------------
if (!empty($guicross) && $question["result_id"] == 1){
mkcrossformat($counts,$qid,$tid);
} else {
switch($question["result_id"]) {
case "1": // Percentages
mkrespercent($counts,$total,$precision,$totals);
break;
case "2": // Rank
mkresrank($counts,$total,$precision,$totals);
break;
case "3": // Count
mkrescount($counts,$total,$precision,$totals);
break;
case "4": // List
mkreslist($counts,$total,$precision,$totals);
break;
case "99": // Average
mkresavg($counts,$total,$precision,$totals,$question['length']);
break;
} // end switch
} //end if
?>