From 64ff414900bff2214c707cc38a1c9bfa2be7b0ec Mon Sep 17 00:00:00 2001
From: Erwan TERTRAIS <erwan@tertrais.xyz>
Date: Tue, 20 Feb 2018 13:06:58 +0100
Subject: [PATCH] ValueMax : limit the number of voters per option

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
---
 admin/migration.php                           | 13 ++--
 app/classes/Framadate/Form.php                |  7 ++
 .../AddColumn_ValueMax_In_poll_For_1_1.php    | 73 +++++++++++++++++++
 .../Framadate/Repositories/PollRepository.php |  6 +-
 .../Framadate/Services/InputService.php       |  8 ++
 .../Framadate/Services/PollService.php        |  4 +-
 app/inc/constants.php                         |  1 +
 create_date_poll.php                          |  1 +
 create_poll.php                               | 32 +++++++-
 js/app/create_poll.js                         | 12 +++
 locale/en.json                                |  5 +-
 locale/fr.json                                |  5 +-
 php.ini                                       |  4 +
 studs.php                                     |  4 +
 tpl/create_poll.tpl                           | 35 +++++++++
 tpl/part/vote_table_classic.tpl               | 29 +++++---
 tpl/part/vote_table_date.tpl                  | 14 +++-
 17 files changed, 227 insertions(+), 26 deletions(-)
 create mode 100644 app/classes/Framadate/Migration/AddColumn_ValueMax_In_poll_For_1_1.php

diff --git a/admin/migration.php b/admin/migration.php
index 93cb1890..b2de0497 100644
--- a/admin/migration.php
+++ b/admin/migration.php
@@ -17,14 +17,15 @@
  * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
  */
 
-use Framadate\Migration\AddColumn_hidden_In_poll_For_0_9;
-use Framadate\Migration\AddColumn_receiveNewComments_For_0_9;
-use Framadate\Migration\AddColumn_uniqId_In_vote_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_for_name_length;
 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\Alter_Comment_table_for_name_length;
+use Framadate\Migration\Alter_Comment_table_adding_date;
+use Framadate\Migration\AddColumn_ValueMax_In_poll_For_1_1;
 use Framadate\Migration\Generate_uniqId_for_old_votes;
 use Framadate\Migration\Increase_pollId_size;
 use Framadate\Migration\Migration;
@@ -42,12 +43,14 @@ $migrations = [
     new AddColumn_receiveNewComments_For_0_9(),
     new AddColumn_uniqId_In_vote_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 RPadVotes_from_0_8(),
     new Alter_Comment_table_for_name_length(),
     new Alter_Comment_table_adding_date(),
     new AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9(),
     new Increase_pollId_size()
+
 ];
 // ---------------------------------------
 
diff --git a/app/classes/Framadate/Form.php b/app/classes/Framadate/Form.php
index f1ad0316..716400d3 100644
--- a/app/classes/Framadate/Form.php
+++ b/app/classes/Framadate/Form.php
@@ -28,6 +28,7 @@ class Form
     public $format;
     public $end_date;
     public $choix_sondage;
+    public $ValueMax;
 
     /**
      * 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
      * @var boolean
      */
+    public $use_ValueMax;
+
+    /**
+     * if true, there will be a limit of voters per option
+     * @var boolean
+     */
     public $hidden;
 
     /**
diff --git a/app/classes/Framadate/Migration/AddColumn_ValueMax_In_poll_For_1_1.php b/app/classes/Framadate/Migration/AddColumn_ValueMax_In_poll_For_1_1.php
new file mode 100644
index 00000000..dbf129c2
--- /dev/null
+++ b/app/classes/Framadate/Migration/AddColumn_ValueMax_In_poll_For_1_1.php
@@ -0,0 +1,73 @@
+<?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)');
+    }
+
+}
diff --git a/app/classes/Framadate/Repositories/PollRepository.php b/app/classes/Framadate/Repositories/PollRepository.php
index 4f5e62ec..9427813a 100644
--- a/app/classes/Framadate/Repositories/PollRepository.php
+++ b/app/classes/Framadate/Repositories/PollRepository.php
@@ -12,10 +12,10 @@ class PollRepository extends AbstractRepository {
 
     public function insertPoll($poll_id, $admin_poll_id, $form) {
         $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)
-          VALUES (?,?,?,?,?,?,FROM_UNIXTIME(?),?,?,?,?,?,?,?)';
+          (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(?),?,?,?,?,?,?,?,?)';
         $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(array($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) {
diff --git a/app/classes/Framadate/Services/InputService.php b/app/classes/Framadate/Services/InputService.php
index 23f6e006..ffb2266a 100644
--- a/app/classes/Framadate/Services/InputService.php
+++ b/app/classes/Framadate/Services/InputService.php
@@ -76,6 +76,14 @@ class InputService {
     public function filterMD5($control) {
         return filter_var($control, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => MD5_REGEX]]);
     }
+    
+    public function filterInteger($int) {
+          if (filter_var($int, FILTER_VALIDATE_INT)) {
+              return $int;
+       } else {
+      return  null;
+      }
+    }
 
     public function filterBoolean($boolean) {
         return !!filter_var($boolean, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_TRUE_REGEX]]);
diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php
index 43efd425..f2466d0a 100644
--- a/app/classes/Framadate/Services/PollService.php
+++ b/app/classes/Framadate/Services/PollService.php
@@ -26,6 +26,8 @@ use Framadate\Repositories\RepositoryFactory;
 use Framadate\Security\Token;
 use Framadate\Utils;
 
+
+
 class PollService {
     private $connect;
     private $logService;
@@ -151,7 +153,7 @@ class PollService {
         return $this->pollRepository->findAllByAdminMail($mail);
     }
 
-    function computeBestChoices($votes) {
+    function computeBestChoices($votes) { 
         $result = ['y' => [0], 'inb' => [0]];
         foreach ($votes as $vote) {
             $choices = str_split($vote->choices);
diff --git a/app/inc/constants.php b/app/inc/constants.php
index d36106ac..b631b9e9 100644
--- a/app/inc/constants.php
+++ b/app/inc/constants.php
@@ -17,6 +17,7 @@
  * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
  */
 
