Misc fixes
[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 - 2008 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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) {
39         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40         require($INC);
41 }
42
43 // Add description as navigation point
44 ADD_DESCR("admin", basename(__FILE__));
45
46 if (!empty($_GET['mid'])) {
47         // Load email data
48         $result = SQL_QUERY_ESC("SELECT id, sender, subject, url, timestamp FROM "._MYSQL_PREFIX."_pool WHERE id=%d LIMIT 1",
49          array(bigintval($_GET['mid'])), __FILE__, __LINE__);
50         list ($id, $sender, $subject, $url, $timestamp,) = SQL_FETCHROW($result);
51         SQL_FREERESULT($result);
52
53         // Delete mail only once
54         if ($sender > 0) {
55                 // Prepare data for the template
56                 define('__ID'     , $id);
57                 define('__SENDER' , ADMIN_USER_PROFILE_LINK($sender));
58                 define('__SUBJECT', $subject);
59                 define('__URL'    , DEREFERER($url));
60                 define('__ORDERED', MAKE_DATETIME($timestamp, "0"));
61
62                 // Load template
63                 LOAD_TEMPLATE("admin_del_email_normal");
64
65                 // Transfer data to data array
66                 $DATA = array($url, $subject);
67
68                 // Load email template and send the email away
69                 $msg_user = LOAD_EMAIL_TEMPLATE("order-deleted", "", $sender);
70                 SEND_EMAIL($sender, MEMBER_ORDER_DELETED, $msg_user);
71
72                 // Delete mail from queue
73                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_pool WHERE id=%d LIMIT 1",
74                  array(bigintval($_GET['mid'])), __FILE__, __LINE__);
75
76                 // Fetch right stats_id from pool
77                 $result = SQL_QUERY_ESC("SELECT s.id FROM "._MYSQL_PREFIX."_user_stats AS s
78 LEFT JOIN "._MYSQL_PREFIX."_pool AS p
79 ON s.pool_id=%d LIMIT 1",
80  array(bigintval($_GET['mid'])), __FILE__, __LINE__);
81                 if (SQL_NUMROWS($result) == 1) {
82                         // Fetch stats id
83                         list($stats_id) = SQL_FETCHROW($result);
84                         SQL_FREERESULT($result);
85
86                         // Remove links from DB
87                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%d",
88                          array(bigintval($stats_id)), __FILE__, __LINE__);
89
90                         // Output link for manually removing stats entry
91                         LOAD_TEMPLATE("admin_settings_saved", false, "<A href=\"".URL."/modules.php?module=admin&amp;what=del_email&amp;pid=".$_GET['mid']."\">".ADMIN_REMOVE_STATS_ENTRY."</A>");
92                 }
93         } else {
94                 // Mail already deleted!
95                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NORMAL_MAIL_ALREADY_DELETED);
96         }
97 } elseif (!empty($_GET['pid'])) {
98         // Remove stats entries
99         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%d LIMIT 1",
100          array(bigintval($_GET['pid'])), __FILE__, __LINE__);
101         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_USER_STATS_REMOVED);
102 } elseif ((!empty($_GET['bid'])) && (EXT_IS_ACTIVE("bonus"))) {
103         // Load data from bonus mail
104         $result = SQL_QUERY_ESC("SELECT id, subject, url, timestamp FROM "._MYSQL_PREFIX."_bonus WHERE id=%d",
105          array(bigintval($_GET['bid'])), __FILE__, __LINE__);
106         list ($id, $subject, $url, $timestamp) = SQL_FETCHROW($result);
107         SQL_FREERESULT($result);
108
109         // Delete mail only once
110         if ($id > 0) {
111                 // Delete bonus mail entirely from database
112                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_bonus WHERE id=%d LIMIT 1",
113                  array(bigintval($_GET['bid'])), __FILE__, __LINE__);
114                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%d",
115                  array(bigintval($_GET['bid'])), __FILE__, __LINE__);
116
117                 // Prepare data for the template
118                 define('__ID'     , $id);
119                 define('__SUBJECT', $subject);
120                 define('__URL'    , DEREFERER($url));
121                 define('__ORDERED', MAKE_DATETIME($timestamp, "0"));
122
123                 // Load template
124                 LOAD_TEMPLATE("admin_del_email_bonus");
125         } else {
126                 // Mail already deleted!
127                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BONUS_MAIL_ALREADY_DELETED);
128         }
129 } else {
130         // No mail orders fond
131         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_WRONG_CALL);
132 }
133
134 //
135 ?>