Now with two underscores
[mailer.git] / mailid.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 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 // Load security stuff here
39 require('inc/libs/security_functions.php');
40
41 // Init start time
42 $GLOBALS['startTime'] = microtime(true);
43
44 // Tell everyone we are in this module
45 $GLOBALS['__module'] = 'mailid';
46 $GLOBALS['output_mode'] = -1;
47 $errorCode = '';
48
49 // Load the required file(s)
50 require('inc/config-global.php');
51
52 // Set content type and HTTP status
53 setContentType('text/html');
54 setHttpStatus('404 NOT FOUND');
55
56 // Is the extension active?
57 redirectOnUninstalledExtension('mailid');
58
59 // Init
60 $userId  = '0';
61 $bonusId = '0';
62 $mailId  = '0';
63
64 // Secure all data
65 if (isGetRequestElementSet('userid'))  $userId  = bigintval(getRequestElement('userid'));
66 if (isGetRequestElementSet('mailid'))  $mailId  = bigintval(getRequestElement('mailid'));
67 if (isGetRequestElementSet('bonusid')) $bonusId = bigintval(getRequestElement('bonusid'));
68
69 // 01           1        12            2    2            21    1                      2210
70 if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalErrorsDetected())) {
71         // Init result
72         $result_link = false;
73
74         // Maybe he wants to confirm an email?
75         if ($mailId > 0) {
76                 // Member mail
77                 $result_link = SQL_QUERY_ESC("SELECT `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
78                         array($mailId, $userId), __FILE__, __LINE__);
79                 $type = 'mailid';
80                 $urlId = $mailId;
81         } elseif ($bonusId > 0) {
82                 // Bonus mail
83                 $result_link = SQL_QUERY_ESC("SELECT `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
84                         array($bonusId, $userId), __FILE__, __LINE__);
85                 $type = 'bonusid';
86                 $urlId = $bonusId;
87         } else {
88                 // Problem: No id entered
89                 redirectToUrl('modules.php?module=index');
90         }
91
92         if (SQL_NUMROWS($result_link) == 1) {
93                 // Load the entry
94                 list($ltype) = SQL_FETCHROW($result_link);
95
96                 // @TODO Rewrite this to a filter
97                 switch ($ltype) {
98                         case 'NORMAL':
99                                 // Is the stats id valid?
100                                 $result = SQL_QUERY_ESC("SELECT `pool_id`,`url`,`subject` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
101                                         array($mailId), __FILE__, __LINE__);
102                                 break;
103
104                         case 'BONUS':
105                                 // Is the bonus extension active?
106                                 redirectOnUninstalledExtension('bonus');
107
108                                 // Bonus-Mails
109                                 $result = SQL_QUERY_ESC("SELECT `id`,`url`,`subject` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
110                                         array($bonusId), __FILE__, __LINE__);
111                                 break;
112
113                         default: // Invalid mail type
114                                 debug_report_bug(__FILE__, __LINE__, 'Invalid mail type ' . $ltype . ' detected.');
115                                 break;
116                 } // END - switch
117
118                 if (SQL_NUMROWS($result) == 1) {
119                         // Load data
120                         list($pool, $url, $title) = SQL_FETCHROW($result);
121
122                         // Free result
123                         SQL_FREERESULT($result);
124
125                         // Set it
126                         setExtraTitle($title);
127
128                         // Is the user's id unlocked?
129                         if (fetchUserData($userId)) {
130                                 // Status must be CONFIRMED
131                                 if (getUserData('status') == 'CONFIRMED') {
132                                         // Update last activity if not admin
133                                         if ((!isAdmin()) || (isDebugModeEnabled())) {
134                                                 // Is not admin, so update last activity
135                                                 updateLastActivity($userId);
136                                         } // END - if
137
138                                         // User has confirmed his account so we can procede...
139                                         // @TODO Rewrite this to a filter
140                                         switch ($ltype) {
141                                                 case 'NORMAL':
142                                                         $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
143                                                                 array(bigintval($pool)), __FILE__, __LINE__);
144                                                         if (SQL_NUMROWS($result) == 1) {
145                                                                 list($pay) = SQL_FETCHROW($result);
146                                                                 $time      = getPaymentPoints($pay, 'time');
147                                                                 $payment   = getPaymentPoints($pay, 'payment');
148                                                                 $isValid   = true;
149                                                         } // END - if
150
151                                                         // Free memory
152                                                         SQL_FREERESULT($result);
153                                                         break;
154
155                                                 case 'BONUS':
156                                                         $result = SQL_QUERY_ESC("SELECT `points`,`time` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
157                                                                 array($bonusId), __FILE__, __LINE__);
158                                                         if (SQL_NUMROWS($result) == 1) {
159                                                                 list($points, $time) = SQL_FETCHROW($result);
160                                                                 $payment = '0.00000';
161                                                                 $isValid = true;
162                                                         } // END - if
163
164                                                         // Free memory
165                                                         SQL_FREERESULT($result);
166                                                         break;
167
168                                                 default: // Invalid mail type
169                                                         debug_report_bug(__FILE__, __LINE__, 'Invalid mail type ' . $ltype . ' detected.');
170                                                         break;
171                                         }
172
173                                         // Add header
174                                         loadIncludeOnce('inc/header.php');
175
176                                         // Was that mail a valid one?
177                                         if ($isValid === true) {
178                                                 // If time is zero seconds we have a sponsor mail. 1 Second shall be set to avoid problems
179                                                 if (($time == '0') && ($payment > 0)) { 
180                                                         $url = getUrl();
181                                                         $time = 1; 
182                                                 } // END - if
183
184                                                 if (($time > 0) && (($payment > 0) || ($points > 0))) {
185                                                         // Set HTTP status to okay
186                                                         setHttpStatus('200 OK');
187
188                                                         // Export data into constants for the template
189                                                         $content = array(
190                                                                 'userid'  => $userId,
191                                                                 'type'    => $type,
192                                                                 'data'    => $urlId,
193                                                                 'url'     => $url
194                                                         );
195
196                                                         // Load template
197                                                         loadTemplate('mailid_frames', false, $content);
198                                                 } else {
199                                                         $errorCode = getCode('DATA_INVALID');
200                                                 }
201                                         } else {
202                                                 $errorCode = getCode('POSSIBLE_INVALID');
203                                         }
204                                 } else {
205                                         $errorCode = getCode('ACCOUNT_' . getUserData('status'));
206                                 }
207                         } else {
208                                 $errorCode = getCode('USER_404');
209                         }
210                 } else {
211                         $errorCode = getCode('STATS_404');
212                 }
213         } else {
214                 $errorCode = getCode('ALREADY_CONFIRMED');
215         }
216
217         // Free result
218         SQL_FREERESULT($result_link);
219 } else {
220         // Nothing entered
221         $errorCode = getCode('ERROR_MAILID');
222 }
223
224 // Error code is set?
225 handleMailIdErrorCode($errorCode);
226
227 // Include footer
228 loadIncludeOnce('inc/footer.php');
229
230 // [EOF]
231 ?>