diff --git a/app/classes/Framadate/Choice.php b/app/classes/Framadate/Choice.php index d1eec51..6375945 100644 --- a/app/classes/Framadate/Choice.php +++ b/app/classes/Framadate/Choice.php @@ -13,7 +13,7 @@ class Choice */ private $slots; - public function __construct($name) + public function __construct($name='') { $this->name = $name; $this->slots = array(); diff --git a/app/classes/Framadate/Utils.php b/app/classes/Framadate/Utils.php index ae431c0..78da6e3 100644 --- a/app/classes/Framadate/Utils.php +++ b/app/classes/Framadate/Utils.php @@ -185,18 +185,19 @@ class Utils /** * Fonction vérifiant l'existance et la valeur non vide d'une clé d'un tableau + * @deprecated * @param string $name La clé à tester * @param array $tableau Le tableau où rechercher la clé ($_POST par défaut) * @return bool Vrai si la clé existe et renvoie une valeur non vide */ - public static function issetAndNoEmpty($name, $tableau = null) + /*public static function issetAndNoEmpty($name, $tableau = null) { if (is_null($tableau)) { $tableau = $_POST; } return isset($tableau[$name]) && ! empty($tableau[$name]); - } + }*/ /** * Fonction permettant de générer les URL pour les sondage @@ -258,4 +259,11 @@ class Utils } $connect->commit(); } + + public static function debug($object) + { + echo '
';
+        print_r($object);
+        echo '
'; + } } diff --git a/choix_autre.php b/choix_autre.php index fd69bd5..7ebca4d 100644 --- a/choix_autre.php +++ b/choix_autre.php @@ -18,7 +18,8 @@ */ namespace Framadate; -session_start(); +include_once __DIR__ . '/app/inc/init.php'; + include_once('creation_sondage.php'); if (file_exists('bandeaux_local.php')) { @@ -27,82 +28,90 @@ if (file_exists('bandeaux_local.php')) { include_once('bandeaux.php'); } -// Step 1/3 : error if $_SESSION from info_sondage are not valid -if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmpty('nom', $_SESSION) === false || (($config['use_smtp']) ? Utils::issetAndNoEmpty('adresse', $_SESSION) === false : false)) { +// Step 1/4 : error if $_SESSION from info_sondage are not valid +if (empty($_SESSION['form']->titre) || empty($_SESSION['form']->nom) || (($config['use_smtp']) ? empty($_SESSION['form']->adresse) : false)) { Utils::print_header ( _("Error!") ); bandeau_titre(_("Error!")); echo '
-

' . _("You haven't filled the first section of the poll creation.") . ' !

-

' . _("Back to the homepage of ") . ' ' . NOMAPPLICATION . '

+

' . _('You haven\'t filled the first section of the poll creation.') . ' !

+

' . _('Back to the homepage of') . ' ' . NOMAPPLICATION . '

'."\n"; bandeau_pied(); } else { + // Step 4 : Data prepare before insert in DB - if (isset($_POST["confirmecreation"])) { - //recuperation des données de champs textes - $temp_results = ''; - if (isset($_SESSION['choices'])) { - for ($i = 0; $i < count($_SESSION['choices']); $i++) { - if ($_SESSION['choices'][$i]!="") { - $temp_results.=','.str_replace(",", " ", htmlentities(html_entity_decode($_SESSION['choices'][$i], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8')); - } + 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; } } - $temp_results=substr($temp_results,1); - $_SESSION["toutchoix"]=$temp_results; + // format du sondage AUTRE + $_SESSION['form']->formatsondage = 'A'; + + // Insert poll in database + $admin_poll_id = ajouter_sondage( + $_SESSION['form']->titre, + $_SESSION['form']->commentaires, + $_SESSION['form']->nom, + $_SESSION['form']->adresse, + $_SESSION['form']->formatsondage, + $_SESSION['form']->editable, + $_SESSION['form']->champdatefin, + $_SESSION['form']->receiveNewVotes, + $_SESSION['form']->getChoices() + ); + + // Clean Form data in $_SESSION + unset($_SESSION['form']); - - if (Utils::issetAndNoEmpty('champdatefin')) { - $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["champdatefin"]=$time; - } - } - } - - //format du sondage AUTRE - $_SESSION["formatsondage"]="A".$_SESSION["studsplus"]; - - ajouter_sondage(); + // Delete old polls + Utils::cleaningOldPolls($connect, 'admin/logs_studs.txt'); + + // Redirect to poll administration + header('Location:' . Utils::getUrlSondage($admin_poll_id, true)); + exit; } - // recuperation des sujets pour sondage AUTRE - if (isset($_POST['choices'])) { - $k = 0; - for ($i = 0; $i < count($_POST['choices']); $i++) { - if (Utils::issetAndNoEmpty($i, $_POST['choices'])) { - $_SESSION['choices'][$k]=htmlentities(html_entity_decode($_POST['choices'][$i], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8'); - $k++; + // Step 3/4 : Confirm poll creation and choose a removal date + else if (isset($_POST['fin_sondage_autre'])) { + Utils::print_header ( _('Removal date and confirmation (3 on 3)') ); + bandeau_titre(_('Removal date and confirmation (3 on 3)')); + + + // Store choices in $_SESSION + if (isset($_POST['choices'])) { + $_SESSION['form']->clearChoices(); + foreach ($_POST['choices'] as $c) + { + if (!empty($c)) + { + $choice = new Choice(htmlentities(html_entity_decode($c, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8')); + $_SESSION['form']->addChoice($choice); + } } } - } - - // Step 3/3 : Confirm poll creation and choose a removal date - if (isset($_POST["fin_sondage_autre"])) { - Utils::print_header ( _("Removal date and confirmation (3 on 3)") ); - bandeau_titre(_("Removal date and confirmation (3 on 3)")); // Expiration date is initialised with config parameter. Value will be modified in step 4 if user has defined an other date - $_SESSION["champdatefin"]= time()+ (86400 * $config['default_poll_duration']); //60 sec * 60 min * 24 hours * config - - $removal_date= utf8_encode(strftime($date_format['txt_full'], ($_SESSION["champdatefin"])));//textual date + $_SESSION['form']->champdatefin = time() + (86400 * $config['default_poll_duration']); //60 sec * 60 min * 24 hours * config // Summary $summary = '
    '; - for ($i=0;$igetChoices() as $choice) { - preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/',$_SESSION['choices'][$i],$md_a_img); // Markdown [![alt](src)](href) - preg_match_all('/!\[(.*?)\]\((.*?)\)/',$_SESSION['choices'][$i],$md_img); // Markdown ![alt](src) - preg_match_all('/\[(.*?)\]\((.*?)\)/',$_SESSION['choices'][$i],$md_a); // Markdown [text](href) + 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) if (isset($md_a_img[2][0]) && $md_a_img[2][0]!='' && isset($md_a_img[3][0]) && $md_a_img[3][0]!='') { // [![alt](src)](href) $li_subject_text = (isset($md_a_img[1][0]) && $md_a_img[1][0]!='') ? stripslashes($md_a_img[1][0]) : _("Choice") .' '.($i+1); @@ -120,7 +129,7 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp } else { // text only - $li_subject_text = stripslashes($_SESSION['choices'][$i]); + $li_subject_text = stripslashes($choice->getName()); $li_subject_html = $li_subject_text; } @@ -129,6 +138,8 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp } $summary .= '
