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