Referal system rewritten, ext-refback continued:
authorRoland Häder <roland@mxchange.org>
Tue, 12 Jul 2011 19:01:06 +0000 (19:01 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 12 Jul 2011 19:01:06 +0000 (19:01 +0000)
- Referal system refactured, it is now much easier to understand
- Extension ext-refback does now show the click rate in refback list
- BIGINT is now always 20 digits long
- Internal TODO closed (unused column 'status')
- TODOs.txt updated

19 files changed:
DOCS/TODOs.txt
inc/daily/daily_100_bonus.php
inc/extensions/ext-booking.php
inc/extensions/ext-mediadata.php
inc/extensions/ext-user.php
inc/functions.php
inc/language/de.php
inc/libs/refback_functions.php
inc/modules/member/what-refback.php
inc/modules/member/what-reflist.php
inc/mysql-manager.php
inc/wrapper-functions.php
install/tables.sql
templates/de/html/member/member_ref_list_level.tpl
templates/de/html/member/member_ref_list_row.tpl
templates/de/html/member/member_refback_list_level.tpl
templates/de/html/member/member_refback_list_row.tpl
templates/de/html/member/member_refback_list_row_deleted.tpl
templates/de/html/member/member_stats_row.tpl

index abac6c9d44a4a374911f1d56d64705700c23df0e..8a9666e92795b1f60a50b03786069996b351b43f 100644 (file)
@@ -40,7 +40,7 @@
 ./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:155:    // @TODO Do we still need this? setExtensionUpdateNotes('');
-./inc/extensions-functions.php:1944:// @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
+./inc/extensions-functions.php:1945:// @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
 ./inc/extensions-functions.php:425:// @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
 ./inc/extensions-functions.php:562:            // @TODO Extension is loaded, what next?
 ./inc/filter/bonus_filter.php:56:              // @TODO This query isn't right, it will only update if the user was for a longer time away!
 ./inc/libs/task_functions.php:247:             // @TODO These can be rewritten to filter
 ./inc/libs/task_functions.php:51:// @TODO Move all extension-dependent queries into filters
 ./inc/libs/theme_functions.php:93:     // @TODO Can't this be rewritten to an API function?
-./inc/libs/user_functions.php:146:     // @TODO These two constants are no longer used, maybe we reactivate this code?
-./inc/libs/user_functions.php:234:// @TODO Double-check configuration entry here
-./inc/libs/user_functions.php:329:                     // @TODO Make this filter working: $ADDON = runFilterChain('post_login_update', $content);
-./inc/libs/user_functions.php:358:                     // @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON));
+./inc/libs/user_functions.php:159:     // @TODO These two constants are no longer used, maybe we reactivate this code?
+./inc/libs/user_functions.php:250:// @TODO Double-check configuration entry here
+./inc/libs/user_functions.php:345:                     // @TODO Make this filter working: $ADDON = runFilterChain('post_login_update', $content);
+./inc/libs/user_functions.php:374:                     // @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON));
 ./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-extension.php:13: * @TODO Rewrite this whole file                                        *
 ./inc/modules/member/what-payout.php:194:                                      // @TODO Rewrite this to a filter
 ./inc/modules/member/what-points.php:55:// @TODO Should we rewrite this to a filter?
 ./inc/modules/member/what-rallyes.php:89:      // @TODO Reactivate this: $content['admin'] = '<a href="{%url=modules.php?module=index&amp;what=impressum&amp;admin=' . $content['admin_id'] . '%}">' . $content['login'] . '</a>';
-./inc/modules/member/what-refback.php:124:                     // @TODO UNUSED: $refRow['status']      = translateUserStatus($refRow['status']);
 ./inc/modules/member/what-reflinks.php:52:// @TODO Move this into a filter
 ./inc/modules/member/what-transfer.php:128:                            // @TODO Rewrite this to a filter
 ./inc/modules/member/what-unconfirmed.php:144: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
 ./inc/modules/member/what-unconfirmed.php:209:                         // @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:64:    // @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1267:  // @TODO Rewrite this to a filter
-./inc/mysql-manager.php:1529:                  // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
-./inc/mysql-manager.php:1617:          // @TODO Rewrite these lines to a filter
-./inc/mysql-manager.php:1641:  // @TODO Rewrite this to a filter
-./inc/mysql-manager.php:2007:                  // @TODO Rewrite this to a filter
-./inc/mysql-manager.php:2051:// @TODO Fix inconsistency between last_module and getWhat()
+./inc/mysql-manager.php:1257:  // @TODO Rewrite this to a filter
+./inc/mysql-manager.php:1520:                  // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
+./inc/mysql-manager.php:1608:          // @TODO Rewrite these lines to a filter
+./inc/mysql-manager.php:1632:  // @TODO Rewrite this to a filter
+./inc/mysql-manager.php:2001:                  // @TODO Rewrite this to a filter
+./inc/mysql-manager.php:2045:// @TODO Fix inconsistency between last_module and getWhat()
 ./inc/mysql-manager.php:371:   // @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
index f51b3dd986fd3b99181f495891a5f9c3a9c68f01..868dce98e0997b041addad43465eeb691e0a8ffc 100644 (file)
@@ -6,7 +6,7 @@
  * -------------------------------------------------------------------- *
  * File              : daily_100_bonus.php                              *
  * -------------------------------------------------------------------- *
- * Short description : Check for 100% clickrate order                   *
+ * Short description : Check for 100% click rate order                  *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Nach Mailbestaetigungen mit 100% Klickrate s.    *
  * -------------------------------------------------------------------- *
index 8d649fd4cc00b1dcd4ebd8a7396260ad2fcdd942..91fa3dbcd64676cd97fb18aa7d2dd5bc6cd33d9f 100644 (file)
@@ -78,7 +78,7 @@ INDEX (`userid`)",
 
                // Add the filters
                registerFilter('post_add_points', 'ADD_BOOKING_RECORD', false, true, isExtensionDryRun());
-               registerFilter('sub_points', 'ADD_BOOKING_RECORD', false, true, isExtensionDryRun());
+               registerFilter('post_sub_points', 'ADD_BOOKING_RECORD', false, true, isExtensionDryRun());
                break;
 
        case 'remove': // Do stuff when removing extension
@@ -88,7 +88,7 @@ INDEX (`userid`)",
 
                // Remove the filters
                unregisterFilter(__FUNCTION__, __LINE__, 'post_add_points', 'ADD_BOOKING_RECORD', true, isExtensionDryRun());
-               unregisterFilter(__FUNCTION__, __LINE__, 'sub_points', 'ADD_BOOKING_RECORD', true, isExtensionDryRun());
+               unregisterFilter(__FUNCTION__, __LINE__, 'post_sub_points', 'ADD_BOOKING_RECORD', true, isExtensionDryRun());
                break;
 
        case 'activate': // Do stuff when admin activates this extension
index 4a7f8c5e27c9ef38bb68adfd03c66eb12d62fcdb..5f061e8543977218abf852b3ea333199ca177edf 100644 (file)
@@ -56,7 +56,7 @@ switch (getExtensionMode()) {
 
                // Add the filters
                registerFilter('post_add_points', 'UPDATE_MEDIADATA_ENTRY', false, true, isExtensionDryRun());
-               registerFilter('sub_points', 'UPDATE_MEDIADATA_ENTRY', false, true, isExtensionDryRun());
+               registerFilter('post_sub_points', 'UPDATE_MEDIADATA_ENTRY', false, true, isExtensionDryRun());
                break;
 
        case 'remove': // Do stuff when removing extension
@@ -67,7 +67,7 @@ switch (getExtensionMode()) {
 
                // Remove the filters
                unregisterFilter(__FUNCTION__, __LINE__, 'post_add_points', 'UPDATE_MEDIADATA_ENTRY', true, isExtensionDryRun());
-               unregisterFilter(__FUNCTION__, __LINE__, 'sub_points', 'UPDATE_MEDIADATA_ENTRY', true, isExtensionDryRun());
+               unregisterFilter(__FUNCTION__, __LINE__, 'post_sub_points', 'UPDATE_MEDIADATA_ENTRY', true, isExtensionDryRun());
                break;
 
        case 'activate': // Do stuff when admin activates this extension
index 76cebee280107558983a0aae3644a9de559f4113..bb56d0cf02558c262f246115809c942905a10ca5 100644 (file)
@@ -41,10 +41,10 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Version number
-setThisExtensionVersion('0.4.2');
+setThisExtensionVersion('0.4.3');
 
 // Version history array (add more with , '0.0.1' and so on)
-setExtensionVersionHistory(array('0.0.0', '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', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5', '0.3.6', '0.3.7', '0.3.8', '0.3.9', '0.4.0', '0.4.1', '0.4.2'));
+setExtensionVersionHistory(array('0.0.0', '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', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5', '0.3.6', '0.3.7', '0.3.8', '0.3.9', '0.4.0', '0.4.1', '0.4.2', '0.4.3'));
 
 // Keep this extension always active!
 setExtensionAlwaysActive('Y');
@@ -53,7 +53,7 @@ switch (getExtensionMode()) {
        case 'register': // Do stuff when installation is running
                addDropTableSql('user_cats');
                addCreateTableSql('user_cats', "
-`id` BIGINT(22) NOT NULL AUTO_INCREMENT,
+`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
 `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
 `cat_id` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
 PRIMARY KEY (`id`),
@@ -63,7 +63,7 @@ INDEX (`cat_id`)",
 
                addDropTableSql('user_data');
                addCreateTableSql('user_data', "
-`userid` BIGINT(22) NOT NULL AUTO_INCREMENT,
+`userid` BIGINT(20) NOT NULL AUTO_INCREMENT,
 `surname` VARCHAR(255) NOT NULL DEFAULT '',
 `family` VARCHAR(255) NOT NULL DEFAULT '',
 `street_nr` VARCHAR(255) NOT NULL DEFAULT '',
@@ -77,7 +77,7 @@ INDEX (`cat_id`)",
 `password` VARCHAR(255) NOT NULL DEFAULT '',
 `max_mails` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
 `receive_mails` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-`refid` BIGINT(22) NOT NULL DEFAULT 0,
+`refid` BIGINT(20) NOT NULL DEFAULT 0,
 `status` ENUM('UNCONFIRMED','CONFIRMED','LOCKED') NOT NULL DEFAULT 'UNCONFIRMED',
 `user_hash` VARCHAR(255) NULL DEFAULT NULL,
 `REMOTE_ADDR` VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
@@ -104,8 +104,8 @@ INDEX `status_mails` (`status`, `max_mails`)",
 
                addDropTableSql('user_points');
                addCreateTableSql('user_points', "
-`id` BIGINT(22) NOT NULL AUTO_INCREMENT,
-`userid` BIGINT(22) NOT NULL DEFAULT 0,
+`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
+`userid` BIGINT(20) NOT NULL DEFAULT 0,
 `ref_depth` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
 `points` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000,
 `locked_points` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000,
@@ -442,6 +442,14 @@ INDEX (`userid`)",
                                // Add special fix include to fix filters
                                addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what`='chk_regs' LIMIT 1");
 
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("&Uuml;berfl&uuml;ssiges Men&uuml; <strong>chk_regs</strong> entfernt, dies kann mit <strong>list_user</strong> &uuml;bernommen werden.");
+                               break;
+
+                       case '0.4.3': // SQL queries for v0.4.3
+                               // Add special fix include to fix filters
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` CHANGE `refid` `refid` BIGINT(20) NULL DEFAULT NULL");
+
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("&Uuml;berfl&uuml;ssiges Men&uuml; <strong>chk_regs</strong> entfernt, dies kann mit <strong>list_user</strong> &uuml;bernommen werden.");
                                break;
index 08fa13dc1783c29bcdaf8fe0502ea790e97c86d1..be4eed9d407a39d4cd699cf21bc3b43d5b5eb2d7 100644 (file)
@@ -2337,7 +2337,7 @@ function getArrayKeysFromSubStrArray ($heystack, $needles, $offset = 0) {
 
 // Determines database column name from given subject and locked
 function determinePointsColumnFromSubjectLocked ($subject, $locked) {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',locked=' . intval($locked) . ' - ENTERED!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',locked=' . intval($locked) . ' - ENTERED!');
        // Default is 'normal' points
        $pointsColumn = 'points';
 
@@ -2360,7 +2360,7 @@ function determinePointsColumnFromSubjectLocked ($subject, $locked) {
        $pointsColumn = $filterData['column'];
 
        // Return it
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',locked=' . intval($locked) . ',pointsColumn=' . $pointsColumn . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',locked=' . intval($locked) . ',pointsColumn=' . $pointsColumn . ' - EXIT!');
        return $pointsColumn;
 }
 
index 3944de41ffe9fad1089409005bc484b1861e7890..d82729f717129bf5f0babc5fe5df3f583a1aaa26 100644 (file)
@@ -437,7 +437,7 @@ addMessages(array(
        'MEMBER_STATS_CONTENT' => "Statistiken versandter Mails",
        'MEMBER_EMAIL_END_SEND' => "Vollst&auml;ndig versendet",
        'MEMBER_EMAIL_CONFIRMED' => "Best&auml;tigt",
-       'MEMBER_EMAIL_PERCENT' => "Klickrate",
+       'MEMBER_CLICK_RATE' => "Klickrate",
        'MEMBER_NO_MAILS_TO_CONFIRM' => "Keine Mails &uuml;brig zum Best&auml;tigen.",
        'MEMBER_SID' => "Mail-Id",
        'CONFIRM_LINK' => "Best&auml;tigungslink",
index 5856a6aeda5c43442c5d012c2843a212bfb1c00a..9cb0ac373452b37c697fe59dcc9684c396bed6dd 100644 (file)
 // Some security stuff...
 if (!defined('__SECURITY')) {
        die();
-}
+} // END - if
 
 // Payback refback for refid and reduce it for current user
 function addRefbackPoints ($userid, $ref, $points, $ref_points) {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',points=' . $points . ',ref_points=' . $ref_points . ' - ENTERED!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',points=' . $points . ',ref_points=' . $ref_points . ' - ENTERED!');
        // Back ref depths
        $GLOBALS['refback_depth'][$userid][$ref] = $GLOBALS['ref_level'];
 
@@ -59,7 +59,7 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) {
                initReferalSystem();
 
                // "Walk" through all refids
-               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',level=' . $content['level'] . ',percents=' . $content['percents'] . ',points=' . $points . ' - LOOP START!');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',level=' . $content['level'] . ',percents=' . $content['percents'] . ',points=' . $points . ' - LOOP START!');
                foreach (getArrayFromRefbackLevel($userid, $content['level']) as $refid) {
                        // Skip level zero or if both are the same
                        if ($userid == $refid) {
@@ -68,16 +68,23 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) {
 
                        // Get refback percents
                        $percents = getRefbackPercents($userid, $refid);
-                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',refid=' . $refid . ',points=' . $points . ',percents=' . $percents);
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',refid=' . $refid . ',points=' . $points . ',percents=' . $percents);
 
                        // Some percents given?
                        if ($percents > 0) {
-                               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'points=' . $points . ',[percents]=' . $content['percents'] . ',percents=' . $percents . ',level=' . $content['level']);
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'points=' . $points . ',[percents]=' . $content['percents'] . ',percents=' . $percents . ',level=' . $content['level']);
                                // Calculate points for refback
                                $refback = $points * ($content['percents'] / 100) * ($percents / 100);
 
                                // Update refback table ('refid' and 'userid' must be exchanged!)
-                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_refs` SET `points`=`points`+%s WHERE `userid`=%s AND `refid`=%s LIMIT 1",
+                               SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_user_refs`
+SET
+       `points`=`points`+%s
+WHERE
+       `userid`=%s AND
+       `refid`=%s
+LIMIT 1",
                                        array(
                                                $refback,
                                                $refid,
@@ -91,14 +98,14 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) {
                                } // END - if
 
                                // Add points again, but only directly
-                               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refback=' . $refback . ',userid=' . $userid . ',ref=' . $ref . ',refid=' . $refid . ' - UPDATE! (' . SQL_AFFECTEDROWS() . ')');
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refback=' . $refback . ',userid=' . $userid . ',ref=' . $ref . ',refid=' . $refid . ' - UPDATE! (' . SQL_AFFECTEDROWS() . ')');
                                addPointsThroughReferalSystem(sprintf("refback:%s", $refid), $userid, $refback);
 
                                // Reduce points if refid is found
                                if ($refid == $ref) {
                                        // Reduce points here!
                                        $return = $points * ($content['percents'] / 100) - $refback;
-                                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'return=' . $return . ' - REDUCED!');
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'return=' . $return . ' - REDUCED!');
                                } // END - if
                        } // END - if
                } // END foreach
@@ -111,13 +118,13 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) {
        $GLOBALS['ref_level'] = $GLOBALS['refback_depth'][$userid][$ref];
 
        // Return them
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',points=' . $points . ',ref_points=' . $ref_points . ',return=' . $return . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',points=' . $points . ',ref_points=' . $ref_points . ',return=' . $return . ' - EXIT!');
        return $return;
 }
 
 // "Getter" for refback percents
 function getRefbackPercents ($userid, $ref) {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ' - ENTERED!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ' - ENTERED!');
        // Skip identical ids
        if ($userid == $ref) {
                return 0;
@@ -136,7 +143,7 @@ function getRefbackPercents ($userid, $ref) {
                if (SQL_NUMROWS($result) == 1) {
                        // Fetch percents
                        list($GLOBALS['refback_percents'][$userid][$ref]) = SQL_FETCHROW($result);
-                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',percents=' . $GLOBALS['refback_percents'][$userid][$ref]);
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',percents=' . $GLOBALS['refback_percents'][$userid][$ref]);
                } else {
                        // Debug log
                        logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ' - No entry found. :-(');
@@ -147,13 +154,13 @@ function getRefbackPercents ($userid, $ref) {
        } // END - if
 
        // Return percents
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',refback_percents=' . $GLOBALS['refback_percents'][$userid][$ref] . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',refback_percents=' . $GLOBALS['refback_percents'][$userid][$ref] . ' - EXIT!');
        return $GLOBALS['refback_percents'][$userid][$ref];
 }
 
 // "Getter" for userid array which will return only one entry
 function getArrayFromRefbackLevel ($refid, $level) {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',level=' . $level);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',level=' . $level);
        // Init userids
        $userIds = array();
 
@@ -169,11 +176,11 @@ ORDER BY
                array($refid, $level), __FUNCTION__, __LINE__);
 
        // Entries found?
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'numRows=' . SQL_NUMROWS($result));
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'numRows=' . SQL_NUMROWS($result));
        if (!SQL_HASZERONUMS($result)) {
                // Add all
                while ($content = SQL_FETCHARRAY($result)) {
-                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',level=' . $level . ',userid=' . $content['userid']);
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',level=' . $level . ',userid=' . $content['userid']);
                        $userIds[] = $content['userid'];
                } // END - while
        } // END - if
@@ -182,137 +189,170 @@ ORDER BY
        SQL_FREERESULT($result);
 
        // Return array
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',userIds()=' . count($userIds) . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',userIds()=' . count($userIds) . ' - EXIT!');
        return $userIds;
 }
 
 // Update "refback table"
 function updateRefbackTable ($userid) {
-       // Make it sure referal level zero (member him-/herself) is at least selected
-       if (empty($GLOBALS['refback_level'])) {
-               $GLOBALS['refback_level'] = NULL;
-       } // END - if
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $GLOBALS['refback_level'] . ' - ENTERED!');
-
-       // Init refid and variables
-       $GLOBALS['refback_refid'][$GLOBALS['refback_level']] = '0';
-       $old = '0';
-       $minus = '0';
-
-       // Check for his referal
-       $result_refid = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `refid`=%s ORDER BY `userid` ASC",
-               array(bigintval($userid)), __FUNCTION__, __LINE__);
-
-       // When no entry was updated then we have to create it here
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQL_NUMROWS()=' . SQL_NUMROWS($result_refid));
-       if (!SQL_HASZERONUMS($result_refid)) {
-               // Load all refids
-               while (list($GLOBALS['refback_refid'][$GLOBALS['refback_level']]) = SQL_FETCHROW($result_refid)) {
-                       // Remmber userid
-                       $GLOBALS['refback_userid'][$GLOBALS['refback_refid'][$GLOBALS['refback_level']]] = $userid;
-
-                       // Refid set?
-                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']]);
-                       if (($GLOBALS['refback_refid'][$GLOBALS['refback_level']] > 0) && ($GLOBALS['refback_refid'][$GLOBALS['refback_level']] != $userid) && (isset($GLOBALS['refback_refid'][$GLOBALS['refback_level']]))) {
-                               // New userid?
-                               if ((isset($GLOBALS['refback_refid'][$GLOBALS['refback_level']-1])) && (isset($GLOBALS['refback_userid'][$GLOBALS['refback_refid'][$GLOBALS['refback_level']-1]]))) {
-                                       // New userid!
-                                       $old = $userid;
-                                       $userid = $GLOBALS['refback_userid'][$GLOBALS['refback_refid'][$GLOBALS['refback_level']-1]];
-                                       $minus = 1;
-                                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',old=' . $old . ',level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - NEW UID!');
-                               } // END - if
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
+       // Load all referals
+       loadRefbackTable($userid);
 
-                               // Check existence
-                               if (is_null($GLOBALS['refback_level'])) {
-                                       // Level is NULL
-                                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level` IS NULL AND `refid`=%s LIMIT 1",
-                                               array(
-                                                       bigintval($userid),
-                                                       bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])
-                                               ), __FUNCTION__, __LINE__);
-                               } else {
-                                       // Level is > 0
-                                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level`=%s AND `refid`=%s LIMIT 1",
-                                               array(
-                                                       bigintval($userid),
-                                                       bigintval($GLOBALS['refback_level']),
-                                                       bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])
-                                               ), __FUNCTION__, __LINE__);
-                               }
-
-                               // Do we have no entry?
-                               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ',minus=' . $minus . ',numRows=' . SQL_NUMROWS($result) . ' - FOUND!');
-                               if (SQL_HASZERONUMS($result)) {
-                                       // Insert this level
-                                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - ADD!');
-                                       SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_refs` (`userid`, `level`, `refid`) VALUES (%s,%s,%s)",
-                                               array(
-                                                       bigintval($userid),
-                                                       $GLOBALS['refback_level'],
-                                                       bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])
-                                               ), __FUNCTION__, __LINE__);
-
-                                       // Move to next referal level and count his counter one up!
-                                       $GLOBALS['refback_level']++;
-                                       updateRefbackTable($GLOBALS['refback_refid'][($GLOBALS['refback_level'] - 1)]);
-                               } // END - if
+       // Add missing level > 1
+       addMissingRefbackLevels($userid);
+
+       // The last step is to flush all userid's entries to the database
+       flushRefbackTableToDatabase($userid);
 
-                               // Do we have another level here?
-                               if ((($GLOBALS['refback_level']-$minus) > 0) && ($old > 0)) {
-                                       // Restore old one
-                                       $userid = $old;
-
-                                       // Shall we add this as well?
-                                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level`=%s AND `refid`=%s LIMIT 1",
-                                               array(
-                                                       bigintval($userid),
-                                                       (bigintval($GLOBALS['refback_level']) - $minus),
-                                                       bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])
-                                               ), __FUNCTION__, __LINE__);
-
-                                       // Do we have no entry?
-                                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . ($GLOBALS['refback_level'] - $minus) . ',minus=' . $minus . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ',numRows=' . SQL_NUMROWS($result) . ' - BACK!');
-                                       if (SQL_HASZERONUMS($result)) {
-                                               // Insert this level
-                                               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_refs` (`userid`, `level`, `refid`) VALUES (%s,%s,%s)",
-                                                       array(
-                                                               bigintval($userid),
-                                                               ($GLOBALS['refback_level'] - $minus),
-                                                               bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])
-                                                       ), __FUNCTION__, __LINE__);
-                                               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . ($GLOBALS['refback_level'] - $minus) . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - RETURNED!');
-                                       } // END - if
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - EXIT!');
+}
+
+// Loads all referals for given userid
+function loadRefbackTable ($userid) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
+       // Init array
+       $GLOBALS['refback_refid'][$userid] = array();
+
+       // Get all level entries from the refsystem table
+       $result = SQL_QUERY_ESC('SELECT `level` FROM `{?_MYSQL_PREFIX?}_refsystem` WHERE `userid`=%s ORDER BY `level` ASC',
+               array($userid), __FUNCTION__, __LINE__);
+
+       // Do we have entries?
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',SQL_NUMROWS()=' . SQL_NUMROWS($result));
+       if (SQL_NUMROWS($result) > 0) {
+               // Then walk through all levels
+               while (list($level) = SQL_FETCHROW($result)) {
+                       // Init array
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level);
+                       $GLOBALS['refback_refid'][$userid][$level] = array();
+
+                       // Level is = 1?
+                       if ($level == 1) {
+                               // Load all referals of this user
+                               $result_refs = SQL_QUERY_ESC('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `refid`=%s ORDER BY `userid` ASC',
+                                       array($userid), __FUNCTION__, __LINE__);
+
+                               // Do we have entries?
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',SQL_NUMROWS()=' . SQL_NUMROWS($result_refs));
+                               if (SQL_NUMROWS($result_refs) > 0) {
+                                       // Then again walk through all
+                                       while (list($refid) = SQL_FETCHROW($result_refs)) {
+                                               // Add this refid
+                                               $GLOBALS['refback_refid'][$userid][$level][] = $refid;
+                                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid);
+                                               // Load the refid's array as well
+                                               loadRefbackTable($refid);
+                                       } // END - while
                                } // END - if
