From 4fef71140a7d5faeaff256ab7c5bf4616c671f63 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Wed, 3 Oct 2012 17:20:38 +0000
Subject: [PATCH] Mailer project continued: - New filter chain
 'member_admin_actions' allows "hooking" of more admin   member actions in
 what=list_user listing. - Added 'list_refs' and list_links' as default admin
 actions - Other minor fixes - TODOs.txt updated

---
 DOCS/TODOs.txt                 | 54 ++++++++++++++++++----------------
 inc/extensions/ext-booking.php |  2 ++
 inc/filter/booking_filter.php  | 13 +++++++-
 inc/language/booking_de.php    |  3 ++
 inc/language/user_de.php       | 20 ++++++++-----
 inc/mysql-manager.php          | 10 +++++--
 inc/template-functions.php     | 20 ++++++-------
 inc/wrapper-functions.php      | 18 ++++++++++--
 8 files changed, 92 insertions(+), 48 deletions(-)

diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt
index b4f89f440e..1fae91354a 100644
--- a/DOCS/TODOs.txt
+++ b/DOCS/TODOs.txt
@@ -43,7 +43,7 @@
 ./inc/extensions/ext-rallye.php:94:		// @TODO Fix config_rallye_prices to list_rallye_prices
 ./inc/extensions/ext-yoomedia.php:121:		// @TODO Can this be moved into a database table?
 ./inc/extensions/ext-yoomedia.php:54:// @TODO Only deprecated when 'ext-network' is ready! setExtensionDeprecated('Y');
-./inc/extensions-functions.php:2038:// @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
+./inc/extensions-functions.php:2040:// @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
 ./inc/extensions-functions.php:424:	// @TODO This redirect is still needed to register sql_patches! Please try to avoid it
 ./inc/extensions-functions.php:440:// @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
 ./inc/extensions-functions.php:580:		// @TODO Extension is loaded, what next?
@@ -75,7 +75,7 @@
 ./inc/libs/doubler_functions.php:93:			// @TODO Can't this be moved into EL?
 ./inc/libs/forced_functions.php:457:// @TODO Can't we use our new expression language instead of this ugly code?
 ./inc/libs/mailid_functions.php:47:		// @TODO Rewrite this to a dynamic include or so
-./inc/libs/network_functions.php:978:	// @TODO Implement this function
+./inc/libs/network_functions.php:978:	// @TODO Implement this function, don't forget to set HTTP status back to '200 OK' if everything went fine
 ./inc/libs/order_functions.php:46:	// @TODO Move this array into a filter
 ./inc/libs/rallye_functions.php:769:// @TODO This function does not load min_users, min_prices, please encapsulate loading rallye data with e.g. getRallyeDataFromId()
 ./inc/libs/rallye_functions.php:836:	$EXPIRE = 3; // @TODO The hard-coded value...
@@ -100,11 +100,11 @@
 ./inc/modules/admin/admin-inc.php:160:		// @TODO This and the next getCurrentAdminId() call might be moved into the templates?
 ./inc/modules/admin/admin-inc.php:233:		// @TODO This can be rewritten into a filter
 ./inc/modules/admin/admin-inc.php:509:// @TODO Try to rewrite this to adminAddMenuSelectionBox()
-./inc/modules/admin/overview-inc.php:168:				// @TODO Rewrite this to a filter
-./inc/modules/admin/overview-inc.php:281:				// @TODO Rewrite this to something with include files and/or filter
-./inc/modules/admin/overview-inc.php:315:						// @TODO This may also be rewritten to include files
-./inc/modules/admin/overview-inc.php:317:							default: // @TODO Unknown support mode
-./inc/modules/admin/overview-inc.php:432:			// @TODO Try to move this in includes
+./inc/modules/admin/overview-inc.php:169:				// @TODO Rewrite this to a filter
+./inc/modules/admin/overview-inc.php:282:				// @TODO Rewrite this to something with include files and/or filter
+./inc/modules/admin/overview-inc.php:316:						// @TODO This may also be rewritten to include files
+./inc/modules/admin/overview-inc.php:318:							default: // @TODO Unknown support mode
+./inc/modules/admin/overview-inc.php:433:			// @TODO Try to move this in includes
 ./inc/modules/admin/overview-inc.php:43:// @TODO This function does also check for uncompleted tasks
 ./inc/modules/admin/what-add_guestnl_cat.php:47:	// @TODO Check if category does already exist
 ./inc/modules/admin/what-admin_add.php:120:				// @TODO This can be somehow rewritten to a function
