Merge branch 'limit-number-of-participants' into 'master'

Limit number of participants

Closes #238

See merge request framasoft/framadate!218
This commit is contained in:
Thomas Citharel 2018-02-20 16:52:32 +01:00
commit 6e1386fa4d
23 changed files with 286 additions and 23 deletions

View File

@ -20,6 +20,7 @@
use Framadate\Migration\AddColumn_hidden_In_poll_For_0_9; use Framadate\Migration\AddColumn_hidden_In_poll_For_0_9;
use Framadate\Migration\AddColumn_receiveNewComments_For_0_9; use Framadate\Migration\AddColumn_receiveNewComments_For_0_9;
use Framadate\Migration\AddColumn_uniqId_In_vote_For_0_9; use Framadate\Migration\AddColumn_uniqId_In_vote_For_0_9;
use Framadate\Migration\AddColumn_ValueMax_In_poll_For_1_1;
use Framadate\Migration\AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9; use Framadate\Migration\AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9;
use Framadate\Migration\Alter_Comment_table_adding_date; use Framadate\Migration\Alter_Comment_table_adding_date;
use Framadate\Migration\Alter_Comment_table_for_name_length; use Framadate\Migration\Alter_Comment_table_for_name_length;
@ -42,6 +43,7 @@ $migrations = [
new AddColumn_receiveNewComments_For_0_9(), new AddColumn_receiveNewComments_For_0_9(),
new AddColumn_uniqId_In_vote_For_0_9(), new AddColumn_uniqId_In_vote_For_0_9(),
new AddColumn_hidden_In_poll_For_0_9(), new AddColumn_hidden_In_poll_For_0_9(),
new AddColumn_ValueMax_In_poll_For_1_1(),
new Generate_uniqId_for_old_votes(), new Generate_uniqId_for_old_votes(),
new RPadVotes_from_0_8(), new RPadVotes_from_0_8(),
new Alter_Comment_table_for_name_length(), new Alter_Comment_table_for_name_length(),

View File

@ -19,6 +19,7 @@
use Framadate\Editable; use Framadate\Editable;
use Framadate\Exception\AlreadyExistsException; use Framadate\Exception\AlreadyExistsException;
use Framadate\Exception\ConcurrentEditionException; use Framadate\Exception\ConcurrentEditionException;
use Framadate\Exception\ConcurrentVoteException;
use Framadate\Exception\MomentAlreadyExistsException; use Framadate\Exception\MomentAlreadyExistsException;
use Framadate\Message; use Framadate\Message;
use Framadate\Security\PasswordHasher; use Framadate\Security\PasswordHasher;
@ -224,6 +225,8 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
} }
} catch (ConcurrentEditionException $cee) { } catch (ConcurrentEditionException $cee) {
$message = new Message('danger', __('Error', 'Poll has been updated before you vote')); $message = new Message('danger', __('Error', 'Poll has been updated before you vote'));
} catch (ConcurrentVoteException $cve) {
$message = new Message('danger', __('Error', "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry."));
} }
} }
} elseif (isset($_POST['save'])) { // Add a new vote } elseif (isset($_POST['save'])) { // Add a new vote
@ -251,6 +254,8 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
$message = new Message('danger', __('Error', 'You already voted')); $message = new Message('danger', __('Error', 'You already voted'));
} catch (ConcurrentEditionException $cee) { } catch (ConcurrentEditionException $cee) {
$message = new Message('danger', __('Error', 'Poll has been updated before you vote')); $message = new Message('danger', __('Error', 'Poll has been updated before you vote'));
} catch (ConcurrentVoteException $cve) {
$message = new Message('danger', __('Error', "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry."));
} }
} }
} }

View File

@ -0,0 +1,12 @@
<?php
namespace Framadate\Exception;
/**
* Class ConcurrentVoteException
*
* Thrown when a poll has a maximum votes constraint for options, and a vote happened since the poll was rendered
*/
class ConcurrentVoteException extends \Exception {
function __construct() {
}
}

View File