+
+                               // Free result
+                               SQL_FREERESULT($result_refs);
                        } // END - if
                } // END - while
-
-               // Free memory
-               SQL_FREERESULT($result_refid);
        } // END - if
 
-       // When he has a referal...
-       if ((($GLOBALS['refback_refid'][$GLOBALS['refback_level']] == $userid) || ($GLOBALS['refback_refid'][$GLOBALS['refback_level']] == '0')) && (isExtensionInstalledAndNewer('cache', '0.1.2')) && (!isset($GLOBALS['refback_cached']))) {
-               // Remove cache here
-               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']] . ' - CACHE!');
-               if ($GLOBALS['cache_instance']->loadCacheFile('refback')) $GLOBALS['cache_instance']->removeCacheFile();
-               $GLOBALS['refback_cached'] = 1;
+       // Free result
+       SQL_FREERESULT($result);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - EXIT!');
+}
+
+// Adds missing refback levels to the array
+function addMissingRefbackLevels ($userid) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
+       // If the array is gone, you have called this function without calling loadRefbackTable()
+       if (!isset($GLOBALS['refback_refid'][$userid])) {
+               // Please fix your code
+               debug_report_bug(__FUNCTION__, __LINE__, 'Called without calling loadRefbackTable() before! userid=' . $userid);
        } // END - if
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',count()=' . count($GLOBALS['refback_refid'][$userid]));
+
+       // Now walk through the array, first levels
+       foreach ($GLOBALS['refback_refid'][$userid] as $level=>$levelArray) {
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',count()=' . count($levelArray));
+               // Next are the users
+               foreach ($levelArray as $refid) {
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid);
+                       // Does the refid have an array?
+                       if (isset($GLOBALS['refback_refid'][$refid])) {
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid . ',count()=' . count($GLOBALS['refback_refid'][$refid]));
+                               // Okay, then walk through here, too
+                               foreach ($GLOBALS['refback_refid'][$refid] as $refLevel=>$refArray) {
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid . ',refLevel=' . $refLevel . ',count()=' . count($refArray));
+                                       // Also walk through this one
+                                       foreach ($refArray as $refRefid) {
+                                               // Calculate new level
+                                               $newLevel =  $level + $refLevel;
+                                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid . ',refLevel=' . $refLevel . ',refRefid=' . $refRefid . ',newLevel=' . $newLevel);
+                                               // Is the refRefid not in?
+                                               if ((!isset($GLOBALS['refback_refid'][$userid][$newLevel])) || (!in_array($refRefid, $GLOBALS['refback_refid'][$userid][$newLevel]))) {
+                                                       // Then we must add this ref's refid to the userid's next level
+                                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',newLevel=' . $newLevel . ',refRefid=' . $refRefid . ' - ADDED!');
+                                                       $GLOBALS['refback_refid'][$userid][$newLevel][] = $refRefid;
+                                               } // END - if
+                                       } // END - foreach
+                               } // END - foreach
+                       } // END - foreach
+               } // END - foreach
+       } // END - foreach
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - EXIT!');
+}
 
