X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Flibs%2Frefback_functions.php;h=5d04dde4814bacde57e6cc1a47350eb9f6e3d136;hb=076e28c32b079b93b73a67b0c8710d65596b76a9;hp=1009819e4f4f326662dc5f73ac4fcfacf31fd863;hpb=dfaa8c1675da4071ea451406a6f6fedd4c568416;p=mailer.git
diff --git a/inc/libs/refback_functions.php b/inc/libs/refback_functions.php
index 1009819e4f..5d04dde481 100644
--- a/inc/libs/refback_functions.php
+++ b/inc/libs/refback_functions.php
@@ -54,9 +54,9 @@ function ADD_REFBACK_POINTS ($uid, $ref, $points, $ref_points) {
// "Walk" through all level
while (list($level, $perc) = SQL_FETCHROW($result_refs)) {
// Reset ref depths
- $DEPTH = -1;
+ unset($DEPTH);
- // "Walk through all refids
+ // "Walk" through all refids
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},ref={$ref},level={$level},points={$points}
\n";
foreach (GET_REFBACK_USERID_ARRAY($uid, $level) as $refid) {
// Skip level zero or if both are the same
@@ -69,7 +69,7 @@ function ADD_REFBACK_POINTS ($uid, $ref, $points, $ref_points) {
// Some percents given?
if ($percents > 0) {
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):points={$points},perc={$perc},percents={$percents},level={$level}
\n";
- // Get points for refback
+ // Calculate points for refback
$refback = $points * ($perc / 100) * ($percents / 100);
// Update refback table ("refid" and "uid" must be exchanged!)
@@ -123,7 +123,7 @@ function GET_REFBACK_PERCENTS ($uid, $ref) {
} else {
// Debug log
//* DEBUG: */ print __FUNCTION__."(".__LINE__."): NO ENTRY FOUND! :-(
\n";
- DEBUG_LOG(__FUNCTION__.": uid={$uid},ref={$ref} - No entry found! :-(");
+ DEBUG_LOG(__FUNCTION__, __LINE__, " uid={$uid},ref={$ref} - No entry found! :-(");
}
// Free result
@@ -170,7 +170,7 @@ function UPDATE_REFBACK_TABLE($uid) {
//* DEBUG: */ print "----------------------- ".__FUNCTION__." - ENTRY ------------------------
- \n";
global $cacheArray, $cacheInstance;
- // Make it sure referral level zero (member him-/herself) is at least selected
+ // Make it sure referal level zero (member him-/herself) is at least selected
if (empty($cacheArray['back_level'])) $cacheArray['back_level'] = 1;
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},level={$cacheArray['back_level']}
\n";
@@ -178,7 +178,7 @@ function UPDATE_REFBACK_TABLE($uid) {
$cacheArray['up_refid'][$cacheArray['back_level']] = 0;
$old = 0; $minus = 0;
- // Check for his referral
+ // 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($uid)), __FILE__, __LINE__);
@@ -214,7 +214,7 @@ function UPDATE_REFBACK_TABLE($uid) {
$result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_refs (userid,level,refid) VALUES (%s,%s,%s)",
array(bigintval($uid), $cacheArray['back_level'], bigintval($cacheArray['up_refid'][$cacheArray['back_level']])), __FILE__, __LINE__);
- // Move to next referral level and count his counter one up!
+ // Move to next referal level and count his counter one up!
$cacheArray['back_level']++; UPDATE_REFBACK_TABLE($cacheArray['up_refid'][($cacheArray['back_level'] - 1)]);
} // END - if
@@ -243,7 +243,7 @@ function UPDATE_REFBACK_TABLE($uid) {
SQL_FREERESULT($result_refid);
} // END - if
- // When he has a referral...
+ // When he has a referal...
if ((($cacheArray['up_refid'][$cacheArray['back_level']] == $uid) || ($cacheArray['up_refid'][$cacheArray['back_level']] == 0)) && (GET_EXT_VERSION("cache") >= "0.1.2") && (!isset($cacheArray['back_cached']))) {
// Remove cache here
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},ref={$cacheArray['up_refid'][$cacheArray['back_level']]} - CACHE!
\n";
@@ -267,7 +267,7 @@ function GET_USER_REFS ($uid, $level) {
$ADD = "";
$refs = array();
- // Do we have nickname installed?
+ // Do we have nickname extension installed?
if (EXT_IS_ACTIVE("nickname")) {
$ADD = ", d.nickname";
} // END - if
@@ -307,7 +307,7 @@ function GET_USER_REF_ENTRY ($id) {
$id = bigintval($id);
// Get entry from database
- $result = SQL_QUERY_ESC("SELECT id, refid, refback FROM "._MYSQL_PREFIX."_user_refs WHERE id=%s AND userid=%s LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT id, refid, refback, level FROM "._MYSQL_PREFIX."_user_refs WHERE id=%s AND userid=%s LIMIT 1",
array($id, $GLOBALS['userid']), __FILE__, __LINE__);
// Is there an entry?
@@ -334,13 +334,13 @@ function REFBACK_CHANGE_MEMBER_PERCENTS ($id, $percents) {
// No member!
$status['message'] = MEMBER_REFBACK_ERROR_NO_MEMBER;
return $status;
- } elseif ("".$id."" != "".bigintval($id)."") {
+ } elseif ("".$id."" != "".($id + 0)."") {
// No number!
- $status['message'] = MEMBER_REFBACK_INVALID_ID_NUMBER;
+ $status['message'] = MEMBER_REFBACK_ERROR_INVALID_ID_NUMBER;
return $status;
} elseif (($percents < 0) || ($percents > 100)) {
// Percentage is not valid!
- $status['message'] = MEMBER_REFBACK_INVALID_PERCENTAGE;
+ $status['message'] = MEMBER_REFBACK_ERROR_INVALID_PERCENTAGE;
return $status;
}
@@ -350,7 +350,7 @@ function REFBACK_CHANGE_MEMBER_PERCENTS ($id, $percents) {
// Is this valid?
if (count($dummy) == 0) {
// ID does not belong to user!
- $status['message'] = MEMBER_REFBACK_ID_MISMATCH;
+ $status['message'] = MEMBER_REFBACK_ERROR_ID_MISMATCH;
return $status;
} // END - if
@@ -364,10 +364,26 @@ function REFBACK_CHANGE_MEMBER_PERCENTS ($id, $percents) {
// Entry updated?
if (SQL_AFFECTEDROWS() < 1) {
// Entry not updated!
- $status['message'] = MEMBER_REFBACK_NOT_UPDATED;;
+ $status['message'] = MEMBER_REFBACK_ERROR_NOT_UPDATED;;
return $status;
} // END - if
+ // Prepare email content
+ $content = array(
+ 'percents' => TRANSLATE_COMMA($percents),
+ 'refid' => $dummy['refid'],
+ 'level' => $dummy['level']
+ );
+
+ // Load member email template
+ $mail = LOAD_EMAIL_TEMPLATE("member_refback", $content, $GLOBALS['userid']);
+
+ // Send email to user
+ SEND_EMAIL($dummy['refid'], MEMBER_REFBACK_SUBJECT, $mail);
+
+ // Send admin notification
+ SEND_ADMIN_NOTIFICATION(ADMIN_REFBACK_SUBJECT, "admin_refback", $content, $GLOBALS['userid']);
+
// All fine!
$status['ok'] = true;