$month = getMonth();
$year = getYear();
-// Init variable
+// Init variables
$lastOnline = '';
+$excludeSql = '';
// Shall I include only active members?
if ((getConfig('birthday_active') == 'Y') && (isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
- $add = ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}';
+ $excludeSql = ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}';
+} // END - if
+
+// Is ext-holiday installed?
+// @TODO Rewrite these if() blocks to a filter
+if (isExtensionActive('holiday')) {
+ // Exclude those as well
+ $excludeSql .= " AND `d`.`holiday_active`='N'";
} // END - if
// Only confirmed members shall receive birthday mails...
$result_birthday = SQL_QUERY_ESC("SELECT
- `userid`,
- `email`,
- `birth_year`
+ `d`.`userid`,
+ `d`.`email`,
+ `d`.`birth_year`
FROM
- `{?_MYSQL_PREFIX?}_user_data`
+ `{?_MYSQL_PREFIX?}_user_data` AS `d`
WHERE
- `status`='CONFIRMED'
- " . runFilterChain('user_exclusion_sql', ' ') . " AND
- `birth_day`=%s AND
- `birth_month`=%s AND
- `birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364))
- ".$lastOnline."
+ `d`.`status`='CONFIRMED'
+ " . runFilterChain('user_exclusion_sql', $excludeSql) . " AND
+ `d`.`birth_day`=%s AND
+ `d`.`birth_month`=%s AND
+ `d`.`birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364))
+ " . $lastOnline . "
ORDER BY
- `userid` ASC",
+ `d`.`userid` ASC",
array($day, $month), __FILE__, __LINE__);
if (!SQL_HASZERONUMS($result_birthday)) {
}
// Purges expired fast-click bonus entries
-function purgeExpiredTurboBonus() {
+function purgeExpiredTurboBonus () {
// Remove entries
$result = SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE (UNIX_TIMESTAMP() - `timemark`) >= {?bonus_timeout?}', __FUNCTION__, __LINE__);
if ((isExtensionActive('autopurge')) && (isExtensionActive('user'))) {
// Start finding them...
$userExclusionSql = ' ';
-
- // Exclude test accounts
- $userExclusionSql = runFilterChain('user_exclusion_sql', ' ');
+ $excludedUserids = runFilterChain('config_userid_exclusion_sql', array());
+ if (count($excludedUserids) > 0) {
+ // Exclude all
+ $userExcludeSql = ' AND `d`.`userid` NOT IN (' . implode(', ', $excludedUserids) . ')';
+ } // END - if
// Check for more extensions
- // @TODO These can be rewritten to filter
- if (isValidId(getDefRefid())) $userExclusionSql .= ' AND `d`.`userid` != {?def_refid?}';
- if (isExtensionActive('beg')) $userExclusionSql .= ' AND `d`.`userid` != {?beg_userid?}';
- if (isExtensionActive('bonus')) $userExclusionSql .= ' AND `d`.`userid` != {?bonus_userid?}';
- if (isExtensionActive('doubler')) $userExclusionSql .= ' AND `d`.`userid` != {?doubler_userid?}';
+ // @TODO This can be rewritten to filter
if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
// Recent ext-holiday found
$userExclusionSql .= " AND `d`.`holiday_active`='N'";
(UNIX_TIMESTAMP() - `d`.`joined`) >= {?ap_inactive_since?} AND
(UNIX_TIMESTAMP() - `d`.`last_online`) >= {?ap_inactive_since?} AND
(UNIX_TIMESTAMP() - `d`.`ap_notified`) >= {?ap_inactive_since?}
-" . $userExclusionSql . "
+ " . runFilterChain('user_exclusion_sql', $userExcludeSql) . "
ORDER BY
`d`.`userid` ASC");
$WHATs[] = 'list_autopurge';
$sql = ''; $mode = '';
// Shall I sent activation or deactivation mail?
-$sql = "SELECT `userid`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE (`beg_rallye_enable_notify` ";
+$sql = "SELECT `d`.`userid`, `d`.`email` FROM `{?_MYSQL_PREFIX?}_user_data` AS `d` WHERE (`d`.`beg_rallye_enable_notify` ";
switch (getBegRallye()) {
case 'Y': // Begging rallye is activated
if (isBegRallyeEnableNotifyEnabled()) {
// Okay, let's check for member accounts
- $sql .= '= 0 OR (`beg_rallye_enable_notify` > 0 AND `beg_rallye_enable_notify` < `beg_rallye_disable_notify`)';
+ $sql .= '= 0 OR (`d`.`beg_rallye_enable_notify` > 0 AND `d`.`beg_rallye_enable_notify` < `d`.`beg_rallye_disable_notify`)';
$mode = 'enable';
} else {
// Do not notify!
case 'N': // Begging rallye is deactivated
if (isBegRallyeDisableNotifyEnabled()) {
// Okay, let's check for member accounts
- $sql .= ' > 0 AND `beg_rallye_disable_notify` < `beg_rallye_enable_notify`';
+ $sql .= ' > 0 AND `d`.`beg_rallye_disable_notify` < `d`.`beg_rallye_enable_notify`';
$mode = 'disable';
} else {
// Do not notify!
} // END - switch
if (!empty($sql)) {
+ // Init additional WHERE statement
+ $whereStatement = '';
+
+ // Is ext-holiday installed?
+ // @TODO Rewrite these if() blocks to a filter
+ if (isExtensionActive('holiday')) {
+ // Exclude those as well
+ $whereStatement .= " AND `d`.`holiday_active`='N'";
+ } // END - if
+
// The SQL command needs to be finisched here (only confirmed accounts!)
- $sql .= ')' . runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'") . ' ORDER BY `last_online` ASC';
+ $sql .= ')' . $whereStatement . runFilterChain('user_exclusion_sql', " AND `d`.`status`='CONFIRMED'") . ' ORDER BY `d`.`last_online` ASC';
// No IP locking setuped by default
$content['ip_locker'] = '{--BEG_NO_LIMITATION--}';
$sql = ''; $mode = '';
// Shall I sent activation or deactivation mail?
-$sql = "SELECT `userid`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE (`bonus_rallye_enable_notify` ";
+$sql = "SELECT `d`.`userid`, `d`.`email` FROM `{?_MYSQL_PREFIX?}_user_data` AS `d` WHERE (`d`.`bonus_rallye_enable_notify` ";
switch (getBonusActive()) {
case 'Y': // Active rallye is activated
if (getBonusEnableNotify() == 'Y') {
// Okay, let's check for member accounts
- $sql .= '= 0 OR (`bonus_rallye_enable_notify` > 0 AND `bonus_rallye_enable_notify` < `bonus_rallye_disable_notify`)';
+ $sql .= '= 0 OR (`d`.`bonus_rallye_enable_notify` > 0 AND `d`.`bonus_rallye_enable_notify` < `d`.`bonus_rallye_disable_notify`)';
$mode = 'enable';
} else {
// Do not notify!
case 'N': // Active rallye is deactivated
if (getBonusDisableNotify() == 'Y') {
// Okay, let's check for member accounts
- $sql .= ' > 0 AND `bonus_rallye_disable_notify` < `bonus_rallye_enable_notify`';
+ $sql .= ' > 0 AND `d`.`bonus_rallye_disable_notify` < `d`.`bonus_rallye_enable_notify`';
$mode = 'disable';
} else {
// Do not notify!
} // END - switch
if (!empty($sql)) {
+ // Init additional WHERE statement
+ $whereStatement = '';
+
+ // Is ext-holiday installed?
+ // @TODO Rewrite these if() blocks to a filter
+ if (isExtensionActive('holiday')) {
+ // Exclude those as well
+ $whereStatement .= " AND `d`.`holiday_active`='N'";
+ } // END - if
+
// The SQL command needs to be finisched here (only confirmed accounts!)
- $sql .= ')' . runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'") . ' ORDER BY `last_online` ASC';
+ $sql .= ')' . $whereStatement . runFilterChain('user_exclusion_sql', " AND `d`.`status`='CONFIRMED'") . ' ORDER BY `d`.`last_online` ASC';
// Normal notification mails or bonus mails?
$sentBonusMails = ((getBonusNotifyPoints() > 0) && ($mode == 'enable') && (isExtensionActive('bonus')));
} // END - if
// Get total points of the doubler itself
-$DOUBLER_POINTS = getDoublerTotalPointsLeft();
-if ($DOUBLER_POINTS == '0') {
+$totalPoints = getDoublerTotalPointsLeft();
+if ($totalPoints == '0') {
// Exit here to prevent some SQL errors (SQL_QUERY_ESC doen't insert zeros! We need to fix this...)
return;
} // END - if
setSession('DOUBLER_USERID', '');
if (empty($GLOBALS['local_doubler_userid'])) $GLOBALS['local_doubler_userid'] = '0';
+// Init additional WHERE statement
+$whereStatement = ' ';
+
+// Is ext-holiday installed?
+// @TODO Rewrite these if() blocks to a filter
+if (isExtensionActive('holiday')) {
+ // Exclude those as well
+ $whereStatement .= " AND `d`.`holiday_active`='N'";
+} // END - if
+
// Check for doubles which we can pay out
$result_total = SQL_QUERY_ESC("SELECT
- d.id, d.userid, d.points, d.remote_ip, d.timemark
+ COUNT(`do`.`id`) AS `cnt`,
FROM
- `{?_MYSQL_PREFIX?}_doubler` AS `d`
-LEFT JOIN
- `{?_MYSQL_PREFIX?}_user_data` AS `u`
+ `{?_MYSQL_PREFIX?}_doubler` AS `do`
+INNER JOIN
+ `{?_MYSQL_PREFIX?}_user_data` AS `d`
ON
- `d`.`userid`=`u`.`userid`
+ `do`.`userid`=`d`.`userid`
WHERE
- `u`.`status`='CONFIRMED'
- " . runFilterChain('user_exclusion_sql', ' ') . " AND
- `d`.`points` <= %s AND
- `d`.`points` >= ({?doubler_min?} * 2) AND
- `d`.`completed`='N' AND
- `d`.`is_ref`='N'
+ `d`.`status`='CONFIRMED'
+ " . runFilterChain('user_exclusion_sql', $whereStatement) . " AND
+ `do`.`points` <= %s AND
+ `do`.`points` >= ({?doubler_min?} * 2) AND
+ `do`.`completed`='N' AND
+ `do`.`is_ref`='N'
ORDER BY
- `d`.`timemark` ASC",
+ `do`.`timemark` ASC",
array(
- $DOUBLER_POINTS
+ $totalPoints
), __FILE__, __LINE__);
+// Get total count
+list($totalCount) = SQL_FETCHROW($result_total);
+
+// Free memory
+SQL_FREERESULT($result_total);
+
// Check for accounts with limitation
$result_main = SQL_QUERY_ESC("SELECT
- `d`.`id`,
- `d`.`userid`,
- `d`.`points`,
- `d`.`remote_ip`,
- `d`.`timemark`
+ `do`.`id`,
+ `do`.`userid`,
+ `do`.`points`,
+ `do`.`remote_ip`,
+ `do`.`timemark`
FROM
- `{?_MYSQL_PREFIX?}_doubler` AS `d`
-LEFT JOIN
- `{?_MYSQL_PREFIX?}_user_data` AS `u`
+ `{?_MYSQL_PREFIX?}_doubler` AS `do`
+INNER JOIN
+ `{?_MYSQL_PREFIX?}_user_data` AS `d`
ON
- `d`.`userid`=`u`.`userid`
+ `do`.`userid`=`d`.`userid`
WHERE
- `u`.`status`='CONFIRMED'
- " . runFilterChain('user_exclusion_sql', ' ') . " AND
- `d`.`points` <= %s AND
- `d`.`points` >= ({?doubler_min?} * 2) AND
- `d`.`completed`='N' AND
- `d`.`is_ref`='N'
+ `d`.`status`='CONFIRMED'
+ " . runFilterChain('user_exclusion_sql', $whereStatement) . " AND
+ `do`.`points` <= %s AND
+ `do`.`points` >= ({?doubler_min?} * 2) AND
+ `do`.`completed`='N' AND
+ `do`.`is_ref`='N'
ORDER BY
- `d`.`timemark` ASC
+ `do`.`timemark` ASC
LIMIT {?doubler_max_sent?}",
array(
- $DOUBLER_POINTS
+ $totalPoints
), __FILE__, __LINE__);
// Are there entries found?
-if (((!SQL_HASZERONUMS($result_total)) && (getConfig('doubler_sent_all') == 'Y')) || ((SQL_NUMROWS($result_main) == getConfig('doubler_group_sent')) && (getConfig('doubler_sent_all') != 'Y'))) {
+if ((($totalCount > 0) && (getConfig('doubler_sent_all') == 'Y')) || ((SQL_NUMROWS($result_main) == getConfig('doubler_group_sent')) && (getConfig('doubler_sent_all') != 'Y'))) {
// Switch to matching SQL resource
$result_load = $result_main;
- if ((!SQL_HASZERONUMS($result_total)) && (getConfig('doubler_sent_all') == 'Y')) {
+ if (($totalCount > 0) && (getConfig('doubler_sent_all') == 'Y')) {
$result_load = $result_total;
} // END - if
// At least one account was found
while ($content = SQL_FETCHARRAY($result_load)) {
// Only double when points are enougth!
- if ($DOUBLER_POINTS >= $content['points']) {
+ if ($totalPoints >= $content['points']) {
// Check for his ref points
$refPoints = countSumTotalData($content['userid'], 'doubler', 'points', 'refid', FALSE, " AND `completed`='N' AND `is_ref`='Y'");
// Update variables to prevent errors
incrementConfigEntry('doubler_used', $content['points']);
- $DOUBLER_POINTS -= $content['points'];
+ $totalPoints -= $content['points'];
// Prepare array
$content['timemark'] = generateDateTime($content['timemark'], 2);
addYouAreHereLink('admin', __FILE__);
// Exclude default referral id if set
-// @TODO Rewrite those lines to filter
-$userExclusionSql = runFilterChain('user_exclusion_sql', ' ');
-if (isValidId(getDefRefid())) $userExclusionSql .= ' AND d.userid != {?def_refid?}';
-if (isExtensionActive('beg')) $userExclusionSql .= ' AND d.userid != {?beg_userid?}';
-if (isExtensionActive('bonus')) $userExclusionSql .= ' AND d.userid != {?bonus_userid?}';
-if (isExtensionActive('doubler')) $userExclusionSql .= ' AND d.userid != {?doubler_userid?}';
-if (isExtensionInstalledAndNewer('holiday', '0.1.3')) $userExclusionSql .= " AND `d`.`holiday_active`='N'";
+$userExclusionSql = ' ';
+$excludedUserids = runFilterChain('config_userid_exclusion_sql', array());
+if (count($excludedUserids) > 0) {
+ // Exclude all
+ $userExcludeSql = ' AND `d`.`userid` NOT IN (' . implode(', ', $excludedUserids) . ')';
+} // END - if
+
+// @TODO Rewrite this as a filter
+if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
+ $userExclusionSql .= " AND `d`.`holiday_active`='N'";
+} // END - if
// Check for all accounts
$result = SQL_QUERY("SELECT
(UNIX_TIMESTAMP() - `d`.`joined`) >= {?ap_inactive_since?} AND
(UNIX_TIMESTAMP() - `d`.`last_online`) >= {?ap_inactive_since?} AND
(UNIX_TIMESTAMP() - `d`.`ap_notified`) >= {?ap_inactive_since?}
- " . $userExclusionSql . "
+ " . runFilterChain('user_exclusion_sql', $userExcludeSql) . "
ORDER BY
`d`.`userid` ASC", __FILE__, __LINE__);
$whereStatement = '';
// Shall we exclude webmaster's own userid?
+ // @TODO Rewrite these if() blocks to a filter
if ((!isBegIncludeOwnEnabled()) && (isValidId(getBegUserid()))) {
// Exclude it
- $whereStatement .= ' AND `userid` != {?beg_userid?}';
+ $whereStatement .= ' AND `d`.`userid` != {?beg_userid?}';
} // END - if
// Let's check if there are some points left we can pay...
if ((isExtensionActive('autopurge')) && (isBegActiveEnabled()) && ((getApInactiveSince() > 0))) {
// Okay, include last online timestamp
- $whereStatement .= ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}';
+ $whereStatement .= ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}';
+ } // END - if
+
+ // Is ext-holiday installed?
+ if (isExtensionActive('holiday')) {
+ // Exclude those as well
+ $whereStatement .= " AND `d`.`holiday_active`='N'";
} // END - if
// SQL string to check for accounts
$result_main = SQL_QUERY("SELECT
- `userid`,
- `beg_points`
+ `d`.`userid`,
+ `d`.`beg_points`
FROM
- `{?_MYSQL_PREFIX?}_user_data`
+ `{?_MYSQL_PREFIX?}_user_data` AS `d`
WHERE
- `status`='CONFIRMED'
+ `d`.`status`='CONFIRMED'
" . $whereStatement . "
" . runFilterChain('user_exclusion_sql', ' ') . " AND
- `beg_points` > 0
+ `d`.`beg_points` > 0
ORDER BY
- `beg_points` DESC,
- `userid` ASC
+ `d`.`beg_points` DESC,
+ `d`.`userid` ASC
LIMIT {?beg_ranks?}", __FILE__, __LINE__);
if (!SQL_HASZERONUMS($result_main)) {
//* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Monthly reset started.');
if ((getBonusRanks() > 0) && (!isCssOutputMode())) {
- // Extension 'autopurge' is inactive or purging of inactive accounts is deactivated
+ // Extension 'autopurge' is inactive or purging of inactive accounts is deactivated\
$whereStatement = runFilterChain('user_exclusion_sql', "WHERE `status`='CONFIRMED'");
// Shall I keep inactive members away from here? (mostly wanted in an "active-rallye" ...)
+ // @TODO Rewrite these if() blocks to a filter
if ((isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
// Okay, include last online timestamp
- $whereStatement .= ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}';
+ $whereStatement .= ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}';
+ } // END - if
+
+ // Is ext-holiday installed?
+ if (isExtensionActive('holiday')) {
+ // Exclude those as well
+ $whereStatement .= " AND `d`.`holiday_active`='N'";
} // END - if
// Add more bonus points here by running a filter
// Run SQL string to check for accounts
$result_main = SQL_QUERY('SELECT
- `userid`,
+ `d`.`userid`,
(0' . $add . ') AS `points`
FROM
- `{?_MYSQL_PREFIX?}_user_data`
+ `{?_MYSQL_PREFIX?}_user_data` AS `d`
' . $whereStatement . '
ORDER BY
- `points` DESC,
- `userid` ASC
+ `d`.`points` DESC,
+ `d`.`userid` ASC
LIMIT {?bonus_ranks?}', __FILE__, __LINE__);
// Some entries were found?
FROM
`{?_MYSQL_PREFIX?}_user_data`
WHERE
- `status`='CONFIRMED'
- " . runFilterChain('user_exclusion_sql', ' ') . " AND
+ `status`='CONFIRMED' AND
(UNIX_TIMESTAMP() - `joined`) >= {?ap_inactive_since?} AND
(UNIX_TIMESTAMP() - `last_online`) >= {?ap_inactive_since?} AND
(UNIX_TIMESTAMP() - `ap_notified`) >= {?ap_inactive_since?} AND
- " . $excludeSql . "
+ " . runFilterChain('user_exclusion_sql', $excludeSql) . "
ORDER BY
`userid` ASC", __FILE__, __LINE__);
`{?_MYSQL_PREFIX?}_user_data`
WHERE
`status`='CONFIRMED'
- " . runFilterChain('user_exclusion_sql', ' ') . " AND
+ " . runFilterChain('user_exclusion_sql', $excludeSql) . " AND
(UNIX_TIMESTAMP() - `joined`) >= {?ap_inactive_since?} AND
(UNIX_TIMESTAMP() - `last_online`) >= {?ap_inactive_since?} AND
(UNIX_TIMESTAMP() - `ap_notified`) >= {?ap_inactive_time?} AND
`ap_notified` > 0
- " . $excludeSql . "
ORDER BY
`userid` ASC", __FILE__, __LINE__);