Double->single rewrites, fixes for email archive
[mailer.git] / inc / autopurge / purge-general.php
index b880ee8b531c6643001e50ddb72dc4a4d15bdb36..3702659edb70d740baf284f85d1058d44c5457ba 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 09/14/2008 *
- * ===============                              Last change: 09/14/2008 *
+ * Mailer v0.2.1-FINAL                                Start: 09/14/2008 *
+ * ===================                          Last change: 09/14/2008 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : purge-general.php                                *
@@ -18,7 +18,7 @@
  * Needs to be in all Files and every File needs "svn propset           *
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
 
 // Some security stuff...
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
-       require($INC);
+       die();
 }
 
 // Abort if autopurge is not active or disabled by admin
-if ((!EXT_IS_ACTIVE('autopurge')) || (getConfig('auto_purge_active') != 'Y')) {
+if ((!isExtensionActive('autopurge')) || (getConfig('auto_purge_active') != 'Y')) {
        // Abort here
        return false;
 }
 
 if ((getConfig('auto_purge_active') == 'Y') && (getConfig('auto_purge') > 0)) {
        // Init SQLs
-       INIT_SQLS();
+       initSqls();
 
        // First calculate the timestamp
        $PURGE = getConfig('auto_purge');
 
        // 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
-FROM `{!_MYSQL_PREFIX!}_user_stats` AS s
-LEFT JOIN `{!_MYSQL_PREFIX!}_payments` AS t
-ON s.payment_id=t.id
-WHERE s.timestamp_ordered <= (UNIX_TIMESTAMP() - %s) ORDER BY s.userid",
-       array(bigintval($PURGE)), __FILE__, __LINE__);
+       $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 <= (UNIX_TIMESTAMP() - %s)
+ORDER BY
+       s.userid ASC",
+               array(bigintval($PURGE)), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) > 0) {
                // Start deleting procedure
-               $uid = 0; $points = 0;
+               $userid = '0'; $points = '0';
                while ($content = SQL_FETCHARRAY($result)) {
                        // Check if confirmation links are purged or not
-                       $result_links = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_user_links` WHERE stats_id=%s LIMIT 1",
-                       array(bigintval($content['id'])), __FILE__, __LINE__);
+                       $result_links = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s LIMIT 1",
+                               array(bigintval($content['id'])), __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 != $content['userid']) && ($uid > 0) && ($points > 0)) {
+                               if (($userid != $content['userid']) && ($userid > 0) && ($points > 0)) {
                                        // Directly add points back to senders account
-                                       AUTOPURGE_ADD_POINTS($uid, $points);
-                                       $points = 0;
+                                       addPointsAutoPurge($userid, $points);
+                                       $points = '0';
                                } // END - if
 
                                // Add points
-                               $uid = $content['userid']; $points += $content['price']; $admin_points += $content['price'];
+                               $userid = $content['userid']; $points += $content['price']; $admin_points += $content['price'];
 
                                // Remove confirmation links from queue
-                               ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_links` WHERE stats_id=%s",
-                               array(bigintval($content['id'])), __FILE__, __LINE__, false));
+                               addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
+                                       array(bigintval($content['id'])), __FILE__, __LINE__, false));
 
                                // Update status of order
-                               ADD_SQL(SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET data_type='DELETED' WHERE `id`=%s LIMIT 1",
-                               array(bigintval($content['pool_id'])), __FILE__, __LINE__, false));
+                               addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='DELETED' WHERE `id`=%s LIMIT 1",
+                                       array(bigintval($content['pool_id'])), __FILE__, __LINE__, false));
                        } // END - if
                } // END - while
 
                // Add last points to last user account
-               if ($points > 0) AUTOPURGE_ADD_POINTS($uid, $points);
+               if ($points > 0) addPointsAutoPurge($userid, $points);
        } // END - if
 
        // Free memory
        SQL_FREERESULT($result);
 
        // Is the 'bonus' extension installed and activated?
-       if (EXT_IS_ACTIVE('bonus', true)) {
+       if (isExtensionActive('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__);
+               $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;
+                       $points = '0';
                        while ($content = SQL_FETCHARRAY($result)) {
                                // Check if confirmation links are purged or not
-                               $result_links = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_user_links` WHERE bonus_id=%s",
-                               array(bigintval($content['id'])), __FILE__, __LINE__);
+                               $result_links = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
+                                       array(bigintval($content['id'])), __FILE__, __LINE__);
                                if (SQL_NUMROWS($result_links) > 0) {
                                        // At least one link was found, enougth to pay back the points
                                        $points += $content['points'] * SQL_NUMROWS($result_links);
@@ -124,17 +130,17 @@ WHERE s.timestamp_ordered <= (UNIX_TIMESTAMP() - %s) ORDER BY s.userid",
                                        SQL_FREERESULT($result_links);
 
                                        // Remove confirmation links from queue
-                                       ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_links` WHERE bonus_id=%s",
-                                       array(bigintval($content['id'])), __FILE__, __LINE__, false));
+                                       addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
+                                               array(bigintval($content['id'])), __FILE__, __LINE__, false));
 
                                        // Update status of order
-                                       ADD_SQL(SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_bonus` SET data_type='DELETED' WHERE `id`=%s LIMIT 1",
-                                       array(bigintval($content['id'])), __FILE__, __LINE__, false));
+                                       addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='DELETED' WHERE `id`=%s LIMIT 1",
+                                               array(bigintval($content['id'])), __FILE__, __LINE__, false));
                                } // END - if
                        } // END - while
 
                        // Add points to jackpot
-                       ADD_JACKPOT($points);
+                       if (isExtensionActive('jackpot')) addPointsToJackpot($points);
 
                        // Add points for the admin
                        $admin_points += $points;
@@ -147,7 +153,7 @@ WHERE s.timestamp_ordered <= (UNIX_TIMESTAMP() - %s) ORDER BY s.userid",
        // Add points from deleted accounts to jackpot, but here just add to notify mail
        if ($admin_points > 0) {
                // Send mail to admin
-               sendAdminNotification(getMessage('AUTOPURGE_ADMIN_SUBJECT'), "admin_autopurge_points", translateComma($points), '0');
+               sendAdminNotification(getMessage('AUTOPURGE_ADMIN_SUBJECT'), 'admin_autopurge_points', translateComma($admin_points), 0);
        } // END - if
 
        // Run all SQLs here