@ -28,6 +28,7 @@ class Form
public $format; public $format;
public $end_date; public $end_date;
public $choix_sondage; public $choix_sondage;
public $ValueMax;
/** /**
* Tells if users can modify their choices. * Tells if users can modify their choices.
@ -49,6 +50,12 @@ class Form
* If true, only the poll maker can see the poll's results * If true, only the poll maker can see the poll's results
* @var boolean * @var boolean
*/ */
public $use_ValueMax;
/**
* if true, there will be a limit of voters per option
* @var boolean
*/
public $hidden; public $hidden;
/** /**

View File

@ -0,0 +1,71 @@
<?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/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-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)
*/
namespace Framadate\Migration;
use Framadate\Utils;
/**
* This migration adds the field Value_Max on the poll table.
*
* @package Framadate\Migration
* @version 0.9
*/
class AddColumn_ValueMax_In_poll_For_1_1 implements Migration {
function __construct() {
}
/**
* This method should describe in english what is the purpose of the migration class.
*
* @return string The description of the migration class
*/
function description() {
return 'Add column "ValueMax" in table "vote" for version 0.9';
}
/**
* This method could check if the execute method should be called.
* It is called before the execute method.
*
* @param \PDO $pdo The connection to database
* @return bool true is the Migration should be executed.
*/
function preCondition(\PDO $pdo) {
return true;
}
/**
* This method is called only one time in the migration page.
*
* @param \PDO $pdo The connection to database
* @return bool true is the execution succeeded
*/
function execute(\PDO $pdo) {
$this->alterPollTable($pdo);
return true;
}
private function alterPollTable(\PDO $pdo) {
$pdo->exec('
ALTER TABLE `' . Utils::table('poll') . '`
ADD `ValueMax` TINYINT,
ADD CHECK (ValueMax > 0)');
}
}

View File

@ -12,10 +12,10 @@ class PollRepository extends AbstractRepository {
public function insertPoll($poll_id, $admin_poll_id, $form) { public function insertPoll($poll_id, $admin_poll_id, $form) {
$sql = 'INSERT INTO `' . Utils::table('poll') . '` $sql = 'INSERT INTO `' . Utils::table('poll') . '`
(id, admin_id, title, description, admin_name, admin_mail, end_date, format, editable, receiveNewVotes, receiveNewComments, hidden, password_hash, results_publicly_visible) (id, admin_id, title, description, admin_name, admin_mail, end_date, format, editable, receiveNewVotes, receiveNewComments, hidden, password_hash, results_publicly_visible,ValueMax)
VALUES (?,?,?,?,?,?,FROM_UNIXTIME(?),?,?,?,?,?,?,?)'; VALUES (?,?,?,?,?,?,FROM_UNIXTIME(?),?,?,?,?,?,?,?,?)';
$prepared = $this->prepare($sql); $prepared = $this->prepare($sql);
$prepared->execute([$poll_id, $admin_poll_id, $form->title, $form->description, $form->admin_name, $form->admin_mail, $form->end_date, $form->format, ($form->editable>=0 && $form->editable<=2) ? $form->editable : 0, $form->receiveNewVotes ? 1 : 0, $form->receiveNewComments ? 1 : 0, $form->hidden ? 1 : 0, $form->password_hash, $form->results_publicly_visible ? 1 : 0]); $prepared->execute([$poll_id, $admin_poll_id, $form->title, $form->description, $form->admin_name, $form->admin_mail, $form->end_date, $form->format, ($form->editable>=0 && $form->editable<=2) ? $form->editable : 0, $form->receiveNewVotes ? 1 : 0, $form->receiveNewComments ? 1 : 0, $form->hidden ? 1 : 0, $form->password_hash, $form->results_publicly_visible ? 1 : 0,$form->ValueMax]);
} }
function findById($poll_id) { function findById($poll_id) {

View File

@ -76,6 +76,13 @@ class InputService {
public function filterMD5($control) { public function filterMD5($control) {
return filter_var($control, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => MD5_REGEX]]); return filter_var($control, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => MD5_REGEX]]);
} }
public function filterInteger($int) {
if (filter_var($int, FILTER_VALIDATE_INT)) {
return $int;
}
return null;
}
public function filterBoolean($boolean) { public function filterBoolean($boolean) {
return !!filter_var($boolean, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_TRUE_REGEX]]); return !!filter_var($boolean, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_TRUE_REGEX]]);

View File

