Smartysize infos_creation, and rename it to create_poll

This commit is contained in:
Olivier PEREZ 2015-03-29 22:13:22 +02:00
parent a2f2118087
commit da2cdeda12
11 changed files with 407 additions and 14 deletions

View File

@ -182,4 +182,8 @@ class Utils {
return $cleaned; return $cleaned;
} }
public static function fromPostOrEmpty($postKey) {
return !empty($_POST[$postKey]) ? Utils::htmlEscape($_POST[$postKey]) : '';
}
} }

View File

@ -81,9 +81,9 @@ $config = [
'show_what_is_that' => true, // display "how to use" section 'show_what_is_that' => true, // display "how to use" section
'show_the_software' => true, // display technical information about the software 'show_the_software' => true, // display technical information about the software
'show_cultivate_your_garden' => true, // display "developpement and administration" information 'show_cultivate_your_garden' => true, // display "developpement and administration" information
/* choix_autre.php / choix_date.php */ /* create_classic_poll.php / create_date_poll.php */
'default_poll_duration' => 180, // default values for the new poll duration (number of days). 'default_poll_duration' => 180, // default values for the new poll duration (number of days).
/* choix_autre.php */ /* create_classic_poll.php */
'user_can_add_img_or_link' => true, // user can add link or URL when creating his poll. 'user_can_add_img_or_link' => true, // user can add link or URL when creating his poll.
]; ];

View File

@ -39,7 +39,7 @@ if (isset($_POST['lang']) && is_string($_POST['lang']) && in_array($_POST['lang'
$html_lang = substr($locale, 0, 2); $html_lang = substr($locale, 0, 2);
/* Date Format */ /* Date Format */
$date_format['txt_full'] = __('Date\\FULL'); //summary in choix_date.php and removal date in choix_(date|autre).php $date_format['txt_full'] = __('Date\\FULL'); //summary in create_date_poll.php and removal date in choix_(date|autre).php
$date_format['txt_short'] = __('Date\\SHORT'); // radio title $date_format['txt_short'] = __('Date\\SHORT'); // radio title
$date_format['txt_day'] = __('Date\\DAY'); $date_format['txt_day'] = __('Date\\DAY');
$date_format['txt_date'] = __('Date\\DATE'); $date_format['txt_date'] = __('Date\\DATE');

View File

@ -180,7 +180,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
$end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_time)); //textual date $end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_time)); //textual date
echo ' echo '
<form name="formulaire" action="' . Utils::get_server_name() . 'choix_autre.php" method="POST" class="form-horizontal" role="form"> <form name="formulaire" action="' . Utils::get_server_name() . 'create_classic_poll.php" method="POST" class="form-horizontal" role="form">
<div class="row"> <div class="row">
<div class="col-md-8 col-md-offset-2"> <div class="col-md-8 col-md-offset-2">
<div class="well summary"> <div class="well summary">
@ -224,7 +224,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
bandeau_titre(__('Step 2 classic\\Poll subjects (2 on 3)')); bandeau_titre(__('Step 2 classic\\Poll subjects (2 on 3)'));
echo ' echo '
<form name="formulaire" action="' . Utils::get_server_name() . 'choix_autre.php" method="POST" class="form-horizontal" role="form"> <form name="formulaire" action="' . Utils::get_server_name() . 'create_classic_poll.php" method="POST" class="form-horizontal" role="form">
<div class="row"> <div class="row">
<div class="col-md-8 col-md-offset-2">'; <div class="col-md-8 col-md-offset-2">';
echo ' echo '

View File

@ -178,7 +178,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
$end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_time)); //textual date $end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_time)); //textual date
echo ' echo '
<form name="formulaire" action="' . Utils::get_server_name() . 'choix_date.php" method="POST" class="form-horizontal" role="form"> <form name="formulaire" action="' . Utils::get_server_name() . 'create_date_poll.php" method="POST" class="form-horizontal" role="form">
<div class="row" id="selected-days"> <div class="row" id="selected-days">
<div class="col-md-8 col-md-offset-2"> <div class="col-md-8 col-md-offset-2">
<h3>'. __('Step 3\\Confirm the creation of your poll') .'</h3> <h3>'. __('Step 3\\Confirm the creation of your poll') .'</h3>
@ -222,7 +222,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
bandeau_titre(__('Step 2 date\\Poll dates (2 on 3)')); bandeau_titre(__('Step 2 date\\Poll dates (2 on 3)'));
echo ' echo '
<form name="formulaire" action="' . Utils::get_server_name() . 'choix_date.php" method="POST" class="form-horizontal" role="form"> <form name="formulaire" action="' . Utils::get_server_name() . 'create_date_poll.php" method="POST" class="form-horizontal" role="form">
<div class="row" id="selected-days"> <div class="row" id="selected-days">
<div class="col-md-10 col-md-offset-1"> <div class="col-md-10 col-md-offset-1">
<h3>'. __('Step 2 date\\Choose the dates of your poll') .'</h3> <h3>'. __('Step 2 date\\Choose the dates of your poll') .'</h3>

