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 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Load security stuff here
39 require('inc/libs/security_functions.php');
42 $GLOBALS['startTime'] = microtime(true);
44 // Tell everyone we are in this module
45 $GLOBALS['module'] = 'mailid';
46 $GLOBALS['output_mode'] = -1;
48 // Load the required file(s)
49 require('inc/config-global.php');
51 // Set content type and HTTP status
52 setContentType('text/html');
53 setHttpStatus('404 NOT FOUND');
55 // Is the extension mailid active?
56 redirectOnUninstalledExtension('mailid');
58 // Is the extension other active?
59 redirectOnUninstalledExtension('other');
69 if (isGetRequestParameterSet('userid')) $userId = bigintval(getRequestParameter('userid'));
70 if (isGetRequestParameterSet('mailid')) $mailId = bigintval(getRequestParameter('mailid'));
71 if (isGetRequestParameterSet('bonusid')) $bonusId = bigintval(getRequestParameter('bonusid'));
72 if (isGetRequestParameterSet('code')) $code = bigintval(getRequestParameter('code'));
73 if (isGetRequestParameterSet('mode')) $mode = getRequestParameter('mode');
75 // 01 2 21 12 2 2 21 1 2210
76 if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalErrorsDetected())) {
79 // ... then output header
80 loadIncludeOnce('inc/header.php');
83 // Maybe he wants to confirm an email?
85 $result_main = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
86 array($mailId, $userId), __FILE__, __LINE__);
89 } elseif ($bonusId > 0) {
90 $result_main = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
91 array($bonusId, $userId), __FILE__, __LINE__);
96 if (SQL_NUMROWS($result_main) == 1) {
97 // Is the stats id valid?
98 list($lid, $ltype) = SQL_FETCHROW($result_main);
100 // Init result here with invalid to avoid possible missing variable
101 $result_mailid = false;
103 // @TODO Rewrite this to a filter
106 $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`, `userid`, `id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
107 array($mailId), __FILE__, __LINE__);
111 $result_mailid = SQL_QUERY_ESC("SELECT `id`, `id`, `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
112 array($bonusId), __FILE__, __LINE__);
115 default: // Unknown type
116 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
121 if (SQL_NUMROWS($result_mailid) == 1) {
123 list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
125 // Correct notification switch in non-bonus mails
126 if (($notify != 'Y') && ($notify != 'N')) $notify = 'N';
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($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(__FILE__, __LINE__, '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(getCodeLength(), $code, $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($mailId), __FILE__, __LINE__);
196 // Update mediadata as well
197 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
199 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
201 $stats_data = $mailId;
205 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
206 array($bonusId), __FILE__, __LINE__);
208 // Update mediadata as well
209 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
211 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
213 $stats_data = $bonusId;
216 default: // Unknown type
217 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
221 // Export data into constants for the template
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 (isExtensionInstalledAndNewer('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($userId), __FILE__, __LINE__);
231 // Update random confirmed as well?
232 if (isExtensionInstalledAndNewer('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($userId), __FILE__, __LINE__);
239 // Insert stats record
240 insertUserStatsRecord($userId, $type, $stats_data);
242 // Right code entered?
243 if (bigintval(postRequestParameter('gfx_check')) == $img_code) {
244 // Set HTTP status to okay
245 setHttpStatus('200 OK');
247 // Add points over referal system is the default
248 $template = 'mailid_points_done';
250 // Right code entered add points and remove entry
251 if (ifUserPointsLocked($userId)) {
252 // 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($userId), __FILE__, __LINE__);
261 // @TODO Try to rewrite the following unset()
262 unset($GLOBALS['ref_level']);
263 addPointsThroughReferalSystem('mailid_okay', $userId, $payment);
265 // Shall I add bonus points for "turbo clickers" ?
266 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
267 // Is an active-rallye running and this is not a notification mail?
268 if ((isBonusRallyeActive()) && ($notify != 'Y')) {
269 // Shall I exclude the webmaster's own userid from the active-rallye?
270 if ((((getBonusUserid() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserid() != $userId)) && (getDefRefid() != $userId)) {
271 // Add points and remember ranking are done in this function....
272 addTurboBonus($urlId, $userId, $type);
274 // Set template to mailid_points_done2 which contains a link to the ranking list
275 $template = 'mailid_points_done2';
277 // Different template if user has some mails to confirm
278 if (ifUserPointsLocked($userId)) {
279 $template = 'mailid_points_locked2';
282 // Assign more data for the template
283 $content['userid'] = $userId;
284 $content['type'] = $type;
285 $content['data'] = $urlId;
291 $content['total_points'] = getTotalPoints($userId);
293 // Add payment points
294 $content['points'] = $payment;
297 loadTemplate($template, false, $content);
298 } elseif (isValidUserId($sender)) {
299 // Wrong image code! So add points to sender's account
300 addPointsDirectly('mailid_payback', $sender, $payment);
303 loadTemplate('mailid_points_failed', false, $content);
306 // Remove link from table
307 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
308 array(bigintval($lid)), __FILE__, __LINE__);
312 generateImageOrCode($img_code);
317 // Export data into constants for the template
318 $content['code'] = $code;
319 $content['userid'] = $userId;
320 $content['type'] = $type;
321 $content['data'] = $urlId;
322 $content['banner'] = loadTemplate('mailid_banner', true);
323 if (getCodeLength() > 0) {
325 $content['image'] = generateCaptchaCode($code, $type, $urlId, $userId);
326 $templ = 'mailid_enter_code';
329 $content['gfx'] = $img_code;
330 $templ = 'mailid_confirm_buttom';
334 loadTemplate($templ, false, $content);
337 debug_report_bug(__FILE__, __LINE__, 'No code given.');
342 // Ok, all data is valid and loaded. Finally let's output the timer... :-)
343 // Export data into constants for the template
344 $content['time'] = $time;
345 $content['tim2'] = strlen($time);
346 $content['userid'] = $userId;
347 $content['type'] = $type;
348 $content['data'] = $urlId;
349 $content['rand'] = mt_rand(0, 99999);
350 $content['banner'] = loadTemplate('mailid_banner', true);
353 loadTemplate('mailid_timer', false, $content);
356 default: // Unknown mode
357 debug_report_bug(__FILE__, __LINE__, 'Unknown mode ' . $mode . ' detected.');
361 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (6)');
365 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (5)');
369 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (4)');
373 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (3)');
377 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (2)');
382 SQL_FREERESULT($result_mailid);
384 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (1)');
389 SQL_FREERESULT($result_main);
391 // Insert footer if no image
392 if ($mode != 'img') {
394 loadIncludeOnce('inc/footer.php');
398 // Really all done here... ;-)