Removed comment introduced by Profi-Concept, this comment should fine (in a much...
[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, 2010 by Mailer Developer Team                    *
20  * For more information visit: http://www.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
53 setContentType('text/html');
54
55 // Is the extension active?
56 redirectOnUninstalledExtension('mailid');
57
58 // Init
59 $userId = '0';
60 $bonusId    = '0';
61 $mailId    = '0';
62
63 // Secure all data
64 if (isGetRequestParameterSet('userid'))  $userId  = bigintval(getRequestParameter('userid'));
65 if (isGetRequestParameterSet('mailid'))  $mailId  = bigintval(getRequestParameter('mailid'));
66 if (isGetRequestParameterSet('bonusid')) $bonusId = bigintval(getRequestParameter('bonusid'));
67
68 // 01           1        12            2    2            21    1                      2210
69 if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalErrorsDetected())) {
70         // Init result
71         $result_link = false;
72
73         // Maybe he wants to confirm an email?
74         if ($mailId > 0) {
75                 // Normal-Mails
76                 $result_link = SQL_QUERY_ESC("SELECT `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
77                         array($mailId, $userId), __FILE__, __LINE__);
78                 $type = 'mailid';
79                 $urlId = $mailId;
80         } elseif ($bonusId > 0) {
81                 // Bonus-Mail
82                 $result_link = SQL_QUERY_ESC("SELECT `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
83                         array($bonusId, $userId), __FILE__, __LINE__);
84                 $type = 'bonusid';
85                 $urlId = $bonusId;
86         } else {
87                 // Problem: No id entered
88                 redirectToUrl('modules.php?module=index');
89         }
90
91         if (SQL_NUMROWS($result_link) == 1) {
92                 // Load the entry
93                 list($ltype) = SQL_FETCHROW($result_link);
94
95                 // @TODO Rewrite this to a filter
96                 switch ($ltype) {
97                         case 'NORMAL':
98                                 // Is the stats id valid?
99                                 $result = SQL_QUERY_ESC("SELECT `pool_id`, `url`, `subject` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
100                                         array($mailId), __FILE__, __LINE__);
101                                 break;
102
103                         case 'BONUS':
104                                 // Is the bonus extension active?
105                                 redirectOnUninstalledExtension('bonus');
106
107                                 // Bonus-Mails
108                                 $result = SQL_QUERY_ESC("SELECT id, url, subject FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
109                                         array($bonusId), __FILE__, __LINE__);
110                                 break;
111
112                         default: // Invalid mail type
113                                 debug_report_bug(__FILE__, __LINE__, 'Invalid mail type ' . $ltype . ' detected.');
114                                 break;
115                 } // END - switch
116
117                 if (SQL_NUMROWS($result) == 1) {
118                         // Load data
119                         list($pool, $URL, $title) = SQL_FETCHROW($result);
120
121                         // Free result
122                         SQL_FREERESULT($result);
123
124                         // Set it
125                         setExtraTitle($title);
126
127                         // Is the user's id unlocked?
128                         if (fetchUserData($userId)) {
129                                 // Status must be CONFIRMED
130                                 if (getUserData('status') == 'CONFIRMED') {
131                                         // Update last activity if not admin
132                                         if (!isAdmin()) {
133                                                 // Is not admin, so update last activity
134                                                 updateLastActivity($userId);
135                                         } // END - if
136
137                                         // User has confirmed his account so we can procede...
138                                         // @TODO Rewrite this to a filter
139                                         switch ($ltype) {
140                                                 case 'NORMAL':
141                                                         $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
142                                                                 array(bigintval($pool)), __FILE__, __LINE__);
143                                                         if (SQL_NUMROWS($result) == 1) {
144                                                                 list($pay) = SQL_FETCHROW($result);
145                                                                 $time      = getPaymentPoints($pay, 'time');
146                                                                 $payment   = getPaymentPoints($pay, 'payment');
147                                                                 $isValid   = true;
148                                                         } // END - if
149
150                                                         // Free memory
151                                                         SQL_FREERESULT($result);
152                                                         break;
153
154                                                 case 'BONUS':
155                                                         $result = SQL_QUERY_ESC("SELECT `points`, `time` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
156                                                                 array($bonusId), __FILE__, __LINE__);
157                                                         if (SQL_NUMROWS($result) == 1) {
158                                                                 list($points, $time) = SQL_FETCHROW($result);
159                                                                 $payment = '0.00000';
160                                                                 $isValid = true;
161                                                         } // END - if
162
163                                                         // Free memory
164                                                         SQL_FREERESULT($result);
165                                                         break;
166
167                                                 default: // Invalid mail type
168                                                         debug_report_bug(__FILE__, __LINE__, 'Invalid mail type ' . $ltype . ' detected.');
169                                                         break;
170                                         }
171
172                                         // Add header
173                                         loadIncludeOnce('inc/header.php');
174
175                                         // Was that mail a valid one?
176                                         if ($isValid === true) {
177                                                 // If time is zero seconds we have a sponsor mail. 1 Second shall be set to avoid problems
178                                                 if (($time == '0') && ($payment > 0)) { 
179                                                         $URL = getUrl();
180                                                         $time = 1; 
181                                                 } // END - if
182
183                                                 if (($time > 0) && (($payment > 0) || ($points > 0))) {
184                                                         // Export data into constants for the template
185                                                         $content = array(
186                                                                 'userid'  => $userId,
187                                                                 'type'    => $type,
188                                                                 'data'    => $urlId,
189                                                                 'url'     => $URL
190                                                         );
191
192                                                         // Load template
193                                                         loadTemplate('mailid_frames', false, $content);
194                                                 } else {
195                                                         $errorCode = getCode('DATA_INVALID');
196                                                 }
197                                         } else {
198                                                 $errorCode = getCode('POSSIBLE_INVALID');
199                                         }
200                                 } else {
201                                         $errorCode = getCode('ACCOUNT_' . getUserData('status'));
202                                 }
203                         } else {
204                                 $errorCode = getCode('USER_404');
205                         }
206                 } else {
207                         $errorCode = getCode('STATS_404');
208                 }
209         } else {
210                 $errorCode = getCode('ALREADY_CONFIRMED');
211         }
212
213         // Free result
214         SQL_FREERESULT($result_link);
215 } else {
216         // Nothing entered
217         $errorCode = getCode('ERROR_MAILID');
218 }
219
220 // Error code is set?
221 handleMailIdErrorCode($errorCode);
222
223 // Include footer
224 loadIncludeOnce('inc/footer.php');
225
226 // [EOF]
227 ?>