From a135f74383d29f76a1a145f5f52fbc52929d58db Mon Sep 17 00:00:00 2001 From: Antonin Date: Mon, 6 Apr 2015 12:39:58 +0200 Subject: [PATCH] Hidden results option is taken into account. - Also added possibility for the poll's maker to edit this hidden results option. --- adminstuds.php | 9 ++- app/classes/Framadate/FramaDB.php | 4 +- css/style.css | 5 +- js/core.js | 14 +++++ locale/de.json | 6 +- locale/en.json | 4 +- locale/es.json | 4 +- locale/fr.json | 4 +- studs.php | 1 + tpl/part/poll_info.tpl | 35 ++++++++++-- tpl/part/vote_table_classic.tpl | 89 +++++++++++++++--------------- tpl/part/vote_table_date.tpl | 91 ++++++++++++++++--------------- 12 files changed, 166 insertions(+), 100 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index 997788e..07ee442 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -70,7 +70,7 @@ if (!$poll) { if (isset($_POST['update_poll_info'])) { $updated = false; - $field = $inputService->filterAllowedValues($_POST['update_poll_info'], ['title', 'admin_mail', 'description', 'rules', 'expiration_date', 'name']); + $field = $inputService->filterAllowedValues($_POST['update_poll_info'], ['title', 'admin_mail', 'description', 'rules', 'expiration_date', 'name', 'hidden']); // Update the right poll field if ($field == 'title') { @@ -128,6 +128,13 @@ if (isset($_POST['update_poll_info'])) { $poll->admin_name = $admin_name; $updated = true; } + } elseif ($field == 'hidden') { + $hidden = filter_input(INPUT_POST, 'hidden', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_REGEX]]); + $hidden = $hidden==null?false:true; + if ($hidden != $poll->hidden) { + $poll->hidden = $hidden; + $updated = true; + } } // Update poll in database diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index 8159b33..830d50c 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -90,9 +90,9 @@ class FramaDB { } function updatePoll($poll) { - $prepared = $this->prepare('UPDATE `' . Utils::table('poll') . '` SET title=?, admin_name=?, admin_mail=?, description=?, end_date=?, active=?, editable=? WHERE id = ?'); + $prepared = $this->prepare('UPDATE `' . Utils::table('poll') . '` SET title=?, admin_name=?, admin_mail=?, description=?, end_date=?, active=?, editable=?, hidden=? WHERE id = ?'); - return $prepared->execute([$poll->title, $poll->admin_name, $poll->admin_mail, $poll->description, $poll->end_date, $poll->active, $poll->editable, $poll->id]); + return $prepared->execute([$poll->title, $poll->admin_name, $poll->admin_mail, $poll->description, $poll->end_date, $poll->active, $poll->editable, $poll->hidden, $poll->id]); } function allCommentsByPollId($poll_id) { diff --git a/css/style.css b/css/style.css index 469f019..ffac6ca 100644 --- a/css/style.css +++ b/css/style.css @@ -124,6 +124,7 @@ caption { #email-form .btn-edit, #description-form .btn-edit, #poll-rules-form .btn-edit, +#poll-hidden-form .btn-edit, #expiration-form .btn-edit, #name-form .btn-edit { position:absolute; @@ -138,6 +139,8 @@ caption { #description-form:hover .btn-edit, #poll-rules-form .btn-edit:focus, #poll-rules-form:hover .btn-edit, +#poll-hidden-form .btn-edit:focus, +#poll-hidden-form:hover .btn-edit, #expiration-form .btn-edit:focus, #expiration-form:hover .btn-edit, #name-form .btn-edit:focus, @@ -155,7 +158,7 @@ caption { margin-bottom:0; } -#poll-rules-form p, +#poll-rules-form p, #poll-hidden-form p, .jumbotron p.well { font-size:16px; } diff --git a/js/core.js b/js/core.js index 4667c90..34fd84a 100644 --- a/js/core.js +++ b/js/core.js @@ -98,6 +98,20 @@ $(document).ready(function() { return false; }); + $('#poll-hidden-form .btn-edit').on('click', function() { + $('#poll-hidden-form p').hide(); + $('#poll-hidden-form .js-poll-hidden').removeClass("hidden"); + $('.js-poll-hidden input[type=checkbox]').focus(); + return false; + }); + + $('#poll-hidden-form .btn-cancel').on('click', function() { + $('#poll-hidden-form p').show(); + $('#poll-hidden-form .js-poll-hidden').addClass("hidden"); + $('.js-poll-hidden .btn-edit').focus(); + return false; + }); + $('#expiration-form .btn-edit').on('click', function() { $('#expiration-form p').hide(); $('.js-expiration').removeClass("hidden"); diff --git a/locale/de.json b/locale/de.json index 185e54e..09c148a 100644 --- a/locale/de.json +++ b/locale/de.json @@ -114,7 +114,9 @@ "Votes are editable solely by their owner.": "DE_Les votes sont modifiables uniquement par leur créateur", "Save the new rules": "Neue Regeln speichern", "Cancel the rules edit": "Neue Regeln nicht speichern", - "The name is invalid.": "Der Name ist ungültig." + "The name is invalid.": "Der Name ist ungültig.", + "Results are hidden.": "DE_Les résultats sont cachés.", + "Results are visible.": "DE_Les résultats sont visibles." }, "Poll results": { "Votes of the poll": "Abstimmungen der Umfrage ", @@ -302,7 +304,7 @@ "Framadate is not properly installed, please check the \"INSTALL\" to setup the database before continuing.": "Framadate ist nicht richtig installiert, überprüfen Sie bitte die Schaltfläche \"INSTALL\", um das Setup der Datenbank, bevor Sie fortfahren.", "Failed to save poll": "Fehlgeschlagen Umfrage sparen", "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 : ": "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 6408140..3096931 100644 --- a/locale/en.json +++ b/locale/en.json @@ -115,7 +115,9 @@ "Votes are editable solely by their owner.": "Votes are editable solely by their owner", "Save the new rules": "Save the new rules", "Cancel the rules edit": "Cancel the rules edit", - "The name is invalid.": "The name is invalid." + "The name is invalid.": "The name is invalid.", + "Results are hidden.": "Results are hidden.", + "Results are visible.": "Results are visible." }, "Poll results": { "Votes of the poll": "Votes of the poll", diff --git a/locale/es.json b/locale/es.json index 5005976..13604ea 100644 --- a/locale/es.json +++ b/locale/es.json @@ -114,7 +114,9 @@ "Votes are editable solely by their owner.": "ES_Les votes sont modifiables uniquement par leur créateur", "Save the new rules": "ES_Enregistrer les nouvelles permissions", "Cancel the rules edit": "ES_Annuler le changement de permissions", - "The name is invalid.": "ES_Le nom n'est pas valide." + "The name is invalid.": "ES_Le nom n'est pas valide.", + "Results are hidden.": "ES_Les résultats sont cachés.", + "Results are visible.": "ES_Les résultats sont visibles." }, "Poll results": { "Votes of the poll": "ES_Votes du sondage", diff --git a/locale/fr.json b/locale/fr.json index 1fa44d5..49d923c 100644 --- a/locale/fr.json +++ b/locale/fr.json @@ -114,7 +114,9 @@ "Votes are editable solely by their owner.": "Les votes sont modifiables uniquement par leur créateur", "Save the new rules": "Enregistrer les nouvelles permissions", "Cancel the rules edit": "Annuler le changement de permissions", - "The name is invalid.": "Le nom n'est pas valide." + "The name is invalid.": "Le nom n'est pas valide.", + "Results are hidden.": "Les résultats sont cachés.", + "Results are visible.": "Les résultats sont visibles." }, "Poll results": { "Votes of the poll": "Votes du sondage", diff --git a/studs.php b/studs.php index 142a371..ad5e323 100644 --- a/studs.php +++ b/studs.php @@ -212,6 +212,7 @@ $smarty->assign('comments', $comments); $smarty->assign('editingVoteId', $editingVoteId); $smarty->assign('message', $message); $smarty->assign('admin', false); +$smarty->assign('hidden', $poll->hidden); $smarty->assign('parameter_name_regex', NAME_REGEX); $smarty->display('studs.tpl'); diff --git a/tpl/part/poll_info.tpl b/tpl/part/poll_info.tpl index 645f9b1..9af9067 100644 --- a/tpl/part/poll_info.tpl +++ b/tpl/part/poll_info.tpl @@ -118,14 +118,41 @@ {if $admin}
-
+
+
+ {if $poll->hidden} + {$hidden_icon = "glyphicon-eye-close"} + {$hidden_text = __('PollInfo', 'Results are hidden.')} + {else} + {$hidden_icon = "glyphicon-eye-open"} + {$hidden_text = __('PollInfo', 'Results are visible.')} + {/if} +

