diff --git a/choix_autre.php b/choix_autre.php index da3c4bc..11e693f 100644 --- a/choix_autre.php +++ b/choix_autre.php @@ -57,14 +57,32 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( // Step 4 : Data prepare before insert in DB if (isset($_POST['confirmecreation'])) { - $registredate = explode('/', $_POST['champdatefin']); - if (is_array($registredate) == true && count($registredate) == 3) { - $time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]); - if ($time > time() + (24 * 60 * 60)) { - $_SESSION['form']->champdatefin = $time; + // Define expiration date + $enddate = filter_input(INPUT_POST, 'enddate', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '#^[0-9]{2}/[0-9]{2}/[0-9]{4}$#']]); + $min_time = time() + (24 * 60 * 60); + $max_time = time() + (86400 * $config['default_poll_duration']); + + if (!empty($enddate)) { + $registredate = explode('/', $enddate); + + if (is_array($registredate) && count($registredate) == 3) { + $time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]); + + if ($time < $min_time) { + $_SESSION['form']->end_date = $min_time; + } elseif ($max_time < $time) { + $_SESSION['form']->end_date = $max_time; + } else { + $_SESSION['form']->end_date = $time; + } } } + if (empty($_SESSION['form']->end_date)) { + // By default, expiration date is 6 months after last day + $_SESSION['form']->end_date = $max_time; + } + // format du sondage AUTRE $_SESSION['form']->format = 'A'; @@ -156,7 +174,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( } $summary .= ''; - $end_date_str = utf8_encode(strftime('%d/%M/%Y', $_SESSION['form']->end_date)); //textual date + $end_date_str = utf8_encode(strftime('%d/%m/%Y', $_SESSION['form']->end_date)); //textual date echo '