@ -20,6 +20,7 @@ namespace Framadate\Services;
use Framadate\Exception\AlreadyExistsException; use Framadate\Exception\AlreadyExistsException;
use Framadate\Exception\ConcurrentEditionException; use Framadate\Exception\ConcurrentEditionException;
use Framadate\Exception\ConcurrentVoteException;
use Framadate\Form; use Framadate\Form;
use Framadate\FramaDB; use Framadate\FramaDB;
use Framadate\Repositories\RepositoryFactory; use Framadate\Repositories\RepositoryFactory;
@ -82,9 +83,22 @@ class PollService {
return $slots; return $slots;
} }
/**
* @param $poll_id
* @param $vote_id
* @param $name
* @param $choices
* @param $slots_hash
* @throws ConcurrentEditionException
* @throws ConcurrentVoteException
* @return bool
*/
public function updateVote($poll_id, $vote_id, $name, $choices, $slots_hash) { public function updateVote($poll_id, $vote_id, $name, $choices, $slots_hash) {
$poll = $this->findById($poll_id); $poll = $this->findById($poll_id);
// Check that no-one voted in the meantime and it conflicts the maximum votes constraint
$this->checkMaxVotes($choices, $poll, $poll_id);
// Check if slots are still the same // Check if slots are still the same
$this->checkThatSlotsDidntChanged($poll, $slots_hash); $this->checkThatSlotsDidntChanged($poll, $slots_hash);
@ -93,9 +107,22 @@ class PollService {
return $this->voteRepository->update($poll_id, $vote_id, $name, $choices); return $this->voteRepository->update($poll_id, $vote_id, $name, $choices);
} }
/**
* @param $poll_id
* @param $name
* @param $choices
* @param $slots_hash
* @throws AlreadyExistsException
* @throws ConcurrentEditionException
* @throws ConcurrentVoteException
* @return \stdClass
*/
function addVote($poll_id, $name, $choices, $slots_hash) { function addVote($poll_id, $name, $choices, $slots_hash) {
$poll = $this->findById($poll_id); $poll = $this->findById($poll_id);
// Check that no-one voted in the meantime and it conflicts the maximum votes constraint
$this->checkMaxVotes($choices, $poll, $poll_id);
// Check if slots are still the same // Check if slots are still the same
$this->checkThatSlotsDidntChanged($poll, $slots_hash); $this->checkThatSlotsDidntChanged($poll, $slots_hash);
@ -113,7 +140,7 @@ class PollService {
function addComment($poll_id, $name, $comment) { function addComment($poll_id, $name, $comment) {
if ($this->commentRepository->exists($poll_id, $name, $comment)) { if ($this->commentRepository->exists($poll_id, $name, $comment)) {
return true; return true;
} }
return $this->commentRepository->insert($poll_id, $name, $comment); return $this->commentRepository->insert($poll_id, $name, $comment);
} }
@ -160,10 +187,10 @@ class PollService {
$result['inb'][$i] = 0; $result['inb'][$i] = 0;
$result['y'][$i] = 0; $result['y'][$i] = 0;
} }
if ($choice === 1) { if ($choice === "1") {
$result['inb'][$i]++; $result['inb'][$i]++;
} }
if ($choice === 2) { if ($choice === "2") {
$result['y'][$i]++; $result['y'][$i]++;
} }
} }
@ -252,4 +279,22 @@ class PollService {
throw new ConcurrentEditionException(); throw new ConcurrentEditionException();
} }
} }
/**
* This method checks if the votes doesn't conflicts the maximum votes constraint
*
* @param $user_choice
* @param \stdClass $poll
* @param string $poll_id
* @throws ConcurrentVoteException
*/
private function checkMaxVotes($user_choice, $poll, $poll_id) {
$best_choices = $this->computeBestChoices($this->allVotesByPollId($poll_id));
foreach ($best_choices['y'] as $i => $nb_choice) {
// if for this option we have reached maximum value and user wants to add itself too
if ($nb_choice >= $poll->ValueMax && $user_choice[$i] === "2") {
throw new ConcurrentVoteException();
}
}
}
} }

View File