{$hidden_text}

+ +
+
+
{if $poll->active} {if $poll->editable} - {$rule_id = 2} + {if $poll->editable == constant("Framadate\Editable::EDITABLE_BY_ALL")} + {$rule_id = 2} + {$rule_txt = __('PollInfo', 'Votes are editable')} + {else} + {$rule_id = 3} + {$rule_txt = __('PollInfo', 'Votes are editable solely by their owner.')} + {/if} {$rule_icon = ''} - {$rule_txt = __('PollInfo', 'Votes are editable')} - {else} + {else} {$rule_id = 1} {$rule_icon = ''} {$rule_txt = __('PollInfo', 'Votes and comments are open')} diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl index 3183a11..8e2973a 100644 --- a/tpl/part/vote_table_classic.tpl +++ b/tpl/part/vote_table_classic.tpl @@ -2,7 +2,7 @@ {$best_choices = [0]} {/if} -

{__('Poll results', 'Votes of the poll')}

+

{__('Poll results', 'Votes of the poll')} {if $hidden}({__('PollInfo', 'Results are hidden.')}){/if}

@@ -69,7 +69,7 @@ {/foreach} - {else} + {elseif !$hidden} {* Voted line *} {$vote->name|html} @@ -142,55 +142,58 @@ {/if} - {* Line displaying best moments *} - {$count_bests = 0} - {$max = max($best_choices)} - {if $max > 0} - - {__('Poll results', 'Addition')} - {foreach $best_choices as $best_choice} - {if $max == $best_choice} - {$count_bests = $count_bests +1} - {$best_choice|html} - {elseif $best_choice > 0} - {$best_choice|html} - {else} - - {/if} - {/foreach} - + {if !$hidden} + {* Line displaying best moments *} + {$count_bests = 0} + {$max = max($best_choices)} + {if $max > 0} + + {__('Poll results', 'Addition')} + {foreach $best_choices as $best_choice} + {if $max == $best_choice} + {$count_bests = $count_bests +1} + {$best_choice|html} + {elseif $best_choice > 0} + {$best_choice|html} + {else} + + {/if} + {/foreach} + + {/if} {/if}
-{* Best votes listing *} - -{$max = max($best_choices)} -{if $max > 0} -
- {if $count_bests == 1} -