-       // "Walk" back here
-       $GLOBALS['refback_level']--;
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refback_level=' . $GLOBALS['refback_level'] .' - LEVEL!');
+// Flush all entries for given userid to database
+function flushRefbackTableToDatabase ($userid) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
+       // If the array is gone, you have called this function without calling loadRefbackTable()
+       if (!isset($GLOBALS['refback_refid'][$userid])) {
+               // Please fix your code
+               debug_report_bug(__FUNCTION__, __LINE__, 'Called without calling loadRefbackTable() before! userid=' . $userid);
+       } // END - if
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',count()=' . count($GLOBALS['refback_refid'][$userid]));
 
-       // Fix empty refid
-       if (!isset($GLOBALS['refback_refid'][$GLOBALS['refback_level']-1])) {
-               $GLOBALS['refback_refid'][$GLOBALS['refback_level']-1] = '0';
+       // If no entries are there, skip this whole step
+       if (count($GLOBALS['refback_refid'][$userid]) == 0) {
+               // No entries found
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ABORTING...');
+               return;
        } // END - if
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refback_level=' . $GLOBALS['refback_level'] . ',ref=' . $GLOBALS['refback_refid'][$GLOBALS['refback_level']-1] . ' - EXIT!');
+
+       // Prepare SQL
+       $SQL = 'INSERT INTO `{?_MYSQL_PREFIX?}_user_refs` (`userid`,`level`,`refid`) VALUES ';
+
+       // Now walk through the array, first levels
+       foreach ($GLOBALS['refback_refid'][$userid] as $level=>$levelArray) {
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',count()=' . count($levelArray));
+               // Next are the users
+               foreach ($levelArray as $refid) {
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid);
+                       // Query the user_refs table
+                       list($count) = SQL_FETCHROW(SQL_QUERY_ESC('SELECT COUNT(`id`) AS `count` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level`=%s AND `refid`=%s LIMIT 1',
+                               array(
+                                       $userid,
+                                       $level,
+                                       $refid
+                               ), __FUNCTION__, __LINE__));
+
+                       // Do we have no entry?
+                       if ($count == 0) {
+                               // Then add it to the SQL
+                               $SQL .= '(' . $userid . ',' . $level . ',' . $refid . '),';
+                       } // END - if
+               } // END - foreach
+       } // END - foreach
+
+       // Remove last comma from SQL
+       $SQL = substr($SQL, 0, -1);
+
+       // And run it
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',SQL=' . $SQL);
+       SQL_QUERY($SQL, __FUNCTION__, __LINE__);
+
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - EXIT!');
 }
 
 // "Getter" for array for user refs in given level
 function getArrayFromRefbackUserRefs ($userid, $level) {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ' - ENTERED!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ' - ENTERED!');
        // Default is no refs and no nickname
        $refs = array();
 
@@ -324,6 +364,8 @@ function getArrayFromRefbackUserRefs ($userid, $level) {
        r.`points`,
        d.`status`,
        d.`joined`,
+       d.`mails_confirmed`,
+       d.`emails_received`,
        d.`refid` AS `level_refid`
 FROM
        `{?_MYSQL_PREFIX?}_user_refs` AS r
@@ -342,6 +384,15 @@ ORDER BY
        if (!SQL_HASZERONUMS($result)) {
                // Fetch all entries
                while ($row = SQL_FETCHARRAY($result)) {
+                       // Init click rate
+                       $row['click_rate'] = '0';
+
+                       // Does he have received some mails?
+                       if ($row['emails_received'] > 0) {
+                               // Calculate click rate
+                               $row['click_rate'] = ($row['mails_confirmed'] / $row['emails_received'] * 100);
+                       } // END - if
+
                        // Add row
                        $refs[$row['id']] = $row;
                } // END - while
@@ -351,13 +402,13 @@ ORDER BY
        SQL_FREERESULT($result);
 
        // Return result
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refs()=' . count($refs) . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refs()=' . count($refs) . ' - EXIT!');
        return $refs;
 }
 
 // "Getter" for refback entry
 function getArrayFromUserRefbackData ($id) {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ' - ENTERED!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ' - ENTERED!');
        // Default data is nothing
        $data = array();
 
@@ -378,13 +429,13 @@ function getArrayFromUserRefbackData ($id) {
        SQL_FREERESULT($result);
 
        // Return entry
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',data()=' . count($data) . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',data()=' . count($data) . ' - EXIT!');
        return $data;
 }
 
 // Update refback percents (but with some sanity-checks!
 function updateMemberRefbackPercents ($id, $percents) {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',percents=' . $percents . ' - ENTERED!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',percents=' . $percents . ' - ENTERED!');
        // Default status is failed
        $status['message'] = '{--MEMBER_REFBACK_ERROR_GENERAL--}';
 
@@ -443,7 +494,7 @@ function updateMemberRefbackPercents ($id, $percents) {
        $status['ok'] = true;
 
        // Return status array
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',percents=' . $percents . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',percents=' . $percents . ' - EXIT!');
        return $status;
 }
 
index 1e431f4fb9701400fa27da93d53d827837f53705..fb506673a8eaee97423b1e96ae3e237eccd8aa5c 100644 (file)
@@ -118,10 +118,12 @@ if (!SQL_HASZERONUMS($result)) {
                foreach (getArrayFromRefbackUserRefs(getMemberId(), $content['level']) as $refRow) {
                        // Not-deleted account is default
                        $deleted = false;
-                       if (is_null($refRow['status'])) $deleted = true;
+                       if (is_null($refRow['status'])) {
+                               $deleted = true;
+                       } // END - if
 
                        // Add/"translate" more content
-                       // @TODO UNUSED: $refRow['status']      = translateUserStatus($refRow['status']);
+                       $refRow['click_rate']  = translateComma($refRow['click_rate'], true, 1);
                        $refRow['joined']      = generateDateTime($refRow['joined'], '3');
 
                        // Load row template
index f8fb335492a0aeb071ea12b5dcea284df00928e8..f41db9da7836cff4376f83530680beb841b8eb4d 100644 (file)
@@ -68,7 +68,7 @@ if (!SQL_HASZERONUMS($result)) {
                // Check for users ref in this level
                foreach (getUserReferalPoints(getMemberId(), $content['level']) as $refRow) {
                        // Add/"translate" more content
-                       $refRow['clickrate']   = translateComma($refRow['clickrate'], true, 1);
+                       $refRow['click_rate']   = translateComma($refRow['click_rate'], true, 1);
 
                        // Load row template
                        $rows .= loadTemplate('member_ref_list_row', true, $refRow);
index 9ffbb0297cb7c67fdbc5d356251cdc2ab18c7919..2fd3d23d535598de2b0c1021b3bc4633719377a9 100644 (file)
@@ -155,9 +155,9 @@ function addYouAreHereLink ($accessLevel, $FQFN, $return = false) {
                $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: */ debugOutput(__LINE__.'*'.$type.'/'.getWhat().'*');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $type . 'getWhat()=' . getWhat());
                if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) {
-                       //* DEBUG: */ debugOutput(__LINE__.'+'.$type.'+');
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $type);
                        // Add closing div and br-tag
                        $OUT .= '</div>';
                        $GLOBALS['nav_depth'] = '0';
@@ -208,12 +208,12 @@ ORDER BY
        `sort` ASC",
                array($mode), __FUNCTION__, __LINE__);
 
-       //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . ':' . getWhat() . '*');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',getWhat()=' . getWhat());
        if (!SQL_HASZERONUMS($result_main)) {
                // There are menus available, so we simply display them... :)
                $GLOBALS['rows'] = '';
                while ($content = SQL_FETCHARRAY($result_main)) {
-                       //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . ':' . getWhat() . '*');
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',action=' . $content['action'] . ',getWhat()=' . getWhat());
                        // Disable the block-mode
                        enableBlockMode(false);
 
@@ -251,7 +251,7 @@ ORDER BY
                                        $OUT = '';
 
                                        // Full file name for checking menu
-                                       //* DEBUG: */ debugOutput(__LINE__ . ':!!!!' . $content['sub_what'] . '!!!');
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sub_what=' . $content['sub_what']);
                                        $inc = sprintf("inc/modules/%s/what-%s.php", $mode, $content['sub_what']);
                                        if (isIncludeReadable($inc)) {
                                                // Mark currently selected menu - open
@@ -308,12 +308,12 @@ ORDER BY
                                if (isFileReadable($INC)) {
                                        // Load include file
                                        if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_begin', true, $mode);
-                                       //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . '/' . getWhat().'*');
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',action=' . $content['action'] . ',getWhat()=' . getWhat());
                                        loadInclude($INC);
-                                       //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . '/' . getWhat() . '*');
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',action=' . $content['action'] . ',getWhat()=' . getWhat());
                                        if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_end', true, $mode);
                                }
-                               //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . '/' . $content['sub_what'] . ':' . getWhat() . '*');
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',action=' . $content['action'] . ',getWhat()=' . getWhat());
                        }
 
                        // Free result
@@ -322,7 +322,7 @@ ORDER BY
                        // Count one up
                        $main_cnt++;
 
-                       //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . ':' . getWhat() . '*');
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',getWhat()=' . getWhat());
                        if (SQL_NUMROWS($result_main) > $main_cnt) {
                                // Add seperator
                                $GLOBALS['rows'] .= loadTemplate('menu_seperator', true, $mode);
@@ -357,7 +357,7 @@ ORDER BY
                );
 
                // Load main template
