diff --git a/composer.lock b/composer.lock index a075dd3..42831e3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,15 +4,15 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c023d89db0d1884f6caab2753f9f04f6", + "content-hash": "225cc22652f4252bb94d4e0317ca2af6", "packages": [ { "name": "hutattedonmyarm/apnuti", - "version": "dev-main", + "version": "0.1.0", "dist": { "type": "path", "url": "../APnutI", - "reference": "a0b03d439f9e8fba3e3f37a8a194a3ccabcff183" + "reference": "9f0c8ba3c6bda4f58dd6dcd488172cb354c15745" }, "require": { "ext-curl": "*", diff --git a/globals.php b/globals.php index 56a52c0..ada40e7 100644 --- a/globals.php +++ b/globals.php @@ -46,7 +46,7 @@ function get_page_header( . file_get_contents(__DIR__.'/icons/home.svg') . 'Home' . '
' - . file_get_contents(__DIR__.'/icons/plus.svg') //TODO + . file_get_contents(__DIR__.'/icons/plus.svg') . 'New Poll
' . $greeting . '
' @@ -59,8 +59,8 @@ function get_page_footer() $version = json_decode(file_get_contents(__DIR__ . '/composer.json'), true)['version']; return ''; } diff --git a/icons/src.svg b/icons/src.svg new file mode 100644 index 0000000..4637816 --- /dev/null +++ b/icons/src.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/new_poll.php b/new_poll.php index 1a568d0..630d236 100644 --- a/new_poll.php +++ b/new_poll.php @@ -19,11 +19,34 @@ try { if (!$api->isAuthenticated(false, true)) { die('You need to be logged in to create a new poll!' . get_page_footer()); } + +if (!empty($_POST['submit'])) { + $prompt = $_POST['prompt']; + $options = $_POST['option']; + $is_anonymous = !empty($_POST['anonymous']); + $is_public = !empty($_POST['public']); + $max_options = (int)$_POST['max_options']; + $duration_days = (int)$_POST['duration_days']; + $duration_hours = (int)$_POST['duration_hours']; + $duration_minutes = (int)$_POST['duration_minutes']; + $duration_total_minutes = $duration_days*60*24 + $duration_hours * 60 + $duration_minutes; + try { + $poll = Poll::create($api, $prompt, $options, $max_options, $duration_total_minutes, $is_anonymous, $is_public); + redirect('view_poll.php?poll_created=1&id='.$poll->id); #TODO: Add posting about poll after creation + } catch (\Exception $e) { + die('Something went wrong creating the poll: "' . $e->getMessage() . '"' . get_page_footer()); + } +} ?>
- +
isAuthenticated(false, true)) { /> + placeholder="This will be option #" + maxlength="64"/>
@@ -50,4 +74,5 @@ if (!$api->isAuthenticated(false, true)) {
- \ No newline at end of file + + \ No newline at end of file diff --git a/scripts/new_poll.js b/scripts/new_poll.js index 4716a8b..88bc70b 100644 --- a/scripts/new_poll.js +++ b/scripts/new_poll.js @@ -19,8 +19,8 @@ function validatePoll() { } const maxOptions = parseInt(form.querySelector('input[name=max_options]').value); - if (numOptionsProvided > 1 && (isNaN(maxOptions) || maxOptions <= 0 || maxOptions >= numOptionsProvided)) { - errors.push(`Max Options needs to be greater than 0 and smaller than ${numOptionsProvided}`); + if (numOptionsProvided > 1 && (isNaN(maxOptions) || maxOptions <= 0 || maxOptions > numOptionsProvided)) { + errors.push(`Max Options needs to at least 1 and not more than ${numOptionsProvided}`); } const durationDays = parseInt(form.querySelector('input[name=duration_days]').value); @@ -32,6 +32,10 @@ function validatePoll() { errors.push('Duration must be more than 1 and less than 20160 minutes'); } + form.querySelector('input[name=duration_days] ~ span').innerText = durationDays === 1 ? 'day' : 'days'; + form.querySelector('input[name=duration_hours] ~ span').innerText = durationHours === 1 ? 'hour' : 'hours'; + form.querySelector('input[name=duration_minutes] ~ span').innerText = durationMinutes === 1 ? 'minute' : 'minutes'; + const closesAtLabel = document.getElementById('openUntil'); if (!isNaN(durationTotalMinutes)) { // Add duration_total_minutes to the curent Date diff --git a/scripts/poll.js b/scripts/poll.js index 0bd14d3..5d6ea6c 100644 --- a/scripts/poll.js +++ b/scripts/poll.js @@ -1,6 +1,6 @@ window.addEventListener('DOMContentLoaded', () => { displayLocalTimestamps(); - for (const el of document.querySelectorAll('.option input[type=checkbox]')) { + for (const el of document.querySelectorAll('.option input[type=checkbox], .option input[type=radio]')) { el.onclick = updateVotesRemaining; } const banner = document.querySelector('.success-banner'); @@ -31,7 +31,9 @@ function compareDateToToday(date) { } function updateVotesRemaining() { - const numChecked = document.querySelectorAll('.option input[type=checkbox]:checked').length; + const numChecked = document + .querySelectorAll('.option input[type=checkbox]:checked, .option input[type=radio]:checked') + .length; const votesRemainingElement = document.querySelector('.votes-remaining'); const total = votesRemainingElement.dataset.maxVotes; const remaining = Math.max(0, total - numChecked); diff --git a/styles/style.css b/styles/style.css index 285c016..724d9e4 100644 --- a/styles/style.css +++ b/styles/style.css @@ -254,4 +254,8 @@ footer { background: var(--secondary-bg-color); box-shadow: var(--default-shadow); font-size: smaller; +} + +footer .sourcecode svg { + stroke-width: 1.5em; } \ No newline at end of file diff --git a/view_poll.php b/view_poll.php index 621bf31..8e7a6dc 100644 --- a/view_poll.php +++ b/view_poll.php @@ -66,6 +66,11 @@ if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?> + +
@@ -111,9 +116,9 @@ if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?> $checked = $option->is_your_response ? 'checked' : ''; ?>
+ type="" value="position ?>" - name=""/> + name=""/> text . ' (' . $option->respondents . ')'?>