2 /************************************************************************
3 * MXChange v0.2.1 Start: 02/12/2004 *
4 * ================ Last change: 02/27/2004 *
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 * -------------------------------------------------------------------- *
14 * Module by Robert Niedziela, Megacomputing *
15 * web : http://mc-p.mcserver.de *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2008 by Roland Haeder *
19 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
35 ************************************************************************/
37 // Some security stuff...
38 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
39 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
43 // Add description as navigation point
44 ADD_DESCR('admin', __FILE__);
46 // Init counter for deleted mails
49 if (REQUEST_ISSET_GET('mid')) {
51 $result = SQL_QUERY_ESC("SELECT `id`, `sender`, `subject`, `url`, `timestamp`, `payment_id` FROM `{!_MYSQL_PREFIX!}_pool` WHERE `id`=%s LIMIT 1",
52 array(bigintval(REQUEST_GET('mid'))), __FILE__, __LINE__);
54 // Delete mail only once
55 if (SQL_NUMROWS($result) == 1) {
57 list ($id, $sender, $subject, $url, $timestamp, $payId) = SQL_FETCHROW($result);
58 SQL_FREERESULT($result);
60 // Get points we shall pay back per mail
61 $price = getPaymentPoints($payId, 'price');
63 // Prepare data for the template
65 define('__SENDER' , generateUserProfileLink($sender));
66 define('__SUBJECT', $subject);
67 define('__URL' , DEREFERER($url));
68 define('__ORDERED', generateDateTime($timestamp, '0'));
71 LOAD_TEMPLATE("admin_del_email_normal");
73 // Transfer data to data array
74 $DATA = array('url' => $url, 'subject' => $subject);
76 // Load email template and send the email away
77 $message_user = LOAD_EMAIL_TEMPLATE('order-deleted', array(), $sender);
78 sendEmail($sender, getMessage('MEMBER_ORDER_DELETED'), $message_user);
80 // Fetch right stats_id from pool
81 $result_pool = SQL_QUERY_ESC("SELECT
84 `{!_MYSQL_PREFIX!}_user_stats` AS s
86 `{!_MYSQL_PREFIX!}_pool` AS p
92 array(bigintval(REQUEST_GET('mid'))), __FILE__, __LINE__);
93 if (SQL_NUMROWS($result_pool) == 1) {
95 list($stats_id) = SQL_FETCHROW($result_pool);
98 $links = GET_TOTAL_DATA($stats_id, 'user_links', 'userid', 'stats_id', true);
100 // Reset sent mails for recipient(s)
101 reduceRecipientReceivedMails('stats_id', REQUEST_GET('mid'), $links);
103 // Calc total points and pay them back
104 $totalPoints = $links * $price;
106 // Shall we pay the points back to the user?
107 if (getConfig('repay_deleted_mails') != 'SHRED') {
108 //* DEBUG: */ echo $stats_id.':'.$totalPoints.'/'.$links.'/'.$price."<br />\n";
109 if ($totalPoints > 0) {
110 // Shall we payback to user or jackpot?
111 if (getConfig('repay_deleted_mails') == 'JACKPOT') {
117 //* DEBUG: */ echo "PAYBACK:".$sender."<br />\n";
118 ADD_POINTS_REFSYSTEM('mail_deleted', $sender, $totalPoints, true, '0', false,'direct');
121 if (getConfig('repay_deleted_mails') == 'REPAY') {
123 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_POINTS_REPAYED'),
124 translateComma($totalPoints)
128 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_POINTS_TO_JACKPOT'),
129 translateComma($totalPoints)
133 // No points repayed!
134 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_POINTS_REPAYED'));
138 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_POINTS_SHREDDED'), $totalPoints));
141 // Remove links from DB
142 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_links` WHERE `stats_id`=%s",
143 array(bigintval($stats_id)), __FILE__, __LINE__);
144 $cnt += SQL_AFFECTEDROWS();
146 // Load template for link
147 LOAD_TEMPLATE('admin_settings_saved', false, "<a href=\"{!URL!}/modules.php?module=admin&what=del_email&pid=".bigintval(REQUEST_GET('mid'))."\">".ADMIN_REMOVE_STATS_ENTRY."</a>");
151 SQL_FREERESULT($result_pool);
153 // Delete mail from queue
154 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_pool` WHERE `id`=%s LIMIT 1",
155 array(bigintval(REQUEST_GET('mid'))), __FILE__, __LINE__);
156 $cnt += SQL_AFFECTEDROWS();
158 // Output link for manually removing stats entry
159 OUTPUT_HTML(sprintf(ADMIN_DELETED_MAILS_COUNT, $cnt));
161 // Mail already deleted!
162 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NORMAL_MAIL_ALREADY_DELETED'));
164 } elseif (REQUEST_ISSET_GET('pid')) {
165 // Remove stats entries
166 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE `pool_id`=%s LIMIT 1",
167 array(bigintval(REQUEST_GET('pid'))), __FILE__, __LINE__);
170 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_USER_STATS_REMOVED'));
171 } elseif ((REQUEST_ISSET_GET('bid')) && (EXT_IS_ACTIVE('bonus'))) {
172 // Load data from bonus mail
173 $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{!_MYSQL_PREFIX!}_bonus` WHERE `id`=%s",
174 array(bigintval(REQUEST_GET('bid'))), __FILE__, __LINE__);
176 // Delete mail only once
177 if (SQL_NUMROWS($result) == 1) {
179 list($id, $subject, $url, $timestamp, $sent) = SQL_FETCHROW($result);
181 // Reset sent mails for recipient(s)
182 reduceRecipientReceivedMails('bonus_id', REQUEST_GET('bid'), $sent);
184 // Init counter for deleted mails
187 // Delete bonus mail entirely from database
188 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_bonus` WHERE `id`=%s LIMIT 1",
189 array(bigintval(REQUEST_GET('bid'))), __FILE__, __LINE__);
190 $cnt += SQL_AFFECTEDROWS();
191 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_links` WHERE `bonus_id`=%s",
192 array(bigintval(REQUEST_GET('bid'))), __FILE__, __LINE__);
193 $cnt += SQL_AFFECTEDROWS();
195 // Prepare data for the template
196 define('__ID' , $id);
197 define('__SUBJECT', $subject);
198 define('__URL' , DEREFERER($url));
199 define('__ORDERED', generateDateTime($timestamp, '0'));
200 define('__CNT' , $cnt);
203 LOAD_TEMPLATE('admin_del_email_bonus');
205 // Mail already deleted!
206 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_BONUS_MAIL_ALREADY_DELETED'));
210 SQL_FREERESULT($result);
211 } elseif ((REQUEST_ISSET_GET('nid')) && (GET_EXT_VERSION('bonus') >= '0.8.7')) {
212 // Load data from bonus mail
213 $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp` FROM `{!_MYSQL_PREFIX!}_bonus` WHERE `id`=%s",
214 array(bigintval(REQUEST_GET('nid'))), __FILE__, __LINE__);
216 // Delete mail only once
217 if (SQL_NUMROWS($result) == 1) {
219 list ($id, $subject, $url, $timestamp) = SQL_FETCHROW($result);
220 SQL_FREERESULT($result);
222 // Init counter for deleted mails
225 // Delete bonus mail entirely from database
226 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_bonus` WHERE `id`=%s LIMIT 1",
227 array(bigintval(REQUEST_GET('nid'))), __FILE__, __LINE__);
228 $cnt += SQL_AFFECTEDROWS();
229 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_links` WHERE `bonus_id`=%s",
230 array(bigintval(REQUEST_GET('nid'))), __FILE__, __LINE__);
231 $cnt += SQL_AFFECTEDROWS();
233 // Prepare data for the template
234 define('__ID' , $id);
235 define('__SUBJECT', $subject);
236 define('__URL' , DEREFERER($url));
237 define('__ORDERED', generateDateTime($timestamp, '0'));
238 define('__CNT' , $cnt);
241 LOAD_TEMPLATE('admin_del_email_notify');
243 // Mail already deleted!
244 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NOTIFY_MAIL_ALREADY_DELETED'));
247 // No mail orders fond
248 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));