@@ -168,34 +168,34 @@
 ./inc/modules/member/what-unconfirmed.php:169:	// @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
 ./inc/modules/member/what-unconfirmed.php:234:				// @TODO This 'userid' cannot be saved because of encapsulated EL code
 ./inc/modules/order.php:78:		// @TODO Unused: 2,4
-./inc/mysql-manager.php:1421:		// @TODO Rewrite these lines to a filter
-./inc/mysql-manager.php:1445:	// @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1701:			// @TODO Rewrite this to a filter
-./inc/mysql-manager.php:390:	// @TODO Try to rewrite this to one or more functions
+./inc/mysql-manager.php:1442:		// @TODO Rewrite these lines to a filter
+./inc/mysql-manager.php:1466:	// @TODO Rewrite this to a filter
+./inc/mysql-manager.php:1722:			// @TODO Rewrite this to a filter
+./inc/mysql-manager.php:398:	// @TODO Try to rewrite this to one or more functions
 ./inc/mysql-manager.php:44:// @TODO Can we cache this?
 ./inc/purge/purge-inact.php:55:	// @TODO Rewrite these if() blocks to a filter
 ./inc/revision-functions.php:168:// @TODO This function does also set and get in 'cache_array'
-./inc/template-functions.php:1107:			// @TODO Deprecate this thing
-./inc/template-functions.php:1118:			// @TODO Deprecate this thing
-./inc/template-functions.php:1225:	// @TODO This can be easily moved out after the merge from EL branch to this is complete
-./inc/template-functions.php:1274:		// @TODO Add a little more infos here
-./inc/template-functions.php:1642:// @TODO Lame description for this function
-./inc/template-functions.php:1664:			// @TODO Move this in a filter
+./inc/template-functions.php:1108:			// @TODO Deprecate this thing
+./inc/template-functions.php:1119:			// @TODO Deprecate this thing
+./inc/template-functions.php:1226:	// @TODO This can be easily moved out after the merge from EL branch to this is complete
+./inc/template-functions.php:1275:		// @TODO Add a little more infos here
+./inc/template-functions.php:1643:// @TODO Lame description for this function
+./inc/template-functions.php:1665:			// @TODO Move this in a filter
 ./inc/template-functions.php:197:	 * @TODO On some pages this is buggy
 ./inc/template-functions.php:285:	// @TODO Remove these sanity checks if all is fine
-./inc/template-functions.php:598:// @TODO $simple/$constants are deprecated
-./inc/template-functions.php:696:			// @TODO $userid is deprecated and should be removed from loadEmailTemplate() and replaced with $content[userid] in all templates
-./inc/wrapper-functions.php:2968:	// @TODO Find a way to not use direct module comparison
+./inc/template-functions.php:599:// @TODO $simple/$constants are deprecated
+./inc/template-functions.php:697:			// @TODO $userid is deprecated and should be removed from loadEmailTemplate() and replaced with $content[userid] in all templates
+./inc/wrapper-functions.php:2980:	// @TODO Find a way to not use direct module comparison
 ./inc/wrapper-functions.php:494:// @TODO Do some more sanity check here
 ./inc/xml-functions.php:208:	// @TODO Handle characters
 ./mailid.php:102:		// @TODO Rewrite this to a filter
 ./mailid.php:145:					// @TODO Rewrite this to a filter
-./mailid_top.php:108:		// @TODO Rewrite this to a filter
-./mailid_top.php:145:					// @TODO Rewrite this to a filter
+./mailid_top.php:112:		// @TODO Rewrite this to a filter/function
+./mailid_top.php:149:					// @TODO Rewrite this to a filter
 ./mailid_top.php:18: * @TODO Merge this script with mailid.php                              *
