From d2a626ffcfdac4e581ea826f0b134b6e0ced65ae Mon Sep 17 00:00:00 2001 From: Alex Fuchs Date: Mon, 16 Aug 2021 22:32:01 +0200 Subject: [PATCH] restore voting functionality, keep staff votes for later use --- db_conn.php | 15 ++++++++ index.php | 6 ++-- output.php | 21 ++--------- staffvote.php | 17 +-------- thanks.php | 98 ++++++++++++++++++++++++--------------------------- vote.php | 16 +-------- 6 files changed, 70 insertions(+), 103 deletions(-) create mode 100644 db_conn.php diff --git a/db_conn.php b/db_conn.php new file mode 100644 index 0000000..31778f7 --- /dev/null +++ b/db_conn.php @@ -0,0 +1,15 @@ +load(); +$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS', 'DB_PORT']); + +$remote = mysqli_connect(getenv('DB_HOST'), + getenv('DB_USER'), + getenv('DB_PASS'), + getenv('DB_NAME'), + getenv('DB_PORT')); +if (mysqli_connect_errno()) { + printf("Couldn't connect to database! %s\n", mysqli_connect_error()); + exit(); +} \ No newline at end of file diff --git a/index.php b/index.php index 450d08b..4500c52 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,8 @@ session_unset(); -if(time()>1605459600) { +if(time()>1605459600 && false) { //TODO: edit the timestamp so it matches the desired end of the contest + //TODO edit the page for the new branding echo ' @@ -20,7 +21,7 @@ - + @@ -73,6 +74,7 @@ '; } else { + //TODO implement rebranding echo ' diff --git a/output.php b/output.php index c1067bd..d3b051d 100644 --- a/output.php +++ b/output.php @@ -1,29 +1,15 @@ load(); -$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS', 'DB_PORT']); - -$remote = mysqli_connect(getenv('DB_HOST'), - getenv('DB_USER'), - getenv('DB_PASS'), - getenv('DB_NAME'), - getenv('DB_PORT')); -if (mysqli_connect_errno()) { - printf("Couldn't connect to database! %s\n", mysqli_connect_error()); - exit(); -} if(isset($_POST['selected'])) { $query = "update logocontest.logos set active=0 where id = ".$_POST['selected'].";"; $result = mysqli_query($remote, $query); } -$query = "select * from logocontest.output order by name ASC;"; +$query = "select * from logocontest.output order by won_matchups/output.matchups DESC,output.matchups DESC ;"; $result = mysqli_query($remote, $query); @@ -49,8 +35,7 @@
-

All the logos to choose from!

-

Hint: click on a logo to see it in full size!

+

Output of the current votings

