return $statement;
}
+function qid_exists($qid)
+{
+ $q = query_db(
+ "SELECT * FROM questions WHERE qid = ?",
+ [ $qid ])->fetch();
+ return (bool) $q;
+}
+
function get_title($qid)
{
$q = query_db(
exit;
}
+if (isset($qid) && !qid_exists($qid))
+{
+ // Invalid question ID - redirect to new question
+ header("Location: /");
+ exit;
+}
+
$ended = false;
if (isset($qid))
{
<title>Poll!</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
+ html {
+ background-color: #ffd;
+ }
body {
font-family: sans-serif;
max-width: 30em;
margin: 10px auto;
border: 1px solid #cca;
+ border-radius: 5px;
padding: 10px;
- background-color: #ffd;
+ background-color: #fff;
color: #443;
}
input, textarea {
li[draggable=true] {
cursor: grab;
padding: 0.8em;
- border: 1px solid #443;
+ border: 2px solid #443;
border-radius: 5px;
+ background-color: #dff;
+ box-shadow: 5px 5px 5px #ccc;
+ }
+ .result {
+ background-color: #dff;
+ padding: 10px;
+ border-radius: 5px;
+ border: 2px solid #443;
}
hr {
border: none;
<body>
<?php endif ?>
+ <img src="bot.png" height="60" style="float: right;">
+
<?php #########################################################################
# VOTE
<p>Closes: <input type="datetime-local" value="<?= $enddate ?>" disabled> (UTC)</p>
<?php endif ?>
<hr>
- <p>Drag-and-drop the options to order them from favorite (top) to least favorite (bottom).</p>
+ <!-- <p>Drag-and-drop the options to order them from favorite (top) to least favorite (bottom).</p> -->
<form method="post">
<input name="qid" type="hidden" value="<?= $qid ?>">
+ <img src="fave.png" height="40">
+ <img src="drag.png" height="40" style="float: right;">
<ul>
<?php
$options = get_options($qid);
</li>
<?php endforeach ?>
</ul>
+ <img src="least.png" height="40" style="margin-left: 5em">
<input type="submit" value="Cast Vote!">
<small>(Please vote only once)</small>
</form>
<ul>
<?php foreach (get_results($qid) as $opt => $points): ?>
- <li><b><?= $opt ?></b><br>
+ <li class="result"><b><?= $opt ?></b><br>
<!-- Point Count Bar -->
<small>
<?php for ($i = 0; $i < $points; $i ++): ?>/<?php endfor ?>
FOREIGN KEY(qid) REFERENCES questions(qid) ON DELETE CASCADE
);
+DROP INDEX IF EXISTS options_by_qid;
+CREATE INDEX options_by_qid ON options(qid);
DROP TABLE IF EXISTS responses;
CREATE TABLE responses (
FOREIGN KEY(oid) REFERENCES options(oid) ON DELETE CASCADE
);
+DROP INDEX IF EXISTS responses_by_oid;
+CREATE INDEX responses_by_oid ON responses(oid);