]> git.mxchange.org Git - mailer.git/blobdiff - inc/mysql-manager.php
Updated ext-politician-stop which is satire on politicians that doesn't really know...
[mailer.git] / inc / mysql-manager.php
index 2b879de773f2d4efce72164d78e206ed41886951..e9d5c40fcdeef682d87e01f66bb7b9d2a536fb94 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -42,16 +42,19 @@ if (!defined('__SECURITY')) {
 
 // "Getter" for module description
 // @TODO Can we cache this?
-function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') {
+function getTitleFromMenu ($mode, $what, $column = 'what', $ADD = '') {
+       // Debug message
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mode=' . $mode . ',what=' . $what . ',column=' . $column . ',add=' . $ADD);
+
        // Fix empty 'what'
        if (empty($what)) {
                $what = getIndexHome();
        } elseif ((isGetRequestElementSet('action')) && ($column == 'what')) {
                // Get it from action
                return getTitleFromMenu($mode, getAction(), 'action', $ADD);
-       } elseif ($what == 'overview') {
+       } elseif ($what == 'welcome') {
                // Overview page
-               return '{--WHAT_IS_OVERVIEW--}';
+               return '{--WHAT_IS_WELCOME--}';
        }
 
        // Default is not found
@@ -157,13 +160,15 @@ function addYouAreHereLink ($accessLevel, $FQFN, $return = false) {
                $search = substr($search, 0, -4);
        } // END - if
 
+       // Is ext-sql_patches installed?
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isExtensionInstalledAndNewer()=' . intval(isExtensionInstalledAndNewer('sql_patches', '0.2.3')) . ',youre_here=' . getConfig('youre_here') . ',isAdmin()=' . intval(isAdmin()) . ',modCheck=' . $modCheck);
        if (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) {
                // Output HTML code
                $OUT = $prefix . '<strong><a class="you_are_here" href="{%url=modules.php?module=' . $modCheck . '&amp;' . $type . '=' . $search . $LINK_ADD . '%}">' . getTitleFromMenu($accessLevel, $search, $type, $ADD) . '</a></strong>';
 
                // Can we close the you-are-here navigation?
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $type . 'getWhat()=' . getWhat());
-               if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) {
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $type . ',getWhat()=' . getWhat() . ',isWhatSet()=' . intval(isWhatSet()));
+               if (($type == 'what') || (($type == 'action') && (!isWhatSet()))) {
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $type);
                        // Add closing div and br-tag
                        $GLOBALS['nav_depth'] = '0';
@@ -270,7 +275,7 @@ ORDER BY
                                                } // END - if
 
                                                // Is ext-sql_patches up-to-date, and display_home_in_index is Y?
-                                               if ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isDisplayHomeInIndexEnabled()) && ($content['sub_what'] == getIndexHome())) {
+                                               if ((getModule() == 'index') && (isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isDisplayHomeInIndexEnabled()) && ($content['sub_what'] == getIndexHome())) {
                                                        // Use index.php as link
                                                        $OUT .= '<a name="menu" class="menu_blur" href="{%url=index.php%}" target="_self">';
                                                } else {
@@ -378,7 +383,7 @@ ORDER BY
        } // END - if
 }
 
