Updated copyright year.
[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 - 2016 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         // @TODO Unused: cat_id
52         $content = getPoolDataFromId(getRequestElement('id'));
53
54         // Delete mail only once
55         if (count($content) > 0) {
56                 // Prepare data for the template
57                 $content['timestamp'] = generateDateTime($content['timestamp'], 0);
58
59                 // Load template
60                 loadTemplate('admin_delete_email_normal', FALSE, $content);
61
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);
65
66                 // Fetch right stats_id from pool
67                 $result_pool = sqlQueryEscaped("SELECT
68         `s`.`id`
69 FROM
70         `{?_MYSQL_PREFIX?}_user_stats` AS `s`
71 LEFT JOIN
72         `{?_MYSQL_PREFIX?}_pool` AS `p`
73 ON
74         `s`.`pool_id`=`p`.`id`
75 WHERE
76         `s`.`pool_id`=%s
77 LIMIT 1",
78                         array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
79                 if (sqlNumRows($result_pool) == 1) {
80                         // Fetch stats id
81                         list($stats_id) = sqlFetchRow($result_pool);
82
83                         // Get all user links
84                         $links = countSumTotalData($stats_id, 'user_links', 'userid', 'stats_id', TRUE);
85
86                         // Reset sent mails for recipient(s)
87                         reduceRecipientReceivedMails('stats_id', getRequestElement('id'), $links);
88
89                         // Calc total points and pay them back
90                         $totalPoints = $links * $content['price'];
91
92                         // Shall we pay the points back to the user?
93                         if ($totalPoints == 0) {
94                                 // No points repayed!
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') {
100                                         // Set jackpot
101                                         $content['sender'] = '0';
102                                 } // END - if
103
104                                 // Pay back points
105                                 initReferralSystem();
106                                 addPointsThroughReferralSystem('mail_deleted', $content['sender'], $totalPoints);
107
108                                 // Output message
109                                 if (getConfig('repay_deleted_mails') == 'REPAY') {
110                                         // Repayed
111                                         displayMessage('{%message,ADMIN_POINTS_REPAYED=' . $totalPoints . '%}');
112                                 } else {
113                                         // To jackpot
114                                         displayMessage('{%message,ADMIN_POINTS_TO_JACKPOT=' . $totalPoints . '%}');
115                                 }
116                         } else {
117                                 // Points shredded!
118                                 displayMessage('{%message,ADMIN_POINTS_SHREDDED=' . $totalPoints . '%}');
119                         }
120
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();
125
126                         // Load template for link
127                         displayMessage('<a href="{%url=modules.php?module=admin&amp;what=del_email&amp;pid=' . bigintval(getRequestElement('id')) . '%}">{--ADMIN_REMOVE_STATS_ENTRY--}</a>');
128                 } // END - if
129
130                 // Free the result
131                 sqlFreeResult($result_pool);
132
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();
137
138                 // Output link for manually removing stats entry
139                 outputHtml('{%message,ADMIN_DELETED_MAILS_COUNT=' . $count . '%}');
140         } else {
141                 // Mail already deleted!
142                 displayMessage('{--ADMIN_NORMAL_MAIL_ALREADY_DELETED--}');
143         }
144
145         // Free result
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__);
151
152         // Output message
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__);
158
159         // Delete mail only once
160         if (sqlNumRows($result) == 1) {
161                 // Load data
162                 $content = sqlFetchArray($result);
163
164                 // Reset sent mails for recipient(s)
165                 reduceRecipientReceivedMails('bonus_id', getRequestElement('id'), $content['mails_sent']);
166
167                 // Init counter for deleted mails
168                 $count = '0';
169
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();
177
178                 // Prepare data for the template
179                 $content['timestamp'] = generateDateTime($content['timestamp'], '0');
180                 $content['count']     = $count;
181
182                 // Load template
183                 loadTemplate('admin_delete_email_bonus', FALSE, $content);
184         } else {
185                 // Mail already deleted!
186                 displayMessage('{--ADMIN_BONUS_MAIL_ALREADY_DELETED--}');
187         }
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__);
192
193         // Delete mail only once
194         if (sqlNumRows($result) == 1) {
195                 // Load data
196                 $content = sqlFetchArray($result);
197
198                 // Init counter for deleted mails
199                 $count = '0';
200
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();
208
209                 // Prepare data for the template
210                 $content['timestamp'] = generateDateTime($content['timestamp'], '0');
211                 $content['count']     = $count;
212
213                 // Load template
214                 loadTemplate('admin_delete_email_notify', FALSE, $content);
215         } else {
216                 // Mail already deleted!
217                 displayMessage('{--ADMIN_NOTIFY_MAIL_ALREADY_DELETED--}');
218         }
219
220         // Free result
221         sqlFreeResult($result);
222 } else {
223         // No mail orders fond
224         displayMessage('{--ADMIN_WRONG_CALL--}');
225 }
226
227 // [EOF]
228 ?>