diff --git a/config/apache/standardebooks.org.conf b/config/apache/standardebooks.org.conf index ea6aa72e..847049af 100644 --- a/config/apache/standardebooks.org.conf +++ b/config/apache/standardebooks.org.conf @@ -258,14 +258,15 @@ Define webroot /standardebooks.org/web # Newsletter RewriteRule ^/newsletter$ /newsletter/subscriptions/new.php [L] RewriteRule ^/newsletter/subscriptions/([^/\.]+?)$ /newsletter/subscriptions/get.php?uuid=$1 [L] - RewriteRule ^/newsletter/subscriptions/([^/\.]+?)/(confirm|delete|success)$ /newsletter/subscriptions/$2.php?uuid=$1 [L] + RewriteRule ^/newsletter/subscriptions/([^/\.]+?)/(confirm|delete)$ /newsletter/subscriptions/$2.php?uuid=$1 [L] # Polls - RewriteRule ^/patrons-circle/polls/([^/\.]+)$ /patrons-circle/polls/get.php?pollurlname=$1 [L] - RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes/(new|success)$ /patrons-circle/polls/votes/$2.php?pollurlname=$1 [L] + RewriteRule ^/patrons-circle/polls/([^/\.]+)$ /patrons-circle/polls/get.php?pollurlname=$1 [L] + RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes/new$ /patrons-circle/polls/votes/new.php?pollurlname=$1 [L] + RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes/([0-9]+)$ /patrons-circle/polls/votes/get.php?pollurlname=$1&userid=$2 [L] RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/" - RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes$ /patrons-circle/polls/votes/index.php?pollurlname=$1 [L] + RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes$ /patrons-circle/polls/votes/index.php?pollurlname=$1 [L] RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes$ /patrons-circle/polls/votes/post.php?pollurlname=$1 [L] diff --git a/config/apache/standardebooks.test.conf b/config/apache/standardebooks.test.conf index 6dfa2417..2bcaf34f 100644 --- a/config/apache/standardebooks.test.conf +++ b/config/apache/standardebooks.test.conf @@ -257,14 +257,15 @@ Define webroot /standardebooks.org/web # Newsletter RewriteRule ^/newsletter$ /newsletter/subscriptions/new.php [L] RewriteRule ^/newsletter/subscriptions/([^/\.]+?)$ /newsletter/subscriptions/get.php?uuid=$1 [L] - RewriteRule ^/newsletter/subscriptions/([^/\.]+?)/(confirm|delete|success)$ /newsletter/subscriptions/$2.php?uuid=$1 [L] + RewriteRule ^/newsletter/subscriptions/([^/\.]+?)/(confirm|delete)$ /newsletter/subscriptions/$2.php?uuid=$1 [L] # Polls - RewriteRule ^/patrons-circle/polls/([^/\.]+)$ /patrons-circle/polls/get.php?pollurlname=$1 [L] - RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes/(new|success)$ /patrons-circle/polls/votes/$2.php?pollurlname=$1 [L] + RewriteRule ^/patrons-circle/polls/([^/\.]+)$ /patrons-circle/polls/get.php?pollurlname=$1 [L] + RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes/new$ /patrons-circle/polls/votes/new.php?pollurlname=$1 [L] + RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes/([0-9]+)$ /patrons-circle/polls/votes/get.php?pollurlname=$1&userid=$2 [L] RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/" - RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes$ /patrons-circle/polls/votes/index.php?pollurlname=$1 [L] + RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes$ /patrons-circle/polls/votes/index.php?pollurlname=$1 [L] RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" RewriteRule ^/patrons-circle/polls/([^/\.]+)/votes$ /patrons-circle/polls/votes/post.php?pollurlname=$1 [L] diff --git a/lib/Exceptions/InvalidVoteException.php b/lib/Exceptions/InvalidVoteException.php new file mode 100644 index 00000000..a872fbe9 --- /dev/null +++ b/lib/Exceptions/InvalidVoteException.php @@ -0,0 +1,6 @@ +_Url === null){ - $this->_Url = '/patrons-circle/polls/' . $this->PollItem->Poll->Url . '/votes/' . $this->UserId; + $this->_Url = $this->PollItem->Poll->Url . '/votes/' . $this->UserId; } return $this->_Url; @@ -96,5 +96,25 @@ class Vote extends PropertiesBase{ $this->Validate(); $this->Created = new DateTime(); Db::Query('INSERT into Votes (UserId, PollItemId, Created) values (?, ?, ?)', [$this->UserId, $this->PollItemId, $this->Created]); + + $this->VoteId = Db::GetLastInsertedId(); + } + + public static function Get(?string $pollUrlName, ?int $userId): ?Vote{ + if($pollUrlName === null || $userId === null){ + vdd('nn'); + return null; + } + + $result = Db::Query('SELECT v.* from Votes v inner join + (select pi.PollItemId from PollItems pi inner join Polls p on pi.PollId = p.PollID + where p.UrlName = ? + ) x on v.PollItemId = x.PollItemId where v.UserId = ?', [$pollUrlName, $userId], 'Vote'); + + if(sizeof($result) == 0){ + throw new Exceptions\InvalidVoteException(); + } + + return $result[0]; } } diff --git a/www/patrons-circle/polls/get.php b/www/patrons-circle/polls/get.php index d81e0aea..ab0a3cfe 100644 --- a/www/patrons-circle/polls/get.php +++ b/www/patrons-circle/polls/get.php @@ -14,7 +14,7 @@ catch(Exceptions\SeException $ex){ ?> $poll->Name, 'highlight' => '', 'description' => $poll->Description]) ?>
-
+