-// Checks wether the current user is a member
+// Checks whether the current user is a member
 function isMember () {
        // By default no member
        $ret = false;
@@ -423,7 +428,7 @@ function isMember () {
                // So did we now have valid data and an unlocked user?
                if ((getUserData('status') == 'CONFIRMED') && ($valPass == getSession('u_hash'))) {
                        // Transfer last module and online time
-                       $GLOBALS['last_online']['module'] = getUserData('last_module');
+                       $GLOBALS['last_online']['module'] = getUserData(getUserLastWhatName());
                        $GLOBALS['last_online']['online'] = getUserData('last_online');
 
                        // Account is confirmed and all cookie data is valid so he is definely logged in! :-)
@@ -453,7 +458,7 @@ function fetchUserData ($value, $column = 'userid') {
                return false;
        } elseif (is_null($value)) {
                // This shall never happen, so please report it
-               debug_report_bug(__FUNCTION__, __LINE__, 'value=NULL,column=' . $column . ' - value can never be NULL');
+               reportBug(__FUNCTION__, __LINE__, 'value=NULL,column=' . $column . ' - value can never be NULL');
        }
 
        // If we should look for userid secure&set it here
@@ -461,13 +466,10 @@ function fetchUserData ($value, $column = 'userid') {
                // Secure userid
                $value = bigintval($value);
 
-               // Set it here
-               setCurrentUserId($value);
-
                // Don't look for invalid userids...
                if (!isValidUserId($value)) {
                        // Invalid, so abort here
-                       debug_report_bug(__FUNCTION__, __LINE__, 'User id ' . $value . ' is invalid.');
+                       reportBug(__FUNCTION__, __LINE__, 'User id ' . $value . ' is invalid.');
                } elseif (isUserDataValid()) {
                        // Use cache, so it is fine
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' is valid, using cache #1');
@@ -482,14 +484,11 @@ function fetchUserData ($value, $column = 'userid') {
        // By default none was found
        $found = false;
 
-       // Extra statements
-       $ADD = '';
-       if (isExtensionInstalledAndNewer('user', '0.3.5')) {
-               $ADD = ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`';
-       } // END - if
+       // Extra SQL statements
+       $ADD = runFilterChain('convert_user_data_columns', '');
 
        // Query for the user
-       $result = SQL_QUERY_ESC("SELECT *".$ADD." FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1",
+       $result = SQL_QUERY_ESC("SELECT *" . $ADD . " FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1",
                array($column, $value), __FUNCTION__, __LINE__);
 
        // Do we have a record?
@@ -541,7 +540,12 @@ function fetchUserData ($value, $column = 'userid') {
        return $found;
 }
 
-// This patched function will reduce many SELECT queries for the specified or current admin login
+/*
+ * Checks whether the current session bears a valid admin id and password hash.
+ *
+ * This patched function will reduce many SELECT queries for the current admin
+ * login.
+ */
 function isAdmin () {
        // No admin in installation phase!
        if ((isInstallationPhase()) || (!isAdminRegistered())) {
@@ -551,7 +555,7 @@ function isAdmin () {
        // Init variables
        $ret = false;
        $adminId = '0';
-       $passCookie = '';
+       $passwordFromCookie = '';
        $valPass = '';
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId);
 
@@ -559,12 +563,16 @@ function isAdmin () {
        if ((isSessionVariableSet('admin_id')) && (isSessionVariableSet('admin_md5'))) {
                // Get admin login and password from session/cookies
                $adminId    = getCurrentAdminId();
-               $passCookie = getAdminMd5();
+               $passwordFromCookie = getAdminMd5();
        } // END - if
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mainId=' . $adminId . 'passCookie=' . $passCookie);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId . 'passwordFromCookie=' . $passwordFromCookie);
 
        // Abort if admin id is zero
        if ($adminId == '0') {
+               // A very noisy debug message ...
+               //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Current adminId is zero. isSessionVariableSet(admin_id)=' . intval(isSessionVariableSet('admin_id')) . ',isSessionVariableSet(admin_md5)=' . intval(isSessionVariableSet('admin_md5')));
+
+               // Abort here now
                return false;
        } // END - if
 
@@ -577,7 +585,7 @@ function isAdmin () {
                if (isset($GLOBALS['admin_hash'])) {
                        // Use cached string
                        $valPass = $GLOBALS['admin_hash'];
-               } elseif ((!empty($passCookie)) && (isAdminHashSet($adminId) === true) && (!empty($adminId))) {
+               } elseif ((!empty($passwordFromCookie)) && (isAdminHashSet($adminId) === true) && (!empty($adminId))) {
                        // Login data is valid or not?
                        $valPass = encodeHashForCookie(getAdminHash($adminId));
 
@@ -596,8 +604,8 @@ function isAdmin () {
 
                if (!empty($valPass)) {
                        // Check if password is valid
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie));
-                       $GLOBALS[__FUNCTION__][$adminId] = (($GLOBALS['admin_hash'] == $passCookie) || ((strlen($GLOBALS['admin_hash']) == 32) && ($GLOBALS['admin_hash'] == md5($passCookie))) || (($GLOBALS['admin_hash'] == '*FAILED*') && (!isExtensionActive('cache'))));
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passwordFromCookie . ')='.intval($valPass == $passwordFromCookie));
+                       $GLOBALS[__FUNCTION__][$adminId] = ($GLOBALS['admin_hash'] == $passwordFromCookie);
                } // END - if
        } // END - if
 
@@ -617,6 +625,7 @@ function addMaxReceiveList ($mode, $default = '', $return = false) {
                        __FUNCTION__, __LINE__);
                        break;
 
+               case 'admin':
                case 'member':
                        // Members are allowed to set to zero mails per day (we will change this soon!)
                        $result = SQL_QUERY('SELECT `value`,`comment` FROM `{?_MYSQL_PREFIX?}_max_receive` ORDER BY `value` ASC',
@@ -633,7 +642,11 @@ function addMaxReceiveList ($mode, $default = '', $return = false) {
                $OUT = '';
                while ($content = SQL_FETCHARRAY($result)) {
                        $OUT .= '      <option value="' . $content['value'] . '"';
-                       if (postRequestElement('max_mails') == $content['value']) $OUT .= ' selected="selected"';
+
+                       if (postRequestElement('max_mails') == $content['value']) {
+                               $OUT .= ' selected="selected"';
+                       } // END - if
+
                        $OUT .= '>' . $content['value'] . ' {--PER_DAY--}';
                        if (!empty($content['comment'])) $OUT .= '(' . $content['comment'] . ')';
                        $OUT .= '</option>';
@@ -643,7 +656,7 @@ function addMaxReceiveList ($mode, $default = '', $return = false) {
                $OUT = loadTemplate(($mode . '_receive_table'), true, $OUT);
        } else {
                // Maybe the admin has to setup some maximum values?
-               debug_report_bug(__FUNCTION__, __LINE__, 'Nothing is being done here?');
+               reportBug(__FUNCTION__, __LINE__, 'Nothing is being done here?');
        }
 
        // Free result
@@ -658,7 +671,7 @@ function addMaxReceiveList ($mode, $default = '', $return = false) {
        }
 }
 
-// Checks wether the given email address is used.
+// Checks whether the given email address is used.
 function isEmailTaken ($email) {
        // Default is no userid
        $useridSql = ' IS NOT NULL';
@@ -723,7 +736,7 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry = false) {
                                $action,
                                $what
                        ), __FUNCTION__, __LINE__, false);
-       } elseif (($what != 'overview') && (!empty($what))) {
+       } elseif (($what != 'welcome') && (!empty($what))) {
                // Other actions
                $sql = SQL_QUERY_ESC("SELECT `id`,`what` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what`='%s'".$add." ORDER BY `action` DESC LIMIT 1",
                        array(
@@ -770,16 +783,7 @@ function getActionFromModuleWhat ($module, $what) {
 
        if (!isExtensionInstalledAndNewer('sql_patches', '0.0.5')) {
                // sql_patches is missing so choose depending on mode
-               if (isWhatSet()) {
-                       // Use setted what
-                       $what = getWhat();
-               } elseif ($module == 'admin') {
-                       // Admin area
-                       $what = 'overview';
-               } else {
-                       // Everywhere else
-                       $what = 'welcome';
-               }
+               $what = determineWhat($module);
        } elseif ((empty($what)) && ($module != 'admin')) {
                // Use configured 'home'
                $what = getIndexHome();
@@ -793,7 +797,7 @@ function getActionFromModuleWhat ($module, $what) {
                } elseif (isActionSet()) {
                        // Get it directly from URL
                        return getAction();
-               } elseif (($what == 'overview') || (!isWhatSet())) {
+               } elseif (($what == 'welcome') || (!isWhatSet())) {
                        // Default value for admin area
                        $data['action'] = 'login';
                }
@@ -849,7 +853,7 @@ function getCategory ($cid) {
                $data['cat'] = '{--_CATEGORY_NONE--}';
        } elseif ($cid > 0) {
                // Lookup the category in database
-               $result = SQL_QUERY_ESC("SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
+               $result = SQL_QUERY_ESC('SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1',
                        array(bigintval($cid)), __FUNCTION__, __LINE__);
                if (SQL_NUMROWS($result) == 1) {
                        // Category found... :-)
@@ -865,51 +869,47 @@ function getCategory ($cid) {
 }
 
 // Get a string of "mail title" and price back
-function getPaymentTitlePrice ($pid, $full=false) {
-       // Default is not found
-       $ret = '{--_PAYMENT_404--}';
-
-       // Load payment data
-       $result = SQL_QUERY_ESC("SELECT `mail_title`,`price` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
-               array(bigintval($pid)), __FUNCTION__, __LINE__);
-
-       // Do we have an entry?
-       if (SQL_NUMROWS($result) == 1) {
-               // Payment type found... :-)
-               $data = SQL_FETCHARRAY($result);
-
-               // Only title or also including price?
-               if ($full === false) {
-                       $ret = $data['mail_title'];
-               } else {
-                       $ret = $data['mail_title'] . ' / {%pipe,translateComma=' . $data['price'] . '%} {?POINTS?}';
-               }
-       } // END - if
-
-       // Free result
-       SQL_FREERESULT($result);
+function getPaymentTitlePrice ($paymentsId, $full = false) {
+       // Only title or also including price?
+       if ($full === false) {
+               $ret = getPaymentData($paymentsId, 'main_title');
+       } else {
+               $ret = getPaymentData($paymentsId, 'main_title') . ' / {%pipe,getPaymentData,translateComma=' . $paymentsId . '%} {?POINTS?}';
+       }
 
        // Return result
        return $ret;
 }
 
-// Get (basicly) the price of given payment id
-function getPaymentPoints ($pid, $lookFor = 'price') {
+// "Getter" for payment data (cached)
+function getPaymentData ($paymentsId, $lookFor = 'price') {
        // Default value...
-       $data[$lookFor] = -1;
+       $data[$lookFor] = NULL;
 
-       // Search for it in database
-       $result = SQL_QUERY_ESC("SELECT `%s` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
-               array($lookFor, $pid), __FUNCTION__, __LINE__);
+       // Do we have cache?
+       if (isset($GLOBALS['cache_array']['payments'][$paymentsId]['id'])) {
+               // Use it if found to save SQL queries
+               $data[$lookFor] = $GLOBALS['cache_array']['payments'][$lookFor][$paymentsId];
 
-       // Is the entry there?
-       if (SQL_NUMROWS($result) == 1) {
-               // Payment type found... :-)
-               $data = SQL_FETCHARRAY($result);
-       } // END - if
+               // Update cache hits
+               incrementStatsEntry('cache_hits');
+       } elseif (!isExtensionActive('cache')) {
+               // Search for it in database
+               $result = SQL_QUERY_ESC('SELECT `%s` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1',
+                       array(
+                               $lookFor,
+                               bigintval($paymentsId)
+                       ), __FUNCTION__, __LINE__);
 
-       // Free result
-       SQL_FREERESULT($result);
+               // Is the entry there?
+               if (SQL_NUMROWS($result) == 1) {
+                       // Payment type found... :-)
+                       $data = SQL_FETCHARRAY($result);
+               } // END - if
+
+               // Free result
+               SQL_FREERESULT($result);
+       }
 
        // Return value
        return $data[$lookFor];
@@ -938,7 +938,7 @@ function removeReceiver (&$receivers, $key, $userid, $poolId, $statsId = 0, $isB
                        } // END - if
 
                        // Try to look the entry up
-                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s AND `userid`=%s AND link_type='%s' LIMIT 1",
+                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s AND `userid`=%s AND `link_type`='%s' LIMIT 1",
                                array(
                                        $rowName,
                                        bigintval($statsId),
@@ -949,7 +949,7 @@ function removeReceiver (&$receivers, $key, $userid, $poolId, $statsId = 0, $isB
                        // Was it *not* found?
                        if (SQL_HASZERONUMS($result)) {
                                // So we add one!
-                               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_links` (`%s`,`userid`,`link_type`) VALUES ('%s','%s','%s')",
+                               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_links` (`%s`,`userid`,`link_type`) VALUES (%s,%s,'%s')",
                                        array(
                                                $rowName,
                                                bigintval($statsId),
@@ -960,7 +960,7 @@ function removeReceiver (&$receivers, $key, $userid, $poolId, $statsId = 0, $isB
                                // Update 'mails_sent' if sql_patches is updated
                                if (isExtensionInstalledAndNewer('sql_patches', '0.7.4')) {
                                        // Update the pool
-                                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `mails_sent`=`mails_sent`+1 WHERE `id`=%s LIMIT 1",
+                                       SQL_QUERY_ESC('UPDATE `{?_MYSQL_PREFIX?}_pool` SET `mails_sent`=`mails_sent`+1 WHERE `id`=%s LIMIT 1',
                                                array(bigintval($poolId)), __FUNCTION__, __LINE__);
                                } // END - if
                                $ret = 'done';
@@ -988,14 +988,14 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
                // Count or sum whole table?
                if ($countRows === true) {
                        // Count whole table
-                       $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`" . $add . ' LIMIT 1',
+                       $result = SQL_QUERY_ESC('SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`' . $add . ' LIMIT 1',
                                array(
                                        $lookFor,
                                        $tableName
                                ), __FUNCTION__, __LINE__);
                } else {
                        // Sum whole table
-                       $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`" . $add . ' LIMIT 1',
+                       $result = SQL_QUERY_ESC('SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`' . $add . ' LIMIT 1',
                                array(
                                        $lookFor,
                                        $tableName
@@ -1032,7 +1032,7 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
        SQL_FREERESULT($result);
 
        // Fix empty values
-       if ((empty($data['res'])) && ($lookFor != 'counter') && ($lookFor != 'id') && ($lookFor != 'userid')) {
+       if ((empty($data['res'])) && ($lookFor != 'counter') && ($lookFor != 'id') && ($lookFor != 'userid') && ($lookFor != 'rallye_id')) {
                // Float number
                $data['res'] = '0.00000';
        } elseif (''.$data['res'].'' == '') {
@@ -1045,14 +1045,27 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
        return $data['res'];
 }
 
-// Sends out mail to all administrators. This function is no longer obsolete
-// because we need it when there is no ext-admins installed
-function sendAdminEmails ($subj, $message) {
+/**
+ * Sends out mail to all administrators. This function is no longer obsolete
+ * because we need it when there is no ext-admins installed
+ */
+function sendAdminEmails ($subject, $message, $isBugReport = false) {
+       // Default is no special header
+       $mailHeader = '';
+
+       // Is it a bug report?
+       if ($isBugReport === true) {
+               // Then add a reply-to line back to the author (me)
+               $mailHeader = 'Reply-To: webmaster@mxchange.org' . chr(10);
+       } // END - if
+
        // Load all admin email addresses
        $result = SQL_QUERY('SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC', __FUNCTION__, __LINE__);
+
+       // And send the notification to all of them
        while ($content = SQL_FETCHARRAY($result)) {
                // Send the email out
-               sendEmail($content['email'], $subj, $message);
+               sendEmail($content['email'], $subject, $message, 'N', $mailHeader);
        } // END - if
 
        // Free result
@@ -1290,7 +1303,7 @@ function getAdminMenuMode ($adminId) {
 }
 
 // Generates an option list from various parameters
-function generateOptionList ($table, $id, $name, $default = '', $special = '', $whereStatement = '', $disabled = array(), $callback = '') {
+function generateOptions ($table, $id, $name, $default = '', $special = '', $whereStatement = '', $disabled = array(), $callback = '') {
        $ret = '';
        if ($table == '/ARRAY/') {
                // Selection from array
@@ -1317,7 +1330,7 @@ function generateOptionList ($table, $id, $name, $default = '', $special = '', $
                        } // END - foreach
                } else {
                        // Problem in request
-                       debug_report_bug(__FUNCTION__, __LINE__, 'Not all are arrays: id[' . count($id) . ']=' . gettype($id) . ',name[' . count($name) . ']=' . gettype($name) . ',callback=' . $callback);
+                       reportBug(__FUNCTION__, __LINE__, 'Not all are arrays: id[' . count($id) . ']=' . gettype($id) . ',name[' . count($name) . ']=' . gettype($name) . ',callback=' . $callback);
                }
        } else {
                // Data from database
@@ -1459,14 +1472,10 @@ function getWhatFromModule ($modCheck) {
        // Default is empty
        $what = '';
 
+       // Check on given module
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'modCheck=' . $modCheck);
        switch ($modCheck) {
-               case 'admin':
-                       $what = 'overview';
-                       break;
-
-               case 'login':
-               case 'index':
+               case 'index': // Guest area
                        // Is ext-sql_patches installed and newer than 0.0.5?
                        if (isExtensionInstalledAndNewer('sql_patches', '0.0.5')) {
                                // Use it from config
@@ -1477,8 +1486,8 @@ function getWhatFromModule ($modCheck) {
                        }
                        break;
 
-               default:
-                       $what = '';
+               default: // Default for all other menus (getIndexHome() is for index module only)
+                       $what = 'welcome';
                        break;
        } // END - switch
 
@@ -1487,13 +1496,13 @@ function getWhatFromModule ($modCheck) {
 }
 
 // Returns HTML code with an option list of all categories
-function generateCategoryOptionsList ($mode) {
+function generateCategoryOptionsList ($mode, $userid = NULL) {
        // Prepare WHERE statement
        $whereStatement = " WHERE `visible`='Y'";
        if (isAdmin()) $whereStatement = '';
 
        // Initialize array...
-       $CATS = array(
+       $categories = array(
                'id'      => array(),
                'name'    => array(),
                'userids' => array()
@@ -1508,12 +1517,15 @@ function generateCategoryOptionsList ($mode) {
                // ... and begin loading stuff
                while ($content = SQL_FETCHARRAY($result)) {
                        // Transfer some data
-                       $CATS['id'][]   = $content['id'];
-                       $CATS['name'][] = $content['cat'];
+                       $categories['id'][]   = $content['id'];
+                       array_push($categories['name'], $content['cat']);
 
                        // Check which users are in this category
-                       $result_userids = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s ORDER BY `userid` ASC",
-                               array(bigintval($content['id'])), __FUNCTION__, __LINE__);
+                       $result_userids = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s AND `userid` != %s ORDER BY `userid` ASC",
+                               array(
+                                       bigintval($content['id']),
+                                       convertNullToZero($userid)
+                               ), __FUNCTION__, __LINE__);
 
                        // Init count
                        $userid_cnt = '0';
@@ -1521,14 +1533,14 @@ function generateCategoryOptionsList ($mode) {
                        // Start adding all
                        while ($data = SQL_FETCHARRAY($result_userids)) {
                                // Add user count
-                               $userid_cnt += countSumTotalData($data['userid'], 'user_data', 'userid', 'userid', true, " AND `status`='CONFIRMED' AND `receive_mails` > 0");
+                               $userid_cnt += countSumTotalData($data['userid'], 'user_data', 'userid', 'userid', true, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED' AND `receive_mails` > 0"));
                        } // END - while
 
                        // Free memory
                        SQL_FREERESULT($result_userids);
 
                        // Add counter
-                       $CATS['userids'][] = $userid_cnt;
+                       array_push($categories['userids'], $userid_cnt);
                } // END - while
 
                // Free memory
@@ -1536,9 +1548,8 @@ function generateCategoryOptionsList ($mode) {
 
                // Generate options
                $OUT = '';
-               foreach ($CATS['id'] as $key => $value) {
-                       if (strlen($CATS['name'][$key]) > 20) $CATS['name'][$key] = substr($CATS['name'][$key], 0, 17)."...";
-                       $OUT .= '      <option value="' . $value . '">' . $CATS['name'][$key] . ' (' . $CATS['userids'][$key] . ' {--USER_IN_CAT--})</option>';
+               foreach ($categories['id'] as $key => $value) {
+                       $OUT .= '      <option value="' . $value . '">' . $categories['name'][$key] . ' (' . $categories['userids'][$key] . ' {--USERS_IN_CATEGORY--})</option>';
                } // END - foreach
        } else {
                // No cateogries are defined yet
@@ -1612,8 +1623,7 @@ VALUES ('%s','%s','%s',%s,%s,'NEW', UNIX_TIMESTAMP(),'%s',%s,%s,%s)",
 // Generate a receiver list for given category and maximum receivers
 function generateReceiverList ($categoryId, $receiver, $mode = '') {
        // Init variables
-       $CAT_TABS     = '';
-       $CAT_WHERE    = '';
+       $extraColumns = '';
        $receiverList = '';
        $result       = false;
 
@@ -1627,32 +1637,32 @@ function generateReceiverList ($categoryId, $receiver, $mode = '') {
                $receiver = getTotalReceivers($mode);
        } // END - if
 
+       // Exclude (maybe exclude) testers
+       $addWhere = runFilterChain('user_exclusion_sql', ' ');
+
        // Category given?
        if ($categoryId > 0) {
                // Select category
-               $CAT_TABS  = "LEFT JOIN `{?_MYSQL_PREFIX?}_user_cats` AS c ON d.`userid`=c.`userid`";
-               $CAT_WHERE = sprintf(" AND c.`cat_id`=%s", $categoryId);
+               $extraColumns  = "LEFT JOIN `{?_MYSQL_PREFIX?}_user_cats` AS c ON d.`userid`=c.`userid`";
+               $addWhere = sprintf(" AND c.`cat_id`=%s", $categoryId);
        } // END - if
 
        // Exclude users in holiday?
        if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
                // Add something for the holiday extension
-               $CAT_WHERE .= " AND d.`holiday_active`='N'";
+               $addWhere .= " AND d.`holiday_active`='N'";
        } // END - if
 
+       // Include only HTML recipients?
        if ((isExtensionActive('html_mail')) && ($mode == 'html')) {
-               // Only include HTML receivers
-               $result = SQL_QUERY_ESC("SELECT d.`userid` FROM `{?_MYSQL_PREFIX?}_user_data` AS d ".$CAT_TABS." WHERE d.`status`='CONFIRMED' AND d.`html`='Y'".$CAT_WHERE." ORDER BY d.`{?order_select?}` {?order_mode?} LIMIT %s",
-                       array(
-                               $receiver
-                       ), __FUNCTION__, __LINE__);
-       } else {
-               // Include all
-               $result = SQL_QUERY_ESC("SELECT d.`userid` FROM `{?_MYSQL_PREFIX?}_user_data` AS d ".$CAT_TABS." WHERE d.`status`='CONFIRMED'".$CAT_WHERE." ORDER BY d.`{?order_select?}` {?order_mode?} LIMIT %s",
-                       array(
-                               $receiver
-                       ), __FUNCTION__, __LINE__);
-       }
+               $addWhere .= " AND d.`html`='Y'";
+       } // END - if
+
+       // Run query
+       $result = SQL_QUERY_ESC("SELECT d.`userid` FROM `{?_MYSQL_PREFIX?}_user_data` AS d ".$extraColumns." WHERE d.`status`='CONFIRMED' ".$addWhere." ORDER BY d.`{?order_select?}` {?order_mode?} LIMIT %s",
+               array(
+                       $receiver
+               ), __FUNCTION__, __LINE__);
 
        // Entries found?
        if ((SQL_NUMROWS($result) >= $receiver) && ($receiver > 0)) {
@@ -1736,23 +1746,97 @@ function createNewTask ($subject, $notes, $taskType, $userid = NULL, $adminId =
 }
 
 // Updates last module / online time
-// @TODO Fix inconsistency between last_module and getWhat()
 function updateLastActivity($userid) {
-       // Run the update query
-       SQL_QUERY_ESC("UPDATE
+       // Is 'what' set?
+       if (isWhatSet()) {
+               // Run the update query
+               SQL_QUERY_ESC("UPDATE
        `{?_MYSQL_PREFIX?}_user_data`
 SET
-       `last_module`='%s',
+       `%s`='%s',
        `last_online`=UNIX_TIMESTAMP(),
        `REMOTE_ADDR`='%s'
 WHERE
        `userid`=%s
 LIMIT 1",
                array(
+                       getUserLastWhatName(),
                        getWhat(),
                        detectRemoteAddr(),
                        bigintval($userid)
                ), __FUNCTION__, __LINE__);
+       } else {
+               // No what set, needs to be ignored (last_module is last_what)
+               SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_user_data`
+SET
+       `%s`=NULL,
+       `last_online`=UNIX_TIMESTAMP(),
+       `REMOTE_ADDR`='%s'
+WHERE
+       `userid`=%s
+LIMIT 1",
+               array(
+                       getUserLastWhatName(),
+                       detectRemoteAddr(),
+                       bigintval($userid)
+               ), __FUNCTION__, __LINE__);
+       }
+}
+
+/**
+ * Checks if given subject is found and if not, adds an SQL query to the
+ * extension registration queue.
+ */
+function registerExtensionPointsData ($subject, $columnName, $lockedMode, $paymentMethod) {
+       // Default is old extension version
+       $add = '';
+
+       // Is the extension equal or newer 0.8.9?
+       if (((isInstallationPhase()) && ((getExtensionMode() == 'register') || (getExtensionMode() == 'update'))) || (isExtensionInstalledAndNewer('sql_patches', '0.8.9'))) {
+               // Then add provider
+               $add = " AND `account_provider`='EXTENSION'";
+       } // END - if
+
+       // Is the 'subject' there?
+       if (((!ifSqlTableExists('points_data')) && ((getExtensionMode() == 'register') || (getExtensionMode() == 'update'))) || (countSumTotalData($subject, 'points_data', 'id', 'subject', true, $add) == 0)) {
+               // Not found so:
+               if (isset($GLOBALS['previous_extension'][getCurrentExtensionName()])) {
+                       $dummy = $GLOBALS['previous_extension'][getCurrentExtensionName()];
+                       reportBug(__FUNCTION__, __LINE__, 'previous_extension[' . gettype($dummy) . ']=' . $dummy . ',getCurrentExtensionName()=' . getCurrentExtensionName() . ' - Under development, please report this!');
+               } // END - if
+
+               // ... add an SQL query
+               addExtensionSql(sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_points_data` (`subject`,`column_name`,`locked_mode`,`payment_method`) VALUES ('%s','%s','%s','%s')",
+                       $subject,
+                       $columnName,
+                       $lockedMode,
+                       $paymentMethod
+               ));
+       } // END - if
+}
+
+/**
+ * Checks if given subject is found and if so, adds an SQL query to the
+ * extension unregistration queue.
+ */
+function unregisterExtensionPointsData ($subject) {
+       // Default is old extension version
+       $add = '';
+
+       // Is the extension equal or newer 0.8.9?
+       if (isExtensionInstalledAndNewer('sql_patches', '0.8.9')) {
+               // Then add provider
+               $add = " AND `account_provider`='EXTENSION'";
+       } // END - if
+
+       // Is the 'subject' there?
+       if (countSumTotalData($subject, 'points_data', 'id', 'subject', true, $add) == 1) {
+               // Found one or more, so add an SQL query
+               addExtensionSql(sprintf("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_points_data` WHERE `subject`='%s'" . $add . " LIMIT 1",
+                       $subject
+               ));
+       } // END - if
 }
 
 // [EOF]