Fixed typo in function name
[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 $GLOBALS['what'] = "";
39 $GLOBALS['action'] = "";
40
41 // Tell everyone we are in this module
42 $GLOBALS['module'] = "mailid";
43 $GLOBALS['output_mode'] = -1;
44
45 // Load the required file(s)
46 require("inc/config.php");
47
48 if (isInstalled()) {
49         // Is the extension active?
50         REDIRECT_ON_UNINSTALLED_EXTENSION("mailid");
51
52         // Init
53         $url_uid = 0; $url_bid = 0; $url_mid = 0;
54
55         // Secure all data
56         if (REQUEST_ISSET_GET(('uid')))     $url_uid = bigintval(REQUEST_GET('uid'));
57         if (REQUEST_ISSET_GET(('mailid')))  $url_mid = bigintval(REQUEST_GET('mailid'));
58         if (REQUEST_ISSET_GET(('bonusid'))) $url_bid = bigintval(REQUEST_GET('bonusid'));
59
60         // 01        1        12            3    32           21    1                   22     10
61         if (($url_uid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (getTotalFatalErrors() == 0)) {
62                 // Maybe he wants to confirm an email?
63                 if ($url_mid > 0) {
64                         // Normal-Mails
65                         $result = SQL_QUERY_ESC("SELECT link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE stats_id=%s AND userid=%s LIMIT 1",
66                                 array($url_mid, $url_uid), __FILE__, __LINE__);
67                         $type = "mailid"; $DATA = $url_mid;
68                 } elseif ($url_bid > 0) {
69                         // Bonus-Mail
70                         $result = SQL_QUERY_ESC("SELECT link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE bonus_id=%s AND userid=%s LIMIT 1",
71                                 array($url_bid, $url_uid), __FILE__, __LINE__);
72                         $type = "bonusid"; $DATA = $url_bid;
73                 } else {
74                         // Problem: No ID entered
75                         LOAD_URL("index.php");
76                 }
77
78                 if (SQL_NUMROWS($result) == 1) {
79                         // Load the entry
80                         list($ltype) = SQL_FETCHROW($result);
81
82                         // Clean result
83                         SQL_FREERESULT($result);
84
85                         switch ($ltype)
86                         {
87                         case "NORMAL":
88                                 // Is the stats ID valid?
89                                 $result = SQL_QUERY_ESC("SELECT pool_id, url, subject FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE id=%s LIMIT 1",
90                                         array($url_mid), __FILE__, __LINE__);
91                                 break;
92
93                         case "BONUS":
94                                 // Is the bonus extension active?
95                                 REDIRECT_ON_UNINSTALLED_EXTENSION("bonus");
96
97                                 // Bonus-Mails
98                                 $result = SQL_QUERY_ESC("SELECT id, url, subject FROM `{!_MYSQL_PREFIX!}_bonus` WHERE id=%s LIMIT 1",
99                                         array($url_bid), __FILE__, __LINE__);
100                                 break;
101                         }
102
103                         if (SQL_NUMROWS($result) == 1) {
104                                 // Load data
105                                 list($pool, $URL, $EXTRA_TITLE) = SQL_FETCHROW($result);
106
107                                 // Free result
108                                 SQL_FREERESULT($result);
109
110                                 // Compile extra title
111                                 $EXTRA_TITLE = COMPILE_CODE($EXTRA_TITLE);
112
113                                 // Is the user's ID unlocked?
114                                 $result = SQL_QUERY_ESC("SELECT status, gender, surname, family FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
115                                         array($url_uid), __FILE__, __LINE__);
116                                 if (SQL_NUMROWS($result) == 1) {
117                                         list($status, $gender, $sname, $fname) = SQL_FETCHROW($result);
118                                         SQL_FREERESULT($result);
119                                         if ($status == "CONFIRMED") {
120                                                 // User has confirmed his account so we can procede...
121                                                 switch ($ltype)
122                                                 {
123                                                 case "NORMAL":
124                                                         $result = SQL_QUERY_ESC("SELECT payment_id FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE pool_id=%s LIMIT 1",
125                                                                 array(bigintval($pool)), __FILE__, __LINE__);
126                                                         if (SQL_NUMROWS($result) == 1) {
127                                                                 list($pay) = SQL_FETCHROW($result);
128                                                                 $time      = GET_PAY_POINTS($pay, "time");
129                                                                 $payment   = GET_PAY_POINTS($pay, "payment");
130                                                                 $VALID     = true;
131                                                         }
132
133                                                         // Free memory
134                                                         SQL_FREERESULT($result);
135                                                         break;
136
137                                                 case "BONUS":
138                                                         $result = SQL_QUERY_ESC("SELECT points, time FROM `{!_MYSQL_PREFIX!}_bonus` WHERE id=%s LIMIT 1",
139                                                                 array($url_bid), __FILE__, __LINE__);
140                                                         if (SQL_NUMROWS($result) == 1) {
141                                                                 list($points, $time) = SQL_FETCHROW($result);
142                                                                 $payment = "0.00000";
143                                                                 $VALID = true;
144                                                         }
145
146                                                         // Free memory
147                                                         SQL_FREERESULT($result);
148                                                         break;
149                                                 }
150
151                                                 // Add header
152                                                 LOAD_INC_ONCE("inc/header.php");
153
154                                                 // Was that mail a valid one?
155                                                 if ($VALID) {
156                                                         // If time is zero seconds we have a sponsor mail. 1 Second shall be set to avoid problems
157                                                         if (($time == "0") && ($payment > 0)) { $URL = constant('URL'); $time = "1"; }
158                                                         if (($time > 0) && (($payment > 0) || ($points > 0))) {
159                                                                 // He can confirm this mail!
160                                                                 // Export data into constants for the template
161                                                                 define('_UID_VALUE' , $url_uid);
162                                                                 define('_TYPE_VALUE', $type);
163                                                                 define('_DATA_VALUE', $DATA);
164                                                                 define('_URL_VALUE' , DEREFERER($URL));
165
166                                                                 // Load template
167                                                                 LOAD_TEMPLATE("mailid_frames");
168                                                         } else {
169                                                                 $msg = constant('CODE_DATA_INVALID');
170                                                         }
171                                                 } else {
172                                                         $msg = constant('CODE_POSSIBLE_INVALID');
173                                                 }
174                                         } else {
175                                                 $msg = constant('CODE_ACCOUNT_LOCKED');
176                                         }
177                                 } else {
178                                         SQL_FREERESULT($result);
179                                         $msg = constant('CODE_USER_404');
180                                 }
181                         } else {
182                                 SQL_FREERESULT($result);
183                                 $msg = constant('CODE_STATS_404');
184                         }
185                 } else {
186                         SQL_FREERESULT($result);
187                         $msg = constant('CODE_ALREADY_CONFIRMED');
188                 }
189         } else {
190                 // Nothing entered
191                 $msg = constant('CODE_ERROR_MAILID');
192         }
193
194         // Error code is set?
195         if (!empty($msg)) {
196                 switch (getConfig('mailid_error_redirect')) {
197                         case "INDEX": // Redirect to index page
198                                 LOAD_URL("modules.php?module=index&amp;msg=".$msg."&amp;ext=mailid");
199                                 break;
200
201                         case "REJECT": // Redirect to rejection page
202                                 LOAD_CONFIGURED_URL('reject_url');
203                                 break;
204
205                         default:
206                                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s detected in mailid_error_redirect.", getConfig('mailid_error_redirect')));
207                                 LOAD_URL("modules.php?module=index&amp;msg=".constant('CODE_UNKNOWN_STATUS')."&amp;ext=mailid");
208                                 break;
209                 }
210         } else {
211                 // Include footer
212                 LOAD_INC_ONCE("inc/footer.php");
213         }
214 } else {
215         // You have to install first!
216         LOAD_URL("install.php");
217 }
218
219 //
220 ?>