From 0c2ba20bfacc5286e00dfc24d045985aebcec8d1 Mon Sep 17 00:00:00 2001 From: Antonin Date: Sun, 5 Apr 2015 18:36:43 +0200 Subject: [PATCH] Added option of poll with hidden results. --- admin/migration.php | 4 +- app/classes/Framadate/Form.php | 6 ++ .../AddColumn_hidden_In_poll_For_0_9.php | 77 +++++++++++++++++++ create_poll.php | 14 +--- js/app/create_poll.js | 54 +++++++++++++ locale/de.json | 2 + locale/en.json | 4 +- locale/es.json | 4 +- locale/fr.json | 4 +- tpl/create_poll.tpl | 52 ++++++------- 10 files changed, 178 insertions(+), 43 deletions(-) create mode 100644 app/classes/Framadate/Migration/AddColumn_hidden_In_poll_For_0_9.php create mode 100644 js/app/create_poll.js diff --git a/admin/migration.php b/admin/migration.php index f60d9ce..25bc733 100644 --- a/admin/migration.php +++ b/admin/migration.php @@ -21,6 +21,7 @@ use Framadate\Migration\From_0_0_to_0_8_Migration; use Framadate\Migration\From_0_8_to_0_9_Migration; use Framadate\Migration\AddColumn_receiveNewComments_For_0_9; use Framadate\Migration\AddColumn_uniqId_In_vote_For_0_9; +use Framadate\Migration\AddColumn_hidden_In_poll_For_0_9; use Framadate\Migration\Migration; use Framadate\Utils; @@ -33,7 +34,8 @@ $migrations = [ new From_0_0_to_0_8_Migration(), new From_0_8_to_0_9_Migration(), 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(), ]; // --------------------------------------- diff --git a/app/classes/Framadate/Form.php b/app/classes/Framadate/Form.php index 2570fc4..00f8c4f 100644 --- a/app/classes/Framadate/Form.php +++ b/app/classes/Framadate/Form.php @@ -47,6 +47,12 @@ class Form */ public $receiveNewComments; + /** + * If true, only the poll maker can see the poll's results + * @var boolean + */ + public $hidden; + /** * List of available choices */ diff --git a/app/classes/Framadate/Migration/AddColumn_hidden_In_poll_For_0_9.php b/app/classes/Framadate/Migration/AddColumn_hidden_In_poll_For_0_9.php new file mode 100644 index 0000000..c046752 --- /dev/null +++ b/app/classes/Framadate/Migration/AddColumn_hidden_In_poll_For_0_9.php @@ -0,0 +1,77 @@ +query('SHOW TABLES'); + $tables = $stmt->fetchAll(\PDO::FETCH_COLUMN); + + // Check if tables of v0.9 are presents + $diff = array_diff([Utils::table('poll'), Utils::table('slot'), Utils::table('vote'), Utils::table('comment')], $tables); + return count($diff) === 0; + } + + /** + * This methode 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 `hidden` TINYINT( 1 ) NOT NULL DEFAULT "0"'); + } + +} diff --git a/create_poll.php b/create_poll.php index 567bc0f..664182d 100644 --- a/create_poll.php +++ b/create_poll.php @@ -49,6 +49,7 @@ $description = filter_input(INPUT_POST, 'description', FILTER_SANITIZE_STRING); $editable = filter_input(INPUT_POST, 'editable', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => EDITABLE_CHOICE_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]]); +$hidden = filter_input(INPUT_POST, 'hidden', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_REGEX]]); // On initialise �galement les autres variables @@ -57,7 +58,7 @@ $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; @@ -66,6 +67,7 @@ if (!empty($_POST[GO_TO_STEP_2])) { $_SESSION['form']->editable = $editable; $_SESSION['form']->receiveNewVotes = ($receiveNewVotes !== null); $_SESSION['form']->receiveNewComments = ($receiveNewComments !== null); + $_SESSION['form']->hidden = ($hidden !== null); if ($config['use_smtp'] == true) { if (empty($mail)) { @@ -175,15 +177,6 @@ if (!empty($_POST[GO_TO_STEP_2])) { } } -// Checkbox 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); @@ -200,6 +193,7 @@ $smarty->assign('poll_mail', Utils::fromPostOrDefault('mail', $_SESSION['form']- $smarty->assign('poll_editable', Utils::fromPostOrDefault('editable', $_SESSION['form']->editable)); $smarty->assign('poll_receiveNewVotes', Utils::fromPostOrDefault('receiveNewVotes', $_SESSION['form']->receiveNewVotes)); $smarty->assign('poll_receiveNewComments', Utils::fromPostOrDefault('receiveNewComments', $_SESSION['form']->receiveNewComments)); +$smarty->assign('poll_hidden', Utils::fromPostOrDefault('hidden', $_SESSION['form']->hidden)); $smarty->assign('form', $_SESSION['form']); $smarty->display('create_poll.tpl'); diff --git a/js/app/create_poll.js b/js/app/create_poll.js new file mode 100644 index 0000000..66521dc --- /dev/null +++ b/js/app/create_poll.js @@ -0,0 +1,54 @@ +/** + * 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) + */ + +$(document).ready(function () { + + $("#formulaire").submit(function (event) { + var isHidden = $("#hidden").prop('checked'); + var isOptionAllUserCanModifyEverything = $("#editableByAll").is(":checked"); + + if (isHidden && isOptionAllUserCanModifyEverything) { + event.preventDefault(); + $("#hiddenWithBadEditionModeError").removeClass("hidden"); + } else { + $("#hiddenWithBadEditionModeError").addClass("hidden"); + } + }); + + // 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", ""); + } + +}); \ No newline at end of file diff --git a/locale/de.json b/locale/de.json index a28e227..185e54e 100644 --- a/locale/de.json +++ b/locale/de.json @@ -193,6 +193,7 @@ "Voters can modify their vote themselves.": "Teilnehmer können ihre Antworten verändern", "To receive an email for each new vote.": "Bei jeder neuen Abstimmung eine E-Mail erhalten.", "To receive an email for each new comment.": "Um eine E-Mail für jede neue Kommentar zu empfangen.", + "Only the poll maker can see the poll's results.": "DE_Seul le créateur du sondage peut voir les résultats.", "Go to step 2": "Weiter zum 2. Schritt" }, "Step 2": { @@ -302,5 +303,6 @@ "Failed to save poll": "Fehlgeschlagen Umfrage sparen", "Update vote failed": "Update vote failed", "Adding vote failed": "Adding vote failed" + "You can't create a poll with hidden results with the following edition option : ": "DE_Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : " } } \ No newline at end of file diff --git a/locale/en.json b/locale/en.json index b69babf..6408140 100644 --- a/locale/en.json +++ b/locale/en.json @@ -194,6 +194,7 @@ "Voters can modify their vote themselves.": "Voters can modify their vote themselves.", "To receive an email for each new vote.": "To receive an email for each new vote.", "To receive an email for each new comment.": "To receive an email for each new comment.", + "Only the poll maker can see the poll's results.": "Only the poll maker can see the poll's results.", "Go to step 2": "Go to step 2" }, "Step 2": { @@ -302,6 +303,7 @@ "Framadate is not properly installed, please check the \"INSTALL\" to setup the database before continuing.": "Framadate is not properly installed, please check the 'INSTALL' to setup the database before continuing.", "Failed to save poll": "Failed to save poll", "Update vote failed": "Update vote failed", - "Adding vote failed": "Adding vote failed" + "Adding vote failed": "Adding vote 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 edition option : " } } \ No newline at end of file diff --git a/locale/es.json b/locale/es.json index ad35a9a..5005976 100644 --- a/locale/es.json +++ b/locale/es.json @@ -193,6 +193,7 @@ "Voters can modify their vote themselves.": "Los encuentados pueden cambiar su línea ellos mismos.", "To receive an email for each new vote.": "Usted quiere recibir un correo electónico cada vez que alguien participe a la encuesta.", "To receive an email for each new comment.": "ES_Recevoir un courriel à chaque commentaire.", + "Only the poll maker can see the poll's results.": "ES_Seul le créateur du sondage peut voir les résultats.", "Go to step 2": "ES_Aller à l'étape 2" }, "Step 2": { @@ -301,6 +302,7 @@ "Framadate is not properly installed, please check the \"INSTALL\" to setup the database before continuing.": "ES_Framadate n'est pas installé correctement, lisez le fichier INSTALL pour configurer la base de données avant de continuer.", "Failed to save poll": "ES_Echèc de la sauvegarde du sondage", "Update vote failed": "ES_Mise à jour du vote échoué", - "Adding vote failed": "ES_Ajout d'un vote échoué" + "Adding vote failed": "ES_Ajout d'un vote échoué", + "You can't create a poll with hidden results with the following edition option : ": "ES_Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : " } } \ No newline at end of file diff --git a/locale/fr.json b/locale/fr.json index 241836d..1fa44d5 100644 --- a/locale/fr.json +++ b/locale/fr.json @@ -193,6 +193,7 @@ "Voters can modify their vote themselves.": "Chaque sondé peut modifier son propre vote.", "To receive an email for each new vote.": "Recevoir un courriel à chaque participation d'un sondé.", "To receive an email for each new comment.": "Recevoir un courriel à chaque commentaire.", + "Only the poll maker can see the poll's results.": "Seul le créateur du sondage peut voir les résultats.", "Go to step 2": "Aller à l'étape 2" }, "Step 2": { @@ -301,6 +302,7 @@ "Framadate is not properly installed, please check the \"INSTALL\" to setup the database before continuing.": "Framadate n'est pas installé correctement, lisez le fichier INSTALL pour configurer la base de données avant de continuer.", "Failed to save poll": "Echèc de la sauvegarde du sondage", "Update vote failed": "Mise à jour du vote échoué", - "Adding vote failed": "Ajout d'un vote échoué" + "Adding vote failed": "Ajout d'un vote échoué", + "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'éditions suivantes : " } } diff --git a/tpl/create_poll.tpl b/tpl/create_poll.tpl index 47156c6..ec01d90 100644 --- a/tpl/create_poll.tpl +++ b/tpl/create_poll.tpl @@ -1,5 +1,9 @@ {extends file='page.tpl'} +{block name="header"} + +{/block} + {block name=main}