2011-05-15 01:32:47 +02:00
< ? php
2014-07-04 11:21:31 +02:00
/* This software is governed by the CeCILL - B license . If a copy of this license
* is not distributed with this file , you can obtain one at
* http :// www . cecill . info / licences / Licence_CeCILL_V2 . 1 - en . txt
*
* Authors of STUdS ( initial project ) : Guilhem BORGHESI ( borghesi @ unistra . fr ) and Raphaël DROZ
* Authors of OpenSondage : Framasoft ( https :// github . com / framasoft )
*
* =============================
*
* Ce logiciel est régi par la licence CeCILL - B . Si une copie de cette licence
* ne se trouve pas avec ce fichier vous pouvez l ' obtenir sur
* http :// www . cecill . info / licences / Licence_CeCILL_V2 . 1 - fr . txt
*
* Auteurs de STUdS ( projet initial ) : Guilhem BORGHESI ( borghesi @ unistra . fr ) et Raphaël DROZ
* Auteurs d ' OpenSondage : Framasoft ( https :// github . com / framasoft )
*/
2011-05-15 01:32:47 +02:00
session_start ();
include_once ( 'creation_sondage.php' );
2011-05-15 03:56:54 +02:00
if ( file_exists ( 'bandeaux_local.php' )) {
include_once ( 'bandeaux_local.php' );
} else {
include_once ( 'bandeaux.php' );
2011-05-15 01:32:47 +02:00
}
2011-05-15 03:56:54 +02:00
//si les variables de session ne sont pas valides, il y a une erreur
2011-05-22 04:03:44 +02:00
if ( issetAndNoEmpty ( 'titre' , $_SESSION ) === false || issetAndNoEmpty ( 'nom' , $_SESSION ) === false || issetAndNoEmpty ( 'adresse' , $_SESSION ) === false ) {
2014-06-11 19:19:17 +02:00
echo '<!DOCTYPE html>' . " \n " ;
echo '<html lang="' . $lang . '">' . " \n " ;
2011-05-15 03:56:54 +02:00
echo '<head>' . " \n " ;
2014-06-11 19:19:17 +02:00
echo '<meta charset="utf-8">' . " \n " ;
echo '<title>' . _ ( " Error! " ) . ' - ' . NOMAPPLICATION . '</title>' . " \n " ;
echo '<link rel="stylesheet" href="' . get_server_name () . '/style.css">' . " \n " ;
2011-05-15 03:56:54 +02:00
echo '</head>' . " \n " ;
echo '<body>' . " \n " ;
2011-06-23 16:52:10 +02:00
framanav ();
2011-05-15 03:56:54 +02:00
logo ();
bandeau_tete ();
bandeau_titre ( _ ( " Error! " ));
2014-06-11 19:19:17 +02:00
echo '<div class="corpscentre">' . " \n " ;
print " <h2> " . _ ( " You haven't filled the first section of the poll creation. " ) . " !</h2> " . " \n " ;
print " " . _ ( " Back to the homepage of " ) . " <a href= \" " . get_server_name () . " \" > " . NOMAPPLICATION . " </a>. " . " \n " ;
2011-05-15 03:56:54 +02:00
echo '</div>' . " \n " ;
//bandeau de pied
bandeau_pied ();
echo '</body>' . " \n " ;
echo '</html>' . " \n " ;
} else {
//partie creation du sondage dans la base SQL
//On prépare les données pour les inserer dans la base
2011-05-22 04:03:44 +02:00
$erreur = false ;
$testdate = true ;
$date_selected = '' ;
if ( isset ( $_POST [ " confirmecreation " ]) || isset ( $_POST [ " confirmecreation_x " ])) {
2011-05-15 03:56:54 +02:00
//recuperation des données de champs textes
2011-05-22 04:03:44 +02:00
$toutchoix = '' ;
for ( $i = 0 ; $i < $_SESSION [ " nbrecases " ] + 1 ; $i ++ ) {
if ( isset ( $_POST [ " choix " ]) && issetAndNoEmpty ( $i , $_POST [ " choix " ])) {
2011-05-15 03:56:54 +02:00
$toutchoix .= ',' ;
2011-05-22 04:03:44 +02:00
$toutchoix .= str_replace ( " , " , " " , htmlentities ( html_entity_decode ( $_POST [ " choix " ][ $i ], ENT_QUOTES , 'UTF-8' ), ENT_QUOTES , 'UTF-8' ));
2011-05-15 03:56:54 +02:00
}
}
$toutchoix = substr ( " $toutchoix " , 1 );
$_SESSION [ " toutchoix " ] = $toutchoix ;
2011-05-22 04:03:44 +02:00
if ( issetAndNoEmpty ( 'champdatefin' )) {
2011-05-15 03:56:54 +02:00
$registredate = explode ( " / " , $_POST [ " champdatefin " ]);
2011-05-22 04:03:44 +02:00
if ( is_array ( $registredate ) === false || count ( $registredate ) !== 3 ) {
$testdate = false ;
$date_selected = $_POST [ " champdatefin " ];
} else {
$time = mktime ( 0 , 0 , 0 , $registredate [ 1 ], $registredate [ 0 ], $registredate [ 2 ]);
if ( $time === false || date ( 'd/m/Y' , $time ) !== $_POST [ " champdatefin " ]) {
$testdate = false ;
$date_selected = $_POST [ " champdatefin " ];
} else {
if ( mktime ( 0 , 0 , 0 , $registredate [ 1 ], $registredate [ 0 ], $registredate [ 2 ]) > time () + 250000 ) {
$_SESSION [ " champdatefin " ] = mktime ( 0 , 0 , 0 , $registredate [ 1 ], $registredate [ 0 ], $registredate [ 2 ]);
}
}
2011-05-15 03:56:54 +02:00
}
} else {
$_SESSION [ " champdatefin " ] = time () + 15552000 ;
}
2011-05-22 04:03:44 +02:00
if ( $testdate === true ) {
//format du sondage AUTRE
$_SESSION [ " formatsondage " ] = " A " . $_SESSION [ " studsplus " ];
ajouter_sondage ();
2011-05-15 03:56:54 +02:00
} else {
2011-05-22 04:03:44 +02:00
$_POST [ " fin_sondage_autre " ] = 'ok' ;
2011-05-15 03:56:54 +02:00
}
}
2011-05-22 04:03:44 +02:00
// recuperation des sujets pour sondage AUTRE
$erreur_injection = false ;
if ( isset ( $_SESSION [ " nbrecases " ])) {
for ( $i = 0 ; $i < $_SESSION [ " nbrecases " ]; $i ++ ) {
if ( isset ( $_POST [ " choix " ]) && isset ( $_POST [ " choix " ][ $i ])) {
$_SESSION [ " choix $i " ] = htmlentities ( html_entity_decode ( $_POST [ " choix " ][ $i ], ENT_QUOTES , 'UTF-8' ), ENT_QUOTES , 'UTF-8' );
}
}
} else { //nombre de cases par défaut
2011-05-15 03:56:54 +02:00
$_SESSION [ " nbrecases " ] = 10 ;
}
2011-05-22 04:03:44 +02:00
if ( isset ( $_POST [ " ajoutcases " ]) || isset ( $_POST [ " ajoutcases_x " ])) {
2011-05-15 03:56:54 +02:00
$_SESSION [ " nbrecases " ] = $_SESSION [ " nbrecases " ] + 5 ;
}
2014-06-11 19:19:17 +02:00
if ( ( $testremplissage != " ok " && ( isset ( $_POST [ " fin_sondage_autre " ]) || isset ( $_POST [ " fin_sondage_autre_x " ]))) || ( $testdate === false ) || ( $erreur_injection ) ) {
// S'il y a des erreurs
2014-07-04 11:21:31 +02:00
print_header ( false , _ ( " Error! " ) . ' - ' . _ ( " Poll subjects (2 on 2) " ), $lang );
2014-06-11 19:19:17 +02:00
} else {
2014-07-04 11:21:31 +02:00
print_header ( false , _ ( " Poll subjects (2 on 2) " ), $lang );
2014-06-11 19:19:17 +02:00
}
2011-05-15 03:56:54 +02:00
echo '<body>' . " \n " ;
2011-06-23 16:52:10 +02:00
framanav ();
2011-05-15 03:56:54 +02:00
echo '<form name="formulaire" action="#bas" method="POST" onkeypress="javascript:process_keypress(event)">' . " \n " ;
logo ();
bandeau_tete ();
bandeau_titre ( _ ( " Poll subjects (2 on 2) " ));
sous_bandeau_choix ();
2014-06-11 19:19:17 +02:00
echo '<div class="corps">' . " \n " ;
2014-07-04 11:21:31 +02:00
echo '<p>' . _ ( " Your poll aim is to make a choice between different subjects. " ) . '<br />' . _ ( " Enter the subjects to vote for: " ) . '</p>' . " \n " ;
2011-05-15 03:56:54 +02:00
echo '<table>' . " \n " ;
//affichage des cases texte de formulaire
2011-05-22 04:03:44 +02:00
for ( $i = 0 ; $i < $_SESSION [ " nbrecases " ]; $i ++ ) {
$j = $i + 1 ;
if ( isset ( $_SESSION [ " choix $i " ]) === false ) {
$_SESSION [ " choix $i " ] = '' ;
}
2014-06-11 19:19:17 +02:00
echo '<tr><td><label for="choix' . $i . '">' . _ ( " Choice " ) . ' ' . $j . '</label> : </td><td><input type="text" name="choix[]" size="40" maxlength="40" value="' . str_replace ( " \\ " , " " , $_SESSION [ " choix $i " ]) . '" id="choix' . $i . '"></td></tr>' . " \n " ;
2011-05-15 03:56:54 +02:00
}
echo '</table>' . " \n " ;
//focus javascript sur premiere case
echo '<script type="text/javascript">' . " \n " ;
echo 'document.formulaire.choix0.focus();' . " \n " ;
echo '</script>' . " \n " ;
//ajout de cases supplementaires
echo '<table><tr>' . " \n " ;
2014-06-11 19:19:17 +02:00
echo '<td>' . _ ( " 5 choices more " ) . '</td><td><input type="image" alt="' . _ ( " 5 choices more " ) . '" name="ajoutcases" value="Retour" src="' . get_server_name () . 'images/add-16.png"></td>' . " \n " ;
2011-05-15 03:56:54 +02:00
echo '</tr></table>' . " \n " ;
2011-06-23 01:21:56 +02:00
//echo '<table><tr>'."\n";
//echo '<td>'. _("Next") .'</td><td><input type="image" name="fin_sondage_autre" value="Créer le sondage" src="images/next-32.png"></td>'."\n";
//echo '</tr></table>'."\n";
2013-03-14 14:30:38 +01:00
if ( ! isset ( $_POST [ " fin_sondage_autre_x " ])) {
echo '<button name="fin_sondage_autre_x" value="' . _ ( 'Next' ) . '" type="submit" class="button green poursuivre"><strong>' . _ ( 'Next' ) . '</strong> </button>' ;
echo '<div style="clear:both"></div>' ;
}
2011-05-15 03:56:54 +02:00
//test de remplissage des cases
2011-05-22 04:03:44 +02:00
$testremplissage = '' ;
2011-05-15 03:56:54 +02:00
for ( $i = 0 ; $i < $_SESSION [ " nbrecases " ]; $i ++ ) {
2011-05-22 04:03:44 +02:00
if ( isset ( $_POST [ " choix " ]) && issetAndNoEmpty ( $i , $_POST [ " choix " ])) {
2011-05-15 03:56:54 +02:00
$testremplissage = " ok " ;
}
}
//message d'erreur si aucun champ renseigné
2011-05-22 04:03:44 +02:00
if ( $testremplissage != " ok " && ( isset ( $_POST [ " fin_sondage_autre " ]) || isset ( $_POST [ " fin_sondage_autre_x " ]))) {
2014-06-11 19:19:17 +02:00
print " <p class= \" error \" > " . _ ( " Enter at least one choice " ) . " </p> " . " \n " ;
2011-05-22 04:03:44 +02:00
$erreur = true ;
}
//message d'erreur si mauvaise date
if ( $testdate === false ) {
2014-06-11 19:19:17 +02:00
print " <p class= \" error \" > " . _ ( " Date must be have the format DD/MM/YYYY " ) . " </p> " . " \n " ;
2011-05-15 03:56:54 +02:00
}
if ( $erreur_injection ) {
2014-06-11 19:19:17 +02:00
print " <p class= \" error \" > " . _ ( " Characters \" < and > are not permitted " ) . " </p> \n " ;
2011-05-15 03:56:54 +02:00
}
2011-05-22 04:03:44 +02:00
if (( isset ( $_POST [ " fin_sondage_autre " ]) || isset ( $_POST [ " fin_sondage_autre_x " ])) && ! $erreur && ! $erreur_injection ) {
2011-05-15 03:56:54 +02:00
//demande de la date de fin du sondage
echo '<div class=presentationdatefin>' . " \n " ;
2014-07-04 11:21:31 +02:00
echo '<p>' . _ ( " Your poll will be automatically removed after 6 months. " ) . '<br />' . _ ( " You can fix another removal date for it. " ) . '</p>' . " \n " ;
2014-06-11 19:19:17 +02:00
echo '<label for="champdatefin">' . _ ( " Removal date (optional) " ) . '</label> : <input type="text" class="champdatefin" id="champdatefin" aria-describedby="dateformat" name="champdatefin" value="' . $date_selected . '" size="10" maxlength="10"> <span id="dateformat">' . _ ( " (DD/MM/YYYY) " ) . '</span>' . " \n " ;
2011-05-15 03:56:54 +02:00
echo '</div>' . " \n " ;
echo '<div class=presentationdatefin>' . " \n " ;
2014-07-04 11:21:31 +02:00
echo '<p class="error">' . _ ( " Once you have confirmed the creation of your poll, you will be automatically redirected on the page of your poll. " ) . '<br /><br />' . _ ( " Then, you will receive quickly an email contening the link to your poll for sending it to the voters. " ) . '</p>' . " \n " ;
2011-05-15 03:56:54 +02:00
echo '</div>' . " \n " ;
2011-06-23 01:21:56 +02:00
//echo '<table>'."\n";
//echo '<tr><td>'. _("Create the poll") .'</td><td><input type="image" name="confirmecreation" value="Valider la création"i src="images/add.png"></td></tr>'."\n";
//echo '</table>'."\n";
2014-06-11 19:19:17 +02:00
echo '<button name="confirmecreation" value="confirmecreation" type="submit" class="button green poursuivre margin-top"><strong>' . _ ( 'Make a poll' ) . '</strong> </button>' ;
2011-06-23 01:21:56 +02:00
echo '<div style="clear:both"></div>' ;
2011-05-15 03:56:54 +02:00
}
//fin du formulaire et bandeau de pied
echo '</form>' . " \n " ;
2014-06-11 19:19:17 +02:00
echo '<a id=bas></a>' . " \n " ;
2011-05-15 03:56:54 +02:00
echo '</div>' . " \n " ;
//bandeau de pied
bandeau_pied_mobile ();
echo '</body>' . " \n " ;
echo '</html>' . " \n " ;
2014-06-11 19:19:17 +02:00
}