2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 11/14/2003 *
4 * =================== Last change: 11/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : mailid_top.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Confirmation file for emails *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Bestaetigung von Mails *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * @TODO Merge this script with mailid.php *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
22 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
38 ************************************************************************/
40 // Load security stuff here
41 require('inc/libs/security_functions.php');
44 $GLOBALS['__start_time'] = microtime(true);
46 // Tell everyone we are in this module
47 $GLOBALS['__module'] = 'mailid';
48 $GLOBALS['__output_mode'] = '0';
50 // Disable copyright footer which would be to large for the upper frame
51 $GLOBALS['__copyright_enabled'] = 'N';
53 // Load the required file(s)
54 require('inc/config-global.php');
56 // Set content type and HTTP status
57 setContentType('text/html');
58 setHttpStatus('404 Not Found');
60 // Is the extension mailid active?
61 redirectOnUninstalledExtension('mailid');
63 // Is the extension other active?
64 redirectOnUninstalledExtension('other');
74 if (isGetRequestElementSet('userid')) $userId = bigintval(getRequestElement('userid'));
75 if (isGetRequestElementSet('mailid')) $mailId = bigintval(getRequestElement('mailid'));
76 if (isGetRequestElementSet('bonusid')) $bonusId = bigintval(getRequestElement('bonusid'));
77 if (isGetRequestElementSet('code')) $code = bigintval(getRequestElement('code'));
78 if (isGetRequestElementSet('do')) $do = getRequestElement('do');
80 // 01 2 21 12 2 2 21 1 2210
81 if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalErrorsDetected())) {
84 // ... then output header
85 loadIncludeOnce('inc/header.php');
88 // Maybe he wants to confirm an email?
90 $result_main = SQL_QUERY_ESC("SELECT `id` AS `link_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
91 array($mailId, $userId), __FILE__, __LINE__);
94 } elseif ($bonusId > 0) {
95 $result_main = SQL_QUERY_ESC("SELECT `id` AS `link_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
96 array($bonusId, $userId), __FILE__, __LINE__);
101 reportBug(__FILE__, __LINE__, 'Whether bonusid or mailid was set. This is a strange bug.');
104 // Is an entry found?
105 if (SQL_NUMROWS($result_main) == 1) {
106 // Is the stats id valid?
107 $data = SQL_FETCHARRAY($result_main);
109 // Init result here with invalid to avoid possible missing variable
110 $result_mailid = false;
112 // @TODO Rewrite this to a filter/function
113 switch ($data['link_type']) {
115 $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`, `userid` AS `sender` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
116 array($urlId), __FILE__, __LINE__);
120 $result_mailid = SQL_QUERY_ESC("SELECT `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
121 array($urlId), __FILE__, __LINE__);
124 default: // Unknown type
125 reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
130 if (SQL_NUMROWS($result_mailid) == 1) {
132 $data = merge_array($data, SQL_FETCHARRAY($result_mailid));
134 // Correct notification switch in non-bonus mails
135 if ((!isset($data['is_notify'])) || (!in_array($data['is_notify'], array('Y', 'N')))) {
136 $data['is_notify'] = 'N';
139 // Set sender to 0 when we have a bonus mail
140 if ($data['link_type'] == 'BONUS') {
141 $data['sender'] = '0';
144 // Is the user id valid?
145 if (fetchUserData($userId) === true) {
146 // Is the user status CONFIRMED?
147 if (getUserData('status') == 'CONFIRMED') {
148 // User has confirmed his account so we can procede...
149 // @TODO Rewrite this to a filter
150 switch ($data['link_type']) {
152 $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
153 array(bigintval($data['pool_id'])), __FILE__, __LINE__);
156 if (SQL_NUMROWS($result) == 1) {
157 list($pay) = SQL_FETCHROW($result);
158 $time = getPaymentData($pay, 'time');
159 $payment = getPaymentData($pay, 'payment');
164 SQL_FREERESULT($result);
168 $result = SQL_QUERY_ESC("SELECT `time`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
169 array(bigintval($data['pool_id'])), __FILE__, __LINE__);
172 if (SQL_NUMROWS($result) == 1) {
173 list($time, $payment) = SQL_FETCHROW($result);
178 SQL_FREERESULT($result);
181 default: // Unknown type
182 reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
186 // Is this entry valid?
187 if ($isValid === true) {
188 if (($time == '0') && ($payment > 0)) $time = 1;
189 if (($time > 0) && ($payment > 0)) {
192 // Generate code (the user sees in the CAPTCHA)
193 $realCode = generateRandomCode(getCodeLength(), $code, $userId, $urlId);
196 // @TODO Rewrite this to a filter
203 // @TODO Rewrite this to a filter
204 switch ($data['link_type']) {
206 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
207 array($mailId), __FILE__, __LINE__);
209 // Update mediadata as well
210 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
212 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
214 $stats_data = $mailId;
218 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
219 array($bonusId), __FILE__, __LINE__);
221 // Update mediadata as well
222 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
224 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
226 $stats_data = $bonusId;
229 default: // Unknown type
230 reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
234 // Export data into constants for the template
235 $content['banner'] = loadTemplate('mailid_banner', true);
237 // Only when user extension = v0.1.2: Update mails-confirmed counter
238 // @TODO Rewrite these blocks to filter
239 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
241 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `mails_confirmed`=`mails_confirmed`+1 WHERE `userid`=%s LIMIT 1",
242 array($userId), __FILE__, __LINE__);
244 // Update random confirmed as well?
245 if ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isRandomReferralIdEnabled())) {
246 // Update second counter
247 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=`rand_confirmed` + 1 WHERE `userid`=%s LIMIT 1",
248 array($userId), __FILE__, __LINE__);
252 // Insert stats record
253 insertUserStatsRecord($userId, $type, $stats_data);
255 // Right code entered?
256 if (bigintval(postRequestElement('gfx_check')) == $realCode) {
257 // Set HTTP status to okay
258 setHttpStatus('200 OK');
260 // Add points over referral system is the default
261 $template = 'mailid_points_done';
263 // Right code entered add points and remove entry
264 if (ifUserPointsLocked($userId)) {
265 // Don't add points over the referral system
266 $template = 'mailid_points_locked';
269 // Count down ref_payout value
270 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
271 array($userId), __FILE__, __LINE__);
274 initReferralSystem();
275 addPointsThroughReferralSystem('mailid_okay', $userId, $payment);
277 // Shall I add bonus points for "turbo clickers" ?
278 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
279 // Is an active-rallye running and this is not a notification mail?
280 if ((isBonusRallyeActive()) && ($data['is_notify'] != 'Y')) {
281 // Shall I exclude the webmaster's own userid from the active-rallye?
282 if ((((getBonusUserid() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserid() != $userId)) && (getDefRefid() != $userId)) {
283 // Add points and remember ranking are done in this function....
284 addTurboBonus($urlId, $userId, $type);
286 // Set template to mailid_points_done2 which contains a link to the ranking list
287 $template = 'mailid_points_done2';
289 // Different template if user has some mails to confirm
290 if (ifUserPointsLocked($userId)) {
291 $template = 'mailid_points_locked2';
294 // Assign more data for the template
295 $content['userid'] = $userId;
296 $content['type'] = $type;
297 $content['data'] = $urlId;
303 $content['total_points'] = getTotalPoints($userId);
305 // Add payment points
306 $content['points'] = $payment;
309 loadTemplate($template, false, $content);
310 } elseif (isValidUserId($data['sender'])) {
311 // Wrong image code! So add points to sender's account
312 initReferralSystem();
313 addPointsThroughReferralSystem('mailid_payback', $data['sender'], $payment);
315 // Add payment points
316 $content['points'] = $payment;
319 loadTemplate('mailid_points_failed', false, $content);
321 // Add payment points (again)
322 $content['points'] = $payment;
325 loadTemplate('mailid_points_failed2', false, $content);
328 // Remove link from table
329 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
330 array(bigintval($data['link_id'])), __FILE__, __LINE__);
334 generateImageOrCode($realCode);
339 // Export data into constants for the template
340 $content['code'] = $code;
341 $content['userid'] = $userId;
342 $content['type'] = $type;
343 $content['data'] = $urlId;
344 $content['banner'] = loadTemplate('mailid_banner', true);
345 if (getCodeLength() > 0) {
347 $content['image'] = generateCaptchaCode($code, $type, $urlId, $userId);
348 $templ = 'mailid_enter_code';
351 $content['gfx'] = $realCode;
352 $templ = 'mailid_confirm_buttom';
356 loadTemplate($templ, false, $content);
359 reportBug(__FILE__, __LINE__, 'No code given.');
364 // Ok, all data is valid and loaded. Finally let's output the timer... :-)
365 // Export data into constants for the template
366 $content['time'] = $time;
367 $content['tim2'] = strlen($time);
368 $content['userid'] = $userId;
369 $content['type'] = $type;
370 $content['data'] = $urlId;
371 $content['rand'] = getRandomTan();
372 $content['banner'] = loadTemplate('mailid_banner', true);
375 loadTemplate('mailid_timer', false, $content);
378 default: // Unknown mode
379 reportBug(__FILE__, __LINE__, 'Unknown mode ' . $do . ' detected.');
383 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (6)');
387 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (5)');
391 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (4)');
395 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (3)');
399 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (2)');
404 SQL_FREERESULT($result_mailid);
406 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (1)');
411 SQL_FREERESULT($result_main);
413 // Insert footer if no image
416 loadIncludeOnce('inc/footer.php');
420 // Really all done here... ;-)