91801e67bc13efe975da48acdcce4a9f51626955
[mailer.git] / mailid.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/14/2003 *
4  * ===============                              Last change: 11/25/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : mailid.php                                       *
8  * -------------------------------------------------------------------- *
9  * Short description : Confirmation file for emails                     *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Bestaetigung von Mails                           *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
35 require("inc/libs/security_functions.php");
36
37 // Init "action" and "what"
38 global $what, $action;
39 $GLOBALS['what'] = ""; $GLOBALS['action'] = "";
40
41 // Tell everyone we are in this module
42 $GLOBALS['module'] = "mailid"; $CSS = -1;
43
44 // Load the required file(s)
45 require("inc/config.php");
46
47 if (isBooleanConstantAndTrue('mxchange_installed')) {
48         // Is the extension active?
49         REDIRECT_ON_UNINSTALLED_EXTENSION("mailid");
50
51         // Init
52         $url_uid = 0; $url_bid = 0; $url_mid = 0;
53
54         // Secure all data
55         if (!empty($_GET['uid']))     $url_uid = bigintval($_GET['uid']);
56         if (!empty($_GET['mailid']))  $url_mid = bigintval($_GET['mailid']);
57         if (!empty($_GET['bonusid'])) $url_bid = bigintval($_GET['bonusid']);
58
59         // 01        1        12            3    32           21    1                   22     10
60         if (($url_uid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (getTotalFatalErrors() == 0)) {
61                 // Maybe he wants to confirm an email?
62                 if ($url_mid > 0) {
63                         // Normal-Mails
64                         $result = SQL_QUERY_ESC("SELECT link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE stats_id=%s AND userid=%s LIMIT 1",
65                                 array($url_mid, $url_uid), __FILE__, __LINE__);
66                         $type = "mailid"; $DATA = $url_mid;
67                 } elseif ($url_bid > 0) {
68                         // Bonus-Mail
69                         $result = SQL_QUERY_ESC("SELECT link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE bonus_id=%s AND userid=%s LIMIT 1",
70                                 array($url_bid, $url_uid), __FILE__, __LINE__);
71                         $type = "bonusid"; $DATA = $url_bid;
72                 } else {
73                         // Problem: No ID entered
74                         LOAD_URL("index.php");
75                 }
76
77                 if (SQL_NUMROWS($result) == 1) {
78                         // Load the entry
79                         list($ltype) = SQL_FETCHROW($result);
80
81                         // Clean result
82                         SQL_FREERESULT($result);
83
84                         switch ($ltype)
85                         {
86                         case "NORMAL":
87                                 // Is the stats ID valid?
88                                 $result = SQL_QUERY_ESC("SELECT pool_id, url, subject FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE id=%s LIMIT 1",
89                                         array($url_mid), __FILE__, __LINE__);
90                                 break;
91
92                         case "BONUS":
93                                 // Is the bonus extension active?
94                                 REDIRECT_ON_UNINSTALLED_EXTENSION("bonus");
95
96                                 // Bonus-Mails
97                                 $result = SQL_QUERY_ESC("SELECT id, url, subject FROM `{!_MYSQL_PREFIX!}_bonus` WHERE id=%s LIMIT 1",
98                                         array($url_bid), __FILE__, __LINE__);
99                                 break;
100                         }
101
102                         if (SQL_NUMROWS($result) == 1) {
103                                 // Load data
104                                 list($pool, $URL, $EXTRA_TITLE) = SQL_FETCHROW($result);
105
106                                 // Free result
107                                 SQL_FREERESULT($result);
108
109                                 // Compile extra title
110                                 $EXTRA_TITLE = COMPILE_CODE($EXTRA_TITLE);
111
112                                 // Is the user's ID unlocked?
113                                 $result = SQL_QUERY_ESC("SELECT status, gender, surname, family FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
114                                         array($url_uid), __FILE__, __LINE__);
115                                 if (SQL_NUMROWS($result) == 1) {
116                                         list($status, $gender, $sname, $fname) = SQL_FETCHROW($result);
117                                         SQL_FREERESULT($result);
118                                         if ($status == "CONFIRMED") {
119                                                 // User has confirmed his account so we can procede...
120                                                 switch ($ltype)
121                                                 {
122                                                 case "NORMAL":
123                                                         $result = SQL_QUERY_ESC("SELECT payment_id FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE pool_id=%s LIMIT 1",
124                                                                 array(bigintval($pool)), __FILE__, __LINE__);
125                                                         if (SQL_NUMROWS($result) == 1) {
126                                                                 list($pay) = SQL_FETCHROW($result);
127                                                                 $time      = GET_PAY_POINTS($pay, "time");
128                                                                 $payment   = GET_PAY_POINTS($pay, "payment");
129                                                                 $VALID     = true;
130                                                         }
131
132                                                         // Free memory
133                                                         SQL_FREERESULT($result);
134                                                         break;
135
136                                                 case "BONUS":
137                                                         $result = SQL_QUERY_ESC("SELECT points, time FROM `{!_MYSQL_PREFIX!}_bonus` WHERE id=%s LIMIT 1",
138                                                                 array($url_bid), __FILE__, __LINE__);
139                                                         if (SQL_NUMROWS($result) == 1) {
140                                                                 list($points, $time) = SQL_FETCHROW($result);
141                                                                 $payment = "0.00000";
142                                                                 $VALID = true;
143                                                         }
144
145                                                         // Free memory
146                                                         SQL_FREERESULT($result);
147                                                         break;
148                                                 }
149
150                                                 // Add header
151                                                 LOAD_INC_ONCE("inc/header.php");
152
153                                                 // Was that mail a valid one?
154                                                 if ($VALID) {
155                                                         // If time is zero seconds we have a sponsor mail. 1 Second shall be set to avoid problems
156                                                         if (($time == "0") && ($payment > 0)) { $URL = constant('URL'); $time = "1"; }
157                                                         if (($time > 0) && (($payment > 0) || ($points > 0))) {
158                                                                 // He can confirm this mail!
159                                                                 // Export data into constants for the template
160                                                                 define('_UID_VALUE' , $url_uid);
161                                                                 define('_TYPE_VALUE', $type);
162                                                                 define('_DATA_VALUE', $DATA);
163                                                                 define('_URL_VALUE' , DEREFERER($URL));
164
165                                                                 // Load template
166                                                                 LOAD_TEMPLATE("mailid_frames");
167                                                         } else {
168                                                                 $msg = constant('CODE_DATA_INVALID');
169                                                         }
170                                                 } else {
171                                                         $msg = constant('CODE_POSSIBLE_INVALID');
172                                                 }
173                                         } else {
174                                                 $msg = constant('CODE_ACCOUNT_LOCKED');
175                                         }
176                                 } else {
177                                         SQL_FREERESULT($result);
178                                         $msg = constant('CODE_USER_404');
179                                 }
180                         } else {
181                                 SQL_FREERESULT($result);
182                                 $msg = constant('CODE_STATS_404');
183                         }
184                 } else {
185                         SQL_FREERESULT($result);
186                         $msg = constant('CODE_ALREADY_CONFIRMED');
187                 }
188         } else {
189                 // Nothing entered
190                 $msg = constant('CODE_ERROR_MAILID');
191         }
192
193         // Error code is set?
194         if (!empty($msg)) {
195                 switch (getConfig('mailid_error_redirect')) {
196                         case "INDEX": // Redirect to index page
197                                 LOAD_URL("modules.php?module=index&amp;msg=".$msg."&amp;ext=mailid");
198                                 break;
199
200                         case "REJECT": // Redirect to rejection page
201                                 LOAD_CONFIGURED_URL('reject_url');
202                                 break;
203
204                         default:
205                                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s detected in mailid_error_redirect.", getConfig('mailid_error_redirect')));
206                                 LOAD_URL("modules.php?module=index&amp;msg=".constant('CODE_UNKNOWN_STATUS')."&amp;ext=mailid");
207                                 break;
208                 }
209         } else {
210                 // Include footer
211                 LOAD_INC_ONCE("inc/footer.php");
212         }
213 } else {
214         // You have to install first!
215         LOAD_URL("install.php");
216 }
217
218 //
219 ?>