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://www.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 (isGetRequestParameterSet('userid')) $userId = bigintval(getRequestParameter('userid'));
72 if (isGetRequestParameterSet('mailid')) $mailId = bigintval(getRequestParameter('mailid'));
73 if (isGetRequestParameterSet('bonusid')) $bonusId = bigintval(getRequestParameter('bonusid'));
74 if (isGetRequestParameterSet('code')) $code = bigintval(getRequestParameter('code'));
75 if (isGetRequestParameterSet('mode')) $mode = getRequestParameter('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')) $notify = 'N';
130 // Set sender to 0 when we have a bonus mail
131 if ($ltype == 'BONUS') $sender = '0';
133 // Is the user id valid?
134 if (fetchUserData($userId) === true) {
135 // Is the user status CONFIRMED?
136 if (getUserData('status') == 'CONFIRMED') {
137 // User has confirmed his account so we can procede...
138 // @TODO Rewrite this to a filter
141 $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
142 array(bigintval($pool)), __FILE__, __LINE__);
145 if (SQL_NUMROWS($result) == 1) {
146 list($pay) = SQL_FETCHROW($result);
147 $time = getPaymentPoints($pay, 'time');
148 $payment = getPaymentPoints($pay, 'payment');
153 SQL_FREERESULT($result);
157 $result = SQL_QUERY_ESC("SELECT `time`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
158 array(bigintval($pool)), __FILE__, __LINE__);
161 if (SQL_NUMROWS($result) == 1) {
162 list($time, $payment) = SQL_FETCHROW($result);
167 SQL_FREERESULT($result);
170 default: // Unknown type
171 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
175 // Is this entry valid?
176 if ($isValid === true) {
177 if (($time == '0') && ($payment > 0)) $time = 1;
178 if (($time > 0) && ($payment > 0)) {
181 // Generate code (the user sees in the CAPTCHA)
182 $realCode = generateRandomCode(getCodeLength(), $code, $userId, $urlId);
185 // @TODO Rewrite this to a filter
192 // @TODO Rewrite this to a filter
195 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
196 array($mailId), __FILE__, __LINE__);
198 // Update mediadata as well
199 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
201 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
203 $stats_data = $mailId;
207 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
208 array($bonusId), __FILE__, __LINE__);
210 // Update mediadata as well
211 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
213 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
215 $stats_data = $bonusId;
218 default: // Unknown type
219 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
223 // Export data into constants for the template
224 $content['banner'] = loadTemplate('mailid_banner', true);
226 // Only when user extension = v0.1.2: Update mails-confirmed counter
227 // @TODO Rewrite these blocks to filter
228 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
230 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `mails_confirmed`=`mails_confirmed`+1 WHERE `userid`=%s LIMIT 1",
231 array($userId), __FILE__, __LINE__);
233 // Update random confirmed as well?
234 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
235 // Update second counter
236 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=`rand_confirmed` + 1 WHERE `userid`=%s LIMIT 1",
237 array($userId), __FILE__, __LINE__);
241 // Insert stats record
242 //insertUserStatsRecord($userId, $type, $stats_data);
244 // Right code entered?
245 if (bigintval(postRequestParameter('gfx_check')) == $realCode) {
246 // Set HTTP status to okay
247 setHttpStatus('200 OK');
249 // Add points over referal system is the default
250 $template = 'mailid_points_done';
252 // Right code entered add points and remove entry
253 if (ifUserPointsLocked($userId)) {
254 // Don't add points over the referal system
255 $template = 'mailid_points_locked';
258 // Count down ref_payout value
259 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
260 array($userId), __FILE__, __LINE__);
264 addPointsThroughReferalSystem('mailid_okay', $userId, $payment);
266 // Shall I add bonus points for "turbo clickers" ?
267 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
268 // Is an active-rallye running and this is not a notification mail?
269 if ((isBonusRallyeActive()) && ($notify != 'Y')) {
270 // Shall I exclude the webmaster's own userid from the active-rallye?
271 if ((((getBonusUserid() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserid() != $userId)) && (getDefRefid() != $userId)) {
272 // Add points and remember ranking are done in this function....
273 addTurboBonus($urlId, $userId, $type);
275 // Set template to mailid_points_done2 which contains a link to the ranking list
276 $template = 'mailid_points_done2';
278 // Different template if user has some mails to confirm
279 if (ifUserPointsLocked($userId)) {
280 $template = 'mailid_points_locked2';
283 // Assign more data for the template
284 $content['userid'] = $userId;
285 $content['type'] = $type;
286 $content['data'] = $urlId;
292 $content['total_points'] = getTotalPoints($userId);
294 // Add payment points
295 $content['points'] = $payment;
298 loadTemplate($template, false, $content);
299 } elseif (isValidUserId($sender)) {
300 // Wrong image code! So add points to sender's account
301 addPointsThroughReferalSystem('mailid_payback', $sender, $payment);
303 // Add payment points
304 $content['points'] = $payment;
307 loadTemplate('mailid_points_failed', false, $content);
309 // Add payment points (again)
310 $content['points'] = $payment;
313 loadTemplate('mailid_points_failed2', false, $content);
316 // Remove link from table
317 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
318 array(bigintval($lid)), __FILE__, __LINE__);
322 generateImageOrCode($realCode);
327 // Export data into constants for the template
328 $content['code'] = $code;
329 $content['userid'] = $userId;
330 $content['type'] = $type;
331 $content['data'] = $urlId;
332 $content['banner'] = loadTemplate('mailid_banner', true);
333 if (getCodeLength() > 0) {
335 $content['image'] = generateCaptchaCode($realCode, $type, $urlId, $userId);
336 $templ = 'mailid_enter_code';
339 $content['gfx'] = $realCode;
340 $templ = 'mailid_confirm_buttom';
344 loadTemplate($templ, false, $content);
347 debug_report_bug(__FILE__, __LINE__, 'No code given.');
352 // Ok, all data is valid and loaded. Finally let's output the timer... :-)
353 // Export data into constants for the template
354 $content['time'] = $time;
355 $content['tim2'] = strlen($time);
356 $content['userid'] = $userId;
357 $content['type'] = $type;
358 $content['data'] = $urlId;
359 $content['rand'] = mt_rand(0, 99999);
360 $content['banner'] = loadTemplate('mailid_banner', true);
363 loadTemplate('mailid_timer', false, $content);
366 default: // Unknown mode
367 debug_report_bug(__FILE__, __LINE__, 'Unknown mode ' . $mode . ' detected.');
371 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (6)');
375 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (5)');
379 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (4)');
383 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (3)');
387 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (2)');
392 SQL_FREERESULT($result_mailid);
394 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (1)');
399 SQL_FREERESULT($result_main);
401 // Insert footer if no image
402 if ($mode != 'img') {
404 loadIncludeOnce('inc/footer.php');
408 // Really all done here... ;-)