$sendNotify = isPaymentRecipientNotificationEnabled($subject);
// When $userid is NULL add points to jackpot
- if ((!isValidUserId($userid)) && ($paymentMethod == 'DIRECT') && (isExtensionActive('jackpot'))) {
+ if ((!isValidId($userid)) && ($paymentMethod == 'DIRECT') && (isExtensionActive('jackpot'))) {
// Add points to jackpot only in DIRECT mode
return addPointsToJackpot($points);
} // END - if
// Pay refback here if level > 0 and in ref-mode
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',refid=' . convertNullToZero(getUserData('refid')) . ',points=' . $points . ',paymentMethod=' . $paymentMethod);
- if (($userid != $refid) && (substr($subject, 0, 8) != 'refback:') &&($paymentMethod == 'REFERRAL') && (isValidUserId(getUserData('refid'))) && (isExtensionActive('refback'))) {
+ if (($userid != $refid) && (substr($subject, 0, 8) != 'refback:') &&($paymentMethod == 'REFERRAL') && (isValidId(getUserData('refid'))) && (isExtensionActive('refback'))) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',refid=' . convertNullToZero(getUserData('refid')) . ',ref_points=' . $ref_points . ',depth=' . convertNullToZero($GLOBALS['ref_level']) . ' - BEFORE!');
$ref_points = addRefbackPoints($userid, getUserData('refid'), $points, $ref_points);
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',refid=' . convertNullToZero(getUserData('refid')) . ',ref_points=' . $ref_points . ',depth=' . convertNullToZero($GLOBALS['ref_level']) . ' - AFTER!');
// Maybe there's another ref?
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'points=' . $points . ',refid(var|data)=' . convertNullToZero($refid) . '|' . convertNullToZero(getUserData('refid')) . ',userid=' . $userid . ',paymentMethod=' . $paymentMethod . ',subject=' . $subject . ',ref_level=' . $GLOBALS['ref_level']);
- if ((isValidUserId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($paymentMethod == 'REFERRAL')) {
+ if ((isValidId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($paymentMethod == 'REFERRAL')) {
// Is _ref there?
if (substr($subject, -4, 4) == '_ref') {
// Then remove it, no double _ref suffix!
function updateReferralCounter ($userid) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
// Init referral id
- $ref = NULL;
+ $refid = NULL;
// Check for his referral
if (fetchUserData($userid)) {
// Get it
- $ref = getUserData('refid');
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . convertZeroToNull($ref) . ' - FETCHED!');
+ $refid = getUserData('refid');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . convertZeroToNull($refid) . ' - FETCHED!');
} // END - if
// Init entries
if (empty($GLOBALS['cache_array']['ref_level'][$userid])) {
$GLOBALS['cache_array']['ref_level'][$userid] = NULL;
} // END - if
- if (empty($GLOBALS['cache_array']['ref_level'][$ref])) {
- $GLOBALS['cache_array']['ref_level'][$ref] = NULL;
+ if (empty($GLOBALS['cache_array']['ref_level'][$refid])) {
+ $GLOBALS['cache_array']['ref_level'][$refid] = NULL;
} // END - if
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . convertZeroToNull($ref));
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . convertZeroToNull($refid));
// When he has a referral...
- if (($ref > 0) && ($ref != $userid)) {
+ if ((isValidId($refid)) && ($refid != $userid)) {
// Move to next referral level and count his counter one up
- $GLOBALS['cache_array']['ref_level'][$ref] = $GLOBALS['cache_array']['ref_level'][$userid] + 1;
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref(' . $ref . ')=' . $GLOBALS['cache_array']['ref_level'][$ref] . ' - ADVANCED!');
+ $GLOBALS['cache_array']['ref_level'][$refid] = $GLOBALS['cache_array']['ref_level'][$userid] + 1;
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid(' . $refid . ')=' . $GLOBALS['cache_array']['ref_level'][$refid] . ' - ADVANCED!');
// Update counter
SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refsystem` SET `counter`=`counter`+1 WHERE `userid`=%s AND `level`=%s LIMIT 1",
array(
- bigintval($ref),
- bigintval($GLOBALS['cache_array']['ref_level'][$ref])
+ bigintval($refid),
+ bigintval($GLOBALS['cache_array']['ref_level'][$refid])
), __FUNCTION__, __LINE__);
// When no entry was updated then we have to create it here
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ref=' . $ref . ',level=' . $GLOBALS['cache_array']['ref_level'][$ref] . ',updated=' . SQL_AFFECTEDROWS());
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',level=' . $GLOBALS['cache_array']['ref_level'][$refid] . ',updated=' . SQL_AFFECTEDROWS());
if (SQL_HASZEROAFFECTED()) {
// First count!
SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refsystem` (`userid`, `level`, `counter`) VALUES (%s,%s,1)",
array(
- bigintval($ref),
- convertZeroToNull($GLOBALS['cache_array']['ref_level'][$ref])
+ bigintval($refid),
+ convertZeroToNull($GLOBALS['cache_array']['ref_level'][$refid])
), __FUNCTION__, __LINE__);
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ref=' . $ref . ',level=' . $GLOBALS['cache_array']['ref_level'][$ref] . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS());
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ',level=' . $GLOBALS['cache_array']['ref_level'][$refid] . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS());
} // END - if
// Advance to next level
- updateReferralCounter($ref);
- } elseif ((($ref == $userid) || ($ref == '0')) && (isExtensionInstalledAndNewer('cache', '0.1.2'))) {
+ updateReferralCounter($refid);
+ } elseif ((($refid == $userid) || (!isValidId($refid))) && (isExtensionInstalledAndNewer('cache', '0.1.2'))) {
// Remove cache here
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ref=' . convertZeroToNull($ref) . ' - CACHE!');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . convertZeroToNull($refid) . ' - CACHE!');
rebuildCache('refsystem', 'refsystem');
}
// Update the referral table
updateReferralTable($userid);
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',ref=' . convertZeroToNull($ref) . ',level=' . convertZeroToNull($GLOBALS['cache_array']['ref_level'][$ref]) . ' - EXIT!');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . convertZeroToNull($refid) . ',level=' . convertZeroToNull($GLOBALS['cache_array']['ref_level'][$refid]) . ' - EXIT!');
}
// Subtract points from database and mediadata cache
// Also walk through this one
foreach ($refArray as $refRefid) {
// Calculate new level
- $newLevel = $level + $refLevel;
+ $newLevel = $level + $refLevel;
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . convertNullToZero($refid) . ',refLevel=' . $refLevel . ',refRefid=' . $refRefid . ',newLevel=' . $newLevel);
// Is the refRefid not in?
if ((!isset($GLOBALS['referral_refid'][$userid][$newLevel])) || (!in_array($refRefid, $GLOBALS['referral_refid'][$userid][$newLevel]))) {
}
// Generator (somewhat getter) for points_data, locked_mode
-function generatePointsLockedModeOptions ($lockedMode = NULL) {
+function generatePointsLockedModeOptions ($lockedMode = NULL) {
// Is this cached?
if (!isset($GLOBALS[__FUNCTION__][$lockedMode])) {
// Generate output and cache it
}
// Generator (somewhat getter) for points_data, payment_method
-function generatePointsPaymentMethodOptions ($paymentMethod = NULL) {
+function generatePointsPaymentMethodOptions ($paymentMethod = NULL) {
// Is this cached?
if (!isset($GLOBALS[__FUNCTION__][$paymentMethod])) {
// Generate output and cache it
}
// Generator (somewhat getter) for points_data, notify_recipient
-function generatePointsNotifyRecipientOptions ($notifyRecipient = NULL) {
+function generatePointsNotifyRecipientOptions ($notifyRecipient = NULL) {
// Is this cached?
if (!isset($GLOBALS[__FUNCTION__][$notifyRecipient])) {
// Generate output and cache it
// The variable user comes from click.php
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using user from GET data (' . getRequestElement('user') . ')');
setReferralId(bigintval(getRequestElement('user')));
- } elseif ((isSessionVariableSet('refid')) && (isValidUserId(getSession('refid')))) {
+ } elseif ((isSessionVariableSet('refid')) && (isValidId(getSession('refid')))) {
// Set session refid as global
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using refid from SESSION data (' . getSession('refid') . ')');
setReferralId(bigintval(getSession('refid')));
// Select a random user which has confirmed enougth mails
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Checking random referral id');
setReferralId(determineRandomReferralId());
- } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid()))) {
+ } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidId(getDefRefid()))) {
// Set default refid as refid in URL
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using default refid (' . getDefRefid() . ')');
setReferralId(getDefRefid());
}
// Set cookie when default refid > 0
- if ((!isSessionVariableSet('refid')) || (!isValidUserId(getReferralId())) || ((!isValidUserId(getSession('refid'))) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid())))) {
+ if ((!isSessionVariableSet('refid')) || (!isValidId(getReferralId())) || ((!isValidId(getSession('refid'))) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidId(getDefRefid())))) {
// Default is not found
$found = FALSE;
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using refid from user account by nickname (' . getUserData('userid') . ')');
setReferralId(getUserData('userid'));
} // END - if
- } elseif (isValidUserId(getReferralId())) {
+ } elseif (isValidId(getReferralId())) {
// Direct userid entered
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using direct userid (' . getReferralId() . ')');
$found = fetchUserData(getReferralId());