diff --git a/staffvote.php b/staffvote.php index 6e79802..53734cf 100644 --- a/staffvote.php +++ b/staffvote.php @@ -1,22 +1,7 @@ load(); -$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS', 'DB_PORT']); - -$remote = mysqli_connect(getenv('DB_HOST'), - getenv('DB_USER'), - getenv('DB_PASS'), - getenv('DB_NAME'), - getenv('DB_PORT')); -if (mysqli_connect_errno()) { - printf("Couldn't connect to database! %s\n", mysqli_connect_error()); - exit(); -} +include_once "db_conn.php"; $query = "select * from logocontest.output order by name ASC;"; $result = mysqli_query($remote, $query); diff --git a/thanks.php b/thanks.php index 1eb622f..59644c0 100644 --- a/thanks.php +++ b/thanks.php @@ -1,61 +1,50 @@ load(); -$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS', 'DB_PORT']); - -$remote = mysqli_connect(getenv('DB_HOST'), - getenv('DB_USER'), - getenv('DB_PASS'), - getenv('DB_NAME'), - getenv('DB_PORT')); -if (mysqli_connect_errno()) { - printf("Couldn't connect to database! %s\n", mysqli_connect_error()); - exit(); -} - -if($_POST == []) { - header("Location: staffvote.php"); -} -$query = "select * from ivoted where sessionid = '".session_id()."'"; -$q = mysqli_query($remote,$query); -if($q->num_rows > 0) { - echo "You tried to vote more than once, even though we told you not to. Ollie is very disappointed in you."; - die(); -} -$query = "insert into ivoted values('".session_id()."',".time().")"; -$q = mysqli_query($remote,$query); +if(time()>0 && false) {//TODO enter timestamp here + if($_POST == []) { + header("Location: staffvote.php"); + } + // Single voting is only used for staff voting. During the regular voting time, you can vote as much as you want. + $query = "select * from ivoted where sessionid = '".session_id()."'"; + $q = mysqli_query($remote,$query); + if($q->num_rows > 0) { + echo "You tried to vote more than once, even though we told you not to. Ollie is very disappointed in you."; + die(); + } + $query = "insert into ivoted values('".session_id()."',".time().")"; + $q = mysqli_query($remote,$query); -$query = ""; -if(isset($_POST['ollieburn'])) { - $query = "update logocontest.logos set `ollieburn` = `ollieburn` + 1 where `id` = ".$_POST['ollieburn']."; "; + $query = ""; + if(isset($_POST['ollieburn'])) { + $query = "update logocontest.logos set `ollieburn` = `ollieburn` + 1 where `id` = ".$_POST['ollieburn']."; "; + $q = mysqli_query($remote,$query); + } + $query = "update logocontest.logos set `paint` = `paint` + 1 where `id` = ".$_POST['paint']."; "; $q = mysqli_query($remote,$query); -} -$query = "update logocontest.logos set `paint` = `paint` + 1 where `id` = ".$_POST['paint']."; "; -$q = mysqli_query($remote,$query); -$query = "update logocontest.logos set `animal` = `animal` + 1 where `id` = ".$_POST['animal']."; "; -$q = mysqli_query($remote,$query); -$query = "update logocontest.logos set `staff` = `staff` + 1 where `id` = ".$_POST['staff'].";"; -$q = mysqli_query($remote,$query); -if(isset($_POST['ollieburn'])) { - $query = "select * from logos where id = ".$_POST['ollieburn']; + $query = "update logocontest.logos set `animal` = `animal` + 1 where `id` = ".$_POST['animal']."; "; $q = mysqli_query($remote,$query); - $ollie = mysqli_fetch_assoc($q); + $query = "update logocontest.logos set `staff` = `staff` + 1 where `id` = ".$_POST['staff'].";"; + $q = mysqli_query($remote,$query); + if(isset($_POST['ollieburn'])) { + $query = "select * from logos where id = ".$_POST['ollieburn']; + $q = mysqli_query($remote,$query); + $ollie = mysqli_fetch_assoc($q); + } + $query = "select * from logos where id = ".$_POST['paint']; + $q = mysqli_query($remote,$query); + $paint = mysqli_fetch_assoc($q); + $query = "select * from logos where id = ".$_POST['animal']; + $q = mysqli_query($remote,$query); + $animal = mysqli_fetch_assoc($q); + $query = "select * from logos where id = ".$_POST['staff']; + $q = mysqli_query($remote,$query); + $staff = mysqli_fetch_assoc($q); } -$query = "select * from logos where id = ".$_POST['paint']; -$q = mysqli_query($remote,$query); -$paint = mysqli_fetch_assoc($q); -$query = "select * from logos where id = ".$_POST['animal']; -$q = mysqli_query($remote,$query); -$animal = mysqli_fetch_assoc($q); -$query = "select * from logos where id = ".$_POST['staff']; -$q = mysqli_query($remote,$query); -$staff = mysqli_fetch_assoc($q); @@ -98,8 +87,10 @@
'; -if(isset($ollie)) { - echo '
+ +if(time()>0 && false) {//TODO enter timestamp here + if(isset($ollie)) { + echo '

OllieBurn award:

'.$ollie['name'].' @@ -119,8 +110,8 @@

Staff Choice:

'.$staff['name'].'
'; -} else { - echo ' + } else { + echo '

MSPaint award:

@@ -139,8 +130,11 @@ '.$staff['name'].'
'; + } } + + echo '
diff --git a/vote.php b/vote.php index 0aa8426..d74f67e 100644 --- a/vote.php +++ b/vote.php @@ -1,21 +1,7 @@ load(); -$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS', 'DB_PORT']); - -$remote = mysqli_connect(getenv('DB_HOST'), - getenv('DB_USER'), - getenv('DB_PASS'), - getenv('DB_NAME'), - getenv('DB_PORT')); -if (mysqli_connect_errno()) { - printf("Couldn't connect to database! %s\n", mysqli_connect_error()); - exit(); -} +include_once "db_conn.php"; if(isset($_POST['selected'])) { //Store the Cantor number representing the IDs in the session.