From 68d5b64180083d90c9b7075d83bae38c8b649b2a Mon Sep 17 00:00:00 2001 From: JMarlow Date: Sun, 18 Mar 2018 10:40:38 +0100 Subject: [PATCH] Collecting Polled Users Emails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modification de la BDD : ajout de la colonne mail dans la table vote Modification de la BDD : ajout de la colonne mail dans la table vote (bis) MAJ de VoteRepository : méthode insert et update MAJ de PollService : méthodes updateVote, addVote et splitVotes Modification studs.php, adminstuds.php et vote_table_date.tpl : OK pour l'ajout d'un vote avec nom + mail Modification de vote_table_classic.tpl : OK pour l'ajout d'un vote avec nom + mail Ajout d'un bouton enveloppe pour chaque colonne avec méthode de traitement pour test Le numéro de la colonne est enfin récupéré correctement Implémentation récupération des adresses mails des sondés intéressants dans adminstuds.php et appel d'un fichier display_mails.tpl qui affichent ces adresses mails. Extension du traitement pour les sondages classic Ajout récupération des adresses des non aussi, et ajouts de tests pour l'affichage Changement des input type=text en type=email Corrections automatiques pour passage pipelines Corrections suite aux remarques sur la merge request Corrections 2 suite aux remarques sur la merge request Corrections 3 suite aux remarques sur la merge request Modif BDD : ajout colonne collect_mail dans poll Modif classes Form, PollRepository Passage de la collecte des mails des sondés en fonctionalité optionnelle Si la collecte de mail est activée, la saisie du mail est obligatoire Ajout avertissements collect_mail + editableByAll dans création de sondage et tableaux de vote Update create poll string and put a danger background on warning Signed-off-by: Thomas Citharel Translation strings updated and better position for the email public warning message Also, a CSS tweak and cleanup Signed-off-by: Thomas Citharel CS Signed-off-by: Thomas Citharel --- admin/migration.php | 4 ++ adminstuds.php | 52 +++++++++++++- app/classes/Framadate/Form.php | 6 ++ .../AddColumn_collect_mail_In_poll.php | 70 +++++++++++++++++++ .../Migration/AddColumn_mail_In_vote.php | 70 +++++++++++++++++++ .../Framadate/Repositories/PollRepository.php | 6 +- .../Framadate/Repositories/VoteRepository.php | 13 ++-- .../Framadate/Services/PollService.php | 31 ++++---- create_poll.php | 6 ++ css/style.css | 13 +--- js/app/create_poll.js | 19 +++++ locale/en.json | 20 +++++- studs.php | 14 +++- tpl/create_poll.tpl | 23 +++++- tpl/display_mails.tpl | 34 +++++++++ tpl/part/poll_info.tpl | 5 ++ tpl/part/vote_table_classic.tpl | 25 ++++++- tpl/part/vote_table_date.tpl | 20 +++++- 18 files changed, 386 insertions(+), 45 deletions(-) create mode 100644 app/classes/Framadate/Migration/AddColumn_collect_mail_In_poll.php create mode 100644 app/classes/Framadate/Migration/AddColumn_mail_In_vote.php create mode 100644 tpl/display_mails.tpl diff --git a/admin/migration.php b/admin/migration.php index 3948909..d3e6237 100644 --- a/admin/migration.php +++ b/admin/migration.php @@ -17,7 +17,9 @@ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ +use Framadate\Migration\AddColumn_collect_mail_In_poll; use Framadate\Migration\AddColumn_hidden_In_poll_For_0_9; +use Framadate\Migration\AddColumn_mail_In_vote; use Framadate\Migration\AddColumn_receiveNewComments_For_0_9; use Framadate\Migration\AddColumn_uniqId_In_vote_For_0_9; use Framadate\Migration\AddColumn_ValueMax_In_poll_For_1_1; @@ -53,6 +55,8 @@ $migrations = [ new Increase_pollId_size(), new AddColumn_ValueMax_In_poll_For_1_1(), new Fix_MySQL_No_Zero_Date(), + new AddColumn_mail_In_vote(), + new AddColumn_collect_mail_In_poll() ]; // --------------------------------------- diff --git a/adminstuds.php b/adminstuds.php index 5c51d94..993ad13 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -219,6 +219,11 @@ $selectedNewVotes = []; if (!empty($_POST['save'])) { // Save edition of an old vote $name = $inputService->filterName($_POST['name']); + if(empty($_POST['mail']) || $inputService->filterMail($_POST['mail'])===false) { + $mail = null; + } else { + $mail = $inputService->filterMail($_POST['mail']); + } $editedVote = filter_input(INPUT_POST, 'save', FILTER_VALIDATE_INT); $choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]); $slots_hash = $inputService->filterMD5($_POST['control']); @@ -233,7 +238,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote if ($message === null) { // Update vote try { - $result = $pollService->updateVote($poll_id, $editedVote, $name, $choices, $slots_hash); + $result = $pollService->updateVote($poll_id, $editedVote, $name, $choices, $slots_hash, $mail); if ($result) { $message = new Message('success', __('adminstuds', 'Vote updated')); } else { @@ -249,6 +254,11 @@ if (!empty($_POST['save'])) { // Save edition of an old vote } } elseif (isset($_POST['save'])) { // Add a new vote $name = $inputService->filterName($_POST['name']); + if(empty($_POST['mail']) || $inputService->filterMail($_POST['mail'])===false) { + $mail = null; + } else { + $mail = $inputService->filterMail($_POST['mail']); + } $choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]); $slots_hash = $inputService->filterMD5($_POST['control']); @@ -262,7 +272,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote if ($message === null) { // Add vote try { - $result = $pollService->addVote($poll_id, $name, $choices, $slots_hash); + $result = $pollService->addVote($poll_id, $name, $choices, $slots_hash, $mail); if ($result) { $message = new Message('success', __('adminstuds', 'Vote added')); } else { @@ -398,6 +408,44 @@ if (isset($_GET['delete_column'])) { } } +// ------------------------------- +// Collect the mails of a column +// ------------------------------- + +if (isset($_GET['collect_mail'])) { + $column_str = strval(filter_input(INPUT_GET, 'collect_mail', FILTER_DEFAULT)); + $column_str = strval(Utils::base64url_decode($column_str)); + $column = intval($column_str); + $votes = $pollService->splitVotes($pollService->allVotesByPollId($poll_id)); + $mails_yes = []; + $mails_ifneedbe = []; + $mails_no = []; + $size = count($votes); + for ($i = 0; $i < $size; $i++) +{ + if(intval($votes[$i]->choices[$column]) === 2 && $votes[$i]->mail !== NULL) { + $mails_yes[]=$votes[$i]->mail; + } + else { + if(intval($votes[$i]->choices[$column]) === 1 && $votes[$i]->mail !== NULL) { + $mails_ifneedbe[]=$votes[$i]->mail; + } + elseif($votes[$i]->mail !== NULL) { + $mails_no[]=$votes[$i]->mail; + } + } +} + $smarty->assign('poll_id', $poll_id); + $smarty->assign('admin_poll_id', $admin_poll_id); + $smarty->assign('admin', true); + $smarty->assign('title', __('Generic', 'Poll') . ' - ' . $poll->title . ' - ' . __('adminstuds', 'Collect the emails of the polled users for this column')); + $smarty->assign('mails_yes', $mails_yes); + $smarty->assign('mails_ifneedbe', $mails_ifneedbe); + $smarty->assign('mails_no', $mails_no); + $smarty->display('display_mails.tpl'); + exit; +} + // ------------------------------- // Add a slot // ------------------------------- diff --git a/app/classes/Framadate/Form.php b/app/classes/Framadate/Form.php index 716400d..b6a5270 100644 --- a/app/classes/Framadate/Form.php +++ b/app/classes/Framadate/Form.php @@ -82,6 +82,12 @@ class Form */ public $results_publicly_visible; + /** + * If true, the users can leave an email address while voting in the poll + * @var boolean + */ + public $collect_users_mail; + /** * List of available choices */ diff --git a/app/classes/Framadate/Migration/AddColumn_collect_mail_In_poll.php b/app/classes/Framadate/Migration/AddColumn_collect_mail_In_poll.php new file mode 100644 index 0000000..5ede344 --- /dev/null +++ b/app/classes/Framadate/Migration/AddColumn_collect_mail_In_poll.php @@ -0,0 +1,70 @@ +alterVoteTable($pdo); + + return true; + } + + private function alterVoteTable(\PDO $pdo) { + $pdo->exec(' + ALTER TABLE `' . Utils::table('poll') . '` + ADD `collect_users_mail` TINYINT DEFAULT 0;'); + } +} diff --git a/app/classes/Framadate/Migration/AddColumn_mail_In_vote.php b/app/classes/Framadate/Migration/AddColumn_mail_In_vote.php new file mode 100644 index 0000000..65c9631 --- /dev/null +++ b/app/classes/Framadate/Migration/AddColumn_mail_In_vote.php @@ -0,0 +1,70 @@ +alterVoteTable($pdo); + + return true; + } + + private function alterVoteTable(\PDO $pdo) { + $pdo->exec(' + ALTER TABLE `' . Utils::table('vote') . '` + ADD `mail` VARCHAR(320) DEFAULT NULL;'); + } +} diff --git a/app/classes/Framadate/Repositories/PollRepository.php b/app/classes/Framadate/Repositories/PollRepository.php index 5a11c0b..8c1e7f4 100644 --- a/app/classes/Framadate/Repositories/PollRepository.php +++ b/app/classes/Framadate/Repositories/PollRepository.php @@ -12,10 +12,10 @@ class PollRepository extends AbstractRepository { public function insertPoll($poll_id, $admin_poll_id, $form) { $sql = 'INSERT INTO `' . Utils::table('poll') . '` - (id, admin_id, title, description, admin_name, admin_mail, end_date, format, editable, receiveNewVotes, receiveNewComments, hidden, password_hash, results_publicly_visible,ValueMax) - VALUES (?,?,?,?,?,?,FROM_UNIXTIME(?),?,?,?,?,?,?,?,?)'; + (id, admin_id, title, description, admin_name, admin_mail, end_date, format, editable, receiveNewVotes, receiveNewComments, hidden, password_hash, results_publicly_visible, ValueMax, collect_users_mail) + VALUES (?,?,?,?,?,?,FROM_UNIXTIME(?),?,?,?,?,?,?,?,?,?)'; $prepared = $this->prepare($sql); - $prepared->execute([$poll_id, $admin_poll_id, $form->title, $form->description, $form->admin_name, $form->admin_mail, $form->end_date, $form->format, ($form->editable>=0 && $form->editable<=2) ? $form->editable : 0, $form->receiveNewVotes ? 1 : 0, $form->receiveNewComments ? 1 : 0, $form->hidden ? 1 : 0, $form->password_hash, $form->results_publicly_visible ? 1 : 0,$form->ValueMax]); + $prepared->execute([$poll_id, $admin_poll_id, $form->title, $form->description, $form->admin_name, $form->admin_mail, $form->end_date, $form->format, ($form->editable>=0 && $form->editable<=2) ? $form->editable : 0, $form->receiveNewVotes ? 1 : 0, $form->receiveNewComments ? 1 : 0, $form->hidden ? 1 : 0, $form->password_hash, $form->results_publicly_visible ? 1 : 0, $form->ValueMax, $form->collect_users_mail? 1 : 0]); } function findById($poll_id) { diff --git a/app/classes/Framadate/Repositories/VoteRepository.php b/app/classes/Framadate/Repositories/VoteRepository.php index f015162..588a0ee 100644 --- a/app/classes/Framadate/Repositories/VoteRepository.php +++ b/app/classes/Framadate/Repositories/VoteRepository.php @@ -22,9 +22,9 @@ class VoteRepository extends AbstractRepository { return $prepared->execute([$insert_position, $insert_position + 1, $poll_id]); } - function insert($poll_id, $name, $choices, $token) { - $prepared = $this->prepare('INSERT INTO `' . Utils::table('vote') . '` (poll_id, name, choices, uniqId) VALUES (?,?,?,?)'); - $prepared->execute([$poll_id, $name, $choices, $token]); + function insert($poll_id, $name, $choices, $token, $mail) { + $prepared = $this->prepare('INSERT INTO `' . Utils::table('vote') . '` (poll_id, name, choices, uniqId, mail) VALUES (?,?,?,?,?)'); + $prepared->execute([$poll_id, $name, $choices, $token, $mail]); $newVote = new \stdClass(); $newVote->poll_id = $poll_id; @@ -32,6 +32,7 @@ class VoteRepository extends AbstractRepository { $newVote->name = $name; $newVote->choices = $choices; $newVote->uniqId = $token; + $newVote->mail=$mail; return $newVote; } @@ -73,10 +74,10 @@ class VoteRepository extends AbstractRepository { return $prepared->execute([$index, $index + 2, $poll_id]); } - function update($poll_id, $vote_id, $name, $choices) { - $prepared = $this->prepare('UPDATE `' . Utils::table('vote') . '` SET choices = ?, name = ? WHERE poll_id = ? AND id = ?'); + function update($poll_id, $vote_id, $name, $choices, $mail) { + $prepared = $this->prepare('UPDATE `' . Utils::table('vote') . '` SET choices = ?, name = ?, mail = ? WHERE poll_id = ? AND id = ?'); - return $prepared->execute([$choices, $name, $poll_id, $vote_id]); + return $prepared->execute([$choices, $name, $mail, $poll_id, $vote_id]); } /** diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index d3d6590..f389cec 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -88,43 +88,45 @@ class PollService { * @param $name * @param $choices * @param $slots_hash + * @param string $mail * @throws AlreadyExistsException * @throws ConcurrentEditionException * @throws ConcurrentVoteException * @return bool */ - public function updateVote($poll_id, $vote_id, $name, $choices, $slots_hash) { + public function updateVote($poll_id, $vote_id, $name, $choices, $slots_hash, $mail) { $this->checkVoteConstraints($choices, $poll_id, $slots_hash, $name, $vote_id); - + // Update vote $choices = implode($choices); - return $this->voteRepository->update($poll_id, $vote_id, $name, $choices); + return $this->voteRepository->update($poll_id, $vote_id, $name, $choices, $mail); } - + /** * @param $poll_id * @param $name * @param $choices * @param $slots_hash + * @param string $mail * @throws AlreadyExistsException * @throws ConcurrentEditionException * @throws ConcurrentVoteException * @return \stdClass */ - function addVote($poll_id, $name, $choices, $slots_hash) { + function addVote($poll_id, $name, $choices, $slots_hash, $mail) { $this->checkVoteConstraints($choices, $poll_id, $slots_hash, $name); - + // Insert new vote $choices = implode($choices); $token = $this->random(16); - return $this->voteRepository->insert($poll_id, $name, $choices, $token); + return $this->voteRepository->insert($poll_id, $name, $choices, $token, $mail); } function addComment($poll_id, $name, $comment) { if ($this->commentRepository->exists($poll_id, $name, $comment)) { return true; } - + return $this->commentRepository->insert($poll_id, $name, $comment); } @@ -224,6 +226,7 @@ class PollService { $obj->name = $vote->name; $obj->uniqId = $vote->uniqId; $obj->choices = str_split($vote->choices); + $obj->mail = $vote->mail; $splitted[] = $obj; } @@ -292,7 +295,7 @@ class PollService { private function random($length) { return Token::getToken($length); } - + /** * @param $choices * @param $poll_id @@ -310,20 +313,20 @@ class PollService { } else { $exists = $this->voteRepository->existsByPollIdAndNameAndVoteId($poll_id, $name, $vote_id); } - + if ($exists) { throw new AlreadyExistsException(); } - + $poll = $this->findById($poll_id); - + // Check that no-one voted in the meantime and it conflicts the maximum votes constraint $this->checkMaxVotes($choices, $poll, $poll_id); - + // Check if slots are still the same $this->checkThatSlotsDidntChanged($poll, $slots_hash); } - + /** * This method checks if the hash send by the user is the same as the computed hash. * diff --git a/create_poll.php b/create_poll.php index 91b8ed0..28f78bd 100644 --- a/create_poll.php +++ b/create_poll.php @@ -59,6 +59,8 @@ if ($goToStep2) { $use_ValueMax = isset($_POST['use_ValueMax']) ? $inputService->filterBoolean($_POST['use_ValueMax']) : false; $ValueMax = $use_ValueMax === true ? $inputService->filterValueMax($_POST['ValueMax']) : null; + $collect_users_mail = isset($_POST['collect_users_mail']) ? $inputService->filterBoolean($_POST['collect_users_mail']) : false; + $use_customized_url = isset($_POST['use_customized_url']) ? $inputService->filterBoolean($_POST['use_customized_url']) : false; $customized_url = $use_customized_url === true ? $inputService->filterId($_POST['customized_url']) : null; $name = $inputService->filterName($_POST['name']); @@ -69,6 +71,8 @@ if ($goToStep2) { $receiveNewComments = isset($_POST['receiveNewComments']) ? $inputService->filterBoolean($_POST['receiveNewComments']) : false; $hidden = isset($_POST['hidden']) ? $inputService->filterBoolean($_POST['hidden']) : false; $use_password = filter_input(INPUT_POST, 'use_password', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_REGEX]]); + $collect_users_mail = isset($_POST['collect_users_mail']) ? $inputService->filterBoolean($_POST['collect_users_mail']) : false; + $use_password = filter_input(INPUT_POST, 'use_password', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_REGEX]]); $password = isset($_POST['password']) ? $_POST['password'] : null; $password_repeat = isset($_POST['password_repeat']) ? $_POST['password_repeat'] : null; $results_publicly_visible = filter_input(INPUT_POST, 'results_publicly_visible', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_REGEX]]); @@ -95,6 +99,7 @@ if ($goToStep2) { $_SESSION['form']->receiveNewVotes = $receiveNewVotes; $_SESSION['form']->receiveNewComments = $receiveNewComments; $_SESSION['form']->hidden = $hidden; + $_SESSION['form']->collect_users_mail = $collect_users_mail; $_SESSION['form']->use_password = ($use_password !== null); $_SESSION['form']->results_publicly_visible = ($results_publicly_visible !== null); @@ -291,6 +296,7 @@ $smarty->assign('customized_url', Utils::fromPostOrDefault('customized_url', $_S $smarty->assign('use_customized_url', Utils::fromPostOrDefault('use_customized_url', $_SESSION['form']->use_customized_url)); $smarty->assign('ValueMax', Utils::fromPostOrDefault('ValueMax', $_SESSION['form']->ValueMax)); $smarty->assign('use_ValueMax', Utils::fromPostOrDefault('use_ValueMax', $_SESSION['form']->use_ValueMax)); +$smarty->assign('collect_users_mail', Utils::fromPostOrDefault('collect_users_mail', $_SESSION['form']->collect_users_mail)); $smarty->assign('poll_description', !empty($_POST['description']) ? $_POST['description'] : $_SESSION['form']->description); $smarty->assign('poll_name', Utils::fromPostOrDefault('name', $_SESSION['form']->admin_name)); $smarty->assign('poll_mail', Utils::fromPostOrDefault('mail', $_SESSION['form']->admin_mail)); diff --git a/css/style.css b/css/style.css index 9696951..59d98f7 100644 --- a/css/style.css +++ b/css/style.css @@ -449,19 +449,10 @@ span.edit-username-left { border-color: #949494 !important; } -table.results .bg-danger .glyphicon { +/* TODO : Refactor me ! */ +table.results .bg-danger .glyphicon:not(.glyphicon-alert) { opacity:0; - -moz-animation-name: hideNoIcon; - -moz-animation-iteration-count: 1; - -moz-animation-timing-function: ease-in; - -moz-animation-duration: 2s; - - -webkit-animation-name: hideNoIcon; - -webkit-animation-iteration-count: 1; - -webkit-animation-timing-function: ease-in; - -webkit-animation-duration: 2s; - animation-name: hideNoIcon; animation-iteration-count: 1; animation-timing-function: ease-in; diff --git a/js/app/create_poll.js b/js/app/create_poll.js index c3fcffc..167907b 100644 --- a/js/app/create_poll.js +++ b/js/app/create_poll.js @@ -67,6 +67,25 @@ $(document).ready(function () { } }); + /** + * Hide/Show Warning collect_users_mail + editable by all + */ + $("#collect_users_mail").change(function(){ + if ($(this).prop("checked") && $("input[name='editable']:checked").val() == 1) { + $("#collect_warning").removeClass("hidden"); + } else { + $("#collect_warning").addClass("hidden"); + } + }); + + $("input[name='editable']").change(function(){ + if ($("#collect_users_mail").prop("checked") && $("input[name='editable']:checked").val() == 1) { + $("#collect_warning").removeClass("hidden"); + } else { + $("#collect_warning").addClass("hidden"); + } + }); + // Check cookies are enabled too var cookieEnabled = function () { var cookieEnabled = navigator.cookieEnabled; diff --git a/locale/en.json b/locale/en.json index 13b7bb0..3681c0a 100644 --- a/locale/en.json +++ b/locale/en.json @@ -285,7 +285,8 @@ "Vote yes for": "Vote \"yes\" for", "Votes of the poll": "Votes", "polled user": "polled user", - "polled users": "polled users" + "polled users": "polled users", + "Anyone will be able to access your email address after your vote" : "Anyone will be able to access your email address after your vote" }, "PollInfo": { "Admin link of the poll": "Admin link for the poll", @@ -327,7 +328,8 @@ "Simple editor": "Simple editor", "Title": "Title of the poll", "Votes and comments are locked": "Votes and comments are locked", - "Votes protected by password": "Votes protected by password" + "Votes protected by password": "Votes protected by password", + "Collecting the polled users emails" : "Collecting the polled users emails" }, "Step 1": { "All voters can modify any vote": "All voters can modify any vote", @@ -357,7 +359,10 @@ "Voters can modify their vote themselves": "Voters can modify their vote themselves", "Votes cannot be modified": "Votes cannot be modified", "You are in the poll creation section.": "You are in the poll creation section.", - "You can enable or disable the editor at will.": "You can enable or disable the editor at will." + "You can enable or disable the editor at will.": "You can enable or disable the editor at will.", + "Collect users email" : "Collect users email", + "Collect the polled users email addresses" : "Collect the polled users email addresses", + "Warning: anyone can access the polled users email addresses since all voters can modify any vote. You should restrict permission rules." : "Warning: anyone can access the polled users email addresses since all voters can modify any vote. You should restrict permission rules." }, "Step 2": { "Back to step 1": "Return to step 1", @@ -407,6 +412,7 @@ }, "adminstuds": { "Add a column": "Add a column", + "Collect the emails of the polled users for the choice": "Collect the emails of the polled users for the choice", "All comments deleted": "All comments deleted", "All votes deleted": "All votes deleted", "As poll administrator, you can change all the lines of this poll with this button": "As poll administrator, you can change all the lines of this poll with this button", @@ -450,5 +456,13 @@ "The poll is expired, it will be deleted soon.": "The poll has expired, it will soon be deleted.", "Update vote succeeded": "Vote updated", "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:": "Your vote has been saved, but please note: you need to keep this personalised link to be able to edit your vote." + }, + "display_mails": { + "People who have answered 'Yes' to this option have not left any email addresses." : "People who have answered 'Yes' to this option have not left any email addresses.", + "People who have answered 'If need be' to this option have not left any email addresses." : "People who have answered 'If need be' to this option have not left any email addresses.", + "People who have answered 'No' to this option have not left any email addresses." : "People who have answered 'No' to this option have not left any email addresses.", + "People who have answered 'Yes' to this option have left those email addresses :" : "People who have answered 'Yes' to this option have left those email addresses :", + "People who have answered 'If need be' to this option have left those email addresses :" : "People who have answered 'If need be' to this option have left those email addresses :", + "People who have answered 'No' to this option have left those email addresses :" : "People who have answered 'No' to this option have left those email addresses :" } } diff --git a/studs.php b/studs.php index a90514d..72d0ce4 100644 --- a/studs.php +++ b/studs.php @@ -120,6 +120,11 @@ if ($accessGranted) { if (!empty($_POST['save'])) { // Save edition of an old vote $name = $inputService->filterName($_POST['name']); + if(empty($_POST['mail']) || $inputService->filterMail($_POST['mail']) === false) { + $mail = null; + } else { + $mail = $inputService->filterMail($_POST['mail']); + } $editedVote = filter_input(INPUT_POST, 'save', FILTER_VALIDATE_INT); $choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]); $slots_hash = $inputService->filterMD5($_POST['control']); @@ -134,7 +139,7 @@ if ($accessGranted) { if ($message === null) { // Update vote try { - $result = $pollService->updateVote($poll_id, $editedVote, $name, $choices, $slots_hash); + $result = $pollService->updateVote($poll_id, $editedVote, $name, $choices, $slots_hash, $mail); if ($result) { if ($poll->editable === Editable::EDITABLE_BY_OWN) { $editedVoteUniqueId = filter_input(INPUT_POST, 'edited_vote', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]); @@ -156,6 +161,11 @@ if ($accessGranted) { } } elseif (isset($_POST['save'])) { // Add a new vote $name = $inputService->filterName($_POST['name']); + if(empty($_POST['mail']) || $inputService->filterMail($_POST['mail']) === false) { + $mail = null; + } else { + $mail = $inputService->filterMail($_POST['mail']); + } $choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]); $slots_hash = $inputService->filterMD5($_POST['control']); @@ -169,7 +179,7 @@ if ($accessGranted) { if ($message === null) { // Add vote try { - $result = $pollService->addVote($poll_id, $name, $choices, $slots_hash); + $result = $pollService->addVote($poll_id, $name, $choices, $slots_hash, $mail); if ($result) { if (intval($poll->editable) === Editable::EDITABLE_BY_OWN) { $editedVoteUniqueId = $result->uniqId; diff --git a/tpl/create_poll.tpl b/tpl/create_poll.tpl index 59353e3..d0f0654 100644 --- a/tpl/create_poll.tpl +++ b/tpl/create_poll.tpl @@ -325,9 +325,30 @@ + {* Collect users email *} + +
+ + +
+
+ +
+
+ +
-