Move items out of the 'patrons-circle' folder into the root

This commit is contained in:
Alex Cabal 2022-07-09 19:39:29 -05:00
parent 12b79b5dcd
commit 76a4c34688
17 changed files with 95 additions and 39 deletions

39
www/polls/get.php Normal file
View file

@ -0,0 +1,39 @@
<?
require_once('Core.php');
use Safe\DateTime;
$poll = new Poll();
try{
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false));
}
catch(Exceptions\SeException $ex){
Template::Emit404();
}
?><?= Template::Header(['title' => $poll->Name, 'highlight' => '', 'description' => $poll->Description]) ?>
<main>
<section class="narrow">
<h1><?= Formatter::ToPlainText($poll->Name) ?></h1>
<p><?= $poll->Description ?></p>
<? if($poll->IsActive()){ ?>
<? if($poll->End !== null){ ?>
<p class="center-notice">This poll closes on <?= $poll->End->format('F j, Y g:i A') ?>.</p>
<? } ?>
<p><i>If youre a Patrons Circle member, when prompted enter your email address and leave the password field blank to vote.</i></p>
<p class="button-row narrow">
<a href="<?= $poll->Url ?>/votes/new" class="button">Vote now</a>
<a href="<?= $poll->Url ?>/votes" class="button">View results</a>
</p>
<? }else{ ?>
<? if($poll->Start !== null && $poll->Start > new DateTime()){ ?>
<p class="center-notice">This poll opens on <?= $poll->Start->format('F j, Y g:i A') ?>.</p>
<? }else{ ?>
<p class="center-notice">This poll closed on <?= $poll->End->format('F j, Y g:i A') ?>.</p>
<p class="button-row narrow"><a href="<?= $poll->Url ?>/votes" class="button">View results</a></p>
<? } ?>
<? } ?>
</section>
</main>
<?= Template::Footer() ?>

40
www/polls/index.php Normal file
View file

@ -0,0 +1,40 @@
<?
require_once('Core.php');
$pastPolls = Db::Query('select * from Polls where utc_timestamp() >= End order by Created desc', [], 'Poll');
$openPolls = Db::Query('select * from Polls where (End is null or utc_timestamp() <= End) and (Start is null or Start <= utc_timestamp()) order by Created desc', [], 'Poll');
?><?= Template::Header(['title' => 'Polls', 'highlight' => '', 'description' => 'The various polls active at Standard Ebooks.']) ?>
<main>
<section class="narrow">
<h1>Polls</h1>
<p>Periodically members of the <a href="/about#patrons-circle">Standard Ebooks Patrons Circle</a> vote on the next ebook from the <a href="/contribute/wanted-ebooks">Wanted Ebook List</a> to enter immediate production.</p>
<p>Anyone can <a href="/donate#patrons-circle">join the Patrons Circle</a> by making a small donation in support of our mission of producing beautiful digital literature, for free distribution.</p>
<? if(sizeof($openPolls) > 0){ ?>
<section id="open-polls">
<h2>Open polls</h2>
<ul>
<? foreach($openPolls as $poll){ ?>
<li>
<p><a href="<?= $poll->Url ?>"><?= Formatter::ToPlainText($poll->Name) ?></a></p>
</li>
<? } ?>
</ul>
</section>
<? } ?>
<? if(sizeof($pastPolls) > 0){ ?>
<section id="ended-polls">
<h2>Past polls</h2>
<ul>
<? foreach($pastPolls as $poll){ ?>
<li>
<p><a href="<?= $poll->Url ?>"><?= Formatter::ToPlainText($poll->Name) ?></a></p>
</li>
<? } ?>
</ul>
</section>
<? } ?>
</section>
</main>
<?= Template::Footer() ?>

30
www/polls/votes/get.php Normal file
View file

@ -0,0 +1,30 @@
<?
require_once('Core.php');
use function Safe\session_unset;
session_start();
$vote = new PollVote();
try{
$vote = PollVote::Get(HttpInput::Str(GET, 'pollurlname'), HttpInput::Int(GET, 'userid'));
if(isset($_SESSION['vote-created']) && $_SESSION['vote-created'] == $vote->UserId){
http_response_code(201);
session_unset();
}
}
catch(Exceptions\SeException $ex){
Template::Emit404();
}
?><?= Template::Header(['title' => 'Thank you for voting!', 'highlight' => '', 'description' => 'Thank you for voting in a Standard Ebooks poll!']) ?>
<main>
<section class="narrow">
<h1>Thank you for voting!</h1>
<p class="center-notice">Your vote in the <a href="<?= $vote->PollItem->Poll->Url ?>"><?= Formatter::ToPlainText($vote->PollItem->Poll->Name) ?> poll</a> has been recorded.</p>
<p class="button-row narrow"><a class="button" href="<?= $vote->PollItem->Poll->Url ?>/votes"> view results</a></p>
</section>
</main>
<?= Template::Footer() ?>

44
www/polls/votes/index.php Normal file
View file

