2011-05-15 01:32:47 +02:00
< ? php
2014-09-04 17:52:18 +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 - B_V1 - en . txt
*
* Authors of STUdS ( initial project ) : Guilhem BORGHESI ( borghesi @ unistra . fr ) and Raphaël DROZ
* Authors of Framadate / OpenSondate : Framasoft ( https :// github . com / framasoft )
*
2014-07-04 11:21:31 +02:00
* =============================
2014-09-04 17:52:18 +02:00
*
* 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 - B_V1 - fr . txt
*
2014-07-04 11:21:31 +02:00
* Auteurs de STUdS ( projet initial ) : Guilhem BORGHESI ( borghesi @ unistra . fr ) et Raphaël DROZ
2014-09-04 17:52:18 +02:00
* Auteurs de Framadate / OpenSondage : Framasoft ( https :// github . com / framasoft )
*/
namespace Framadate ;
2011-05-15 01:32:47 +02:00
2014-09-04 17:52:18 +02:00
include_once __DIR__ . '/app/inc/init.php' ;
2015-01-03 17:29:57 +01:00
2015-01-17 16:20:42 +01:00
function fromPostOrEmpty ( $postKey ) {
return isset ( $_POST [ $postKey ]) ? Utils :: htmlEscape ( $_POST [ $postKey ]) : '' ;
}
2014-12-03 21:08:08 +01:00
if ( ! isset ( $_SESSION [ 'form' ])) {
$_SESSION [ 'form' ] = new Form ();
}
2014-09-04 17:52:18 +02:00
2011-05-15 03:56:54 +02:00
if ( file_exists ( 'bandeaux_local.php' )) {
2014-09-04 17:52:18 +02:00
include_once ( 'bandeaux_local.php' );
2011-05-15 03:56:54 +02:00
} else {
2014-09-04 17:52:18 +02:00
include_once ( 'bandeaux.php' );
}
2014-12-03 21:08:08 +01:00
// Type de sondage : <button value="$_SESSION['form']->choix_sondage">
2014-09-04 17:52:18 +02:00
if (( isset ( $_GET [ 'choix_sondage' ]) && $_GET [ 'choix_sondage' ] == 'date' ) ||
( isset ( $_POST [ " choix_sondage " ]) && $_POST [ " choix_sondage " ] == 'creation_sondage_date' )) {
$choix_sondage = " creation_sondage_date " ;
2014-12-03 21:08:08 +01:00
$_SESSION [ 'form' ] -> choix_sondage = $choix_sondage ;
2014-09-04 17:52:18 +02:00
} else {
$choix_sondage = " creation_sondage_autre " ;
2014-12-03 21:08:08 +01:00
$_SESSION [ 'form' ] -> choix_sondage = $choix_sondage ;
2011-05-15 03:56:54 +02:00
}
2011-05-15 01:32:47 +02:00
2015-01-05 23:30:47 +01:00
// We clean the data
$poursuivre = filter_input ( INPUT_POST , 'poursuivre' , FILTER_VALIDATE_REGEXP , [ 'options' => [ 'regexp' => '/^(creation_sondage_date|creation_sondage_autre)$/' ]]);
2015-01-17 16:20:42 +01:00
$title = filter_input ( INPUT_POST , 'title' , FILTER_SANITIZE_STRING );
2015-01-17 01:22:03 +01:00
$name = filter_input ( INPUT_POST , 'name' , FILTER_VALIDATE_REGEXP , [ 'options' => [ 'regexp' => NAME_REGEX ]]);
2015-01-17 16:20:42 +01:00
$mail = filter_input ( INPUT_POST , 'mail' , FILTER_VALIDATE_EMAIL );
$description = filter_input ( INPUT_POST , 'description' , FILTER_SANITIZE_STRING );
2015-01-17 01:22:03 +01:00
$editable = filter_input ( INPUT_POST , 'editable' , FILTER_VALIDATE_REGEXP , [ 'options' => [ 'regexp' => BOOLEAN_REGEX ]]);
$receiveNewVotes = filter_input ( INPUT_POST , 'receiveNewVotes' , FILTER_VALIDATE_REGEXP , [ 'options' => [ 'regexp' => BOOLEAN_REGEX ]]);
$receiveNewComments = filter_input ( INPUT_POST , 'receiveNewComments' , FILTER_VALIDATE_REGEXP , [ 'options' => [ 'regexp' => BOOLEAN_REGEX ]]);
2015-01-05 23:30:47 +01:00
2011-05-15 05:03:10 +02:00
// On initialise également les autres variables
2015-01-17 16:20:42 +01:00
$error_on_mail = false ;
$error_on_title = false ;
$error_on_name = false ;
$error_on_description = false ;
2011-05-15 05:03:10 +02:00
2011-05-15 01:32:47 +02:00
#tests
2015-01-17 16:20:42 +01:00
if ( ! empty ( $_POST [ 'poursuivre' ])) {
2015-01-17 01:22:03 +01:00
$_SESSION [ 'form' ] -> title = $title ;
$_SESSION [ 'form' ] -> admin_name = $name ;
2015-01-17 16:20:42 +01:00
$_SESSION [ 'form' ] -> admin_mail = $mail ;
2015-01-17 01:22:03 +01:00
$_SESSION [ 'form' ] -> description = $description ;
2014-12-05 01:08:38 +01:00
$_SESSION [ 'form' ] -> editable = ( $editable !== null ) ? true : false ;
$_SESSION [ 'form' ] -> receiveNewVotes = ( $receiveNewVotes !== null ) ? true : false ;
2015-01-17 01:22:03 +01:00
$_SESSION [ 'form' ] -> receiveNewComments = ( $receiveNewComments !== null ) ? true : false ;
2014-09-04 17:52:18 +02:00
2015-01-17 16:20:42 +01:00
if ( $config [ 'use_smtp' ] == true ) {
if ( empty ( $mail )) {
$error_on_mail = true ;
2014-11-14 17:35:22 +01:00
}
}
2013-03-05 10:58:01 +01:00
2015-01-17 16:20:42 +01:00
if ( $title !== $_POST [ 'title' ]) {
$error_on_title = true ;
2013-03-05 10:58:01 +01:00
}
2014-09-04 17:52:18 +02:00
2015-01-17 16:20:42 +01:00
if ( $name !== $_POST [ 'name' ]) {
$error_on_name = true ;
2013-03-05 10:58:01 +01:00
}
2015-01-17 16:20:42 +01:00
if ( $description !== $_POST [ 'description' ]) {
$error_on_description = true ;
2013-03-05 10:58:01 +01:00
}
2014-09-04 17:52:18 +02:00
// Si pas d'erreur dans l'adresse alors on change de page vers date ou autre
2015-01-17 16:20:42 +01:00
if ( $config [ 'use_smtp' ] == true ) {
$email_OK = $mail && ! $error_on_mail ;
} else {
2014-11-14 17:35:22 +01:00
$email_OK = true ;
}
2015-01-17 16:20:42 +01:00
if ( $title && $name && $email_OK && ! $error_on_title && ! $error_on_description && ! $error_on_name ) {
2014-09-04 17:52:18 +02:00
2015-01-17 01:22:03 +01:00
if ( $poursuivre == 'creation_sondage_date' ) {
header ( 'Location:choix_date.php' );
2014-09-04 17:52:18 +02:00
exit ();
}
2013-03-05 10:58:01 +01:00
2015-01-17 01:22:03 +01:00
if ( $poursuivre == 'creation_sondage_autre' ) {
header ( 'Location:choix_autre.php' );
2014-09-04 17:52:18 +02:00
exit ();
}
} else {
// Title Erreur !
2015-03-22 23:33:03 +01:00
Utils :: print_header ( __ ( 'Generic\\Error!' ) . ' - ' . __ ( 'Step 1\\Poll creation (1 on 3)' ) );
2014-09-04 17:52:18 +02:00
}
2014-06-11 19:19:17 +02:00
} else {
2014-09-04 17:52:18 +02:00
// Title OK (formulaire pas encore rempli)
2015-03-22 23:33:03 +01:00
Utils :: print_header ( __ ( 'Step 1\\Poll creation (1 on 3)' ) );
2011-05-15 01:32:47 +02:00
}
2015-03-22 23:33:03 +01:00
bandeau_titre ( __ ( 'Step 1\\Poll creation (1 on 3)' ) );
2011-05-15 01:32:47 +02:00
2014-09-04 17:52:18 +02:00
/*
* Préparation des messages d ' erreur
*/
2015-01-17 16:20:42 +01:00
$errors = array (
2014-09-04 17:52:18 +02:00
'title' => array (
'msg' => '' ,
'aria' => '' ,
'class' => ''
),
'description' => array (
'msg' => '' ,
'aria' => '' ,
'class' => ''
),
'name' => array (
'msg' => '' ,
'aria' => '' ,
'class' => ''
),
'email' => array (
'msg' => '' ,
'aria' => '' ,
'class' => ''
)
);
2015-01-17 16:20:42 +01:00
if ( ! empty ( $_POST [ 'poursuivre' ])) {
if ( empty ( $_POST [ 'title' ])) {
$errors [ 'title' ][ 'aria' ] = 'aria-describeby="poll_title_error" ' ;
$errors [ 'title' ][ 'class' ] = ' has-error' ;
2015-03-22 23:33:03 +01:00
$errors [ 'title' ][ 'msg' ] = '<div class="alert alert-danger" ><p id="poll_title_error">' . __ ( 'Error\\Enter a title' ) . '</p></div>' ;
2015-01-17 16:20:42 +01:00
} elseif ( $error_on_title ) {
$errors [ 'title' ][ 'aria' ] = 'aria-describeby="poll_title_error" ' ;
$errors [ 'title' ][ 'class' ] = ' has-error' ;
2015-03-22 23:33:03 +01:00
$errors [ 'title' ][ 'msg' ] = '<div class="alert alert-danger"><p id="poll_title_error">' . __ ( 'Error\\Something is wrong with the format' ) . '</p></div>' ;
2015-01-17 16:20:42 +01:00
}
2011-05-15 03:56:54 +02:00
2015-01-17 16:20:42 +01:00
if ( $error_on_description ) {
$errors [ 'description' ][ 'aria' ] = 'aria-describeby="poll_comment_error" ' ;
$errors [ 'description' ][ 'class' ] = ' has-error' ;
2015-03-22 23:33:03 +01:00
$errors [ 'description' ][ 'msg' ] = '<div class="alert alert-danger"><p id="poll_comment_error">' . __ ( 'Error\\Something is wrong with the format' ) . '</p></div>' ;
2015-01-17 16:20:42 +01:00
}
2011-05-15 03:56:54 +02:00
2015-01-17 16:20:42 +01:00
if ( empty ( $_POST [ 'name' ])) {
$errors [ 'name' ][ 'aria' ] = 'aria-describeby="poll_name_error" ' ;
$errors [ 'name' ][ 'class' ] = ' has-error' ;
2015-03-22 23:33:03 +01:00
$errors [ 'name' ][ 'msg' ] = '<div class="alert alert-danger"><p id="poll_name_error">' . __ ( 'Error\\Enter a name' ) . '</p></div>' ;
2015-01-17 16:20:42 +01:00
} elseif ( $error_on_name ) {
$errors [ 'name' ][ 'aria' ] = 'aria-describeby="poll_name_error" ' ;
$errors [ 'name' ][ 'class' ] = ' has-error' ;
2015-03-22 23:33:03 +01:00
$errors [ 'name' ][ 'msg' ] = '<div class="alert alert-danger"><p id="poll_name_error">' . __ ( 'Error\\Something is wrong with the format' ) . '</p></div>' ;
2015-01-17 16:20:42 +01:00
}
2011-05-15 03:56:54 +02:00
2015-01-17 16:20:42 +01:00
if ( empty ( $_POST [ 'mail' ])) {
$errors [ 'email' ][ 'aria' ] = 'aria-describeby="poll_name_error" ' ;
$errors [ 'email' ][ 'class' ] = ' has-error' ;
2015-03-22 23:33:03 +01:00
$errors [ 'email' ][ 'msg' ] = '<div class="alert alert-danger"><p id="poll_email_error">' . __ ( 'Error\\Enter an email address' ) . '</p></div>' ;
2015-01-17 16:20:42 +01:00
} elseif ( $error_on_mail ) {
$errors [ 'email' ][ 'aria' ] = 'aria-describeby="poll_email_error" ' ;
$errors [ 'email' ][ 'class' ] = ' has-error' ;
2015-03-22 23:33:03 +01:00
$errors [ 'email' ][ 'msg' ] = '<div class="alert alert-danger"><p id="poll_email_error">' . __ ( 'Error\\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.' ) . '</p></div>' ;
2015-01-17 16:20:42 +01:00
}
2011-05-15 01:32:47 +02:00
}
2014-09-04 17:52:18 +02:00
/*
* Préparation en fonction des paramètres de session
*/
2011-05-15 03:56:54 +02:00
2014-09-04 17:52:18 +02:00
// REMOTE_USER ?
2015-01-17 16:20:42 +01:00
/**
* @ return string
*/
2011-05-15 03:56:54 +02:00
2014-09-04 17:52:18 +02:00
if ( USE_REMOTE_USER && isset ( $_SERVER [ 'REMOTE_USER' ])) {
2015-01-17 16:20:42 +01:00
$input_name = '<input type="hidden" name="name" value="' . Utils :: htmlEscape ( $_POST [ 'name' ]) . '" />' . $_SESSION [ 'form' ] -> admin_name ;
$input_email = '<input type="hidden" name="mail" value="' . Utils :: htmlEscape ( $_POST [ 'mail' ]) . '">' . $_SESSION [ 'form' ] -> admin_mail ;
2014-09-04 17:52:18 +02:00
} else {
2015-01-17 16:20:42 +01:00
$input_name = '<input id="yourname" type="text" name="name" class="form-control" ' . $errors [ 'name' ][ 'aria' ] . ' value="' . fromPostOrEmpty ( 'name' ) . '" />' ;
$input_email = '<input id="email" type="text" name="mail" class="form-control" ' . $errors [ 'email' ][ 'aria' ] . ' value="' . fromPostOrEmpty ( 'mail' ) . '" />' ;
2011-05-15 01:32:47 +02:00
}
2014-09-04 17:52:18 +02:00
// Checkbox checked ?
2014-12-05 01:08:38 +01:00
if ( $_SESSION [ 'form' ] -> editable ) {
$editable = 'checked' ;
2011-05-15 03:56:54 +02:00
}
2014-12-05 01:08:38 +01:00
if ( $_SESSION [ 'form' ] -> receiveNewVotes ) {
$receiveNewVotes = 'checked' ;
2011-05-15 03:56:54 +02:00
}
2011-05-15 01:32:47 +02:00
2015-01-17 01:22:03 +01:00
if ( $_SESSION [ 'form' ] -> receiveNewComments ) {
$receiveNewComments = 'checked' ;
}
2014-12-05 01:08:38 +01:00
// Display form
2014-09-04 17:52:18 +02:00
echo '
2015-03-04 21:44:55 +01:00
< div class = " row " style = " display:none " id = " form-block " >
2014-11-06 15:20:03 +01:00
< div class = " col-md-8 col-md-offset-2 " >
2014-09-04 17:52:18 +02:00
< form name = " formulaire " id = " formulaire " action = " ' . Utils::get_server_name() . 'infos_sondage.php " method = " POST " class = " form-horizontal " role = " form " >
< div class = " alert alert-info " >
2015-03-22 23:33:03 +01:00
< p > '. __(' Step 1 \\You are in the poll creation section . ').' < br /> '.__(' Step 1 \\Required fields cannot be left blank . ') .' </ p >
2014-09-04 17:52:18 +02:00
</ div >
< div class = " form-group'. $errors['title'] ['class'].' " >
2015-03-22 23:33:03 +01:00
< label for = " poll_title " class = " col-sm-4 control-label " > ' . __(' Step 1 \\Poll title ') . ' *</ label >
2014-11-06 15:20:03 +01:00
< div class = " col-sm-8 " >
2015-01-17 16:20:42 +01:00
< input id = " poll_title " type = " text " name = " title " class = " form-control " '.$errors[' title '][' aria '].' value = " '. fromPostOrEmpty('title') .' " />
2014-09-04 17:52:18 +02:00
</ div >
</ div >
'.$errors[' title '][' msg '].'
< div class = " form-group'. $errors['description'] ['class'].' " >
2015-03-22 23:33:03 +01:00
< label for = " poll_comments " class = " col-sm-4 control-label " > '. __(' Generic\\Description ') .' </ label >
2014-11-06 15:20:03 +01:00
< div class = " col-sm-8 " >
2015-01-17 16:20:42 +01:00
< textarea id = " poll_comments " name = " description " class = " form-control " '.$errors[' description '][' aria '].' rows = " 5 " > '. fromPostOrEmpty(' description ') .' </ textarea >
2014-09-04 17:52:18 +02:00
</ div >
</ div >
'.$errors[' description '][' msg '].'
< div class = " form-group'. $errors['name'] ['class'].' " >
2015-03-22 23:33:03 +01:00
< label for = " yourname " class = " col-sm-4 control-label " > '. __(' Generic\\Your name ') .' *</ label >
2014-11-06 15:20:03 +01:00
< div class = " col-sm-8 " >
2014-09-04 17:52:18 +02:00
'.$input_name.'
</ div >
</ div >
2014-11-12 17:49:52 +01:00
'.$errors[' name '][' msg ' ];
2015-01-17 16:20:42 +01:00
if ( $config [ 'use_smtp' ] == true ) {
2014-11-14 17:35:22 +01:00
echo '
< div class = " form-group'. $errors['email'] ['class'].' " >
2015-03-22 23:33:03 +01:00
< label for = " email " class = " col-sm-4 control-label " > '. __(' Generic\\Your email address ') .' *< br />< span class = " small " > '. __(' Generic\\ ( in the format name @ mail . com ) ') .' </ span ></ label >
2014-11-14 17:35:22 +01:00
< div class = " col-sm-8 " >
'.$input_email.'
</ div >
</ div >
'.$errors[' email '][' msg ' ];
}
echo '
< div class = " form-group " >
2015-01-17 01:22:03 +01:00
< div class = " col-sm-offset-4 col-sm-8 " >
2014-09-04 17:52:18 +02:00
< div class = " checkbox " >
< label >
2015-03-22 23:33:03 +01:00
< input type = checkbox name = " editable " '.$editable.' id = " editable " > '. __(' Step 1 \\Voters can modify their vote themselves . ') .'
2014-09-04 17:52:18 +02:00
</ label >
</ div >
</ div >
2014-11-12 17:49:52 +01:00
</ div > ' ;
2015-01-17 16:20:42 +01:00
if ( $config [ 'use_smtp' ] == true ) {
2014-11-14 17:35:22 +01:00
echo ' < div class = " form-group " >
2015-01-17 01:22:03 +01:00
< div class = " col-sm-offset-4 col-sm-8 " >
< div class = " checkbox " >
< label >
2015-03-22 23:33:03 +01:00
< input type = checkbox name = " receiveNewVotes " '.$receiveNewVotes.' id = " receiveNewVotes " > '. __(' Step 1 \\To receive an email for each new vote . ') .'
2015-01-17 01:22:03 +01:00
</ label >
</ div >
</ div >
</ div > ' ;
echo ' < div class = " form-group " >
< div class = " col-sm-offset-4 col-sm-8 " >
2014-11-14 17:35:22 +01:00
< div class = " checkbox " >
< label >
2015-03-22 23:33:03 +01:00
< input type = checkbox name = " receiveNewComments " '.$receiveNewComments.' id = " receiveNewComments " > '. __(' Step 1 \\To receive an email for each new comment . ') .'
2014-11-14 17:35:22 +01:00
</ label >
</ div >
</ div >
</ div > ' ;
}
echo '
< p class = " text-right " >
2014-09-04 17:52:18 +02:00
< input type = " hidden " name = " choix_sondage " value = " '. $choix_sondage .' " />
2015-03-22 23:33:03 +01:00
< button name = " poursuivre " value = " '. $choix_sondage .' " type = " submit " class = " btn btn-success " title = " '. __('Step 1 \\ Go to step 2') . ' " > '. __(' Generic\\Next ') . ' </ button >
2014-09-04 17:52:18 +02:00
</ p >
2015-01-17 01:22:03 +01:00
< script type = " text/javascript " > document . formulaire . title . focus (); </ script >
2014-09-04 17:52:18 +02:00
</ form >
</ div >
2015-03-04 23:35:03 +01:00
</ div >
2015-03-04 21:44:55 +01:00
< noscript >
< div class = " alert alert-danger " > ' .
2015-03-22 23:33:03 +01:00
__ ( 'Step 1\\Javascript is disabled on your browser. Its activation is required to create a poll.' )
2015-03-04 21:44:55 +01:00
. ' </ div >
</ noscript >
2015-03-04 23:35:03 +01:00
< div id = " cookie-warning " class = " alert alert-danger " style = " display:none " > ' .
2015-03-22 23:33:03 +01:00
__ ( 'Step 1\\Cookies are disabled on your browser. Theirs activation is required to create a poll.' )
2015-03-04 23:35:03 +01:00
. ' </ div >
' ;
echo '
< script >
// Check Javascript is enabled, if it is it will execute this script
( function () {
// Check cookies are enabled too
var cookieEnabled = function () {
var cookieEnabled = navigator . cookieEnabled ;
// if not IE4+ nor NS6+
if ( ! cookieEnabled && typeof navigator . cookieEnabled === " undefined " ){
document . cookie = " testcookie "
cookieEnabled = document . cookie . indexOf ( " testcookie " ) != - 1 ;
}
return cookieEnabled ;
}
if ( cookieEnabled ()) {
// Show the form block
document . getElementById ( " form-block " ) . setAttribute ( " style " , " " );
} else {
// Show the warning about cookies
document . getElementById ( " cookie-warning " ) . setAttribute ( " style " , " " );
}
})();
</ script >
2015-03-04 21:44:55 +01:00
' ;
2011-05-15 01:32:47 +02:00
bandeau_pied ();