Reset rewritten, SQL fixed, zeros are now numeric
[mailer.git] / inc / autopurge.php
index 52ac70472785d03c154d95ed708e9c406884f5ec..a0896be2c32a52c8911a8af81318a8ada6c813bd 100644 (file)
@@ -38,20 +38,20 @@ if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
        require($INC);
 }
 
-if (($CONFIG['auto_purge_active'] == "Y") && ($CONFIG['auto_purge'] > 0))
+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'];
+               $PURGE = time() - $_CONFIG['auto_purge'];
        }
         else
        {
-               $PURGE = time() - $CONFIG['auto_purge'] * 24 * 60 * 60;
+               $PURGE = time() - $_CONFIG['auto_purge'] * 24 * 60 * 60;
        }
 
        // Init variables
-       $admin_points = "0";
+       $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
@@ -63,11 +63,11 @@ WHERE s.timestamp_ordered <= %s ORDER BY s.userid",
        if (SQL_NUMROWS($result) > 0)
        {
                // Start deleting procedure
-               $uid = "0"; $points = "0";
+               $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",
+                       $result_links = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%s LIMIT 1",
                         array(bigintval($mid)), __FILE__, __LINE__);
                        if (SQL_NUMROWS($result_links) == 1)
                        {
@@ -79,17 +79,17 @@ WHERE s.timestamp_ordered <= %s ORDER BY s.userid",
                                {
                                        // Directly add points back to senders account
                                        AUTOPURGE_ADD_POINTS($uid, $points);
-                                       $points = "0";
+                                       $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",
+                               $result_del = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%s",
                                 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",
+                               $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='DELETED' WHERE id=%s LIMIT 1",
                                 array(bigintval($pool)), __FILE__, __LINE__);
                        }
                }
@@ -110,11 +110,11 @@ WHERE s.timestamp_ordered <= %s ORDER BY s.userid",
                if (SQL_NUMROWS($result) > 0)
                {
                        // Start deleting procedure
-                       $points = "0";
+                       $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",
+                               $result_links = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%s",
                                 array(bigintval($bid)), __FILE__, __LINE__);
                                if (SQL_NUMROWS($result_links) > 0)
                                {
@@ -125,11 +125,11 @@ WHERE s.timestamp_ordered <= %s ORDER BY s.userid",
                                        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",
+                                       $result_del = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%s",
                                         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",
+                                       $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='DELETED' WHERE id=%s LIMIT 1",
                                         array(bigintval($bid)), __FILE__, __LINE__);
                                }
                        }
@@ -149,23 +149,15 @@ WHERE s.timestamp_ordered <= %s ORDER BY s.userid",
        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);
-               }
+               SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_SUBJECT, "admin_autopurge_points", TRANSLATE_COMMA($points), "0");
        }
 }
 
 // Shall I look for inactive accounts and autopurge inactive accounts?
-if ($CONFIG['ap_inactive'] == "Y")
+if ($_CONFIG['ap_inactive'] == "Y")
 {
        // Ok, let's have a look...
-       $since = bigintval(time() - $CONFIG['ap_in_since']);
+       $since = bigintval(time() - $_CONFIG['ap_in_since']);
        $EXCLUDE_LIST = " AND d.userid != c.def_refid";
 
        // Check for more extensions
@@ -190,8 +182,8 @@ ORDER BY d.userid", array($since, $since, $since), __FILE__, __LINE__);
        {
                // Prepare variables and constants...
                $UIDs = "";
-               define('__INACTIVE_SINCE', ($CONFIG['ap_in_since'] / 60 / 60));
-               define('__INACTIVE_TIME' , ($CONFIG['ap_in_time']  / 60 / 60));
+               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))
@@ -207,7 +199,7 @@ ORDER BY d.userid", array($since, $since, $since), __FILE__, __LINE__);
                        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",
+                       $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET ap_notified=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
                         array(bigintval($uid)), __FILE__, __LINE__);
                }
 
@@ -215,15 +207,7 @@ ORDER BY d.userid", array($since, $since, $since), __FILE__, __LINE__);
                $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);
-               }
+               SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_INACTIVE_SUBJECT, "admin_autopurge_inactive", $UIDs, "");
        }
 
        // Free memory
@@ -231,7 +215,7 @@ ORDER BY d.userid", array($since, $since, $since), __FILE__, __LINE__);
 
        // 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']);
+       $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
@@ -260,17 +244,9 @@ ORDER BY userid",
                $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
 
                // Send mail notification to admin
-               if ($CONFIG['ap_un_mail'] == "Y")
+               if ($_CONFIG['ap_un_mail'] == "Y")
                {
-                       if (GET_EXT_VERSION("admins") >= "0.4.1")
-                       {
-                               SEND_ADMIN_EMAILS_PRO(AUTOPURGE_ADMIN_DELETE_SUBJECT, "admin_autopurge_delete", $UIDs, "");
-                       }
-                        else
-                       {
-                               $msg = LOAD_EMAIL_TEMPLATE("admin_autopurge_delete", $UIDs, "");
-                               SEND_ADMIN_EMAILS(AUTOPURGE_ADMIN_DELETE_SUBJECT, $msg);
-                       }
+                       SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_DELETE_SUBJECT, "admin_autopurge_delete", $UIDs, "");
                }
        }
 