{__('Poll results', 'Best choice')}

-
-

{__('Poll results', 'The best choice at this time is:')}

- {elseif $count_bests > 1} -

{__('Poll results', 'Best choices')}

+{if !$hidden} + {* Best votes listing *} + {$max = max($best_choices)} + {if $max > 0} +
+ {if $count_bests == 1} +

{__('Poll results', 'Best choice')}

-

{__('Poll results', 'The bests choices at this time are:')}

- {/if} +

{__('Poll results', 'The best choice at this time is:')}

+ {elseif $count_bests > 1} +

{__('Poll results', 'Best choices')}

+
+

{__('Poll results', 'The bests choices at this time are:')}

+ {/if} - {$i = 0} -
    - {foreach $slots as $slot} - {if $best_choices[$i] == $max} -
  • {$slot->title|html|markdown:true}
  • - {/if} - {$i = $i+1} - {/foreach} -
-

{__('Generic', 'with')} {$max|html} {if $max==1}{__('Generic', 'vote')}{else}{__('Generic', 'votes')}{/if}.

+ {$i = 0} +
    + {foreach $slots as $slot} + {if $best_choices[$i] == $max} +
  • {$slot->title|html|markdown:true}
  • + {/if} + {$i = $i+1} + {/foreach} +
+

{__('Generic', 'with')} {$max|html} {if $max==1}{__('Generic', 'vote')}{else}{__('Generic', 'votes')}{/if}.