@ -55,6 +55,10 @@ if (isset($_GET['type']) && $_GET['type'] === 'date' ||
$goToStep2 = filter_input(INPUT_POST, GO_TO_STEP_2, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^(date|classic)$/']]); $goToStep2 = filter_input(INPUT_POST, GO_TO_STEP_2, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^(date|classic)$/']]);
if ($goToStep2) { if ($goToStep2) {
$title = $inputService->filterTitle($_POST['title']); $title = $inputService->filterTitle($_POST['title']);
$use_ValueMax = isset($_POST['use_ValueMax']) ? $inputService->filterBoolean($_POST['use_ValueMax']) : false;
$ValueMax = $use_ValueMax === true ? $inputService->filterInteger($_POST['ValueMax']) : null;
$use_customized_url = isset($_POST['use_customized_url']) ? $inputService->filterBoolean($_POST['use_customized_url']) : false; $use_customized_url = isset($_POST['use_customized_url']) ? $inputService->filterBoolean($_POST['use_customized_url']) : false;
$customized_url = $use_customized_url === true ? $inputService->filterId($_POST['customized_url']) : null; $customized_url = $use_customized_url === true ? $inputService->filterId($_POST['customized_url']) : null;
$name = $inputService->filterName($_POST['name']); $name = $inputService->filterName($_POST['name']);
@ -77,10 +81,13 @@ if ($goToStep2) {
$error_on_password = false; $error_on_password = false;
$error_on_password_repeat = false; $error_on_password_repeat = false;
$error_on_customized_url = false; $error_on_customized_url = false;
$error_on_ValueMax = false;
$_SESSION['form']->title = $title; $_SESSION['form']->title = $title;
$_SESSION['form']->id = $customized_url; $_SESSION['form']->id = $customized_url;
$_SESSION['form']->use_customized_url = $use_customized_url; $_SESSION['form']->use_customized_url = $use_customized_url;
$_SESSION['form']->use_ValueMax = $use_ValueMax;
$_SESSION['form']->ValueMax = $ValueMax;
$_SESSION['form']->admin_name = $name; $_SESSION['form']->admin_name = $name;
$_SESSION['form']->admin_mail = $mail; $_SESSION['form']->admin_mail = $mail;
$_SESSION['form']->description = $description; $_SESSION['form']->description = $description;
@ -110,6 +117,13 @@ if ($goToStep2) {
} }
} }
if ($use_ValueMax) {
if ($use_ValueMax === false) {
$error_on_ValueMax = true;
$error_on_customized_url_msg = __('Error', 'Mauvaise valeur');
}
}
if ($name !== $_POST['name']) { if ($name !== $_POST['name']) {
$error_on_name = true; $error_on_name = true;
} }
@ -134,7 +148,7 @@ if ($goToStep2) {
} }
if ($title && $name && $email_OK && !$error_on_title && !$error_on_customized_url && !$error_on_description && !$error_on_name if ($title && $name && $email_OK && !$error_on_title && !$error_on_customized_url && !$error_on_description && !$error_on_name
&& !$error_on_password && !$error_on_password_repeat && !$error_on_password && !$error_on_password_repeat &&!$error_on_ValueMax
) { ) {
// If no errors, we hash the password if needed // If no errors, we hash the password if needed
if ($_SESSION['form']->use_password) { if ($_SESSION['form']->use_password) {
@ -193,12 +207,17 @@ $errors = [
'msg' => '', 'msg' => '',
'aria' => '', 'aria' => '',
'class' => '' 'class' => ''
],
'ValueMax' => [
'msg' => '',
'aria' => '',
'class' => ''
], ],
'password_repeat' => [ 'password_repeat' => [
'msg' => '', 'msg' => '',
'aria' => '', 'aria' => '',
'class' => '' 'class' => ''
] ],
]; ];
if (!empty($_POST[GO_TO_STEP_2])) { if (!empty($_POST[GO_TO_STEP_2])) {
@ -254,6 +273,11 @@ if (!empty($_POST[GO_TO_STEP_2])) {
$errors['password_repeat']['class'] = ' has-error'; $errors['password_repeat']['class'] = ' has-error';
$errors['password_repeat']['msg'] = __('Error', 'Passwords do not match'); $errors['password_repeat']['msg'] = __('Error', 'Passwords do not match');
} }
if ($error_on_ValueMax) {
$errors['ValueMax']['aria'] = 'aria-describeby="poll_ValueMax" ';
$errors['ValueMax']['class'] = ' has-error';
$errors['ValueMax']['msg'] = __('Error', 'error on ValueMax');
}
} }
$useRemoteUser = USE_REMOTE_USER && isset($_SERVER['REMOTE_USER']); $useRemoteUser = USE_REMOTE_USER && isset($_SERVER['REMOTE_USER']);
@ -268,6 +292,8 @@ $smarty->assign('poll_type', $poll_type);
$smarty->assign('poll_title', Utils::fromPostOrDefault('title', $_SESSION['form']->title)); $smarty->assign('poll_title', Utils::fromPostOrDefault('title', $_SESSION['form']->title));
$smarty->assign('customized_url', Utils::fromPostOrDefault('customized_url', $_SESSION['form']->id)); $smarty->assign('customized_url', Utils::fromPostOrDefault('customized_url', $_SESSION['form']->id));
$smarty->assign('use_customized_url', Utils::fromPostOrDefault('use_customized_url', $_SESSION['form']->use_customized_url)); $smarty->assign('use_customized_url', Utils::fromPostOrDefault('use_customized_url', $_SESSION['form']->use_customized_url));
$smarty->assign('ValueMax', Utils::fromPostOrDefault('ValueMax', $_SESSION['form']->ValueMax));
$smarty->assign('use_ValueMax', Utils::fromPostOrDefault('use_ValueMax', $_SESSION['form']->use_ValueMax));
$smarty->assign('poll_description', Utils::fromPostOrDefault('description', $_SESSION['form']->description)); $smarty->assign('poll_description', Utils::fromPostOrDefault('description', $_SESSION['form']->description));
$smarty->assign('poll_name', Utils::fromPostOrDefault('name', $_SESSION['form']->admin_name)); $smarty->assign('poll_name', Utils::fromPostOrDefault('name', $_SESSION['form']->admin_name));
$smarty->assign('poll_mail', Utils::fromPostOrDefault('mail', $_SESSION['form']->admin_mail)); $smarty->assign('poll_mail', Utils::fromPostOrDefault('mail', $_SESSION['form']->admin_mail));

