diff --git a/infos_sondage.php b/infos_sondage.php index 0737a8c..de89495 100644 --- a/infos_sondage.php +++ b/infos_sondage.php @@ -45,59 +45,82 @@ if (file_exists('bandeaux_local.php')) { include_once('bandeaux.php'); } +// On teste toutes les variables pour supprimer l'ensemble des warnings PHP +// On transforme en entites html les données afin éviter les failles XSS +$post_var = array('titre', 'nom', 'adresse', 'commentaires', 'studsplus', 'mailsonde', 'creation_sondage_date', 'creation_sondage_date_x', 'creation_sondage_autre', 'creation_sondage_autre_x',); +foreach ($post_var as $var) { + if (isset($_POST[$var]) === true) { + $$var = htmlentities($_POST[$var], ENT_QUOTES, 'UTF-8'); + } else { + $$var = null; + } +} + +// On initialise egalement la session car sinon bonjour les warning :-) +$session_var = array('titre', 'nom', 'adresse', 'commentaires', 'mailsonde', 'studsplus', ); +foreach ($session_var as $var) { + if (issetAndNoEmpty($var, $_SESSION) === false) { + $_SESSION[$var] = null; + } +} + +// On initialise également les autres variables +$erreur_adresse = false; +$erreur_injection_titre = false; +$erreur_injection_nom = false; +$erreur_injection_commentaires = false; +$cocheplus = ''; +$cochemail = ''; + #tests -if (($_POST["creation_sondage_date"]||$_POST["creation_sondage_autre"]||$_POST["creation_sondage_date_x"]||$_POST["creation_sondage_autre_x"])) { - $_SESSION["titre"]=$_POST["titre"]; - $_SESSION["nom"]=$_POST["nom"]; - $_SESSION["adresse"]=$_POST["adresse"]; - $_SESSION["commentaires"]=$_POST["commentaires"]; +if (issetAndNoEmpty("creation_sondage_date") || issetAndNoEmpty("creation_sondage_autre") || issetAndNoEmpty("creation_sondage_date_x") || issetAndNoEmpty("creation_sondage_autre_x")){ + $_SESSION["titre"] = $titre; + $_SESSION["nom"] = $nom; + $_SESSION["adresse"] = $adresse; + $_SESSION["commentaires"] = $commentaires; unset($_SESSION["studsplus"]); - if ($_POST["studsplus"]) { - $_SESSION["studsplus"] = '+'; + if ($studsplus !== null) { + $_SESSION["studsplus"] = '+'; + } else { + $_SESSION["studsplus"] = ''; } unset($_SESSION["mailsonde"]); - if ($_POST["mailsonde"]) { + if ($mailsonde !== null) { $_SESSION["mailsonde"] = true; + } else { + $_SESSION["mailsonde"] = false; } - if(!filter_var($_POST["adresse"], FILTER_VALIDATE_EMAIL) || strpos($_POST["adresse"], '@') === false) { + if(validateEmail($adresse) === false) { $erreur_adresse = true; } - if (preg_match(';<|>|";',$_POST["titre"])) { + if (preg_match(';<|>|";',$titre)) { $erreur_injection_titre = true; } - if (preg_match(';<|>|";',$_POST["nom"])) { + if (preg_match(';<|>|";',$nom)) { $erreur_injection_nom = true; } - if (preg_match(';<|>|";',$_POST["commentaires"])) { + if (preg_match(';<|>|";',$commentaires)) { $erreur_injection_commentaires = true; } // Si pas d'erreur dans l'adresse alors on change de page vers date ou autre - if ($_POST["titre"] && $_POST["nom"] && $_POST["adresse"] && ! $erreur_adresse && ! $erreur_injection_titre && ! $erreur_injection_commentaires && ! $erreur_injection_nom ) { - if ($_POST["creation_sondage_date"]||$_POST["creation_sondage_date_x"]) { + if ($titre && $nom && $adresse && !$erreur_adresse && ! $erreur_injection_titre && ! $erreur_injection_commentaires && ! $erreur_injection_nom) { + if ($creation_sondage_date !== null || $creation_sondage_date_x !== null) { header("Location:choix_date.php"); exit(); } - if ($_POST["creation_sondage_autre"]||$_POST["creation_sondage_autre_x"]) { + if ($creation_sondage_autre !== null || $creation_sondage_autre_x !== null) { header("Location:choix_autre.php"); exit(); } } - - //En cas d'erreur, recuperation des variables deja entrées - if (empty($_POST["titre"]) || empty($_POST["adresse"]) || empty($_POST["nom"])) { - $_SESSION["titre"]=$_POST["titre"]; - $_SESSION["nom"]=$_POST["nom"]; - $_SESSION["adresse"]=$_POST["adresse"]; - $_SESSION["commentaires"]=$_POST["commentaires"]; - } } //affichage de la page @@ -111,7 +134,7 @@ sous_bandeau(); // premier sondage ? test l'existence des schémas SQL avant d'aller plus loin if(!check_table_sondage()) { - echo '