+
-
+ {/if} {/if} \ No newline at end of file diff --git a/tpl/part/vote_table_date.tpl b/tpl/part/vote_table_date.tpl index 49f19a5..c104d41 100644 --- a/tpl/part/vote_table_date.tpl +++ b/tpl/part/vote_table_date.tpl @@ -2,7 +2,7 @@ {$best_choices = [0]} {/if} -

{__('Poll results', 'Votes of the poll')}

+

{__('Poll results', 'Votes of the poll')} {if $hidden}({__('PollInfo', 'Results are hidden.')}){/if}

@@ -115,7 +115,7 @@ {/foreach} - {else} + {elseif !$hidden} {* Voted line *} @@ -193,57 +193,60 @@ {/if} - {* Line displaying best moments *} - {$count_bests = 0} - {$max = max($best_choices)} - {if $max > 0} - - {__('Poll results', 'Addition')} - {foreach $best_choices as $best_moment} - {if $max == $best_moment} - {$count_bests = $count_bests +1} - {$best_moment|html} - {elseif $best_moment > 0} - {$best_moment|html} - {else} - - {/if} - {/foreach} - + {if !$hidden} + {* Line displaying best moments *} + {$count_bests = 0} + {$max = max($best_choices)} + {if $max > 0} + + {__('Poll results', 'Addition')} + {foreach $best_choices as $best_moment} + {if $max == $best_moment} + {$count_bests = $count_bests +1} + {$best_moment|html} + {elseif $best_moment > 0} + {$best_moment|html} + {else} + + {/if} + {/foreach} + + {/if} {/if}
-{* Best votes listing *} - -{$max = max($best_choices)} -{if $max > 0} -
- {if $count_bests == 1} -

{__('Poll results', 'Best choice')}

-
-

{__('Poll results', 'The best choice at this time is:')}

- {elseif $count_bests > 1} -

{__('Poll results', 'Best choices')}

+{if !$hidden} + {* Best votes listing *} + {$max = max($best_choices)} + {if $max > 0} +
+ {if $count_bests == 1} +

{__('Poll results', 'Best choice')}

-

{__('Poll results', 'The bests choices at this time are:')}

- {/if} +

{__('Poll results', 'The best choice at this time is:')}

+ {elseif $count_bests > 1} +

{__('Poll results', 'Best choices')}

+
+

{__('Poll results', 'The bests choices at this time are:')}

+ {/if} - {$i = 0} -
    - {foreach $slots as $slot} - {foreach $slot->moments as $moment} - {if $best_choices[$i] == $max} -
  • {$slot->day|date_format:$date_format.txt_full|html} - {$moment|html}
  • - {/if} - {$i = $i+1} + {$i = 0} +
      + {foreach $slots as $slot} + {foreach $slot->moments as $moment} + {if $best_choices[$i] == $max} +
    • {$slot->day|date_format:$date_format.txt_full|html} - {$moment|html}
    • + {/if} + {$i = $i+1} + {/foreach} {/foreach} - {/foreach} -
    -

    {__('Generic', 'with')} {$max|html} {if $max==1}{__('Generic', 'vote')}{else}{__('Generic', 'votes')}{/if}.

    +
+

{__('Generic', 'with')} {$max|html} {if $max==1}{__('Generic', 'vote')}{else}{__('Generic', 'votes')}{/if}.

+
-
+ {/if} {/if} \ No newline at end of file