diff --git a/composer.json b/composer.json index 9a8964e..7c2cf7a 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,7 @@ { + "name": "hutattedonmyarm/dragonpolls", + "version": "0.1.0", + "description": "A polling client for pnut.io", "require": { "hutattedonmyarm/apnuti": "@dev" }, diff --git a/globals.php b/globals.php index 4ab57ed..56a52c0 100644 --- a/globals.php +++ b/globals.php @@ -51,7 +51,18 @@ function get_page_header( . $greeting . '
' . $logout_link - . ''; + . '
'; +} + +function get_page_footer() +{ + $version = json_decode(file_get_contents(__DIR__ . '/composer.json'), true)['version']; + return '
'; } function redirect($to) diff --git a/index.php b/index.php index aa94d7f..f2c61f8 100644 --- a/index.php +++ b/index.php @@ -3,3 +3,4 @@ require_once __DIR__ .'/bootstrap.php'; echo get_page_header(); +echo get_page_footer(); diff --git a/scripts/poll.js b/scripts/poll.js index 6407332..0bd14d3 100644 --- a/scripts/poll.js +++ b/scripts/poll.js @@ -3,7 +3,10 @@ window.addEventListener('DOMContentLoaded', () => { for (const el of document.querySelectorAll('.option input[type=checkbox]')) { el.onclick = updateVotesRemaining; } - document.querySelector('.success-banner').onclick = hideBanner; + const banner = document.querySelector('.success-banner'); + if (banner) { + banner.onclick = hideBanner; + } }); function displayLocalTimestamps() { diff --git a/styles/style.css b/styles/style.css index df16f03..8caaec3 100644 --- a/styles/style.css +++ b/styles/style.css @@ -29,6 +29,12 @@ body { background: var(--main-bg-color); color: var(--main-fg-color); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Cantarell, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; + display: flex; + flex-direction: column; +} + +main { + flex-grow: 1; } button { @@ -87,7 +93,7 @@ header { align-items: center; } -header a { +header a, footer a { margin-right: 1em; } @@ -174,4 +180,14 @@ datewrapper time { .success-banner span { font-size: x-large; +} + +/* Footer */ +footer { + display: flex; + align-items: center; + padding: 8px; + background: var(--secondary-bg-color); + box-shadow: var(--default-shadow); + font-size: smaller; } \ No newline at end of file diff --git a/view_poll.php b/view_poll.php index 7429a3a..621bf31 100644 --- a/view_poll.php +++ b/view_poll.php @@ -13,11 +13,11 @@ use APnutI\Entities\User; try { echo get_page_header('Poll', true, ['poll']); } catch (\Exception $e) { - die('Something went wrong :( "'.$e->getMessage().'"'); + die('Something went wrong :( "' . $e->getMessage() . '"' . get_page_footer()); } if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) { - die('Invalid poll ID'); + die('Invalid poll ID'.get_page_footer()); } $poll_id = (int)$_GET['id']; $poll = null; @@ -26,9 +26,9 @@ try { $poll_token = array_key_exists('polltoken', $_GET) ? $_GET['polltoken'] : null; $poll = $api->getPoll($poll_id, $poll_token); } catch (NotFoundException $nfe) { - die('Poll not found'); + die('Poll not found'.get_page_footer()); } catch (NotSupportedPollException $nspe) { - die('Sorry, this poll has a not yet supported type: ' . $nspe->getMessage()); + die('Sorry, this poll has a not yet supported type: ' . $nspe->getMessage() . get_page_footer()); } catch (PollAccessRestrictedException $are) { $message = array_key_exists('polltoken', $_GET) ? 'Sorry, your poll token is invalid! Please enter a valid token: ' @@ -38,9 +38,10 @@ try { $message . '
' . '
' + . get_page_footer() ); } catch (\Exception $e) { - die('Something went wrong :( "'.$e->getMessage().'"'); + die('Something went wrong :( "'.$e->getMessage().'"' . get_page_footer()); } jslog($poll); @@ -63,7 +64,7 @@ $disabled_button = ($poll->canVote() && count($user_votes) > 0) ? '' : 'disabled if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?>
@@ -104,10 +105,15 @@ if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?> 'include_html' => false, 'include_counts' => false, ]; + $input_type = $poll->max_options === 1 ? 'radio' : 'checkbox'; + $input_name = $poll->max_options === 1 ? 'options' : 'options[]'; foreach ($poll->options as $option) { $checked = $option->is_your_response ? 'checked' : ''; ?>
- value="position ?>" name="options[]"/> + + value="position ?>" + name=""/> text . ' (' . $option->respondents . ')'?>
@@ -133,4 +139,4 @@ if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?>
- + diff --git a/vote_poll.php b/vote_poll.php index 2a7ac7f..392463d 100644 --- a/vote_poll.php +++ b/vote_poll.php @@ -2,16 +2,21 @@ require_once __DIR__ . '/bootstrap.php'; $voted_options = []; -foreach ($_POST['options'] as $option) { - $voted_options[] = (int)$option; +if (is_array($_POST['options'])) { + foreach ($_POST['options'] as $option) { + $voted_options[] = (int)$option; + } +} else { + $voted_options[] = (int)$_POST['options']; } try { $res = $api->voteInPoll((int)$_POST['pollid'], $voted_options, $_POST['polltoken']); } catch (\Exception $e) { get_page_header('Voting error'); - $str = 'Sorry, something went wrong while voting!' - . 'Please yell at @hutattedonmyarm>
' - . 'Go back to the poll'; + $str = 'Sorry, something went wrong while voting! "' + . $e->getMessage() + . '"
Please yell at @hutattedonmyarm
' + . 'Go back to the poll'; die($str); } redirect('view_poll.php?id='.$_POST['pollid'].'&success=1');