diff --git a/adminstuds.php b/adminstuds.php index 5750828..cc6f675 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -122,8 +122,7 @@ if (isset($_POST['update_poll_info'])) { break; } } elseif ($field == 'expiration_date') { - $expiration_date = filter_input(INPUT_POST, 'expiration_date', FILTER_VALIDATE_REGEXP, - ['options' => ['regexp' => '#^[0-9]{4}-[0-9]{2}-[0-9]{2}$#']]); + $expiration_date = $inputService->filterDate($_POST['expiration_date']); if ($expiration_date) { $poll->end_date = $expiration_date; $updated = true; diff --git a/app/classes/Framadate/Services/AdminPollService.php b/app/classes/Framadate/Services/AdminPollService.php index 369d13d..2e3f3af 100644 --- a/app/classes/Framadate/Services/AdminPollService.php +++ b/app/classes/Framadate/Services/AdminPollService.php @@ -4,6 +4,7 @@ namespace Framadate\Services; use Framadate\Exception\MomentAlreadyExistsException; use Framadate\FramaDB; use Framadate\Repositories\RepositoryFactory; +use Framadate\Utils; /** * Class AdminPollService @@ -33,7 +34,7 @@ class AdminPollService { function updatePoll($poll) { global $config; - if ($poll->end_date > $poll->creation_date && $poll->end_date <= strtotime($poll->creation_date) + (86400 * $config['default_poll_duration'])) { + if ($poll->end_date > $poll->creation_date) { return $this->pollRepository->update($poll); } else { return false; diff --git a/app/classes/Framadate/Services/InputService.php b/app/classes/Framadate/Services/InputService.php index 5db7f7e..ebf3c5f 100644 --- a/app/classes/Framadate/Services/InputService.php +++ b/app/classes/Framadate/Services/InputService.php @@ -17,6 +17,7 @@ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ namespace Framadate\Services; +use DateTime; /** * This class helps to clean all inputs from the users or external services. @@ -90,6 +91,11 @@ class InputService { return $this->returnIfNotBlank($comment); } + public function filterDate($date) { + $dDate = DateTime::createFromFormat(__('Date', 'datetime_parseformat'), $date)->setTime(0, 0, 0); + return $dDate->format('Y-m-d H:i:s'); + } + /** * Return the value if it's not blank. * @@ -107,4 +113,4 @@ class InputService { return null; } -} \ No newline at end of file +}