diff --git a/adminstuds.php b/adminstuds.php index b642d845291beab76bb5f9466eae933119315f97..0d03059092899b141ea713b311a58b8d53e9acc9 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -149,14 +149,29 @@ if (isset($_POST['update_poll_info'])) { } } elseif ($field === 'password') { $password = isset($_POST['password']) ? $_POST['password'] : null; + + /** + * Did the user choose results to be publicly visible ? + */ $resultsPubliclyVisible = isset($_POST['resultsPubliclyVisible']) ? $inputService->filterBoolean($_POST['resultsPubliclyVisible']) : false; + /** + * If there's one, save the password + */ if (!empty($password)) { $poll->password_hash = PasswordHasher::hash($password); $updated = true; } - if ($poll->password_hash === null || $poll->hidden === true){ - $poll->results_publicly_visible = false; - } + + /** + * If not pasword was set and the poll should be hidden, hide the results + */ + if ($poll->password_hash === null || $poll->hidden === true) { + $poll->results_publicly_visible = false; + } + + /** + * We don't have a password, the poll is hidden and we change the results public visibility + */ if ($resultsPubliclyVisible !== $poll->results_publicly_visible && $poll->password_hash !== null && $poll->hidden === false) { $poll->results_publicly_visible = $resultsPubliclyVisible; $updated = true; diff --git a/js/app/studs.js b/js/app/studs.js index 9ee6696113d642e53a836c180ac43044622eb51c..7ebef8c1c6f89cf84c6f7c7cb5dc314202c9d877 100644 --- a/js/app/studs.js +++ b/js/app/studs.js @@ -103,8 +103,14 @@ $(document).ready(function () { return false; }); - $('#password').on('keyup change', function () { - if($('#password').val() && !($('#hidden').attr('checked'))){$('#resultsPubliclyVisible').removeAttr('disabled');} - else {$('#resultsPubliclyVisible').attr('disabled','disabled');}; - }); + /** + * Disable view public results option when there's a password and the poll is not hidden + */ + $('#password').on('keyup change', function () { + if($('#password').val() && !($('#hidden').attr('checked'))){ + $('#resultsPubliclyVisible').removeAttr('disabled'); + } else { + $('#resultsPubliclyVisible').attr('disabled','disabled'); + } + }); });