-}
-
-if (($_CONFIG['auto_purge_active'] == 'Y') && ($_CONFIG['auto_purge'] > 0))
-{
- // First calculate the timestamp
- if (function_exists('CREATE_TIME_SELECTIONS'))
- {
- $PURGE = time() - $_CONFIG['auto_purge'];
- }
- else
- {
- $PURGE = time() - $_CONFIG['auto_purge'] * 24 * 60 * 60;
- }
-
- // Init variables
- $admin_points = "0";
-
- // Then check for outdated mail order. We don't delete them just the confirmation links will be deleted.
- $result = SQL_QUERY_ESC("SELECT s.id, s.userid, s.pool_id, t.price
-FROM "._MYSQL_PREFIX."_user_stats AS s
-LEFT JOIN "._MYSQL_PREFIX."_payments AS t
-ON s.payment_id=t.id
-WHERE s.timestamp_ordered <= %s ORDER BY s.userid",
- array(bigintval($PURGE)), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) > 0)
- {
- // Start deleting procedure
- $uid = "0"; $points = "0";
- while(list($mid, $sender, $pool, $price) = SQL_FETCHROW($result))
- {
- // Check if confirmation links are purged or not
- $result_links = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%d LIMIT 1",
- array(bigintval($mid)), __FILE__, __LINE__);
- if (SQL_NUMROWS($result_links) == 1)
- {
- // Free memory
- SQL_FREERESULT($result_links);
-
- // At least one link was found, enougth to pay back the points
- if (($uid != $sender) && ($uid > 0) && ($points > 0))
- {
- // Directly add points back to senders account
- AUTOPURGE_ADD_POINTS($uid, $points);
- $points = "0";
- }
- // Add points
- $uid = $sender; $points += $price; $admin_points += $price;
-
- // Remove confirmation links from queue
- $result_del = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%d",
- array(bigintval($mid)), __FILE__, __LINE__);
-
- // Update status of order
- $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='DELETED' WHERE id=%d LIMIT 1",
- array(bigintval($pool)), __FILE__, __LINE__);
- }
- }
-
- // Add last points to last user account
- if ($points > 0) AUTOPURGE_ADD_POINTS($uid, $points);
- }
-
- // Free memory
- SQL_FREERESULT($result);
-
- // Is the 'bonus' extension installed and activated?
- if (EXT_IS_ACTIVE("bonus", true))
- {
- // Check for bonus campaigns
- $result = SQL_QUERY_ESC("SELECT id, points FROM "._MYSQL_PREFIX."_bonus WHERE data_type='SEND' AND timestamp <= %s ORDER BY id",
- array(bigintval($PURGE)), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) > 0)
- {
- // Start deleting procedure
- $points = "0";
- while (list($bid, $price) = SQL_FETCHROW($result))
- {
- // Check if confirmation links are purged or not
- $result_links = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%d",
- array(bigintval($bid)), __FILE__, __LINE__);
- if (SQL_NUMROWS($result_links) > 0)
- {
- // At least one link was found, enougth to pay back the points
- $points += $price * SQL_NUMROWS($result_links);
-
- // Free memory
- SQL_FREERESULT($result_links);
-
- // Remove confirmation links from queue
- $result_del = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%d",
- array(bigintval($bid)), __FILE__, __LINE__);
-
- // Update status of order
- $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='DELETED' WHERE id=%d LIMIT 1",
- array(bigintval($bid)), __FILE__, __LINE__);
- }
- }
-
- // Add points to jackpot
- ADD_JACKPOT($points);
-
- // Add points for the admin
- $admin_points += $points;
- }
-
- // Free memory
- SQL_FREERESULT($result);
- }
-
- // Add points from deleted accounts to jackpot, but here just add to notify mail
- if ($admin_points > 0)
- {
- // Send mail to admin
- if (GET_EXT_VERSION("admins") >= "0.4.1")
- {
- SEND_ADMIN_EMAILS_PRO(AUTOPURGE_ADMIN_SUBJECT, "admin_autopurge_points", TRANSLATE_COMMA($points), "0");
- }
- else
- {
- $msg = LOAD_EMAIL_TEMPLATE("admin_autopurge_points", TRANSLATE_COMMA($points), "0");
- SEND_ADMIN_EMAILS(AUTOPURGE_ADMIN_SUBJECT, $msg);
- }
- }
-}
-
-// Shall I look for inactive accounts and autopurge inactive accounts?
-if ($_CONFIG['ap_inactive'] == 'Y')
-{
- // Ok, let's have a look...
- $since = bigintval(time() - $_CONFIG['ap_in_since']);
- $EXCLUDE_LIST = " AND d.userid != c.def_refid";
-
- // Check for more extensions
- if (EXT_IS_ACTIVE("beg")) $EXCLUDE_LIST .= " AND d.userid != c.beg_uid";
- if (EXT_IS_ACTIVE("bonus")) $EXCLUDE_LIST .= " AND d.userid != c.bonus_uid";
- if (EXT_IS_ACTIVE("doubler")) $EXCLUDE_LIST .= " AND d.userid != c.doubler_uid";
-
- // Check for new holiday extension
- if (GET_EXT_VERSION("holiday") >= "0.1.3")
- {
- $EXCLUDE_LIST .= " AND d.holiday_active = 'N'";
- }
-
- // Check for all accounts
- $result_inactive = SQL_QUERY_ESC("SELECT DISTINCT d.userid, d.email, d.last_online
-FROM "._MYSQL_PREFIX."_user_data AS d, "._MYSQL_PREFIX."_config AS c
-WHERE d.status='CONFIRMED' AND d.joined < %s AND d.last_online < %s AND d.ap_notified < %s
-".$EXCLUDE_LIST."
-ORDER BY d.userid", array($since, $since, $since), __FILE__, __LINE__);
-
- if (SQL_NUMROWS($result_inactive) > 0)
- {
- // Prepare variables and constants...
- $UIDs = "";
- define('__INACTIVE_SINCE', ($_CONFIG['ap_in_since'] / 60 / 60));
- define('__INACTIVE_TIME' , ($_CONFIG['ap_in_time'] / 60 / 60));
-
- // Mark found accounts as inactive and send an email
- while(list($uid, $email, $last) = SQL_FETCHROW($result_inactive))
- {
- // Remember userids for the admin
- $UIDs .= $uid.", ";
-
- // Get date/time from timestamp
- $last = MAKE_DATETIME($last, "0");
-
- // Load mail template
- $msg = LOAD_EMAIL_TEMPLATE("member_autopurge_inactive", $last, bigintval($uid));
- SEND_EMAIL($email, AUTOPURGE_MEMBER_INACTIVE_SUBJECT, $msg);
-
- // Update this account
- $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET ap_notified=UNIX_TIMESTAMP() WHERE userid=%d LIMIT 1",
- array(bigintval($uid)), __FILE__, __LINE__);
- }
-
- // Remove last comma
- $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
-
- // Send mail notification to admin
- if (GET_EXT_VERSION("admins") >= "0.4.1")
- {
- SEND_ADMIN_EMAILS_PRO(AUTOPURGE_ADMIN_INACTIVE_SUBJECT, "admin_autopurge_inactive", $UIDs, "");
- }
- else
- {
- $msg = LOAD_EMAIL_TEMPLATE("admin_autopurge_inactive", $UIDs, "");
- SEND_ADMIN_EMAILS(AUTOPURGE_ADMIN_INACTIVE_SUBJECT, $msg);
- }
- }
-
- // Free memory
- SQL_FREERESULT($result_inactive);
-
- // Now let's have a look for inactive accounts we want to delete we newly use the same exclude list
- // here for e.g. excluding holiday users
- $time = bigintval(time() - $_CONFIG['ap_in_time']);
- $result_inactive = SQL_QUERY_ESC("SELECT d.userid, d.email, d.last_online
-FROM "._MYSQL_PREFIX."_user_data AS d, "._MYSQL_PREFIX."_config AS c
-WHERE status='CONFIRMED' AND joined < %s AND last_online< %s AND ap_notified < %s
-".$EXCLUDE_LIST."
-ORDER BY userid",
- array($since, $since, $time), __FILE__, __LINE__);
- if (SQL_NUMROWS($result_inactive) > 0)
- {
- // Prepare variable...
- $UIDs = "";