@@ -279,17 +255,17 @@ ORDER BY userid",
 }
 
 // Shall I auto-purge unconfirmed accounts?
-if ($CONFIG['ap_unconfirmed'] == "Y")
+if ($_CONFIG['ap_unconfirmed'] == "Y")
 {
        // Init variables and find unconfirmed accounts which I shall auto-purge
-       $time = bigintval(time() - $CONFIG['ap_un_time']);
+       $time = bigintval(time() - $_CONFIG['ap_un_time']);
        $result_uncon = SQL_QUERY_ESC("SELECT userid, email, joined FROM "._MYSQL_PREFIX."_user_data WHERE status='UNCONFIRMED' AND joined < %s ORDER BY userid",
         array($time), __FILE__, __LINE__);
        if (SQL_NUMROWS($result_uncon) > 0)
        {
                // Prepare variable...
                $UIDs = "";
-               define('__UNCONFIRMED_TIME' , ($CONFIG['ap_un_time']  / 60 / 60));
+               define('__UNCONFIRMED_TIME' , ($_CONFIG['ap_un_time']  / 60 / 60));
 
                // Delete inactive accounts
                while (list($uid, $email, $joined) = SQL_FETCHROW($result_uncon))
@@ -308,17 +284,9 @@ if ($CONFIG['ap_unconfirmed'] == "Y")
                $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
 
                // Send mail notification to admin
-               if ($CONFIG['ap_un_mail'] == "Y")
+               if ($_CONFIG['ap_un_mail'] == "Y")
                {
-                       if (GET_EXT_VERSION("admins") >= "0.4.1")
-                       {
-                               SEND_ADMIN_EMAILS_PRO(AUTOPURGE_ADMIN_UNCONFIRMED_SUBJECT, "admin_autopurge_unconfirmed", $UIDs, "");
-                       }
-                        else
-                       {
-                               $msg = LOAD_EMAIL_TEMPLATE("admin_autopurge_unconfirmed", $UIDs, "");
-                               SEND_ADMIN_EMAILS(AUTOPURGE_ADMIN_UNCONFIRMED_SUBJECT, $msg);
-                       }
+                       SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_UNCONFIRMED_SUBJECT, "admin_autopurge_unconfirmed", $UIDs, "");
                }
        }
 
@@ -327,34 +295,25 @@ if ($CONFIG['ap_unconfirmed'] == "Y")
 }
 
 // Check version (must be > 0.0)
-if ((GET_EXT_VERSION("task") > "0.0") && ($CONFIG['ap_tasks'] == "Y"))
+if ((GET_EXT_VERSION("task") > "0.0") && ($_CONFIG['ap_tasks'] == "Y"))
 {
        // Purge deleted tasks (no notification to admin)
-       $since = bigintval(time() - $CONFIG['ap_tasks_time']);
+       $since = bigintval(time() - $_CONFIG['ap_tasks_time']);
        $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE status='DELETED' AND task_created <= %s",
         array($since), __FILE__, __LINE__);
        $DELETED = SQL_AFFECTEDROWS();
 
-       if (($DELETED > 0) && ($CONFIG['ap_tasks_mail'] == "Y"))
+       if (($DELETED > 0) && ($_CONFIG['ap_tasks_mail'] == "Y"))
        {
                // Send out email to admin
-               if (GET_EXT_VERSION("admins") >= "0.4.1")
-               {
-                       SEND_ADMIN_EMAILS_PRO(AUTOPURGE_ADMIN_TASKS_SUBJECT, "admin_autopurge_tsks", $DELETED, "");
-               }
-                else
-               {
-                       $msg = LOAD_EMAIL_TEMPLATE("admin_autopurge_tsks", $DELETED, "");
-                       SEND_ADMIN_EMAILS(AUTOPURGE_ADMIN_TASKS_SUBJECT, $msg);
-               }
+               SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_TASKS_SUBJECT, "admin_autopurge_tsks", $DELETED, "");
        }
 }
 
 // Search for mails from deleted members?