Name) ?>

Description ?>

IsActive()){ ?> @@ -33,6 +33,6 @@ catch(Exceptions\SeException $ex){

View results

-
+
diff --git a/www/patrons-circle/polls/votes/get.php b/www/patrons-circle/polls/votes/get.php new file mode 100644 index 00000000..f18f1b72 --- /dev/null +++ b/www/patrons-circle/polls/votes/get.php @@ -0,0 +1,28 @@ +VoteId){ + http_response_code(201); + session_unset(); + } +} +catch(Exceptions\SeException $ex){ + Template::Emit404(); +} + +?> 'Thank you for voting!', 'highlight' => '', 'description' => 'Thank you for voting in a Standard Ebooks poll!']) ?> +
+
+

Thank you for voting!

+

Your vote in the PollItem->Poll->Name) ?> poll has been recorded.

+

view results

+
+
+ diff --git a/www/patrons-circle/polls/votes/index.php b/www/patrons-circle/polls/votes/index.php index f95a7996..d2d30ce8 100644 --- a/www/patrons-circle/polls/votes/index.php +++ b/www/patrons-circle/polls/votes/index.php @@ -12,7 +12,7 @@ catch(Exceptions\SeException $ex){ ?> 'Results for the ' . $poll->Name . ' poll', 'highlight' => '', 'description' => 'The voting results for the ' . $poll->Name . ' poll.']) ?>
-
+

Results for the Name) ?> Poll

Total votes: VoteCount) ?>

IsActive()){ ?> @@ -39,6 +39,6 @@ catch(Exceptions\SeException $ex){ -
+
diff --git a/www/patrons-circle/polls/votes/new.php b/www/patrons-circle/polls/votes/new.php index 8d70660b..d08b5478 100644 --- a/www/patrons-circle/polls/votes/new.php +++ b/www/patrons-circle/polls/votes/new.php @@ -24,7 +24,7 @@ if($exception){ ?> $poll->Name . ' - Vote Now', 'highlight' => '', 'description' => 'Vote in the ' . $poll->Name . ' poll']) ?>
-
+

Vote in the Name) ?> Poll

$exception]) ?>
@@ -51,6 +51,6 @@ if($exception){
-
+
diff --git a/www/patrons-circle/polls/votes/post.php b/www/patrons-circle/polls/votes/post.php index c2d3b03d..6bf18629 100644 --- a/www/patrons-circle/polls/votes/post.php +++ b/www/patrons-circle/polls/votes/post.php @@ -25,8 +25,9 @@ try{ session_unset(); if($requestType == WEB){ + $_SESSION['vote-created'] = $vote->VoteId; http_response_code(303); - header('Location: ' . $vote->PollItem->Poll->Url . '/votes/success'); + header('Location: ' . $vote->Url); } else{ // Access via REST api; 201 CREATED with location diff --git a/www/patrons-circle/polls/votes/success.php b/www/patrons-circle/polls/votes/success.php deleted file mode 100644 index 9ca1135e..00000000 --- a/www/patrons-circle/polls/votes/success.php +++ /dev/null @@ -1,21 +0,0 @@ - 'Thank you for voting!', 'highlight' => 'newsletter', 'description' => 'Thank you for voting in a Standard Ebooks poll!']) ?> -
-
-

Thank you for voting!

-

Your vote in the Name) ?> poll has been recorded.

-

view results

-
-
-