dcd0208ad0247cb47df77dee388cbd3e6d08ace6
[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  * $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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Load security stuff here
40 require('inc/libs/security_functions.php');
41
42 // Init start time
43 $GLOBALS['startTime'] = microtime(true);
44
45 // Tell everyone we are in this module
46 $GLOBALS['module'] = 'mailid';
47 $GLOBALS['output_mode'] = -1;
48 $errorCode = '';
49
50 // Load the required file(s)
51 require('inc/config-global.php');
52
53 // Set content type
54 setContentType('text/html');
55
56 // Is the extension active?
57 redirectOnUninstalledExtension('mailid');
58
59 // Init
60 $url_userid = 0;
61 $url_bid = 0;
62 $url_mid = 0;
63
64 // Secure all data
65 if (isGetRequestElementSet('userid'))  $url_userid = bigintval(getRequestElement('userid'));
66 if (isGetRequestElementSet('mailid'))  $url_mid    = bigintval(getRequestElement('mailid'));
67 if (isGetRequestElementSet('bonusid')) $url_bid    = bigintval(getRequestElement('bonusid'));
68
69 // 01           1        12            2    2            21    1                   22     10
70 if (($url_userid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (getTotalFatalErrors() == 0)) {
71         // Init result
72         $result_link = false;
73
74         // Maybe he wants to confirm an email?
75         if ($url_mid > 0) {
76                 // Normal-Mails
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($url_mid, $url_userid), __FILE__, __LINE__);
79                 $type = 'mailid'; $urlId = $url_mid;
80         } elseif ($url_bid > 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($url_bid, $url_userid), __FILE__, __LINE__);
84                 $type = 'bonusid'; $urlId = $url_bid;
85         } else {
86                 // Problem: No ID entered
87                 redirectToUrl('index.php');
88         }
89
90         if (SQL_NUMROWS($result_link) == 1) {
91                 // Load the entry
92                 list($ltype) = SQL_FETCHROW($result);
93
94                 // Clean result
95                 SQL_FREERESULT($result);
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('Invalid mail type ' . $ltype . ' detected.');
116                                 break;
117                 }
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                         $result = SQL_QUERY_ESC("SELECT `status`, `gender`, `surname`, `family` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
131                                 array($url_userid), __FILE__, __LINE__);
132                         if (SQL_NUMROWS($result) == 1) {
133                                 list($status, $gender, $surname, $family) = SQL_FETCHROW($result);
134                                 SQL_FREERESULT($result);
135                                 if ($status == 'CONFIRMED') {
136                                         // User has confirmed his account so we can procede...
137                                         // @TODO Rewrite this to a filter
138                                         switch ($ltype) {
139                                                 case 'NORMAL':
140                                                         $result = SQL_QUERY_ESC("SELECT payment_id FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
141                                                                 array(bigintval($pool)), __FILE__, __LINE__);
142                                                         if (SQL_NUMROWS($result) == 1) {
143                                                                 list($pay) = SQL_FETCHROW($result);
144                                                                 $time      = getPaymentPoints($pay, 'time');
145                                                                 $payment   = getPaymentPoints($pay, 'payment');
146                                                                 $isValid   = true;
147                                                         } // END - if
148
149                                                         // Free memory
150                                                         SQL_FREERESULT($result);
151                                                         break;
152
153                                                 case 'BONUS':
154                                                         $result = SQL_QUERY_ESC("SELECT points, time FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
155                                                                 array($url_bid), __FILE__, __LINE__);
156                                                         if (SQL_NUMROWS($result) == 1) {
157                                                                 list($points, $time) = SQL_FETCHROW($result);
158                                                                 $payment = '0.00000';
159                                                                 $isValid = true;
160                                                         }
161
162                                                         // Free memory
163                                                         SQL_FREERESULT($result);
164                                                         break;
165
166                                                 default: // Invalid mail type
167                                                         debug_report_bug('Invalid mail type ' . $ltype . ' detected.');
168                                                         break;
169                                         }
170
171                                         // Add header
172                                         loadIncludeOnce('inc/header.php');
173
174                                         // Was that mail a valid one?
175                                         if ($isValid === true) {
176                                                 // If time is zero seconds we have a sponsor mail. 1 Second shall be set to avoid problems
177                                                 if (($time == 0) && ($payment > 0)) { $URL = getConfig('URL'); $time = 1; }
178                                                 if (($time > 0) && (($payment > 0) || ($points > 0))) {
179                                                         // Export data into constants for the template
180                                                         $content = array(
181                                                                 'userid'  => $url_userid,
182                                                                 'type' => $type,
183                                                                 'data' => $urlId,
184                                                                 'url'  => generateDerefererUrl($URL)
185                                                         );
186
187                                                         // Load template
188                                                         loadTemplate('mailid_frames', false, $content);
189                                                 } else {
190                                                         $errorCode = getCode('DATA_INVALID');
191                                                 }
192                                         } else {
193                                                 $errorCode = getCode('POSSIBLE_INVALID');
194                                         }
195                                 } else {
196                                         $errorCode = getCode('ACCOUNT_' . $status);
197                                 }
198                         } else {
199                                 SQL_FREERESULT($result);
200                                 $errorCode = getCode('USER_404');
201                         }
202                 } else {
203                         SQL_FREERESULT($result);
204                         $errorCode = getCode('STATS_404');
205                 }
206         } else {
207                 SQL_FREERESULT($result);
208                 $errorCode = getCode('ALREADY_CONFIRMED');
209         }
210 } else {
211         // Nothing entered
212         $errorCode = getCode('ERROR_MAILID');
213 }
214
215 // Error code is set?
216 if (!empty($errorCode)) {
217         // @TODO Rewrite this to a dynamic include or so
218         switch (getConfig('mailid_error_redirect')) {
219                 case 'INDEX': // Redirect to index page
220                         redirectToUrl('modules.php?module=index&amp;code=' . $errorCode . '&amp;ext=mailid');
221                         break;
222
223                 case 'REJECT': // Redirect to rejection page
224                         if (isExtensionActive('other')) {
225                                 // Redirect to configured URL
226                                 redirectToConfiguredUrl('reject_url');
227                         } else {
228                                 // Redirect to index
229                                 redirectToUrl('index.php');
230                         }
231                         break;
232
233                 default:
234                         logDebugMessage(__FILE__, __LINE__, sprintf("Unknown status %s detected in mailid_error_redirect.", getConfig('mailid_error_redirect')));
235                         redirectToUrl('modules.php?module=index&amp;code=' . getCode('UNKNOWN_STATUS') . '&amp;ext=mailid');
236                         break;
237         } // END - switch
238 } // END - if
239
240 // Include footer
241 loadIncludeOnce('inc/footer.php');
242
243 // [EOF]
244 ?>