]> littlesong.place Git - poll.git/commitdiff
Add images, general fixes
authorChris Fulljames <christianfulljames@gmail.com>
Sat, 30 May 2026 14:18:22 +0000 (10:18 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Sat, 30 May 2026 14:18:22 +0000 (10:18 -0400)
bot.png [new file with mode: 0644]
drag.png [new file with mode: 0644]
fave.png [new file with mode: 0644]
index.php
least.png [new file with mode: 0644]
schema.sql

diff --git a/bot.png b/bot.png
new file mode 100644 (file)
index 0000000..8ae55d9
Binary files /dev/null and b/bot.png differ
diff --git a/drag.png b/drag.png
new file mode 100644 (file)
index 0000000..85ae8ad
Binary files /dev/null and b/drag.png differ
diff --git a/fave.png b/fave.png
new file mode 100644 (file)
index 0000000..794507a
Binary files /dev/null and b/fave.png differ
index 0cb3a07090a8d70face8046379f41aada96ea02f..e201106da22b312d349794fc1558ccb78c99c85e 100644 (file)
--- a/index.php
+++ b/index.php
@@ -17,6 +17,14 @@ function query_db($query, $params=null)
     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(
@@ -124,6 +132,13 @@ if (isset($_POST['title']) and isset($_POST['options']))
     exit;
 }
 
+if (isset($qid) && !qid_exists($qid))
+{
+    // Invalid question ID - redirect to new question
+    header("Location: /");
+    exit;
+}
+
 $ended = false;
 if (isset($qid))
 {
@@ -180,13 +195,17 @@ if (isset($qid) && isset($_GET['count'])) {
     <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 {
@@ -232,8 +251,16 @@ if (isset($qid) && isset($_GET['count'])) {
     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;
@@ -261,6 +288,8 @@ if (isset($qid) && isset($_GET['count'])) {
 <body>
 <?php endif ?>
 
+    <img src="bot.png" height="60" style="float: right;">
+
 <?php #########################################################################
 # VOTE
 
@@ -271,9 +300,11 @@ if (isset($qid) && $view == "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);
@@ -288,6 +319,7 @@ if (isset($qid) && $view == "vote"): ?>
             </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>
@@ -343,7 +375,7 @@ elseif (isset($qid)): ?>
 
     <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 ?>
diff --git a/least.png b/least.png
new file mode 100644 (file)
index 0000000..ac180c2
Binary files /dev/null and b/least.png differ
index 152a91120b304b1f9ca1bb3759530a4b4d180439..c5fa308fc74aacaeffed0c9661267ec5c7f8659b 100644 (file)
@@ -13,6 +13,8 @@ CREATE TABLE options (
 
     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 (
@@ -22,4 +24,6 @@ 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);