View File

@ -44,6 +44,18 @@ $(document).ready(function () {
} }
}); });
/**
* Enable/Disable ValueMax options
*/
$("#use_ValueMax").change(function () {
if ($(this).prop("checked")) {
$("#ValueMax").removeClass("hidden");
} else {
$("#ValueMax").addClass("hidden");
}
});
/** /**
* Hide/Show password options * Hide/Show password options
*/ */

View File

@ -395,6 +395,7 @@
"Adding vote failed": "C'hwitadenn war ouzhpennadenn ar vouezh", "Adding vote failed": "C'hwitadenn war ouzhpennadenn ar vouezh",
"You already voted": "Mouezhzt ho peus endeo", "You already voted": "Mouezhzt ho peus endeo",
"Poll has been updated before you vote": "Hizivaet eo bet ar sontadeg a-raok ho mouezh", "Poll has been updated before you vote": "Hizivaet eo bet ar sontadeg a-raok ho mouezh",
"Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.": "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.",
"Comment failed": "C'hiwtadenn war an evezhiadenn", "Comment failed": "C'hiwtadenn war an evezhiadenn",
"You can't create a poll with hidden results with the following edition option:": "N'hallit ket krouiñ ur sontadeg gant respontoù kuzhet gant an dibarzhioù embann da heul:", "You can't create a poll with hidden results with the following edition option:": "N'hallit ket krouiñ ur sontadeg gant respontoù kuzhet gant an dibarzhioù embann da heul:",
"Failed to delete column": "C'hwitadenn war zilemel ar bann", "Failed to delete column": "C'hwitadenn war zilemel ar bann",

View File

@ -396,6 +396,7 @@
"Adding vote failed": "Stimmabgabe fehlgeschlagen", "Adding vote failed": "Stimmabgabe fehlgeschlagen",
"You already voted": "Sie haben bereits abgestimmt", "You already voted": "Sie haben bereits abgestimmt",
"Poll has been updated before you vote": "Die Abstimmung wurde vor Ihrer Stimmabgabe aktualisiert", "Poll has been updated before you vote": "Die Abstimmung wurde vor Ihrer Stimmabgabe aktualisiert",
"Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.": "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.",
"Comment failed": "Abgabe des Kommentars gescheitert", "Comment failed": "Abgabe des Kommentars gescheitert",
"You can't create a poll with hidden results with the following edition option:": "Sie können mit der folgenden Editier-Option keine Umfrage mit versteckten Ergebnissen erzeugen:", "You can't create a poll with hidden results with the following edition option:": "Sie können mit der folgenden Editier-Option keine Umfrage mit versteckten Ergebnissen erzeugen:",
"Failed to delete column": "Löschen der Spalte fehlgeschlagen", "Failed to delete column": "Löschen der Spalte fehlgeschlagen",

View File

