From: Roland Häder <roland@mxchange.org>
Date: Thu, 5 Nov 2009 18:25:39 +0000 (+0000)
Subject: Some more rewrites and fix for countPostSelection()
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9bd8a51d553d07c64aebb230714c5fd87258cc57;p=mailer.git

Some more rewrites and fix for countPostSelection()
---

diff --git a/inc/modules/admin/what-adminedit.php b/inc/modules/admin/what-adminedit.php
index cf97dffe96..ff42b89782 100644
--- a/inc/modules/admin/what-adminedit.php
+++ b/inc/modules/admin/what-adminedit.php
@@ -51,16 +51,12 @@ if (isGetRequestElementSet('sub')) {
 	$SUB = getRequestElement('sub');
 } // END - if
 
-// Get count of (maybe) selected menu points
-$chk = '0';
-if (isPostRequestElementSet('sel')) $chk = countPostSelection();
-
 // List all menu points and make them editable
-if ((isPostRequestElementSet('edit')) && ($chk > 0) && (!isDemoModeActive())) {
+if ((isPostRequestElementSet('edit')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
 	// Edit menu entries
 	// @TODO Kill all constants in this file
 	$content['sub'] = $SUB;
-	$content['chk'] = $chk;
+	$content['chk'] = countPostSelection();
 	$cnt = '0'; $SW = 2;
 	foreach (postRequestElement('sel') as $sel => $confirm) {
 		if ($confirm == 1) {
@@ -106,10 +102,10 @@ if ((isPostRequestElementSet('edit')) && ($chk > 0) && (!isDemoModeActive())) {
 
 	// Load template
 	loadTemplate('admin_amenu_edit_form', false, $content);
-} elseif ((isPostRequestElementSet('del')) && (!isDemoModeActive())) {
+} elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
 	// Prepare misc content
 	$content['sub'] = $SUB;
-	$content['chk'] = $chk;
+	$content['chk'] = countPostSelection();
 
 	// Del menu entries with or without confirmation
 	$SW = 2; $cnt = '0'; $OUT = '';
diff --git a/inc/modules/admin/what-del_holiday.php b/inc/modules/admin/what-del_holiday.php
index a61324a4f5..ab80774af0 100644
--- a/inc/modules/admin/what-del_holiday.php
+++ b/inc/modules/admin/what-del_holiday.php
@@ -44,12 +44,8 @@ if ((!defined('__SECURITY')) || (!isAdmin())) {
 // Add description as navigation point
 addMenuDescription('admin', __FILE__);
 
-// Check for selected holidays
-$SUM = '0';
-if (isPostRequestElementSet('sel')) $SUM = countPostSelection();
-
 // Shall I delete selected holidays???
-if ($SUM > 0) {
+if (countPostSelection() > 0) {
 	// Delete multiple holiday requests (for list_holiday)
 	$cnt = '0';
 	foreach (postRequestElement('sel') as $id => $sel) {
diff --git a/inc/modules/admin/what-guestedit.php b/inc/modules/admin/what-guestedit.php
index 566696a9d7..b31c8c5288 100644
--- a/inc/modules/admin/what-guestedit.php
+++ b/inc/modules/admin/what-guestedit.php
@@ -52,15 +52,11 @@ if (isGetRequestElementSet('sub')) {
 	$SUB = getRequestElement('sub');
 } // END - if
 
-// Get count of (maybe) selected menu points
-$chk = '0';
-if (isPostRequestElementSet('sel')) $chk = countPostSelection();
-
 // List all menu points and make them editable
-if ((isPostRequestElementSet('edit')) && ($chk > 0) && (!isDemoModeActive())) {
+if ((isPostRequestElementSet('edit')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
 	// Edit menu entries
 	$content['sub'] = $SUB;
-	$content['chk'] = $chk;
+	$content['chk'] = countPostSelection();
 
 	$cnt = '0'; $OUT = ''; $SW = 2;
 	foreach (postRequestElement('sel') as $sel => $confirm) {
@@ -104,10 +100,10 @@ if ((isPostRequestElementSet('edit')) && ($chk > 0) && (!isDemoModeActive())) {
 
 	// Load template
 	loadTemplate('admin_gmenu_edit_form', false, $content);
-} elseif ((isPostRequestElementSet('del')) && (!isDemoModeActive())) {
+} elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
 	// Del menu entries with or without confirmation
 	$content['sub'] = $SUB;
-	$content['chk'] = $chk;
+	$content['chk'] = countPostSelection();
 
 	$cnt = '0';
 	$OUT = '';
@@ -186,10 +182,10 @@ if ((isPostRequestElementSet('edit')) && ($chk > 0) && (!isDemoModeActive())) {
 			loadTemplate('admin_menu_unknown_okay', false, postRequestElement('ok'));
 			break;
 	} // END - switch
-} elseif ((isPostRequestElementSet('status')) && ($chk > 0) && (!isDemoModeActive())) {
+} elseif ((isPostRequestElementSet('status')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
 	// Change status (visible / locked)
 	$content['sub'] = $SUB;
-	$content['chk'] = $chk;
+	$content['chk'] = countPostSelection();
 
 	// Load template
 	$SW = 2; $cnt = '0'; $OUT = '';
diff --git a/inc/modules/admin/what-memedit.php b/inc/modules/admin/what-memedit.php
index 4bdeedc178..72ae2f4ddb 100644
--- a/inc/modules/admin/what-memedit.php
+++ b/inc/modules/admin/what-memedit.php
@@ -52,15 +52,11 @@ if (isGetRequestElementSet('sub')) {
 	$SUB = getRequestElement('sub');
 } // END - if
 
-// Get count of (maybe) selected menu points
-$chk = '0';
-if (isPostRequestElementSet('sel')) $chk = countPostSelection();
-
 // List all menu points and make them editable
-if ((isPostRequestElementSet('edit')) && ($chk > 0) && (!isDemoModeActive())) {
+if ((isPostRequestElementSet('edit')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
 	// Edit menu entries
 	$content['sub'] = $SUB;
-	$content['chk'] = $chk;
+	$content['chk'] = countPostSelection();
 	$SW = 2; $cnt = '0'; $OUT = '';
 	foreach (postRequestElement('sel') as $sel => $confirm) {
 		if ($confirm == 1) {
@@ -100,10 +96,10 @@ if ((isPostRequestElementSet('edit')) && ($chk > 0) && (!isDemoModeActive())) {
 
 	// Load template
 	loadTemplate('admin_mmenu_edit', false, $content);
-} elseif ((isPostRequestElementSet('del')) && ($chk > 0) && (!isDemoModeActive())) {
+} elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
 	// Del menu entries with or without confirmation
 	$content['sub'] = $SUB;
-	$content['chk'] = $chk;
+	$content['chk'] = countPostSelection();
 	$SW = 2; $cnt = '0'; $OUT = '';
 	foreach (postRequestElement('sel') as $sel => $confirm) {
 		if ($confirm == 1) {
@@ -139,10 +135,10 @@ if ((isPostRequestElementSet('edit')) && ($chk > 0) && (!isDemoModeActive())) {
 
 	// Load template
 	loadTemplate('admin_mmenu_delete', false, $content);
-} elseif ((isPostRequestElementSet('status')) && ($chk > 0) && (!isDemoModeActive())) {
+} elseif ((isPostRequestElementSet('status')) && (countPostSelection() > 0) && (!isDemoModeActive())) {
 	// Change status (visible / locked)
 	$content['sub'] = $SUB;
-	$content['chk'] = $chk;
+	$content['chk'] = countPostSelection();
 	$SW = 2; $cnt = '0'; $OUT = '';
 	foreach (postRequestElement('sel') as $sel => $confirm) {
 		if ($confirm == 1) {
diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php
index bc7e771463..cd1eddf236 100644
--- a/inc/wrapper-functions.php
+++ b/inc/wrapper-functions.php
@@ -428,8 +428,15 @@ function removeFile ($FQFN) {
 }
 
 // Wrapper for $_POST['sel']
-function countPostSelection () {
-	return countSelection(postRequestElement('sel'));
+function countPostSelection ($element = 'sel') {
+	// Is it set?
+	if (isPostRequestElementSet($element)) {
+		// Return counted elements
+		return countSelection(postRequestElement($element));
+	} else {
+		// Return zero if not found
+		return 0;
+	}
 }
 
 // Checks wether the config-local.php is loaded