-               //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . '/' . $content['sub_what'] . ':' . getWhat() . '*');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',getWhat()=' . getWhat());
                loadTemplate('menu_table', false, $content);
        } // END - if
 }
@@ -540,7 +540,7 @@ function isAdmin () {
                $adminId    = getCurrentAdminId();
                $passCookie = getAdminMd5();
        } // END - if
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId.'/'.$passCookie);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mainId=' . $adminId . 'passCookie=' . $passCookie);
 
        // Abort if admin id is zero
        if ($adminId == '0') {
@@ -674,7 +674,7 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) {
        $add = '';
        if ((!isAdmin()) && ($mode != 'admin')) $add = " AND `locked`='N'";
 
-       //* DEBUG: */ debugOutput(__LINE__ . ':' . $mode . '/' . $action . '/' . $what . '*');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mode=' . $mode . ',action=' . $action . ',what=' . $what);
        if (($mode != 'admin') && ($updateEntry === true)) {
                // Update guest or member menu
                $sql = SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET `counter`=`counter`+1 WHERE `action`='%s' AND `what`='%s'".$add." LIMIT 1",
@@ -724,10 +724,10 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) {
 
 // Get action value from mode (admin/guest/member) and what-value
 function getActionFromModuleWhat ($module, $what) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'module=' . $module . ',what=' . $what);
        // Init status
        $data['action'] = '';
 
-       //* DEBUG: */ debugOutput(__LINE__ . '=' . $module . '/'.$what . '/' . getAction() . '=');
        if (!isExtensionInstalledAndNewer('sql_patches', '0.0.5')) {
                // sql_patches is missing so choose depending on mode
                if (isWhatSet()) {
@@ -928,7 +928,7 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
        // Init count/sum
        $data['res'] = '0';
 
-       //* DEBUG: */ debugOutput($search.'/'.$tableName.'/'.$lookFor.'/'.$whereStatement.'/'.$add);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',tableName=' . $tableName . ',lookFor=' . $lookFor . ',whereStatement=' . $whereStatement . ',add=' . $add);
        if ((empty($search)) && ($search != '0')) {
                // Count or sum whole table?
                if ($countRows === true) {
@@ -948,7 +948,7 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
                }
        } elseif (($countRows === true) || ($lookFor == 'userid')) {
                // Count rows
-               //* DEBUG: */ debugOutput('COUNT!');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'COUNT!');
                $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'".$add,
                        array(
                                $lookFor,
@@ -959,7 +959,7 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
                        ), __FUNCTION__, __LINE__);
        } else {
                // Add all rows
-               //* DEBUG: */ debugOutput('SUM!');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SUM!');
                $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'".$add,
                        array(
                                $lookFor,
@@ -986,7 +986,7 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
        }
 
        // Return value
-       //* DEBUG: */ debugOutput('ret=' . $data['res']);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'res=' . $data['res']);
        return $data['res'];
 }
 // Getter fro ref level percents
@@ -1026,7 +1026,7 @@ function getReferalLevelPercents ($level) {
 
 // Initializes the referal system
 function initReferalSystem () {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' Referal system initialized!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' Referal system initialized!');
        $GLOBALS['ref_level']  = NULL;
        $GLOBALS['ref_system'] = true;
 }
@@ -1040,24 +1040,14 @@ function initReferalSystem () {
  * points        = ... xxx points
  * refid         = inc/modules/guest/what-confirm.php need this
  * locked        = Shall I pay it to normal (false) or locked (true) points ammount?
- * paymentMethod = Deprecated parameter, the payment method
  */
-function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = '0', $paymentMethod = 'INVALID') {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',sendNotify=' . intval($sendNotify) . ',refid=' . $refid . ',paymentMethod=' . $paymentMethod . ' - ENTERED!');
+function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = '0') {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',refid=' . $refid . ' - ENTERED!');
        // By default nothing has been added
        $added = false;
 
-       // Convert mode to upper-case
-       $paymentMethod = strtoupper($paymentMethod);
-
-       // Is it not invalid?
-       if ($paymentMethod != 'INVALID') {
-               // We are not using this anymore
-               debug_report_bug(__FUNCTION__, __LINE__, 'subject=' . $subject . ',paymentMethod=' . $paymentMethod . ' - deprecated parameter used.');
-       } // END - if
-
        // Determine payment method and notification
-       $paymentMethod = getPaymentMethodFromSubject($subject);
+       $paymentMethod = strtoupper(getPaymentMethodFromSubject($subject));
        $sendNotify    = isPaymentRecipientNotificationEnabled($subject);
 
        // When $userid = '0' add points to jackpot
@@ -1067,7 +1057,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = '0'
        } // END - if
 
        // Check user account
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',points=' . $points);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',points=' . $points);
        if (fetchUserData($userid)) {
                // Determine wether the user has some mails to click before he/she gets the points
                $locked = ifUserPointsLocked($userid);
@@ -1080,19 +1070,19 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = '0'
 
                // Get percents
                $per = getReferalLevelPercents($GLOBALS['ref_level']);
-               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points.',depth='.$GLOBALS['ref_level'].',per='.$per.',mode='.$paymentMethod);
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points.',depth='.$GLOBALS['ref_level'].',per='.$per.',mode='.$paymentMethod);
 
                // Some percents found?
                if ($per > 0) {
                        // Calculate new points
                        $ref_points = $points * $per / 100;
-                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points.',per='.$per.',depth='.$GLOBALS['ref_level'].',ref_points='.$ref_points);
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points.',per='.$per.',depth='.$GLOBALS['ref_level'].',ref_points='.$ref_points);
 
                        // Pay refback here if level > 0 and in ref-mode
                        if ((isExtensionActive('refback')) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($paymentMethod == 'REFERAL') && (isset($GLOBALS['cache_array']['add_userid'][$userid]))) {
-                               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - BEFORE!');
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - BEFORE!');
                                $ref_points = addRefbackPoints($GLOBALS['cache_array']['add_userid'][$userid], $userid, $points, $ref_points);
-                               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - AFTER!');
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - AFTER!');
                        } // END - if
 
                        // Update points...