@ -247,7 +247,10 @@
"Password confirmation": "Confirmation", "Password confirmation": "Confirmation",
"Permissions": "Permissions", "Permissions": "Permissions",
"Optional parameters": "Optional parameters", "Optional parameters": "Optional parameters",
"Go to step 2": "Go to step 2" "Go to step 2": "Go to step 2",
"Limit the ammount of voters per option": "Limit the ammount of voters per option",
"ValueMax instructions": "voters per options ",
"Value Max" : "Value Max"
}, },
"Step 2": { "Step 2": {
"Back to step 1": "Return to step 1", "Back to step 1": "Return to step 1",
@ -396,6 +399,7 @@
"Adding vote failed": "Adding vote failed", "Adding vote failed": "Adding vote failed",
"You already voted": "You already voted", "You already voted": "You already voted",
"Poll has been updated before you vote": "Poll has been updated before you vote", "Poll has been updated before you vote": "Poll has been updated before you vote",
"Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.": "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.",
"Comment failed": "Comment failed", "Comment failed": "Comment failed",
"You can't create a poll with hidden results with the following edition option:": "You can't create a poll with hidden results with the following option: ", "You can't create a poll with hidden results with the following edition option:": "You can't create a poll with hidden results with the following option: ",
"Failed to delete column": "Failed to delete column", "Failed to delete column": "Failed to delete column",

View File

@ -396,6 +396,7 @@
"Adding vote failed": "Error al crear el voto", "Adding vote failed": "Error al crear el voto",
"You already voted": "Usted ya votó", "You already voted": "Usted ya votó",
"Poll has been updated before you vote": "La encuesta fue actualizada antes de su voto", "Poll has been updated before you vote": "La encuesta fue actualizada antes de su voto",
"Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.": "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.",
"Comment failed": "Error al crear el comentario", "Comment failed": "Error al crear el comentario",
"You can't create a poll with hidden results with the following edition option:": "No puede crear una encuesta con resultados no visibles con los siguientes opciones de edición", "You can't create a poll with hidden results with the following edition option:": "No puede crear una encuesta con resultados no visibles con los siguientes opciones de edición",
"Failed to delete column": "Error al eliminar la columna", "Failed to delete column": "Error al eliminar la columna",

View File

@ -247,7 +247,10 @@
"Password confirmation": "Confirmation", "Password confirmation": "Confirmation",
"Permissions": "Permissions", "Permissions": "Permissions",
"Optional parameters": "Paramètres facultatifs", "Optional parameters": "Paramètres facultatifs",
"Go to step 2": "Aller à l'étape 2" "Go to step 2": "Aller à l'étape 2",
"Limit the ammount of voters per option":"limiter le nombre de votants par option",
"Value Max": "Valeur Maximale",
"ValueMax instructions": "Votants maximum par option"
}, },
"Step 2": { "Step 2": {
"Back to step 1": "Revenir à létape 1", "Back to step 1": "Revenir à létape 1",
@ -396,6 +399,7 @@
"Adding vote failed": "Échec de l'ajout d'un vote", "Adding vote failed": "Échec de l'ajout d'un vote",
"You already voted": "Vous avez déjà voté", "You already voted": "Vous avez déjà voté",
"Poll has been updated before you vote": "Le sondage a été mis à jour avant votre vote", "Poll has been updated before you vote": "Le sondage a été mis à jour avant votre vote",
"Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.": "Votre vote n'a pas été pris en compte, car quelqu'un a voté entre temps et cela entre en conflit avec vos choix et les conditions du sondage. Merci de réessayer.",
"Comment failed": "Échec du commentaire", "Comment failed": "Échec du commentaire",
"You can't create a poll with hidden results with the following edition option:": "Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'édition suivantes : ", "You can't create a poll with hidden results with the following edition option:": "Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'édition suivantes : ",
"Failed to delete column": "Échec de la suppression de colonne", "Failed to delete column": "Échec de la suppression de colonne",

View File

@ -396,6 +396,7 @@
"Adding vote failed": "Aggiunta del voto fallito", "Adding vote failed": "Aggiunta del voto fallito",
"You already voted": "IT_Vous avez déjà voté", "You already voted": "IT_Vous avez déjà voté",
"Poll has been updated before you vote": "IT_Le sondage a été mis à jour avant votre vote", "Poll has been updated before you vote": "IT_Le sondage a été mis à jour avant votre vote",
"Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.": "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.",
"Comment failed": "Commento fallito", "Comment failed": "Commento fallito",
"You can't create a poll with hidden results with the following edition option:": "Non potete creare un sondaggio con i risultati nascosti con queste opzioni: ", "You can't create a poll with hidden results with the following edition option:": "Non potete creare un sondaggio con i risultati nascosti con queste opzioni: ",
"Failed to delete column": "Impossibile eliminare la colonna", "Failed to delete column": "Impossibile eliminare la colonna",

View File

@ -396,6 +396,7 @@
"Adding vote failed": "Toevoegen stem gefaald", "Adding vote failed": "Toevoegen stem gefaald",
"You already voted": "Je hebt al gestemd", "You already voted": "Je hebt al gestemd",
"Poll has been updated before you vote": "De poll is gewijzigd voordat je stemde", "Poll has been updated before you vote": "De poll is gewijzigd voordat je stemde",
"Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.": "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.",
"Comment failed": "Opmerking mislukt", "Comment failed": "Opmerking mislukt",
"You can't create a poll with hidden results with the following edition option:": "Je kan geen poll met verborgen resultaten maken met de volgende optie: ", "You can't create a poll with hidden results with the following edition option:": "Je kan geen poll met verborgen resultaten maken met de volgende optie: ",
"Failed to delete column": "Kolom verwijderen mislukt", "Failed to delete column": "Kolom verwijderen mislukt",

View File

@ -396,6 +396,7 @@
"Adding vote failed": "Fracàs de lapondon dun vòte", "Adding vote failed": "Fracàs de lapondon dun vòte",
"You already voted": "Avètz ja votat", "You already voted": "Avètz ja votat",
"Poll has been updated before you vote": "Lo sondatge es estat mes a jorn abans vòstre vòte", "Poll has been updated before you vote": "Lo sondatge es estat mes a jorn abans vòstre vòte",
"Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.": "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry.",
"Comment failed": "Fracàs del comentari", "Comment failed": "Fracàs del comentari",
"You can't create a poll with hidden results with the following edition option:": "Podètz pas crear de sondatges amb de resultats amagats amb las opcions dedicion seguentas:", "You can't create a poll with hidden results with the following edition option:": "Podètz pas crear de sondatges amb de resultats amagats amb las opcions dedicion seguentas:",
"Failed to delete column": "Fracàs de la supression de colomna", "Failed to delete column": "Fracàs de la supression de colomna",
@ -428,4 +429,4 @@
"Check again": "Tornar verificar", "Check again": "Tornar verificar",
"Continue the installation": "Contunhar linstallacion" "Continue the installation": "Contunhar linstallacion"
} }
} }

