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 * 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 *
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');
54 setContentType('text/html');
56 // Is the extension mailid active?
57 redirectOnUninstalledExtension('mailid');
59 // Is the extension other active?
60 redirectOnUninstalledExtension('other');
70 if (isGetRequestParameterSet('userid')) $url_userid = bigintval(getRequestParameter('userid'));
71 if (isGetRequestParameterSet('mailid')) $url_mid = bigintval(getRequestParameter('mailid'));
72 if (isGetRequestParameterSet('bonusid')) $url_bid = bigintval(getRequestParameter('bonusid'));
73 if (isGetRequestParameterSet('code')) $code = bigintval(getRequestParameter('code'));
74 if (isGetRequestParameterSet('mode')) $mode = getRequestParameter('mode');
76 // 01 1 12 2 2 21 1 22 10
77 if (($url_userid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (getTotalFatalErrors() == '0')) {
78 // No image? Then output header
79 if ($mode != 'img') loadIncludeOnce('inc/header.php');
81 // Maybe he wants to confirm an email?
83 $result = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
84 array($url_mid, $url_userid), __FILE__, __LINE__);
85 $type = 'mailid'; $urlId = $url_mid;
86 } elseif ($url_bid > 0) {
87 $result = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
88 array($url_bid, $url_userid), __FILE__, __LINE__);
89 $type = 'bonusid'; $urlId = $url_bid;
92 if (SQL_NUMROWS($result) == 1) {
93 // Is the stats id valid?
94 list($lid, $ltype) = SQL_FETCHROW($result);
95 SQL_FREERESULT($result);
97 // Init result here with invalid to avoid possible missing variable
98 $result_mailid = false;
100 // @TODO Rewrite this to a filter
103 $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`, `userid`, `id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
104 array($url_mid), __FILE__, __LINE__);
108 $result_mailid = SQL_QUERY_ESC("SELECT `id`, `id`, `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
109 array($url_bid), __FILE__, __LINE__);
112 default: // Unknown type
113 debug_report_bug('Unknown mail type ' . $ltype . ' detected.');
118 if (SQL_NUMROWS($result_mailid) == 1) {
120 list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
122 // Correct notification switch in non-bonus mails
123 if (($notify != 'Y') && ($notify != 'N')) $notify = 'N';
126 SQL_FREERESULT($result_mailid);
128 // Set sender to 0 when we have a bonus mail
129 if ($ltype == 'BONUS') $sender = '0';
131 // Is the user id valid?
132 if (fetchUserData($url_userid) === true) {
133 // Is the user status CONFIRMED?
134 if (getUserData('status') == 'CONFIRMED') {
135 // User has confirmed his account so we can procede...
136 // @TODO Rewrite this to a filter
139 $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
140 array(bigintval($pool)), __FILE__, __LINE__);
143 if (SQL_NUMROWS($result) == 1) {
144 list($pay) = SQL_FETCHROW($result);
145 $time = getPaymentPoints($pay, 'time');
146 $payment = getPaymentPoints($pay, 'payment');
151 SQL_FREERESULT($result);
155 $result = SQL_QUERY_ESC("SELECT `time`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
156 array(bigintval($pool)), __FILE__, __LINE__);
159 if (SQL_NUMROWS($result) == 1) {
160 list($time, $payment) = SQL_FETCHROW($result);
165 SQL_FREERESULT($result);
168 default: // Unknown type
169 debug_report_bug('Unknown mail type ' . $ltype . ' detected.');
173 // Is this entry valid?
174 if ($isValid === true) {
175 if (($time == '0') && ($payment > 0)) $time = 1;
176 if (($time > 0) && ($payment > 0)) {
180 $img_code = generateRandomCode(getConfig('code_length'), $code, $url_userid, $urlId);
183 // @TODO Rewrite this to a filter
190 // @TODO Rewrite this to a filter
193 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
194 array($url_mid), __FILE__, __LINE__);
196 // Update mediadata as well
197 if (getExtensionVersion('mediadata') >= '0.0.4') {
199 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
201 $stats_data = $url_mid;
205 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
206 array($url_bid), __FILE__, __LINE__);
208 // Update mediadata as well
209 if (getExtensionVersion('mediadata') >= '0.0.4') {
211 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
213 $stats_data = $url_bid;
216 default: // Unknown type
217 debug_report_bug('Unknown mail type ' . $ltype . ' detected.');
221 // Export data into constants for the template
222 $content['points'] = translateComma($payment);
223 $content['banner'] = loadTemplate('mailid_banner', true);
225 // Only when user extension = v0.1.2: Update mails-confirmed counter
226 // @TODO Rewrite these blocks to filter
227 if (getExtensionVersion('user') >= '0.1.2') {
229 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET mails_confirmed=mails_confirmed + 1 WHERE `userid`=%s LIMIT 1",
230 array($url_userid), __FILE__, __LINE__);
232 // Update random confirmed as well?
233 if (getExtensionVersion('user') >= '0.3.4') {
234 // Update second counter
235 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET rand_confirmed=rand_confirmed + 1 WHERE `userid`=%s LIMIT 1",
236 array($url_userid), __FILE__, __LINE__);
240 // Insert stats record
241 insertUserStatsRecord($url_userid, $type, $stats_data);
243 // Right code entered?
244 if (bigintval(postRequestParameter('gfx_check')) == $img_code) {
245 // Add points over referal system is the default
247 $template = 'mailid_points_done';
249 // Right code entered add points and remove entry
250 if ((getUserData('ref_payout') > 0) && (getConfig('allow_direct_pay') != 'Y')) {
251 // Don't add points over the referal system
253 $template = 'mailid_points_locked';
256 // Count down ref_payout value
257 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
258 array($url_userid), __FILE__, __LINE__);
261 // @TODO Try to rewrite the following unset()
262 unset($GLOBALS['ref_level']);
263 addPointsThroughReferalSystem('mailid_okay', $url_userid, $payment, false, 0, $locked);
265 // Shall I add bonus points for "turbo clickers" ?
266 if (getExtensionVersion('bonus') >= '0.2.2') {
267 // Is an active-rallye running and this is not a notification mail?
268 if ((getConfig('bonus_active') == 'Y') && ($notify != 'Y')) {
269 // Shall I exclude the webmaster's own userid from the active-rallye?
270 if ((((getConfig('bonus_userid') == $url_userid) && (getConfig('bonus_include_own') == 'Y')) || (getConfig('bonus_userid') != $url_userid)) && (getConfig('def_refid') != $url_userid)) {
271 // Add points and remember ranking are done in this function....
272 addTurboBonus($urlId, $url_userid, $type);
274 // Set template to mailid_points_done2 which contains a link to the ranking list
275 $template = 'mailid_points_done2';
276 if ($locked) $template = 'mailid_points_locked2';
277 $content['userid'] = $url_userid;
278 $content['type'] = $type;
279 $content['data'] = $urlId;
285 $content['total'] = translateComma(
286 countSumTotalData($url_userid, 'user_points', 'points') -
287 countSumTotalData($url_userid, 'user_data', 'used_points')
291 loadTemplate($template, false, $content);
292 } elseif ($sender > 0) {
293 // Wrong image code! So add points to sender's account
294 addPointsDirectly('mailid_payback', $sender, $payment);
297 loadTemplate('mailid_points_failed', false, $content);
300 // Remove link from table
301 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
302 array(bigintval($lid)), __FILE__, __LINE__);
306 generateImageOrCode($img_code);
311 // Export data into constants for the template
312 $content['code'] = $code;
313 $content['userid'] = $url_userid;
314 $content['type'] = $type;
315 $content['data'] = $urlId;
316 $content['banner'] = loadTemplate('mailid_banner', true);
317 if (getConfig('code_length') > 0) {
319 $content['image'] = generateCaptchaCode($code, $type, $urlId, $url_userid);
320 $templ = 'mailid_enter_code';
323 $content['gfx'] = $img_code;
324 $templ = 'mailid_confirm_buttom';
328 loadTemplate($templ, false, $content);
331 debug_report_bug('No code given.');
336 // Ok, all data is valid and loaded. Finally let's output the timer... :-)
337 // Export data into constants for the template
338 $content['time'] = $time;
339 $content['tim2'] = strlen($time);
340 $content['userid'] = $url_userid;
341 $content['type'] = $type;
342 $content['data'] = $urlId;
343 $content['rand'] = mt_rand(0, 99999);
344 $content['banner'] = loadTemplate('mailid_banner', true);
347 loadTemplate('mailid_timer', false, $content);
350 default: // Unknown mode
351 debug_report_bug('Unknown mode ' . $mode . ' detected.');
355 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (6)</div>');
359 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (5)</div>');
363 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (4)</div>');
367 SQL_FREERESULT($result);
368 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (3)</div>');
372 SQL_FREERESULT($result);
373 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (2)</div>');
377 SQL_FREERESULT($result);
378 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (1)</div>');
382 // Insert footer if no image
383 if ($mode != 'img') {
385 loadIncludeOnce('inc/footer.php');
389 // Really all done here... ;-)