From 905208c211ee88335485cb2acc74978f877bc85c Mon Sep 17 00:00:00 2001
From: Antonin <zepcome@gmail.com>
Date: Mon, 9 May 2016 15:01:39 +0200
Subject: [PATCH] Deny the possibility to add an empty slot.

---
 adminstuds.php        | 17 +++++++++++++----
 locale/de.json        |  3 ++-
 locale/en.json        |  3 ++-
 locale/es.json        |  3 ++-
 locale/fr.json        |  3 ++-
 locale/it.json        |  3 ++-
 locale/oc.json        |  3 ++-
 tpl/add_column.tpl    |  4 ++++
 tpl/part/messages.tpl | 25 +++++++++++++++++++++++++
 tpl/studs.tpl         | 26 ++------------------------
 10 files changed, 56 insertions(+), 34 deletions(-)

diff --git a/adminstuds.php b/adminstuds.php
index 5c6ba56e..358951f0 100644
--- a/adminstuds.php
+++ b/adminstuds.php
@@ -359,21 +359,30 @@ if (isset($_GET['delete_column'])) {
 // -------------------------------
 // Add a slot
 // -------------------------------
-
-if (isset($_GET['add_column'])) {
+function exit_displaying_add_column($message = null) {
+    global $smarty, $poll_id, $admin_poll_id, $poll;
     $smarty->assign('poll_id', $poll_id);
     $smarty->assign('admin_poll_id', $admin_poll_id);
     $smarty->assign('format', $poll->format);
     $smarty->assign('title', __('Generic', 'Poll') . ' - ' . $poll->title);
+    $smarty->assign('message', $message);
     $smarty->display('add_column.tpl');
     exit;
 }
+
+if (isset($_GET['add_column'])) {
+    exit_displaying_add_column();
+}
+
 if (isset($_POST['confirm_add_column'])) {
     try {
+        if (($poll->format === 'D' && empty($_POST['newdate']))
+         || ($poll->format === 'A' && empty($_POST['choice']))) {
+           exit_displaying_add_column(new Message('danger', __('Error', "Can't create an empty column.")));
+        }
         if ($poll->format === 'D') {
             $newdate = strip_tags($_POST['newdate']);
             $newmoment = str_replace(',', '-', strip_tags($_POST['newmoment']));
-
             $ex = explode('/', $newdate);
             $adminPollService->addDateSlot($poll_id, mktime(0, 0, 0, $ex[1], $ex[0], $ex[2]), $newmoment);
         } else {
@@ -383,7 +392,7 @@ if (isset($_POST['confirm_add_column'])) {
 
         $message = new Message('success', __('adminstuds', 'Choice added'));
     } catch (MomentAlreadyExistsException $e) {
-        $message = new Message('danger', __('Error', 'The column already exists'));
+        exit_displaying_add_column(new Message('danger', __('Error', 'The column already exists')));
     }
 }
 
diff --git a/locale/de.json b/locale/de.json
index 59d6834b..568adadf 100644
--- a/locale/de.json
+++ b/locale/de.json
@@ -397,7 +397,8 @@
         "Passwords do not match": "DE_Les mot de passes ne correspondent pas.",
         "Poll id already used": "DE_L'identifiant est déjà utilisé",
         "You can't select more than %d dates": "DE_Vous ne pouvez pas choisir plus de %d dates",
-        "Can't create the config.php file in '%s'.": "DE_Impossible de créer le fichier config.php dans '%s'."
+        "Can't create the config.php file in '%s'.": "DE_Impossible de créer le fichier config.php dans '%s'.",
+        "Can't create an empty column.": "DE_Impossible de créer une colonne vide."
     },
     "Check": {
         "Installation checking": "DE_Vérifications de l'installation",
diff --git a/locale/en.json b/locale/en.json
index c6fade52..9faeed6e 100644
--- a/locale/en.json
+++ b/locale/en.json
@@ -398,7 +398,8 @@
     "Passwords do not match": "Passwords do not match.",
     "Poll id already used": "Identifier is already used",
     "You can't select more than %d dates": "You can't select more than %d dates",
-    "Can't create the config.php file in '%s'.": "Can't create the config.php file in '%s'."
+    "Can't create the config.php file in '%s'.": "Can't create the config.php file in '%s'.",
+    "Can't create an empty column.": "Can't create an empty column."
   },
   "Check": {
     "Installation checking": "Installation checking",
diff --git a/locale/es.json b/locale/es.json
index 2b07f843..8eebe580 100644
--- a/locale/es.json
+++ b/locale/es.json
@@ -397,7 +397,8 @@
     "Passwords do not match": "ES_Les mot de passes ne correspondent pas.",
     "Poll id already used": "ES_L'identifiant est déjà utilisé",
     "You can't select more than %d dates": "ES_Vous ne pouvez pas choisir plus de %d dates",
-    "Can't create the config.php file in '%s'.": "ES_Impossible de créer le fichier config.php dans '%s'."
+    "Can't create the config.php file in '%s'.": "ES_Impossible de créer le fichier config.php dans '%s'.",
+    "Can't create an empty column.": "ES_Impossible de créer une colonne vide."
   },
   "Check": {
     "Installation checking": "ES_Vérifications de l'installation",
diff --git a/locale/fr.json b/locale/fr.json
index 54c50301..9b33af3c 100644
--- a/locale/fr.json
+++ b/locale/fr.json
@@ -397,7 +397,8 @@
     "Passwords do not match": "Les mots de passe ne correspondent pas.",
     "Poll id already used": "L'identifiant est déjà utilisé",
     "You can't select more than %d dates": "Vous ne pouvez pas choisir plus de %d dates",
-    "Can't create the config.php file in '%s'.": "Impossible de créer le fichier config.php dans '%s'."
+    "Can't create the config.php file in '%s'.": "Impossible de créer le fichier config.php dans '%s'.",
+    "Can't create an empty column.": "Impossible de créer une colonne vide."
   },
   "Check": {
     "Installation checking": "Vérifications de l'installation",
diff --git a/locale/it.json b/locale/it.json
index 1bbebcd6..06775a5d 100644
--- a/locale/it.json
+++ b/locale/it.json
@@ -397,7 +397,8 @@
     "Passwords do not match": "IT_Les mots de passe ne correspondent pas.",
     "Poll id already used": "IT_L'identifiant est déjà utilisé",
     "You can't select more than %d dates": "IT_Vous ne pouvez pas choisir plus de %d dates",
-    "Can't create the config.php file in '%s'.": "IT_Impossible de créer le fichier config.php dans '%s'."
+    "Can't create the config.php file in '%s'.": "IT_Impossible de créer le fichier config.php dans '%s'.",
+    "Can't create an empty column.": "IT_Impossible de créer une colonne vide."
   },
   "Check": {
     "Installation checking": "IT_Vérifications de l'installation",
diff --git a/locale/oc.json b/locale/oc.json
index ff70a2f5..6f4fcd63 100644
--- a/locale/oc.json
+++ b/locale/oc.json
@@ -397,7 +397,8 @@
     "Passwords do not match": "OC_Les mots de passe ne correspondent pas.",
     "Poll id already used": "OC_L'identifiant est déjà utilisé",
     "You can't select more than %d dates": "OC_Vous ne pouvez pas choisir plus de %d dates",
-    "Can't create the config.php file in '%s'.": "OC_Impossible de créer le fichier config.php dans '%s'."
+    "Can't create the config.php file in '%s'.": "OC_Impossible de créer le fichier config.php dans '%s'.",
+    "Can't create an empty column.": "OC_Impossible de créer une colonne vide."
   },
   "Check": {
     "Installation checking": "OC_Vérifications de l'installation",
diff --git a/tpl/add_column.tpl b/tpl/add_column.tpl
index 7cf1bdd2..600b53a2 100644
--- a/tpl/add_column.tpl
+++ b/tpl/add_column.tpl
@@ -11,10 +11,14 @@
 {/block}
 
 {block name=main}
+
     <form action="{poll_url id=$admin_poll_id admin=true}" method="POST">
         <div class="alert alert-info text-center">
             <h2>{__('adminstuds', 'Column\'s adding')}</h2>
 
+            {* Messages *}
+            {include 'part/messages.tpl'}
+
             {if $format === 'D'}
                 <div class="form-group">
                     <label for="newdate" class="col-md-4">{__('Generic', 'Day')}</label>
diff --git a/tpl/part/messages.tpl b/tpl/part/messages.tpl
index e69de29b..2bcb7b9b 100644
--- a/tpl/part/messages.tpl
+++ b/tpl/part/messages.tpl
@@ -0,0 +1,25 @@
+{* Messages *}
+<div id="message-container">
+    {if !empty($message)}
+        <div class="alert alert-dismissible alert-{$message->type|html} hidden-print" role="alert">
+            <button type="button" class="close" data-dismiss="alert" aria-label="{__('Generic', 'Close')}"><span aria-hidden="true">&times;</span></button>
+            {$message->message|html}
+            {if $message->link != null}
+                <div class="input-group input-group-sm">
+                        <span class="input-group-btn">
+                            <a {if $message->linkTitle != null} title="{$message->linkTitle|escape}" {/if} class="btn btn-default btn-sm" href="{$message->link}">
+                                {if $message->linkIcon != null}<i class="glyphicon glyphicon-pencil"></i>{if $message->linkTitle != null}<span class="sr-only">{$message->linkTitle|escape}</span>{/if}{/if}
+                            </a>
+                        </span>
+                    <input type="text" aria-hidden="true" value="{$message->link}" class="form-control" readonly="readonly" >
+                </div>
+                {if $message->includeTemplate != null}
+                    {$message->includeTemplate}
+                {/if}
+            {/if}
+        </div>
+    {/if}
+</div>
+<div id="nameErrorMessage" class="hidden alert alert-dismissible alert-danger hidden-print" role="alert">{__('Error', 'The name is invalid.')}<button type="button" class="close" data-dismiss="alert" aria-label="{__('Generic', 'Close')}"><span aria-hidden="true">&times;</span></button></div>
+<div id="genericErrorTemplate" class="hidden alert alert-dismissible alert-danger hidden-print" role="alert"><span class="contents"></span><button type="button" class="close" data-dismiss="alert" aria-label="{__('Generic', 'Close')}"><span aria-hidden="true">&times;</span></button></div>
+<div id="genericUnclosableSuccessTemplate" class="hidden alert alert-success hidden-print" role="alert"><span class="contents"></span></div>
\ No newline at end of file
diff --git a/tpl/studs.tpl b/tpl/studs.tpl
index fe4fb7f7..55348686 100644
--- a/tpl/studs.tpl
+++ b/tpl/studs.tpl
@@ -13,30 +13,8 @@
 
 
     {* Messages *}
-    <div id="message-container">
-        {if !empty($message)}
-            <div class="alert alert-dismissible alert-{$message->type|html} hidden-print" role="alert">
-                <button type="button" class="close" data-dismiss="alert" aria-label="{__('Generic', 'Close')}"><span aria-hidden="true">&times;</span></button>
-                {$message->message|html}
-                {if $message->link != null}
-                    <div class="input-group input-group-sm">
-                        <span class="input-group-btn">
-                            <a {if $message->linkTitle != null} title="{$message->linkTitle|escape}" {/if} class="btn btn-default btn-sm" href="{$message->link}">
-                                {if $message->linkIcon != null}<i class="glyphicon glyphicon-pencil"></i>{if $message->linkTitle != null}<span class="sr-only">{$message->linkTitle|escape}</span>{/if}{/if}
-                            </a>
-                        </span>
-                        <input type="text" aria-hidden="true" value="{$message->link}" class="form-control" readonly="readonly" >
-                    </div>
-                    {if $message->includeTemplate != null}
-                        {$message->includeTemplate}
-                    {/if}
-                {/if}
-            </div>
-        {/if}
-    </div>
-    <div id="nameErrorMessage" class="hidden alert alert-dismissible alert-danger hidden-print" role="alert">{__('Error', 'The name is invalid.')}<button type="button" class="close" data-dismiss="alert" aria-label="{__('Generic', 'Close')}"><span aria-hidden="true">&times;</span></button></div>
-    <div id="genericErrorTemplate" class="hidden alert alert-dismissible alert-danger hidden-print" role="alert"><span class="contents"></span><button type="button" class="close" data-dismiss="alert" aria-label="{__('Generic', 'Close')}"><span aria-hidden="true">&times;</span></button></div>
-    <div id="genericUnclosableSuccessTemplate" class="hidden alert alert-success hidden-print" role="alert"><span class="contents"></span></div>
+    {include 'part/messages.tpl'}
+
 
     {if !$accessGranted && !$resultPubliclyVisible}
 
-- 
GitLab