diff --git a/create_classic_poll.php b/create_classic_poll.php index 8f5deba..3830305 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -17,6 +17,7 @@ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ use Framadate\Choice; +use Framadate\Services\InputService; use Framadate\Services\LogService; use Framadate\Services\MailService; use Framadate\Services\PollService; @@ -40,32 +41,107 @@ if (is_file('bandeaux_local.php')) { include_once('bandeaux.php'); } +// Min/Max archive date +$min_expiry_time = $pollService->minExpiryDate(); +$max_expiry_time = $pollService->maxExpiryDate(); + $form = unserialize($_SESSION['form']); -// Step 1/4 : error if $_SESSION from info_sondage are not valid -if (empty($form->title) || empty($form->admin_name) || (($config['use_smtp']) ? empty($form->admin_mail) : false)) { - $smarty->assign('title', __('Error', 'Error!')); - $smarty->assign('error', __('Error', 'You haven\'t filled the first section of the poll creation, or your session has expired.')); - $smarty->display('error.tpl'); - exit; +if (!isset($form->title) || !isset($form->admin_name) || ($config['use_smtp'] && !isset($form->admin_mail))) { + $step = 1; +} elseif (isset($_POST['confirmation'])) { + $step = 4; +} elseif (empty($_POST['fin_sondage_autre']) ) { + $step = 2; +} else { + $step = 3; } - // Min/Max archive date - $min_expiry_time = $pollService->minExpiryDate(); - $max_expiry_time = $pollService->maxExpiryDate(); - // The poll format is other (A) if we are in this file - if (!isset($form->format)) { - $form->format = 'A'; - } - // If we come from another format, we need to clear choices - if (isset($form->format) && $form->format !== 'A') { - $form->format = 'A'; - $form->clearChoices(); - } +// The poll format is AUTRE (other) +if ($form->format !== 'A') { + $form->format = 'A'; + $form->clearChoices(); +} - // Step 4 : Data prepare before insert in DB - if (isset($_POST['confirmation'])) { - // Define expiration date +switch ($step) { + case 2: // Step 2/4 : Select choices of the poll + $choices = $form->getChoices(); + $nb_choices = max( 5- count($choices), 0); + while ($nb_choices-- > 0) { + $c = new Choice(''); + $form->addChoice($c); + } + + $_SESSION['form'] = serialize($form); + + // Display step 2 + $smarty->assign('title', __('Step 2 classic', 'Poll subjects (2 on 3)')); + $smarty->assign('choices', $form->getChoices()); + $smarty->assign('allowMarkdown', $config['user_can_add_img_or_link']); + $smarty->assign('error', null); + + $smarty->display('create_classic_poll_step_2.tpl'); + exit; + + case 3: // Step 3/4 : Confirm poll creation and choose a removal date + // Handle Step2 submission + if (!empty($_POST['choices'])) { + // remove empty choices + $_POST['choices'] = array_filter($_POST['choices'], function ($c) { + return !empty($c); + }); + + $form->clearChoices(); + + // store choices in $_SESSION + foreach ($_POST['choices'] as $c) { + $c = strip_tags($c); + $choice = new Choice($c); + $form->addChoice($choice); + } + } + + // Expiration date is initialised with config parameter. Value will be modified in step 4 if user has defined an other date + $form->end_date = $max_expiry_time; + + // Summary + $summary = '