X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Flibs%2Frefback_functions.php;h=18b9ff9490cf53a347452f73074e6e602e9ac827;hb=9b93cb80c13ee59fbd935b2988127cf4a1135000;hp=5dc539c2e7ad52e091f99f3de2770139ce2b1386;hpb=8f14df8c3232a31917df0ac57363dbd6e975c147;p=mailer.git
diff --git a/inc/libs/refback_functions.php b/inc/libs/refback_functions.php
index 5dc539c2e7..18b9ff9490 100644
--- a/inc/libs/refback_functions.php
+++ b/inc/libs/refback_functions.php
@@ -14,11 +14,9 @@
* $Date:: $ *
* $Tag:: 0.2.1-FINAL $ *
* $Author:: $ *
- * Needs to be in all Files and every File needs "svn propset *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
* -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
- * Copyright (c) 2009, 2010 by Mailer Developer Team *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team *
* For more information visit: http://www.mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -52,7 +50,7 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) {
$return = $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
@@ -114,36 +112,39 @@ function getRefbackPercents ($userid, $ref) {
// Skip identical ids
if ($userid == $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, $userid), __FUNCTION__, __LINE__);
-
- // Entry found? (Should be!)
- if (SQL_NUMROWS($result) == 1) {
- // Fetch percents
- list($percents) = SQL_FETCHROW($result);
- //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):percents={$percents}
");
- } else {
- // Debug log
- //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."): NO ENTRY FOUND! :-(
");
- logDebugMessage(__FUNCTION__, __LINE__, "userid={$userid},ref={$ref} - No entry found! :-(");
- }
-
- // Free result
- SQL_FREERESULT($result);
+ // Is it cached?
+ if (!isset($GLOBALS['refback_percents'][$userid][$ref])) {
+ // Default is zero
+ $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",
+ array($ref, $userid), __FUNCTION__, __LINE__);
+
+ // Entry found? (Should be!)
+ if (SQL_NUMROWS($result) == 1) {
+ // Fetch percents
+ list($GLOBALS['refback_percents'][$userid][$ref]) = SQL_FETCHROW($result);
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):percents=".$GLOBALS['refback_percents'][$userid][$ref]."
");
+ } else {
+ // Debug log
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."): NO ENTRY FOUND! :-(
");
+ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . $ref . ' - No entry found. :-(');
+ }
+
+ // Free result
+ SQL_FREERESULT($result);
+ } // END - if
// Return percents
//* DEBUG: */ print("----------------------- ".__FUNCTION__." - EXIT ------------------------
");
- return $percents;
+ return $GLOBALS['refback_percents'][$userid][$ref];
}
// "Getter" for userid array which will return only one entry
-function getArrayFromRefbackLevel ($rid, $level) {
+function getArrayFromRefbackLevel ($refid, $level) {
//* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ------------------------
- \n");
- //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):rid={$rid},level={$level}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):refid={$refid},level={$level}
");
// Init userids
$userIds = array();
@@ -156,14 +157,14 @@ WHERE
`refid`=%s AND `level`=%s
ORDER BY
`userid` ASC",
- array($rid, $level), __FUNCTION__, __LINE__);
+ array($refid, $level), __FUNCTION__, __LINE__);
// Entries found?
//* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):numRows=".SQL_NUMROWS($result)."
");
- if (SQL_NUMROWS($result) > 0) {
+ if (!SQL_HASZERONUMS($result)) {
// Add all
while ($content = SQL_FETCHARRAY($result)) {
- //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):rid={$rid},level={$level},userid={$content['userid']}
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):refid={$refid},level={$level},userid={$content['userid']}
");
$userIds[] = $content['userid'];
} // END - while
} // END - if
@@ -172,7 +173,7 @@ ORDER BY
SQL_FREERESULT($result);
// Return array
- //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):rid={$rid},count()=".count($userIds)."
");
+ //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):refid={$refid},count()=".count($userIds)."
");
//* DEBUG: */ print("
----------------------- ".__FUNCTION__." - EXIT ------------------------
");
return $userIds;
}
@@ -194,7 +195,7 @@ function updateRefbackTable ($userid) {
// When no entry was updated then we have to create it here
//* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):found=".SQL_NUMROWS($result_refid)."
");
- if (SQL_NUMROWS($result_refid) > 0) {
+ if (!SQL_HASZERONUMS($result_refid)) {
// Load all refids
while (list($GLOBALS['refback_refid'][$GLOBALS['refback_level']]) = SQL_FETCHROW($result_refid)) {
// Remmber userid
@@ -213,8 +214,12 @@ function updateRefbackTable ($userid) {
} // 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($userid), $GLOBALS['refback_level'], bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])), __FUNCTION__, __LINE__);
+ $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: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},level={$GLOBALS['refback_level']},ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]},minus={$minus},numRows=".SQL_NUMROWS($result)." - FOUND!
");
@@ -225,7 +230,8 @@ function updateRefbackTable ($userid) {
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)]);
+ $GLOBALS['refback_level']++;
+ updateRefbackTable($GLOBALS['refback_refid'][($GLOBALS['refback_level'] - 1)]);
} // END - if
// Do we have another level here?
@@ -234,8 +240,12 @@ function updateRefbackTable ($userid) {
$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), ($GLOBALS['refback_level']-$minus), bigintval($GLOBALS['refback_refid'][$GLOBALS['refback_level']])), __FUNCTION__, __LINE__);
+ $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: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},level=".($GLOBALS['refback_level']-$minus).",ref={$GLOBALS['refback_refid'][$GLOBALS['refback_level']]},numRows=".SQL_NUMROWS($result)." - BACK!
");
@@ -275,37 +285,32 @@ function updateRefbackTable ($userid) {
function getArrayFromRefbackUserRefs ($userid, $level) {
//* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ------------------------- \n");
// Default is no refs and no nickname
- $add = '';
$refs = array();
- // Do we have nickname extension installed?
- if (isExtensionActive('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.",
- d.joined,
- d.refid AS level_refid
+ r.`id`,
+ r.`refid`,
+ r.`refback`,
+ r.`points`,
+ d.`status`
+ d.`joined`,
+ 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
+ r.`refid`=d.`userid`
WHERE
- r.userid=%s AND r.level=%s
+ r.`userid`=%s AND
+ r.`level`=%s
ORDER BY
- r.refid ASC",
+ 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)) {
// Add row
@@ -352,20 +357,20 @@ function getArrayFromUserRefbackData ($id) {
function updateMemberRefbackPercents ($id, $percents) {
//* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ------------------------
- \n");
// Default status is failed
- $status['message'] = getMessage('MEMBER_REFBACK_ERROR_GENERAL');
+ $status['message'] = '{--MEMBER_REFBACK_ERROR_GENERAL--}';
// Do some sanity-checks
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).'') {
// 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;
}
@@ -375,7 +380,7 @@ function updateMemberRefbackPercents ($id, $percents) {
// Is this valid?
if (count($dummy) == 0) {
// id does not belong to user!
- $status['message'] = getMessage('MEMBER_REFBACK_ERROR_ID_MISMATCH');
+ $status['message'] = '{--MEMBER_REFBACK_ERROR_ID_MISMATCH--}';
return $status;
} // END - if
@@ -387,9 +392,9 @@ function updateMemberRefbackPercents ($id, $percents) {
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
@@ -400,10 +405,10 @@ function updateMemberRefbackPercents ($id, $percents) {
$mail = loadEmailTemplate('member_refback', $dummy, $dummy['refid']);
// Send email to user
- sendEmail($dummy['refid'], getMessage('MEMBER_REFBACK_SUBJECT'), $mail);
+ sendEmail($dummy['refid'], '{--MEMBER_REFBACK_SUBJECT--}', $mail);
// Send admin notification
- sendAdminNotification(getMessage('ADMIN_REFBACK_SUBJECT'), 'admin_refback', $dummy, getMemberId());
+ sendAdminNotification('{--ADMIN_REFBACK_SUBJECT--}', 'admin_refback', $dummy, getMemberId());
// All fine!
$status['ok'] = true;
@@ -413,5 +418,17 @@ function updateMemberRefbackPercents ($id, $percents) {
return $status;
}
+// Checks wether refback is enabled
+function isRefbackEnabled () {
+ // Do we have cache?
+ if (!isset($GLOBALS[__FUNCTION__])) {
+ // Determine it
+ $GLOBALS[__FUNCTION__] = (getConfig('refback_enabled') == 'Y');
+ } // END - if
+
+ // Return cache
+ return $GLOBALS[__FUNCTION__];
+}
+
// [EOF]
?>