Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[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['ordered'] = generateDateTime($timestamp, '0');
68
69                 // Load template
70                 loadTemplate('admin_del_email_normal', false, $content);
71
72                 // Transfer data to data array
73                 $DATA = array('url' => $url, 'subject' => $subject);
74
75                 // Load email template and send the email away
76                 $message_user = loadEmailTemplate('order-deleted', array(), $sender);
77                 sendEmail($sender, getMessage('MEMBER_ORDER_DELETED'), $message_user);
78
79                 // Fetch right stats_id from pool
80                 $result_pool = SQL_QUERY_ESC("SELECT
81         s.id
82 FROM
83         `{?_MYSQL_PREFIX?}_user_stats` AS s
84 LEFT JOIN
85         `{?_MYSQL_PREFIX?}_pool` AS p
86 ON
87         s.pool_id=p.id
88 WHERE
89         s.pool_id=%s
90 LIMIT 1",
91                         array(bigintval(getRequestElement('mid'))), __FILE__, __LINE__);
92                 if (SQL_NUMROWS($result_pool) == 1) {
93                         // Fetch stats id
94                         list($stats_id) = SQL_FETCHROW($result_pool);
95
96                         // Get all user links
97                         $links = countSumTotalData($stats_id, 'user_links', 'userid', 'stats_id', true);
98
99                         // Reset sent mails for recipient(s)
100                         reduceRecipientReceivedMails('stats_id', getRequestElement('mid'), $links);
101
102                         // Calc total points and pay them back
103                         $totalPoints = $links * $price;
104
105                         // Shall we pay the points back to the user?
106                         if (getConfig('repay_deleted_mails') != 'SHRED') {
107                                 //* DEBUG: */ outputHtml($stats_id.':'.$totalPoints.'/'.$links.'/'.$price."<br />");
108                                 if ($totalPoints > 0) {
109                                         // Shall we payback to user or jackpot?
110                                         if (getConfig('repay_deleted_mails') == 'JACKPOT') {
111                                                 // Set jackpot
112                                                 $sender = 0;
113                                         } // END - if
114
115                                         // Pay back points
116                                         //* DEBUG: */ outputHtml("PAYBACK:".$sender."<br />");
117                                         addPointsThroughReferalSystem('mail_deleted', $sender, $totalPoints, true, '0', false,'direct');
118
119                                         // Output message
120                                         if (getConfig('repay_deleted_mails') == 'REPAY') {
121                                                 // Repayed
122                                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_POINTS_REPAYED'),
123                                                         translateComma($totalPoints)
124                                                 ));
125                                         } else {
126                                                 // To jackpot
127                                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_POINTS_TO_JACKPOT'),
128                                                         translateComma($totalPoints)
129                                                 ));
130                                         }
131                                 } else {
132                                         // No points repayed!
133                                         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_POINTS_REPAYED'));
134                                 }
135                         } else {
136                                 // Points shredded!
137                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_POINTS_SHREDDED'), $totalPoints));
138                         }
139
140                         // Remove links from DB
141                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
142                         array(bigintval($stats_id)), __FILE__, __LINE__);
143                         $cnt += SQL_AFFECTEDROWS();
144
145                         // Load template for link
146                         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>");
147                 } // END - if
148
149                 // Free the result
150                 SQL_FREERESULT($result_pool);
151
152                 // Delete mail from queue
153                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
154                         array(bigintval(getRequestElement('mid'))), __FILE__, __LINE__);
155                 $cnt += SQL_AFFECTEDROWS();
156
157                 // Output link for manually removing stats entry
158                 outputHtml(sprintf(getMessage('ADMIN_DELETED_MAILS_COUNT'), $cnt));
159         } else {
160                 // Mail already deleted!
161                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NORMAL_MAIL_ALREADY_DELETED'));
162         }
163 } elseif (isGetRequestElementSet('pid')) {
164         // Remove stats entries
165         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
166         array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
167
168         // Output message
169         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_USER_STATS_REMOVED'));
170 } elseif ((isGetRequestElementSet('bid')) && (isExtensionActive('bonus'))) {
171         // Load data from bonus mail
172         $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s",
173                 array(bigintval(getRequestElement('bid'))), __FILE__, __LINE__);
174
175         // Delete mail only once
176         if (SQL_NUMROWS($result) == 1) {
177                 // Load data
178                 list($id, $subject, $url, $timestamp, $sent) = SQL_FETCHROW($result);
179
180                 // Reset sent mails for recipient(s)
181                 reduceRecipientReceivedMails('bonus_id', getRequestElement('bid'), $sent);
182
183                 // Init counter for deleted mails
184                 $cnt = 0;
185
186                 // Delete bonus mail entirely from database
187                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
188                         array(bigintval(getRequestElement('bid'))), __FILE__, __LINE__);
189                 $cnt += SQL_AFFECTEDROWS();
190                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
191                         array(bigintval(getRequestElement('bid'))), __FILE__, __LINE__);
192                 $cnt += SQL_AFFECTEDROWS();
193
194                 // Prepare data for the template
195                 $content['id']      = $id;
196                 $content['subject'] = $subject;
197                 $content['url']     = generateDerefererUrl($url);
198                 $content['ordered'] = generateDateTime($timestamp, '0');
199                 $content['cnt']     = $cnt;
200
201                 // Load template
202                 loadTemplate('admin_del_email_bonus', false, $content);
203         } else {
204                 // Mail already deleted!
205                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_BONUS_MAIL_ALREADY_DELETED'));
206         }
207
208         // Free result
209         SQL_FREERESULT($result);
210 } elseif ((isGetRequestElementSet('nid')) && (getExtensionVersion('bonus') >= '0.8.7')) {
211         // Load data from bonus mail
212         $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s",
213                 array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
214
215         // Delete mail only once
216         if (SQL_NUMROWS($result) == 1) {
217                 // Load data
218                 list ($id, $subject, $url, $timestamp) = SQL_FETCHROW($result);
219
220                 // Init counter for deleted mails
221                 $cnt = 0;
222
223                 // Delete bonus mail entirely from database
224                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
225                         array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
226                 $cnt += SQL_AFFECTEDROWS();
227                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
228                         array(bigintval(getRequestElement('nid'))), __FILE__, __LINE__);
229                 $cnt += SQL_AFFECTEDROWS();
230
231                 // Prepare data for the template
232                 $content['id']      = $id;
233                 $content['subject'] = $subject;
234                 $content['url']     = generateDerefererUrl($url);
235                 $content['ordered'] = generateDateTime($timestamp, '0');
236                 $content['cnt']     = $cnt;
237
238                 // Load template
239                 loadTemplate('admin_del_email_notify', false, $content);
240         } else {
241                 // Mail already deleted!
242                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NOTIFY_MAIL_ALREADY_DELETED'));
243         }
244
245         // Free result
246         SQL_FREERESULT($result);
247 } else {
248         // No mail orders fond
249         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
250 }
251
252 //
253 ?>