2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 - 2009 by Roland Haeder *
19 * Copyright (c) 2009, 2010 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addMenuDescription('admin', __FILE__);
46 // Init counter for deleted mails
49 if (isGetRequestParameterSet('mid')) {
51 $result = SQL_QUERY_ESC("SELECT `id`, `sender`, `subject`, `url`, `timestamp`, `cat_id`, `payment_id` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
52 array(bigintval(getRequestParameter('mid'))), __FILE__, __LINE__);
54 // Delete mail only once
55 if (SQL_NUMROWS($result) == 1) {
57 $content = SQL_FETCHARRAY($result);
59 // Get points we shall pay back per mail
60 // @TODO Unused: $price = getPaymentPoints($content['payment_id'], 'price');
61 // @TODO Unused: cat_id, payment_id
63 // Prepare data for the template
64 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
67 loadTemplate('admin_del_email_normal', false, $content);
69 // Load email template and send the email away
70 $message_user = loadEmailTemplate('order-deleted', $content, $sender);
71 sendEmail($sender, '{--MEMBER_ORDER_DELETED--}', $message_user);
73 // Fetch right stats_id from pool
74 $result_pool = SQL_QUERY_ESC("SELECT
77 `{?_MYSQL_PREFIX?}_user_stats` AS s
79 `{?_MYSQL_PREFIX?}_pool` AS p
85 array(bigintval(getRequestParameter('mid'))), __FILE__, __LINE__);
86 if (SQL_NUMROWS($result_pool) == 1) {
88 list($stats_id) = SQL_FETCHROW($result_pool);
91 $links = countSumTotalData($stats_id, 'user_links', 'userid', 'stats_id', true);
93 // Reset sent mails for recipient(s)
94 reduceRecipientReceivedMails('stats_id', getRequestParameter('mid'), $links);
96 // Calc total points and pay them back
97 $totalPoints = $links * $price;
99 // Shall we pay the points back to the user?
100 if ($totalPoints == 0) {
101 // No points repayed!
102 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_POINTS_REPAYED--}');
103 } elseif (getConfig('repay_deleted_mails') != 'SHRED') {
104 //* DEBUG: */ debugOutput($stats_id.':'.$totalPoints.'/'.$links.'/'.$price);
105 // Shall we payback to user or jackpot?
106 if (getConfig('repay_deleted_mails') == 'JACKPOT') {
112 //* DEBUG: */ debugOutput('PAYBACK:'.$sender);
113 addPointsThroughReferalSystem('mail_deleted', $sender, $totalPoints, true, 0, false,'direct');
116 if (getConfig('repay_deleted_mails') == 'REPAY') {
118 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_POINTS_REPAYED',
119 translateComma($totalPoints)
123 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_POINTS_TO_JACKPOT',
124 translateComma($totalPoints)
129 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_POINTS_SHREDDED', translateComma($totalPoints)));
132 // Remove links from DB
133 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
134 array(bigintval($stats_id)), __FILE__, __LINE__);
135 $cnt += SQL_AFFECTEDROWS();
137 // Load template for link
138 loadTemplate('admin_settings_saved', false, '<a href="{%url=modules.php?module=admin&what=del_email&pid=' . bigintval(getRequestParameter('mid')) . '%}">{--ADMIN_REMOVE_STATS_ENTRY--}</a>');
142 SQL_FREERESULT($result_pool);
144 // Delete mail from queue
145 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
146 array(bigintval(getRequestParameter('mid'))), __FILE__, __LINE__);
147 $cnt += SQL_AFFECTEDROWS();
149 // Output link for manually removing stats entry
150 outputHtml(getMaskedMessage('ADMIN_DELETED_MAILS_COUNT', $cnt));
152 // Mail already deleted!
153 loadTemplate('admin_settings_saved', false, '{--ADMIN_NORMAL_MAIL_ALREADY_DELETED--}');
157 SQL_FREERESULT($result);
158 } elseif (isGetRequestParameterSet('pid')) {
159 // Remove stats entries
160 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
161 array(bigintval(getRequestParameter('pid'))), __FILE__, __LINE__);
164 loadTemplate('admin_settings_saved', false, '{--ADMIN_USER_STATS_REMOVED--}');
165 } elseif ((isGetRequestParameterSet('bid')) && (isExtensionActive('bonus'))) {
166 // Load data from bonus mail
167 $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s",
168 array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
170 // Delete mail only once
171 if (SQL_NUMROWS($result) == 1) {
173 $content = SQL_FETCHARRAY($result);
175 // Reset sent mails for recipient(s)
176 reduceRecipientReceivedMails('bonus_id', getRequestParameter('bid'), $content['mails_sent']);
178 // Init counter for deleted mails
181 // Delete bonus mail entirely from database
182 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
183 array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
184 $cnt += SQL_AFFECTEDROWS();
185 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
186 array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
187 $cnt += SQL_AFFECTEDROWS();
189 // Prepare data for the template
190 $content['url'] = generateDerefererUrl($content['url']);
191 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
192 $content['cnt'] = $cnt;
195 loadTemplate('admin_del_email_bonus', false, $content);
197 // Mail already deleted!
198 loadTemplate('admin_settings_saved', false, '{--ADMIN_BONUS_MAIL_ALREADY_DELETED--}');
202 SQL_FREERESULT($result);
203 } elseif ((isGetRequestParameterSet('nid')) && (isExtensionInstalledAndNewer('bonus', '0.8.7'))) {
204 // Load data from bonus mail
205 $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s",
206 array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
208 // Delete mail only once
209 if (SQL_NUMROWS($result) == 1) {
211 $content = SQL_FETCHARRAY($result);
213 // Init counter for deleted mails
216 // Delete bonus mail entirely from database
217 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
218 array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
219 $cnt += SQL_AFFECTEDROWS();
220 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
221 array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
222 $cnt += SQL_AFFECTEDROWS();
224 // Prepare data for the template
225 $content['url'] = generateDerefererUrl($content['url']);
226 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
227 $content['cnt'] = $cnt;
230 loadTemplate('admin_del_email_notify', false, $content);
232 // Mail already deleted!
233 loadTemplate('admin_settings_saved', false, '{--ADMIN_NOTIFY_MAIL_ALREADY_DELETED--}');
237 SQL_FREERESULT($result);
239 // No mail orders fond
240 loadTemplate('admin_settings_saved', false, '{--ADMIN_WRONG_CALL--}');