' . + echo '

'. _("STUdS is not properly installed, please check the 'INSTALL' to setup the database before continuing") . "

"."\n"; bandeau_pied(); @@ -130,7 +153,7 @@ echo '
'. _("You are in the poll creation section.
Required fields canno echo ''."\n"; echo ''."\n"; -if (!$_SESSION["titre"]&&($_POST["creation_sondage_date"]||$_POST["creation_sondage_autre"]||$_POST["creation_sondage_date_x"]||$_POST["creation_sondage_autre_x"])) { +if (!$_SESSION["titre"] && (issetAndNoEmpty('creation_sondage_date') || issetAndNoEmpty('creation_sondage_autre') || issetAndNoEmpty('creation_sondage_date_x') || issetAndNoEmpty('creation_sondage_autre_x'))) { print ""."\n"; } elseif ($erreur_injection_titre) { print "
"."\n"; @@ -152,7 +175,7 @@ if (isset($_SERVER['REMOTE_USER'])) { echo ''."\n"; } -if (!$_SESSION["nom"]&&($_POST["creation_sondage_date"]||$_POST["creation_sondage_autre"]||$_POST["creation_sondage_date_x"]||$_POST["creation_sondage_autre_x"])) { +if (!$_SESSION["nom"] && (issetAndNoEmpty('creation_sondage_date') || issetAndNoEmpty('creation_sondage_autre') || issetAndNoEmpty('creation_sondage_date_x') || issetAndNoEmpty('creation_sondage_autre_x'))) { print ""."\n"; } elseif ($erreur_injection_nom) { print "
"."\n"; @@ -167,9 +190,9 @@ if (isset($_SERVER['REMOTE_USER'])) { echo ''."\n"; } -if (!$_SESSION["adresse"]&&($_POST["creation_sondage_date"]||$_POST["creation_sondage_autre"]||$_POST["creation_sondage_date_x"]||$_POST["creation_sondage_autre_x"])) { +if (!$_SESSION["adresse"] && (issetAndNoEmpty('creation_sondage_date') || issetAndNoEmpty('creation_sondage_autre') || issetAndNoEmpty('creation_sondage_date_x') || issetAndNoEmpty('creation_sondage_autre_x'))) { print ""."\n"; -} elseif ($erreur_adresse&&($_POST["creation_sondage_date"]||$_POST["creation_sondage_autre"]||$_POST["creation_sondage_date_x"]||$_POST["creation_sondage_autre_x"])) { +} elseif ($erreur_adresse && (issetAndNoEmpty('creation_sondage_date') || issetAndNoEmpty('creation_sondage_autre') || issetAndNoEmpty('creation_sondage_date_x') || issetAndNoEmpty('creation_sondage_autre_x'))) { print ""."\n"; } @@ -184,7 +207,7 @@ echo ''."\n"; echo '
'. _("The fields marked with * are required!") .'

'."\n"; #affichage du cochage par défaut -if (!$_SESSION["studsplus"]&&!$_POST["creation_sondage_date"]&&!$_POST["creation_sondage_autre"]&&!$_POST["creation_sondage_date_x"]&&!$_POST["creation_sondage_autre_x"]) { +if (!$_SESSION["studsplus"] && !issetAndNoEmpty('creation_sondage_date') && !issetAndNoEmpty('creation_sondage_autre') && !issetAndNoEmpty('creation_sondage_date_x') && !issetAndNoEmpty('creation_sondage_autre_x')) { $_SESSION["studsplus"]="+"; }
'. _("Poll title *: ") .'" . _("Enter a title") . "" . _("Characters < > and \" are not permitted") . "" . _("Enter a name") . "" . _("Characters < > and \" are not permitted") . "" . _("Enter an email address") . " " . _("The address is not correct! (You should enter a valid email address in order to receive the link to your poll)") . "