New template helper function doTemplateExtensionRegistrationLink() introduced
[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  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Load security stuff here
41 require('inc/libs/security_functions.php');
42
43 // Init start time
44 $GLOBALS['startTime'] = microtime(true);
45
46 // Tell everyone we are in this module
47 $GLOBALS['module'] = 'mailid';
48 $GLOBALS['output_mode'] = -1;
49 $errorCode = '';
50
51 // Load the required file(s)
52 require('inc/config-global.php');
53
54 // Set content type
55 setContentType('text/html');
56
57 // Is the extension active?
58 redirectOnUninstalledExtension('mailid');
59
60 // Init
61 $url_userid = '0';
62 $url_bid    = '0';
63 $url_mid    = '0';
64
65 // Secure all data
66 if (isGetRequestParameterSet('userid'))  $url_userid = bigintval(getRequestParameter('userid'));
67 if (isGetRequestParameterSet('mailid'))  $url_mid    = bigintval(getRequestParameter('mailid'));
68 if (isGetRequestParameterSet('bonusid')) $url_bid    = bigintval(getRequestParameter('bonusid'));
69
70 // 01           1        12            2    2            21    1                      2210
71 if ((isValidUserId($url_userid)) && (($url_mid > 0) || ($url_bid > 0)) && (!ifFatalErrorsDetected())) {
72         // Init result
73         $result_link = false;
74
75         // Maybe he wants to confirm an email?
76         if ($url_mid > 0) {
77                 // Normal-Mails
78                 $result_link = SQL_QUERY_ESC("SELECT `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
79                         array($url_mid, $url_userid), __FILE__, __LINE__);
80                 $type = 'mailid';
81                 $urlId = $url_mid;
82         } elseif ($url_bid > 0) {
83                 // Bonus-Mail
84                 $result_link = SQL_QUERY_ESC("SELECT `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
85                         array($url_bid, $url_userid), __FILE__, __LINE__);
86                 $type = 'bonusid';
87                 $urlId = $url_bid;
88         } else {
89                 // Problem: No id entered
90                 redirectToUrl('modules.php?module=index');
91         }
92
93         if (SQL_NUMROWS($result_link) == 1) {
94                 // Load the entry
95                 list($ltype) = SQL_FETCHROW($result_link);
96
97                 // @TODO Rewrite this to a filter
98                 switch ($ltype) {
99                         case 'NORMAL':
100                                 // Is the stats id valid?
101                                 $result = SQL_QUERY_ESC("SELECT `pool_id`, `url`, `subject` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
102                                         array($url_mid), __FILE__, __LINE__);
103                                 break;
104
105                         case 'BONUS':
106                                 // Is the bonus extension active?
107                                 redirectOnUninstalledExtension('bonus');
108
109                                 // Bonus-Mails
110                                 $result = SQL_QUERY_ESC("SELECT id, url, subject FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
111                                         array($url_bid), __FILE__, __LINE__);
112                                 break;
113
114                         default: // Invalid mail type
115                                 debug_report_bug(__FILE__, __LINE__, 'Invalid mail type ' . $ltype . ' detected.');
116                                 break;
117                 } // END - switch
118
119                 if (SQL_NUMROWS($result) == 1) {
120                         // Load data
121                         list($pool, $URL, $title) = SQL_FETCHROW($result);
122
123                         // Free result
124                         SQL_FREERESULT($result);
125
126                         // Set it
127                         setExtraTitle($title);
128
129                         // Is the user's id unlocked?
130                         if (fetchUserData($url_userid)) {
131                                 // Status must be CONFIRMED
132                                 if (getUserData('status') == 'CONFIRMED') {
133                                         // Update last activity if not admin
134                                         if (!isAdmin()) {
135                                                 // Is not admin, so update last activity
136                                                 updateLastActivity($url_userid);
137                                         } // END - if
138
139                                         // User has confirmed his account so we can procede...
140                                         // @TODO Rewrite this to a filter
141                                         switch ($ltype) {
142                                                 case 'NORMAL':
143                                                         $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
144                                                                 array(bigintval($pool)), __FILE__, __LINE__);
145                                                         if (SQL_NUMROWS($result) == 1) {
146                                                                 list($pay) = SQL_FETCHROW($result);
147                                                                 $time      = getPaymentPoints($pay, 'time');
148                                                                 $payment   = getPaymentPoints($pay, 'payment');
149                                                                 $isValid   = true;
150                                                         } // END - if
151
152                                                         // Free memory
153                                                         SQL_FREERESULT($result);
154                                                         break;
155
156                                                 case 'BONUS':
157                                                         $result = SQL_QUERY_ESC("SELECT `points`, `time` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
158                                                                 array($url_bid), __FILE__, __LINE__);
159                                                         if (SQL_NUMROWS($result) == 1) {
160                                                                 list($points, $time) = SQL_FETCHROW($result);
161                                                                 $payment = '0.00000';
162                                                                 $isValid = true;
163                                                         } // END - if
164
165                                                         // Free memory
166                                                         SQL_FREERESULT($result);
167                                                         break;
168
169                                                 default: // Invalid mail type
170                                                         debug_report_bug(__FILE__, __LINE__, 'Invalid mail type ' . $ltype . ' detected.');
171                                                         break;
172                                         }
173
174                                         // Add header
175                                         loadIncludeOnce('inc/header.php');
176
177                                         // Was that mail a valid one?
178                                         if ($isValid === true) {
179                                                 // If time is zero seconds we have a sponsor mail. 1 Second shall be set to avoid problems
180                                                 if (($time == '0') && ($payment > 0)) { 
181                                                         $URL = getUrl();
182                                                         $time = 1; 
183                                                 } // END - if
184
185                                                 if (($time > 0) && (($payment > 0) || ($points > 0))) {
186                                                         // Export data into constants for the template
187                                                         $content = array(
188                                                                 'userid'  => $url_userid,
189                                                                 'type'    => $type,
190                                                                 'data'    => $urlId,
191                                                                 'url'     => $URL
192                                                         );
193
194                                                         // Load template
195                                                         loadTemplate('mailid_frames', false, $content);
196                                                 } else {
197                                                         $errorCode = getCode('DATA_INVALID');
198                                                 }
199                                         } else {
200                                                 $errorCode = getCode('POSSIBLE_INVALID');
201                                         }
202                                 } else {
203                                         $errorCode = getCode('ACCOUNT_' . getUserData('status'));
204                                 }
205                         } else {
206                                 $errorCode = getCode('USER_404');
207                         }
208                 } else {
209                         $errorCode = getCode('STATS_404');
210                 }
211         } else {
212                 $errorCode = getCode('ALREADY_CONFIRMED');
213         }
214
215         // Free result
216         SQL_FREERESULT($result_link);
217 } else {
218         // Nothing entered
219         $errorCode = getCode('ERROR_MAILID');
220 }
221
222 // Error code is set?
223 handleMailIdErrorCode($errorCode);
224
225 // Include footer
226 loadIncludeOnce('inc/footer.php');
227
228 // [EOF]
229 ?>