]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-del_email.php
Referal system refactured (and some parts fixed), wrapper function introduced:
[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- / Mitglied-Mail loeschen                  *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 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 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 // Init counter for deleted mails
47 $count = '0';
48
49 if (isGetRequestParameterSet('mid')) {
50         // Load email data
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(getRequestParameter('mid'))), __FILE__, __LINE__);
53
54         // Delete mail only once
55         if (SQL_NUMROWS($result) == 1) {
56                 // Load data
57                 $content = SQL_FETCHARRAY($result);
58
59                 // Get points we shall pay back per mail
60                 $content['price'] = getPaymentPoints($content['payment_id'], 'price');
61                 // @TODO Unused: cat_id, payment_id
62
63                 // Prepare data for the template
64                 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
65
66                 // Load template
67                 loadTemplate('admin_delete_email_normal', false, $content);
68
69                 // Load email template and send the email away
70                 $message_user = loadEmailTemplate('member_order_deleted', $content, $content['sender']);
71                 sendEmail($content['sender'], '{--MEMBER_ORDER_DELETED--}', $message_user);
72
73                 // Fetch right stats_id from pool
74                 $result_pool = SQL_QUERY_ESC("SELECT
75         s.id
76 FROM
77         `{?_MYSQL_PREFIX?}_user_stats` AS s
78 LEFT JOIN
79         `{?_MYSQL_PREFIX?}_pool` AS p
80 ON
81         s.pool_id=p.id
82 WHERE
83         s.`pool_id`=%s
84 LIMIT 1",
85                         array(bigintval(getRequestParameter('mid'))), __FILE__, __LINE__);
86                 if (SQL_NUMROWS($result_pool) == 1) {
87                         // Fetch stats id
88                         list($stats_id) = SQL_FETCHROW($result_pool);
89
90                         // Get all user links
91                         $links = countSumTotalData($stats_id, 'user_links', 'userid', 'stats_id', true);
92
93                         // Reset sent mails for recipient(s)
94                         reduceRecipientReceivedMails('stats_id', getRequestParameter('mid'), $links);
95
96                         // Calc total points and pay them back
97                         $totalPoints = $links * $content['price'];
98
99                         // Shall we pay the points back to the user?
100                         if ($totalPoints == 0) {
101                                 // No points repayed!
102                                 displayMessage('{--ADMIN_NO_POINTS_REPAYED--}');
103                         } elseif (getConfig('repay_deleted_mails') != 'SHRED') {
104                                 //* DEBUG: */ debugOutput($stats_id . ':' . $totalPoints . '/' . $links . '/' . $content['price']);
105                                 // Shall we payback to user or jackpot?
106                                 if (getConfig('repay_deleted_mails') == 'JACKPOT') {
107                                         // Set jackpot
108                                         $content['sender'] = '0';
109                                 } // END - if
110
111                                 // Pay back points
112                                 addPointsThroughReferalSystem('mail_deleted', $content['sender'], $totalPoints);
113
114                                 // Output message
115                                 if (getConfig('repay_deleted_mails') == 'REPAY') {
116                                         // Repayed
117                                         displayMessage('{%message,ADMIN_POINTS_REPAYED=' . $totalPoints . '%}');
118                                 } else {
119                                         // To jackpot
120                                         displayMessage('{%message,ADMIN_POINTS_TO_JACKPOT=' . $totalPoints . '%}');
121                                 }
122                         } else {
123                                 // Points shredded!
124                                 displayMessage('{%message,ADMIN_POINTS_SHREDDED=' . $totalPoints . '%}');
125                         }
126
127                         // Remove links from DB
128                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
129                                 array(bigintval($stats_id)), __FILE__, __LINE__);
130                         $count += SQL_AFFECTEDROWS();
131
132                         // Load template for link
133                         displayMessage('<a href="{%url=modules.php?module=admin&amp;what=del_email&amp;pid=' . bigintval(getRequestParameter('mid')) . '%}">{--ADMIN_REMOVE_STATS_ENTRY--}</a>');
134                 } // END - if
135
136                 // Free the result
137                 SQL_FREERESULT($result_pool);
138
139                 // Delete mail from queue
140                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
141                         array(bigintval(getRequestParameter('mid'))), __FILE__, __LINE__);
142                 $count += SQL_AFFECTEDROWS();
143
144                 // Output link for manually removing stats entry
145                 outputHtml('{%message,ADMIN_DELETED_MAILS_COUNT=' . $count . '%}');
146         } else {
147                 // Mail already deleted!
148                 displayMessage('{--ADMIN_NORMAL_MAIL_ALREADY_DELETED--}');
149         }
150
151         // Free result
152         SQL_FREERESULT($result);
153 } elseif (isGetRequestParameterSet('pid')) {
154         // Remove stats entries
155         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
156                 array(bigintval(getRequestParameter('pid'))), __FILE__, __LINE__);
157
158         // Output message
159         displayMessage('{--ADMIN_USER_STATS_REMOVED--}');
160 } elseif ((isGetRequestParameterSet('bid')) && (isExtensionActive('bonus'))) {
161         // Load data from bonus mail
162         $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
163                 array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
164
165         // Delete mail only once
166         if (SQL_NUMROWS($result) == 1) {
167                 // Load data
168                 $content = SQL_FETCHARRAY($result);
169
170                 // Reset sent mails for recipient(s)
171                 reduceRecipientReceivedMails('bonus_id', getRequestParameter('bid'), $content['mails_sent']);
172
173                 // Init counter for deleted mails
174                 $count = '0';
175
176                 // Delete bonus mail entirely from database
177                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
178                         array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
179                 $count += SQL_AFFECTEDROWS();
180                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
181                         array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
182                 $count += SQL_AFFECTEDROWS();
183
184                 // Prepare data for the template
185                 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
186                 $content['cnt']       = $count;
187
188                 // Load template
189                 loadTemplate('admin_delete_email_bonus', false, $content);
190         } else {
191                 // Mail already deleted!
192                 displayMessage('{--ADMIN_BONUS_MAIL_ALREADY_DELETED--}');
193         }
194
195         // Free result
196         SQL_FREERESULT($result);
197 } elseif ((isGetRequestParameterSet('nid')) && (isExtensionInstalledAndNewer('bonus', '0.8.7'))) {
198         // Load data from bonus mail
199         $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
200                 array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
201
202         // Delete mail only once
203         if (SQL_NUMROWS($result) == 1) {
204                 // Load data
205                 $content = SQL_FETCHARRAY($result);
206
207                 // Init counter for deleted mails
208                 $count = '0';
209
210                 // Delete bonus mail entirely from database
211                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
212                         array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
213                 $count += SQL_AFFECTEDROWS();
214                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
215                         array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
216                 $count += SQL_AFFECTEDROWS();
217
218                 // Prepare data for the template
219                 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
220                 $content['cnt']       = $count;
221
222                 // Load template
223                 loadTemplate('admin_delete_email_notify', false, $content);
224         } else {
225                 // Mail already deleted!
226                 displayMessage('{--ADMIN_NOTIFY_MAIL_ALREADY_DELETED--}');
227         }
228
229         // Free result
230         SQL_FREERESULT($result);
231 } else {
232         // No mail orders fond
233         displayMessage('{--ADMIN_WRONG_CALL--}');
234 }
235
236 // [EOF]
237 ?>