From 65a753129a85cc343e5970d7787a84ce93920413 Mon Sep 17 00:00:00 2001 From: Antonin <antonin.murtin@gmail.com> Date: Mon, 30 Nov 2015 22:23:26 +0100 Subject: [PATCH] Remembering last user vote in session --- adminstuds.php | 1 + studs.php | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index aa7eb24f..ce091fac 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -395,5 +395,6 @@ $smarty->assign('admin', true); $smarty->assign('hidden', false); $smarty->assign('accessGranted', true); $smarty->assign('resultPubliclyVisible', true); +$smarty->assign('editedVoteUniqueId', ''); $smarty->display('studs.tpl'); diff --git a/studs.php b/studs.php index 47a56260..afbdf307 100644 --- a/studs.php +++ b/studs.php @@ -22,12 +22,19 @@ use Framadate\Services\InputService; use Framadate\Services\MailService; use Framadate\Services\NotificationService; use Framadate\Services\SecurityService; +use Framadate\Services\SessionService; use Framadate\Message; use Framadate\Utils; use Framadate\Editable; include_once __DIR__ . '/app/inc/init.php'; +/* Constantes */ +/* ---------- */ + +const USER_REMEMBER_VOTES_KEY = 'UserVotes'; + + /* Variables */ /* --------- */ @@ -40,7 +47,6 @@ $resultPubliclyVisible = true; $slots = array(); $votes = array(); $comments = array(); -$editedVoteUniqueId = null; /* Services */ /*----------*/ @@ -51,6 +57,7 @@ $inputService = new InputService(); $mailService = new MailService($config['use_smtp']); $notificationService = new NotificationService($mailService); $securityService = new SecurityService(); +$sessionService = new SessionService(); /* PAGE */ @@ -69,6 +76,8 @@ if (!$poll) { exit; } +$editedVoteUniqueId = $sessionService->get(USER_REMEMBER_VOTES_KEY, $poll_id, ''); + // ------------------------------- // Password verification // ------------------------------- @@ -127,8 +136,9 @@ if ($accessGranted) { $result = $pollService->updateVote($poll_id, $editedVote, $name, $choices); if ($result) { if ($poll->editable == Editable::EDITABLE_BY_OWN) { - $editedVoteUniqId = filter_input(INPUT_POST, 'edited_vote', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]); - $urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqId); + $editedVoteUniqueId = filter_input(INPUT_POST, 'edited_vote', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]); + $sessionService->set(USER_REMEMBER_VOTES_KEY, $poll_id, $editedVoteUniqueId); + $urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId); $message = new Message('success', __('studs', 'Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:'), $urlEditVote); } else { $message = new Message('success', __('studs', 'Update vote succeeded')); @@ -154,7 +164,9 @@ if ($accessGranted) { $result = $pollService->addVote($poll_id, $name, $choices); if ($result) { if ($poll->editable == Editable::EDITABLE_BY_OWN) { - $urlEditVote = Utils::getUrlSondage($poll_id, false, $result->uniqId); + $editedVoteUniqueId = $result->uniqId; + $sessionService->set(USER_REMEMBER_VOTES_KEY, $poll_id, $editedVoteUniqueId); + $urlEditVote = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId); $message = new Message('success', __('studs', 'Your vote has been registered successfully, but be careful: regarding this poll options, you need to keep this personal link to edit your own vote:'), $urlEditVote); } else { $message = new Message('success', __('studs', 'Adding the vote succeeded')); -- GitLab