X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=inc%2Flibs%2Frefback_functions.php;h=82746fe51dc5e5d6d03c8e0de926f16604682f87;hb=f2edf32502b2774dc17ef419a2e6a1c60e361c0a;hp=2b024b81c873f3f50a57d4b5dbc8247091a50286;hpb=debaac55fafff501de5077f3672623c0d738a5b2;p=mailer.git
diff --git a/inc/libs/refback_functions.php b/inc/libs/refback_functions.php
index 2b024b81c8..82746fe51d 100644
--- a/inc/libs/refback_functions.php
+++ b/inc/libs/refback_functions.php
@@ -1,7 +1,7 @@
".__FUNCTION__." - ENTRY ------------------------
- \n";
+function addRefbackPoints ($userid, $ref, $points, $ref_points) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',points=' . $points . ',ref_points=' . $ref_points . ' - ENTERED!');
// Back ref depths
- $GLOBALS['cache_array']['depth'][$uid][$ref] = $GLOBALS['ref_level'];
+ $GLOBALS['refback_depth'][$userid][$ref] = $GLOBALS['ref_level'];
// Init points
- $return = $points;
+ $return = $ref_points;
// Get all ref levels
- $result_refs = SQL_QUERY("SELECT level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE level > 0 ORDER BY level ASC",
+ $result_refs = SQL_QUERY('SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level` > 0 ORDER BY `level` ASC',
__FUNCTION__, __LINE__);
// "Walk" through all level
while ($content = SQL_FETCHARRAY($result_refs)) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'level=' . $content['level'] . ',percents=' . $content['percents'] . ' - LOOP START!');
// Reset ref depths
- unset($GLOBALS['ref_level']);
+ initReferralSystem();
- // "Walk" through all refids
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},ref={$ref},level={$content['level']},points={$points}
\n";
- foreach (GET_REFBACK_USERID_ARRAY($uid, $content['level']) as $refid) {
- // Skip level zero or if both are the same
- if ($uid == $refid) continue;
+ // Init array
+ $refids = getArrayFromRefbackLevel($userid, $content['level']);
- // Get refback percents
- $percents = GET_REFBACK_PERCENTS($uid, $refid);
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},ref={$ref},refid={$refid},points={$points},percents={$percents}
\n";
+ // "Walk" through all refids
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',level=' . $content['level'] . ',percents=' . $content['percents'] . ',points=' . $points . ' - LOOP START!');
+ foreach ($refids as $refid) {
+ /*
+ * Get refback percents, do not swap $refid and $userid by the next
+ * call. If you do so, you will check the wrong direction, $userid
+ * is always bigger than $refid.
+ */
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . convertNullToZero($refid) . ' - CALLING getRefbackPercents()');
+ $content['refback_percents'] = getRefbackPercents($refid, $userid);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . convertNullToZero($refid) . ',refback_percents=' . $content['refback_percents']);
// Some percents given?
- if ($percents > 0) {
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):points={$points},perc={$content['percents']},percents={$percents},level={$content['level']}
\n";
+ if ($content['refback_percents'] > 0) {
// Calculate points for refback
- $refback = $points * ($content['percents'] / 100) * ($percents / 100);
-
- // Update refback table ("refid" and "uid" 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, $uid), __FUNCTION__, __LINE__);
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):refback={$refback},uid={$uid},refid={$refid} - UPDATE! (".SQL_AFFECTEDROWS().")
\n";
+ $refbackPoints = $points * ($content['percents'] / 100) * ($content['refback_percents'] / 100);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'points=' . $points . ',percents=' . $content['percents'] . ',refback_percents=' . $content['refback_percents'] . ',level=' . $content['level'] . ',refback_points=' . $refbackPoints);
+
+ // Update refback table ('refid' and 'userid' must be exchanged!)
+ SQL_QUERY_ESC('UPDATE
+ `{?_MYSQL_PREFIX?}_user_refs`
+SET
+ `refback_points`=`refback_points`+%s
+WHERE
+ `userid`=%s AND
+ `refid`=%s
+LIMIT 1',
+ array(
+ $refbackPoints,
+ $refid,
+ $userid
+ ), __FUNCTION__, __LINE__);
+
+ // Something must have been updated
+ if (SQL_HASZEROAFFECTED()) {
+ // Please report this bug
+ reportBug(__FUNCTION__, __LINE__, 'Nothing has been updated in user_refs,userid=' . $userid . ',refid=' . convertNullToZero($refid) . ',refbackPoints=' . $refbackPoints);
+ } // END - if
// Add points again, but only directly
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):refback={$refback}
\n";
- ADD_POINTS_REFSYSTEM(sprintf("refback:%s", $refid), $uid, $refback, false, "0", false, "direct");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refbackPoints=' . $refbackPoints . ',userid=' . $userid . ',ref=' . $ref . ',refid=' . convertNullToZero($refid) . ' - REFBACK-UPDATE! (' . SQL_AFFECTEDROWS() . ')');
+ addPointsThroughReferralSystem(sprintf("refback:%s", $refid), $userid, $refbackPoints);
// Reduce points if refid is found
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . $refid . ',ref=' . $ref . ' - REDUCING?');
if ($refid == $ref) {
// Reduce points here!
- $return = $points * ($content['percents'] / 100) - $refback;
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):points={$return} - REDUCED
\n";
+ $return = $points * ($content['percents'] / 100) - $refbackPoints;
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'return=' . $return . ' - REDUCED!');
} // END - if
} // END - if
} // END foreach
@@ -99,67 +120,83 @@ function ADD_REFBACK_POINTS ($uid, $ref, $points, $ref_points) {
SQL_FREERESULT($result_refs);
// Restore ref depth
- $GLOBALS['ref_level'] = $GLOBALS['cache_array']['depth'][$uid][$ref];
+ $GLOBALS['ref_level'] = $GLOBALS['refback_depth'][$userid][$ref];
// Return them
- //* DEBUG: */ print "
----------------------- ".__FUNCTION__." - EXIT ------------------------
\n";
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ',points=' . $points . ',ref_points=' . $ref_points . ',return=' . $return . ' - EXIT!');
return $return;
}
-// "Getter" for refback percents
-function GET_REFBACK_PERCENTS ($uid, $ref) {
- //* DEBUG: */ print "----------------------- ".__FUNCTION__." - ENTRY ------------------------- \n";
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},ref={$ref}
\n";
- // Skip identical ids
- if ($uid == $ref) return 0;
-
- // Default is zero
- $percents = 0;
-
- // Get percents from database
- $result = SQL_QUERY_ESC("SELECT refback FROM `{!_MYSQL_PREFIX!}_user_refs` WHERE userid=%s AND refid=%s LIMIT 1",
- array($ref, $uid), __FUNCTION__, __LINE__);
-
- // Entry found? (Should be!)
- if (SQL_NUMROWS($result) == 1) {
- // Fetch percents
- list($percents) = SQL_FETCHROW($result);
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):percents={$percents}
\n";
- } else {
- // Debug log
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."): NO ENTRY FOUND! :-(
\n";
- DEBUG_LOG(__FUNCTION__, __LINE__, " uid={$uid},ref={$ref} - No entry found! :-(");
- }
+/**
+ * "Getter" for refback percents
+ *
+ * @param $userid "Current" user's userid
+ * @param $refid $userid has this userid as referral
+ * @return $percents Refback percents $userid has given to $refid
+ */
+function getRefbackPercents ($userid, $refid) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . $refid . ' - ENTERED!');
+ if ((!isValidUserId($userid)) || (!isValidUserId($refid))) {
+ // userid and/or refid is invalid
+ reportBug(__FUNCTION__, __LINE__, 'userid=' . convertNullToZero($userid) . ', refid=' . convertNullToZero($refid) . ' - Both must be > 0');
+ } elseif ($userid == $refid) {
+ // Skip identical ids
+ return 0;
+ } // END - if
- // Free result
- SQL_FREERESULT($result);
+ // Is it cached?
+ if (!isset($GLOBALS['refback_percents'][$userid][$refid])) {
+ // Default is zero
+ $GLOBALS['refback_percents'][$userid][$refid] = '0';
+
+ // Get percents from database
+ $result = SQL_QUERY_ESC("SELECT `refback_percents` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `refid`=%s LIMIT 1",
+ array($userid, $refid), __FUNCTION__, __LINE__);
+
+ // Entry found? (Should be!)
+ if (SQL_NUMROWS($result) == 1) {
+ // Fetch percents
+ list($GLOBALS['refback_percents'][$userid][$refid]) = SQL_FETCHROW($result);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . $refid . ',percents=' . $GLOBALS['refback_percents'][$userid][$refid]);
+ } else {
+ // Please report all findings
+ reportBug(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . $refid . ' - No entry found. :-(');
+ }
+
+ // Free result
+ SQL_FREERESULT($result);
+ } // END - if
// Return percents
- //* DEBUG: */ print "
----------------------- ".__FUNCTION__." - EXIT ------------------------
\n";
- return $percents;
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . $refid . ',refback_percents=' . $GLOBALS['refback_percents'][$userid][$refid] . ' - EXIT!');
+ return $GLOBALS['refback_percents'][$userid][$refid];
}
// "Getter" for userid array which will return only one entry
-function GET_REFBACK_USERID_ARRAY ($rid, $level) {
- //* DEBUG: */ print "----------------------- ".__FUNCTION__." - ENTRY ------------------------- \n";
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):rid={$rid},level={$level}
\n";
+function getArrayFromRefbackLevel ($refid, $level) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . convertNullToZero($refid) . ',level=' . $level . ' - ENTERED!');
// Init userids
$userIds = array();
// Look for all
- $result = SQL_QUERY_ESC("SELECT userid
-FROM `{!_MYSQL_PREFIX!}_user_refs`
-WHERE refid=%s AND level=%s
-ORDER BY userid ASC",
- array($rid,$level), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT
+ `userid`
+FROM
+ `{?_MYSQL_PREFIX?}_user_refs`
+WHERE
+ `refid`=%s AND
+ `level`=%s
+ORDER BY
+ `userid` ASC",
+ array($refid, $level), __FUNCTION__, __LINE__);
// Entries found?
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):numRows=".SQL_NUMROWS($result)."
\n";
- if (SQL_NUMROWS($result) > 0) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'numRows=' . SQL_NUMROWS($result));
+ if (!SQL_HASZERONUMS($result)) {
// Add all
while ($content = SQL_FETCHARRAY($result)) {
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):rid={$rid},level={$level},userid={$content['userid']}
\n";
- $userIds[] = $content['userid'];
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . convertNullToZero($refid) . ',level=' . $level . ',userid=' . $content['userid']);
+ array_push($userIds, $content['userid']);
} // END - while
} // END - if
@@ -167,130 +204,53 @@ ORDER BY userid ASC",
SQL_FREERESULT($result);
// Return array
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):rid={$rid},count()=".count($userIds)."
\n";
- //* DEBUG: */ print "
----------------------- ".__FUNCTION__." - EXIT ------------------------
\n";
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . convertNullToZero($refid) . ',userIds()=' . count($userIds) . ' - EXIT!');
return $userIds;
}
-// Update "refback table"
-function UPDATE_REFBACK_TABLE ($uid) {
- //* DEBUG: */ print "----------------------- ".__FUNCTION__." - ENTRY ------------------------- \n";
- // Make it sure referal level zero (member him-/herself) is at least selected
- if (empty($GLOBALS['cache_array']['back_level'])) $GLOBALS['cache_array']['back_level'] = 1;
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},level={$GLOBALS['cache_array']['back_level']}
\n";
-
- // Init refid
- $GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_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($uid)), __FUNCTION__, __LINE__);
-
- // When no entry was updated then we have to create it here
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):found=".SQL_NUMROWS($result_refid)."
\n";
- if (SQL_NUMROWS($result_refid) > 0) {
- // Load all refids
- while (list($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']]) = SQL_FETCHROW($result_refid)) {
- // Remmber userid
- $GLOBALS['cache_array']['up_userid'][$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']]] = $uid;
-
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},ref={$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']]}
\n";
- // Refid set?
- if (($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']] > 0) && ($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']] != $uid) && (isset($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']]))) {
- // New userid?
- if ((isset($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']-1])) && (isset($GLOBALS['cache_array']['up_userid'][$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']-1]]))) {
- // New userid!
- $old = $uid;
- $uid = $GLOBALS['cache_array']['up_userid'][$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']-1]];
- $minus = 1;
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},old={$old},level={$GLOBALS['cache_array']['back_level']},ref={$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']]} - NEW UID!
\n";
- } // END - if
-
- // Check existence
- $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_refs` WHERE userid=%s AND level='%s' AND refid=%s LIMIT 1",
- array(bigintval($uid), $GLOBALS['cache_array']['back_level'], bigintval($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']])), __FUNCTION__, __LINE__);
-
- // Do we have no entry?
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},level={$GLOBALS['cache_array']['back_level']},ref={$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']]},minus={$minus},numRows=".SQL_NUMROWS($result)." - FOUND!
\n";
- if (SQL_NUMROWS($result) == 0) {
- // Insert this level
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},level={$GLOBALS['cache_array']['back_level']},ref={$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']]} - ADD!
\n";
- SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_refs` (userid,level,refid) VALUES (%s,%s,%s)",
- array(bigintval($uid), $GLOBALS['cache_array']['back_level'], bigintval($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']])), __FUNCTION__, __LINE__);
-
- // Move to next referal level and count his counter one up!
- $GLOBALS['cache_array']['back_level']++; UPDATE_REFBACK_TABLE($GLOBALS['cache_array']['up_refid'][($GLOBALS['cache_array']['back_level'] - 1)]);
- } // END - if
-
- // Do we have another level here?
- if ((($GLOBALS['cache_array']['back_level']-$minus) > 0) && ($old > 0)) {
- // Restore old one
- $uid = $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($uid), ($GLOBALS['cache_array']['back_level']-$minus), bigintval($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']])), __FUNCTION__, __LINE__);
-
- // Do we have no entry?
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},level=".($GLOBALS['cache_array']['back_level']-$minus).",ref={$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']]},numRows=".SQL_NUMROWS($result)." - BACK!
\n";
- 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($uid), ($GLOBALS['cache_array']['back_level']-$minus), bigintval($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']])), __FUNCTION__, __LINE__);
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},level=".($GLOBALS['cache_array']['back_level']-$minus).",ref={$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']]} - RETURNED!
\n";
- } // END - if
- } // END - if
- } // END - if
- } // END - while
-
- // Free memory
- SQL_FREERESULT($result_refid);
- } // END - if
-
- // When he has a referal...
- if ((($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']] == $uid) || ($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']] == 0)) && (GET_EXT_VERSION("cache") >= "0.1.2") && (!isset($GLOBALS['cache_array']['back_cached']))) {
- // Remove cache here
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},ref={$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']]} - CACHE!
\n";
- if ($GLOBALS['cache_instance']->loadCacheFile("refback")) $GLOBALS['cache_instance']->destroyCacheFile();
- $GLOBALS['cache_array']['back_cached'] = 1;
- } // END - if
-
- // "Walk" back here
- $GLOBALS['cache_array']['back_level']--;
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},level={$GLOBALS['cache_array']['back_level']} - LEVEL!
\n";
-
- // Fix empty refid
- if (!isset($GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']-1])) $GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']-1] = 0;
- //* DEBUG: */ print __FUNCTION__."(".__LINE__."):uid={$uid},level={$GLOBALS['cache_array']['back_level']},ref={$GLOBALS['cache_array']['up_refid'][$GLOBALS['cache_array']['back_level']-1]} - BACK!
\n";
- //* DEBUG: */ print "
----------------------- ".__FUNCTION__." - EXIT ------------------------
\n";
-}
-
// "Getter" for array for user refs in given level
-function GET_USER_REFS ($uid, $level) {
- //* DEBUG: */ print "----------------------- ".__FUNCTION__." - ENTRY ------------------------- \n";
+function getArrayFromRefbackUserRefs ($userid, $level) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ' - ENTERED!');
// Default is no refs and no nickname
- $ADD = "";
$refs = array();
- // Do we have nickname extension installed?
- if (EXT_IS_ACTIVE("nickname")) {
- $ADD = ", d.nickname";
- } // END - if
-
// Get refs from database
- $result = SQL_QUERY_ESC("SELECT r.id, r.refid, r.refback, r.points, d.status".$ADD."
-FROM `{!_MYSQL_PREFIX!}_user_refs` AS r
-LEFT JOIN `{!_MYSQL_PREFIX!}_user_data` AS d
-ON r.refid=d.userid
-WHERE r.userid=%s AND r.level=%s
-ORDER BY r.refid ASC",
- array(bigintval($uid), bigintval($level)), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT
+ r.`id`,
+ r.`refid`,
+ r.`refback_percents`,
+ r.`refback_points`,
+ d.`status`,
+ d.`joined`,
+ d.`mails_confirmed`,
+ d.`emails_received`,
+ d.`refid` AS `level_refid`
+FROM
+ `{?_MYSQL_PREFIX?}_user_refs` AS r
+LEFT JOIN
+ `{?_MYSQL_PREFIX?}_user_data` AS d
+ON
+ r.`refid`=d.`userid`
+WHERE
+ r.`userid`=%s AND
+ r.`level`=%s
+ORDER BY
+ r.`refid` ASC",
+ array(bigintval($userid), bigintval($level)), __FUNCTION__, __LINE__);
// Are there some entries?
- if (SQL_NUMROWS($result) > 0) {
+ 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
@@ -300,13 +260,13 @@ ORDER BY r.refid ASC",
SQL_FREERESULT($result);
// Return result
- //* DEBUG: */ print "
----------------------- ".__FUNCTION__." - EXIT ------------------------
\n";
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refs()=' . count($refs) . ' - EXIT!');
return $refs;
}
// "Getter" for refback entry
-function GET_USER_REF_ENTRY ($id) {
- //* DEBUG: */ print "----------------------- ".__FUNCTION__." - ENTRY ------------------------- \n";
+function getArrayFromUserRefbackData ($id) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ' - ENTERED!');
// Default data is nothing
$data = array();
@@ -314,8 +274,8 @@ function GET_USER_REF_ENTRY ($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",
- array($id, getUserId()), __FUNCTION__, __LINE__);
+ $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?
if (SQL_NUMROWS($result) == 1) {
@@ -327,77 +287,91 @@ function GET_USER_REF_ENTRY ($id) {
SQL_FREERESULT($result);
// Return entry
- //* DEBUG: */ print "
----------------------- ".__FUNCTION__." - EXIT ------------------------
\n";
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',data()=' . count($data) . ' - EXIT!');
return $data;
}
// Update refback percents (but with some sanity-checks!
-function REFBACK_CHANGE_MEMBER_PERCENTS ($id, $percents) {
- //* DEBUG: */ print "----------------------- ".__FUNCTION__." - ENTRY ------------------------- \n";
+function updateMemberRefbackPercents ($id, $percents, $note) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',percents=' . $percents . ' - ENTERED!');
// Default status is failed
- $status['message'] = getMessage('MEMBER_REFBACK_ERROR_GENERAL');
+ $status['message'] = 'MEMBER_REFBACK_ERROR_GENERAL';
// Do some sanity-checks
- if (!IS_MEMBER()) {
+ if (!isMember()) {
// No member!
- $status['message'] = getMessage('MEMBER_REFBACK_ERROR_NO_MEMBER');
+ $status['message'] = 'MEMBER_REFBACK_ERROR_NO_MEMBER';
return $status;
- } elseif ("".$id."" != "".($id + 0)."") {
+ } elseif (''.$id.'' != ''.($id + 0).'') {
// No number!
- $status['message'] = getMessage('MEMBER_REFBACK_ERROR_INVALID_ID_NUMBER');
+ $status['message'] = 'MEMBER_REFBACK_ERROR_INVALID_ID_NUMBER';
return $status;
} elseif (($percents < 0) || ($percents > 100)) {
// Percentage is not valid!
- $status['message'] = getMessage('MEMBER_REFBACK_ERROR_INVALID_PERCENTAGE');
+ $status['message'] = 'MEMBER_REFBACK_ERROR_INVALID_PERCENTAGE';
return $status;
}
// Get ref entry
- $dummy = GET_USER_REF_ENTRY($id);
+ $content = getArrayFromUserRefbackData($id);
// Is this valid?
- if (count($dummy) == 0) {
- // ID does not belong to user!
- $status['message'] = getMessage('MEMBER_REFBACK_ERROR_ID_MISMATCH');
+ if (count($content) == 0) {
+ // id does not belong to user!
+ $status['message'] = 'MEMBER_REFBACK_ERROR_ID_MISMATCH';
return $status;
} // END - if
// Revert german commata
- $percents = REVERT_COMMA($percents);
+ $percents = convertCommaToDot($percents);
// Update entry
- SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_refs` SET refback='%s' WHERE id=%s AND userid=%s LIMIT 1",
- array($percents, $id, getUserId()), __FUNCTION__, __LINE__);
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_refs` SET `refback_percents`='%s' WHERE `id`=%s AND `userid`=%s LIMIT 1",
+ array(
+ $percents,
+ $id,
+ getMemberId()
+ ), __FUNCTION__, __LINE__);
// Entry updated?
- if (SQL_AFFECTEDROWS() < 1) {
+ if (SQL_HASZEROAFFECTED()) {
// Entry not updated!
- $status['message'] = getMessage('MEMBER_REFBACK_ERROR_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']
- );
+ $content['refback_percents'] = $percents;
+ $content['refback_notice'] = $note;
// Load member email template
- $mail = LOAD_EMAIL_TEMPLATE("member_refback", $content, getUserId());
+ $mail = loadEmailTemplate('member_refback', $content, $content['refid']);
// Send email to user
- SEND_EMAIL($dummy['refid'], getMessage('MEMBER_REFBACK_SUBJECT'), $mail);
+ sendEmail($content['refid'], '{--MEMBER_REFBACK_SUBJECT--}', $mail);
// Send admin notification
- SEND_ADMIN_NOTIFICATION(getMessage('ADMIN_REFBACK_SUBJECT'), "admin_refback", $content, getUserId());
+ sendAdminNotification('{--ADMIN_REFBACK_SUBJECT--}', 'admin_refback', $content, $content['refid']);
// All fine!
- $status['ok'] = true;
+ $status['ok'] = TRUE;
// Return status array
- //* DEBUG: */ print "
----------------------- ".__FUNCTION__." - EXIT ------------------------
\n";
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',percents=' . $percents . ' - EXIT!');
return $status;
}
-//
+
+// Checks whether refback is enabled
+function isRefbackEnabled () {
+ // Is there cache?
+ if (!isset($GLOBALS[__FUNCTION__])) {
+ // Determine it
+ $GLOBALS[__FUNCTION__] = (getConfig('refback_enabled') == 'Y');
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__];
+}
+
+// [EOF]
?>