210
create_poll.php Normal file
View File

@ -0,0 +1,210 @@
<?php
/**
* 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)
*
* =============================
*
* 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
*
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
use Framadate\Form;
use Framadate\Utils;
include_once __DIR__ . '/app/inc/init.php';
const GO_TO_STEP_2 = 'gotostep2';
if (!isset($_SESSION['form'])) {
$_SESSION['form'] = new Form();
}
// Type de sondage
if (isset($_GET['type']) && $_GET['type'] == 'date' ||
isset($_POST['type']) && $_POST['type'] == 'date'
) {
$poll_type = 'date';
$_SESSION['form']->choix_sondage = $poll_type;
} else {
$poll_type = 'classic';
$_SESSION['form']->choix_sondage = $poll_type;
}
// We clean the data
$goToStep2 = filter_input(INPUT_POST, GO_TO_STEP_2, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^(date|classic)$/']]);
$title = filter_input(INPUT_POST, 'title', FILTER_SANITIZE_STRING);
$name = filter_input(INPUT_POST, 'name', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => NAME_REGEX]]);
$mail = filter_input(INPUT_POST, 'mail', FILTER_VALIDATE_EMAIL);
$description = filter_input(INPUT_POST, 'description', FILTER_SANITIZE_STRING);
$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]]);
// On initialise également les autres variables
$error_on_mail = false;
$error_on_title = false;
$error_on_name = false;
$error_on_description = false;
//
if (!empty($_POST[GO_TO_STEP_2])) {
$_SESSION['form']->title = $title;
$_SESSION['form']->admin_name = $name;
$_SESSION['form']->admin_mail = $mail;
$_SESSION['form']->description = $description;
$_SESSION['form']->editable = ($editable !== null);
$_SESSION['form']->receiveNewVotes = ($receiveNewVotes !== null);
$_SESSION['form']->receiveNewComments = ($receiveNewComments !== null);
if ($config['use_smtp'] == true) {
if (empty($mail)) {
$error_on_mail = true;
}
}
if ($title !== $_POST['title']) {
$error_on_title = true;
}
if ($name !== $_POST['name']) {
$error_on_name = true;
}
if ($description !== $_POST['description']) {
$error_on_description = true;
}
// Si pas d'erreur dans l'adresse alors on change de page vers date ou autre
if ($config['use_smtp'] == true) {
$email_OK = $mail && !$error_on_mail;
} else {
$email_OK = true;
}
if ($title && $name && $email_OK && !$error_on_title && !$error_on_description && !$error_on_name) {
if ($goToStep2 == 'date') {
header('Location:create_date_poll.php');
exit();
}
if ($goToStep2 == 'classic') {
header('Location:create_classic_poll.php');
exit();
}
} else {
// Title Erreur !
$title = __('Generic', 'Error!') . ' - ' . __('Step 1', 'Poll creation (1 on 3)');
}
} else {
// Title OK (formulaire pas encore rempli)
$title = __('Step 1', 'Poll creation (1 on 3)');
}
// Prepare error messages
$errors = array(
'title' => array(
'msg' => '',
'aria' => '',
'class' => ''
),
'description' => array(
'msg' => '',
'aria' => '',
'class' => ''
),
'name' => array(
'msg' => '',
'aria' => '',
'class' => ''
),
'email' => array(
'msg' => '',
'aria' => '',
'class' => ''
)
);
// TODO Move it to TPL
if (!empty($_POST[GO_TO_STEP_2])) {
if (empty($_POST['title'])) {
$errors['title']['aria'] = 'aria-describeby="poll_title_error" ';
$errors['title']['class'] = ' has-error';
$errors['title']['msg'] = __('Error', 'Enter a title');
} elseif ($error_on_title) {
$errors['title']['aria'] = 'aria-describeby="poll_title_error" ';
$errors['title']['class'] = ' has-error';
$errors['title']['msg'] = __('Error', 'Something is wrong with the format');
}
if ($error_on_description) {
$errors['description']['aria'] = 'aria-describeby="poll_comment_error" ';
$errors['description']['class'] = ' has-error';
$errors['description']['msg'] = __('Error', 'Something is wrong with the format');
}
if (empty($_POST['name'])) {
$errors['name']['aria'] = 'aria-describeby="poll_name_error" ';
$errors['name']['class'] = ' has-error';
$errors['name']['msg'] = __('Error', 'Enter a name');
} elseif ($error_on_name) {
$errors['name']['aria'] = 'aria-describeby="poll_name_error" ';
$errors['name']['class'] = ' has-error';
$errors['name']['msg'] = __('Error', 'Something is wrong with the format');
}
if (empty($_POST['mail'])) {
$errors['email']['aria'] = 'aria-describeby="poll_name_error" ';
$errors['email']['class'] = ' has-error';
$errors['email']['msg'] = __('Error', 'Enter an email address');
} elseif ($error_on_mail) {
$errors['email']['aria'] = 'aria-describeby="poll_email_error" ';
$errors['email']['class'] = ' has-error';
$errors['email']['msg'] = __('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.');
}
}
// Checkbox checked ?
if ($_SESSION['form']->editable) {
$editable = 'checked';
}
if ($_SESSION['form']->receiveNewVotes) {
$receiveNewVotes = 'checked';
}
if ($_SESSION['form']->receiveNewComments) {
$receiveNewComments = 'checked';
}
$useRemoteUser = USE_REMOTE_USER && isset($_SERVER['REMOTE_USER']);
$smarty->assign('title', $title);
$smarty->assign('useRemoteUser', $useRemoteUser);
$smarty->assign('errors', $errors);
$smarty->assign('use_smtp', $config['use_smtp']);
$smarty->assign('goToStep2', GO_TO_STEP_2);
$smarty->assign('poll_type', $poll_type);
$smarty->assign('poll_title', Utils::fromPostOrEmpty('title'));
$smarty->assign('poll_description', Utils::fromPostOrEmpty('description'));
$smarty->assign('poll_name', Utils::fromPostOrEmpty('name'));
$smarty->assign('poll_mail', Utils::fromPostOrEmpty('mail'));
$smarty->assign('poll_editable', Utils::fromPostOrEmpty('editable'));
$smarty->assign('poll_receiveNewVotes', Utils::fromPostOrEmpty('receiveNewVotes'));
$smarty->assign('poll_receiveNewComments', Utils::fromPostOrEmpty('receiveNewComments'));
$smarty->assign('form', $_SESSION['form']);
$smarty->display('create_poll.tpl');

View File

@ -67,7 +67,7 @@ function ajouter_sondage()
} }
$sondage_admin = $sondage.random(8); $sondage_admin = $sondage.random(8);
$date_fin = $_SESSION["champdatefin"]; // provided by choix_autre.php or choix_date.php $date_fin = $_SESSION["champdatefin"]; // provided by create_classic_poll.php or create_date_poll.php
$_SESSION["champdatefin"]=""; //clean param cause 2 polls created by the same user in the same session can be affected by this param during the 2nd creation. $_SESSION["champdatefin"]=""; //clean param cause 2 polls created by the same user in the same session can be affected by this param during the 2nd creation.
$sql = 'INSERT INTO sondage $sql = 'INSERT INTO sondage
(id_sondage, commentaires, mail_admin, nom_admin, titre, id_sondage_admin, date_fin, format, mailsonde) (id_sondage, commentaires, mail_admin, nom_admin, titre, id_sondage_admin, date_fin, format, mailsonde)

View File

@ -320,7 +320,7 @@ table.results .btn-link.btn-sm {
box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.125) inset; box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.125) inset;
} }
/* choix_date.php */ /* create_date_poll.php */
#selected-days .form-group { #selected-days .form-group {
margin-left:0; margin-left:0;
margin-right:0; margin-right:0;
@ -346,7 +346,7 @@ table.results .btn-link.btn-sm {
border:none; border:none;
background:transparent; background:transparent;
} }
/* choix_autre.php */ /* create_classic_poll.php */
.md-a-img { .md-a-img {
text-decoration:none !important; text-decoration:none !important;
} }

