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)) && (!ifFatalErrorsDetected())) {
78 // No image? Then output header
79 if ($mode != 'img') loadIncludeOnce('inc/header.php');
81 // Maybe he wants to confirm an email?
83 $result_main = 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_main = 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_main) == 1) {
93 // Is the stats id valid?
94 list($lid, $ltype) = SQL_FETCHROW($result_main);
96 // Init result here with invalid to avoid possible missing variable
97 $result_mailid = false;
99 // @TODO Rewrite this to a filter
102 $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`, `userid`, `id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
103 array($url_mid), __FILE__, __LINE__);
107 $result_mailid = SQL_QUERY_ESC("SELECT `id`, `id`, `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
108 array($url_bid), __FILE__, __LINE__);
111 default: // Unknown type
112 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
117 if (SQL_NUMROWS($result_mailid) == 1) {
119 list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
121 // Correct notification switch in non-bonus mails
122 if (($notify != 'Y') && ($notify != 'N')) $notify = 'N';
124 // Set sender to 0 when we have a bonus mail
125 if ($ltype == 'BONUS') $sender = '0';
127 // Is the user id valid?
128 if (fetchUserData($url_userid) === true) {
129 // Is the user status CONFIRMED?
130 if (getUserData('status') == 'CONFIRMED') {
131 // User has confirmed his account so we can procede...
132 // @TODO Rewrite this to a filter
135 $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
136 array(bigintval($pool)), __FILE__, __LINE__);
139 if (SQL_NUMROWS($result) == 1) {
140 list($pay) = SQL_FETCHROW($result);
141 $time = getPaymentPoints($pay, 'time');
142 $payment = getPaymentPoints($pay, 'payment');
147 SQL_FREERESULT($result);
151 $result = SQL_QUERY_ESC("SELECT `time`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
152 array(bigintval($pool)), __FILE__, __LINE__);
155 if (SQL_NUMROWS($result) == 1) {
156 list($time, $payment) = SQL_FETCHROW($result);
161 SQL_FREERESULT($result);
164 default: // Unknown type
165 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
169 // Is this entry valid?
170 if ($isValid === true) {
171 if (($time == '0') && ($payment > 0)) $time = 1;
172 if (($time > 0) && ($payment > 0)) {
176 $img_code = generateRandomCode(getConfig('code_length'), $code, $url_userid, $urlId);
179 // @TODO Rewrite this to a filter
186 // @TODO Rewrite this to a filter
189 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
190 array($url_mid), __FILE__, __LINE__);
192 // Update mediadata as well
193 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
195 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
197 $stats_data = $url_mid;
201 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
202 array($url_bid), __FILE__, __LINE__);
204 // Update mediadata as well
205 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
207 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
209 $stats_data = $url_bid;
212 default: // Unknown type
213 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
217 // Export data into constants for the template
218 $content['points'] = translateComma($payment);
219 $content['banner'] = loadTemplate('mailid_banner', true);
221 // Only when user extension = v0.1.2: Update mails-confirmed counter
222 // @TODO Rewrite these blocks to filter
223 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
225 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET mails_confirmed=mails_confirmed + 1 WHERE `userid`=%s LIMIT 1",
226 array($url_userid), __FILE__, __LINE__);
228 // Update random confirmed as well?
229 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
230 // Update second counter
231 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET rand_confirmed=rand_confirmed + 1 WHERE `userid`=%s LIMIT 1",
232 array($url_userid), __FILE__, __LINE__);
236 // Insert stats record
237 insertUserStatsRecord($url_userid, $type, $stats_data);
239 // Right code entered?
240 if (bigintval(postRequestParameter('gfx_check')) == $img_code) {
241 // Add points over referal system is the default
243 $template = 'mailid_points_done';
245 // Right code entered add points and remove entry
246 if ((getUserData('ref_payout') > 0) && (getConfig('allow_direct_pay') != 'Y')) {
247 // Don't add points over the referal system
249 $template = 'mailid_points_locked';
252 // Count down ref_payout value
253 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
254 array($url_userid), __FILE__, __LINE__);
257 // @TODO Try to rewrite the following unset()
258 unset($GLOBALS['ref_level']);
259 addPointsThroughReferalSystem('mailid_okay', $url_userid, $payment, false, 0, $locked);
261 // Shall I add bonus points for "turbo clickers" ?
262 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
263 // Is an active-rallye running and this is not a notification mail?
264 if ((getConfig('bonus_active') == 'Y') && ($notify != 'Y')) {
265 // Shall I exclude the webmaster's own userid from the active-rallye?
266 if ((((getConfig('bonus_userid') == $url_userid) && (getConfig('bonus_include_own') == 'Y')) || (getConfig('bonus_userid') != $url_userid)) && (getConfig('def_refid') != $url_userid)) {
267 // Add points and remember ranking are done in this function....
268 addTurboBonus($urlId, $url_userid, $type);
270 // Set template to mailid_points_done2 which contains a link to the ranking list
271 $template = 'mailid_points_done2';
272 if ($locked) $template = 'mailid_points_locked2';
273 $content['userid'] = $url_userid;
274 $content['type'] = $type;
275 $content['data'] = $urlId;
281 $content['total'] = translateComma(
282 countSumTotalData($url_userid, 'user_points', 'points') -
283 countSumTotalData($url_userid, 'user_data', 'used_points')
287 loadTemplate($template, false, $content);
288 } elseif ($sender > 0) {
289 // Wrong image code! So add points to sender's account
290 addPointsDirectly('mailid_payback', $sender, $payment);
293 loadTemplate('mailid_points_failed', false, $content);
296 // Remove link from table
297 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
298 array(bigintval($lid)), __FILE__, __LINE__);
302 generateImageOrCode($img_code);
307 // Export data into constants for the template
308 $content['code'] = $code;
309 $content['userid'] = $url_userid;
310 $content['type'] = $type;
311 $content['data'] = $urlId;
312 $content['banner'] = loadTemplate('mailid_banner', true);
313 if (getConfig('code_length') > 0) {
315 $content['image'] = generateCaptchaCode($code, $type, $urlId, $url_userid);
316 $templ = 'mailid_enter_code';
319 $content['gfx'] = $img_code;
320 $templ = 'mailid_confirm_buttom';
324 loadTemplate($templ, false, $content);
327 debug_report_bug(__FILE__, __LINE__, 'No code given.');
332 // Ok, all data is valid and loaded. Finally let's output the timer... :-)
333 // Export data into constants for the template
334 $content['time'] = $time;
335 $content['tim2'] = strlen($time);
336 $content['userid'] = $url_userid;
337 $content['type'] = $type;
338 $content['data'] = $urlId;
339 $content['rand'] = mt_rand(0, 99999);
340 $content['banner'] = loadTemplate('mailid_banner', true);
343 loadTemplate('mailid_timer', false, $content);
346 default: // Unknown mode
347 debug_report_bug(__FILE__, __LINE__, 'Unknown mode ' . $mode . ' detected.');
351 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (6)</div>');
355 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (5)</div>');
359 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (4)</div>');
363 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (3)</div>');
367 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (2)</div>');
372 SQL_FREERESULT($result_mailid);
374 loadTemplate('admin_settings_saved', false, '<div class="member_failed">{--MAIL_ALREADY_CONFIRMED--} (1)</div>');
379 SQL_FREERESULT($result_main);
381 // Insert footer if no image
382 if ($mode != 'img') {
384 loadIncludeOnce('inc/footer.php');
388 // Really all done here... ;-)