From a3f5763edd1422fe51eb5b210bebc0dfd940ebaa Mon Sep 17 00:00:00 2001
From: Antonin <zepcome@gmail.com>
Date: Sun, 5 Apr 2015 17:44:29 +0200
Subject: [PATCH] New edition possibility is taken into account
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

	- Also added Framadate\Message à link attribute
	- Added local anchor #edit with vote edition
	- For now, when the poll owner check the new edit option (ie: "Votes are editable solely by their owner"), users get their update link on vote creation
---
 adminstuds.php                    | 12 +++++++++---
 app/classes/Framadate/FramaDB.php |  2 +-
 app/classes/Framadate/Message.php |  4 +++-
 app/classes/Framadate/Utils.php   |  4 ++--
 app/inc/smarty.php                |  4 ++--
 locale/de.json                    |  4 +++-
 locale/en.json                    |  4 +++-
 locale/es.json                    |  4 +++-
 locale/fr.json                    |  4 +++-
 studs.php                         |  8 +++++++-
 tpl/part/poll_info.tpl            |  1 +
 tpl/part/vote_table_classic.tpl   |  4 ++--
 tpl/part/vote_table_date.tpl      |  5 ++---
 tpl/studs.tpl                     |  2 +-
 14 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/adminstuds.php b/adminstuds.php
index b7fe9592..997788eb 100644
--- a/adminstuds.php
+++ b/adminstuds.php
@@ -22,6 +22,7 @@ use Framadate\Services\InputService;
 use Framadate\Services\LogService;
 use Framadate\Message;
 use Framadate\Utils;
+use Framadate\Editable;
 
 include_once __DIR__ . '/app/inc/init.php';
 
