More fixes, missing js.php added
[mailer.git] / inc / modules / admin / what-del_email.php
index da714d6..7ea60fc 100644 (file)
@@ -74,32 +74,21 @@ if (!empty($_GET['mid'])) {
                $msg_user = LOAD_EMAIL_TEMPLATE("order-deleted", array(), $sender);
                SEND_EMAIL($sender, MEMBER_ORDER_DELETED, $msg_user);
 
-               // Delete mail from queue
-               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_pool WHERE id=%s LIMIT 1",
-                array(bigintval($_GET['mid'])), __FILE__, __LINE__);
-
                // Fetch right stats_id from pool
-               $result = SQL_QUERY_ESC("SELECT s.id FROM "._MYSQL_PREFIX."_user_stats AS s
+               $result_pool = SQL_QUERY_ESC("SELECT s.id FROM "._MYSQL_PREFIX."_user_stats AS s
 LEFT JOIN "._MYSQL_PREFIX."_pool AS p
 ON s.pool_id=p.id
 WHERE s.pool_id=%s LIMIT 1",
  array(bigintval($_GET['mid'])), __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) == 1) {
+               if (SQL_NUMROWS($result_pool) == 1) {
                        // Fetch stats id
-                       list($stats_id) = SQL_FETCHROW($result);
-
-                       // Free the result
-                       SQL_FREERESULT($result);
+                       list($stats_id) = SQL_FETCHROW($result_pool);
 
                        // Get all user links
-                       $result = SQL_QUERY_ESC("SELECT COUNT(id) AS 'cnt' FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%s",
-                               array(bigintval($stats_id)), __FILE__, __LINE__);
-
-                       // Get unconfirmed links for calculation of total points
-                       list($links) = SQL_FETCHROW($result);
+                       $links = GET_TOTAL_DATA($stats_id, "user_links", "userid", "stats_id", true);
 
-                       // Free result
-                       SQL_FREERESULT($result);
+                       // Reset sent mails for recipient(s)
+                       REDUCT_RECIPIENT_RECEIVED_MAILS("stats_id", $_GET['mid'], $links);
 
                        // Calc total points and pay them back
                        $totalPoints = $links * $price;
@@ -112,7 +101,7 @@ WHERE s.pool_id=%s LIMIT 1",
                                        if ($_CONFIG['repay_deleted_mails'] == "JACKPOT") {
                                                // Set jackpot
                                                $sender = 0;
-                                       }
+                                       } // END - if
 
                                        // Pay back points
                                        //* DEBUG: */ echo "PAYBACK:".$sender."<br />\n";
@@ -122,12 +111,12 @@ WHERE s.pool_id=%s LIMIT 1",
                                        if ($_CONFIG['repay_deleted_mails'] == 'REPAY') {
                                                // Repayed
                                                LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_POINTS_REPAYED,
-                                                       number_format($totalPoints, 0, ",", ".")
+                                                       TRANSLATE_COMMA($totalPoints)
                                                ));
                                        } else {
                                                // To jackpot
                                                LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_POINTS_TO_JACKPOT,
-                                                       number_format($totalPoints, 0, ",", ".")
+                                                       TRANSLATE_COMMA($totalPoints)
                                                ));
                                        }
                                } else {
@@ -139,13 +128,20 @@ WHERE s.pool_id=%s LIMIT 1",
                                LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_POINTS_SHREDDED, $totalPoints));
                        }
 
+                       // Delete mail from queue
+                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_pool WHERE id=%s LIMIT 1",
+                               array(bigintval($_GET['mid'])), __FILE__, __LINE__);
+
                        // Remove links from DB
-                       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%s",
-                        array(bigintval($stats_id)), __FILE__, __LINE__);
+                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%s",
+                               array(bigintval($stats_id)), __FILE__, __LINE__);
 
                        // Output link for manually removing stats entry
                        LOAD_TEMPLATE("admin_settings_saved", false, "<A href=\"".URL."/modules.php?module=admin&amp;what=del_email&amp;pid=".bigintval($_GET['mid'])."\">".ADMIN_REMOVE_STATS_ENTRY."</A>");
                }
+
+               // Free the result
+               SQL_FREERESULT($result_pool);
        } else {
                // Mail already deleted!
                LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NORMAL_MAIL_ALREADY_DELETED);
@@ -153,24 +149,28 @@ WHERE s.pool_id=%s LIMIT 1",
 } elseif (!empty($_GET['pid'])) {
        // Remove stats entries
        $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%s LIMIT 1",
-        array(bigintval($_GET['pid'])), __FILE__, __LINE__);
+               array(bigintval($_GET['pid'])), __FILE__, __LINE__);
+
+       // Output message
        LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_USER_STATS_REMOVED);
 } elseif ((!empty($_GET['bid'])) && (EXT_IS_ACTIVE("bonus"))) {
        // Load data from bonus mail
-       $result = SQL_QUERY_ESC("SELECT id, subject, url, timestamp FROM "._MYSQL_PREFIX."_bonus WHERE id=%s",
-        array(bigintval($_GET['bid'])), __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT id, subject, url, timestamp, mails_sent FROM "._MYSQL_PREFIX."_bonus WHERE id=%s",
+               array(bigintval($_GET['bid'])), __FILE__, __LINE__);
 
        // Delete mail only once
        if (SQL_NUMROWS($result) == 1) {
                // Load data
-               list ($id, $subject, $url, $timestamp) = SQL_FETCHROW($result);
-               SQL_FREERESULT($result);
+               list ($id, $subject, $url, $timestamp, $sent) = SQL_FETCHROW($result);
+
+               // Reset sent mails for recipient(s)
+               REDUCT_RECIPIENT_RECEIVED_MAILS ("bonus_id", $_GET['bid'], $sent);
 
                // Delete bonus mail entirely from database
-               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_bonus WHERE id=%s LIMIT 1",
-                array(bigintval($_GET['bid'])), __FILE__, __LINE__);
-               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%s",
-                array(bigintval($_GET['bid'])), __FILE__, __LINE__);
+               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_bonus WHERE id=%s LIMIT 1",
+                       array(bigintval($_GET['bid'])), __FILE__, __LINE__);
+               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%s",
+                       array(bigintval($_GET['bid'])), __FILE__, __LINE__);
 
                // Prepare data for the template
                define('__ID'     , $id);
@@ -184,6 +184,9 @@ WHERE s.pool_id=%s LIMIT 1",
                // Mail already deleted!
                LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BONUS_MAIL_ALREADY_DELETED);
        }
+
+       // Free result
+       SQL_FREERESULT($result);
 } elseif ((!empty($_GET['nid'])) && (GET_EXT_VERSION("bonus") >= "0.8.7")) {
        // Load data from bonus mail
        $result = SQL_QUERY_ESC("SELECT id, subject, url, timestamp FROM "._MYSQL_PREFIX."_bonus WHERE id=%s",