exit;
}
+$ended = false;
+if (isset($qid))
+{
+ $enddate = get_end_date($qid);
+ if ($enddate)
+ {
+ $nowdate = gmdate("Y-m-d\TH:i");
+ $ended = $nowdate > $enddate;
+ }
+
+ if ($ended && $view == "vote")
+ {
+ // Poll ended - redirect to results
+ header("Location: ".poll_url($qid, "results"));
+ exit;
+ }
+}
+
// Voting
if (isset($_POST['qid']))
{
- foreach ($_POST as $key => $value)
+ if (!$ended)
{
- $prefix = "opt-";
- if (str_starts_with($key, $prefix))
+ foreach ($_POST as $key => $value)
{
- $opt = substr($key, strlen($prefix));
- $opt = str_replace("_", " ", $opt);
- add_vote($_POST['qid'], $opt, (int) $value);
+ $prefix = "opt-";
+ if (str_starts_with($key, $prefix))
+ {
+ $opt = substr($key, strlen($prefix));
+ $opt = str_replace("_", " ", $opt);
+ add_vote($_POST['qid'], $opt, (int) $value);
+ }
}
}
exit;
}
-$ended = false;
-if (isset($qid))
-{
- $enddate = get_end_date($qid);
- if ($enddate)
- {
- $nowdate = gmdate("Y-m-d\TH:i");
- $ended = $nowdate > $enddate;
- }
-}
-
?>
<!DOCTYPE html>
<html>
border: 1px solid #cca;
padding: 10px;
background-color: #ffd;
- color: #434;
+ color: #443;
}
input, textarea {
font-family: sans-serif;
width: 100%;
margin-bottom: 0.5em;
}
+ textarea {
+ resize: vertical;
+ }
input[type=submit] {
background: #fdf;
- color: #434;
+ color: #443;
border: 0;
cursor: pointer;
border-radius: 5px;
- padding: 5px;
+ padding: 10px;
font-weight: bold;
margin: 10px 0px;
}
input[disabled] {
background: none;
border: none;
- color: #434;
+ color: #443;
+ width: unset;
}
input[type=number] {
width: unset;
li[draggable=true] {
cursor: grab;
padding: 0.8em;
- border: 1px solid #cca;
+ border: 1px solid #443;
+ border-radius: 5px;
}
hr {
border: none;
<?php #########################################################################
# VOTE
-if (isset($qid) && $view == "vote" && !$ended): ?>
+if (isset($qid) && $view == "vote"): ?>
<h2><?= get_title($qid) ?></h2>
<?php if ($enddate): ?>
<p>Closes: <input type="datetime-local" value="<?= $enddate ?>" disabled> (UTC)</p>
<?php endif ?>
- <!--
- <p>
- The option with the most points wins!
- Give your favorite option 5 points, second favorite 4 points, etc.
- Or give them all 5 points if you really can't decide.
- </p>
- -->
-
<hr>
+ <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 ?>">
<ul>
<?php endforeach ?>
</ul>
<input type="submit" value="Cast Vote!">
+ <small>(Please vote only once)</small>
</form>
<script>
<hr>
<br><a href="<?= poll_url($qid, "results") ?>">Show Results</a>
- <br><br><a href="/">New Poll</a>
+ | <a href="/">New Poll</a>
<?php #########################################################################
# RESULTS
<h2><?= get_title($qid) ?></h2>
<?php if ($ended): ?>
- <p>Poll has ended.</p>
+ <small>Poll has ended.</small>
<?php endif ?>
<ul>