@@ -1116,7 +1106,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = '0'
                                                bigintval($GLOBALS['ref_level'])
                                        ), __FUNCTION__, __LINE__);
                        }
-                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pointsColumn='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$paymentMethod.' - UPDATE! ('.SQL_AFFECTEDROWS().')');
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pointsColumn='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$paymentMethod.' - UPDATE! ('.SQL_AFFECTEDROWS().')');
 
                        // No entry updated?
                        if (SQL_HASZEROAFFECTED()) {
@@ -1128,12 +1118,12 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = '0'
                                                makeZeroToNull($GLOBALS['ref_level']),
                                                $ref_points
                                        ), __FUNCTION__, __LINE__);
-                               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'data='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$paymentMethod.' - INSERTED! ('.SQL_AFFECTEDROWS().')');
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'data='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$paymentMethod.' - INSERTED! ('.SQL_AFFECTEDROWS().')');
                        } // END - if
 
                        // Check affected rows
                        $added = SQL_AFFECTEDROWS();
-                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added='.intval($added));
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added='.intval($added));
 
                        // Prepare data for the filter
                        $filterData = array(
@@ -1155,7 +1145,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = '0'
 
                        // Extract $added
                        $added = $filterData['added'];
-                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added='.intval($added));
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added='.intval($added));
 
                        // Points updated, maybe I shall send him an email?
                        if (($sendNotify === true) && (isValidUserId(getUserData('refid'))) && ($locked === false)) {
@@ -1192,82 +1182,83 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = '0'
 
                        // Increase referal level
                        $GLOBALS['ref_level']++;
-                       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' Referal level increased, ref_level=' . $GLOBALS['ref_level']);
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' Referal level increased, ref_level=' . $GLOBALS['ref_level']);
 
                        // Maybe there's another ref?
                        if ((isValidUserId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($paymentMethod == 'REFERAL')) {
                                // Then let's credit him here...
-                               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . getUserData('refid') . ',points=' . $points . ',ref_points=' . $ref_points . ' - ADVANCE!');
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . getUserData('refid') . ',points=' . $points . ',ref_points=' . $ref_points . ' - ADVANCE!');
                                $added = ($added && addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, getUserData('refid')));
                        } // END - if
                } // END - if
        } // END - if
 
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',sendNotify=' . intval($sendNotify) . ',refid=' . $refid . ',paymentMethod=' . $paymentMethod . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',sendNotify=' . intval($sendNotify) . ',refid=' . $refid . ',paymentMethod=' . $paymentMethod . ' - EXIT!');
        return $added;
 }
 
 // Updates the referal counter
 function updateReferalCounter ($userid) {
-       // Make it sure referal level zero (member him-/herself) is at least selected
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
+       // Init referal id
+       $ref = NULL;
+
+       // Check for his referal
+       if (fetchUserData($userid)) {
+               // Get it
+               $ref = getUserData('refid');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . makeZeroToNull($ref) . ' - FETCHED!');
+       } // END - if
+
+       // Init entries
        if (empty($GLOBALS['cache_array']['ref_level'][$userid])) {
                $GLOBALS['cache_array']['ref_level'][$userid] = NULL;
        } // END - if
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',level='.$GLOBALS['cache_array']['ref_level'][$userid]);
+       if (empty($GLOBALS['cache_array']['ref_level'][$ref])) {
+               $GLOBALS['cache_array']['ref_level'][$ref] = NULL;
+       } // END - if
+
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . makeZeroToNull($ref));
 
