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')) $userId = bigintval(getRequestParameter('userid'));
71 if (isGetRequestParameterSet('mailid')) $mailId = bigintval(getRequestParameter('mailid'));
72 if (isGetRequestParameterSet('bonusid')) $bonusId = bigintval(getRequestParameter('bonusid'));
73 if (isGetRequestParameterSet('code')) $code = bigintval(getRequestParameter('code'));
74 if (isGetRequestParameterSet('mode')) $mode = getRequestParameter('mode');
76 // 01 2 21 12 2 2 21 1 2210
77 if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 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($mailId, $userId), __FILE__, __LINE__);
87 } elseif ($bonusId > 0) {
88 $result_main = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
89 array($bonusId, $userId), __FILE__, __LINE__);
94 if (SQL_NUMROWS($result_main) == 1) {
95 // Is the stats id valid?
96 list($lid, $ltype) = SQL_FETCHROW($result_main);
98 // Init result here with invalid to avoid possible missing variable
99 $result_mailid = false;
101 // @TODO Rewrite this to a filter
104 $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`, `userid`, `id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
105 array($mailId), __FILE__, __LINE__);
109 $result_mailid = SQL_QUERY_ESC("SELECT `id`, `id`, `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
110 array($bonusId), __FILE__, __LINE__);
113 default: // Unknown type
114 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
119 if (SQL_NUMROWS($result_mailid) == 1) {
121 list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
123 // Correct notification switch in non-bonus mails
124 if (($notify != 'Y') && ($notify != 'N')) $notify = 'N';
126 // Set sender to 0 when we have a bonus mail
127 if ($ltype == 'BONUS') $sender = '0';
129 // Is the user id valid?
130 if (fetchUserData($userId) === true) {
131 // Is the user status CONFIRMED?
132 if (getUserData('status') == 'CONFIRMED') {
133 // User has confirmed his account so we can procede...
134 // @TODO Rewrite this to a filter
137 $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
138 array(bigintval($pool)), __FILE__, __LINE__);
141 if (SQL_NUMROWS($result) == 1) {
142 list($pay) = SQL_FETCHROW($result);
143 $time = getPaymentPoints($pay, 'time');
144 $payment = getPaymentPoints($pay, 'payment');
149 SQL_FREERESULT($result);
153 $result = SQL_QUERY_ESC("SELECT `time`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
154 array(bigintval($pool)), __FILE__, __LINE__);
157 if (SQL_NUMROWS($result) == 1) {
158 list($time, $payment) = SQL_FETCHROW($result);
163 SQL_FREERESULT($result);
166 default: // Unknown type
167 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
171 // Is this entry valid?
172 if ($isValid === true) {
173 if (($time == '0') && ($payment > 0)) $time = 1;
174 if (($time > 0) && ($payment > 0)) {
178 $img_code = generateRandomCode(getConfig('code_length'), $code, $userId, $urlId);
181 // @TODO Rewrite this to a filter
188 // @TODO Rewrite this to a filter
191 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
192 array($mailId), __FILE__, __LINE__);
194 // Update mediadata as well
195 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
197 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
199 $stats_data = $mailId;
203 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
204 array($bonusId), __FILE__, __LINE__);
206 // Update mediadata as well
207 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
209 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
211 $stats_data = $bonusId;
214 default: // Unknown type
215 debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
219 // Export data into constants for the template
220 $content['banner'] = loadTemplate('mailid_banner', true);
222 // Only when user extension = v0.1.2: Update mails-confirmed counter
223 // @TODO Rewrite these blocks to filter
224 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
226 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET mails_confirmed=mails_confirmed + 1 WHERE `userid`=%s LIMIT 1",
227 array($userId), __FILE__, __LINE__);
229 // Update random confirmed as well?
230 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
231 // Update second counter
232 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=`rand_confirmed` + 1 WHERE `userid`=%s LIMIT 1",
233 array($userId), __FILE__, __LINE__);
237 // Insert stats record
238 insertUserStatsRecord($userId, $type, $stats_data);
240 // Right code entered?
241 if (bigintval(postRequestParameter('gfx_check')) == $img_code) {
242 // Add points over referal system is the default
243 $template = 'mailid_points_done';
245 // Right code entered add points and remove entry
246 if (ifUserPointsLocked($userId)) {
247 // Don't add points over the referal system
248 $template = 'mailid_points_locked';
251 // Count down ref_payout value
252 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
253 array($userId), __FILE__, __LINE__);
256 // @TODO Try to rewrite the following unset()
257 unset($GLOBALS['ref_level']);
258 addPointsThroughReferalSystem('mailid_okay', $userId, $payment);
260 // Shall I add bonus points for "turbo clickers" ?
261 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
262 // Is an active-rallye running and this is not a notification mail?
263 if ((isBonusRallyeActive()) && ($notify != 'Y')) {
264 // Shall I exclude the webmaster's own userid from the active-rallye?
265 if ((((getBonusUserId() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserId() != $userId)) && (getConfig('def_refid') != $userId)) {
266 // Add points and remember ranking are done in this function....
267 addTurboBonus($urlId, $userId, $type);
269 // Set template to mailid_points_done2 which contains a link to the ranking list
270 $template = 'mailid_points_done2';
272 // Different template if user has some mails to confirm
273 if (ifUserPointsLocked($userId)) {
274 $template = 'mailid_points_locked2';
277 // Assign more data for the template
278 $content['userid'] = $userId;
279 $content['type'] = $type;
280 $content['data'] = $urlId;
286 $content['total'] = getTotalPoints($userId);
288 // Add payment points
289 $content['points'] = $payment;
292 loadTemplate($template, false, $content);
293 } elseif (isValidUserId($sender)) {
294 // Wrong image code! So add points to sender's account
295 addPointsDirectly('mailid_payback', $sender, $payment);
298 loadTemplate('mailid_points_failed', false, $content);
301 // Remove link from table
302 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
303 array(bigintval($lid)), __FILE__, __LINE__);
307 generateImageOrCode($img_code);
312 // Export data into constants for the template
313 $content['code'] = $code;
314 $content['userid'] = $userId;
315 $content['type'] = $type;
316 $content['data'] = $urlId;
317 $content['banner'] = loadTemplate('mailid_banner', true);
318 if (getConfig('code_length') > 0) {
320 $content['image'] = generateCaptchaCode($code, $type, $urlId, $userId);
321 $templ = 'mailid_enter_code';
324 $content['gfx'] = $img_code;
325 $templ = 'mailid_confirm_buttom';
329 loadTemplate($templ, false, $content);
332 debug_report_bug(__FILE__, __LINE__, 'No code given.');
337 // Ok, all data is valid and loaded. Finally let's output the timer... :-)
338 // Export data into constants for the template
339 $content['time'] = $time;
340 $content['tim2'] = strlen($time);
341 $content['userid'] = $userId;
342 $content['type'] = $type;
343 $content['data'] = $urlId;
344 $content['rand'] = mt_rand(0, 99999);
345 $content['banner'] = loadTemplate('mailid_banner', true);
348 loadTemplate('mailid_timer', false, $content);
351 default: // Unknown mode
352 debug_report_bug(__FILE__, __LINE__, 'Unknown mode ' . $mode . ' detected.');
356 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (6)');
360 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (5)');
364 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (4)');
368 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (3)');
372 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (2)');
377 SQL_FREERESULT($result_mailid);
379 loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (1)');
384 SQL_FREERESULT($result_main);
386 // Insert footer if no image
387 if ($mode != 'img') {
389 loadIncludeOnce('inc/footer.php');
393 // Really all done here... ;-)