Added poll creation, srourcecode icon
This commit is contained in:
parent
4572e730f9
commit
67283a9474
6
composer.lock
generated
6
composer.lock
generated
@ -4,15 +4,15 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "c023d89db0d1884f6caab2753f9f04f6",
|
"content-hash": "225cc22652f4252bb94d4e0317ca2af6",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "hutattedonmyarm/apnuti",
|
"name": "hutattedonmyarm/apnuti",
|
||||||
"version": "dev-main",
|
"version": "0.1.0",
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "path",
|
"type": "path",
|
||||||
"url": "../APnutI",
|
"url": "../APnutI",
|
||||||
"reference": "a0b03d439f9e8fba3e3f37a8a194a3ccabcff183"
|
"reference": "9f0c8ba3c6bda4f58dd6dcd488172cb354c15745"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-curl": "*",
|
"ext-curl": "*",
|
||||||
|
@ -46,7 +46,7 @@ function get_page_header(
|
|||||||
. file_get_contents(__DIR__.'/icons/home.svg')
|
. file_get_contents(__DIR__.'/icons/home.svg')
|
||||||
. '<span class="linklabel">Home</span></div></a>'
|
. '<span class="linklabel">Home</span></div></a>'
|
||||||
. '<a href="new_poll.php" class="newpolllink '.$newpoll_class.'" title="New Poll"><div class="linkcontents">'
|
. '<a href="new_poll.php" class="newpolllink '.$newpoll_class.'" title="New Poll"><div class="linkcontents">'
|
||||||
. file_get_contents(__DIR__.'/icons/plus.svg') //TODO
|
. file_get_contents(__DIR__.'/icons/plus.svg')
|
||||||
. '<span class="linklabel">New Poll</span></div></a>'
|
. '<span class="linklabel">New Poll</span></div></a>'
|
||||||
. $greeting
|
. $greeting
|
||||||
. '<div class="spacer"></div>'
|
. '<div class="spacer"></div>'
|
||||||
@ -59,8 +59,8 @@ function get_page_footer()
|
|||||||
$version = json_decode(file_get_contents(__DIR__ . '/composer.json'), true)['version'];
|
$version = json_decode(file_get_contents(__DIR__ . '/composer.json'), true)['version'];
|
||||||
return '</main><footer>'
|
return '</main><footer>'
|
||||||
. '<a href="https://phlaym.net/git/phlaym/Pfadlock/releases/tag/'.$version.'">Version ' . $version . '</a>'
|
. '<a href="https://phlaym.net/git/phlaym/Pfadlock/releases/tag/'.$version.'">Version ' . $version . '</a>'
|
||||||
. '<a href="https://phlaym.net/git/phlaym/Dragonpolls" title="Source"><div class="linkcontents">'
|
. '<a href="https://phlaym.net/git/phlaym/Dragonpolls" title="Source" class="sourcecode"><div class="linkcontents">'
|
||||||
. file_get_contents(__DIR__.'/icons/home.svg')
|
. file_get_contents(__DIR__.'/icons/src.svg')
|
||||||
. '<span class="linklabel">Source Code</span></div></a>'
|
. '<span class="linklabel">Source Code</span></div></a>'
|
||||||
. '</footer></body></html>';
|
. '</footer></body></html>';
|
||||||
}
|
}
|
||||||
|
11
icons/src.svg
Normal file
11
icons/src.svg
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<svg width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
|
||||||
|
<g transform="matrix(4.17104e-17,-0.681183,0.681183,4.17104e-17,-9.57533,155.35)">
|
||||||
|
<path d="M35.135,106.364L81.255,43.418L127.376,106.364" style="fill:none;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(4.17104e-17,0.681183,-0.681183,4.17104e-17,209.575,44.6502)">
|
||||||
|
<path d="M35.135,106.364L81.255,43.418L127.376,106.364" style="fill:none;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,27.1275,-4.41151)">
|
||||||
|
<path d="M60.179,143.051C61.016,141.935 85.567,65.772 85.567,65.772" style="fill:none;"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 824 B |
31
new_poll.php
31
new_poll.php
@ -19,11 +19,34 @@ try {
|
|||||||
if (!$api->isAuthenticated(false, true)) {
|
if (!$api->isAuthenticated(false, true)) {
|
||||||
die('You need to be logged in to create a new poll!' . get_page_footer());
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<form method="POST" class="create-poll">
|
<form method="POST" class="create-poll">
|
||||||
<label for="prompt">Prompt</label>
|
<label for="prompt">Prompt</label>
|
||||||
<input type="text" name="prompt" placeholder="What would you like to poll about?" id="prompt" required/>
|
<input
|
||||||
|
type="text"
|
||||||
|
name="prompt"
|
||||||
|
placeholder="What would you like to poll about?"
|
||||||
|
id="prompt" required
|
||||||
|
maxlength="<?= $api->getMaxPostLength() ?>"/>
|
||||||
<label for="options">Options</label>
|
<label for="options">Options</label>
|
||||||
<div id="options">
|
<div id="options">
|
||||||
<?php
|
<?php
|
||||||
@ -31,7 +54,8 @@ if (!$api->isAuthenticated(false, true)) {
|
|||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="option[]"
|
name="option[]"
|
||||||
placeholder="This will be option #<?= $i+1 ?>" <?= $i < 2 ? 'required' : '' ?>/>
|
placeholder="This will be option #<?= $i+1 ?>" <?= $i < 2 ? 'required' : '' ?>
|
||||||
|
maxlength="64"/>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
<label for="anonymous">Anonymous</label>
|
<label for="anonymous">Anonymous</label>
|
||||||
@ -50,4 +74,5 @@ if (!$api->isAuthenticated(false, true)) {
|
|||||||
<span class="error"></span>
|
<span class="error"></span>
|
||||||
<button type="submit" name="submit" value="submit">Create poll</button>
|
<button type="submit" name="submit" value="submit">Create poll</button>
|
||||||
</form>
|
</form>
|
||||||
</form>
|
</form>
|
||||||
|
<?= get_page_footer() ?>
|
@ -19,8 +19,8 @@ function validatePoll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const maxOptions = parseInt(form.querySelector('input[name=max_options]').value);
|
const maxOptions = parseInt(form.querySelector('input[name=max_options]').value);
|
||||||
if (numOptionsProvided > 1 && (isNaN(maxOptions) || maxOptions <= 0 || maxOptions >= numOptionsProvided)) {
|
if (numOptionsProvided > 1 && (isNaN(maxOptions) || maxOptions <= 0 || maxOptions > numOptionsProvided)) {
|
||||||
errors.push(`Max Options needs to be greater than 0 and smaller than ${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);
|
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');
|
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');
|
const closesAtLabel = document.getElementById('openUntil');
|
||||||
if (!isNaN(durationTotalMinutes)) {
|
if (!isNaN(durationTotalMinutes)) {
|
||||||
// Add duration_total_minutes to the curent Date
|
// Add duration_total_minutes to the curent Date
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
window.addEventListener('DOMContentLoaded', () => {
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
displayLocalTimestamps();
|
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;
|
el.onclick = updateVotesRemaining;
|
||||||
}
|
}
|
||||||
const banner = document.querySelector('.success-banner');
|
const banner = document.querySelector('.success-banner');
|
||||||
@ -31,7 +31,9 @@ function compareDateToToday(date) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateVotesRemaining() {
|
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 votesRemainingElement = document.querySelector('.votes-remaining');
|
||||||
const total = votesRemainingElement.dataset.maxVotes;
|
const total = votesRemainingElement.dataset.maxVotes;
|
||||||
const remaining = Math.max(0, total - numChecked);
|
const remaining = Math.max(0, total - numChecked);
|
||||||
|
@ -254,4 +254,8 @@ footer {
|
|||||||
background: var(--secondary-bg-color);
|
background: var(--secondary-bg-color);
|
||||||
box-shadow: var(--default-shadow);
|
box-shadow: var(--default-shadow);
|
||||||
font-size: smaller;
|
font-size: smaller;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer .sourcecode svg {
|
||||||
|
stroke-width: 1.5em;
|
||||||
}
|
}
|
@ -66,6 +66,11 @@ if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?>
|
|||||||
<div class="banner-wrapper">
|
<div class="banner-wrapper">
|
||||||
<div class="success-banner"><span>✓</span> Your vote has been saved, thank you!</div>
|
<div class="success-banner"><span>✓</span> Your vote has been saved, thank you!</div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php }
|
||||||
|
if (array_key_exists('poll_created', $_GET) && $_GET['poll_created'] == 1) { ?>
|
||||||
|
<div class="banner-wrapper">
|
||||||
|
<div class="success-banner"><span>✓</span> Your poll has been created, thank you!</div>
|
||||||
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<div class="poll">
|
<div class="poll">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
@ -111,9 +116,9 @@ if (array_key_exists('success', $_GET) && $_GET['success'] == 1) { ?>
|
|||||||
$checked = $option->is_your_response ? 'checked' : ''; ?>
|
$checked = $option->is_your_response ? 'checked' : ''; ?>
|
||||||
<div class="option" style="grid-row: <?= $row ?>;">
|
<div class="option" style="grid-row: <?= $row ?>;">
|
||||||
<input
|
<input
|
||||||
type="<?= $input_type ?>" <?= $checked.' '.$disabled ?>
|
type="<?= $input_type ?>" <?= $checked.' '.$disabled ?>
|
||||||
value="<?= $option->position ?>"
|
value="<?= $option->position ?>"
|
||||||
name="<?= $input_name ?>"/>
|
name="<?= $input_name ?>"/>
|
||||||
<span class="option-text"><?= $option->text . ' (' . $option->respondents . ')'?></span>
|
<span class="option-text"><?= $option->text . ' (' . $option->respondents . ')'?></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="option-responses" style="grid-row: <?= $row++ ?>;grid-column: 2;">
|
<div class="option-responses" style="grid-row: <?= $row++ ?>;grid-column: 2;">
|
||||||
|
Loading…
Reference in New Issue
Block a user