-       // Update counter
-       if (!is_null($GLOBALS['cache_array']['ref_level'][$userid])) {
-               // Level is > 0
+       // When he has a referal...
+       if (($ref > 0) && ($ref != $userid)) {
+               // Move to next referal level and count his counter one up
+               $GLOBALS['cache_array']['ref_level'][$ref] = $GLOBALS['cache_array']['ref_level'][$userid] + 1;
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref(' . $ref . ')=' . $GLOBALS['cache_array']['ref_level'][$ref] . ' - ADVANCED!');
+
+               // Update counter
                SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refsystem` SET `counter`=`counter`+1 WHERE `userid`=%s AND `level`=%s LIMIT 1",
                        array(
-                                       bigintval($userid),
-                               bigintval($GLOBALS['cache_array']['ref_level'][$userid])
+                               bigintval($ref),
+                               bigintval($GLOBALS['cache_array']['ref_level'][$ref])
                        ), __FUNCTION__, __LINE__);
 
                // When no entry was updated then we have to create it here
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'updated=' . SQL_AFFECTEDROWS());
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ref=' . $ref . ',level=' . $GLOBALS['cache_array']['ref_level'][$ref] . ',updated=' . SQL_AFFECTEDROWS());
                if (SQL_HASZEROAFFECTED()) {
                        // First count!
                        SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refsystem` (`userid`, `level`, `counter`) VALUES (%s,%s,1)",
                                array(
-                                       bigintval($userid),
-                                       makeZeroToNull($GLOBALS['cache_array']['ref_level'][$userid])
+                                       bigintval($ref),
+                                       makeZeroToNull($GLOBALS['cache_array']['ref_level'][$ref])
                                ), __FUNCTION__, __LINE__);
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS());
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ref=' . $ref . ',level=' . $GLOBALS['cache_array']['ref_level'][$ref] . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS());
                } // END - if
