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- / Mitglied-Mail loeschen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://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 addYouAreHereLink('admin', __FILE__);
46 // Init counter for deleted mails
49 if ((isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'normal')) {
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(getRequestElement('id'))), __FILE__, __LINE__);
54 // Delete mail only once
55 if (SQL_NUMROWS($result) == 1) {
57 // @TODO Unused: cat_id
58 $content = SQL_FETCHARRAY($result);
60 // Prepare data for the template
61 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
64 loadTemplate('admin_delete_email_normal', FALSE, $content);
66 // Load email template and send the email away
67 $message_user = loadEmailTemplate('member_order_deleted', $content, $content['sender']);
68 sendEmail($content['sender'], '{--MEMBER_ORDER_DELETED--}', $message_user);
70 // Fetch right stats_id from pool
71 $result_pool = SQL_QUERY_ESC("SELECT
74 `{?_MYSQL_PREFIX?}_user_stats` AS `s`
76 `{?_MYSQL_PREFIX?}_pool` AS `p`
78 `s`.`pool_id`=`p`.`id`
82 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
83 if (SQL_NUMROWS($result_pool) == 1) {
85 list($stats_id) = SQL_FETCHROW($result_pool);
88 $links = countSumTotalData($stats_id, 'user_links', 'userid', 'stats_id', TRUE);
90 // Reset sent mails for recipient(s)
91 reduceRecipientReceivedMails('stats_id', getRequestElement('id'), $links);
93 // Calc total points and pay them back
94 $totalPoints = $links * $content['price'];
96 // Shall we pay the points back to the user?
97 if ($totalPoints == 0) {
99 displayMessage('{--ADMIN_NO_POINTS_REPAYED--}');
100 } elseif (getConfig('repay_deleted_mails') != 'SHRED') {
101 //* DEBUG: */ debugOutput($stats_id . ':' . $totalPoints . '/' . $links . '/' . $content['price']);
102 // Shall we payback to user or jackpot?
103 if (getConfig('repay_deleted_mails') == 'JACKPOT') {
105 $content['sender'] = '0';
109 initReferralSystem();
110 addPointsThroughReferralSystem('mail_deleted', $content['sender'], $totalPoints);
113 if (getConfig('repay_deleted_mails') == 'REPAY') {
115 displayMessage('{%message,ADMIN_POINTS_REPAYED=' . $totalPoints . '%}');
118 displayMessage('{%message,ADMIN_POINTS_TO_JACKPOT=' . $totalPoints . '%}');
122 displayMessage('{%message,ADMIN_POINTS_SHREDDED=' . $totalPoints . '%}');
125 // Remove links from DB
126 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
127 array(bigintval($stats_id)), __FILE__, __LINE__);
128 $count += SQL_AFFECTEDROWS();
130 // Load template for link
131 displayMessage('<a href="{%url=modules.php?module=admin&what=del_email&pid=' . bigintval(getRequestElement('id')) . '%}">{--ADMIN_REMOVE_STATS_ENTRY--}</a>');
135 SQL_FREERESULT($result_pool);
137 // Delete mail from queue
138 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
139 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
140 $count += SQL_AFFECTEDROWS();
142 // Output link for manually removing stats entry
143 outputHtml('{%message,ADMIN_DELETED_MAILS_COUNT=' . $count . '%}');
145 // Mail already deleted!
146 displayMessage('{--ADMIN_NORMAL_MAIL_ALREADY_DELETED--}');
150 SQL_FREERESULT($result);
151 } elseif (isGetRequestElementSet('pid')) {
152 // Remove stats entries
153 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
154 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
157 displayMessage('{--ADMIN_USER_STATS_REMOVED--}');
158 } elseif (((isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'bonus')) && (isExtensionActive('bonus'))) {
159 // Load data from bonus mail
160 $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
161 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
163 // Delete mail only once
164 if (SQL_NUMROWS($result) == 1) {
166 $content = SQL_FETCHARRAY($result);
168 // Reset sent mails for recipient(s)
169 reduceRecipientReceivedMails('bonus_id', getRequestElement('id'), $content['mails_sent']);
171 // Init counter for deleted mails
174 // Delete bonus mail entirely from database
175 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
176 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
177 $count += SQL_AFFECTEDROWS();
178 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
179 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
180 $count += SQL_AFFECTEDROWS();
182 // Prepare data for the template
183 $content['timestamp'] = generateDateTime($content['timestamp'], '0');
184 $content['count'] = $count;
187 loadTemplate('admin_delete_email_bonus', FALSE, $content);
189 // Mail already deleted!
190 displayMessage('{--ADMIN_BONUS_MAIL_ALREADY_DELETED--}');
194 SQL_FREERESULT($result);
195 } elseif ((isGetRequestElementSet('nid')) && (isExtensionInstalledAndNewer('bonus', '0.8.7'))) {
196 // Load data from bonus mail
197 $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
198 array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
200 // Delete mail only once
201 if (SQL_NUMROWS($result) == 1) {
203 $content = SQL_FETCHARRAY($result);
205 // Init counter for deleted mails
208 // Delete bonus mail entirely from database
209 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
210 array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
211 $count += SQL_AFFECTEDROWS();
212 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
213 array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
214 $count += SQL_AFFECTEDROWS();
216 // Prepare data for the template
217 $content['timestamp'] = generateDateTime($content['timestamp'], '0');
218 $content['count'] = $count;
221 loadTemplate('admin_delete_email_notify', FALSE, $content);
223 // Mail already deleted!
224 displayMessage('{--ADMIN_NOTIFY_MAIL_ALREADY_DELETED--}');
228 SQL_FREERESULT($result);
230 // No mail orders fond
231 displayMessage('{--ADMIN_WRONG_CALL--}');