@@ -95,17 +96,22 @@ if (isset($_POST['update_poll_info'])) {
         switch ($rules) {
             case 0:
                 $poll->active = false;
-                $poll->editable = false;
+                $poll->editable = Editable::NOT_EDITABLE;
                 $updated = true;
                 break;
             case 1:
                 $poll->active = true;
-                $poll->editable = false;
+                $poll->editable = Editable::NOT_EDITABLE;
                 $updated = true;
                 break;
             case 2:
                 $poll->active = true;
-                $poll->editable = true;
+                $poll->editable = Editable::EDITABLE_BY_ALL;
+                $updated = true;
+                break;
+            case 3:
+                $poll->active = true;
+                $poll->editable = Editable::EDITABLE_BY_OWN;
                 $updated = true;
                 break;
         }
diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php
index ba1b2500..8159b331 100644
--- a/app/classes/Framadate/FramaDB.php
+++ b/app/classes/Framadate/FramaDB.php
@@ -131,7 +131,7 @@ class FramaDB {
         $newVote->id = $this->pdo->lastInsertId();
         $newVote->name = $name;
         $newVote->choices = $choices;
-        $newVote->token = $token;
+        $newVote->uniqId = $token;
 
         return $newVote;
     }
diff --git a/app/classes/Framadate/Message.php b/app/classes/Framadate/Message.php
index 9819e000..c7d7edea 100644
--- a/app/classes/Framadate/Message.php
+++ b/app/classes/Framadate/Message.php
@@ -22,10 +22,12 @@ class Message {
 
     var $type;
     var $message;
+    var $link;
 
-    function __construct($type, $message) {
+    function __construct($type, $message, $link=null) {
         $this->type = $type;
         $this->message = $message;
+        $this->link = $link;
     }
 
 }
diff --git a/app/classes/Framadate/Utils.php b/app/classes/Framadate/Utils.php
index 6a91a271..9c0ab32d 100644
--- a/app/classes/Framadate/Utils.php
+++ b/app/classes/Framadate/Utils.php
@@ -110,7 +110,7 @@ class Utils {
             } else {
                 $url = str_replace('/admin', '', self::get_server_name()) . $id;
                 if ($vote_id != '') {
-                    $url .= '/vote/'.$vote_id;
+                    $url .= '/vote/'.$vote_id."#edit";
                 }
             }
         } else {
@@ -119,7 +119,7 @@ class Utils {
             } else {
                 $url = str_replace('/admin', '', self::get_server_name()) . 'studs.php?poll=' . $id;
                 if ($vote_id != '') {
-                    $url .= '&vote='.$vote_id;
+                    $url .= '&vote='.$vote_id."#edit";
                 }
             }
         }
diff --git a/app/inc/smarty.php b/app/inc/smarty.php
index 87e80462..98ad34bd 100644
--- a/app/inc/smarty.php
+++ b/app/inc/smarty.php
@@ -47,8 +47,8 @@ if ($_SERVER['FRAMADATE_DEVMODE']) {
 
 function smarty_function_poll_url($params, Smarty_Internal_Template $template) {
     $poll_id =  filter_var($params['id'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
-    $admin =  $params['admin']?true:false;
-    $vote_unique_id = filter_var($params['vote_id'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
+    $admin =  (isset($params['admin']) && $params['admin']) ? true : false;
+    $vote_unique_id = isset($params['vote_id']) ? filter_var($params['vote_id'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]) : '';
 
     // If filter_var fails (i.e.: hack tentative), it will return false. At least no leak is possible from this.
 
diff --git a/locale/de.json b/locale/de.json
index 9a99039d..a28e227f 100644
--- a/locale/de.json
+++ b/locale/de.json
@@ -111,6 +111,7 @@
         "Votes and comments are locked": "Abstimmungen und Kommentare sind gesperrt",
         "Votes and comments are open": "Abstimmungen und Kommentare sind möglich",
         "Votes are editable": "Die Abstimmungen können geändert werden",
+        "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."
@@ -144,7 +145,8 @@
         "If you want to vote in this poll, you have to give your name, choose the values that fit best for you and validate with the plus button at the end of the line.": "Wenn Sie bei dieser Umfrage abstimmen möchten, müssen Sie ihren Namen angeben. Wählen Sie die Optionen, die für Sie am besten passen und bestätigen Sie diese über den Plus-Button am Ende der Zeile.",
         "POLL_LOCKED_WARNING": "Die Administration gesperrt diese Umfrage. Bewertungen und Kommentare werden eingefroren, es ist nicht mehr möglich, teilzunehmen",
         "The poll is expired, it will be deleted soon.": "Die Umfrage ist abgelaufen, es wird bald gelöscht werden.",
-        "Deletion date:": "Löschdatum:"
+        "Deletion date:": "Löschdatum:",
+        "Your vote has been registered successfully, but be careful : regarding this poll options, you need to keep this personal link to edit your own vote : ": "DE_Votre vote a bien été pris en compte, mais faites attention : ce sondage n'autorise l'édition de votre vote qu'avec le lien personnalisé suivant ; conservez le précieusement ! "
     },
     "adminstuds": {
         "As poll administrator, you can change all the lines of this poll with this button": "Als Administrator der Umfrage, können Sie alle Zeilen der Umfrage über diesen Button ändern",
diff --git a/locale/en.json b/locale/en.json
index 06d02978..b69babf5 100644
--- a/locale/en.json
+++ b/locale/en.json
@@ -112,6 +112,7 @@
     "Votes and comments are locked": "Votes and comments are locked",
     "Votes and comments are open": "Votes and comments are open",
     "Votes are editable": "Votes are editable",
+    "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."
@@ -145,7 +146,8 @@
     "If you want to vote in this poll, you have to give your name, choose the values that fit best for you and validate with the plus button at the end of the line.": "If you want to vote in this poll, you have to give your name, choose the values that fit best for you and validate with the plus button at the end of the line.",
     "POLL_LOCKED_WARNING": "The administration locked this poll. Votes and comments are frozen, it is no longer possible to participate",
     "The poll is expired, it will be deleted soon.":  "The poll is expired, it will be deleted soon.",
-    "Deletion date:": "Deletion date:"
+    "Deletion date:": "Deletion date:",
+    "Your vote has been registered successfully, but be careful : regarding this poll options, you need to keep this personal link to edit your own vote : ": "Your vote has been registered successfully, but be careful : regarding this poll options, you need to keep this personal link to edit your own vote : "
   },
   "adminstuds": {
     "As poll administrator, you can change all the lines of this poll with this button": "As poll administrator, you can change all the lines of this poll with this button",
diff --git a/locale/es.json b/locale/es.json
index 55aa4557..ad35a9ab 100644
--- a/locale/es.json
+++ b/locale/es.json
@@ -111,6 +111,7 @@
         "Votes and comments are locked": "ES_Les votes et commentaires sont verrouillés",
         "Votes and comments are open": "ES_Les votes et commentaires sont ouverts",
         "Votes are editable": "ES_Les votes sont modifiables",
+        "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."
@@ -144,7 +145,8 @@
         "If you want to vote in this poll, you have to give your name, choose the values that fit best for you and validate with the plus button at the end of the line.": "Para participar a esta encuesta, introduzca su nombre, elige todas las valores que son apriopriadas y validar su seleccion con el botón verde a la fin de línea.",
         "POLL_LOCKED_WARNING": "ES_L'administrateur a verrouillé ce sondage. Les votes et commentaires sont gelés, il n'est plus possible de participer",
         "The poll is expired, it will be deleted soon.": "ES_Le sondage a expiré, il sera bientôt supprimé.",
-        "Deletion date:": "ES_Date de suppression :"
+        "Deletion date:": "ES_Date de suppression :",
+        "Your vote has been registered successfully, but be careful : regarding this poll options, you need to keep this personal link to edit your own vote : ": "ES_Votre vote a bien été pris en compte, mais faites attention : ce sondage n'autorise l'édition de votre vote qu'avec le lien personnalisé suivant ; conservez le précieusement ! "
     },
     "adminstuds": {
         "As poll administrator, you can change all the lines of this poll with this button": "En calidad de administrador, Usted puede cambiar todas la líneas de este encuesta con este botón",
diff --git a/locale/fr.json b/locale/fr.json
index 21261d1f..241836d0 100644
--- a/locale/fr.json
+++ b/locale/fr.json
@@ -111,6 +111,7 @@
     "Votes and comments are locked": "Les votes et commentaires sont verrouillés",
     "Votes and comments are open": "Les votes et commentaires sont ouverts",
     "Votes are editable": "Les votes sont modifiables",
+    "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."
@@ -144,7 +145,8 @@
     "If you want to vote in this poll, you have to give your name, choose the values that fit best for you and validate with the plus button at the end of the line.": "Pour participer à ce sondage, veuillez entrer votre nom, choisir toutes les valeurs qui vous conviennent et valider votre choix avec le bouton en bout de ligne.",
     "POLL_LOCKED_WARNING": "L'administrateur a verrouillé ce sondage. Les votes et commentaires sont gelés, il n'est plus possible de participer",
     "The poll is expired, it will be deleted soon.": "Le sondage a expiré, il sera bientôt supprimé.",
-    "Deletion date:": "Date de suppression :"
+    "Deletion date:": "Date de suppression :",
+    "Your vote has been registered successfully, but be careful : regarding this poll options, you need to keep this personal link to edit your own vote : ": "Votre vote a bien été pris en compte, mais faites attention : ce sondage n'autorise l'édition de votre vote qu'avec le lien personnalisé suivant ; conservez le précieusement ! "
   },
   "adminstuds": {
     "As poll administrator, you can change all the lines of this poll with this button": "En tant qu'administrateur, vous pouvez modifier toutes les lignes de ce sondage avec ce bouton",
diff --git a/studs.php b/studs.php
index c9659177..142a371d 100644
--- a/studs.php
+++ b/studs.php
@@ -22,6 +22,7 @@ use Framadate\Services\InputService;
 use Framadate\Services\MailService;
 use Framadate\Message;
 use Framadate\Utils;
+use Framadate\Editable;
 
 include_once __DIR__ . '/app/inc/init.php';
 
@@ -155,7 +156,12 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
         // Add vote
         $result = $pollService->addVote($poll_id, $name, $choices);
         if ($result) {
-            $message = new Message('success', _('Update vote successfully.'));
+            if ($poll->editable == Editable::EDITABLE_BY_OWN) {
+                $urlEditVote = Utils::getUrlSondage($poll_id, false, $result->uniqId);
+                $message = new Message('success', __('studs', "Your vote has been registered successfully, but be careful : regarding this poll options, you need to keep this personal link to edit your own vote : "), $urlEditVote);
+            } else {
+                $message = new Message('success', _('Update vote successfully.'));
+            }
             sendUpdateNotification($poll, $mailService, $name, ADD_VOTE);
         } else {
             $message = new Message('danger', _('Update vote failed.'));
diff --git a/tpl/part/poll_info.tpl b/tpl/part/poll_info.tpl
index b39d1c91..645f9b1e 100644
--- a/tpl/part/poll_info.tpl
+++ b/tpl/part/poll_info.tpl
@@ -144,6 +144,7 @@
                                     <option value="0"{if $rule_id==0} selected="selected"{/if}>{__('PollInfo', 'Votes and comments are locked')}</option>
                                     <option value="1"{if $rule_id==1} selected="selected"{/if}>{__('PollInfo', 'Votes and comments are open')}</option>
                                     <option value="2"{if $rule_id==2} selected="selected"{/if}>{__('PollInfo', 'Votes are editable')}</option>
+                                    <option value="3"{if $rule_id==3} selected="selected"{/if}>{__('PollInfo', 'Votes are editable solely by their owner.')}</option>
                                 </select>
                                 <span class="input-group-btn">
                                     <button type="submit" name="update_poll_info" value="rules" class="btn btn-success" title="{__('PollInfo', 'Save the new rules')}"><span class="glyphicon glyphicon-ok"></span><span class="sr-only">{__('Generic', 'Save')}</span></button>
diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl
index 786ab3dd..3183a113 100644
--- a/tpl/part/vote_table_classic.tpl
+++ b/tpl/part/vote_table_classic.tpl
@@ -37,7 +37,7 @@
 
                     {if $editingVoteId === $vote->uniqId}
                         <td class="bg-info" style="padding:5px">
-                            <div class="input-group input-group-sm">
+                            <div class="input-group input-group-sm" id="edit">
                                 <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                                 <input type="text" id="name" name="name" value="{$vote->name|html}" class="form-control" title="{__('Genric', 'Your name')}" placeholder="{__('Genric', 'Your name')}" />
                             </div>
@@ -86,7 +86,7 @@
 
                         {/foreach}
 
-                        {if $active && $poll->editable && !$expired}
+                        {if $active && !$expired && ($poll->editable == constant('Framadate\Editable::EDITABLE_BY_ALL') or $admin)}
                             <td>
                                 <a href="{poll_url id=$poll->id vote_id=$vote->uniqId}" class="btn btn-link btn-sm" title="{__('Poll results', 'Edit the line:')|html} {$vote->name|html}">
                                     <span class="glyphicon glyphicon-pencil"></span><span class="sr-only">{__('Generic', 'Edit')}</span>
diff --git a/tpl/part/vote_table_date.tpl b/tpl/part/vote_table_date.tpl
index c081576c..49f19a51 100644
--- a/tpl/part/vote_table_date.tpl
+++ b/tpl/part/vote_table_date.tpl
@@ -82,9 +82,8 @@
                     {* Edited line *}
 
                     {if $editingVoteId === $vote->uniqId && !$expired}
-
                         <td class="bg-info" style="padding:5px">
-                            <div class="input-group input-group-sm">
+                            <div class="input-group input-group-sm" id="edit">
                                 <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                                 <input type="text" id="name" name="name" value="{$vote->name|html}" class="form-control" title="{__('Generic', 'Your name')}" placeholder="{__('Generic', 'Your name')}" />
                             </div>
@@ -134,7 +133,7 @@
 
                         {/foreach}
 
-                        {if $active && $poll->editable && !$expired}
+                        {if $active && !$expired && ($poll->editable == constant('Framadate\Editable::EDITABLE_BY_ALL') or $admin)}
                             <td>
                                 <a href="{poll_url id=$poll->id vote_id=$vote->uniqId}" class="btn btn-link btn-sm" title="{__('Poll results', 'Edit the line:')|escape} {$vote->name|html}">
                                     <span class="glyphicon glyphicon-pencil"></span><span class="sr-only">{__('Generic', 'Edit')}</span>
diff --git a/tpl/studs.tpl b/tpl/studs.tpl
index 10d1c040..e553fd44 100644
--- a/tpl/studs.tpl
+++ b/tpl/studs.tpl
@@ -9,7 +9,7 @@
 
     <div id="message-container">
         {if !empty($message)}
-            <div class="alert alert-dismissible alert-{$message->type|html}" role="alert">{$message->message|html}<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>
+            <div class="alert alert-dismissible alert-{$message->type|html}" role="alert">{$message->message|html}{if $message->link != null}<br/><a href="{$message->link}">{$message->link}</a>{/if}<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>
         {/if}
     </div>
     <div id="nameErrorMessage" class="hidden alert alert-dismissible alert-danger" role="alert">{__('PollInfo', 'The name is invalid.')}<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>
-- 
GitLab