View File

@ -99,12 +99,12 @@ if (!empty($_POST['poursuivre'])) {
if ($title && $name && $email_OK && ! $error_on_title && ! $error_on_description && ! $error_on_name) { if ($title && $name && $email_OK && ! $error_on_title && ! $error_on_description && ! $error_on_name) {
if ( $poursuivre == 'creation_sondage_date' ) { if ( $poursuivre == 'creation_sondage_date' ) {
header('Location:choix_date.php'); header('Location:create_date_poll.php');
exit(); exit();
} }
if ( $poursuivre == 'creation_sondage_autre' ) { if ( $poursuivre == 'creation_sondage_autre' ) {
header('Location:choix_autre.php'); header('Location:create_classic_poll.php');
exit(); exit();
} }

179
tpl/create_poll.tpl Normal file
View File

@ -0,0 +1,179 @@
{extends file='page.tpl'}
{block name=main}
<div class="row" style="display:none" id="form-block">
<div class="col-md-8 col-md-offset-2">
<form name="formulaire" id="formulaire" action="" method="POST" class="form-horizontal" role="form">
<div class="alert alert-info">
<p>
{__('Step 1', 'You are in the poll creation section.')}<br/>
{__('Step 1', 'Required fields cannot be left blank.')}
</p>
</div>
<div class="form-group '.$errors['title']['class'].'">
<label for="poll_title" class="col-sm-4 control-label">{__('Step 1', 'Poll title')} *</label>
<div class="col-sm-8">
<input id="poll_title" type="text" name="title" class="form-control" {$errors['title']['aria']}
value="{$poll_title}"/>
</div>
</div>
{if !empty($errors['title']['msg'])}
<div class="alert alert-danger">
<p id="poll_title_error">
{$errors['title']['msg']}
</p>
</div>
{/if}
<div class="form-group '.$errors['description']['class'].'">
<label for="poll_comments" class="col-sm-4 control-label">{__('Generic', 'Description')}</label>
<div class="col-sm-8">
<textarea id="poll_comments" name="description"
class="form-control" {$errors['description']['aria']}
rows="5">{$poll_description}</textarea>
</div>
</div>
{if !empty($errors['description']['msg'])}
<div class="alert alert-danger">
<p id="poll_title_error">
{$errors['description']['msg']}
</p>
</div>
{/if}
<div class="form-group '.$errors['name']['class'].'">
<label for="yourname" class="col-sm-4 control-label">{__('Generic', 'Your name')} *</label>
<div class="col-sm-8">
{if $useRemoteUser}
<input type="hidden" name="name" value="{$form->admin_name}" />{$form->admin_name}
{else}
<input id="yourname" type="text" name="name" class="form-control" {$errors['name']['aria']} value="{$poll_name}" />
{/if}
</div>
</div>
{if !empty($errors['name']['msg'])}
<div class="alert alert-danger">
<p id="poll_title_error">
{$errors['name']['msg']}
</p>
</div>
{/if}
{if $use_smtp}
<div class="form-group '.$errors['email']['class'].'">
<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>
<div class="col-sm-8">
{if $useRemoteUser}
<input type="hidden" name="mail" value="{$form->admin_mail}">{$form->admin_mail}
{else}
<input id="email" type="text" name="mail" class="form-control" {$errors['email']['aria']} value="{$poll_mail}" />
{/if}
</div>
</div>
{if !empty($errors['email']['msg'])}
<div class="alert alert-danger">
<p id="poll_title_error">
{$errors['email']['msg']}
</p>
</div>
{/if}
{/if}
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<div class="checkbox">
<label>
<input type=checkbox name="editable" {if $poll_editable}checked{/if} id="editable">
{__('Step 1', 'Voters can modify their vote themselves.')}
</label>
</div>
</div>
</div>
{if $use_smtp}
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<div class="checkbox">
<label>
<input type=checkbox name="receiveNewVotes" {if $poll_receiveNewVotes}checked{/if}
id="receiveNewVotes">
{__('Step 1', 'To receive an email for each new vote.')}
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<div class="checkbox">
<label>
<input type=checkbox name="receiveNewComments" {if $poll_receiveNewComments}checked{/if}
id="receiveNewComments">
{__('Step 1', 'To receive an email for each new comment.')}
</label>
</div>
</div>
</div>
{/if}
<p class="text-right">
<input type="hidden" name="type" value="$poll_type"/>
<button name="{$goToStep2}" value="{$poll_type}" type="submit"
class="btn btn-success">{__('Step 1', 'Go to step 2')}</button>
</p>
<script type="text/javascript">document.formulaire.title.focus();</script>
</form>
</div>
</div>
<noscript>
<div class="alert alert-danger">
{__('Step 1', 'Javascript is disabled on your browser. Its activation is required to create a poll.')}
</div>
</noscript>
<div id="cookie-warning" class="alert alert-danger" style="display:none">
{__('Step 1', 'Cookies are disabled on your browser. Theirs activation is required to create a poll.')}
</div>
<script>
{* TODO Put this in a JS file *}
// 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>
{/block}

View File

@ -4,7 +4,7 @@
<div class="row"> <div class="row">
<div class="col-md-6 text-center"> <div class="col-md-6 text-center">
<p class="home-choice"> <p class="home-choice">
<a href="{$SERVER_URL}infos_sondage.php?choix_sondage=date" class="opacity" role="button"> <a href="{$SERVER_URL}create_poll.php?type=date" class="opacity" role="button">
<img class="img-responsive center-block" src="{'images/date.png'|resource}" alt=""/> <img class="img-responsive center-block" src="{'images/date.png'|resource}" alt=""/>
<br/> <br/>
<span class="btn btn-primary btn-lg"> <span class="btn btn-primary btn-lg">
@ -16,7 +16,7 @@
</div> </div>
<div class="col-md-6 text-center"> <div class="col-md-6 text-center">
<p class="home-choice"> <p class="home-choice">
<a href="{$SERVER_URL}infos_sondage.php?choix_sondage=autre" class="opacity" role="button"> <a href="{$SERVER_URL}create_poll.php?type=autre" class="opacity" role="button">
<img alt="" class="img-responsive center-block" src="{'images/classic.png'|resource}"/> <img alt="" class="img-responsive center-block" src="{'images/classic.png'|resource}"/>
<br/> <br/>
<span class="btn btn-info btn-lg"> <span class="btn btn-info btn-lg">