/**
*
- * Dynamic referal system, can also send mails!
+ * 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...
* add_mode = Add points only to $userid or also refs? (WARNING! Changing 'ref' to 'direct'
* for default value will cause no referal will get points ever!!!)
*/
-function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $refid = '0', $add_mode = 'ref') {
+function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $refid = '0', $addMode = 'ref') {
// By default nothing has been added
$added = false;
//* DEBUG: */ debugOutput('----------------------- <font color="#00aa00">' . __FUNCTION__ . ' - ENTRY</font> ------------------------<ul><li>');
// Convert mode to lower-case
- $add_mode = strtolower($add_mode);
+ $addMode = strtolower($addMode);
// When $userid = '0' add points to jackpot
if (($userid == '0') && (isExtensionActive('jackpot'))) {
// Add points to jackpot
- addPointsToJackpot($points);
- return;
+ return addPointsToJackpot($points);
} // END - if
// Count up referal depth
// Determine wether the user has some mails to click before he/she gets the points
$locked = ifUserPointsLocked($userid);
- // Default is 'normal' points
- $data = 'points';
-
- // Which points, locked or normal?
- if ($locked === true) {
- $data = 'locked_points';
- } // END - if
+ // 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: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):userid='.$userid.',points='.$points.',depth='.$GLOBALS['ref_level'].',per='.$per.',mode='.$add_mode);
+ //* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):userid='.$userid.',points='.$points.',depth='.$GLOBALS['ref_level'].',per='.$per.',mode='.$addMode);
// Some percents found?
if ($per > 0) {
$ref_points = $points * $per / 100;
// Pay refback here if level > 0 and in ref-mode
- if ((isExtensionActive('refback')) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($add_mode == 'ref') && (isset($GLOBALS['cache_array']['add_userid'][$userid]))) {
+ if ((isExtensionActive('refback')) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($addMode == 'ref') && (isset($GLOBALS['cache_array']['add_userid'][$userid]))) {
//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):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: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - AFTER!');
// Update points...
SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `%s`=`%s`+%s WHERE `userid`=%s AND `ref_depth`=%s LIMIT 1",
- array($data, $data, $ref_points, bigintval($userid), bigintval($GLOBALS['ref_level'])), __FUNCTION__, __LINE__);
- //* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):data='.$data.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$add_mode.' - UPDATE! ('.SQL_AFFECTEDROWS().')');
+ array(
+ $pointsColumn,
+ $pointsColumn,
+ $ref_points,
+ bigintval($userid),
+ bigintval($GLOBALS['ref_level'])
+ ), __FUNCTION__, __LINE__);
+ //* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):pointsColumn='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$addMode.' - UPDATE! ('.SQL_AFFECTEDROWS().')');
// No entry updated?
if (SQL_HASZEROAFFECTED()) {
// First ref in this level! :-)
- SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`,`ref_depth`,`%s`) VALUES (%s,%s,%s)",
- array($data, bigintval($userid), bigintval($GLOBALS['ref_level']), $ref_points), __FUNCTION__, __LINE__);
- //* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):data='.$data.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$add_mode.' - INSERTED! ('.SQL_AFFECTEDROWS().')');
+ SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`, `ref_depth`, `%s`) VALUES (%s, %s, %s)",
+ array(
+ $pointsColumn,
+ bigintval($userid),
+ bigintval($GLOBALS['ref_level']),
+ $ref_points
+ ), __FUNCTION__, __LINE__);
+ //* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):data='.$pointsColumn.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$addMode.' - INSERTED! ('.SQL_AFFECTEDROWS().')');
} // END - if
// Check affected rows
// Prepare data for the filter
$filterData = array(
- 'subject' => $subject,
- 'userid' => $userid,
- 'points' => $points,
- 'notify' => $sendNotify,
- 'refid' => $refid,
- 'locked' => $locked,
- 'mode' => 'add',
- 'sub_mode' => $add_mode,
- 'added' => $added
+ 'subject' => $subject,
+ 'userid' => $userid,
+ 'points' => $points,
+ 'ref_points' => $ref_points,
+ 'column' => $pointsColumn,
+ 'notify' => $sendNotify,
+ 'refid' => $refid,
+ 'locked' => $locked,
+ 'mode' => 'add',
+ 'add_mode' => $addMode,
+ 'added' => $added
);
// Filter it now
- $filterData = runFilterChain('add_points', $filterData);
+ $filterData = runFilterChain('post_add_points', $filterData);
// Extract $added
$added = $filterData['added'];
// Send email
sendEmail($userid, '{--THANX_REFERAL_ONE_SUBJECT--}', $message);
- } elseif (($sendNotify === true) && (!isValidUserId(getUserData('refid'))) && ($locked === false) && ($add_mode == 'direct')) {
+ } elseif (($sendNotify === true) && (!isValidUserId(getUserData('refid'))) && ($locked === false) && ($addMode == 'direct')) {
// Prepare content
$content = array(
'reason' => '{--REASON_DIRECT_PAYMENT--}',
}
// Maybe there's another ref?
- if ((isValidUserId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($add_mode == 'ref')) {
+ if ((isValidUserId(getUserData('refid'))) && ($points > 0) && (getUserData('refid') != $userid) && ($addMode == 'ref')) {
// Then let's credit him here...
//* DEBUG: */ debugOutput(__FUNCTION__ . '(<font color="#0000aa">' . __LINE__ . '</font>):userid='.$userid.',ref='.getUserData('refid').',points='.$points.' - ADVANCE!');
$added = ($added && addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, $sendNotify, getUserData('refid')));
), __FUNCTION__, __LINE__);
}
+// Determines database column name from given subject and locked
+function determinePointsColumnFromSubjectLocked ($subject, $locked) {
+ // Default is 'normal' points
+ $pointsColumn = 'points';
+
+ // Which points, locked or normal?
+ if ($locked === true) {
+ $pointsColumn = 'locked_points';
+ } // END - if
+
+ // Prepare array for filter
+ $filterData = array(
+ 'subject' => $subject,
+ 'locked' => $locked,
+ 'column' => $pointsColumn
+ );
+
+ // Run the filter
+ $filterData = runFilterChain('determine_points_column_name', $filterData);
+
+ // Extract column name from array
+ $pointsColumn = $filterData['column'];
+
+ // Return it
+ return $pointsColumn;
+}
+
// [EOF]
?>