More fixes, missing js.php added
[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 ((!defined('__SECURITY')) || (!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", __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=%s 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' => $url, 'subject' => $subject);
72
73                 // Load email template and send the email away
74                 $msg_user = LOAD_EMAIL_TEMPLATE("order-deleted", array(), $sender);
75                 SEND_EMAIL($sender, MEMBER_ORDER_DELETED, $msg_user);
76
77                 // Fetch right stats_id from pool
78                 $result_pool = SQL_QUERY_ESC("SELECT s.id FROM "._MYSQL_PREFIX."_user_stats AS s
79 LEFT JOIN "._MYSQL_PREFIX."_pool AS p
80 ON s.pool_id=p.id
81 WHERE s.pool_id=%s LIMIT 1",
82  array(bigintval($_GET['mid'])), __FILE__, __LINE__);
83                 if (SQL_NUMROWS($result_pool) == 1) {
84                         // Fetch stats id
85                         list($stats_id) = SQL_FETCHROW($result_pool);
86
87                         // Get all user links
88                         $links = GET_TOTAL_DATA($stats_id, "user_links", "userid", "stats_id", true);
89
90                         // Reset sent mails for recipient(s)
91                         REDUCT_RECIPIENT_RECEIVED_MAILS("stats_id", $_GET['mid'], $links);
92
93                         // Calc total points and pay them back
94                         $totalPoints = $links * $price;
95
96                         // Shall we pay the points back to the user?
97                         if ($_CONFIG['repay_deleted_mails'] != 'SHRED') {
98                                 //* DEBUG: */ echo $stats_id.":".$totalPoints."/".$links."/".$price."<br />\n";
99                                 if ($totalPoints > 0) {
100                                         // Shall we payback to user or jackpot?
101                                         if ($_CONFIG['repay_deleted_mails'] == "JACKPOT") {
102                                                 // Set jackpot
103                                                 $sender = 0;
104                                         } // END - if
105
106                                         // Pay back points
107                                         //* DEBUG: */ echo "PAYBACK:".$sender."<br />\n";
108                                         ADD_POINTS_REFSYSTEM($sender, $totalPoints, true, "0", false,"direct");
109
110                                         // Output message
111                                         if ($_CONFIG['repay_deleted_mails'] == 'REPAY') {
112                                                 // Repayed
113                                                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_POINTS_REPAYED,
114                                                         TRANSLATE_COMMA($totalPoints)
115                                                 ));
116                                         } else {
117                                                 // To jackpot
118                                                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_POINTS_TO_JACKPOT,
119                                                         TRANSLATE_COMMA($totalPoints)
120                                                 ));
121                                         }
122                                 } else {
123                                         // No points repayed!
124                                         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_POINTS_REPAYED);
125                                 }
126                         } else {
127                                 // Points shredded!
128                                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_POINTS_SHREDDED, $totalPoints));
129                         }
130
131                         // Delete mail from queue
132                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_pool WHERE id=%s LIMIT 1",
133                                 array(bigintval($_GET['mid'])), __FILE__, __LINE__);
134
135                         // Remove links from DB
136                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%s",
137                                 array(bigintval($stats_id)), __FILE__, __LINE__);
138
139                         // Output link for manually removing stats entry
140                         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>");
141                 }
142
143                 // Free the result
144                 SQL_FREERESULT($result_pool);
145         } else {
146                 // Mail already deleted!
147                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NORMAL_MAIL_ALREADY_DELETED);
148         }
149 } elseif (!empty($_GET['pid'])) {
150         // Remove stats entries
151         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%s LIMIT 1",
152                 array(bigintval($_GET['pid'])), __FILE__, __LINE__);
153
154         // Output message
155         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_USER_STATS_REMOVED);
156 } elseif ((!empty($_GET['bid'])) && (EXT_IS_ACTIVE("bonus"))) {
157         // Load data from bonus mail
158         $result = SQL_QUERY_ESC("SELECT id, subject, url, timestamp, mails_sent FROM "._MYSQL_PREFIX."_bonus WHERE id=%s",
159                 array(bigintval($_GET['bid'])), __FILE__, __LINE__);
160
161         // Delete mail only once
162         if (SQL_NUMROWS($result) == 1) {
163                 // Load data
164                 list ($id, $subject, $url, $timestamp, $sent) = SQL_FETCHROW($result);
165
166                 // Reset sent mails for recipient(s)
167                 REDUCT_RECIPIENT_RECEIVED_MAILS ("bonus_id", $_GET['bid'], $sent);
168
169                 // Delete bonus mail entirely from database
170                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_bonus WHERE id=%s LIMIT 1",
171                         array(bigintval($_GET['bid'])), __FILE__, __LINE__);
172                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%s",
173                         array(bigintval($_GET['bid'])), __FILE__, __LINE__);
174
175                 // Prepare data for the template
176                 define('__ID'     , $id);
177                 define('__SUBJECT', $subject);
178                 define('__URL'    , DEREFERER($url));
179                 define('__ORDERED', MAKE_DATETIME($timestamp, "0"));
180
181                 // Load template
182                 LOAD_TEMPLATE("admin_del_email_bonus");
183         } else {
184                 // Mail already deleted!
185                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BONUS_MAIL_ALREADY_DELETED);
186         }
187
188         // Free result
189         SQL_FREERESULT($result);
190 } elseif ((!empty($_GET['nid'])) && (GET_EXT_VERSION("bonus") >= "0.8.7")) {
191         // Load data from bonus mail
192         $result = SQL_QUERY_ESC("SELECT id, subject, url, timestamp FROM "._MYSQL_PREFIX."_bonus WHERE id=%s",
193          array(bigintval($_GET['nid'])), __FILE__, __LINE__);
194
195         // Delete mail only once
196         if (SQL_NUMROWS($result) == 1) {
197                 // Load data
198                 list ($id, $subject, $url, $timestamp) = SQL_FETCHROW($result);
199                 SQL_FREERESULT($result);
200
201                 // Delete bonus mail entirely from database
202                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_bonus WHERE id=%s LIMIT 1",
203                  array(bigintval($_GET['nid'])), __FILE__, __LINE__);
204                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%s",
205                  array(bigintval($_GET['nid'])), __FILE__, __LINE__);
206
207                 // Prepare data for the template
208                 define('__ID'     , $id);
209                 define('__SUBJECT', $subject);
210                 define('__URL'    , DEREFERER($url));
211                 define('__ORDERED', MAKE_DATETIME($timestamp, "0"));
212
213                 // Load template
214                 LOAD_TEMPLATE("admin_del_email_notify");
215         } else {
216                 // Mail already deleted!
217                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NOTIFY_MAIL_ALREADY_DELETED);
218         }
219 } else {
220         // No mail orders fond
221         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_WRONG_CALL);
222 }
223
224 //
225 ?>