2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 11/14/2003 *
4 * =================== Last change: 01/10/2013 *
6 * -------------------------------------------------------------------- *
8 * -------------------------------------------------------------------- *
9 * Short description : Confirmation file for emails *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Bestaetigung von Mails *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2013 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
36 ************************************************************************/
38 // Load security stuff here
39 require('inc/libs/security_functions.php');
42 $GLOBALS['__start_time'] = microtime(TRUE);
44 // Tell everyone we are in this module
45 $GLOBALS['__module'] = 'mailid';
46 $GLOBALS['__output_mode'] = '0';
48 // Disable copyright footer which would be to large for the upper frame
49 $GLOBALS['__copyright_enabled'] = 'N';
51 // Load the required file(s)
52 require('inc/config-global.php');
54 // Set content type and HTTP status
55 setContentType('text/html');
56 setHttpStatus('404 Not Found');
58 // Is ext-mailid active?
59 redirectOnUninstalledExtension('mailid');
61 // Is ext-other active?
62 redirectOnUninstalledExtension('other');
75 if (isGetRequestElementSet('userid')) $data['userid'] = bigintval(getRequestElement('userid'));
76 if (isGetRequestElementSet('id')) $data['id'] = bigintval(getRequestElement('id'));
77 if (isGetRequestElementSet('code')) $data['code'] = bigintval(getRequestElement('code'));
78 if (isGetRequestElementSet('do')) $data['do'] = getRequestElement('do');
79 if (isGetRequestElementSet('type')) $data['type'] = getRequestElement('type');
81 // @TODO Improve check on $data['type'], empty() is not very much ...
82 if ((isValidId($data['userid'])) && (isValidId($data['id'])) && (!empty($data['type'])) && (!ifFatalErrorsDetected())) {
83 // Is 'do' still "frames"?
84 if ($data['do'] == 'frames') {
85 // This is a frameset module
86 $GLOBALS['frameset_mode'] = TRUE;
90 if ($data['do'] != 'img') {
91 // ... then output header
92 loadIncludeOnce('inc/header.php');
95 // Init result for below sqlNumRows() function
98 // Maybe he wants to confirm an email?
99 switch ($data['type']) {
101 $result_main = sqlQueryEscaped("SELECT `id` AS `link_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
102 array($data['id'], $data['userid']), __FILE__, __LINE__);
106 $result_main = sqlQueryEscaped("SELECT `id` AS `link_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
107 array($data['id'], $data['userid']), __FILE__, __LINE__);
110 default: // Not detected
111 reportBug(__FILE__, __LINE__, 'No valid type=' . $data['type'] . ' set.');
115 // Is an entry found?
116 if (sqlNumRows($result_main) == 1) {
117 // Is the stats id valid?
118 $data = merge_array($data, sqlFetchArray($result_main));
120 // Init result here with invalid to avoid possible missing variable
121 $result_mailid = FALSE;
123 // @TODO Rewrite this to a filter/function
124 switch ($data['link_type']) {
126 $result_mailid = sqlQueryEscaped("SELECT `pool_id`, `userid` AS `sender`, `url` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
127 array($data['id']), __FILE__, __LINE__);
131 $result_mailid = sqlQueryEscaped("SELECT `id` AS `pool_id`, `is_notify`, `url` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
132 array($data['id']), __FILE__, __LINE__);
135 default: // Unknown type
136 reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
141 if (sqlNumRows($result_mailid) == 1) {
143 $data = merge_array($data, sqlFetchArray($result_mailid));
145 // Correct notification switch in non-bonus mails
146 if ((!isset($data['is_notify'])) || (!in_array($data['is_notify'], array('Y', 'N')))) {
147 $data['is_notify'] = 'N';
150 // Set sender to 0 when we have a bonus mail
151 if ($data['link_type'] == 'BONUS') {
152 $data['sender'] = NULL;
155 // Is the user id valid?
156 if (fetchUserData($data['userid']) === TRUE) {
157 // Is the user status CONFIRMED?
158 if (getUserData('status') == 'CONFIRMED') {
159 // User has confirmed his account so we can procede...
160 // @TODO Rewrite this to a filter
161 switch ($data['link_type']) {
163 $result = sqlQueryEscaped("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
164 array(bigintval($data['pool_id'])), __FILE__, __LINE__);
167 if (sqlNumRows($result) == 1) {
168 $data = merge_array($data, sqlFetchArray($result));
169 $data['time'] = getPaymentTime($data['payment_id']);
170 $data['payment'] = getPaymentPayment($data['payment_id']);
175 sqlFreeResult($result);
179 $result = sqlQueryEscaped("SELECT `time`, `points` AS `payment` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
180 array(bigintval($data['pool_id'])), __FILE__, __LINE__);
183 if (sqlNumRows($result) == 1) {
184 $data = merge_array($data, sqlFetchArray($result));
189 sqlFreeResult($result);
192 default: // Unknown type
193 reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
197 // Is this entry valid?
198 if ($isValid === TRUE) {
199 // Run at least one second
200 if (($data['time'] < 1) && ($data['payment'] > 0)) {
201 // Zero seconds is not supported
205 // Is time and payment set?
206 if (($data['time'] > 0) && ($data['payment'] > 0)) {
207 $data['real_code'] = '0';
208 if (!empty($data['code'])) {
209 // Generate code (the user sees in the CAPTCHA)
210 $data['real_code'] = generateRandomCode(getCodeLength(), $data['code'], $data['userid'], $data['id']);
213 // Do the call-back by given data array
214 doMailIdCallback($data);
216 $data['error_code'] = getCode('DATA_INVALID');
217 $data['do'] = 'failed';
220 $data['error_code'] = getCode('POSSIBLE_INVALID');
221 $data['do'] = 'failed';
224 $data['error_code'] = getCode('ACCOUNT_' . strtoupper(getUserData('status')));
225 $data['do'] = 'failed';
228 $data['error_code'] = getCode('USER_404');
229 $data['do'] = 'failed';
232 $data['error_code'] = getCode('STATS_404');
233 $data['do'] = 'failed';
237 sqlFreeResult($result_mailid);
239 $data['error_code'] = getCode('ALREADY_CONFIRMED');
240 $data['do'] = 'failed';
244 sqlFreeResult($result_main);
246 // Not all variables are set
247 $data['error_code'] = getCode('ERROR_MAILID');
248 $data['do'] = 'failed';
251 // Error code is set?
252 handleMailIdErrorCode($data['error_code']);
254 // Insert footer if no image
255 if ($data['do'] != 'img') {
257 loadIncludeOnce('inc/footer.php');
260 // Really all done here... ;-)