From: Roland Häder <roland@mxchange.org>
Date: Sun, 3 Oct 2010 23:04:22 +0000 (+0000)
Subject: - Beg link does now (not yet implemented but prepared) log all referal URLs. It
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c9b17a86f4d62b50b8b1fbe6f9d88e6092430526;p=mailer.git

- Beg link does now (not yet implemented but prepared) log all referal URLs. It
  is also planed to not pay beg link calls without a referer (admin can setup
  it).
- The database layer is now aware of queries like
  "ALTER TABLE `foo` CHANGE `bar` `bazz` ...."
- Several minor fixes/improvements
- TODOs.txt updated
---

diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt
index c670c833e1..44c02fc533 100644
--- a/DOCS/TODOs.txt
+++ b/DOCS/TODOs.txt
@@ -1,7 +1,7 @@
 ### WARNING: THIS FILE IS AUTO-GENERATED BY ./DOCS/todo-builder.sh (uid=/user=quix0r) ###
 ### DO NOT EDIT THIS FILE. ###
 ./autoreg.php:58:// @TODO Add processing of request here
-./beg.php:163:			// @TODO Opps, what is missing here???
+./beg.php:171:			// @TODO Opps, what is missing here???
 ./birthday_confirm.php:93:		// @TODO Try to rewrite the following unset()
 ./inc/autopurge/purge-inact.php:55:	// @TODO Rewrite these if() blocks to a filter
 ./inc/cache/config-local.php:124:// @TODO Rewrite the following three constants, somehow...
@@ -60,9 +60,9 @@
 ./inc/language/refback_de.php:44:// @TODO Rewrite these constants to one
 ./inc/language/sponsor_de.php:117:// @TODO Rewrite these four constants to one and use sprintf()
 ./inc/libs/admins_functions.php:430:		// @TODO This can be, somehow, rewritten
-./inc/libs/beg_functions.php:52:		// @TODO Try to rewrite the following unset()
+./inc/libs/beg_functions.php:55:		// @TODO Try to rewrite the following unset()
 ./inc/libs/bonus_functions.php:199:		// @TODO Move this HTML to a template
-./inc/libs/bonus_functions.php:283:		// @TODO This query isn't right, it will only update if the user was for a longer time away!
+./inc/libs/bonus_functions.php:287:		// @TODO This query isn't right, it will only update if the user was for a longer time away!
 ./inc/libs/cache_functions.php:78:		// @TODO This should be rewritten not to load the cache file for just checking if it is there for save removal.
 ./inc/libs/doubler_functions.php:44:// @TODO Lame description
 ./inc/libs/doubler_functions.php:92:			// @TODO Can't this be moved into EL?
@@ -77,7 +77,8 @@
 ./inc/libs/register_functions.php:362:	// @TODO Wether the registration bonus should only be added to user directly or through referal system should be configurable
 ./inc/libs/sponsor_functions.php:159:					// @TODO Rewrite this to API function
 ./inc/libs/sponsor_functions.php:430:			// @TODO Rewrite this to API function
-./inc/libs/surfbar_functions.php:1538:		// @TODO This can be somehow rewritten
+./inc/libs/surfbar_functions.php:1026:	// @TODO Try to rewrite the following unset()
+./inc/libs/surfbar_functions.php:1541:		// @TODO This can be somehow rewritten
 ./inc/libs/surfbar_functions.php:710:// @TODO Can't we use our new expression language instead of this ugly code?
 ./inc/libs/surfbar_functions.php:951:	// @TODO Invalid salt should be refused
 ./inc/libs/task_functions.php:239:		// @TODO These can be rewritten to filter
@@ -86,9 +87,9 @@
 ./inc/libs/user_functions.php:144:	// @TODO These two constants are no longer used, maybe we reactivate this code?
 ./inc/libs/user_functions.php:232:// @TODO Double-check configuration entry here
 ./inc/libs/user_functions.php:325:			// @TODO Make this filter working: $ADDON = runFilterChain('post_login_update', $content);
-./inc/libs/user_functions.php:345:			// @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON));
-./inc/libs/user_functions.php:421:	// @TODO We should try to rewrite this to fetchUserData() somehow
-./inc/libs/user_functions.php:609:					// @TODO Try to rewrite the following unset()
+./inc/libs/user_functions.php:347:			// @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON));
+./inc/libs/user_functions.php:423:	// @TODO We should try to rewrite this to fetchUserData() somehow
+./inc/libs/user_functions.php:611:					// @TODO Try to rewrite the following unset()
 ./inc/libs/yoomedia_functions.php:114:	$response = YOOMEDIA_QUERY_API('out_textmail.php', true); // @TODO Ask Yoo!Media for test script
 ./inc/load_config.php:75:	// @TODO Rewrite them to avoid this else block
 ./inc/loader/load_cache-extension.php:13: * @TODO Rewrite this whole file to load_cache-extensions.php           *
@@ -174,11 +175,11 @@
 ./inc/modules/member/what-unconfirmed.php:206:				// @TODO This 'userid' cannot be saved because of encapsulated EL code
 ./inc/modules/order.php:74:		// @TODO Unused: 2,4
 ./inc/monthly/monthly_bonus.php:67:	// @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1172:	// @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1427:			// @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
-./inc/mysql-manager.php:1535:	// @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1902:			// @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1946:// @TODO Fix inconsistency between last_module and getWhat()
+./inc/mysql-manager.php:1188:	// @TODO Rewrite this to a filter
+./inc/mysql-manager.php:1443:			// @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
+./inc/mysql-manager.php:1551:	// @TODO Rewrite this to a filter
+./inc/mysql-manager.php:1922:			// @TODO Rewrite this to a filter
+./inc/mysql-manager.php:1966:// @TODO Fix inconsistency between last_module and getWhat()
 ./inc/mysql-manager.php:368:	// @TODO Try to rewrite this to one or more functions
 ./inc/mysql-manager.php:44:// @TODO Can we cache this?
 ./inc/reset/reset_beg.php:49:// @TODO This should be converted in a daily beg rallye
