X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Freferal-functions.php;h=384f1a8a88d2a4191932da6b01b9bb18f5d48de5;hb=ed3a88c0334600c7d7246480008c79716aa3f80b;hp=ac0299e6d950c45c8b3b342ef50a8b921f742b8b;hpb=3cf256f9324419b7ae71b035993c2aba36b05d0c;p=mailer.git diff --git a/inc/referal-functions.php b/inc/referal-functions.php index ac0299e6d9..384f1a8a88 100644 --- a/inc/referal-functions.php +++ b/inc/referal-functions.php @@ -83,17 +83,15 @@ function getReferalLevelPercents ($level) { } /** - * * Dynamic referal and points system, can also send mails! * * subject = Subject line, write in lower-case letters and underscore is allowed * userid = Referal id wich should receive... * points = ... xxx points * refid = inc/modules/guest/what-confirm.php need this - * locked = Shall I pay it to normal (false) or locked (true) points ammount? */ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = NULL) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',refid=' . $refid . ' - ENTERED!'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',refid=' . makeNullToZero($refid) . ' - ENTERED!'); // By default nothing has been added $added = false; @@ -101,14 +99,17 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = NUL $paymentMethod = strtoupper(getPaymentMethodFromSubject($subject)); $sendNotify = isPaymentRecipientNotificationEnabled($subject); - // When $userid = '0' add points to jackpot - if (($userid == '0') && ($paymentMethod == 'DIRECT') && (isExtensionActive('jackpot'))) { + // When $userid is NULL add points to jackpot + if ((!isValidUserId($userid)) && ($paymentMethod == 'DIRECT') && (isExtensionActive('jackpot'))) { // Add points to jackpot only in DIRECT mode return addPointsToJackpot($points); } // END - if + // Set userid as current + setCurrentUserId($userid); + // Check user account - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',points=' . $points); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',points=' . $points . ',paymentMethod=' . $paymentMethod . ',sendNotify=' . intval($sendNotify)); if (fetchUserData($userid)) { // Determine wether the user has some mails to click before he/she gets the points $locked = ifUserPointsLocked($userid); @@ -116,24 +117,21 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = NUL // Detect database column $pointsColumn = determinePointsColumnFromSubjectLocked($subject, $locked); - // This is the user and his ref - $GLOBALS['cache_array']['add_userid'][getUserData('refid')] = $userid; - // Get percents $per = getReferalLevelPercents($GLOBALS['ref_level']); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points.',depth='.$GLOBALS['ref_level'].',per='.$per.',mode='.$paymentMethod); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',points=' . $points . ',depth=' . makeNullToZero($GLOBALS['ref_level']) . ',per=' . $per . ',mode=' . $paymentMethod . ',pointsColumn=' . $pointsColumn . ',locked=' . intval($locked) . ',refid=' . getUserData('refid')); // Some percents found? if ($per > 0) { // Calculate new points $ref_points = $points * $per / 100; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',points='.$points.',per='.$per.',depth='.$GLOBALS['ref_level'].',ref_points='.$ref_points); // Pay refback here if level > 0 and in ref-mode - if ((isExtensionActive('refback')) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($paymentMethod == 'REFERAL') && (isset($GLOBALS['cache_array']['add_userid'][$userid]))) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - BEFORE!'); - $ref_points = addRefbackPoints($GLOBALS['cache_array']['add_userid'][$userid], $userid, $points, $ref_points); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - AFTER!'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . makeNullToZero(getUserData('refid')) . ',points=' . $points . ',paymentMethod=' . $paymentMethod); + if (($userid != $refid) && ($paymentMethod == 'REFERAL') && (isValidUserId(getUserData('refid'))) && (isExtensionActive('refback'))) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . makeNullToZero(getUserData('refid')) . ',ref_points=' . $ref_points . ',depth=' . makeNullToZero($GLOBALS['ref_level']) . ' - BEFORE!'); + $ref_points = addRefbackPoints($userid, getUserData('refid'), $points, $ref_points); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . makeNullToZero(getUserData('refid')) . ',ref_points=' . $ref_points . ',depth=' . makeNullToZero($GLOBALS['ref_level']) . ' - AFTER!'); } // END - if // Update points... @@ -157,7 +155,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = NUL bigintval($GLOBALS['ref_level']) ), __FUNCTION__, __LINE__); } - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pointsColumn='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$paymentMethod.' - UPDATE! ('.SQL_AFFECTEDROWS().')'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'pointsColumn='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.makeNullToZero($GLOBALS['ref_level']).',mode='.$paymentMethod.' - UPDATE! ('.SQL_AFFECTEDROWS().')'); // No entry updated? if (SQL_HASZEROAFFECTED()) { @@ -169,12 +167,12 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = NUL makeZeroToNull($GLOBALS['ref_level']), $ref_points ), __FUNCTION__, __LINE__); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'data='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$paymentMethod.' - INSERTED! ('.SQL_AFFECTEDROWS().')'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'data='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.makeNullToZero($GLOBALS['ref_level']).',mode='.$paymentMethod.' - INSERTED! ('.SQL_AFFECTEDROWS().')'); } // END - if // Check affected rows - $added = SQL_AFFECTEDROWS(); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added='.intval($added)); + $added = (SQL_AFFECTEDROWS() == 1); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added=' . intval($added) . ' - BEFORE FILTER'); // Prepare data for the filter $filterData = array( @@ -196,7 +194,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = NUL // Extract $added $added = $filterData['added']; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added='.intval($added)); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'added=' . intval($added) . ' - AFTER FILTER'); // Points updated, maybe I shall send him an email? if (($sendNotify === true) && (isValidUserId(getUserData('refid'))) && ($locked === false)) { @@ -231,20 +229,27 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $refid = NUL } // END - if } - // Increase referal level - $GLOBALS['ref_level']++; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ' Referal level increased, ref_level=' . $GLOBALS['ref_level']); + // Increase referal level, if payment method is REFERAL + if ($paymentMethod == 'REFERAL') { + // Increase it + $GLOBALS['ref_level']++; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Referal level increased, ref_level=' . makeNullToZero($GLOBALS['ref_level']) . ',points=' . $points . ',refid=' . makeNullToZero(getUserData('refid')) . ',userid=' . $userid . ',paymentMethod=' . $paymentMethod); + } elseif (isDebugModeEnabled()) { + // Not increasing referal level, DIRECT payment method + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Referal level *NOT* increased, ref_level=' . makeNullToZero($GLOBALS['ref_level']) . ',points=' . $points . ',refid=' . makeNullToZero(getUserData('refid')) . ',userid=' . $userid . ',paymentMethod=' . $paymentMethod); + } // Maybe there's another ref? + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'points=' . $points . ',refid(var|data)=' . makeNullToZero($refid) . '|' . makeNullToZero(getUserData('refid')) . ',userid=' . $userid . ',paymentMethod=' . $paymentMethod); if ((isValidUserId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($paymentMethod == 'REFERAL')) { // Then let's credit him here... - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . getUserData('refid') . ',points=' . $points . ',ref_points=' . $ref_points . ' - ADVANCE!'); - $added = ($added && addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, getUserData('refid'))); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',refid=' . makeNullToZero(getUserData('refid')) . ',points=' . $points . ',ref_points=' . $ref_points . ',added[' . gettype($added) . ']=' . intval($added) . ' - ADVANCE!'); + $added = ($added && addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, getFetchedUserData('userid', getUserData('refid'), 'refid'))); } // END - if } // END - if } // END - if - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',sendNotify=' . intval($sendNotify) . ',refid=' . $refid . ',paymentMethod=' . $paymentMethod . ' - EXIT!'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',userid=' . $userid . ',points=' . $points . ',sendNotify=' . intval($sendNotify) . ',refid=' . makeNullToZero($refid) . ',paymentMethod=' . $paymentMethod . ' - EXIT!'); return $added; } @@ -585,15 +590,15 @@ function addMissingReferalLevels ($userid) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid); // Does the refid have an array? if (isset($GLOBALS['referal_refid'][$refid])) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid . ',count()=' . count($GLOBALS['referal_refid'][$refid])); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . makeNullToZero($refid) . ',count()=' . count($GLOBALS['referal_refid'][$refid])); // Okay, then walk through here, too foreach ($GLOBALS['referal_refid'][$refid] as $refLevel=>$refArray) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid . ',refLevel=' . $refLevel . ',count()=' . count($refArray)); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . makeNullToZero($refid) . ',refLevel=' . $refLevel . ',count()=' . count($refArray)); // Also walk through this one foreach ($refArray as $refRefid) { // Calculate new level $newLevel = $level + $refLevel; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . $refid . ',refLevel=' . $refLevel . ',refRefid=' . $refRefid . ',newLevel=' . $newLevel); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level=' . $level . ',refid=' . makeNullToZero($refid) . ',refLevel=' . $refLevel . ',refRefid=' . $refRefid . ',newLevel=' . $newLevel); // Is the refRefid not in? if ((!isset($GLOBALS['referal_refid'][$userid][$newLevel])) || (!in_array($refRefid, $GLOBALS['referal_refid'][$userid][$newLevel]))) { // Then we must add this ref's refid to the userid's next level