./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
-./inc/referal-functions.php:308: // @TODO Rewrite this to a filter
./inc/revision-functions.php:169:// @TODO This function does also set and get in 'cache_array'
./inc/template-functions.php:1069: // @TODO Deprecate this thing
./inc/template-functions.php:1080: // @TODO Deprecate this thing
} // END - if
// Version number
-setThisExtensionVersion('0.0.3');
+setThisExtensionVersion('0.0.4');
// Version history array (add more with , '0.0.1' and so on)
-setExtensionVersionHistory(array('0.0.0','0.0.1', '0.0.2', '0.0.3'));
+setExtensionVersionHistory(array('0.0.0','0.0.1', '0.0.2', '0.0.3', '0.0.4'));
switch (getExtensionMode()) {
case 'register': // Do stuff when installation is running
- // SQL commands to run
- addDropTableSql('user_refs');
- addCreateTableSql('user_refs', "
-`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-`userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-`level` smallINT(6) UNSIGNED NOT NULL DEFAULT 0,
-`refid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-`refback` float(4,1) NOT NULL DEFAULT 0.0,
-`points` FLOAT(20,5) DEFAULT 0.00000 NOT NULL,
-PRIMARY KEY (`id`),
-UNIQUE `user_refid` (`userid`, `level`, `refid`),
-INDEX (`level`),
-INDEX (`refid`)",
- 'User Referals With Refback');
+ // Member menu
addMemberMenuSql('main', 'refback', 'Ref-Back einstellen', 4);
// Execute this special file on registration
addDropTableSql('user_refs');
addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='refback'");
addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what` IN('config_refback','list_refback')");
- addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_refsystem` SET level=level-1");
break;
case 'activate': // Do stuff when admin activates this extension
break;
case '0.0.2': // SQL queries for v0.0.2
- addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` CHANGE `userid` `userid` BIGINT(20) UNSIGNED NULL DEFAULT NULL');
- addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` CHANGE `level` `level` SMALLINT(6) UNSIGNED NULL DEFAULT NULL');
- addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` CHANGE `refid` `refid` BIGINT(20) UNSIGNED NULL DEFAULT NULL');
- addExtensionSql('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid` IS NULL OR `refid` IS NULL OR `level` IS NULL');
-
// Update notes (these will be set as task text!)
- setExtensionUpdateNotes("Updates von ext-user hier her verschoben.");
+ setExtensionUpdateNotes("Ungütiges Update seit Revision 246x.");
break;
case '0.0.3': // SQL queries for v0.0.3
// This depends on ext-sql_patches
addExtensionDependency('sql_patches');
+ // Update notes
+ setExtensionUpdateNotes("Refback-Gutschriften werden nun über die Tabelle <strong>{OPEN_CONFIG}_MYSQL_PREFIX{CLOSE_CONFIG}_points_data</strong> verwaltet.");
+ break;
+
+ case '0.0.4': // SQL queries for v0.0.4
+ // This extension update depends on ext-sql_patches
+ addExtensionDependency('user');
+
+ // SQL commands to run - drop old first, add new next
+ addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` DROP `refback`');
+ addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` DROP `points`');
+ addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` ADD `refback_percents` FLOAT(4,1) NOT NULL DEFAULT 0.0');
+ addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_user_refs` ADD `refback_points` FLOAT(20,5) NOT NULL DEFAULT 0.00000');
+
// Update notes
setExtensionUpdateNotes("Refback-Gutschriften werden nun über die Tabelle <strong>{OPEN_CONFIG}_MYSQL_PREFIX{CLOSE_CONFIG}_points_data</strong> verwaltet.");
break;
case '0.5.4': // SQL queries for v0.5.4
addMemberMenuSql('main', 'reflist', 'Ref-Übersicht', 5);
- // Depends on refback extension
- addExtensionDependency('refback');
-
// Update notes (these will be set as task text!)
setExtensionUpdateNotes("Ref-Übersicht eingebaut. Diese hängt von der Erweiterung <strong>refback</strong> ab.");
break;
} // END - if
// Version number
-setThisExtensionVersion('0.4.3');
+setThisExtensionVersion('0.4.4');
// 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', '0.4.3'));
+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', '0.4.4'));
// Keep this extension always active!
setExtensionAlwaysActive('Y');
// Update notes (these will be set as task text!)
setExtensionUpdateNotes("Überflüssiges Menü <strong>chk_regs</strong> entfernt, dies kann mit <strong>list_user</strong> übernommen werden.");
break;
+
+ case '0.4.4': // SQL queries for v0.4.4
+ // SQL commands to run
+ addDropTableSql('user_refs');
+ addCreateTableSql('user_refs', "
+`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+`userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`level` smallINT(6) UNSIGNED NOT NULL DEFAULT 0,
+`refid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+PRIMARY KEY (`id`),
+UNIQUE `user_refid` (`userid`, `level`, `refid`),
+INDEX (`level`),
+INDEX (`refid`)",
+ 'User referals');
+
+ // Update notes (these will be set as task text!)
+ setExtensionUpdateNotes("Neues Tabellenlayout und verschoben von ext-refback.");
+
+ // Load ext-refback's special include to regenerate the referal table
+ addIncludeToPool('extension', 'inc/gen_refback.php');
+ break;
} // END - switch
break;
die();
} // END - if
-// Make sure our functions are there
-loadIncludeOnce('inc/libs/refback_functions.php');
-
// Sanity-check: Do we have ref level 0?
$result = SQL_QUERY('SELECT `id` FROM `{?_MYSQL_PREFIX?}_refsystem` WHERE `level`=0 OR `level` IS NULL', __FILE__, __LINE__);
if (!SQL_HASZERONUMS($result)) {
// Begin with all users in level one
$result_direct = SQL_QUERY('SELECT
- u.userid
+ `userid`
FROM
- `{?_MYSQL_PREFIX?}_user_data` AS u
+ `{?_MYSQL_PREFIX?}_user_data`
WHERE
- u.refid=0
+ `refid`=0
ORDER BY
- u.userid ASC', __FILE__, __LINE__);
+ `userid` ASC', __FILE__, __LINE__);
// Do we have entries?
if (!SQL_HASZERONUMS($result_direct)) {
while ($content = SQL_FETCHARRAY($result_direct)) {
// Update refback table
//* DEBUG: */ debugOutput('userid=' . $content['userid']);
- updateRefbackTable($content['userid']);
+ updateReferalTable($content['userid']);
} // END - while
} // END - if
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['refback_percents'] . ',points=' . $points . ' - LOOP START!');
foreach (getArrayFromRefbackLevel($userid, $content['level']) as $refid) {
// Skip level zero or if both are the same
if ($userid == $refid) {
// 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['refback_percents'] . ',percents=' . $percents . ',level=' . $content['level']);
// Calculate points for refback
- $refback = $points * ($content['percents'] / 100) * ($percents / 100);
+ $refback = $points * ($content['refback_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
+ `refback_points`=`refback_points`+%s
WHERE
`userid`=%s AND
`refid`=%s
// Reduce points if refid is found
if ($refid == $ref) {
// Reduce points here!
- $return = $points * ($content['percents'] / 100) - $refback;
+ $return = $points * ($content['refback_percents'] / 100) - $refback;
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'return=' . $return . ' - REDUCED!');
} // END - if
} // END - if
$GLOBALS['refback_percents'][$userid][$ref] = '0';
// Get percents from database
- $result = SQL_QUERY_ESC("SELECT `refback` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `refid`=%s LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT `refback_percents` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `refid`=%s LIMIT 1",
array($ref, $userid), __FUNCTION__, __LINE__);
// Entry found? (Should be!)
FROM
`{?_MYSQL_PREFIX?}_user_refs`
WHERE
- `refid`=%s AND `level`=%s
+ `refid`=%s AND
+ `level`=%s
ORDER BY
`userid` ASC",
array($refid, $level), __FUNCTION__, __LINE__);
return $userIds;
}
-// Update "refback table"
-function updateRefbackTable ($userid) {
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
- // Load all referals
- loadRefbackTable($userid);
-
- // Add missing level > 1
- addMissingRefbackLevels($userid);
-
- // The last step is to flush all userid's entries to the database
- flushRefbackTableToDatabase($userid);
-
- //* 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
- } // END - if
-
- // 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!');
-}
-
-// 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]));
-
- // 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
-
- // 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!');
$result = SQL_QUERY_ESC("SELECT
r.`id`,
r.`refid`,
- r.`refback`,
- r.`points`,
+ r.`refback_percents`,
+ r.`refback_points`,
d.`status`,
d.`joined`,
d.`mails_confirmed`,
$id = bigintval($id);
// Get entry from database
- $result = SQL_QUERY_ESC("SELECT `id`, `userid`, `refid`, `refback`, `level`, `points` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `id`=%s AND `userid`=%s LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT `id`, `userid`, `refid`, `refback_percents`, `level`, `refback_points` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `id`=%s AND `userid`=%s LIMIT 1",
array($id, getMemberId()), __FUNCTION__, __LINE__);
// Is there an entry?
// Update entry
SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_refs` SET `refback`='%s' WHERE `id`=%s AND `userid`=%s LIMIT 1",
- array($percents, $id, getMemberId()), __FUNCTION__, __LINE__);
+ array(
+ $percents,
+ $id,
+ getMemberId()
+ ), __FUNCTION__, __LINE__);
// Entry updated?
if (SQL_HASZEROAFFECTED()) {
} // END - if
// Prepare email content
- $dummy['percents'] = $percents;
+ $dummy['refback_percents'] = $percents;
// Load member email template
$mail = loadEmailTemplate('member_refback', $dummy, $dummy['refid']);
// Was the form submitted?
if ((isFormSent('edit')) && (isPostRequestParameterSet('id'))) {
// Okay, has the user entered some values?
- if (isPostRequestParameterSet('percents')) {
+ if (isPostRequestParameterSet('refback_percents')) {
// Revert german commta for testing
- $percents = convertCommaToDot(postRequestParameter('percents'));
+ $percents = convertCommaToDot(postRequestParameter('refback_percents'));
// Validate percents
if ((($percents >= getConfig('refback_min_perc')) || (round($percents) == 0)) && ($percents <= getConfig('refback_max_perc'))) {
// Change ref-back for this direct id
- $status = updateMemberRefbackPercents(postRequestParameter('id'), postRequestParameter('percents'));
+ $status = updateMemberRefbackPercents(postRequestParameter('id'), postRequestParameter('refback_percents'));
// Check status
if (isset($status['ok'])) {
rebuildCache('refsystem', 'refsystem');
}
- // Handle refback here if extension is installed
- // @TODO Rewrite this to a filter
- if (isExtensionActive('refback')) {
- updateRefbackTable($userid);
- } // END - if
+ // Update the referal table
+ updateReferalTable($userid);
+
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . makeZeroToNull($ref) . ',level=' . makeZeroToNull($GLOBALS['cache_array']['ref_level'][$ref]) . ' - EXIT!');
}
$result = SQL_QUERY_ESC("SELECT
ur.`id`, ur.`refid`, ud.`status`, ud.`last_online`, ud.`mails_confirmed`, ud.`emails_received`
FROM
- `{?_MYSQL_PREFIX?}_user_refs` AS ur
+ `{?_MYSQL_PREFIX?}_user_refs` AS `ur`
LEFT JOIN
- `{?_MYSQL_PREFIX?}_user_points` AS up
+ `{?_MYSQL_PREFIX?}_user_points` AS `up`
ON
- ur.refid=up.userid AND
- (ur.level=0 OR ur.level IS NULL)
+ ur.`refid`=up.`userid` AND
+ (ur.`level`=0 OR ur.`level` IS NULL)
LEFT JOIN
- `{?_MYSQL_PREFIX?}_user_data` AS ud
+ `{?_MYSQL_PREFIX?}_user_data` AS `ud`
ON
ur.`refid`=ud.`userid`
WHERE
return $isEnabled;
}
+// Update "referal table"
+function updateReferalTable ($userid) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
+ // Load all referals
+ loadReferalTable($userid);
+
+ // Add missing level > 1
+ addMissingReferalLevels($userid);
+
+ // The last step is to flush all userid's entries to the database
+ flushReferalTableToDatabase($userid);
+
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - EXIT!');
+}
+
+// Loads all referals for given userid
+function loadReferalTable ($userid) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
+ // Init array
+ $GLOBALS['referal_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['referal_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['referal_refid'][$userid][$level][] = $refid;
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid);
+ // Load the refid's array as well
+ loadReferalTable($refid);
+ } // END - while
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result_refs);
+ } // END - if
+ } // END - while
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - EXIT!');
+}
+
+// Adds missing referal levels to the array
+function addMissingReferalLevels ($userid) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
+ // If the array is gone, you have called this function without calling loadReferalTable()
+ if (!isset($GLOBALS['referal_refid'][$userid])) {
+ // Please fix your code
+ debug_report_bug(__FUNCTION__, __LINE__, 'Called without calling loadReferalTable() before! userid=' . $userid);
+ } // END - if
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',count()=' . count($GLOBALS['referal_refid'][$userid]));
+
+ // Now walk through the array, first levels
+ foreach ($GLOBALS['referal_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['referal_refid'][$refid])) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid . ',count()=' . count($GLOBALS['referal_refid'][$refid]));
+ // Okay, then walk through here, too
+ foreach ($GLOBALS['referal_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['referal_refid'][$userid][$newLevel])) || (!in_array($refRefid, $GLOBALS['referal_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['referal_refid'][$userid][$newLevel][] = $refRefid;
+ } // END - if
+ } // END - foreach
+ } // END - foreach
+ } // END - foreach
+ } // END - foreach
+ } // END - foreach
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - EXIT!');
+}
+
+// Flush all entries for given userid to database
+function flushReferalTableToDatabase ($userid) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
+ // If the array is gone, you have called this function without calling loadReferalTable()
+ if (!isset($GLOBALS['referal_refid'][$userid])) {
+ // Please fix your code
+ debug_report_bug(__FUNCTION__, __LINE__, 'Called without calling loadReferalTable() before! userid=' . $userid);
+ } // END - if
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',count()=' . count($GLOBALS['referal_refid'][$userid]));
+
+ // If no entries are there, skip this whole step
+ if (count($GLOBALS['referal_refid'][$userid]) == 0) {
+ // No entries found
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ABORTING...');
+ return;
+ } // END - if
+
+ // Prepare SQL
+ $SQL = 'INSERT INTO `{?_MYSQL_PREFIX?}_user_refs` (`userid`,`level`,`refid`) VALUES ';
+
+ // Now walk through the array, first levels
+ foreach ($GLOBALS['referal_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!');
+}
+
// [EOF]
?>
-----------------------------------
Ref-Back: {%pipe,translateComma=$content[percents]%}%
-----------------------------------
-Bereits erhalten: {%pipe,translateComma=$content[points]%} {?POINTS?}
+Bereits erhalten: {%pipe,translateComma=$content[refback_points]%} {?POINTS?}
-----------------------------------
Mit freundlichen Grüßen,
Ref-Back: {%pipe,translateComma=$content[percents]%}%
------------------------------
-Sie haben bereits {%pipe,translateComma=$content[points]%} {?POINTS?} Ref-Back-Vergütung an das Mitglied abgegeben.
+Sie haben bereits {%pipe,translateComma=$content[refback_points]%} {?POINTS?} Ref-Back-Vergütung an das Mitglied abgegeben.
Mit freundlichen Grüßen,
Ihr {?MAIN_TITLE?} Team
</div>
<div class="bottom" align="center">
{--MEMBER_REFBACK_PERCENTS--}:
- <input type="text" class="form_field" name="percents" size="6" maxlength="7" value="{%pipe,translateComma=$content[refback]%}" />%
+ <input type="text" class="form_field" name="refback_percents" size="6" maxlength="7" value="{%pipe,translateComma=$content[refback_percents]%}" />%
</div>
<div class="table_footer">
<input type="reset" class="form_reset" value="{--CLEAR_FORM--}" />
$content[level_refid]
</td>
<td align="center" class="{%template,ColorSwitch%} bottom right">
- {%pipe,translateComma=$content[refback]%}%
+ {%pipe,translateComma=$content[refback_percents]%}%
</td>
<td align="center" class="{%template,ColorSwitch%} bottom right">
- {%pipe,translateComma=$content[points]%} {?POINTS?}
+ {%pipe,translateComma=$content[refback_points]%} {?POINTS?}
</td>
<td align="center" class="{%template,ColorSwitch%} bottom right">
$content[click_rate]%
$content[level_refid]
</td>
<td align="center" class="{%template,ColorSwitch%} bottom right">
- {%pipe,translateComma=$content[refback]%}%
+ {%pipe,translateComma=$content[refback_percents]%}%
</td>
<td align="center" class="{%template,ColorSwitch%} bottom right">
- {%pipe,translateComma=$content[points]%} {?POINTS?}
+ {%pipe,translateComma=$content[refback_points]%} {?POINTS?}
</td>
<td align="center" class="{%template,ColorSwitch%} bottom right">
$content[click_rate]%