From 905208c211ee88335485cb2acc74978f877bc85c Mon Sep 17 00:00:00 2001 From: Antonin 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 5c6ba56..358951f 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 59d6834..568adad 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 c6fade5..9faeed6 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 2b07f84..8eebe58 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 54c5030..9b33af3 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 1bbebcd..06775a5 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 ff70a2f..6f4fcd6 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 7cf1bdd..600b53a 100644 --- a/tpl/add_column.tpl +++ b/tpl/add_column.tpl @@ -11,10 +11,14 @@ {/block} {block name=main} +

{__('adminstuds', 'Column\'s adding')}

+ {* Messages *} + {include 'part/messages.tpl'} + {if $format === 'D'}
diff --git a/tpl/part/messages.tpl b/tpl/part/messages.tpl index e69de29..2bcb7b9 100644 --- a/tpl/part/messages.tpl +++ b/tpl/part/messages.tpl @@ -0,0 +1,25 @@ +{* Messages *} +
+ {if !empty($message)} + + {/if} +
+ + + \ No newline at end of file diff --git a/tpl/studs.tpl b/tpl/studs.tpl index fe4fb7f..5534868 100644 --- a/tpl/studs.tpl +++ b/tpl/studs.tpl @@ -13,30 +13,8 @@ {* Messages *} -
- {if !empty($message)} - - {/if} -
- - - + {include 'part/messages.tpl'} + {if !$accessGranted && !$resultPubliclyVisible}