Poll creation: Fix + Improve end date choice

This commit is contained in:
Olivier PEREZ 2015-01-04 01:36:55 +01:00
parent bb3d10583d
commit 6fff5f107a
10 changed files with 59 additions and 32 deletions

View File

@ -57,14 +57,32 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
// Step 4 : Data prepare before insert in DB // Step 4 : Data prepare before insert in DB
if (isset($_POST['confirmecreation'])) { if (isset($_POST['confirmecreation'])) {
$registredate = explode('/', $_POST['champdatefin']); // Define expiration date
if (is_array($registredate) == true && count($registredate) == 3) { $enddate = filter_input(INPUT_POST, 'enddate', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '#^[0-9]{2}/[0-9]{2}/[0-9]{4}$#']]);
$time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]); $min_time = time() + (24 * 60 * 60);
if ($time > time() + (24 * 60 * 60)) { $max_time = time() + (86400 * $config['default_poll_duration']);
$_SESSION['form']->champdatefin = $time;
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 // format du sondage AUTRE
$_SESSION['form']->format = 'A'; $_SESSION['form']->format = 'A';
@ -156,7 +174,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
} }
$summary .= '</ol>'; $summary .= '</ol>';
$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 ' echo '
<form name="formulaire" action="' . Utils::get_server_name() . 'choix_autre.php" method="POST" class="form-horizontal" role="form"> <form name="formulaire" action="' . Utils::get_server_name() . 'choix_autre.php" method="POST" class="form-horizontal" role="form">
@ -167,23 +185,23 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
' . $summary . ' ' . $summary . '
</div> </div>
<div class="alert alert-info"> <div class="alert alert-info">
<p>' . _('Your poll will be automatically removed after') . ' ' . $config['default_poll_duration'] . ' ' . _('days') . '.<br />' . _("You can fix another removal date for it.") . '</p> <p>' . _('Your poll will be automatically removed after') . ' ' . $config['default_poll_duration'] . ' ' . _('days') . '.<br />' . _('You can set a closer removal date for it.') . '</p>
<div class="form-group"> <div class="form-group">
<label for="champdatefin" class="col-sm-5 control-label">' . _('Removal date (optional)') . '</label> <label for="enddate" class="col-sm-5 control-label">' . _('Removal date (optional)') . '</label>
<div class="col-sm-6"> <div class="col-sm-6">
<div class="input-group date"> <div class="input-group date">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span> <span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
<input type="text" class="form-control" id="champdatefin" data-date-format="' . _("dd/mm/yyyy") . '" aria-describedby="dateformat" name="champdatefin" value="' . $end_date_str . '" size="10" maxlength="10" placeholder="' . _("dd/mm/yyyy") . '" /> <input type="text" class="form-control" id="enddate" data-date-format="' . _('dd/mm/yyyy') . '" aria-describedby="dateformat" name="enddate" value="' . $end_date_str . '" size="10" maxlength="10" placeholder="' . _("dd/mm/yyyy") . '" />
</div> </div>
</div> </div>
<span id="dateformat" class="sr-only">' . _("(dd/mm/yyyy)") . '</span> <span id="dateformat" class="sr-only">' . _('(dd/mm/yyyy)') . '</span>
</div> </div>
</div> </div>
<div class="alert alert-warning"> <div class="alert alert-warning">
<p>' . _("Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll.") . '</p>'; <p>' . _('Once you have confirmed the creation of your poll, you will be automatically redirected on the administration page of your poll.') . '</p>';
if ($config['use_smtp'] == true) { if ($config['use_smtp'] == true) {
echo ' echo '
<p>' . _("Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.") . '</p>'; <p>' . _('Then, you will receive quickly two emails: one contening the link of your poll for sending it to the voters, the other contening the link to the administration page of your poll.') . '</p>';
} }
echo ' echo '
</div> </div>

View File

