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`, `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 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 $content['sender'] = generateUserProfileLink($sender);
66 $content['subject'] = $subject;
67 $content['url'] = generateDerefererUrl($url);
68 $content['url_raw'] = $url;
69 $content['timestamp'] = generateDateTime($timestamp, 0);
72 loadTemplate('admin_del_email_normal', false, $content);
74 // Load email template and send the email away
75 $message_user = loadEmailTemplate('order-deleted', $content, $sender);
76 sendEmail($sender, getMessage('MEMBER_ORDER_DELETED'), $message_user);
78 // Fetch right stats_id from pool
79 $result_pool = SQL_QUERY_ESC("SELECT
82 `{?_MYSQL_PREFIX?}_user_stats` AS s
84 `{?_MYSQL_PREFIX?}_pool` AS p
90 array(bigintval(getRequestParameter('mid'))), __FILE__, __LINE__);
91 if (SQL_NUMROWS($result_pool) == 1) {
93 list($stats_id) = SQL_FETCHROW($result_pool);
96 $links = countSumTotalData($stats_id, 'user_links', 'userid', 'stats_id', true);
98 // Reset sent mails for recipient(s)
99 reduceRecipientReceivedMails('stats_id', getRequestParameter('mid'), $links);
101 // Calc total points and pay them back
102 $totalPoints = $links * $price;
104 // Shall we pay the points back to the user?
105 if ($totalPoints == 0) {
106 // No points repayed!
107 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_POINTS_REPAYED'));
108 } elseif (getConfig('repay_deleted_mails') != 'SHRED') {
109 //* DEBUG: */ debugOutput($stats_id.':'.$totalPoints.'/'.$links.'/'.$price);
110 // Shall we payback to user or jackpot?
111 if (getConfig('repay_deleted_mails') == 'JACKPOT') {
117 //* DEBUG: */ debugOutput('PAYBACK:'.$sender);
118 addPointsThroughReferalSystem('mail_deleted', $sender, $totalPoints, true, 0, false,'direct');
121 if (getConfig('repay_deleted_mails') == 'REPAY') {
123 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_POINTS_REPAYED',
124 translateComma($totalPoints)
128 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_POINTS_TO_JACKPOT',
129 translateComma($totalPoints)
134 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_POINTS_SHREDDED', translateComma($totalPoints)));
137 // Remove links from DB
138 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
139 array(bigintval($stats_id)), __FILE__, __LINE__);
140 $cnt += SQL_AFFECTEDROWS();
142 // Load template for link
143 loadTemplate('admin_settings_saved', false, '<a href="{%url=modules.php?module=admin&what=del_email&pid=' . bigintval(getRequestParameter('mid')) . '%}">{--ADMIN_REMOVE_STATS_ENTRY--}</a>');
147 SQL_FREERESULT($result_pool);
149 // Delete mail from queue
150 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
151 array(bigintval(getRequestParameter('mid'))), __FILE__, __LINE__);
152 $cnt += SQL_AFFECTEDROWS();
154 // Output link for manually removing stats entry
155 outputHtml(getMaskedMessage('ADMIN_DELETED_MAILS_COUNT', $cnt));
157 // Mail already deleted!
158 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NORMAL_MAIL_ALREADY_DELETED'));
160 } elseif (isGetRequestParameterSet('pid')) {
161 // Remove stats entries
162 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
163 array(bigintval(getRequestParameter('pid'))), __FILE__, __LINE__);
166 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_USER_STATS_REMOVED'));
167 } elseif ((isGetRequestParameterSet('bid')) && (isExtensionActive('bonus'))) {
168 // Load data from bonus mail
169 $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s",
170 array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
172 // Delete mail only once
173 if (SQL_NUMROWS($result) == 1) {
175 $content = SQL_FETCHARRAY($result);
177 // Reset sent mails for recipient(s)
178 reduceRecipientReceivedMails('bonus_id', getRequestParameter('bid'), $content['mails_sent']);
180 // Init counter for deleted mails
183 // Delete bonus mail entirely from database
184 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
185 array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
186 $cnt += SQL_AFFECTEDROWS();
187 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
188 array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
189 $cnt += SQL_AFFECTEDROWS();
191 // Prepare data for the template
192 $content['url'] = generateDerefererUrl($content['url']);
193 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
194 $content['cnt'] = $cnt;
197 loadTemplate('admin_del_email_bonus', false, $content);
199 // Mail already deleted!
200 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_BONUS_MAIL_ALREADY_DELETED'));
204 SQL_FREERESULT($result);
205 } elseif ((isGetRequestParameterSet('nid')) && (isExtensionInstalledAndNewer('bonus', '0.8.7'))) {
206 // Load data from bonus mail
207 $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s",
208 array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
210 // Delete mail only once
211 if (SQL_NUMROWS($result) == 1) {
213 $content = SQL_FETCHARRAY($result);
215 // Init counter for deleted mails
218 // Delete bonus mail entirely from database
219 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
220 array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
221 $cnt += SQL_AFFECTEDROWS();
222 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
223 array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
224 $cnt += SQL_AFFECTEDROWS();
226 // Prepare data for the template
227 $content['url'] = generateDerefererUrl($content['url']);
228 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
229 $content['cnt'] = $cnt;
232 loadTemplate('admin_del_email_notify', false, $content);
234 // Mail already deleted!
235 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NOTIFY_MAIL_ALREADY_DELETED'));
239 SQL_FREERESULT($result);
241 // No mail orders fond
242 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));