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 - 2011 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['startTime'] = microtime(true);
46 // Tell everyone we are in this module
47 $GLOBALS['module'] = 'mailid';
48 $GLOBALS['output_mode'] = -1;
50 // Load the required file(s)
51 require('inc/config-global.php');
53 // Set content type and HTTP status
54 setContentType('text/html');
55 setHttpStatus('404 NOT FOUND');
57 // Is the extension mailid active?
58 redirectOnUninstalledExtension('mailid');
60 // Is the extension other active?
61 redirectOnUninstalledExtension('other');
71 if (isGetRequestElementSet('userid')) $userId = bigintval(getRequestElement('userid'));
72 if (isGetRequestElementSet('mailid')) $mailId = bigintval(getRequestElement('mailid'));
73 if (isGetRequestElementSet('bonusid')) $bonusId = bigintval(getRequestElement('bonusid'));
74 if (isGetRequestElementSet('code')) $code = bigintval(getRequestElement('code'));
75 if (isGetRequestElementSet('mode')) $mode = getRequestElement('mode');
77 // 01 2 21 12 2 2 21 1 2210
78 if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalErrorsDetected())) {
81 // ... then output header
82 loadIncludeOnce('inc/header.php');
85 // Maybe he wants to confirm an email?
87 $result_main = SQL_QUERY_ESC("SELECT `id`,`link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
88 array($mailId, $userId), __FILE__, __LINE__);
91 } elseif ($bonusId > 0) {
92 $result_main = SQL_QUERY_ESC("SELECT `id`,`link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
93 array($bonusId, $userId), __FILE__, __LINE__);
98 if (SQL_NUMROWS($result_main) == 1) {
99 // Is the stats id valid?
100 list($lid, $ltype) = SQL_FETCHROW($result_main);
102 // Init result here with invalid to avoid possible missing variable
103 $result_mailid = false;
105 // @TODO Rewrite this to a filter
108 $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`,`userid`,`id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
109 array($mailId), __FILE__, __LINE__);
113 $result_mailid = SQL_QUERY_ESC("SELECT `id`,`id`,`is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
114 array($bonusId), __FILE__, __LINE__);
117 default: // Unknown type
118 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
123 if (SQL_NUMROWS($result_mailid) == 1) {
125 list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
127 // Correct notification switch in non-bonus mails
128 if (($notify != 'Y') && ($notify != 'N')) {
132 // Set sender to 0 when we have a bonus mail
133 if ($ltype == 'BONUS') {
137 // Is the user id valid?
138 if (fetchUserData($userId) === true) {
139 // Is the user status CONFIRMED?
140 if (getUserData('status') == 'CONFIRMED') {
141 // User has confirmed his account so we can procede...
142 // @TODO Rewrite this to a filter
145 $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
146 array(bigintval($pool)), __FILE__, __LINE__);
149 if (SQL_NUMROWS($result) == 1) {
150 list($pay) = SQL_FETCHROW($result);
151 $time = getPaymentPoints($pay, 'time');
152 $payment = getPaymentPoints($pay, 'payment');
157 SQL_FREERESULT($result);
161 $result = SQL_QUERY_ESC("SELECT `time`,`points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
162 array(bigintval($pool)), __FILE__, __LINE__);
165 if (SQL_NUMROWS($result) == 1) {
166 list($time, $payment) = SQL_FETCHROW($result);
171 SQL_FREERESULT($result);
174 default: // Unknown type
175 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
179 // Is this entry valid?
180 if ($isValid === true) {
181 if (($time == '0') && ($payment > 0)) $time = 1;
182 if (($time > 0) && ($payment > 0)) {
185 // Generate code (the user sees in the CAPTCHA)
186 $realCode = generateRandomCode(getCodeLength(), $code, $userId, $urlId);
189 // @TODO Rewrite this to a filter
196 // @TODO Rewrite this to a filter
199 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
200 array($mailId), __FILE__, __LINE__);
202 // Update mediadata as well
203 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
205 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
207 $stats_data = $mailId;
211 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
212 array($bonusId), __FILE__, __LINE__);
214 // Update mediadata as well
215 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
217 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
219 $stats_data = $bonusId;
222 default: // Unknown type
223 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
227 // Export data into constants for the template
228 $content['banner'] = loadTemplate('mailid_banner', true);
230 // Only when user extension = v0.1.2: Update mails-confirmed counter
231 // @TODO Rewrite these blocks to filter
232 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
234 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `mails_confirmed`=`mails_confirmed`+1 WHERE `userid`=%s LIMIT 1",
235 array($userId), __FILE__, __LINE__);
237 // Update random confirmed as well?
238 if ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isRandomReferralIdEnabled())) {
239 // Update second counter
240 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=`rand_confirmed` + 1 WHERE `userid`=%s LIMIT 1",
241 array($userId), __FILE__, __LINE__);
245 // Insert stats record
246 insertUserStatsRecord($userId, $type, $stats_data);
248 // Right code entered?
249 if (bigintval(postRequestElement('gfx_check')) == $realCode) {
250 // Set HTTP status to okay
251 setHttpStatus('200 OK');
253 // Add points over referral system is the default
254 $template = 'mailid_points_done';
256 // Right code entered add points and remove entry
257 if (ifUserPointsLocked($userId)) {
258 // Don't add points over the referral system
259 $template = 'mailid_points_locked';
262 // Count down ref_payout value
263 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
264 array($userId), __FILE__, __LINE__);
267 initReferralSystem();
268 addPointsThroughReferralSystem('mailid_okay', $userId, $payment);
270 // Shall I add bonus points for "turbo clickers" ?
271 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
272 // Is an active-rallye running and this is not a notification mail?
273 if ((isBonusRallyeActive()) && ($notify != 'Y')) {
274 // Shall I exclude the webmaster's own userid from the active-rallye?
275 if ((((getBonusUserid() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserid() != $userId)) && (getDefRefid() != $userId)) {
276 // Add points and remember ranking are done in this function....
277 addTurboBonus($urlId, $userId, $type);
279 // Set template to mailid_points_done2 which contains a link to the ranking list
280 $template = 'mailid_points_done2';
282 // Different template if user has some mails to confirm
283 if (ifUserPointsLocked($userId)) {
284 $template = 'mailid_points_locked2';
287 // Assign more data for the template
288 $content['userid'] = $userId;
289 $content['type'] = $type;
290 $content['data'] = $urlId;
296 $content['total_points'] = getTotalPoints($userId);
298 // Add payment points
299 $content['points'] = $payment;
302 loadTemplate($template, false, $content);
303 } elseif (isValidUserId($sender)) {
304 // Wrong image code! So add points to sender's account
305 initReferralSystem();
306 addPointsThroughReferralSystem('mailid_payback', $sender, $payment);
308 // Add payment points
309 $content['points'] = $payment;
312 loadTemplate('mailid_points_failed', false, $content);
314 // Add payment points (again)
315 $content['points'] = $payment;
318 loadTemplate('mailid_points_failed2', false, $content);
321 // Remove link from table
322 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
323 array(bigintval($lid)), __FILE__, __LINE__);
327 generateImageOrCode($realCode);
332 // Export data into constants for the template
333 $content['code'] = $code;
334 $content['userid'] = $userId;
335 $content['type'] = $type;
336 $content['data'] = $urlId;
337 $content['banner'] = loadTemplate('mailid_banner', true);
338 if (getCodeLength() > 0) {
340 $content['image'] = generateCaptchaCode($realCode, $type, $urlId, $userId);
341 $templ = 'mailid_enter_code';
344 $content['gfx'] = $realCode;
345 $templ = 'mailid_confirm_buttom';
349 loadTemplate($templ, false, $content);
352 debug_report_bug(__FILE__, __LINE__, 'No code given.');
357 // Ok, all data is valid and loaded. Finally let's output the timer... :-)
358 // Export data into constants for the template
359 $content['time'] = $time;
360 $content['tim2'] = strlen($time);
361 $content['userid'] = $userId;
362 $content['type'] = $type;
363 $content['data'] = $urlId;
364 $content['rand'] = mt_rand(0, 99999);
365 $content['banner'] = loadTemplate('mailid_banner', true);
368 loadTemplate('mailid_timer', false, $content);
371 default: // Unknown mode
372 debug_report_bug(__FILE__, __LINE__, 'Unknown mode ' . $mode . ' detected.');
376 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (6)');
380 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (5)');
384 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (4)');
388 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (3)');
392 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (2)');
397 SQL_FREERESULT($result_mailid);
399 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (1)');
404 SQL_FREERESULT($result_main);
406 // Insert footer if no image
407 if ($mode != 'img') {
409 loadIncludeOnce('inc/footer.php');
413 // Really all done here... ;-)