View File

@ -4,3 +4,7 @@ log_errors = On
error_log = /var/log/apache2/error.log error_log = /var/log/apache2/error.log
ignore_repeated_errors = On ignore_repeated_errors = On
register_globals = Off register_globals = Off
[Date]
date.timezone = "Europe/Paris"

View File

@ -19,6 +19,7 @@
use Framadate\Editable; use Framadate\Editable;
use Framadate\Exception\AlreadyExistsException; use Framadate\Exception\AlreadyExistsException;
use Framadate\Exception\ConcurrentEditionException; use Framadate\Exception\ConcurrentEditionException;
use Framadate\Exception\ConcurrentVoteException;
use Framadate\Message; use Framadate\Message;
use Framadate\Security\Token; use Framadate\Security\Token;
use Framadate\Services\InputService; use Framadate\Services\InputService;
@ -146,6 +147,8 @@ if ($accessGranted) {
} }
} catch (ConcurrentEditionException $cee) { } catch (ConcurrentEditionException $cee) {
$message = new Message('danger', __('Error', 'Poll has been updated before you vote')); $message = new Message('danger', __('Error', 'Poll has been updated before you vote'));
} catch (ConcurrentVoteException $cve) {
$message = new Message('danger', __('Error', "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry."));
} }
} }
} elseif (isset($_POST['save'])) { // Add a new vote } elseif (isset($_POST['save'])) { // Add a new vote
@ -179,6 +182,8 @@ if ($accessGranted) {
$message = new Message('danger', __('Error', 'You already voted')); $message = new Message('danger', __('Error', 'You already voted'));
} catch (ConcurrentEditionException $cee) { } catch (ConcurrentEditionException $cee) {
$message = new Message('danger', __('Error', 'Poll has been updated before you vote')); $message = new Message('danger', __('Error', 'Poll has been updated before you vote'));
} catch (ConcurrentVoteException $cve) {
$message = new Message('danger', __('Error', "Your vote wasn't counted, because someone voted in the meantime and it conflicted with your choices and the poll conditions. Please retry."));
} }
} }
} }
@ -231,5 +236,6 @@ $smarty->assign('hidden', $poll->hidden);
$smarty->assign('accessGranted', $accessGranted); $smarty->assign('accessGranted', $accessGranted);
$smarty->assign('resultPubliclyVisible', $resultPubliclyVisible); $smarty->assign('resultPubliclyVisible', $resultPubliclyVisible);
$smarty->assign('editedVoteUniqueId', $editedVoteUniqueId); $smarty->assign('editedVoteUniqueId', $editedVoteUniqueId);
$smarty->assign('ValueMax', $poll->ValueMax);
$smarty->display('studs.tpl'); $smarty->display('studs.tpl');

View File

@ -116,6 +116,41 @@
<div class="collapse" id="optionnal"> <div class="collapse" id="optionnal">
{* Value MAX *}
<div class="form-group">
<label for="use_valueMax" class="col-sm-4 control-label">
{__('Step 1', 'Value Max')}<br/>
</label>
<div class="col-sm-8">
<div class="checkbox">
<label>
<input id="use_ValueMax" name="use_ValueMax" type="checkbox" >
{__('Step 1', "Limit the ammount of voters per option")}
</label>
</div>
</div>
</div>
<div class="form-group">
<div id="ValueMax"{if !$use_ValueMax} class="hidden"{/if}>
<div class="col-sm-offset-4 col-sm-8">
<label >
<input id="ValueMax" type="number" min= "0" name="ValueMax">
{__('Step 1', "ValueMax instructions")}
</label>
</div>
</div>
</div>
{* Poll identifier *} {* Poll identifier *}
<div class="form-group {$errors['customized_url']['class']}"> <div class="form-group {$errors['customized_url']['class']}">

View File

