]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-del_email.php
Rewrites from to , fixes
[mailer.git] / inc / modules / admin / what-del_email.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 02/12/2004 *
4  * ================                             Last change: 02/27/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  *                                                                      *
14  *  Module by Robert Niedziela, Megacomputing                           *
15  *          web : http://mc-p.mcserver.de                               *
16  *                                                                      *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * For more information visit: http://www.mxchange.org                  *
20  *                                                                      *
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.                                  *
25  *                                                                      *
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.                         *
30  *                                                                      *
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,               *
34  * MA  02110-1301  USA                                                  *
35  ************************************************************************/
36
37 // Some security stuff...
38 if ((!defined('__SECURITY')) || (!isAdmin())) {
39         die();
40 }
41
42 // Add description as navigation point
43 addMenuDescription('admin', __FILE__);
44
45 // Init counter for deleted mails
46 $cnt = 0;
47
48 if (isGetRequestElementSet('mid')) {
49         // Load email data
50         $result = SQL_QUERY_ESC("SELECT `id`, `sender`, `subject`, `url`, `timestamp`, `payment_id` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
51                 array(bigintval(getRequestElement('mid'))), __FILE__, __LINE__);
52
53         // Delete mail only once
54         if (SQL_NUMROWS($result) == 1) {
55                 // Load data
56                 list ($id, $sender, $subject, $url, $timestamp, $payId) = SQL_FETCHROW($result);
57                 SQL_FREERESULT($result);
58
59                 // Get points we shall pay back per mail
60                 $price = getPaymentPoints($payId, 'price');
61
62                 // Prepare data for the template
63                 $content['id']      = $id;
64                 $content['sender']  = generateUserProfileLink($sender);
65                 $content['subject'] = $subject;
66                 $content['url']     = generateDerefererUrl($url);
67                 $content['url_raw'] = $url;
68                 $content['ordered'] = generateDateTime($timestamp, '0');
69
70                 // Load template
71                 loadTemplate('admin_del_email_normal', false, $content);
72
73                 // Load email template and send the email away
74                 $message_user = loadEmailTemplate('order-deleted', $content, $sender);
75                 sendEmail($sender, getMessage('MEMBER_ORDER_DELETED'), $message_user);
76
77                 // Fetch right stats_id from pool
78                 $result_pool = SQL_QUERY_ESC("SELECT
79         s.id
80 FROM
81         `{?_MYSQL_PREFIX?}_user_stats` AS s
82 LEFT JOIN
83         `{?_MYSQL_PREFIX?}_pool` AS p
84 ON
85         s.pool_id=p.id
86 WHERE
87         s.`pool_id`=%s
88 LIMIT 1",
89                         array(bigintval(getRequestElement('mid'))), __FILE__, __LINE__);
90                 if (SQL_NUMROWS($result_pool) == 1) {
91                         // Fetch stats id
92                         list($stats_id) = SQL_FETCHROW($result_pool);
93
94                         // Get all user links
95                         $links = countSumTotalData($stats_id, 'user_links', 'userid', 'stats_id', true);
96
97                         // Reset sent mails for recipient(s)
98                         reduceRecipientReceivedMails('stats_id', getRequestElement('mid'), $links);
99
100                         // Calc total points and pay them back
101                         $totalPoints = $links * $price;
102
103                         // Shall we pay the points back to the user?
104                         if (getConfig('repay_deleted_mails') != 'SHRED') {
105                                 //* DEBUG: */ outputHtml($stats_id.':'.$totalPoints.'/'.$links.'/'.$price."<br />");
106                                 if ($totalPoints > 0) {
107                                         // Shall we payback to user or jackpot?
108                                         if (getConfig('repay_deleted_mails') == 'JACKPOT') {
109                                                 // Set jackpot
110                                                 $sender = 0;
111                                         } // END - if
112
113                                         // Pay back points
114                                         //* DEBUG: */ outputHtml("PAYBACK:".$sender."<br />");
115                                         addPointsThroughReferalSystem('mail_deleted', $sender, $totalPoints, true, '0', false,'direct');
116
117                                         // Output message
118                                         if (getConfig('repay_deleted_mails') == 'REPAY') {
119                                                 // Repayed
120                                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_POINTS_REPAYED'),
121                                                         translateComma($totalPoints)
122                                                 ));
123                                         } else {
124                                                 // To jackpot
125                                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_POINTS_TO_JACKPOT'),
126                                                         translateComma($totalPoints)
127                                                 ));
128                                         }
129                                 } else {
130                                         // No points repayed!
131                                         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_POINTS_REPAYED'));
132                                 }
133                         } else {
134                                 // Points shredded!
135                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_POINTS_SHREDDED'), $totalPoints));
136                         }
137
138                         // Remove links from DB
139                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
140                         array(bigintval($stats_id)), __FILE__, __LINE__);
141                         $cnt += SQL_AFFECTEDROWS();
142
143                         // Load template for link
144                         loadTemplate('admin_settings_saved', false, "<a href=\"{?URL?}/modules.php?module=admin&amp;what=del_email&amp;pid=".bigintval(getRequestElement('mid'))."\">{--ADMIN_REMOVE_STATS_ENTRY--}</a>");
145                 } // END - if
146
147                 // Free the result
148                 SQL_FREERESULT($result_pool);
149
150                 // Delete mail from queue
151                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
152                         array(bigintval(getRequestElement('mid'))), __FILE__, __LINE__);
153                 $cnt += SQL_AFFECTEDROWS();
154
155                 // Output link for manually removing stats entry
156                 outputHtml(sprintf(getMessage('ADMIN_DELETED_MAILS_COUNT'), $cnt));
157         } else {
158                 // Mail already deleted!
159                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NORMAL_MAIL_ALREADY_DELETED'));
160         }
161 } elseif (isGetRequestElementSet('pid')) {
162         // Remove stats entries
163         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
164         array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
165
166         // Output message
167         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_USER_STATS_REMOVED'));
168 } elseif ((isGetRequestElementSet('bid')) && (isExtensionActive('bonus'))) {
169         // Load data from bonus mail
170         $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s",
171                 array(bigintval(getRequestElement('bid'))), __FILE__, __LINE__);
172
173         // Delete mail only once
174         if (SQL_NUMROWS($result) == 1) {
175                 // Load data
176                 list($id, $subject, $url, $timestamp, $sent) = SQL_FETCHROW($result);
177
178                 // Reset sent mails for recipient(s)
179                 reduceRecipientReceivedMails('bonus_id', getRequestElement('bid'), $sent);
180
181                 // Init counter for deleted mails
182                 $cnt = 0;
183
184                 // Delete bonus mail entirely from database
185                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
186                         array(bigintval(getRequestElement('bid'))), __FILE__, __LINE__);
187                 $cnt += SQL_AFFECTEDROWS();
188                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
189                         array(bigintval(getRequestElement('bid'))), __FILE__, __LINE__);
190                 $cnt += SQL_AFFECTEDROWS();
191
192                 // Prepare data for the template
193                 $content['id']      = $id;
194                 $content['subject'] = $subject;
195                 $content['url']     = generateDerefererUrl($url);
196                 $content['ordered'] = generateDateTime($timestamp, '0');
197                 $content['cnt']     = $cnt;
198
199                 // Load template
200                 loadTemplate('admin_del_email_bonus', false, $content);
201         } else {
202                 // Mail already deleted!
203                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_BONUS_MAIL_ALREADY_DELETED'));
204         }
205
206         // Free result
207         SQL_FREERESULT($result);
208 } elseif ((isGetRequestElementSet('nid')) && (getExtensionVersion('bonus') >= '0.8.7')) {
209         // Load data from bonus mail
210         $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s",
211                 array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
212
213         // Delete mail only once
214         if (SQL_NUMROWS($result) == 1) {
215                 // Load data
216                 list ($id, $subject, $url, $timestamp) = SQL_FETCHROW($result);
217
218                 // Init counter for deleted mails
219                 $cnt = 0;
220
221                 // Delete bonus mail entirely from database
222                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
223                         array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
224                 $cnt += SQL_AFFECTEDROWS();
225                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
226                         array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
227                 $cnt += SQL_AFFECTEDROWS();
228
229                 // Prepare data for the template
230                 $content['id']      = $id;
231                 $content['subject'] = $subject;
232                 $content['url']     = generateDerefererUrl($url);
233                 $content['ordered'] = generateDateTime($timestamp, '0');
234                 $content['cnt']     = $cnt;
235
236                 // Load template
237                 loadTemplate('admin_del_email_notify', false, $content);
238         } else {
239                 // Mail already deleted!
240                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NOTIFY_MAIL_ALREADY_DELETED'));
241         }
242
243         // Free result
244         SQL_FREERESULT($result);
245 } else {
246         // No mail orders fond
247         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
248 }
249
250 //
251 ?>