60705d4ea662fe530f06f2ae96ac71c599faecc2
[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 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://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 ((isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'normal')) {
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(getRequestElement('id'))), __FILE__, __LINE__);
53
54         // Delete mail only once
55         if (SQL_NUMROWS($result) == 1) {
56                 // Load data
57                 // @TODO Unused: cat_id
58                 $content = SQL_FETCHARRAY($result);
59
60                 // Prepare data for the template
61                 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
62
63                 // Load template
64                 loadTemplate('admin_delete_email_normal', FALSE, $content);
65
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);
69
70                 // Fetch right stats_id from pool
71                 $result_pool = SQL_QUERY_ESC("SELECT
72         `s`.`id`
73 FROM
74         `{?_MYSQL_PREFIX?}_user_stats` AS `s`
75 LEFT JOIN
76         `{?_MYSQL_PREFIX?}_pool` AS `p`
77 ON
78         `s`.`pool_id`=`p`.`id`
79 WHERE
80         `s`.`pool_id`=%s
81 LIMIT 1",
82                         array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
83                 if (SQL_NUMROWS($result_pool) == 1) {
84                         // Fetch stats id
85                         list($stats_id) = SQL_FETCHROW($result_pool);
86
87                         // Get all user links
88                         $links = countSumTotalData($stats_id, 'user_links', 'userid', 'stats_id', TRUE);
89
90                         // Reset sent mails for recipient(s)
91                         reduceRecipientReceivedMails('stats_id', getRequestElement('id'), $links);
92
93                         // Calc total points and pay them back
94                         $totalPoints = $links * $content['price'];
95
96                         // Shall we pay the points back to the user?
97                         if ($totalPoints == 0) {
98                                 // No points repayed!
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') {
104                                         // Set jackpot
105                                         $content['sender'] = '0';
106                                 } // END - if
107
108                                 // Pay back points
109                                 initReferralSystem();
110                                 addPointsThroughReferralSystem('mail_deleted', $content['sender'], $totalPoints);
111
112                                 // Output message
113                                 if (getConfig('repay_deleted_mails') == 'REPAY') {
114                                         // Repayed
115                                         displayMessage('{%message,ADMIN_POINTS_REPAYED=' . $totalPoints . '%}');
116                                 } else {
117                                         // To jackpot
118                                         displayMessage('{%message,ADMIN_POINTS_TO_JACKPOT=' . $totalPoints . '%}');
119                                 }
120                         } else {
121                                 // Points shredded!
122                                 displayMessage('{%message,ADMIN_POINTS_SHREDDED=' . $totalPoints . '%}');
123                         }
124
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();
129
130                         // Load template for link
131                         displayMessage('<a href="{%url=modules.php?module=admin&amp;what=del_email&amp;pid=' . bigintval(getRequestElement('id')) . '%}">{--ADMIN_REMOVE_STATS_ENTRY--}</a>');
132                 } // END - if
133
134                 // Free the result
135                 SQL_FREERESULT($result_pool);
136
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();
141
142                 // Output link for manually removing stats entry
143                 outputHtml('{%message,ADMIN_DELETED_MAILS_COUNT=' . $count . '%}');
144         } else {
145                 // Mail already deleted!
146                 displayMessage('{--ADMIN_NORMAL_MAIL_ALREADY_DELETED--}');
147         }
148
149         // Free result
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__);
155
156         // Output message
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__);
162
163         // Delete mail only once
164         if (SQL_NUMROWS($result) == 1) {
165                 // Load data
166                 $content = SQL_FETCHARRAY($result);
167
168                 // Reset sent mails for recipient(s)
169                 reduceRecipientReceivedMails('bonus_id', getRequestElement('id'), $content['mails_sent']);
170
171                 // Init counter for deleted mails
172                 $count = '0';
173
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();
181
182                 // Prepare data for the template
183                 $content['timestamp'] = generateDateTime($content['timestamp'], '0');
184                 $content['count']     = $count;
185
186                 // Load template
187                 loadTemplate('admin_delete_email_bonus', FALSE, $content);
188         } else {
189                 // Mail already deleted!
190                 displayMessage('{--ADMIN_BONUS_MAIL_ALREADY_DELETED--}');
191         }
192
193         // Free result
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__);
199
200         // Delete mail only once
201         if (SQL_NUMROWS($result) == 1) {
202                 // Load data
203                 $content = SQL_FETCHARRAY($result);
204
205                 // Init counter for deleted mails
206                 $count = '0';
207
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();
215
216                 // Prepare data for the template
217                 $content['timestamp'] = generateDateTime($content['timestamp'], '0');
218                 $content['count']     = $count;
219
220                 // Load template
221                 loadTemplate('admin_delete_email_notify', FALSE, $content);
222         } else {
223                 // Mail already deleted!
224                 displayMessage('{--ADMIN_NOTIFY_MAIL_ALREADY_DELETED--}');
225         }
226
227         // Free result
228         SQL_FREERESULT($result);
229 } else {
230         // No mail orders fond
231         displayMessage('{--ADMIN_WRONG_CALL--}');
232 }
233
234 // [EOF]
235 ?>