diff --git a/beg.php b/beg.php
index 60afef8e96..387c9e6acc 100644
--- a/beg.php
+++ b/beg.php
@@ -83,9 +83,11 @@ if (isGetRequestParameterSet('userid')) {
 
 	// Check if account was found
 	if ((isUserDataValid()) && (getUserData('status') == 'CONFIRMED')) {
-		// Multiply configured values with 100000 and divide with 100000 so we can also handle small values
-		// If we need more number behind the decimal dot then we just need to increase all these three
-		// numbers matching to the numbers behind the decimal dot. Simple! ;-)
+		/*
+		 * Multiply configured values with 100000 and divide with 100000 so we can also handle small values
+		 * If we need more number behind the decimal dot then we just need to increase all these three
+		 * numbers matching to the numbers behind the decimal dot. Simple! ;-)
+		 */
 		$points = mt_rand((getConfig('beg_points') * 100000), (getConfig('beg_points_max') * 100000)) / 100000;
 
 		// Set nickname / userid for template
@@ -109,14 +111,20 @@ if (isGetRequestParameterSet('userid')) {
 		if (((SQL_HASZERONUMS($result)) || (isAdmin())) && ($points > 0) && (!isMember()) && (getConfig('beg_pay_mode') == 'NONE')) {
 			// Admin is testing?
 			if (!isAdmin()) {
-				// Remember remote address, userid and timestamp for next click
-				// but only when there is no admin begging.
-				// Admins shall be able to test it!
+				/*
+				 * Remember remote address, userid and timestamp for next click
+				 * but only when there is no admin begging.
+				 * Admins shall be able to test it!
+				 */
 				SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_beg_ips` (`userid`, `remote_ip`,`sid`, `timeout`) VALUES ('%s','%s','%s', UNIX_TIMESTAMP())",
-					array(getUserData('userid'), detectRemoteAddr(), session_id()), __FILE__, __LINE__);
+					array(
+						getUserData('userid'),
+						detectRemoteAddr(),
+						session_id()
+					), __FILE__, __LINE__);
 
 				// Was is successfull?
-				$pay (SQL_AFFECTEDROWS() == 1);
+				$pay (!SQL_HASZEROAFFECTED());
 			} else {
 				// Is admin!
 				$pay = true;
diff --git a/click.php b/click.php
index a43e2cbfe9..3f303196ff 100644
--- a/click.php
+++ b/click.php
@@ -54,7 +54,7 @@ if ((isGetRequestParameterSet('user')) && (isGetRequestParameterSet('banner')))
 	SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1", array(bigintval(getRequestParameter('banner'))), __FILE__, __LINE__);
 
 	// A line has been updated?
-	if ((SQL_AFFECTEDROWS() == 1) && (isGetRequestParameterSet('user'))) {
+	if ((!SQL_HASZEROAFFECTED()) && (isGetRequestParameterSet('user'))) {
 		// Redirect to the user's referal link
 		redirectToUrl('ref.php?refid=' . bigintval(getRequestParameter('user')));
 	} // END - if
diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php
index d2d13ba453..8aeff002e2 100644
--- a/inc/db/lib-mysql3.php
+++ b/inc/db/lib-mysql3.php
@@ -382,7 +382,7 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) {
 	$tableName = str_replace('`', '', $tableArray[2]);
 
 	// Shall we add/drop?
-	if (((strpos($sql, 'ADD') !== false) || (strpos($sql, 'DROP') !== false)) && ($noIndex === true)) {
+	if (((strpos($sql, 'ADD') !== false) || (strpos($sql, 'DROP') !== false) || (strpos($sql, 'CHANGE') !== false)) && ($noIndex === true)) {
 		// Try two columns, one should fix
 		foreach (array(4,5) as $idx) {
 			// And column name as well
@@ -392,27 +392,31 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) {
 			$result = SQL_QUERY_ESC("SHOW COLUMNS FROM `%s` LIKE '%s'",
 				array($tableName, $columnName), __FUNCTION__, __LINE__);
 
-			// Do we have no entry on ADD or an entry on DROP?
-			// 123           4       4     3    3      4           4          32    23           4       4     3    3      4            4          321
-			if (((SQL_HASZERONUMS($result)) && (strpos($sql, 'ADD') !== false)) || ((SQL_NUMROWS($result) == 1) && (strpos($sql, 'DROP') !== false))) {
+			// Debug log
+			//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',idx=' . $idx . ',sql=' . $sql . ',hasZeroNums=' . intval(SQL_HASZERONUMS($result)));
+
+			// Do we have no entry on ADD or an entry on DROP/CHANGE?
+			// 123               4       43    3      4           4          32    23           4       4     3    3      4            4          32    23                4       43    3      4              4          3    3         321
+			if (((SQL_HASZERONUMS($result)) && (strpos($sql, 'ADD') !== false)) || ((!SQL_HASZERONUMS($result)) && (strpos($sql, 'DROP') !== false)) || ((!SQL_HASZERONUMS($result)) && (strpos($sql, 'CHANGE') !== false) && ($idx == 5))) {
 				// Do the query
 				//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Executing: ' . $sql);
 				$result = SQL_QUERY($sql, $F, $L, false);
 
 				// Skip further attempt(s)
 				break;
-			} elseif ((((SQL_NUMROWS($result) == 1) && (strpos($sql, 'ADD') !== false)) || ((SQL_HASZERONUMS($result)) && (strpos($sql, 'DROP') !== false))) && ($columnName != 'KEY')) {
+			//       1234                5       54    4      5           5          43    34                5       54    4      5            5          43    3      4              4          32    2                    21
+			} elseif ((((!SQL_HASZERONUMS($result)) && (strpos($sql, 'ADD') !== false)) || ((!SQL_HASZERONUMS($result)) && (strpos($sql, 'DROP') !== false)) || (strpos($sql, 'CHANGE') !== false)) && ($columnName != 'KEY')) {
 				// Abort here because it is alreay there
 				//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: ' . $sql);
 				break;
 			} elseif ($columnName != 'KEY') {
-				// Something didn't fit
-				//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Possible problem: ' . $sql);
+				// Something didn't fit, we better log it
+				logDebugMessage(__FUNCTION__, __LINE__, 'Possible problem: ' . $sql . ',hasZeroNums=' . intval(SQL_HASZERONUMS($result)) . '');
 			}
 		} // END - foreach
 	} elseif ((getConfig('_TABLE_TYPE') == 'InnoDB') && (strpos($sql, 'FULLTEXT') !== false)) {
 		// Skip this query silently
-		//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Skipped FULLTEXT: sql=%s,file=%s,line=%s", $sql, $F, $L));
+		//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Skipped FULLTEXT: sql=%s,columnName=%s,idx=%d,hasZeroNums=%d,file=%s,line=%s", $sql, $columnName, $idx, intval(SQL_HASZERONUMS($result)), $F, $L));
 	} elseif ($noIndex === false) {
 		// And column name as well
 		//* DEBUG: */ debugOutput(__LINE__.':tableArray=<pre>' . print_r($tableArray, true) . '</pre>');
@@ -545,6 +549,12 @@ function SQL_HASZERONUMS ($result) {
 	return (SQL_NUMROWS($result) === 0);
 }
 
+// Wrapper function to make code more readable
+function SQL_HASZEROAFFECTED () {
+	// Just pass it through
+	return (SQL_AFFECTEDROWS() === 0);
+}
+
 // Private function to prepare the SQL query string
 function SQL_PREPARE_SQL_STRING ($sqlString, $enableCodes = true) {
 	// Is it already cached?
diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php
index 95fbd32cfd..8fab51c468 100644
--- a/inc/extensions-functions.php
+++ b/inc/extensions-functions.php
@@ -475,7 +475,7 @@ function doExtensionSqls ($ext_id, $load_mode) {
 	runFilterChain('extension_' . $load_mode);
 
 	// Remove cache file(s) if extension is active
-	if (((isExtensionActive('cache')) && ((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
+	if (((isExtensionActive('cache')) && ((!SQL_HASZEROAFFECTED())) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
 		// Run filters
 		runFilterChain('post_extension_run_sql', getCurrentExtensionName());
 	} // END - if
@@ -1804,7 +1804,7 @@ function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
 		addExtensionSql($sql);
 	} elseif (isDebugModeEnabled()) {
 		// Double menus should be located and fixed!
-		logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s,active=%s detected.", $action, $what, $title, $active));
+		logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s,locked=%s,visible=%s detected.", $action, $what, $title, $locked, $visible));
 	}
 }
 
diff --git a/inc/extensions/ext-beg.php b/inc/extensions/ext-beg.php
index 1b29e1c7a2..d591d04bc8 100644
--- a/inc/extensions/ext-beg.php
+++ b/inc/extensions/ext-beg.php
@@ -41,10 +41,10 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Version number
-setThisExtensionVersion('0.2.8');
+setThisExtensionVersion('0.2.9');
 
 // Version history array (add more with , '0.1.0' and so on)
-setExtensionVersionHistory(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8'));
+setExtensionVersionHistory(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8', '0.2.9'));
 
 switch (getExtensionMode()) {
 	case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
@@ -62,6 +62,7 @@ switch (getExtensionMode()) {
 `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
 `remote_ip` VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
 `timeout` VARCHAR(10) NOT NULL DEFAULT '',
+`sid` VARCHAR(255) NOT NULL DEFAULT '',
 KEY (`userid`),
 PRIMARY KEY (`id`)
 ) TYPE={?_TABLE_TYPE?}");
@@ -70,9 +71,10 @@ PRIMARY KEY (`id`)
 	case 'remove': // Do stuff when removing extension
 		// SQL commands to run
 		addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_beg_ips`');
-		addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what`='config_beg' OR `what`='list_beg'");
+		addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_beg_referals`');
+		addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what` IN ('config_beg','list_beg','list_beg_referal_urls')");
 		addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `what`='beg'");
-		addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='beg' OR `what`='beg2'");
+		addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what` IN ('beg','beg2')");
 		break;
 
 	case 'activate': // Do stuff when admin activates this extension
@@ -249,7 +251,7 @@ PRIMARY KEY (`id`)
 				setExtensionUpdateNotes("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
 				break;
 
-			case '0.2.6': // SQL queries for v0.2.6
+ 			case '0.2.6': // SQL queries for v0.2.6
 				addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_beg_ips` ADD `sid` VARCHAR(255) NOT NULL DEFAULT ''");
 				addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `beg_pay_mode` ENUM('IMG','JS','BOTH','NONE') DEFAULT 'NONE' NOT NULL ;");
 
@@ -277,6 +279,24 @@ PRIMARY KEY (`id`)
 				// Update notes (these will be set as task text!)
 				setExtensionUpdateNotes("Umbenannt nach neuer Namenskonvention");
 				break;
+
+			case '0.2.9': // SQL queries for v0.2.9
+				addExtensionSql('DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_beg_referals`');
+				addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_beg_referals` (
+`id` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
+`userid` BIGINT( 20 ) UNSIGNED NULL DEFAULT NULL ,
+`remote_ip` VARCHAR( 15 ) NOT NULL DEFAULT '0.0.0.0',
+`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
+`referal_url` TINYTEXT NOT NULL ,
+INDEX ( `userid` )
+) ENGINE = {?_TABLE_TYPE?} COMMENT = 'Recorded Referal URLs'");
+
+				// Add admin menu
+				addAdminMenuSql('user','list_beg_referal_urls','Bettel-Referals auflisten','Listet alle Bettellink-Aufrufe inklusive Referal-URL auf.','13');
+
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Loggen der Referal-URLs hinzugef&uuml;gt.");
+				break;
 		} // END - switch
 		break;
 
@@ -290,7 +310,7 @@ PRIMARY KEY (`id`)
 		// Remove old entries
 		$OLD = getConfig('beg_timeout');
 		if (getConfig('beg_userid_timeout') > $OLD) $OLD = getConfig('beg_userid_timeout');
-		$result_ext = SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_beg_ips` WHERE `timeout` < (UNIX_TIMESTAMP() - ' . ($OLD + 60*60) . ')', __FILE__, __LINE__);
+		SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_beg_ips` WHERE `timeout` < (UNIX_TIMESTAMP() - ' . ($OLD + 60*60) . ')', __FILE__, __LINE__);
 
 		// Check for beg rallye is active and send mails out
 		if ((isBegRallyeEnabled()) && (isBegNewMemberNotifyEnabled())) {
diff --git a/inc/extensions/ext-booking.php b/inc/extensions/ext-booking.php
index 7900d6d41a..ea0d1b45b6 100644
--- a/inc/extensions/ext-booking.php
+++ b/inc/extensions/ext-booking.php
@@ -109,7 +109,7 @@ PRIMARY KEY (`id`)
 				// Update notes (these will be set as task text!)
 				setExtensionUpdateNotes('');
 				break;
-		}
+		} // END - switch
 
 	case 'modify': // When the extension got modified
 		break;
@@ -123,7 +123,7 @@ PRIMARY KEY (`id`)
 	default: // Unknown extension mode
 		logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));
 		break;
-}
+} // END - switch
 
 // [EOF]
 ?>
diff --git a/inc/extensions/ext-refback.php b/inc/extensions/ext-refback.php
index d7e07134f4..940a2cff79 100644
--- a/inc/extensions/ext-refback.php
+++ b/inc/extensions/ext-refback.php
@@ -61,7 +61,7 @@ PRIMARY KEY (`id`),
 UNIQUE `user_refid` (`userid`,`level`,`refid`),
 KEY (`level`),
 KEY (`refid`)
-) ENGINE={?_TABLE_TYPE?} COMMENT='User Referals With Refback'");
+) ENGINE = {?_TABLE_TYPE?} COMMENT='User Referals With Refback'");
 		addMemberMenuSql('main','refback','Ref-Back einstellen','N','Y',4);
 
 		// Execute this special file on registration
diff --git a/inc/extensions/ext-sql_patches.php b/inc/extensions/ext-sql_patches.php
index fc66df9d3f..9ae78ef366 100644
--- a/inc/extensions/ext-sql_patches.php
+++ b/inc/extensions/ext-sql_patches.php
@@ -720,7 +720,7 @@ CHANGE `what` `what` VARCHAR(50) NULL DEFAULT NULL');
 `added` DATETIME NOT NULL,
 PRIMARY KEY (`hostname`),
 INDEX (`ip`)
-) ENGINE={?_TABLE_TYPE?}");
+) ENGINE = {?_TABLE_TYPE?}");
 
 				// Configuration
 				addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `dns_cache_timeout` BIGINT(20) NOT NULL DEFAULT ' . (60*60*24));
diff --git a/inc/language/beg_de.php b/inc/language/beg_de.php
index ecbe31500b..7d2896f008 100644
--- a/inc/language/beg_de.php
+++ b/inc/language/beg_de.php
@@ -55,7 +55,7 @@ addMessages(array(
 	'BEG_CLICKS' => "Dies war insgesamt der <strong>%s.</strong> Klick auf sein Bettel-Link.",
 	'BEG_THANKS_FOR_CLICK' => "Danke f&uuml;r Ihre Spende.",
 	'BEG_CONTINUE_REGISTER' => "Und weiter geht es zur Anmeldung bei {?MAIN_TITLE?} ...",
-	'BEG_SORRY_ANOTHER_WAS_HERE_1' => "Oh schade! Es war vor kurzem schon einer hier! Das Mitglied ",
+	'BEG_SORRY_ANOTHER_WAS_HERE_1' => "Oh, schade! Es war vor kurzem schon einer hier! Das Mitglied ",
 	'BEG_SORRY_ANOTHER_WAS_HERE_2' => " hat von Ihnen auch keine ",
 	'BEG_SORRY_ANOTHER_WAS_HERE_3' => " {?POINTS?} erhalten.",
 	'BEG_THANKS_FOR_CLICK_AGAIN' => "Danke dennoch f&uuml;r den erneuten Klick.",
@@ -77,7 +77,7 @@ addMessages(array(
 	'ADMIN_SELECT_BEG_MODE' => "Verg&uuml;tungsmodus der erbettelten {?POINTS?}",
 	'BEG_MODE_DIRECT' => "Nur direktem Mitglied gutschreiben.",
 	'BEG_MODE_REF' => "Auch dem Werber des Mitgliedes gutschreiben.",
-	'BEG_SORRY_YOURE_LOGGED_IN_1' => "Oh schade! Sie haben vermutlich auf Ihren eigenen Bettel-Link mit der Mitglieder-Id ",
+	'BEG_SORRY_YOURE_LOGGED_IN_1' => "Oh, schade! Sie haben vermutlich auf Ihren eigenen Bettel-Link mit der Mitglieder-Id ",
 	'BEG_SORRY_YOURE_LOGGED_IN_2' => " geklickt. Sie haben somit auch keine ",
 	'BEG_SORRY_YOURE_LOGGED_IN_3' => " {?POINTS?} erhalten.",
 	'BEG_SAME_UID_AS_OWN' => "Mitglieder-Id des Webmasters benutzt.",
diff --git a/inc/language/de.php b/inc/language/de.php
index be7d4074ad..4abf6b23b8 100644
--- a/inc/language/de.php
+++ b/inc/language/de.php
@@ -119,7 +119,7 @@ addMessages(array(
 	'UNDO_SELECTIONS' => "Auswahl zur&uuml;cknehmen",
 	'ADMIN_EDIT_MENUS' => "Men&uuml;s bearbeiten",
 	'ADMIN_DELETE_MENUS' => "Men&uuml;s l&ouml;schen",
-	'ADMIN_EDIT_ADMIN_MENU' => "Admin-Men&uuml;eintr&auml;ge &auml;ndern",
+	'ADMIN_EDIT_ADMIN_MENU_TITLE' => "Admin-Men&uuml;eintr&auml;ge &auml;ndern",
 	'ADMIN_EDIT_MENU' => "Es soll/sollen <span class=\"data\">%s</span> Men&uuml;eintrag/-eintr&auml;ge ge&auml;ndert werden:",
 	'ADMIN_ENTRY_MODIFY' => "Eintrag",
 	'SUBMIT_CHANGES' => "&Auml;nderungen durchf&uuml;hren",
diff --git a/inc/libs/beg_functions.php b/inc/libs/beg_functions.php
index 6536b44c3d..90e61bdc45 100644
--- a/inc/libs/beg_functions.php
+++ b/inc/libs/beg_functions.php
@@ -42,6 +42,9 @@ if (!defined('__SECURITY')) {
 
 // Add points to user or begging rallye account
 function addPointsBeg ($userid, $points) {
+	// Default is not added
+	$added = false;
+
 	// Is begging rallye active?
 	if (isBegRallyeEnabled()) {
 		// Add points to rallye account
@@ -51,7 +54,7 @@ function addPointsBeg ($userid, $points) {
 		// Add points to account
 		// @TODO Try to rewrite the following unset()
 		unset($GLOBALS['ref_level']);
-		addPointsThroughReferalSystem('beg', $userid, $points, false, 0, strtolower(getConfig('beg_mode')));
+		$added = addPointsThroughReferalSystem('beg', $userid, $points, false, 0, strtolower(getConfig('beg_mode')));
 	}
 
 	// Subtract begged points from member account if the admin has selected one
@@ -59,6 +62,9 @@ function addPointsBeg ($userid, $points) {
 		// Subtract from this account
 		subtractPoints('beg_payout', getConfig('beg_userid'), $points);
 	} // END - if
+
+	// Return result
+	return $added;
 }
 
 // Checks wether beg_rallye is enabled
diff --git a/inc/libs/bonus_functions.php b/inc/libs/bonus_functions.php
index 286a79e3ee..2b75d7b96a 100644
--- a/inc/libs/bonus_functions.php
+++ b/inc/libs/bonus_functions.php
@@ -107,7 +107,7 @@ function addTurboBonus ($mid, $userid, $type) {
 			$points
 		), __FUNCTION__, __LINE__);
 
-	if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getConfig('bonus_mode') != 'ADD') && ($points > 0)) handleBonusPoints($points);
+	if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getBonusMode() != 'ADD') && ($points > 0)) handleBonusPoints($points);
 }
 
 //
@@ -214,7 +214,7 @@ function handleBonusPoints ($mode) {
 	if (!isBonusRallyeActive()) return;
 
 	// Switch to jackpot-mode when no UID is supplied but userid-mode is selected
-	if ((getConfig('bonus_mode') == 'UID') && (getBonusUserId() == '0') && (isExtensionActive('jackpot'))) {
+	if ((getBonusMode() == 'UID') && (getBonusUserId() == '0') && (isExtensionActive('jackpot'))) {
 		// Update database & config
 		updateConfiguration('bonus_mode', 'JACKPOT');
 	} // END - if
@@ -231,7 +231,7 @@ function handleBonusPoints ($mode) {
 	$total = getTotalPoints(getBonusUserId());
 
 	// Subtract points from...
-	switch (getConfig('bonus_mode')) {
+	switch (getBonusMode()) {
 		case 'JACKPOT': // ... jackpot
 			if ((isExtensionActive('jackpot')) && (subtractPointsFromJackpot($points) == -1) && (isValidUserId(getBonusUserId()))) {
 				if ($total >= $points) {
@@ -250,6 +250,10 @@ function handleBonusPoints ($mode) {
 				$dummy = subtractPointsFromJackpot($points);
 			}
 			break;
+
+		default: // This should not happen
+			debug_report_bug(__FUNCTION__, __LINE__, 'Invalid config entry ' . getBonusMode() . ' detected.');
+			break;
 	} // END - switch
 }
 
@@ -258,7 +262,7 @@ function purgeExpiredTurboBonus() {
 	// Remove entries
 	$result = SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE `timemark` < (UNIX_TIMESTAMP() - {?bonus_timeout?})', __FUNCTION__, __LINE__);
 
-	if (SQL_AFFECTEDROWS() > 0) {
+	if (!SQL_HASZEROAFFECTED()) {
 		// Send out email to admin
 		sendAdminNotification('{--ADMIN_AUTOPURGE_TURBO_SUBJECT--}', 'admin_autopurge_turbo', SQL_AFFECTEDROWS());
 	} // END - if
@@ -295,7 +299,7 @@ LIMIT 1',
 		);
 
 		// Updated entry?
-		$bonus = (SQL_AFFECTEDROWS() == 1);
+		$bonus = (!SQL_HASZEROAFFECTED());
 	} // END - if
 
 	if (($bonus === true) && (getRequestParameter('mode') == 'bonus')) {
@@ -347,5 +351,17 @@ function getBonusTimeout () {
 	return $GLOBALS[__FUNCTION__];
 }
 
+// Getter for bonus_mode
+function getBonusMode () {
+	// Do we have cache?
+	if (!isset($GLOBALS[__FUNCTION__])) {
+		// Determine it
+		$GLOBALS[__FUNCTION__] = getConfig('bonus_mode');
+	} // END - if
+
+	// Return cache
+	return $GLOBALS[__FUNCTION__];
+}
+
 // [EOF]
 ?>
diff --git a/inc/libs/booking_functions.php b/inc/libs/booking_functions.php
index 603f70a97c..7373071ba6 100644
--- a/inc/libs/booking_functions.php
+++ b/inc/libs/booking_functions.php
@@ -57,6 +57,9 @@ function addBookingRecord ($subject, $userid, $points, $mode) {
 function FILTER_ADD_BOOKING_RECORD ($data) {
 	// Add a record
 	addBookingRecord($data['subject'], $data['userid'], $data['points'], $data['mode']);
+
+	// Return data
+	return $data;
 }
 
 // [EOF]
diff --git a/inc/libs/mediadata_functions.php b/inc/libs/mediadata_functions.php
index 164a70f131..65ad9e0158 100644
--- a/inc/libs/mediadata_functions.php
+++ b/inc/libs/mediadata_functions.php
@@ -42,35 +42,64 @@ if (!defined('__SECURITY')) {
 
 // Update an entry
 function updateMediadataEntry ($keys_array, $mode, $value) {
+	// Default is nothing added/updated
+	$added = null;
+
+	// Do we have entries?
 	if (is_array($keys_array) && ($value > 0)) {
 		// Is an array so we can run it through
 		foreach ($keys_array as $key) {
 			// First check if it does exist
-			$result_media = SQL_QUERY_ESC("SELECT media_key FROM `{?_MYSQL_PREFIX?}_mediadata`
-WHERE media_key = '%s' LIMIT 1", array($key), __FUNCTION__, __LINE__);
+			$result_media = SQL_QUERY_ESC("SELECT
+	`media_key`
+FROM
+	`{?_MYSQL_PREFIX?}_mediadata`
+WHERE
+	`media_key` = '%s'
+LIMIT 1", array($key), __FUNCTION__, __LINE__);
 			if (SQL_NUMROWS($result_media) == 0) {
 				// Not found so we create it (mode will be ignored here!)
 				SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_mediadata` (`media_key`, `media_value`) VALUES ('%s', '%s')",
-				array($key, $value), __FUNCTION__, __LINE__);
+					array($key, $value), __FUNCTION__, __LINE__);
 			} else {
 				// Update entry
 				switch ($mode) {
 					case 'add': $mode = '+'; break;
 					case 'sub': $mode = '-'; break;
-				}
+				} // END - switch
 
 				if ($mode == 'init') {
 					// Initialize entry
 					SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_mediadata` SET `media_value`=%s WHERE `media_key`='%s' LIMIT 1",
-					array($value, $key), __FUNCTION__, __LINE__);
+						array($value, $key), __FUNCTION__, __LINE__);
 				} else {
 					// Update entry
 					SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_mediadata` SET `media_value`=`media_value`".$mode."%s WHERE `media_key`='%s' LIMIT 1",
-					array($value, $key), __FUNCTION__, __LINE__);
+						array($value, $key), __FUNCTION__, __LINE__);
 				}
 			}
-		}
-	}
+
+			// Check affected rows
+			if (is_null($added)) {
+				//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):added='.intval($added));
+				$added = (!SQL_HASZEROAFFECTED());
+				//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):added='.intval($added));
+			} else {
+				//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):added='.intval($added));
+				$added = ($added && (!SQL_HASZEROAFFECTED()));
+				//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):added='.intval($added));
+			}
+		} // END - foreach
+	} // END - if
+
+	// Zero entries are always added
+	if ($value == 0) {
+		// Is zero value, so we need to set $added here to avoid wrong false result
+		$added = true;
+	} // END - if
+
+	// Return result
+	return $added;
 }
 
 // Getter for entry
@@ -93,7 +122,10 @@ function getMediadataEntry ($key) {
 // Filter for updating media data
 function FILTER_UPDATE_MEDIADATA_ENTRY ($data) {
 	// Execute the filter function
-	updateMediadataEntry(array('total_points'), $data['mode'], $data['points']);
+	$data['added'] = ($data['added'] && updateMediadataEntry(array('total_points'), $data['mode'], $data['points']));
+
+	// Return data
+	return $data;
 }
 
 //
diff --git a/inc/libs/network_functions.php b/inc/libs/network_functions.php
index cec04a7b82..b3800e9a69 100644
--- a/inc/libs/network_functions.php
+++ b/inc/libs/network_functions.php
@@ -772,7 +772,7 @@ function doAdminNetworkProcessAddNetwork () {
 	setPostRequestParameter('network_id', SQL_INSERTID());
 
 	// Output message
-	if (SQL_AFFECTEDROWS() == 1) {
+	if (!SQL_HASZEROAFFECTED()) {
 		// Successfully added
 		loadTemplate('admin_network_added', false, postRequestArray());
 	} else {
@@ -1045,7 +1045,7 @@ function doAdminNetworkProcessAddNetworkType () {
 )", __FUNCTION__, __LINE__);
 
 	// Output message
-	if (SQL_AFFECTEDROWS() == 1) {
+	if (!SQL_HASZEROAFFECTED()) {
 		// Successfully added
 		loadTemplate('admin_network_type_added', false, postRequestArray());
 	} else {
@@ -1243,7 +1243,7 @@ function doAdminNetworkProcessAddNetworkParam () {
 )", __FUNCTION__, __LINE__);
 
 	// Output message
-	if (SQL_AFFECTEDROWS() == 1) {
+	if (!SQL_HASZEROAFFECTED()) {
 		// Successfully added
 		loadTemplate('admin_network_request_param_added', false, postRequestArray());
 	} else {
@@ -1289,7 +1289,7 @@ function doAdminNetworkProcessAddNetworkApiTranslation () {
 )", __FUNCTION__, __LINE__);
 
 	// Output message
-	if (SQL_AFFECTEDROWS() == 1) {
+	if (!SQL_HASZEROAFFECTED()) {
 		// Successfully added
 		loadTemplate('admin_network_api_translation_added', false, postRequestArray());
 	} else {
diff --git a/inc/libs/refback_functions.php b/inc/libs/refback_functions.php
index ec73f87dbb..575a918c28 100644
--- a/inc/libs/refback_functions.php
+++ b/inc/libs/refback_functions.php
@@ -389,7 +389,7 @@ function updateMemberRefbackPercents ($id, $percents) {
 		array($percents, $id, getMemberId()), __FUNCTION__, __LINE__);
 
 	// Entry updated?
-	if (SQL_AFFECTEDROWS() < 1) {
+	if (SQL_HASZEROAFFECTED()) {
 		// Entry not updated!
 		$status['message'] = '{--MEMBER_REFBACK_ERROR_NOT_UPDATED--}';
 		return $status;
diff --git a/inc/libs/sponsor_functions.php b/inc/libs/sponsor_functions.php
index 6c5dc2fd3e..ea4a23b039 100644
--- a/inc/libs/sponsor_functions.php
+++ b/inc/libs/sponsor_functions.php
@@ -370,7 +370,7 @@ LIMIT 1",
 			), __FUNCTION__, __LINE__);
 
 		// This update went fine?
-		$login = (SQL_AFFECTEDROWS() == 1);
+		$login = (!SQL_HASZEROAFFECTED());
 	} // END - if
 
 	// Return status
@@ -473,7 +473,7 @@ function saveSponsorData ($postData, $content) {
 	} // END - switch
 
 	// Has an entry updated?
-	if (SQL_AFFECTEDROWS() == 1) {
+	if (!SQL_HASZEROAFFECTED()) {
 		// Template and subject are set?
 		if (!empty($templ) && !empty($subj)) {
 			// Run SQL command and check for success
diff --git a/inc/libs/surfbar_functions.php b/inc/libs/surfbar_functions.php
index 5f14531f9f..340347e418 100644
--- a/inc/libs/surfbar_functions.php
+++ b/inc/libs/surfbar_functions.php
@@ -1022,9 +1022,12 @@ function SURFBAR_PAY_POINTS () {
 		subtractPoints(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), SURFBAR_GET_USERID(), SURFBAR_GET_COSTS());
 	} // END - if
 
-	// Book it to the user
 	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.getMemberId().',reward='.SURFBAR_GET_REWARD().'', false);
-	addPointsThroughReferalSystem(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), getMemberId(), SURFBAR_GET_DATA('reward'));
+	// @TODO Try to rewrite the following unset()
+	unset($GLOBALS['ref_level']);
+
+	// Book it to the user
+	addPointsThroughReferalSystem(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), getMemberId(), SURFBAR_GET_REWARD());
 }
 
 // Updates the statistics of current URL/userid
@@ -1053,7 +1056,7 @@ function SURFBAR_UPDATE_INSERT_STATS_RECORD () {
 		), __FUNCTION__, __LINE__);
 
 	// Was that update okay?
-	if (SQL_AFFECTEDROWS() < 1) {
+	if (SQL_HASZEROAFFECTED()) {
 		// No, then insert entry
 		SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_stats` (`stats_userid`, `stats_url_id`, `stats_count`) VALUES (%s,%s,1)",
 			array(
@@ -1092,7 +1095,7 @@ function SURFBAR_UPDATE_SALT_STATS () {
 	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'salt='.SURFBAR_GET_SALT().',id='.SURFBAR_GET_ID().',userid='.getMemberId().'', false);
 
 	// Was that okay?
-	if (SQL_AFFECTEDROWS() < 1) {
+	if (SQL_HASZEROAFFECTED()) {
 		// Insert missing entry!
 		SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_salts` (`salts_url_id`, `salts_userid`, `salts_last_salt`) VALUES (%s, %s, '%s')",
 			array(SURFBAR_GET_ID(), getMemberId(), SURFBAR_GET_SALT()), __FUNCTION__, __LINE__);
@@ -1102,7 +1105,7 @@ function SURFBAR_UPDATE_SALT_STATS () {
 	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'affectedRows='.SQL_AFFECTEDROWS().'', false);
 
 	// Return if the update was okay
-	return (SQL_AFFECTEDROWS() == 1);
+	return (!SQL_HASZEROAFFECTED());
 }
 
 // Check if the reload lock is active for given id
diff --git a/inc/libs/user_functions.php b/inc/libs/user_functions.php
index 1c7ae8a45b..1e5bfa4d52 100644
--- a/inc/libs/user_functions.php
+++ b/inc/libs/user_functions.php
@@ -339,7 +339,9 @@ function doUserLogin ($userid, $passwd, $successUrl = '', $errorUrl = 'modules.p
 				$GLOBALS['bonus_payed'] = true;
 
 				// Subtract login bonus from userid's account or jackpot
-				if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getConfig('bonus_mode') != 'ADD')) handleBonusPoints('login_bonus');
+				if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getBonusMode() != 'ADD')) {
+					handleBonusPoints('login_bonus');
+				} // END - if
 			} // END - if
 
 			// @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON));
@@ -353,7 +355,7 @@ function doUserLogin ($userid, $passwd, $successUrl = '', $errorUrl = 'modules.p
 				// Update database records
 				SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `total_logins`=`total_logins`+1" . $add . " WHERE `userid`=%s LIMIT 1",
 					array($userid), __FUNCTION__, __LINE__);
-				if (SQL_AFFECTEDROWS() == 1) {
+				if (!SQL_HASZEROAFFECTED()) {
 					// Is a success URL set?
 					if (empty($successUrl)) {
 						// Procedure to checking for login data
@@ -581,7 +583,7 @@ LIMIT 1",
 			array($hash), __FILE__, __LINE__);
 
 		// Was it updated?
-		if (SQL_AFFECTEDROWS() == 1) {
+		if (!SQL_HASZEROAFFECTED()) {
 			// Send email if updated
 			$message = loadEmailTemplate('confirm-member', $content, bigintval($userid));
 
diff --git a/inc/module-functions.php b/inc/module-functions.php
index 445c8505d4..d0f00c8fa6 100644
--- a/inc/module-functions.php
+++ b/inc/module-functions.php
@@ -298,7 +298,7 @@ VALUES
 			}
 
 			// Everthing is fine?
-			if (SQL_AFFECTEDROWS() < 1) {
+			if (SQL_HASZEROAFFECTED()) {
 				// Something bad happend!
 				setModuleStatus($module_chk, 'major');
 				return 'major';
diff --git a/inc/modules/admin/what-adminedit.php b/inc/modules/admin/what-adminedit.php
index 95f2180a2d..023110a00f 100644
--- a/inc/modules/admin/what-adminedit.php
+++ b/inc/modules/admin/what-adminedit.php
@@ -56,7 +56,7 @@ if ((isFormSent('edit')) && (ifPostContainsSelections()) && (!isDemoModeActive()
 	// @TODO Kill all constants in this file
 	$content['sub'] = $SUB;
 	$content['chk'] = countPostSelection();
-	$cnt = '0';
+	$cnt = '0'; $OUT = '';
 	foreach (postRequestParameter('sel') as $sel => $confirm) {
 		if ($confirm == 1) {
 			$cnt++;
diff --git a/inc/modules/admin/what-edit_emails.php b/inc/modules/admin/what-edit_emails.php
index f8e35fea0e..fd2032d99c 100644
--- a/inc/modules/admin/what-edit_emails.php
+++ b/inc/modules/admin/what-edit_emails.php
@@ -90,7 +90,7 @@ LIMIT 1",
 				bigintval(postRequestParameter('id')),
 			), __FILE__, __LINE__);
 
-		if (SQL_AFFECTEDROWS() == 1) {
+		if (!SQL_HASZEROAFFECTED()) {
 			$content = '{--SETTINGS_SAVED--}';
 		} else {
 			$content = '<span class="notice">{--SETTINGS_NOT_SAVED--}</span>';
diff --git a/inc/modules/admin/what-lock_user.php b/inc/modules/admin/what-lock_user.php
index ffb7175830..c56d63ff98 100644
--- a/inc/modules/admin/what-lock_user.php
+++ b/inc/modules/admin/what-lock_user.php
@@ -64,7 +64,7 @@ if (isGetRequestParameterSet('userid')) {
 			}
 
 			// Entry updated?
-			if (SQL_AFFECTEDROWS() == 1) {
+			if (!SQL_HASZEROAFFECTED()) {
 				// Send an email to the user! In later version you can optionally switch this feature off
 				$message = loadEmailTemplate('lock-user', array('text' => postRequestParameter('reason')), bigintval(getRequestParameter('userid')));
 
@@ -96,7 +96,7 @@ LIMIT 1",
 			}
 
 			// Entry updated?
-			if (SQL_AFFECTEDROWS() == 1) {
+			if (!SQL_HASZEROAFFECTED()) {
 				// Send an email to the user! In later version you can optionally switch this feature off
 				$message = loadEmailTemplate('unlock-user', array('text' => postRequestParameter('reason')), bigintval(getRequestParameter('userid')));
 
diff --git a/inc/modules/admin/what-refbanner.php b/inc/modules/admin/what-refbanner.php
index c2162c3f69..4dbd34cb38 100644
--- a/inc/modules/admin/what-refbanner.php
+++ b/inc/modules/admin/what-refbanner.php
@@ -92,7 +92,7 @@ VALUES ('%s','%s','%s')",
 	} // END - switch
 
 	// Check if we have saved (updated)
-	if (SQL_AFFECTEDROWS() == 1) {
+	if (!SQL_HASZEROAFFECTED()) {
 		// Updated!
 		$content = '{--SETTINGS_SAVED--}';
 	} else {
diff --git a/inc/modules/admin/what-unlock_sponsor.php b/inc/modules/admin/what-unlock_sponsor.php
index 86e4cdba73..704072bb8a 100644
--- a/inc/modules/admin/what-unlock_sponsor.php
+++ b/inc/modules/admin/what-unlock_sponsor.php
@@ -155,7 +155,7 @@ LIMIT 1",
 					array(bigintval($content['refid'])), __FILE__, __LINE__);
 
 				// Whas that update fine?
-				if (SQL_AFFECTEDROWS() == 1) {
+				if (!SQL_HASZEROAFFECTED()) {
 					// Load referal's data
 					$result = SQL_QUERY_ESC("SELECT
 	`id`, `gender`, `surname`, `family`, `email`,
diff --git a/inc/modules/guest/what-sponsor_login.php b/inc/modules/guest/what-sponsor_login.php
index 6d1255957e..73b9f6a815 100644
--- a/inc/modules/guest/what-sponsor_login.php
+++ b/inc/modules/guest/what-sponsor_login.php
@@ -99,7 +99,7 @@ LIMIT 1",
 				), __FILE__, __LINE__);
 
 			// Check on success
-			if (SQL_AFFECTEDROWS() == 1) {
+			if (!SQL_HASZEROAFFECTED()) {
 				// Prepare mail and send it to the sponsor
 				$message = loadEmailTemplate('sponsor_pending', $data);
 				sendEmail($data['email'], '{--SPONSOR_ACCOUNT_PENDING_SUBJECT--}', $message);
@@ -128,7 +128,7 @@ LIMIT 1",
 				array(bigintval($data['id']), getRequestParameter('hash')), __FILE__, __LINE__);
 
 			// Check on success
-			if (SQL_AFFECTEDROWS() == 1) {
+			if (!SQL_HASZEROAFFECTED()) {
 				// Sponsor account is unlocked again
 				loadTemplate('admin_settings_saved', false, '{--SPONSOR_ACCOUNT_IS_CONFIRMED_AGAIN--}');
 			} else {
diff --git a/inc/modules/member/what-mydata.php b/inc/modules/member/what-mydata.php
index a805b179bc..6b0a8d7321 100644
--- a/inc/modules/member/what-mydata.php
+++ b/inc/modules/member/what-mydata.php
@@ -293,7 +293,7 @@ LIMIT 1",
 				}
 
 				// Did something change?
-				if (SQL_AFFECTEDROWS() == 1) {
+				if (!SQL_HASZEROAFFECTED()) {
 					// Get all modes ...
 					$modes = explode(';', $mode);
 
diff --git a/inc/modules/order.php b/inc/modules/order.php
index eb99854749..fda6bbc7d1 100644
--- a/inc/modules/order.php
+++ b/inc/modules/order.php
@@ -70,7 +70,7 @@ if (empty($url)) {
 		array($type, bigintval(getRequestParameter('order')), getMemberId()), __FILE__, __LINE__);
 
 	// Finally is the entry valid?
-	if (SQL_AFFECTEDROWS() == 1) {
+	if (!SQL_HASZEROAFFECTED()) {
 		// @TODO Unused: 2,4
 		// Load mail again...              0         1          2             3            4         5       6            7
 		$result = SQL_QUERY_ESC("SELECT `subject`, `text`, `receivers`, `payment_id`, `timestamp`, `url`, `cat_id`, `target_send` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s AND `sender`=%s LIMIT 1",
diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php
index f3401f2891..749a368f42 100644
--- a/inc/mysql-manager.php
+++ b/inc/mysql-manager.php
@@ -693,10 +693,10 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) {
 	// Should we look for affected rows (only update) or found rows?
 	if ($updateEntry === true) {
 		// Check updated/affected rows
-		$ret = (SQL_AFFECTEDROWS() == 1);
+		$ret = (!SQL_HASZEROAFFECTED());
 	} else {
 		// Check found rows
-		$ret = (SQL_NUMROWS($result) == 1);
+		$ret = (!SQL_HASZERONUMS($result));
 	}
 
 	// Free memory
@@ -995,6 +995,9 @@ function getReferalLevelPercents ($level) {
  *               for default value will cause no referal will get points ever!!!)
  */
 function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $refid = '0', $add_mode = 'ref') {
+	// By default nothing has been added
+	$added = false;
+
 	//* DEBUG: */ debugOutput('----------------------- <font color="#00aa00">' . __FUNCTION__ . ' - ENTRY</font> ------------------------<ul><li>');
 	// Convert mode to lower-case
 	$add_mode = strtolower($add_mode);
@@ -1057,13 +1060,17 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
 			//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):data='.$data.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$add_mode.' - UPDATE! ('.SQL_AFFECTEDROWS().')');
 
 			// No entry updated?
-			if (SQL_AFFECTEDROWS() < 1) {
+			if (SQL_HASZEROAFFECTED()) {
 				// First ref in this level! :-)
 				SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`,`ref_depth`,`%s`) VALUES (%s,%s,%s)",
 					array($data, bigintval($userid), bigintval($GLOBALS['ref_level']), $ref_points), __FUNCTION__, __LINE__);
 				//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):data='.$data.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$add_mode.' - INSERTED! ('.SQL_AFFECTEDROWS().')');
 			} // END - if
 
+			// Check affected rows
+			$added = SQL_AFFECTEDROWS();
+			//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):added='.intval($added));
+
 			// Prepare data for the filter
 			$filterData = array(
 				'subject'  => $subject,
@@ -1074,10 +1081,15 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
 				'locked'   => $locked,
 				'mode'     => 'add',
 				'sub_mode' => $add_mode,
+				'added'    => $added
 			);
 
 			// Filter it now
-			runFilterChain('add_points', $filterData);
+			$filterData = runFilterChain('add_points', $filterData);
+
+			// Extract $added
+			$added = $filterData['added'];
+			//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):added='.intval($added));
 
 			// Points updated, maybe I shall send him an email?
 			if (($sendNotify === true) && (isValidUserId(getUserData('refid'))) && ($locked === false)) {
@@ -1115,12 +1127,13 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
 			if ((isValidUserId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($add_mode == 'ref')) {
 				// Then let's credit him here...
 				//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):userid='.$userid.',ref='.getUserData('refid').',points='.$points.' - ADVANCE!');
-				addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, $sendNotify, getUserData('refid'));
+				$added = ($added && addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, $sendNotify, getUserData('refid')));
 			} // END - if
 		} // END - if
 	} // END - if
 
-	//* DEBUG: */ debugOutput('</li></ul>----------------------- <font color="#aa0000">'.__FUNCTION__.' - EXIT</font> ------------------------<br />');
+	//* DEBUG: */ debugOutput('</li></ul>----------------------- <font color="#aa0000">'.__FUNCTION__.': added=' . intval($added) . ' - EXIT</font> ------------------------<br />');
+	return $added;
 }
 
 // Updates the referal counter
@@ -1135,10 +1148,13 @@ function updateReferalCounter ($userid) {
 
 	// When no entry was updated then we have to create it here
 	//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):updated=' . SQL_AFFECTEDROWS());
-	if (SQL_AFFECTEDROWS() < 1) {
+	if (SQL_HASZEROAFFECTED()) {
 		// First count!
 		SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refsystem` (`userid`, `level`, `counter`) VALUES (%s,%s,1)",
-			array(bigintval($userid), $GLOBALS['cache_array']['ref_level'][$userid]), __FUNCTION__, __LINE__);
+			array(
+				bigintval($userid),
+				$GLOBALS['cache_array']['ref_level'][$userid]
+			), __FUNCTION__, __LINE__);
 		//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):userid='.$userid);
 	} // END - if
 
@@ -1598,11 +1614,15 @@ function subtractPoints ($subject, $userid, $points) {
 		'subject' => $subject,
 		'userid'  => $userid,
 		'points'  => $points,
-		'mode'    => 'sub'
+		'mode'    => 'sub',
+		'added'   => (!SQL_HASZEROAFFECTED())
 	);
 
 	// Insert booking record
-	runFilterChain('sub_points', $filterData);
+	$filterData = runFilterChain('sub_points', $filterData);
+
+	// Return result
+	return $filterData['added'];
 }
 
 // "Getter" for total available receivers
diff --git a/inc/pool/pool-user.php b/inc/pool/pool-user.php
index 036aa3557b..35797ccffa 100644
--- a/inc/pool/pool-user.php
+++ b/inc/pool/pool-user.php
@@ -73,7 +73,7 @@ if (!SQL_HASZERONUMS($result_main)) {
 		if (isset($DATA['html_msg'])) $HTML = $DATA['html_msg'];
 
 		// Entry updated?
-		if (SQL_AFFECTEDROWS() == 1) {
+		if (!SQL_HASZEROAFFECTED()) {
 			// "Explode" all receivers into an array
 			if (isInString(';', $DATA['receivers'])) {
 				// There's more than one receiver in the list...
diff --git a/templates/de/html/admin/admin_user_details.tpl b/templates/de/html/admin/admin_user_details.tpl
index 9710237d18..dc85ff32d0 100644
--- a/templates/de/html/admin/admin_user_details.tpl
+++ b/templates/de/html/admin/admin_user_details.tpl
@@ -167,26 +167,6 @@
 			<strong>{%pipe,fixEmptyContentToDashes=$content[lock_reason]%}</strong>
 		</td>
 	</tr>
-	<!--
-	<tr>
-		<td align="center" class="top right">
-			{--_UNUSED--}:<br />
-			<strong>---</strong>
-		</td>
-		<td align="center" class="top right">
-			{--_UNUSED--}:<br />
-			<strong>---</strong>
-		</td>
-		<td align="center" class="top right">
-			{--_UNUSED--}:<br />
-			<strong>---</strong>
-		</td>
-		<td align="center" class="top">
-			{--_UNUSED--}:<br />
-			<strong>---</strong>
-		</td>
-	</tr>
-	//-->
 	<tr>
 		<td align="center" class="table_footer top" colspan="4">
 			<div>