TODOs.txt updated
[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            3    32           21    1                   22     10
70 if (($url_userid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (getTotalFatalErrors() == 0)) {
71         // Maybe he wants to confirm an email?
72         if ($url_mid > 0) {
73                 // Normal-Mails
74                 $result = SQL_QUERY_ESC("SELECT `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
75                         array($url_mid, $url_userid), __FILE__, __LINE__);
76                 $type = 'mailid'; $urlId = $url_mid;
77         } elseif ($url_bid > 0) {
78                 // Bonus-Mail
79                 $result = SQL_QUERY_ESC("SELECT `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
80                         array($url_bid, $url_userid), __FILE__, __LINE__);
81                 $type = 'bonusid'; $urlId = $url_bid;
82         } else {
83                 // Problem: No ID entered
84                 redirectToUrl('index.php');
85         }
86
87         if (SQL_NUMROWS($result) == 1) {
88                 // Load the entry
89                 list($ltype) = SQL_FETCHROW($result);
90
91                 // Clean result
92                 SQL_FREERESULT($result);
93
94                 // @TODO Rewrite this to a filter
95                 switch ($ltype)
96                 {
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($url_mid), __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($url_bid), __FILE__, __LINE__);
110                                 break;
111
112                         default: // Invalid mail type
113                                 debug_report_bug('Invalid mail type ' . $ltype . ' detected.');
114                                 break;
115                 }
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                         $result = SQL_QUERY_ESC("SELECT `status`, `gender`, `surname`, `family` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
129                                 array($url_userid), __FILE__, __LINE__);
130                         if (SQL_NUMROWS($result) == 1) {
131                                 list($status, $gender, $surname, $family) = SQL_FETCHROW($result);
132                                 SQL_FREERESULT($result);
133                                 if ($status == 'CONFIRMED') {
134                                         // User has confirmed his account so we can procede...
135                                         // @TODO Rewrite this to a filter
136                                         switch ($ltype)
137                                         {
138                                                 case 'NORMAL':
139                                                         $result = SQL_QUERY_ESC("SELECT payment_id FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
140                                                                 array(bigintval($pool)), __FILE__, __LINE__);
141                                                         if (SQL_NUMROWS($result) == 1) {
142                                                                 list($pay) = SQL_FETCHROW($result);
143                                                                 $time      = getPaymentPoints($pay, 'time');
144                                                                 $payment   = getPaymentPoints($pay, 'payment');
145                                                                 $isValid   = true;
146                                                         } // END - if
147
148                                                         // Free memory
149                                                         SQL_FREERESULT($result);
150                                                         break;
151
152                                                 case 'BONUS':
153                                                         $result = SQL_QUERY_ESC("SELECT points, time FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
154                                                                 array($url_bid), __FILE__, __LINE__);
155                                                         if (SQL_NUMROWS($result) == 1) {
156                                                                 list($points, $time) = SQL_FETCHROW($result);
157                                                                 $payment = '0.00000';
158                                                                 $isValid = true;
159                                                         }
160
161                                                         // Free memory
162                                                         SQL_FREERESULT($result);
163                                                         break;
164
165                                                 default: // Invalid mail type
166                                                         debug_report_bug('Invalid mail type ' . $ltype . ' detected.');
167                                                         break;
168                                         }
169
170                                         // Add header
171                                         loadIncludeOnce('inc/header.php');
172
173                                         // Was that mail a valid one?
174                                         if ($isValid === true) {
175                                                 // If time is zero seconds we have a sponsor mail. 1 Second shall be set to avoid problems
176                                                 if (($time == '0') && ($payment > 0)) { $URL = getConfig('URL'); $time = '1'; }
177                                                 if (($time > 0) && (($payment > 0) || ($points > 0))) {
178                                                         // Export data into constants for the template
179                                                         $content = array(
180                                                                 'userid'  => $url_userid,
181                                                                 'type' => $type,
182                                                                 'data' => $urlId,
183                                                                 'url'  => generateDerefererUrl($URL)
184                                                         );
185
186                                                         // Load template
187                                                         loadTemplate('mailid_frames', false, $content);
188                                                 } else {
189                                                         $errorCode = getCode('DATA_INVALID');
190                                                 }
191                                         } else {
192                                                 $errorCode = getCode('POSSIBLE_INVALID');
193                                         }
194                                 } else {
195                                         $errorCode = getCode('ACCOUNT_LOCKED');
196                                 }
197                         } else {
198                                 SQL_FREERESULT($result);
199                                 $errorCode = getCode('USER_404');
200                         }
201                 } else {
202                         SQL_FREERESULT($result);
203                         $errorCode = getCode('STATS_404');
204                 }
205         } else {
206                 SQL_FREERESULT($result);
207                 $errorCode = getCode('ALREADY_CONFIRMED');
208         }
209 } else {
210         // Nothing entered
211         $errorCode = getCode('ERROR_MAILID');
212 }
213
214 // Error code is set?
215 if (!empty($errorCode)) {
216         // @TODO Rewrite this to a dynamic include or so
217         switch (getConfig('mailid_error_redirect')) {
218                 case 'INDEX': // Redirect to index page
219                         redirectToUrl('modules.php?module=index&amp;code=' . $errorCode . '&amp;ext=mailid');
220                         break;
221
222                 case 'REJECT': // Redirect to rejection page
223                         if (isExtensionActive('other')) {
224                                 // Redirect to configured URL
225                                 redirectToConfiguredUrl('reject_url');
226                         } else {
227                                 // Redirect to index
228                                 redirectToUrl('index.php');
229                         }
230                         break;
231
232                 default:
233                         logDebugMessage(__FILE__, __LINE__, sprintf("Unknown status %s detected in mailid_error_redirect.", getConfig('mailid_error_redirect')));
234                         redirectToUrl('modules.php?module=index&amp;code=' . getCode('UNKNOWN_STATUS') . '&amp;ext=mailid');
235                         break;
236         } // END - switch
237 } // END - if
238
239 // Include footer
240 loadIncludeOnce('inc/footer.php');
241
242 // [EOF]
243 ?>