Commented out for testing... opps
[mailer.git] / inc / modules / admin / what-del_email.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 02/12/2004 *
4  * ================                             Last change: 02/27/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-del_email.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Delete a bonus or normal mail                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Bonus- / Normal-Mail loeschen                    *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  *  Module by Robert Niedziela, Megacomputing                           *
15  *          web : http://mc-p.mcserver.de                               *
16  *                                                                      *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
19  * For more information visit: http://www.mxchange.org                  *
20  *                                                                      *
21  * This program is free software; you can redistribute it and/or modify *
22  * it under the terms of the GNU General Public License as published by *
23  * the Free Software Foundation; either version 2 of the License, or    *
24  * (at your option) any later version.                                  *
25  *                                                                      *
26  * This program is distributed in the hope that it will be useful,      *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
29  * GNU General Public License for more details.                         *
30  *                                                                      *
31  * You should have received a copy of the GNU General Public License    *
32  * along with this program; if not, write to the Free Software          *
33  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
34  * MA  02110-1301  USA                                                  *
35  ************************************************************************/
36
37 // Some security stuff...
38 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) {
39         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40         require($INC);
41 }
42
43 // Add description as navigation point
44 ADD_DESCR("admin", basename(__FILE__));
45
46 if (!empty($_GET['mid'])) {
47         // Load email data
48         $result = SQL_QUERY_ESC("SELECT id, sender, subject, url, timestamp, payment_id FROM "._MYSQL_PREFIX."_pool WHERE id=%d LIMIT 1",
49          array(bigintval($_GET['mid'])), __FILE__, __LINE__);
50
51         // Delete mail only once
52         if (SQL_NUMROWS($result) == 1) {
53                 // Load data
54                 list ($id, $sender, $subject, $url, $timestamp, $payId) = SQL_FETCHROW($result);
55                 SQL_FREERESULT($result);
56
57                 // Get points we shall pay back per mail
58                 $price = GET_PAY_POINTS($payId, "price");
59
60                 // Prepare data for the template
61                 define('__ID'     , $id);
62                 define('__SENDER' , ADMIN_USER_PROFILE_LINK($sender));
63                 define('__SUBJECT', $subject);
64                 define('__URL'    , DEREFERER($url));
65                 define('__ORDERED', MAKE_DATETIME($timestamp, "0"));
66
67                 // Load template
68                 LOAD_TEMPLATE("admin_del_email_normal");
69
70                 // Transfer data to data array
71                 $DATA = array($url, $subject);
72
73                 // Load email template and send the email away
74                 $msg_user = LOAD_EMAIL_TEMPLATE("order-deleted", "", $sender);
75                 SEND_EMAIL($sender, MEMBER_ORDER_DELETED, $msg_user);
76
77                 // Delete mail from queue
78                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_pool WHERE id=%d LIMIT 1",
79                  array(bigintval($_GET['mid'])), __FILE__, __LINE__);
80
81                 // Fetch right stats_id from pool
82                 $result = SQL_QUERY_ESC("SELECT s.id FROM "._MYSQL_PREFIX."_user_stats AS s
83 LEFT JOIN "._MYSQL_PREFIX."_pool AS p
84 ON s.pool_id=p.id
85 WHERE s.pool_id=%d LIMIT 1",
86  array(bigintval($_GET['mid'])), __FILE__, __LINE__);
87                 if (SQL_NUMROWS($result) == 1) {
88                         // Fetch stats id
89                         list($stats_id) = SQL_FETCHROW($result);
90
91                         // Free the result
92                         SQL_FREERESULT($result);
93
94                         // Shall we pay the points back to the user?
95                         if ($_CONFIG['repay_deleted_mails'] != "NEVER") {
96                                 // Get all user links
97                                 $result = SQL_QUERY_ESC("SELECT COUNT(id) AS 'cnt' FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%d",
98                                         array(bigintval($stats_id)), __FILE__, __LINE__);
99
100                                 // Get unconfirmed links for calculation of total points
101                                 list($links) = SQL_FETCHROW($result);
102
103                                 // Free result
104                                 SQL_FREERESULT($result);
105
106                                 // Calc total points and pay them back
107                                 $totalPoints = $links * $price;
108                                 //* DEBUG: */ echo $stats_id.":".$totalPoints."/".$links."/".$price."<br />\n";
109                                 if ($totalPoints > 0) {
110                                         // Shall we payback to user or jackpot?
111                                         if ($_CONFIG['repay_deleted_mails'] == "JACKPOT") {
112                                                 // Set jackpot
113                                                 $sender = 0;
114                                         }
115
116                                         // Pay back points
117                                         //* DEBUG: */ echo "PAYBACK:".$sender."<br />\n";
118                                         ADD_POINTS_REFSYSTEM($sender, $totalPoints, true, "0", false,"direct");
119
120                                         // Output message
121                                         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_POINTS_REPAYED,
122                                                 number_format($totalPoints, 0, ",", ".")
123                                         ));
124                                 } else {
125                                         // No points repayed!
126                                         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_POINTS_REPAYED);
127                                 }
128                         }
129
130                         // Remove links from DB
131                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%d",
132                          array(bigintval($stats_id)), __FILE__, __LINE__);
133
134                         // Output link for manually removing stats entry
135                         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>");
136                 }
137         } else {
138                 // Mail already deleted!
139                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NORMAL_MAIL_ALREADY_DELETED);
140         }
141 } elseif (!empty($_GET['pid'])) {
142         // Remove stats entries
143         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%d LIMIT 1",
144          array(bigintval($_GET['pid'])), __FILE__, __LINE__);
145         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_USER_STATS_REMOVED);
146 } elseif ((!empty($_GET['bid'])) && (EXT_IS_ACTIVE("bonus"))) {
147         // Load data from bonus mail
148         $result = SQL_QUERY_ESC("SELECT id, subject, url, timestamp FROM "._MYSQL_PREFIX."_bonus WHERE id=%d",
149          array(bigintval($_GET['bid'])), __FILE__, __LINE__);
150
151         // Delete mail only once
152         if (SQL_NUMROWS($result) == 1) {
153                 // Load data
154                 list ($id, $subject, $url, $timestamp) = SQL_FETCHROW($result);
155                 SQL_FREERESULT($result);
156
157                 // Delete bonus mail entirely from database
158                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_bonus WHERE id=%d LIMIT 1",
159                  array(bigintval($_GET['bid'])), __FILE__, __LINE__);
160                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%d",
161                  array(bigintval($_GET['bid'])), __FILE__, __LINE__);
162
163                 // Prepare data for the template
164                 define('__ID'     , $id);
165                 define('__SUBJECT', $subject);
166                 define('__URL'    , DEREFERER($url));
167                 define('__ORDERED', MAKE_DATETIME($timestamp, "0"));
168
169                 // Load template
170                 LOAD_TEMPLATE("admin_del_email_bonus");
171         } else {
172                 // Mail already deleted!
173                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BONUS_MAIL_ALREADY_DELETED);
174         }
175 } else {
176         // No mail orders fond
177         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_WRONG_CALL);
178 }
179
180 //
181 ?>