-       } // END - if
 
-       // Init referal id
-       $ref = '0';
-
-       // Check for his referal
-       if (fetchUserData($userid)) {
-               // Get it
-               $ref = getUserData('refid');
-       } // END - if
-
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',ref='.$ref);
-
-       // When he has a referal...
-       if (($ref > 0) && ($ref != $userid)) {
-               // Move to next referal level and count his counter one up!
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ref='.$ref.' - ADVANCE!');
-               $GLOBALS['cache_array']['ref_level'][$userid]++;
+               // Advance to next level
                updateReferalCounter($ref);
        } elseif ((($ref == $userid) || ($ref == '0')) && (isExtensionInstalledAndNewer('cache', '0.1.2'))) {
                // Remove cache here
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ref='.$ref.' - CACHE!');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ref=' . makeZeroToNull($ref) . ' - CACHE!');
                rebuildCache('refsystem', 'refsystem');
        }
 
-       // "Walk" back here
-       $GLOBALS['cache_array']['ref_level'][$userid]--;
-
        // Handle refback here if extension is installed
        // @TODO Rewrite this to a filter
        if (isExtensionActive('refback')) {
                updateRefbackTable($userid);
        } // END - if
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . makeZeroToNull($ref) . ',level=' . makeZeroToNull($GLOBALS['cache_array']['ref_level'][$ref]) . ' - EXIT!');
 }
 
 // Sends out mail to all administrators. This function is no longer obsolete