@ -160,21 +160,24 @@
<input type="text" id="name" name="name" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" /> <input type="text" id="name" name="name" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" />
</div> </div>
</td> </td>
{$i = 0}
{foreach $slots as $id=>$slot} {foreach $slots as $id=>$slot}
<td class="bg-info" headers="C{$id}"> <td class="bg-info" headers="C{$id}">
<ul class="list-unstyled choice"> <ul class="list-unstyled choice">
<li class="yes"> {if $best_choices['y'][$i] lt $poll->ValueMax || $poll->ValueMax eq NULL}
<input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2" /> <li class="yes">
<label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{__('Poll results', 'Vote yes for')|html} {$slot->title|html}"> <input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2" />
<i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span> <label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{__('Poll results', 'Vote yes for')|html} {$slot->title|html}">
</label> <i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span>
</li> </label>
<li class="ifneedbe"> </li>
<input type="radio" id="i-choice-{$id}" name="choices[{$id}]" value="1" /> <li class="ifneedbe">
<label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{__('Poll results', 'Vote ifneedbe for')|html} {$slot->title|html}"> <input type="radio" id="i-choice-{$id}" name="choices[{$id}]" value="1" />
(<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span> <label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{__('Poll results', 'Vote ifneedbe for')|html} {$slot->title|html}">
</label> <i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
</li> </label>
</li>
{/if}
<li class="no"> <li class="no">
<input type="radio" id="n-choice-{$id}" name="choices[{$id}]" value="0" /> <input type="radio" id="n-choice-{$id}" name="choices[{$id}]" value="0" />
<label class="btn btn-default btn-xs startunchecked" for="n-choice-{$id}" title="{__('Poll results', 'Vote no for')|html} {$slot->title|html}"> <label class="btn btn-default btn-xs startunchecked" for="n-choice-{$id}" title="{__('Poll results', 'Vote no for')|html} {$slot->title|html}">
@ -186,6 +189,8 @@
</li> </li>
</ul> </ul>
</td> </td>
{$i = $i+1}
{/foreach} {/foreach}
<td><button type="submit" class="btn btn-success btn-md" name="save" title="{__('Poll results', 'Save the choices')}">{__('Generic', 'Save')}</button></td> <td><button type="submit" class="btn btn-success btn-md" name="save" title="{__('Poll results', 'Save the choices')}">{__('Generic', 'Save')}</button></td>
</tr> </tr>

View File

@ -219,11 +219,17 @@
<input type="text" id="name" name="name" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" /> <input type="text" id="name" name="name" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" />
</div> </div>
</td> </td>
{$i = 0} {$i = 0}
{foreach $slots as $slot} {foreach $slots as $slot}
{foreach $slot->moments as $moment} {foreach $slot->moments as $moment}
<td class="bg-info" headers="M{$headersM[$i]} D{$headersD[$i]} H{$headersH[$i]}"> <td class="bg-info" headers="M{$headersM[$i]} D{$headersD[$i]} H{$headersH[$i]}">
<ul class="list-unstyled choice"> <ul class="list-unstyled choice">
{if $best_choices['y'][$i] lt $poll->ValueMax || $poll->ValueMax eq NULL}
<li class="yes"> <li class="yes">
<input type="radio" id="y-choice-{$i}" name="choices[{$i}]" value="2" /> <input type="radio" id="y-choice-{$i}" name="choices[{$i}]" value="2" />
<label class="btn btn-default btn-xs" for="y-choice-{$i}" title="{__('Poll results', 'Vote yes for')|html} {$slot->day|date_format:$date_format.txt_short|html} - {$moment|html}"> <label class="btn btn-default btn-xs" for="y-choice-{$i}" title="{__('Poll results', 'Vote yes for')|html} {$slot->day|date_format:$date_format.txt_short|html} - {$moment|html}">
@ -236,6 +242,9 @@
(<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span> (<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
</label> </label>
</li> </li>
{/if}
<li class="no"> <li class="no">
<input type="radio" id="n-choice-{$i}" name="choices[{$i}]" value="0" /> <input type="radio" id="n-choice-{$i}" name="choices[{$i}]" value="0" />
<label class="btn btn-default btn-xs startunchecked" for="n-choice-{$i}" title="{__('Poll results', 'Vote no for')|html} {$slot->day|date_format:$date_format.txt_short|html} - {$moment|html}"> <label class="btn btn-default btn-xs startunchecked" for="n-choice-{$i}" title="{__('Poll results', 'Vote no for')|html} {$slot->day|date_format:$date_format.txt_short|html} - {$moment|html}">
@ -247,6 +256,9 @@
</li> </li>
</ul> </ul>
</td> </td>
{$i = $i+1} {$i = $i+1}
{/foreach} {/foreach}
{/foreach} {/foreach}