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, 2010 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');
52 setContentType('text/html');
54 // Is the extension mailid active?
55 redirectOnUninstalledExtension('mailid');
57 // Is the extension other active?
58 redirectOnUninstalledExtension('other');
68 if (isGetRequestParameterSet('userid')) $userId = bigintval(getRequestParameter('userid'));
69 if (isGetRequestParameterSet('mailid')) $mailId = bigintval(getRequestParameter('mailid'));
70 if (isGetRequestParameterSet('bonusid')) $bonusId = bigintval(getRequestParameter('bonusid'));
71 if (isGetRequestParameterSet('code')) $code = bigintval(getRequestParameter('code'));
72 if (isGetRequestParameterSet('mode')) $mode = getRequestParameter('mode');
74 // 01 2 21 12 2 2 21 1 2210
75 if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalErrorsDetected())) {
76 // No image? Then output header
77 if ($mode != 'img') loadIncludeOnce('inc/header.php');
79 // Maybe he wants to confirm an email?
81 $result_main = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
82 array($mailId, $userId), __FILE__, __LINE__);
85 } elseif ($bonusId > 0) {
86 $result_main = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
87 array($bonusId, $userId), __FILE__, __LINE__);
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($mailId), __FILE__, __LINE__);
107 $result_mailid = SQL_QUERY_ESC("SELECT `id`, `id`, `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
108 array($bonusId), __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($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, $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($mailId), __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 = $mailId;
201 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
202 array($bonusId), __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 = $bonusId;
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['banner'] = loadTemplate('mailid_banner', true);
220 // Only when user extension = v0.1.2: Update mails-confirmed counter
221 // @TODO Rewrite these blocks to filter
222 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
224 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET mails_confirmed=mails_confirmed + 1 WHERE `userid`=%s LIMIT 1",
225 array($userId), __FILE__, __LINE__);
227 // Update random confirmed as well?
228 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
229 // Update second counter
230 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=`rand_confirmed` + 1 WHERE `userid`=%s LIMIT 1",
231 array($userId), __FILE__, __LINE__);
235 // Insert stats record
236 insertUserStatsRecord($userId, $type, $stats_data);
238 // Right code entered?
239 if (bigintval(postRequestParameter('gfx_check')) == $img_code) {
240 // Add points over referal system is the default
241 $template = 'mailid_points_done';
243 // Right code entered add points and remove entry
244 if (ifUserPointsLocked($userId)) {
245 // Don't add points over the referal system
246 $template = 'mailid_points_locked';
249 // Count down ref_payout value
250 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
251 array($userId), __FILE__, __LINE__);
254 // @TODO Try to rewrite the following unset()
255 unset($GLOBALS['ref_level']);
256 addPointsThroughReferalSystem('mailid_okay', $userId, $payment);
258 // Shall I add bonus points for "turbo clickers" ?
259 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
260 // Is an active-rallye running and this is not a notification mail?
261 if ((isBonusRallyeActive()) && ($notify != 'Y')) {
262 // Shall I exclude the webmaster's own userid from the active-rallye?
263 if ((((getBonusUserId() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserId() != $userId)) && (getConfig('def_refid') != $userId)) {
264 // Add points and remember ranking are done in this function....
265 addTurboBonus($urlId, $userId, $type);
267 // Set template to mailid_points_done2 which contains a link to the ranking list
268 $template = 'mailid_points_done2';
270 // Different template if user has some mails to confirm
271 if (ifUserPointsLocked($userId)) {
272 $template = 'mailid_points_locked2';
275 // Assign more data for the template
276 $content['userid'] = $userId;
277 $content['type'] = $type;
278 $content['data'] = $urlId;
284 $content['total'] = getTotalPoints($userId);
286 // Add payment points
287 $content['points'] = $payment;
290 loadTemplate($template, false, $content);
291 } elseif (isValidUserId($sender)) {
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'] = $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, $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(__FILE__, __LINE__, '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'] = $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(__FILE__, __LINE__, 'Unknown mode ' . $mode . ' detected.');
354 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (6)');
358 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (5)');
362 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (4)');
366 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (3)');
370 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (2)');
375 SQL_FREERESULT($result_mailid);
377 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (1)');
382 SQL_FREERESULT($result_main);
384 // Insert footer if no image
385 if ($mode != 'img') {
387 loadIncludeOnce('inc/footer.php');
391 // Really all done here... ;-)