+
 // FRAMADATE version
 const VERSION = '1.0';
 
diff --git a/create_date_poll.php b/create_date_poll.php
index 05261b01..89f805b5 100644
--- a/create_date_poll.php
+++ b/create_date_poll.php
@@ -48,6 +48,7 @@ if ($_SESSION['form']->format !== 'D') {
     $_SESSION['form']->clearChoices();
 }
 
+
 if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) || ($config['use_smtp'] && !isset($_SESSION['form']->admin_mail))) {
     $step = 1;
 } else if (!empty($_POST['confirmation'])) {
diff --git a/create_poll.php b/create_poll.php
index a55fdbfc..015b63e4 100644
--- a/create_poll.php
+++ b/create_poll.php
@@ -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)$/']]);
 if ($goToStep2) {
     $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;
     $customized_url = $use_customized_url === true ? $inputService->filterId($_POST['customized_url']) : null;
     $name = $inputService->filterName($_POST['name']);
@@ -77,10 +81,14 @@ if ($goToStep2) {
     $error_on_password = false;
     $error_on_password_repeat = false;
     $error_on_customized_url = false;
+    $error_on_ValueMax = false;
+
 
     $_SESSION['form']->title = $title;
     $_SESSION['form']->id = $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_mail = $mail;
     $_SESSION['form']->description = $description;
@@ -110,6 +118,14 @@ 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']) {
         $error_on_name = true;
     }
@@ -134,7 +150,7 @@ if ($goToStep2) {
     }
 
     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 ($_SESSION['form']->use_password) {
@@ -193,12 +209,17 @@ $errors = [
         'msg' => '',
         'aria' => '',
         'class' => ''
+    ],
+	'ValueMax' => [
+        'msg' => '',
+        'aria' => '',
+        'class' => ''
     ],
     'password_repeat' => [
         'msg' => '',
         'aria' => '',
         'class' => ''
-    ]
+    ],
 ];
 
 if (!empty($_POST[GO_TO_STEP_2])) {
@@ -254,6 +275,11 @@ if (!empty($_POST[GO_TO_STEP_2])) {
         $errors['password_repeat']['class'] = ' has-error';
         $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']);
@@ -268,6 +294,8 @@ $smarty->assign('poll_type', $poll_type);
 $smarty->assign('poll_title', Utils::fromPostOrDefault('title', $_SESSION['form']->title));
 $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('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_name', Utils::fromPostOrDefault('name', $_SESSION['form']->admin_name));
 $smarty->assign('poll_mail', Utils::fromPostOrDefault('mail', $_SESSION['form']->admin_mail));
diff --git a/js/app/create_poll.js b/js/app/create_poll.js
index f98370a8..26fc42c0 100644
--- a/js/app/create_poll.js
+++ b/js/app/create_poll.js
@@ -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
      */
diff --git a/locale/en.json b/locale/en.json
index cf005a92..c412a76d 100644
--- a/locale/en.json
+++ b/locale/en.json
@@ -247,7 +247,10 @@
         "Password confirmation": "Confirmation",
         "Permissions": "Permissions",
         "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": {
         "Back to step 1": "Return to step 1",
diff --git a/locale/fr.json b/locale/fr.json
index d6288a48..6486504a 100644
--- a/locale/fr.json
+++ b/locale/fr.json
@@ -247,7 +247,10 @@
         "Password confirmation": "Confirmation",
         "Permissions": "Permissions",
         "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": {
         "Back to step 1": "Revenir à l’étape 1",
diff --git a/php.ini b/php.ini
index 347e2e39..bde5cfc8 100644
--- a/php.ini
+++ b/php.ini
@@ -4,3 +4,7 @@ log_errors = On
 error_log = /var/log/apache2/error.log
 ignore_repeated_errors = On
 register_globals = Off
+
+
+[Date]
+date.timezone = "Europe/Paris"
diff --git a/studs.php b/studs.php
index adb1eb19..1b71197b 100644
--- a/studs.php
+++ b/studs.php
@@ -30,6 +30,9 @@ use Framadate\Services\SecurityService;
 use Framadate\Services\SessionService;
 use Framadate\Utils;
 
+
+
+
 include_once __DIR__ . '/app/inc/init.php';
 
 /* Constantes */
@@ -231,5 +234,6 @@ $smarty->assign('hidden', $poll->hidden);
 $smarty->assign('accessGranted', $accessGranted);
 $smarty->assign('resultPubliclyVisible', $resultPubliclyVisible);
 $smarty->assign('editedVoteUniqueId', $editedVoteUniqueId);
+$smarty->assign('ValueMax', $poll->ValueMax);
 
 $smarty->display('studs.tpl');
diff --git a/tpl/create_poll.tpl b/tpl/create_poll.tpl
index d71e4f99..7167d22f 100644
--- a/tpl/create_poll.tpl
+++ b/tpl/create_poll.tpl
@@ -116,6 +116,41 @@
 
                 <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 *}
 
                     <div class="form-group {$errors['customized_url']['class']}">
diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl
index 0ccdcae5..6ebed255 100644
--- a/tpl/part/vote_table_classic.tpl
+++ b/tpl/part/vote_table_classic.tpl
@@ -160,21 +160,24 @@
                             <input type="text" id="name" name="name" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" />
                         </div>
                     </td>
+					{$i = 0}
                     {foreach $slots as $id=>$slot}
                         <td class="bg-info" headers="C{$id}">
                             <ul class="list-unstyled choice">
-                                <li class="yes">
-                                    <input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2" />
-                                    <label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{__('Poll results', 'Vote yes for')|html} {$slot->title|html}">
-                                        <i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span>
-                                    </label>
-                                </li>
-                                <li class="ifneedbe">
-                                    <input type="radio" id="i-choice-{$id}" name="choices[{$id}]" value="1" />
-                                    <label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{__('Poll results', 'Vote ifneedbe for')|html} {$slot->title|html}">
-                                        (<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
-                                    </label>
-                                </li>
+								{if $best_choices['y'][$i] lt $poll->ValueMax || $poll->ValueMax eq NULL}
+                               	 	<li class="yes">
+                                    	<input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2" />
+                                    	<label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{__('Poll results', 'Vote yes for')|html} {$slot->title|html}">
+                                       		<i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span>
+                                    	</label>
+                                	</li>
+                               		 <li class="ifneedbe">
+                                  	  <input type="radio" id="i-choice-{$id}" name="choices[{$id}]" value="1" />
+                                  	  <label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{__('Poll results', 'Vote ifneedbe for')|html} {$slot->title|html}">
+                                        <i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
+                                    	</label>
+                               	 	</li>
+								{/if}
                                 <li class="no">
                                     <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}">
@@ -186,6 +189,8 @@
                                 </li>
                             </ul>
                         </td>
+						{$i = $i+1}
+                        
                     {/foreach}
                     <td><button type="submit" class="btn btn-success btn-md" name="save" title="{__('Poll results', 'Save the choices')}">{__('Generic', 'Save')}</button></td>
                 </tr>
diff --git a/tpl/part/vote_table_date.tpl b/tpl/part/vote_table_date.tpl
index 6384b87d..2494be29 100644
--- a/tpl/part/vote_table_date.tpl
+++ b/tpl/part/vote_table_date.tpl
@@ -219,11 +219,17 @@
                             <input type="text" id="name" name="name" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" />
                         </div>
                     </td>
+				
+			
                     {$i = 0}
-                    {foreach $slots as $slot}
+                    {foreach $slots as $slot} 
                         {foreach $slot->moments as $moment}
+
+				
+
                             <td class="bg-info" headers="M{$headersM[$i]} D{$headersD[$i]} H{$headersH[$i]}">
                                 <ul class="list-unstyled choice">
+				{if $best_choices['y'][$i] lt $poll->ValueMax || $poll->ValueMax eq NULL}
                                     <li class="yes">
                                         <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}">
@@ -236,6 +242,9 @@
                                             (<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
                                         </label>
                                     </li>
+					
+				{/if}
+
                                     <li class="no">
                                         <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}">
@@ -247,6 +256,9 @@
                                     </li>
                                 </ul>
                             </td>
+
+				
+
                             {$i = $i+1}
                         {/foreach}
                     {/foreach}
-- 
GitLab