diff --git a/adminstuds.php b/adminstuds.php index b168345..6d71f70 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -63,7 +63,7 @@ if (!$poll) { if (isset($_POST['update_poll_info'])) { $updated = false; - $field = $inputService->filterAllowedValues($_POST['update_poll_info'], ['title', 'admin_mail', 'comment', 'rules']); + $field = $inputService->filterAllowedValues($_POST['update_poll_info'], ['title', 'admin_mail', 'comment', 'rules', 'expiration_date']); // Update the right poll field if ($field == 'title') { @@ -103,6 +103,13 @@ if (isset($_POST['update_poll_info'])) { $updated = true; break; } + } elseif ($field == 'expiration_date') { + $expiration_date = filter_input(INPUT_POST, 'expiration_date', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '#^[0-9]+[-/][0-9]+[-/][0-9]+#']]); + $expiration_date = strtotime($expiration_date); + if ($expiration_date) { + $poll->end_date = $expiration_date; + $updated = true; + } } // Update poll in database @@ -110,6 +117,7 @@ if (isset($_POST['update_poll_info'])) { $message = new Message('success', _('Poll saved.')); } else { $message = new Message('danger', _('Failed to save poll.')); + $poll = $pollService->findById($poll_id); } } diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index c41a439..b7a9f0e 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -88,9 +88,9 @@ class FramaDB { } function updatePoll($poll) { - $prepared = $this->prepare('UPDATE ' . Utils::table('poll') . ' SET title=?, admin_mail=?, comment=?, active=?, editable=? WHERE id = ?'); + $prepared = $this->prepare('UPDATE ' . Utils::table('poll') . ' SET title=?, admin_mail=?, description=?, end_date=FROM_UNIXTIME(?), active=?, editable=? WHERE id = ?'); - return $prepared->execute([$poll->title, $poll->admin_mail, $poll->comment, $poll->active, $poll->editable, $poll->id]); + return $prepared->execute([$poll->title, $poll->admin_mail, $poll->description, $poll->end_date, $poll->active, $poll->editable, $poll->id]); } function allCommentsByPollId($poll_id) { diff --git a/app/classes/Framadate/Services/AdminPollService.php b/app/classes/Framadate/Services/AdminPollService.php index 3926362..a346de2 100644 --- a/app/classes/Framadate/Services/AdminPollService.php +++ b/app/classes/Framadate/Services/AdminPollService.php @@ -22,7 +22,12 @@ class AdminPollService { } function updatePoll($poll) { - return $this->connect->updatePoll($poll); + global $config; + if ($poll->end_date <= strtotime($poll->creation_date) + (86400 * $config['default_poll_duration'])) { + return $this->connect->updatePoll($poll); + } else { + return false; + } } /** diff --git a/css/style.css b/css/style.css index f3bb307..3188c8d 100644 --- a/css/style.css +++ b/css/style.css @@ -120,7 +120,8 @@ caption { #title-form h3 .btn-edit, #email-form .btn-edit, #description-form .btn-edit, -#poll-rules-form .btn-edit { +#poll-rules-form .btn-edit, +#expiration-form .btn-edit { position:absolute; left:-2000px; } @@ -132,7 +133,9 @@ caption { #description-form .btn-edit:focus, #description-form:hover .btn-edit, #poll-rules-form .btn-edit:focus, -#poll-rules-form:hover .btn-edit { +#poll-rules-form:hover .btn-edit, +#expiration-form .btn-edit:focus, +#expiration-form:hover .btn-edit { position:relative !important; left:0; padding: 0px 10px; diff --git a/js/core.js b/js/core.js index dd4a4aa..9e1c4b4 100644 --- a/js/core.js +++ b/js/core.js @@ -364,6 +364,20 @@ $(document).ready(function() { return false; }); + $('#expiration-form .btn-edit').on('click', function() { + $('#expiration-form p').hide(); + $('.js-expiration').removeClass("hidden"); + $('.js-expiration input').focus(); + return false; + }); + + $('#expiration-form .btn-cancel').on('click', function() { + $('#expiration-form p').show(); + $('#expiration-form .js-expiration').addClass("hidden"); + $('#expiration-form .btn-edit').focus(); + return false; + }); + // Horizontal scroll buttons if($('.results').width() > $('.container').width()) { $('.scroll-buttons').removeClass('hidden'); diff --git a/tpl/part/poll_info.tpl b/tpl/part/poll_info.tpl index f74625b..68abcfc 100644 --- a/tpl/part/poll_info.tpl +++ b/tpl/part/poll_info.tpl @@ -12,8 +12,8 @@
{$poll->comment}
{$poll->end_date|date_format:$date_format['txt_date']}
+{$poll->end_date|date_format:$date_format['txt_date']}{if $admin} {/if}
+ {if $admin} +{$rule_icon} {$rule_txt}
+{$rule_icon} {$rule_txt}