-./mailid_top.php:192:							// @TODO Rewrite this to a filter
-./mailid_top.php:199:									// @TODO Rewrite this to a filter
-./mailid_top.php:234:									// @TODO Rewrite these blocks to filter
+./mailid_top.php:196:							// @TODO Rewrite this to a filter
+./mailid_top.php:203:									// @TODO Rewrite this to a filter
+./mailid_top.php:238:									// @TODO Rewrite these blocks to filter
 ./view.php:71:		// @TODO No banner found, output some default banner
 ./templates/de/html/admin/admin_add_country.tpl:23:			<!-- @TODO Rewrite this selection box to our generic functions //-->
 ./templates/de/html/admin/admin_config_other.tpl:79:			<!-- @TODO Rewrite this selection to one of our functions //-->
@@ -227,11 +227,13 @@
 ./inc/extensions/ext-funcoins.php:2:// @DEPRECATED
 ./inc/extensions/ext-iso3166.php:2:// @DEPRECATED
 ./inc/extensions/ext-primera.php:2:// @DEPRECATED
+./inc/filter/politician_stop_filter.php:2:// @DEPRECATED
 ./inc/gen_refback.php:2:// @DEPRECATED
 ./inc/js/js-jquery.php:2:// @DEPRECATED
 ./inc/language/funcoins_de.php:2:// @DEPRECATED
 ./inc/language/primera_de.php:2:// @DEPRECATED
 ./inc/libs/funcoins_functions.php:2:// @DEPRECATED
+./inc/libs/politician_stop_functions.php:2:// @DEPRECATED
 ./inc/libs/primera_functions.php:2:// @DEPRECATED
 ./inc/loader/load_cache-admin.php:2:// @DEPRECATED
 ./inc/loader/load_cache-config.php:2:// @DEPRECATED
@@ -417,6 +419,7 @@
 ./templates/de/html/admin/admin_payout_add_new.tpl:1:<!-- @DEPRECATED //-->
 ./templates/de/html/admin/admin_reset_pass_done.tpl:1:<!-- @DEPRECATED //-->
 ./templates/de/html/admin/admin_send_reset_link.tpl:1:<!-- @DEPRECATED //-->
+./templates/de/html/app_die_message.tpl:1:<!-- @DEPRECATED //-->
 ./templates/de/html/awards.tpl:1:<!-- @DEPRECATED //-->
 ./templates/de/html/beg/beg_banner.tpl:1:<!-- @DEPRECATED //-->
 ./templates/de/html/bug-tracker.tpl:1:<!-- @DEPRECATED //-->
@@ -493,6 +496,7 @@
 ./templates/de/html/partner.tpl:1:<!-- @DEPRECATED //-->
 ./templates/de/html/philosophy.tpl:1:<!-- @DEPRECATED //-->
 ./templates/de/html/photos.tpl:1:<!-- @DEPRECATED //-->
+./templates/de/html/politician_stop/politician_stop_snippet.tpl:1:<!-- @DEPRECATED //-->
 ./templates/de/html/powered.tpl:1:<!-- @DEPRECATED //-->
 ./templates/de/html/premium-backlinks.tpl:1:<!-- @DEPRECATED //-->
 ./templates/de/html/rallye_test.tpl:1:<!-- @DEPRECATED //-->
diff --git a/inc/extensions/ext-booking.php b/inc/extensions/ext-booking.php
index bb4469b12a..6afac46583 100644
--- a/inc/extensions/ext-booking.php
+++ b/inc/extensions/ext-booking.php
@@ -79,6 +79,7 @@ INDEX (`userid`)",
 		// Add the filters
 		registerFilter(__FILE__, __LINE__, 'post_add_points', 'ADD_BOOKING_RECORD', false, true, isExtensionDryRun());
 		registerFilter(__FILE__, __LINE__, 'post_sub_points', 'ADD_BOOKING_RECORD', false, true, isExtensionDryRun());