@ -0,0 +1,44 @@
<?
require_once('Core.php');
$poll = new Poll();
try{
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false));
}
catch(Exceptions\SeException $ex){
Template::Emit404();
}
?><?= Template::Header(['title' => 'Results for the ' . $poll->Name . ' poll', 'highlight' => '', 'description' => 'The voting results for the ' . $poll->Name . ' poll.']) ?>
<main>
<section class="narrow">
<h1>Results for the <?= Formatter::ToPlainText($poll->Name) ?> Poll</h1>
<p class="center-notice">Total votes: <?= number_format($poll->VoteCount) ?></p>
<? if($poll->IsActive()){ ?>
<? if($poll->End !== null){ ?>
<p class="center-notice">This poll closes on <?= $poll->End->format('F j, Y g:i A') ?>.</p>
<? } ?>
<? }elseif($poll->End !== null){ ?>
<p class="center-notice">This poll closed on <?= $poll->End->format('F j, Y g:i A') ?>.</p>
<? } ?>
<table class="votes">
<tbody>
<? foreach($poll->PollItemsByWinner as $pollItem){ ?>
<tr>
<td><?= Formatter::ToPlainText($pollItem->Name) ?></td>
<td>
<div class="meter">
<div aria-hidden="true">
<p><?= number_format($pollItem->VoteCount) ?></p>
</div>
<meter min="0" max="<?= $poll->VoteCount ?>" value="<?= $pollItem->VoteCount ?>"></meter>
</div>
</td>
</tr>
<? } ?>
</tbody>
</table>
</section>
</main>
<?= Template::Footer() ?>

65
www/polls/votes/new.php Normal file
View file

@ -0,0 +1,65 @@
<?
require_once('Core.php');
use function Safe\session_unset;
session_start();
$vote = new PollVote();
if(isset($_SESSION['vote'])){
$vote = $_SESSION['vote'];
}
else{
$vote->User = new User();
$vote->User->Email = $_SERVER['PHP_AUTH_USER'] ?? null;
}
$exception = $_SESSION['exception'] ?? null;
$poll = new Poll();
try{
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false));
}
catch(Exceptions\SeException $ex){
Template::Emit404();
}
if($exception){
http_response_code(400);
session_unset();
}
?><?= Template::Header(['title' => $poll->Name . ' - Vote Now', 'highlight' => '', 'description' => 'Vote in the ' . $poll->Name . ' poll']) ?>
<main>
<section class="narrow">
<h1>Vote in the <?= Formatter::ToPlainText($poll->Name) ?> Poll</h1>
<?= Template::Error(['exception' => $exception]) ?>
<form method="post" action="<?= Formatter::ToPlainText($poll->Url) ?>/votes">
<label class="email">Your email address
<input type="email" name="email" value="<? if($vote->User !== null){ ?><?= Formatter::ToPlainText($vote->User->Email) ?><? } ?>" maxlength="80" required="required" readonly="readonly" />
</label>
<fieldset>
<p>Select one of these options</p>
<ul>
<? foreach($poll->PollItems as $pollItem){ ?>
<li>
<label class="checkbox">
<input type="radio" value="<?= $pollItem->PollItemId ?>" name="pollitemid" required="required"<? if($vote->PollItemId == $pollItem->PollItemId){ ?> checked="checked"<? } ?>/>
<span>
<b><?= Formatter::ToPlainText($pollItem->Name) ?></b>
<? if($pollItem->Description !== null){ ?>
<span><?= Formatter::ToPlainText($pollItem->Description) ?></span>
<? } ?>
</span>
</label>
</li>
<? } ?>
</ul>
</fieldset>
<button>Vote</button>
</form>
</section>
</main>
<?= Template::Footer() ?>

52
www/polls/votes/post.php Normal file
View file

@ -0,0 +1,52 @@
<?
require_once('Core.php');
use function Safe\preg_match;
use function Safe\session_unset;
if(HttpInput::RequestMethod() != HTTP_POST){
http_response_code(405);
exit();
}
session_start();
$requestType = HttpInput::RequestType();
$vote = new PollVote();
try{
$error = new Exceptions\ValidationException();
$vote->PollItemId = HttpInput::Int(POST, 'pollitemid');
$vote->Create(HttpInput::Str(POST, 'email', false));
session_unset();
if($requestType == WEB){
$_SESSION['vote-created'] = $vote->UserId;
http_response_code(303);
header('Location: ' . $vote->Url);
}
else{
// Access via REST api; 201 CREATED with location
http_response_code(201);
header('Location: ' . $vote->Url);
}
}
catch(Exceptions\SeException $ex){
// Validation failed
if($requestType == WEB){
$_SESSION['vote'] = $vote;
$_SESSION['exception'] = $ex;
// Access via form; 303 redirect to the form, which will emit a 400 BAD REQUEST
http_response_code(303);
header('Location: /polls/' . HttpInput::Str(GET, 'pollurlname', false) . '/votes/new');
}
else{
// Access via REST api; 400 BAD REQUEST
http_response_code(400);
}
}