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