You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once __DIR__ . "/required.php";
|
|
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
$qid = $VARS['qid'];
|
|
|
|
|
|
|
|
if (!$database->has('questions', ['qid' => $qid])) {
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
$total = $database->count('responses', ['qid' => $qid]);
|
|
|
|
$answers = $database->select('answers', ['aid', 'atext'], ['qid' => $qid]);
|
|
|
|
$data['total'] = $total;
|
|
|
|
$data['answers'] = [];
|
|
|
|
foreach ($answers as $a) {
|
|
|
|
$votes = $database->count('responses', ['aid' => $a['aid']]);
|
|
|
|
|
|
|
|
$data['answers'][] = [
|
|
|
|
"id" => $a['aid'],
|
|
|
|
"votes" => $votes,
|
|
|
|
"percent" => ($votes / $total) * 100.0 . "%"
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$responses = $database->select('responses', ['name', 'aid'], ['qid' => $qid]);
|
|
|
|
$data['responses'] = [];
|
|
|
|
foreach ($responses as $r) {
|
|
|
|
if ($r['name'] == null) {
|
|
|
|
$r['name'] = "Anonymous";
|
|
|
|
}
|
|
|
|
$data['responses'][] = [
|
|
|
|
"name" => $r['name'],
|
|
|
|
"aid" => $r['aid']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode($data);
|