@ -58,22 +58,29 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
if (!empty($_POST['confirmation'])) { if (!empty($_POST['confirmation'])) {
// Define expiration date // Define expiration date
if (!empty($_POST['champdatefin'])) $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);
$registredate = explode('/', $_POST['champdatefin']); $max_time = time() + (86400 * $config['default_poll_duration']);
if (is_array($registredate) && count($registredate) == 3)
{ if (!empty($enddate)) {
$time = mktime(0,0,0, $registredate[1], $registredate[0], $registredate[2]); $registredate = explode('/', $enddate);
if ($time > time() + (24*60*60))
{ if (is_array($registredate) && count($registredate) == 3) {
$_SESSION['form']->end_date=$time; $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)) { if (empty($_SESSION['form']->end_date)) {
// By default, expiration date is 6 months after last day // By default, expiration date is 6 months after last day
$_SESSION['form']->end_date=end($temp_results)+(86400 * $config['default_poll_duration']); $_SESSION['form']->end_date = $max_time;
} }
// Insert poll in database // Insert poll in database
@ -165,6 +172,8 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
} }
$summary .= '</ul>'; $summary .= '</ul>';
$end_date_str = utf8_encode(strftime('%d/%m/%Y', $_SESSION['form']->end_date)); //textual date
echo ' echo '
<form name="formulaire" action="' . Utils::get_server_name() . 'choix_date.php" method="POST" class="form-horizontal" role="form"> <form name="formulaire" action="' . Utils::get_server_name() . 'choix_date.php" method="POST" class="form-horizontal" role="form">
<div class="row" id="selected-days"> <div class="row" id="selected-days">
@ -175,13 +184,13 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
'. $summary .' '. $summary .'
</div> </div>
<div class="alert alert-info clearfix"> <div class="alert alert-info clearfix">
<p>' . _('Your poll will be automatically removed '). $config['default_poll_duration'] . ' ' . _("days") . ' ' ._('after the last date of your poll') . '.<br />' . _('You can fix another removal date for it.') .'</p> <p>' . _('Your poll will be automatically removed '). $config['default_poll_duration'] . ' ' . _('days') . ' ' ._('after the last date of your poll') . '.<br />' . _('You can set a closer removal date for it.') .'</p>
<div class="form-group"> <div class="form-group">
<label for="champdatefin" class="col-sm-5 control-label">'. _('Removal date') .'</label> <label for="enddate" class="col-sm-5 control-label">'. _('Removal date') .'</label>
<div class="col-sm-6"> <div class="col-sm-6">
<div class="input-group date"> <div class="input-group date">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span> <span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
<input type="text" class="form-control" id="champdatefin" data-date-format="'. _("dd/mm/yyyy") .'" aria-describedby="dateformat" name="champdatefin" value="'.strftime('%d/%m/%Y', $removal_date).'" size="10" maxlength="10" placeholder="'. _('dd/mm/yyyy') .'" /> <input type="text" class="form-control" id="enddate" data-date-format="'. _('dd/mm/yyyy') .'" aria-describedby="dateformat" name="enddate" value="'.$end_date_str.'" size="10" maxlength="10" placeholder="'. _('dd/mm/yyyy') .'" />
</div> </div>
</div> </div>
<span id="dateformat" class="sr-only">'. _("(dd/mm/yyyy)") .'</span> <span id="dateformat" class="sr-only">'. _("(dd/mm/yyyy)") .'</span>

Binary file not shown.

View File

@ -567,7 +567,7 @@ msgstr "Löschdatum:"
msgid "Your poll will be automatically removed after 6 months." msgid "Your poll will be automatically removed after 6 months."
msgstr "Ihre Umfrage wird automatisch nach 6 Monaten gelöscht." msgstr "Ihre Umfrage wird automatisch nach 6 Monaten gelöscht."
msgid "You can fix another removal date for it." msgid "You can set a closer removal date for it."
msgstr "Sie können jedoch auch ein anderes Löschdatum festlegen." msgstr "Sie können jedoch auch ein anderes Löschdatum festlegen."
msgid "Removal date (optional)" msgid "Removal date (optional)"

Binary file not shown.

View File

@ -576,8 +576,8 @@ msgstr "Removal date:"
msgid "Your poll will be automatically removed after" msgid "Your poll will be automatically removed after"
msgstr "Your poll will be automatically removed after" msgstr "Your poll will be automatically removed after"
msgid "You can fix another removal date for it." msgid "You can set a closer removal date for it."
msgstr "You can fix another removal date for it." msgstr "You can set a closer removal date for it."
msgid "Removal date (optional)" msgid "Removal date (optional)"
msgstr "Removal date (optional)" msgstr "Removal date (optional)"

Binary file not shown.

View File

@ -526,7 +526,7 @@ msgid "Characters \" < and > are not permitted"
msgstr "Los caracteres \" < y > no estan autorizados!" msgstr "Los caracteres \" < y > no estan autorizados!"
#: choix_autre.php:191 #: choix_autre.php:191
msgid "Your poll will be automatically removed after 6 months.<br> You can fix another removal date for it." msgid "Your poll will be automatically removed after 6 months.<br> You can set a closer removal date for it."
msgstr "Su encuesta ser&aacute; automaticamente borrado dentro de 6 meses.<br> Mientras, usted puede cambiar este fecha aqu&iacute;." msgstr "Su encuesta ser&aacute; automaticamente borrado dentro de 6 meses.<br> Mientras, usted puede cambiar este fecha aqu&iacute;."
#: choix_autre.php:193 #: choix_autre.php:193

Binary file not shown.

View File

@ -576,8 +576,8 @@ msgstr "Date de suppression :"
msgid "Your poll will be automatically removed after" msgid "Your poll will be automatically removed after"
msgstr "Votre sondage sera automatiquement effacé dans" msgstr "Votre sondage sera automatiquement effacé dans"
msgid "You can fix another removal date for it." msgid "You can set a closer removal date for it."
msgstr "Néanmoins vous pouvez décider ci-dessous d'une date plus rapprochée pour la suppression de votre sondage." msgstr "Vous pouvez décider d'une date de suppression plus proche."
msgid "Removal date (optional)" msgid "Removal date (optional)"
msgstr "Date de fin (facultative)" msgstr "Date de fin (facultative)"