X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Flibs%2Frefback_functions.php;h=ff6f2dbf4319ea3bc3104d91d2b9236749b25ba7;hb=aa1fa67e62e0d175d5d801becaea4362a5b50e2a;hp=48ddd1a1928d4c3a2b5314faba46e80afa3c6955;hpb=9afd6ec5878544a7982c50ed9c0dd7de37606d5b;p=mailer.git
diff --git a/inc/libs/refback_functions.php b/inc/libs/refback_functions.php
index 48ddd1a192..ff6f2dbf43 100644
--- a/inc/libs/refback_functions.php
+++ b/inc/libs/refback_functions.php
@@ -1,7 +1,7 @@
".__LINE__."):userid={$userid},ref={$ref},level={$content['level']},points={$points}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},ref={$ref},level={$content['level']},points={$points}
");
foreach (getArrayFromRefbackLevel($userid, $content['level']) as $refid) {
// Skip level zero or if both are the same
if ($userid == $refid) continue;
// Get refback percents
$percents = getRefbackPercents($userid, $refid);
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},ref={$ref},refid={$refid},points={$points},percents={$percents}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},ref={$ref},refid={$refid},points={$points},percents={$percents}
");
// Some percents given?
if ($percents > 0) {
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):points={$points},perc={$content['percents']},percents={$percents},level={$content['level']}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):points={$points},perc={$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!)
+ // 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",
array($refback, $refid, $userid), __FUNCTION__, __LINE__);
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):refback={$refback},userid={$userid},refid={$refid} - UPDATE! (".SQL_AFFECTEDROWS().")
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):refback={$refback},userid={$userid},refid={$refid} - UPDATE! (".SQL_AFFECTEDROWS().")
");
// Add points again, but only directly
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):refback={$refback}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):refback={$refback}
");
addPointsDirectly(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: */ print(__FUNCTION__."(".__LINE__."):points={$return} - REDUCED
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):points={$return} - REDUCED
");
} // END - if
} // END - if
} // END foreach
@@ -109,7 +110,7 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) {
// "Getter" for refback percents
function getRefbackPercents ($userid, $ref) {
//* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ------------------------
- \n");
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},ref={$ref}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},ref={$ref}
");
// Skip identical ids
if ($userid == $ref) return 0;
@@ -124,10 +125,10 @@ function getRefbackPercents ($userid, $ref) {
if (SQL_NUMROWS($result) == 1) {
// Fetch percents
list($percents) = SQL_FETCHROW($result);
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):percents={$percents}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):percents={$percents}
");
} else {
// Debug log
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."): NO ENTRY FOUND! :-(
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."): NO ENTRY FOUND! :-(
");
logDebugMessage(__FUNCTION__, __LINE__, "userid={$userid},ref={$ref} - No entry found! :-(");
}
@@ -142,7 +143,7 @@ function getRefbackPercents ($userid, $ref) {
// "Getter" for userid array which will return only one entry
function getArrayFromRefbackLevel ($rid, $level) {
//* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ------------------------- \n");
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):rid={$rid},level={$level}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):rid={$rid},level={$level}
");
// Init userids
$userIds = array();
@@ -158,11 +159,11 @@ ORDER BY
array($rid, $level), __FUNCTION__, __LINE__);
// Entries found?
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):numRows=".SQL_NUMROWS($result)."
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):numRows=".SQL_NUMROWS($result)."
");
if (SQL_NUMROWS($result) > 0) {
// Add all
while ($content = SQL_FETCHARRAY($result)) {
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):rid={$rid},level={$level},userid={$content['userid']}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):rid={$rid},level={$level},userid={$content['userid']}
");
$userIds[] = $content['userid'];
} // END - while
} // END - if
@@ -171,7 +172,7 @@ ORDER BY
SQL_FREERESULT($result);
// Return array
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):rid={$rid},count()=".count($userIds)."
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):rid={$rid},count()=".count($userIds)."
");
//* DEBUG: */ print("
----------------------- ".__FUNCTION__." - EXIT ------------------------
");
return $userIds;
}
@@ -181,7 +182,7 @@ function updateRefbackTable ($userid) {
//* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ------------------------- \n");
// Make it sure referal level zero (member him-/herself) is at least selected
if (empty($GLOBALS['refback_level'])) $GLOBALS['refback_level'] = 1;
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},level={$GLOBALS['refback_level']}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},level={$GLOBALS['refback_level']}
");
// Init refid
$GLOBALS['refback_refid'][$GLOBALS['refback_level']] = '0';
@@ -192,7 +193,7 @@ function updateRefbackTable ($userid) {
array(bigintval($userid)), __FUNCTION__, __LINE__);
// When no entry was updated then we have to create it here
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):found=".SQL_NUMROWS($result_refid)."
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):found=".SQL_NUMROWS($result_refid)."
");
if (SQL_NUMROWS($result_refid) > 0) {
// Load all refids
while (list($GLOBALS['refback_refid'][$GLOBALS['refback_level']]) = SQL_FETCHROW($result_refid)) {
@@ -200,7 +201,7 @@ function updateRefbackTable ($userid) {
$GLOBALS['refback_userid'][$GLOBALS['refback_refid'][$GLOBALS['refback_level']]] = $userid;
// Refid set?
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]}
");
+ //* DEBUG: */ print(__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]]))) {
@@ -208,7 +209,7 @@ function updateRefbackTable ($userid) {
$old = $userid;
$userid = $GLOBALS['refback_userid'][$GLOBALS['refback_refid'][$GLOBALS['refback_level']-1]];
$minus = 1;
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},old={$old},level={$GLOBALS['refback_level']},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]} - NEW UID!
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},old={$old},level={$GLOBALS['refback_level']},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]} - NEW UID!
");
} // END - if
// Check existence
@@ -216,10 +217,10 @@ function updateRefbackTable ($userid) {
array(bigintval($userid), $GLOBALS['refback_level'], bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])), __FUNCTION__, __LINE__);
// Do we have no entry?
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},level={$GLOBALS['refback_level']},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]},minus={$minus},numRows=".SQL_NUMROWS($result)." - FOUND!
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},level={$GLOBALS['refback_level']},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]},minus={$minus},numRows=".SQL_NUMROWS($result)." - FOUND!
");
if (SQL_NUMROWS($result) == '0') {
// Insert this level
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},level={$GLOBALS['refback_level']},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]} - ADD!
");
+ //* DEBUG: */ print(__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__);
@@ -237,12 +238,12 @@ function updateRefbackTable ($userid) {
array(bigintval($userid), ($GLOBALS['refback_level']-$minus), bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])), __FUNCTION__, __LINE__);
// Do we have no entry?
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},level=".($GLOBALS['refback_level']-$minus).",ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]},numRows=".SQL_NUMROWS($result)." - BACK!
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},level=".($GLOBALS['refback_level']-$minus).",ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]},numRows=".SQL_NUMROWS($result)." - BACK!
");
if (SQL_NUMROWS($result) == '0') {
// 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: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},level=".($GLOBALS['refback_level']-$minus).",ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]} - RETURNED!
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},level=".($GLOBALS['refback_level']-$minus).",ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]} - RETURNED!
");
} // END - if
} // END - if
} // END - if
@@ -255,18 +256,18 @@ function updateRefbackTable ($userid) {
// 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: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]} - CACHE!
");
+ //* DEBUG: */ print(__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;
} // END - if
// "Walk" back here
$GLOBALS['refback_level']--;
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},level={$GLOBALS['refback_level']} - LEVEL!
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},level={$GLOBALS['refback_level']} - LEVEL!
");
// Fix empty refid
if (!isset($GLOBALS['refback_refid'][$GLOBALS['refback_level']-1])) $GLOBALS['refback_refid'][$GLOBALS['refback_level']-1] = '0';
- //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},level={$GLOBALS['refback_level']},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']-1]} - BACK!
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},level={$GLOBALS['refback_level']},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']-1]} - BACK!
");
//* DEBUG: */ print("
----------------------- ".__FUNCTION__." - EXIT ------------------------
");
}
@@ -288,7 +289,9 @@ function getArrayFromRefbackUserRefs ($userid, $level) {
r.refid,
r.refback,
r.points,
- d.status".$add."
+ d.status".$add.",
+ d.joined,
+ d.refid AS level_refid
FROM
`{?_MYSQL_PREFIX?}_user_refs` AS r
LEFT JOIN
@@ -328,7 +331,7 @@ function getArrayFromUserRefbackData ($id) {
$id = bigintval($id);
// Get entry from database
- $result = SQL_QUERY_ESC("SELECT `id`, `refid`, `refback`, `level` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `id`=%s AND `userid`=%s LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT `id`, `userid`, `refid`, `refback`, `level`, `points` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `id`=%s AND `userid`=%s LIMIT 1",
array($id, getMemberId()), __FUNCTION__, __LINE__);
// Is there an entry?
@@ -394,11 +397,12 @@ function updateMemberRefbackPercents ($id, $percents) {
$content = array(
'percents' => translateComma($percents),
'refid' => $dummy['refid'],
- 'level' => $dummy['level']
+ 'level' => $dummy['level'],
+ 'points' => translateComma($dummy['points']),
);
// Load member email template
- $mail = loadEmailTemplate('member_refback', $content, getMemberId());
+ $mail = loadEmailTemplate('member_refback', $content, $dummy['refid']);
// Send email to user
sendEmail($dummy['refid'], getMessage('MEMBER_REFBACK_SUBJECT'), $mail);