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 - 2013 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 // @TODO Unused: cat_id
52 $content = getPoolDataFromId(getRequestElement('id'));
54 // Delete mail only once
55 if (count($content) > 0) {
56 // Prepare data for the template
57 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
60 loadTemplate('admin_delete_email_normal', FALSE, $content);
62 // Load email template and send the email away
63 $message_user = loadEmailTemplate('member_order_deleted', $content, $content['sender']);
64 sendEmail($content['sender'], '{--MEMBER_ORDER_DELETED--}', $message_user);
66 // Fetch right stats_id from pool
67 $result_pool = sqlQueryEscaped("SELECT
70 `{?_MYSQL_PREFIX?}_user_stats` AS `s`
72 `{?_MYSQL_PREFIX?}_pool` AS `p`
74 `s`.`pool_id`=`p`.`id`
78 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
79 if (sqlNumRows($result_pool) == 1) {
81 list($stats_id) = sqlFetchRow($result_pool);
84 $links = countSumTotalData($stats_id, 'user_links', 'userid', 'stats_id', TRUE);
86 // Reset sent mails for recipient(s)
87 reduceRecipientReceivedMails('stats_id', getRequestElement('id'), $links);
89 // Calc total points and pay them back
90 $totalPoints = $links * $content['price'];
92 // Shall we pay the points back to the user?
93 if ($totalPoints == 0) {
95 displayMessage('{--ADMIN_NO_POINTS_REPAYED--}');
96 } elseif (getConfig('repay_deleted_mails') != 'SHRED') {
97 //* DEBUG: */ debugOutput($stats_id . ':' . $totalPoints . '/' . $links . '/' . $content['price']);
98 // Shall we payback to user or jackpot?
99 if (getConfig('repay_deleted_mails') == 'JACKPOT') {
101 $content['sender'] = '0';
105 initReferralSystem();
106 addPointsThroughReferralSystem('mail_deleted', $content['sender'], $totalPoints);
109 if (getConfig('repay_deleted_mails') == 'REPAY') {
111 displayMessage('{%message,ADMIN_POINTS_REPAYED=' . $totalPoints . '%}');
114 displayMessage('{%message,ADMIN_POINTS_TO_JACKPOT=' . $totalPoints . '%}');
118 displayMessage('{%message,ADMIN_POINTS_SHREDDED=' . $totalPoints . '%}');
121 // Remove links from DB
122 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
123 array(bigintval($stats_id)), __FILE__, __LINE__);
124 $count += sqlAffectedRows();
126 // Load template for link
127 displayMessage('<a href="{%url=modules.php?module=admin&what=del_email&pid=' . bigintval(getRequestElement('id')) . '%}">{--ADMIN_REMOVE_STATS_ENTRY--}</a>');
131 sqlFreeResult($result_pool);
133 // Delete mail from queue
134 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
135 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
136 $count += sqlAffectedRows();
138 // Output link for manually removing stats entry
139 outputHtml('{%message,ADMIN_DELETED_MAILS_COUNT=' . $count . '%}');
141 // Mail already deleted!
142 displayMessage('{--ADMIN_NORMAL_MAIL_ALREADY_DELETED--}');
146 sqlFreeResult($result);
147 } elseif (isGetRequestElementSet('pid')) {
148 // Remove stats entries
149 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
150 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
153 displayMessage('{--ADMIN_USER_STATS_REMOVED--}');
154 } elseif (((isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'bonus')) && (isExtensionActive('bonus'))) {
155 // Load data from bonus mail
156 $result = sqlQueryEscaped("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
157 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
159 // Delete mail only once
160 if (sqlNumRows($result) == 1) {
162 $content = sqlFetchArray($result);
164 // Reset sent mails for recipient(s)
165 reduceRecipientReceivedMails('bonus_id', getRequestElement('id'), $content['mails_sent']);
167 // Init counter for deleted mails
170 // Delete bonus mail entirely from database
171 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
172 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
173 $count += sqlAffectedRows();
174 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
175 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
176 $count += sqlAffectedRows();
178 // Prepare data for the template
179 $content['timestamp'] = generateDateTime($content['timestamp'], '0');
180 $content['count'] = $count;
183 loadTemplate('admin_delete_email_bonus', FALSE, $content);
185 // Mail already deleted!
186 displayMessage('{--ADMIN_BONUS_MAIL_ALREADY_DELETED--}');
188 } elseif ((isGetRequestElementSet('nid')) && (isExtensionInstalledAndNewer('bonus', '0.8.7'))) {
189 // Load data from bonus mail
190 $result = sqlQueryEscaped("SELECT `id`, `subject`, `url`, `timestamp` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
191 array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
193 // Delete mail only once
194 if (sqlNumRows($result) == 1) {
196 $content = sqlFetchArray($result);
198 // Init counter for deleted mails
201 // Delete bonus mail entirely from database
202 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
203 array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
204 $count += sqlAffectedRows();
205 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
206 array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
207 $count += sqlAffectedRows();
209 // Prepare data for the template
210 $content['timestamp'] = generateDateTime($content['timestamp'], '0');
211 $content['count'] = $count;
214 loadTemplate('admin_delete_email_notify', FALSE, $content);
216 // Mail already deleted!
217 displayMessage('{--ADMIN_NOTIFY_MAIL_ALREADY_DELETED--}');
221 sqlFreeResult($result);
223 // No mail orders fond
224 displayMessage('{--ADMIN_WRONG_CALL--}');