@@ -1666,7 +1657,7 @@ function getWhatFromModule ($modCheck) {
        // Default is empty
        $what = '';
 
-       //* DEBUG: */ debugOutput(__LINE__.'!'.$modCheck.'!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'modCheck=' . $modCheck);
        switch ($modCheck) {
                case 'admin':
                        $what = 'overview';
@@ -1697,7 +1688,10 @@ function getWhatFromModule ($modCheck) {
 function subtractPoints ($subject, $userid, $points) {
        // Add points to used points
        SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `used_points`=`used_points`+%s WHERE `userid`=%s LIMIT 1",
-               array($points, bigintval($userid)), __FUNCTION__, __LINE__);
+               array(
+                       $points,
+                       bigintval($userid)
+               ), __FUNCTION__, __LINE__);
 
        // Prepare filter data
        $filterData = array(
@@ -1709,7 +1703,7 @@ function subtractPoints ($subject, $userid, $points) {
        );
 
        // Insert booking record
-       $filterData = runFilterChain('sub_points', $filterData);
+       $filterData = runFilterChain('post_sub_points', $filterData);
 
        // Return result
        return $filterData['added'];
@@ -1953,13 +1947,13 @@ ORDER BY
                        // Get unconfirmed mails
                        $row['unconfirmed']  = countSumTotalData($row['refid'], 'user_links', 'id', 'userid', true);
 
-                       // Init clickrate with zero
-                       $row['clickrate'] = '0';
+                       // Init click rate with zero
+                       $row['click_rate'] = '0';
 
                        // Is at least one mail received?
                        if ($row['emails_received'] > 0) {
-                               // Calculate clickrate
-                               $row['clickrate'] = ($row['mails_confirmed'] / $row['emails_received'] * 100);
+                               // Calculate click rate
+                               $row['click_rate'] = ($row['mails_confirmed'] / $row['emails_received'] * 100);
                        } // END - if
 
                        // Activity is 'active' by default because if autopurge is not installed
index 4384212523182b1da67ba855a6244deea58cda4c..97fe0ab20a436f2dcc43b012ff1d17dda9428671 100644 (file)
@@ -1061,7 +1061,7 @@ function isDebuggingTemplateCache () {
 
 // Wrapper for fetchUserData() and getUserData() calls
 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
        // Is it cached?
        if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
                // Default is 'guest'
@@ -1078,7 +1078,7 @@ function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
        } // END - if
 
        // Return it
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
        return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
 }
 
@@ -2480,7 +2480,7 @@ function generateWrappedUserEmailLink ($email) {
 
 // Wrapper to check if user points are locked
 function ifUserPointsLocked ($userid) {
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
        // Do we have cache?
        if (!isset($GLOBALS[__FUNCTION__][$userid])) {
                // Determine it
@@ -2488,7 +2488,7 @@ function ifUserPointsLocked ($userid) {
        } // END - if
 
        // Return cache
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
        return $GLOBALS[__FUNCTION__][$userid];
 }
 
index 401e47f7f5c4ccaeb7825c67e969aeb81620ad6c..175675837275ef092ca64c6407cdfe5c211bdbe6 100644 (file)
@@ -1,6 +1,6 @@
 DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_admin_menu`;
 CREATE TABLE `{?_MYSQL_PREFIX?}_admin_menu` (
-  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
+  `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
   `action` VARCHAR(255) NOT NULL DEFAULT '',
   `what` VARCHAR(255) NULL DEFAULT NULL,
   `title` VARCHAR(50) NOT NULL DEFAULT '',
@@ -21,7 +21,7 @@ CREATE TABLE `{?_MYSQL_PREFIX?}_admins` (
 
 DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_cats`;
 CREATE TABLE `{?_MYSQL_PREFIX?}_cats` (
-  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
+  `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
   `cat` VARCHAR(255) NOT NULL DEFAULT '',
   `visible` ENUM('Y','N') NOT NULL DEFAULT 'Y',
   `sort` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
@@ -67,7 +67,7 @@ CREATE TABLE `{?_MYSQL_PREFIX?}_config` (
 
 DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_guest_menu`;
 CREATE TABLE `{?_MYSQL_PREFIX?}_guest_menu` (
-  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
+  `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
   `action` VARCHAR(255) NOT NULL DEFAULT '',
   `what` VARCHAR(255) NULL DEFAULT NULL,
   `title` VARCHAR(50) NOT NULL DEFAULT '',
@@ -80,7 +80,7 @@ CREATE TABLE `{?_MYSQL_PREFIX?}_guest_menu` (
 
 DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_max_receive`;
 CREATE TABLE `{?_MYSQL_PREFIX?}_max_receive` (
-  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
+  `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
   `value` MEDIUMINT(9) NOT NULL DEFAULT 0,
   `comment` VARCHAR(255) NOT NULL DEFAULT '',
   PRIMARY KEY  (`id`)
@@ -88,7 +88,7 @@ CREATE TABLE `{?_MYSQL_PREFIX?}_max_receive` (
 
 DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_member_menu`;
 CREATE TABLE `{?_MYSQL_PREFIX?}_member_menu` (
-  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
+  `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
   `action` VARCHAR(255) NOT NULL DEFAULT '',
   `what` VARCHAR(255) NULL DEFAULT NULL,
   `title` VARCHAR(50) NOT NULL DEFAULT '',
@@ -144,11 +144,11 @@ CREATE TABLE `{?_MYSQL_PREFIX?}_pool` (
 
 DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_refbanner`;
 CREATE TABLE `{?_MYSQL_PREFIX?}_refbanner` (
-  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
+  `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
   `url` TEXT NOT NULL,
   `alternate` TEXT NOT NULL,
   `visible` ENUM('Y','N') NOT NULL DEFAULT 'Y',
-  `counter` BIGINT(22) NOT NULL DEFAULT 0,
+  `counter` BIGINT(20) NOT NULL DEFAULT 0,
   `clicks` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
   PRIMARY KEY  (`id`)
 ) ENGINE = {?_TABLE_TYPE?} CHARACTER SET utf8 COLLATE utf8_general_ci;
@@ -163,7 +163,7 @@ CREATE TABLE `{?_MYSQL_PREFIX?}_refdepths` (
 
 DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_refsystem`;
 CREATE TABLE `{?_MYSQL_PREFIX?}_refsystem` (
-  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
+  `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
   `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
   `level` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
   `counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
index 6062fc8bc44ca902ba74f9e2fbc366490d9aed63..00d94b74e87c095bc06e4332b952e9a87552a761 100644 (file)
@@ -20,7 +20,7 @@
                <strong>{--UNCONFIRMED_LINKS--}</strong>
        </td>
        <td align="center" class="header_column bottom right">
-               <strong>{--MEMBER_EMAIL_PERCENT--}</strong>
+               <strong>{--MEMBER_CLICK_RATE--}</strong>
        </td>
        <td align="center" class="header_column bottom">
                <strong>{--MEMBER_REFLIST_ACTIVITY--}</strong>
index 44076c0f0bd7558a28a29d1f1f861fa6dd46f58e..15a722a3cc8835afc76564301d0e53f9ee324bf2 100644 (file)
@@ -12,7 +12,7 @@
                {%pipe,translateComma=$content[unconfirmed]%}
        </td>
        <td align="center" class="{%template,ColorSwitch%} bottom right">
-               $content[clickrate]&#37;
+               $content[click_rate]&#37;
        </td>
        <td align="center" class="{%template,ColorSwitch%} bottom right">
                $content[activity]
index 604e7181cab35292a34b40988d2f2063e2f62893..f27edbe28da7ebb9ed7e6c7a5d3a41e2557bb30d 100644 (file)
@@ -1,7 +1,7 @@
 <div align="center" style="padding:0px;margin:0px">
 <table border="0" cellspacing="0" cellpadding="0" class="table dashed" width="730">
 <tr>
-       <td align="center" class="header_column" colspan="6">
+       <td align="center" class="header_column" colspan="7">
                <strong>{--MEMBER_REFBACK_LIST_TITLE_1--}$content[level]{--MEMBER_REFBACK_LIST_TITLE_2--}{%pipe,translateComma=$content[percents]%}{--MEMBER_REFBACK_LIST_TITLE_3--}</strong>
        </td>
 </tr>
@@ -18,6 +18,9 @@
        <td align="center" class="header_column bottom right">
                <strong>{--MEMBER_REFBACK_POINTS--}</strong>
        </td>
+       <td align="center" class="header_column bottom right">
+               <strong>{--MEMBER_CLICK_RATE--}</strong>
+       </td>
        <td align="center" class="header_column bottom right">
                <strong>{--MEMBER_JOINED--}</strong>
        </td>
@@ -27,7 +30,7 @@
 </tr>
 $content[rows]
 <tr>
-       <td align="center" class="table_footer" colspan="6">
+       <td align="center" class="table_footer" colspan="7">
                <span class="notice">{%message,MEMBER_REFLIST_COUNTER=$content[counter]%}</span>
        </td>
 </tr>
index 78963e44b33bb7e5baa33b06bf945c67be58ba83..1a9a177cb73f6d8901730b7052eda7f967ba5f3f 100644 (file)
@@ -11,6 +11,9 @@
        <td align="center" class="{%template,ColorSwitch%} bottom right">
                {%pipe,translateComma=$content[points]%} {?POINTS?}
        </td>
+       <td align="center" class="{%template,ColorSwitch%} bottom right">
+               $content[click_rate]&#37;
+       </td>
        <td align="center" class="{%template,ColorSwitch%} bottom right">
                $content[joined]
        </td>
index c10ce3e68248424d4c5abf2182e9791e3357f05e..4e7198fddf419261592a3734a89958957043201c 100644 (file)
@@ -11,6 +11,9 @@
        <td align="center" class="{%template,ColorSwitch%} bottom right">
                {%pipe,translateComma=$content[points]%} {?POINTS?}
        </td>
+       <td align="center" class="{%template,ColorSwitch%} bottom right">
+               $content[click_rate]&#37;
+       </td>
        <td align="center" class="{%template,ColorSwitch%} bottom right">
                $content[joined]
        </td>
index 671dcd19b3351da3babf646495444c853ed5fce0..27aa7e9c1ad8cf8d7c7cf7af91e8a2e4b64909de 100644 (file)
@@ -38,7 +38,7 @@
                <strong>{%pipe,translateComma=$content[clicks]%}</strong>
        </td>
        <td align="center" class="{%template,ColorSwitch%} top">
-               {--MEMBER_EMAIL_PERCENT--}:<br />
+               {--MEMBER_CLICK_RATE--}:<br />
                <strong>{%pipe,translateComma=$content[percents]%}&#37;</strong>
        </td>
 </tr>