mirror of
https://github.com/standardebooks/web.git
synced 2025-07-12 09:32:24 -04:00
55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?
|
||
require_once('Core.php');
|
||
|
||
use Safe\DateTime;
|
||
|
||
$poll = new Poll();
|
||
$canVote = true; // Allow non-logged-in users to see the 'vote' button
|
||
|
||
try{
|
||
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false));
|
||
|
||
if(isset($GLOBALS['User'])){
|
||
$canVote = false; // User is logged in, hide the vote button unless they haven't voted yet
|
||
try{
|
||
PollVote::Get($poll->UrlName, $GLOBALS['User']->UserId);
|
||
}
|
||
catch(Exceptions\SeException $ex){
|
||
// User has already voted
|
||
$canVote = true;
|
||
}
|
||
}
|
||
}
|
||
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>
|
||
<? } ?>
|
||
<? if(!$canVote){ ?>
|
||
<p class="center-notice">You’ve already voted in this poll.</p>
|
||
<? } ?>
|
||
<p class="button-row narrow">
|
||
<? if($canVote){ ?>
|
||
<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() ?>
|