From: Chris Fulljames Date: Fri, 29 May 2026 21:13:32 +0000 (-0400) Subject: Prevent voting after close X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=61303f99397b1a8d45c0ea706aba77424b9aede9;p=poll.git Prevent voting after close --- diff --git a/index.php b/index.php index 5642e00..0cb3a07 100644 --- a/index.php +++ b/index.php @@ -124,17 +124,38 @@ if (isset($_POST['title']) and isset($_POST['options'])) 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); + } } } @@ -152,17 +173,6 @@ if (isset($qid) && isset($_GET['count'])) { exit; } -$ended = false; -if (isset($qid)) -{ - $enddate = get_end_date($qid); - if ($enddate) - { - $nowdate = gmdate("Y-m-d\TH:i"); - $ended = $nowdate > $enddate; - } -} - ?> @@ -177,7 +187,7 @@ if (isset($qid)) border: 1px solid #cca; padding: 10px; background-color: #ffd; - color: #434; + color: #443; } input, textarea { font-family: sans-serif; @@ -186,20 +196,24 @@ if (isset($qid)) 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; @@ -218,7 +232,8 @@ if (isset($qid)) li[draggable=true] { cursor: grab; padding: 0.8em; - border: 1px solid #cca; + border: 1px solid #443; + border-radius: 5px; } hr { border: none; @@ -249,21 +264,14 @@ if (isset($qid)) +if (isset($qid) && $view == "vote"): ?>

Closes: (UTC)

- -
+

Drag-and-drop the options to order them from favorite (top) to least favorite (bottom).

+ (Please vote only once)