diff --git a/app/classes/Framadate/Services/AdminPollService.php b/app/classes/Framadate/Services/AdminPollService.php index 85cbe71..95b2a53 100644 --- a/app/classes/Framadate/Services/AdminPollService.php +++ b/app/classes/Framadate/Services/AdminPollService.php @@ -290,7 +290,7 @@ class AdminPollService { // Search where to insert new column foreach ($slots as $k=>$slot) { - $rowDatetime = $slot->title; + $rowDatetime = (int) $slot->title; $moments = explode(',', $slot->moments); if ($datetime === $rowDatetime) { diff --git a/app/inc/constants.php b/app/inc/constants.php index 0f41737..f18a410 100644 --- a/app/inc/constants.php +++ b/app/inc/constants.php @@ -18,7 +18,7 @@ */ // FRAMADATE version -const VERSION = '1.1.8'; +const VERSION = '1.1.9'; // PHP Needed version const PHP_NEEDED_VERSION = '5.6'; diff --git a/create_classic_poll.php b/create_classic_poll.php index 920b0ae..fc777c4 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -40,8 +40,10 @@ if (is_file('bandeaux_local.php')) { include_once('bandeaux.php'); } +$form = unserialize($_SESSION['form']); + // Step 1/4 : error if $_SESSION from info_sondage are not valid -if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (($config['use_smtp']) ? empty($_SESSION['form']->admin_mail) : false)) { +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.')); $smarty->display('error.tpl'); @@ -51,10 +53,14 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( $min_expiry_time = $pollService->minExpiryDate(); $max_expiry_time = $pollService->maxExpiryDate(); - // The poll format is AUTRE (other) - if ($_SESSION['form']->format !== 'A') { - $_SESSION['form']->format = 'A'; - $_SESSION['form']->clearChoices(); + // 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(); } // Step 4 : Data prepare before insert in DB @@ -69,22 +75,22 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( $time = mktime(0, 0, 0, $registredate[1], $registredate[0], $registredate[2]); if ($time < $min_expiry_time) { - $_SESSION['form']->end_date = $min_expiry_time; + $form->end_date = $min_expiry_time; } elseif ($max_expiry_time < $time) { - $_SESSION['form']->end_date = $max_expiry_time; + $form->end_date = $max_expiry_time; } else { - $_SESSION['form']->end_date = $time; + $form->end_date = $time; } } } - if (empty($_SESSION['form']->end_date)) { + if (empty($form->end_date)) { // By default, expiration date is 6 months after last day - $_SESSION['form']->end_date = $max_expiry_time; + $form->end_date = $max_expiry_time; } // Insert poll in database - $ids = $pollService->createPoll($_SESSION['form']); + $ids = $pollService->createPoll($form); $poll_id = $ids[0]; $admin_poll_id = $ids[1]; @@ -92,15 +98,15 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( if ($config['use_smtp'] === true) { $message = __('Mail', "This is the message you have to send to the people you want to poll. \nNow, you have to send this message to everyone you want to poll."); $message .= '

'; - $message .= Utils::htmlMailEscape($_SESSION['form']->admin_name) . ' ' . __('Mail', 'hast just created a poll called') . ' : "' . Utils::htmlMailEscape($_SESSION['form']->title) . '".
'; + $message .= Utils::htmlMailEscape($form->admin_name) . ' ' . __('Mail', 'hast just created a poll called') . ' : "' . Utils::htmlMailEscape($form->title) . '".
'; $message .= sprintf(__('Mail', 'Thanks for filling the poll at the link above') . ' :

%1$s', Utils::getUrlSondage($poll_id)); $message_admin = __('Mail', "This message should NOT be sent to the polled people. It is private for the poll's creator.\n\nYou can now modify it at the link above"); $message_admin .= sprintf(' :

%1$s', Utils::getUrlSondage($admin_poll_id, true)); - if ($mailService->isValidEmail($_SESSION['form']->admin_mail)) { - $mailService->send($_SESSION['form']->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Author\'s message') . '] ' . __('Generic', 'Poll') . ': ' . $_SESSION['form']->title, $message_admin); - $mailService->send($_SESSION['form']->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'For sending to the polled users') . '] ' . __('Generic', 'Poll') . ': ' . $_SESSION['form']->title, $message); + if ($mailService->isValidEmail($form->admin_mail)) { + $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Author\'s message') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message_admin); + $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'For sending to the polled users') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message); } } @@ -112,7 +118,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( // creation message $sessionService->set("Framadate", "messagePollCreated", TRUE); - + // Redirect to poll administration header('Location:' . Utils::getUrlSondage($admin_poll_id, true)); exit; @@ -120,22 +126,22 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( else if (isset($_POST['fin_sondage_autre'])) { // Store choices in $_SESSION if (isset($_POST['choices'])) { - $_SESSION['form']->clearChoices(); + $form->clearChoices(); foreach ($_POST['choices'] as $c) { if (!empty($c)) { $c = strip_tags($c); $choice = new Choice($c); - $_SESSION['form']->addChoice($choice); + $form->addChoice($choice); } } } // Expiration date is initialised with config parameter. Value will be modified in step 4 if user has defined an other date - $_SESSION['form']->end_date = $max_expiry_time; + $form->end_date = $max_expiry_time; // Summary $summary = '
    '; - foreach ($_SESSION['form']->getChoices() as $i=>$choice) { + foreach ($form->getChoices() as $i=>$choice) { preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/', $choice->getName(), $md_a_img); // Markdown [![alt](src)](href) preg_match_all('/!\[(.*?)\]\((.*?)\)/', $choice->getName(), $md_img); // Markdown ![alt](src) preg_match_all('/\[(.*?)\]\((.*?)\)/', $choice->getName(), $md_a); // Markdown [text](href) @@ -159,6 +165,8 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( $end_date_str = utf8_encode(strftime($date_format['txt_date'], $max_expiry_time)); //textual date + $_SESSION['form'] = serialize($form); + $smarty->assign('title', __('Step 3', 'Removal date and confirmation (3 on 3)')); $smarty->assign('summary', $summary); $smarty->assign('end_date_str', $end_date_str); @@ -186,7 +194,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( echo ' ' . "\n"; // Fields choices : 5 by default - $choices = $_SESSION['form']->getChoices(); + $choices = $form->getChoices(); $nb_choices = max(count($choices), 5); for ($i = 0; $i < $nb_choices; $i++) { $choice = isset($choices[$i]) ? $choices[$i] : new Choice(); @@ -253,4 +261,3 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( bandeau_pied(); } - diff --git a/create_date_poll.php b/create_date_poll.php index 83e0496..0eb35e7 100644 --- a/create_date_poll.php +++ b/create_date_poll.php @@ -44,17 +44,23 @@ if (is_readable('bandeaux_local.php')) { $min_expiry_time = $pollService->minExpiryDate(); $max_expiry_time = $pollService->maxExpiryDate(); -// The poll format is DATE -if ($_SESSION['form']->format !== 'D') { - $_SESSION['form']->format = 'D'; - $_SESSION['form']->clearChoices(); +$form = unserialize($_SESSION['form']); + +// The poll format is DATE if we are in this file +if (!isset($form->format)) { + $form->format = 'D'; +} +// If we come from another format, we need to clear choices +if (isset($form->format) && $form->format !== 'D') { + $form->format = 'D'; + $form->clearChoices(); } -if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) || ($config['use_smtp'] && !isset($_SESSION['form']->admin_mail))) { +if (!isset($form->title) || !isset($form->admin_name) || ($config['use_smtp'] && !isset($form->admin_mail))) { $step = 1; } else if (!empty($_POST['confirmation'])) { $step = 4; -} else if (empty($_POST['choixheures']) || isset($_SESSION['form']->totalchoixjour)) { +} else if (empty($_POST['choixheures']) || isset($form->totalchoixjour)) { $step = 2; } else { $step = 3; @@ -72,25 +78,28 @@ switch ($step) { // Step 2/4 : Select dates of the poll // Prefill form->choices - foreach ($_SESSION['form']->getChoices() as $c) { + foreach ($form->getChoices() as $c) { + /** @var Choice $c */ $count = 3 - count($c->getSlots()); for ($i = 0; $i < $count; $i++) { $c->addSlot(''); } } - $count = 3 - count($_SESSION['form']->getChoices()); + $count = 3 - count($form->getChoices()); for ($i = 0; $i < $count; $i++) { $c = new Choice(''); $c->addSlot(''); $c->addSlot(''); $c->addSlot(''); - $_SESSION['form']->addChoice($c); + $form->addChoice($c); } + $_SESSION['form'] = serialize($form); + // Display step 2 $smarty->assign('title', __('Step 2 date', 'Poll dates (2 on 3)')); - $smarty->assign('choices', $_SESSION['form']->getChoices()); + $smarty->assign('choices', $form->getChoices()); $smarty->assign('error', null); $smarty->display('create_date_poll_step_2.tpl'); @@ -110,7 +119,7 @@ switch ($step) { if (count($_POST['days']) > MAX_SLOTS_PER_POLL) { // Display step 2 $smarty->assign('title', __('Step 2 date', 'Poll dates (2 on 3)')); - $smarty->assign('choices', $_SESSION['form']->getChoices()); + $smarty->assign('choices', $form->getChoices()); $smarty->assign('error', __f('Error', 'You can\'t select more than %d dates', MAX_SLOTS_PER_POLL)); $smarty->display('create_date_poll_step_2.tpl'); @@ -118,7 +127,7 @@ switch ($step) { } // Clear previous choices - $_SESSION['form']->clearChoices(); + $form->clearChoices(); // Reorder moments to deal with suppressed dates $moments = []; @@ -138,7 +147,7 @@ switch ($step) { $date = DateTime::createFromFormat(__('Date', 'datetime_parseformat'), $_POST['days'][$i])->setTime(0, 0, 0); $time = $date->getTimestamp(); $choice = new Choice($time); - $_SESSION['form']->addChoice($choice); + $form->addChoice($choice); $schedules = $inputService->filterArray($moments[$i], FILTER_DEFAULT); for ($j = 0; $j < count($schedules); $j++) { @@ -148,12 +157,12 @@ switch ($step) { } } } - $_SESSION['form']->sortChoices(); + $form->sortChoices(); } // Display step 3 $summary = '