-if ($CONFIG['ap_del_mails'])
-{
+if ($_CONFIG['ap_del_mails']) {
        // Okay, let's check for them...
-       $since = bigintval(time() - $CONFIG['ap_dm_timeout']);
+       $since = bigintval(time() - $_CONFIG['ap_dm_timeout']);
        $result_mails = SQL_QUERY_ESC("SELECT sender FROM "._MYSQL_PREFIX."_pool WHERE data_type='DELETED' AND timestamp <= %s ORDER BY sender",
         array($since), __FILE__, __LINE__);
 
@@ -362,22 +321,19 @@ if ($CONFIG['ap_del_mails'])
        $DELETED = 0;
 
        // Do we have "purged" mails?
-       if (SQL_NUMROWS($result_mails) > 0)
-       {
+       if (SQL_NUMROWS($result_mails) > 0) {
                // Okay, check for their sender's
-               while(list($sender) = SQL_FETCHROW($result_mails))
-               {
+               while(list($sender) = SQL_FETCHROW($result_mails)) {
                        // Check now...
-                       $fount = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1", array(bigintval($sender)), __FILE__, __LINE__));
-                       if ($found == 0)
-                       {
+                       $fount = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1", array(bigintval($sender)), __FILE__, __LINE__));
+                       if ($found == 0) {
                                // Okay we found some mails!
-                               $result_remove = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_pool WHERE sender=%d",
+                               $result_remove = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_pool WHERE sender=%s",
                                 array(bigintval($sender)), __FILE__, __LINE__);
                                $DELETED += SQL_AFFECTEDROWS();
 
                                // Reset query (to prevent possible errors) ...
-                               $since = bigintval(time() - $CONFIG['ap_dm_timeout']);
+                               $since = bigintval(time() - $_CONFIG['ap_dm_timeout']);
                                $result_mails = SQL_QUERY_ESC("SELECT sender FROM "._MYSQL_PREFIX."_pool WHERE data_type='DELETED' AND timestamp <= %s ORDER BY sender",
                                 array($since), __FILE__, __LINE__);
                        }
@@ -388,26 +344,23 @@ if ($CONFIG['ap_del_mails'])
        SQL_FREERESULT($result_mails);
 
        // Now let's check for stats entries as well
-       $since = bigintval(time() - $CONFIG['ap_dm_timeout']);
+       $since = bigintval(time() - $_CONFIG['ap_dm_timeout']);
        $result_mails = SQL_QUERY_ESC("SELECT sender FROM "._MYSQL_PREFIX."_pool WHERE data_type='DELETED' AND timestamp <= %s ORDER BY sender",
         array($since), __FILE__, __LINE__);
 
        // Do we have "purged" mails?
-       if (SQL_NUMROWS($result_mails) > 0)
-       {
+       if (SQL_NUMROWS($result_mails) > 0) {
                // Okay, check for their sender's
-               while(list($sender) = SQL_FETCHROW($result_mails))
-               {
+               while(list($sender) = SQL_FETCHROW($result_mails)) {
                        // Check now...
-                       $found = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1", array(bigintval($sender)), __FILE__, __LINE__));
-                       if ($found == 0)
-                       {
+                       $found = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1", array(bigintval($sender)), __FILE__, __LINE__));
+                       if ($found == 0) {
                                // Okay we found some mails!
-                               $result_remove = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_stats WHERE sender=%d", array(bigintval($sender)), __FILE__, __LINE__);
+                               $result_remove = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_stats WHERE sender=%s", array(bigintval($sender)), __FILE__, __LINE__);
                                $DELETED += SQL_AFFECTEDROWS();
 
                                // Reset query (to prevent possible errors) ...
-                               $since = bigintval(time() - $CONFIG['ap_dm_timeout']);
+                               $since = bigintval(time() - $_CONFIG['ap_dm_timeout']);
                                $result_mails = SQL_QUERY_ESC("SELECT sender FROM "._MYSQL_PREFIX."_user_stats WHERE data_type='DELETED' AND timestamp_send <= %s ORDER BY sender",
                                 array($since), __FILE__, __LINE__);
                        }
@@ -418,33 +371,23 @@ if ($CONFIG['ap_del_mails'])
        SQL_FREERESULT($result_mails);
 
        // Do we have deleted mails and the admin want's to receive a notification
-       if (($DELETED > 0) && ($CONFIG['ap_dm_notify'] == "Y"))
-       {
+       if (($DELETED > 0) && ($_CONFIG['ap_dm_notify'] == "Y")) {
                // Send out email to admin
-               if (GET_EXT_VERSION("admins") >= "0.4.1")
-               {
-                       SEND_ADMIN_EMAILS_PRO(AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT, "admin_autopurge_del_mails", $DELETED, "");
-               }
-                else
-               {
-                       $msg = LOAD_EMAIL_TEMPLATE("admin_autopurge_del_mails", $DELETED, "");
-                       SEND_ADMIN_EMAILS(AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT, $msg);
-               }
+               SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT, "admin_autopurge_del_mails", $DELETED, "");
        }
 }
 
-if (EXT_IS_ACTIVE("rallye"))
-{
+if (EXT_IS_ACTIVE("rallye")) {
        // Check expired rallyes (hard-coded 3 days limit for displaying expired rallyes!)
        require_once(PATH."inc/libs/rallye_functions.php");
        RALLYE_DELETE_EXPIRED_RALLYES();
 }
-//
-if (EXT_IS_ACTIVE("bonus"))
-{
+
+if (EXT_IS_ACTIVE("bonus")) {
        // Check for expired turbo bonus lines
        require_once(PATH."inc/libs/bonus_functions.php");
        BONUS_PURGE_EXPIRED_TURBO_BONUS();
 }
+
 //
 ?>