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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Load security stuff here
40 require('inc/libs/security_functions.php');
43 $GLOBALS['startTime'] = microtime(true);
45 // Tell everyone we are in this module
46 $GLOBALS['module'] = 'mailid';
47 $GLOBALS['output_mode'] = -1;
49 // Load the required file(s)
50 require('inc/config-global.php');
53 setContentType('text/html');
55 // Is the extension mailid active?
56 redirectOnUninstalledExtension('mailid');
58 // Is the extension other active?
59 redirectOnUninstalledExtension('other');
69 if (isGetRequestElementSet('userid')) $url_userid = bigintval(getRequestElement('userid'));
70 if (isGetRequestElementSet('mailid')) $url_mid = bigintval(getRequestElement('mailid'));
71 if (isGetRequestElementSet('bonusid')) $url_bid = bigintval(getRequestElement('bonusid'));
72 if (isGetRequestElementSet('code')) $code = bigintval(getRequestElement('code'));
73 if (isGetRequestElementSet('mode')) $mode = getRequestElement('mode');
75 // 01 1 12 2 2 21 1 22 10
76 if (($url_userid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (getTotalFatalErrors() == '0')) {
77 // No image? Then output header
78 if ($mode != 'img') loadIncludeOnce('inc/header.php');
80 // Maybe he wants to confirm an email?
82 $result = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
83 array($url_mid, $url_userid), __FILE__, __LINE__);
84 $type = 'mailid'; $urlId = $url_mid;
85 } elseif ($url_bid > 0) {
86 $result = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
87 array($url_bid, $url_userid), __FILE__, __LINE__);
88 $type = 'bonusid'; $urlId = $url_bid;
91 if (SQL_NUMROWS($result) == 1) {
92 // Is the stats id valid?
93 list($lid, $ltype) = SQL_FETCHROW($result);
94 SQL_FREERESULT($result);
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('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';
125 SQL_FREERESULT($result_mailid);
127 // Set sender to 0 when we have a bonus mail
128 if ($ltype == 'BONUS') $sender = '0';
130 // Is the user id valid?
131 if (fetchUserData($url_userid) === true) {
132 // Is the user status CONFIRMED?
133 if (getUserData('status') == 'CONFIRMED') {
134 // User has confirmed his account so we can procede...
135 // @TODO Rewrite this to a filter
138 $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
139 array(bigintval($pool)), __FILE__, __LINE__);
142 if (SQL_NUMROWS($result) == 1) {
143 list($pay) = SQL_FETCHROW($result);
144 $time = getPaymentPoints($pay, 'time');
145 $payment = getPaymentPoints($pay, 'payment');
150 SQL_FREERESULT($result);
154 $result = SQL_QUERY_ESC("SELECT `time`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
155 array(bigintval($pool)), __FILE__, __LINE__);
158 if (SQL_NUMROWS($result) == 1) {
159 list($time, $payment) = SQL_FETCHROW($result);
164 SQL_FREERESULT($result);
167 default: // Unknown type
168 debug_report_bug('Unknown mail type ' . $ltype . ' detected.');
172 // Is this entry valid?
173 if ($isValid === true) {
174 if (($time == '0') && ($payment > 0)) $time = 1;
175 if (($time > 0) && ($payment > 0)) {
179 $img_code = generateRandomCode(getConfig('code_length'), $code, $url_userid, $urlId);
182 // @TODO Rewrite this to a filter
189 // @TODO Rewrite this to a filter
192 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
193 array($url_mid), __FILE__, __LINE__);
195 // Update mediadata as well
196 if (getExtensionVersion('mediadata') >= '0.0.4') {
198 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
200 $stats_data = $url_mid;
204 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
205 array($url_bid), __FILE__, __LINE__);
207 // Update mediadata as well
208 if (getExtensionVersion('mediadata') >= '0.0.4') {
210 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
212 $stats_data = $url_bid;
215 default: // Unknown type
216 debug_report_bug('Unknown mail type ' . $ltype . ' detected.');
220 // Export data into constants for the template
221 $content['points'] = translateComma($payment);
222 $content['banner'] = loadTemplate('mailid_banner', true);
224 // Only when user extension = v0.1.2: Update mails-confirmed counter
225 // @TODO Rewrite these blocks to filter
226 if (getExtensionVersion('user') >= '0.1.2') {
228 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET mails_confirmed=mails_confirmed + 1 WHERE `userid`=%s LIMIT 1",
229 array($url_userid), __FILE__, __LINE__);
231 // Update random confirmed as well?
232 if (getExtensionVersion('user') >= '0.3.4') {
233 // Update second counter
234 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET rand_confirmed=rand_confirmed + 1 WHERE `userid`=%s LIMIT 1",
235 array($url_userid), __FILE__, __LINE__);
239 // Insert stats record
240 insertUserStatsRecord($url_userid, $type, $stats_data);
242 // Right code entered?
243 if (bigintval(postRequestElement('gfx_check')) == $img_code) {
244 // Add points over referal system is the default
246 $template = 'mailid_points_done';
248 // Right code entered add points and remove entry
249 if ((getUserData('ref_payout') > 0) && (getConfig('allow_direct_pay') != 'Y')) {
250 // Don't add points over the referal system
252 $template = 'mailid_points_locked';
255 // Count down ref_payout value
256 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
257 array($url_userid), __FILE__, __LINE__);
260 // @TODO Try to rewrite the following unset()
261 unset($GLOBALS['ref_level']);
262 addPointsThroughReferalSystem('mailid_okay', $url_userid, $payment, false, 0, $locked);
264 // Shall I add bonus points for "turbo clickers" ?
265 if (getExtensionVersion('bonus') >= '0.2.2') {
266 // Is an active-rallye running and this is not a notification mail?
267 if ((getConfig('bonus_active') == 'Y') && ($notify != 'Y')) {
268 // Shall I exclude the webmaster's own userid from the active-rallye?
269 if ((((getConfig('bonus_userid') == $url_userid) && (getConfig('bonus_include_own') == 'Y')) || (getConfig('bonus_userid') != $url_userid)) && (getConfig('def_refid') != $url_userid)) {
270 // Add points and remember ranking are done in this function....
271 addTurboBonus($urlId, $url_userid, $type);
273 // Set template to mailid_points_done2 which contains a link to the ranking list
274 $template = 'mailid_points_done2';
275 if ($locked) $template = 'mailid_points_locked2';
276 $content['userid'] = $url_userid;
277 $content['type'] = $type;
278 $content['data'] = $urlId;
284 $content['total'] = translateComma(
285 countSumTotalData($url_userid, 'user_points', 'points') -
286 countSumTotalData($url_userid, 'user_data', 'used_points')
290 loadTemplate($template, false, $content);
291 } elseif ($sender > 0) {
292 // Wrong image code! So add points to sender's account
293 addPointsDirectly('mailid_payback', $sender, $payment);
296 loadTemplate('mailid_points_failed', false, $content);
299 // Remove link from table
300 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
301 array(bigintval($lid)), __FILE__, __LINE__);
305 generateImageOrCode($img_code);
310 // Export data into constants for the template
311 $content['code'] = $code;
312 $content['userid'] = $url_userid;
313 $content['type'] = $type;
314 $content['data'] = $urlId;
315 $content['banner'] = loadTemplate('mailid_banner', true);
316 if (getConfig('code_length') > 0) {
318 $content['image'] = generateCaptchaCode($code, $type, $urlId, $url_userid);
319 $templ = 'mailid_enter_code';
322 $content['gfx'] = $img_code;
323 $templ = 'mailid_confirm_buttom';
327 loadTemplate($templ, false, $content);
330 debug_report_bug('No code given.');
335 // Ok, all data is valid and loaded. Finally let's output the timer... :-)
336 // Export data into constants for the template
337 $content['time'] = $time;
338 $content['tim2'] = strlen($time);
339 $content['userid'] = $url_userid;
340 $content['type'] = $type;
341 $content['data'] = $urlId;
342 $content['rand'] = mt_rand(0, 99999);
343 $content['banner'] = loadTemplate('mailid_banner', true);
346 loadTemplate('mailid_timer', false, $content);
349 default: // Unknown mode
350 debug_report_bug('Unknown mode ' . $mode . ' detected.');
354 loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (6)</div>");
358 loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (5)</div>");
362 loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (4)</div>");
366 SQL_FREERESULT($result);
367 loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (3)</div>");
371 SQL_FREERESULT($result);
372 loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (2)</div>");
376 SQL_FREERESULT($result);
377 loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (1)</div>");
381 // Insert footer if no image
382 if ($mode != 'img') {
384 loadIncludeOnce('inc/footer.php');
388 // Really all done here... ;-)