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