+		registerFilter(__FILE__, __LINE__, 'member_admin_actions', 'ADD_BOOKING_MEMBER_ACTION', false, true, isExtensionDryRun());
 		break;
 
 	case 'remove': // Do stuff when removing extension
@@ -89,6 +90,7 @@ INDEX (`userid`)",
 		// Remove the filters
 		unregisterFilter(__FILE__, __LINE__, 'post_add_points', 'ADD_BOOKING_RECORD', true, isExtensionDryRun());
 		unregisterFilter(__FILE__, __LINE__, 'post_sub_points', 'ADD_BOOKING_RECORD', true, isExtensionDryRun());
+		unregisterFilter(__FILE__, __LINE__, 'member_admin_actions', 'ADD_BOOKING_MEMBER_ACTION', true, isExtensionDryRun());
 		break;
 
 	case 'activate': // Do stuff when admin activates this extension
diff --git a/inc/filter/booking_filter.php b/inc/filter/booking_filter.php
index 9e65874f04..73aad6d671 100644
--- a/inc/filter/booking_filter.php
+++ b/inc/filter/booking_filter.php
@@ -42,8 +42,8 @@ if (!defined('__SECURITY')) {
 
 // Filter for adding booking record
 function FILTER_ADD_BOOKING_RECORD ($filterData) {
-	// Add a record
 	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
+	// Add a record
 	addBookingRecord($filterData['subject'], $filterData['userid'], $filterData['points'], $filterData['points_mode']);
 
 	// Return data
@@ -51,5 +51,16 @@ function FILTER_ADD_BOOKING_RECORD ($filterData) {
 	return $filterData;
 }
 
+// Filter for adding member action
+function FILTER_ADD_BOOKING_MEMBER_ACTION ($filterData) {
+	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
+	// Add entry
+	array_push($filterData, 'list_booking');
+
+	// Return data
+	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
+	return $filterData;
+}
+
 // [EOF]
 ?>
diff --git a/inc/language/booking_de.php b/inc/language/booking_de.php
index 8f1bd6eb31..77e8fed9b7 100644
--- a/inc/language/booking_de.php
+++ b/inc/language/booking_de.php
@@ -42,6 +42,9 @@ if (!defined('__SECURITY')) {
 
 // Language strings
 addMessages(array(
+	// Admin member 'action' links
+	'ADMIN_USER_ACTION_LINK_LIST_BOOKING' => "Kontoauszug anzeigen",
+	'ADMIN_USER_ACTION_LINK_LIST_BOOKING_TITLE' => "Zeigt den Kontoauszug des Mitgliedes an.",
 ));
 
 // [EOF]
diff --git a/inc/language/user_de.php b/inc/language/user_de.php
index fc65a05cc8..51b3741a2a 100644
--- a/inc/language/user_de.php
+++ b/inc/language/user_de.php
@@ -50,20 +50,26 @@ addMessages(array(
 	'ADMIN_USER_ACCOUNT_NOT_SAVED' => "Mitgliedsaccount <u>nicht</u> gespeichert.",
 	'ADMIN_USER_ACCOUNT_LOCKED' => "Mitgliedsaccount <span class=\"data\">%s</span> wurde gesperrt.",
 	'ADMIN_USER_ACCOUNT_UNLOCKED' => "Mitgliedsaccount <span class=\"data\">%s</span> wurde freigegeben.",
+
+	// Admin member 'action' links
 	'ADMIN_USER_ACTION_LINK_DELETE_USER' => "Mitgliedsdaten l&ouml;schen",
-	'ADMIN_USER_ACTION_LINK_EDIT_USER' => "Mitgliedsdaten bearbeiten",
-	'ADMIN_USER_ACTION_LINK_LOCK_USER' => "Mitglied sperren",
-	'ADMIN_USER_ACTION_LINK_UNLOCK_USER' => "Mitglied entsperren",
-	'ADMIN_USER_ACTION_LINK_ADD_POINTS' => "{?POINTS?} aufbuchen",
-	'ADMIN_USER_ACTION_LINK_SUB_POINTS' => "{?POINTS?} abziehen",
 	'ADMIN_USER_ACTION_LINK_DELETE_USER_TITLE' => "Mitglied l&ouml;schen (mit Abfrage)",
+	'ADMIN_USER_ACTION_LINK_EDIT_USER' => "Mitgliedsdaten bearbeiten",
 	'ADMIN_USER_ACTION_LINK_EDIT_USER_TITLE' => "Mitglied editieren",
+	'ADMIN_USER_ACTION_LINK_LOCK_USER' => "Mitglied sperren",
 	'ADMIN_USER_ACTION_LINK_LOCK_USER_TITLE' => "Mitglied sperren (mit Sperrgrund)",
-	'ADMIN_USER_ACTION_LINK_UNLOCK_USER_TITLE' => "Mitglied entsperren",
+	'ADMIN_USER_ACTION_LINK_ADD_POINTS' => "{?POINTS?} aufbuchen",
 	'ADMIN_USER_ACTION_LINK_ADD_POINTS_TITLE' => "Dem Mitglied {?POINTS?} aufbuchen",
+	'ADMIN_USER_ACTION_LINK_SUB_POINTS' => "{?POINTS?} abziehen",
 	'ADMIN_USER_ACTION_LINK_SUB_POINTS_TITLE' => "Dem Mitglied {?POINTS?} abziehen",
-	'ADMIN_USER_ACTION_LINK_CONFIRM_ACCOUNT_TITLE' => "Das Mitgliederaccount best&auml;tigen",
+	'ADMIN_USER_ACTION_LINK_UNLOCK_USER' => "Mitglied entsperren",
+	'ADMIN_USER_ACTION_LINK_UNLOCK_USER_TITLE' => "Mitglied entsperren",
 	'ADMIN_USER_ACTION_LINK_CONFIRM_ACCOUNT' => "Best&auml;tigen",
+	'ADMIN_USER_ACTION_LINK_CONFIRM_ACCOUNT_TITLE' => "Das Mitgliederaccount best&auml;tigen",
+	'ADMIN_USER_ACTION_LINK_LIST_REFS' => "Referrals anzeigen",
+	'ADMIN_USER_ACTION_LINK_LIST_REFS_TITLE' => "Alle Referrals des Mitglieds auflisten",
+	'ADMIN_USER_ACTION_LINK_LIST_LINKS' => "Unbest&auml;tigte Mails",
+	'ADMIN_USER_ACTION_LINK_LIST_LINKS_TITLE' => "Alle unbest&auml;tigten Mails des Mitglieds auflisten",
 
 	// Legends
 	'ADMIN_CONFIG_USER_LEGEND' => "Konfiguration zur Mitgliederliste",
diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php
index 129b7c6ae1..cfd3e318cd 100644
--- a/inc/mysql-manager.php
+++ b/inc/mysql-manager.php
@@ -476,12 +476,18 @@ function fetchUserData ($value, $column = 'userid') {
 		if (!isValidUserId($value)) {
 			// Invalid, so abort here
 			reportBug(__FUNCTION__, __LINE__, 'User id ' . $value . ' is invalid.');
+		} // END - if
+
+		// Unset cached values if found and different
+		if ((isCurrentUserIdSet()) && (getCurrentUserId() != $value)) {
+			// Unset it
+			unsetCurrentUserId();
 		} elseif (isUserDataValid()) {
 			// Use cache, so it is fine
 			//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' is valid, using cache #1');
 			return true;
-		}
-	} elseif (isUserDataValid())  {
+		} // END - if
+	} elseif (isUserDataValid()) {
 		// Using cache is fine
 		//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' is valid, using cache #2');
 		return true;
diff --git a/inc/template-functions.php b/inc/template-functions.php
index 495cccb345..73d0de026f 100644
--- a/inc/template-functions.php
+++ b/inc/template-functions.php
@@ -1090,7 +1090,7 @@ function generateMemberAdminActionLinks ($userid) {
 	} // END - if
 
 	// Define all main targets
-	$targetArray = array('del_user', 'edit_user', 'lock_user', 'add_points', 'sub_points');
+	$targetArray = runFilterChain('member_admin_actions', array('del_user', 'edit_user', 'lock_user', 'list_refs', 'list_links', 'add_points', 'sub_points'));
 
 	// Get user status
 	$status = getFetchedUserData('userid', $userid, 'status');
@@ -1098,29 +1098,29 @@ function generateMemberAdminActionLinks ($userid) {
 	// Begin of navigation links
 	$OUT = '[';
 
-	foreach ($targetArray as $tar) {
-		$OUT .= '<span class="admin_user_link"><a href="{%url=modules.php?module=admin&amp;what=' . $tar . '&amp;userid=' . $userid . '%}" title="{--ADMIN_USER_ACTION_LINK_';
-		//* DEBUG: */ debugOutput('*' . $tar.'/' . $status.'*');
-		if (($tar == 'lock_user') && ($status == 'LOCKED')) {
+	foreach ($targetArray as $target) {
+		$OUT .= '<span class="admin_user_link"><a href="{%url=modules.php?module=admin&amp;what=' . $target . '&amp;userid=' . $userid . '%}" title="{--ADMIN_USER_ACTION_LINK_';
+		//* DEBUG: */ debugOutput('*' . $target.'/' . $status.'*');
+		if (($target == 'lock_user') && ($status == 'LOCKED')) {
 			// Locked accounts shall be unlocked
 			$OUT .= 'UNLOCK_USER';
-		} elseif ($tar == 'del_user') {
+		} elseif ($target == 'del_user') {
 			// @TODO Deprecate this thing
 			$OUT .= 'DELETE_USER';
 		} else {
 			// All other status is fine
-			$OUT .= strtoupper($tar);
+			$OUT .= strtoupper($target);
 		}
 		$OUT .= '_TITLE--}">{--ADMIN_USER_ACTION_LINK_';
-		if (($tar == 'lock_user') && ($status == 'LOCKED')) {
+		if (($target == 'lock_user') && ($status == 'LOCKED')) {
 			// Locked accounts shall be unlocked
 			$OUT .= 'UNLOCK_USER';
-		} elseif ($tar == 'del_user') {
+		} elseif ($target == 'del_user') {
 			// @TODO Deprecate this thing
 			$OUT .= 'DELETE_USER';
 		} else {
 			// All other status is fine
-			$OUT .= strtoupper($tar);
+			$OUT .= strtoupper($target);
 		}
 		$OUT .= '--}</a></span>|';
 	} // END - foreach
diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php
index 47bf5c07af..fda7b2a4c0 100644
--- a/inc/wrapper-functions.php
+++ b/inc/wrapper-functions.php
@@ -997,9 +997,7 @@ function setCurrentUserId ($userid) {
 	// Is the cache from below functions different?
 	if (((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) || ((!isset($GLOBALS['current_userid'])) && (isset($GLOBALS['isCurrentUserIdSet'])))) {
 		// Then unset both
-		unset($GLOBALS['getCurrentUserId']);
-		unset($GLOBALS['isCurrentUserIdSet']);
-		unset($GLOBALS['isValidUserId'][$userid]);
+		unsetCurrentUserId();
 	} // END - if
 
 	// Set userid
@@ -1042,6 +1040,20 @@ function isCurrentUserIdSet () {
 	return $GLOBALS[__FUNCTION__];
 }
 
+// Unsets current userid
+function unsetCurrentUserId () {
+	// Do we have it set?
+	if (isset($GLOBALS['current_userid'])) {
+		// Unset this, too
+		unset($GLOBALS['isValidUserId'][$GLOBALS['current_userid']]);
+	} // END - if
+
+	// Unset all cache entries
+	unset($GLOBALS['current_userid']);
+	unset($GLOBALS['getCurrentUserId']);
+	unset($GLOBALS['isCurrentUserIdSet']);
+}
+
 // Checks whether we are debugging template cache
 function isDebuggingTemplateCache () {
 	// Do we have cache?
-- 
2.39.5