'; + $end_date_str = utf8_encode(strftime('%d/%M/%Y', $_SESSION['form']->champdatefin));//textual date + echo '
@@ -138,13 +149,13 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp '. $summary .'
-

' . _("Your poll will be automatically removed after"). " " . $config['default_poll_duration'] . " " . _("days") . ': '.$removal_date.'.
' . _("You can fix another removal date for it.") .'

+

' . _('Your poll will be automatically removed after'). ' ' . $config['default_poll_duration'] . ' ' . _('days') . '.
' . _("You can fix another removal date for it.") .'

- +
'. _("(dd/mm/yyyy)") .' @@ -168,10 +179,10 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp bandeau_pied(); - // Step 2/3 : Select choices of the poll + // Step 2/4 : Select choices of the poll } else { - Utils::print_header( _("Poll subjects (2 on 3)")); - bandeau_titre(_("Poll subjects (2 on 3)")); + Utils::print_header( _('Poll subjects (2 on 3)')); + bandeau_titre(_('Poll subjects (2 on 3)')); echo ' @@ -187,16 +198,17 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp echo '
'."\n"; // Fields choices : 5 by default - $nb_choices = (isset($_SESSION['choices'])) ? max(count($_SESSION['choices']), 5) : 5; + $choices = $_SESSION['form']->getChoices(); + $nb_choices = max(count($choices), 5); for ($i = 0; $i < $nb_choices; $i++) { - $choice_value = (isset($_SESSION['choices'][$i])) ? str_replace("\\","",$_SESSION['choices'][$i]) : ''; + $choice = isset($choices[$i]) ? $choices[$i] : new Choice(); echo '
- +
- '; + '; if($config['user_can_add_img_or_link']){ - echo ' '; + echo ' '; } echo '
@@ -206,8 +218,8 @@ if (Utils::issetAndNoEmpty('titre', $_SESSION) === false || Utils::issetAndNoEmp echo '
- - + +
diff --git a/choix_date.php b/choix_date.php index 200b8a9..99f5a5b 100644 --- a/choix_date.php +++ b/choix_date.php @@ -28,7 +28,7 @@ if (is_readable('bandeaux_local.php')) { include_once('bandeaux.php'); } -// Step 1/3 : error if $_SESSION from info_sondage are not valid +// Step 1/4 : error if $_SESSION from info_sondage are not valid if (!isset($_SESSION['form']->titre) || !isset($_SESSION['form']->nom) || (($config['use_smtp']) ? !isset($_SESSION['form']->adresse) : false)) { Utils::print_header ( _("Error!") ); @@ -39,6 +39,7 @@ if (!isset($_SESSION['form']->titre) || !isset($_SESSION['form']->nom) || (($con

' . _("You haven't filled the first section of the poll creation.") . ' !

' . _("Back to the homepage of ") . ' ' . '' . NOMAPPLICATION . '.

'; + bandeau_pied(); @@ -66,6 +67,7 @@ if (!isset($_SESSION['form']->titre) || !isset($_SESSION['form']->nom) || (($con $_SESSION['form']->champdatefin=end($temp_results)+(86400 * $config['default_poll_duration']); } + // Insert poll in database $admin_poll_id = ajouter_sondage( $_SESSION['form']->titre, $_SESSION['form']->commentaires, diff --git a/infos_sondage.php b/infos_sondage.php index dc773bf..58e00d8 100644 --- a/infos_sondage.php +++ b/infos_sondage.php @@ -57,7 +57,7 @@ $erreur_injection_nom = false; $erreur_injection_commentaires = false; #tests -if (Utils::issetAndNoEmpty("poursuivre")){ +if (!empty($_POST['poursuivre'])){ $_SESSION['form']->titre = $titre; $_SESSION['form']->nom = $nom; $_SESSION['form']->adresse = $adresse; @@ -140,7 +140,7 @@ $errors = array( ) ); -if (!$_SESSION['form']->titre && Utils::issetAndNoEmpty("poursuivre") ) { +if (!$_SESSION['form']->titre && !empty($_POST['poursuivre'])) { $errors['title']['aria'] = 'aria-describeby="poll_title_error" '; $errors['title']['class'] = ' has-error'; $errors['title']['msg'] = '

' . _("Enter a title") . '

'; } elseif ($erreur_injection_titre) { @@ -153,7 +153,7 @@ if ($erreur_injection_commentaires) { $errors['description']['msg'] = '

' . _("Characters < > and \" are not permitted") . '

'; } -if (!$_SESSION['form']->nom && Utils::issetAndNoEmpty("poursuivre")) { +if (!$_SESSION['form']->nom && !empty($_POST['poursuivre'])) { $errors['name']['aria'] = 'aria-describeby="poll_name_error" '; $errors['name']['class'] = ' has-error'; $errors['name']['msg'] = '

' . _("Enter a name") . '

'; } elseif ($erreur_injection_nom) { @@ -161,10 +161,10 @@ if (!$_SESSION['form']->nom && Utils::issetAndNoEmpty("poursuivre")) { $errors['name']['msg'] = '

' . _("Characters < > and \" are not permitted") . '

'; } -if (!$_SESSION['form']->adresse && Utils::issetAndNoEmpty("poursuivre")) { +if (!$_SESSION['form']->adresse && !empty($_POST['poursuivre'])) { $errors['email']['aria'] = 'aria-describeby="poll_name_error" '; $errors['email']['class'] = ' has-error'; $errors['email']['msg'] = '

' . _("Enter an email address") . '

'; -} elseif ($erreur_adresse && Utils::issetAndNoEmpty("poursuivre")) { +} elseif ($erreur_adresse && !empty($_POST['poursuivre'])) { $errors['email']['aria'] = 'aria-describeby="poll_email_error" '; $errors['email']['class'] = ' has-error'; $errors['email']['msg'] = '

' . _("The address is not correct! You should enter a valid email address (like r.stallman@outlock.com) in order to receive the link to your poll.") . '

'; }