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())) {
78 // ... then output header
79 loadIncludeOnce('inc/header.php');
82 // Maybe he wants to confirm an email?
84 $result_main = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
85 array($mailId, $userId), __FILE__, __LINE__);
88 } elseif ($bonusId > 0) {
89 $result_main = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
90 array($bonusId, $userId), __FILE__, __LINE__);
95 if (SQL_NUMROWS($result_main) == 1) {
96 // Is the stats id valid?
97 list($lid, $ltype) = SQL_FETCHROW($result_main);
99 // Init result here with invalid to avoid possible missing variable
100 $result_mailid = false;
102 // @TODO Rewrite this to a filter
105 $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`, `userid`, `id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
106 array($mailId), __FILE__, __LINE__);
110 $result_mailid = SQL_QUERY_ESC("SELECT `id`, `id`, `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
111 array($bonusId), __FILE__, __LINE__);
114 default: // Unknown type
115 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
120 if (SQL_NUMROWS($result_mailid) == 1) {
122 list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
124 // Correct notification switch in non-bonus mails
125 if (($notify != 'Y') && ($notify != 'N')) $notify = 'N';
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($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(__FILE__, __LINE__, '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(getCodeLength(), $code, $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($mailId), __FILE__, __LINE__);
195 // Update mediadata as well
196 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
198 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
200 $stats_data = $mailId;
204 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
205 array($bonusId), __FILE__, __LINE__);
207 // Update mediadata as well
208 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
210 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
212 $stats_data = $bonusId;
215 default: // Unknown type
216 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
220 // Export data into constants for the template
221 $content['banner'] = loadTemplate('mailid_banner', true);
223 // Only when user extension = v0.1.2: Update mails-confirmed counter
224 // @TODO Rewrite these blocks to filter
225 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
227 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET mails_confirmed=mails_confirmed + 1 WHERE `userid`=%s LIMIT 1",
228 array($userId), __FILE__, __LINE__);
230 // Update random confirmed as well?
231 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
232 // Update second counter
233 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=`rand_confirmed` + 1 WHERE `userid`=%s LIMIT 1",
234 array($userId), __FILE__, __LINE__);
238 // Insert stats record
239 insertUserStatsRecord($userId, $type, $stats_data);
241 // Right code entered?
242 if (bigintval(postRequestParameter('gfx_check')) == $img_code) {
243 // Add points over referal system is the default
244 $template = 'mailid_points_done';
246 // Right code entered add points and remove entry
247 if (ifUserPointsLocked($userId)) {
248 // 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($userId), __FILE__, __LINE__);
257 // @TODO Try to rewrite the following unset()
258 unset($GLOBALS['ref_level']);
259 addPointsThroughReferalSystem('mailid_okay', $userId, $payment);
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 ((isBonusRallyeActive()) && ($notify != 'Y')) {
265 // Shall I exclude the webmaster's own userid from the active-rallye?
266 if ((((getBonusUserId() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserId() != $userId)) && (getDefRefid() != $userId)) {
267 // Add points and remember ranking are done in this function....
268 addTurboBonus($urlId, $userId, $type);
270 // Set template to mailid_points_done2 which contains a link to the ranking list
271 $template = 'mailid_points_done2';
273 // Different template if user has some mails to confirm
274 if (ifUserPointsLocked($userId)) {
275 $template = 'mailid_points_locked2';
278 // Assign more data for the template
279 $content['userid'] = $userId;
280 $content['type'] = $type;
281 $content['data'] = $urlId;
287 $content['total'] = getTotalPoints($userId);
289 // Add payment points
290 $content['points'] = $payment;
293 loadTemplate($template, false, $content);
294 } elseif (isValidUserId($sender)) {
295 // Wrong image code! So add points to sender's account
296 addPointsDirectly('mailid_payback', $sender, $payment);
299 loadTemplate('mailid_points_failed', false, $content);
302 // Remove link from table
303 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
304 array(bigintval($lid)), __FILE__, __LINE__);
308 generateImageOrCode($img_code);
313 // Export data into constants for the template
314 $content['code'] = $code;
315 $content['userid'] = $userId;
316 $content['type'] = $type;
317 $content['data'] = $urlId;
318 $content['banner'] = loadTemplate('mailid_banner', true);
319 if (getCodeLength() > 0) {
321 $content['image'] = generateCaptchaCode($code, $type, $urlId, $userId);
322 $templ = 'mailid_enter_code';
325 $content['gfx'] = $img_code;
326 $templ = 'mailid_confirm_buttom';
330 loadTemplate($templ, false, $content);
333 debug_report_bug(__FILE__, __LINE__, 'No code given.');
338 // Ok, all data is valid and loaded. Finally let's output the timer... :-)
339 // Export data into constants for the template
340 $content['time'] = $time;
341 $content['tim2'] = strlen($time);
342 $content['userid'] = $userId;
343 $content['type'] = $type;
344 $content['data'] = $urlId;
345 $content['rand'] = mt_rand(0, 99999);
346 $content['banner'] = loadTemplate('mailid_banner', true);
349 loadTemplate('mailid_timer', false, $content);
352 default: // Unknown mode
353 debug_report_bug(__FILE__, __LINE__, 'Unknown mode ' . $mode . ' detected.');
357 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (6)');
361 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (5)');
365 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (4)');
369 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (3)');
373 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (2)');
378 SQL_FREERESULT($result_mailid);
380 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (1)');
385 SQL_FREERESULT($result_main);
387 // Insert footer if no image
388 if ($mode != 'img') {
390 loadIncludeOnce('inc/footer.php');
394 // Really all done here... ;-)