]> git.mxchange.org Git - mailer.git/blob - mailid_top.php
Extension ext-surfbar continued:
[mailer.git] / mailid_top.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 11/14/2003 *
4  * ===================                          Last change: 11/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : mailid_top.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Confirmation file for emails                     *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Bestaetigung von Mails                           *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * @TODO Merge this script with mailid.php                              *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
22  * For more information visit: http://mxchange.org                      *
23  *                                                                      *
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.                                  *
28  *                                                                      *
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.                         *
33  *                                                                      *
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,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Load security stuff here
41 require('inc/libs/security_functions.php');
42
43 // Init start time
44 $GLOBALS['__start_time'] = microtime(TRUE);
45
46 // Tell everyone we are in this module
47 $GLOBALS['__module']      = 'mailid';
48 $GLOBALS['__output_mode'] = '0';
49
50 // Disable copyright footer which would be to large for the upper frame
51 $GLOBALS['__copyright_enabled'] = 'N';
52
53 // Load the required file(s)
54 require('inc/config-global.php');
55
56 // Set content type and HTTP status
57 setContentType('text/html');
58 setHttpStatus('404 Not Found');
59
60 // Is the extension mailid active?
61 redirectOnUninstalledExtension('mailid');
62
63 // Is the extension other active?
64 redirectOnUninstalledExtension('other');
65
66 // Init variables
67 $userId = '0';
68 $bonusId = '0';
69 $mailId = '0';
70 $code = '0';
71 $do = '';
72
73 // Secure all data
74 if (isGetRequestElementSet('userid'))  $userId  = bigintval(getRequestElement('userid'));
75 if (isGetRequestElementSet('mailid'))  $mailId  = bigintval(getRequestElement('mailid'));
76 if (isGetRequestElementSet('bonusid')) $bonusId = bigintval(getRequestElement('bonusid'));
77 if (isGetRequestElementSet('code'))    $code    = bigintval(getRequestElement('code'));
78 if (isGetRequestElementSet('do'))      $do      = getRequestElement('do');
79
80 // 01             2       21    12           2    2            21    1                      2210
81 if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalErrorsDetected())) {
82         // No image?
83         if ($do != 'img') {
84                 // ... then output header
85                 loadIncludeOnce('inc/header.php');
86         } // END - fi
87
88         // Maybe he wants to confirm an email?
89         if ($mailId > 0) {
90                 $result_main = SQL_QUERY_ESC("SELECT `id` AS `link_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
91                         array($mailId, $userId), __FILE__, __LINE__);
92                 $type = 'mailid';
93                 $urlId = $mailId;
94         } elseif ($bonusId > 0) {
95                 $result_main = SQL_QUERY_ESC("SELECT `id` AS `link_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
96                         array($bonusId, $userId), __FILE__, __LINE__);
97                 $type = 'bonusid';
98                 $urlId = $bonusId;
99         } else {
100                 // Not detected
101                 reportBug(__FILE__, __LINE__, 'Whether bonusid or mailid was set. This is a strange bug.');
102         }
103
104         // Is an entry found?
105         if (SQL_NUMROWS($result_main) == 1) {
106                 // Is the stats id valid?
107                 $data = SQL_FETCHARRAY($result_main);
108
109                 // Init result here with invalid to avoid possible missing variable
110                 $result_mailid = FALSE;
111
112                 // @TODO Rewrite this to a filter/function
113                 switch ($data['link_type']) {
114                         case 'NORMAL':
115                                 $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`, `userid` AS `sender` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
116                                         array($urlId), __FILE__, __LINE__);
117                                 break;
118
119                         case 'BONUS':
120                                 $result_mailid = SQL_QUERY_ESC("SELECT `id` AS `pool_id`, `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
121                                         array($urlId), __FILE__, __LINE__);
122                                 break;
123
124                         default: // Unknown type
125                                 reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
126                                 break;
127                 } // END - switch
128
129                 // Entry found?
130                 if (SQL_NUMROWS($result_mailid) == 1) {
131                         // Load data
132                         $data = merge_array($data, SQL_FETCHARRAY($result_mailid));
133
134                         // Correct notification switch in non-bonus mails
135                         if ((!isset($data['is_notify'])) || (!in_array($data['is_notify'], array('Y', 'N')))) {
136                                 $data['is_notify'] = 'N';
137                         } // END - if
138
139                         // Set sender to 0 when we have a bonus mail
140                         if ($data['link_type'] == 'BONUS') {
141                                 $data['sender'] = NULL;
142                         } // END - if
143
144                         // Is the user id valid?
145                         if (fetchUserData($userId) === TRUE) {
146                                 // Is the user status CONFIRMED?
147                                 if (getUserData('status') == 'CONFIRMED') {
148                                         // User has confirmed his account so we can procede...
149                                         // @TODO Rewrite this to a filter
150                                         switch ($data['link_type']) {
151                                                 case 'NORMAL':
152                                                         $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
153                                                                 array(bigintval($data['pool_id'])), __FILE__, __LINE__);
154
155                                                         // Entry found?
156                                                         if (SQL_NUMROWS($result) == 1) {
157                                                                 list($paymentId) = SQL_FETCHROW($result);
158                                                                 $time      = getPaymentData($paymentId, 'time');
159                                                                 $payment   = getPaymentData($paymentId, 'payment');
160                                                                 $isValid   = TRUE;
161                                                         } // END - if
162
163                                                         // Free memory...
164                                                         SQL_FREERESULT($result);
165                                                         break;
166
167                                                 case 'BONUS':
168                                                         $result = SQL_QUERY_ESC("SELECT `time`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
169                                                                 array(bigintval($data['pool_id'])), __FILE__, __LINE__);
170
171                                                         // Entry found?
172                                                         if (SQL_NUMROWS($result) == 1) {
173                                                                 list($time, $payment) = SQL_FETCHROW($result);
174                                                                 $isValid = TRUE;
175                                                         } // END - if
176
177                                                         // Free memory...
178                                                         SQL_FREERESULT($result);
179                                                         break;
180
181                                                 default: // Unknown type
182                                                         reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
183                                                         break;
184                                         } // END - switch
185
186                                         // Is this entry valid?
187                                         if ($isValid === TRUE) {
188                                                 // Run at least one second
189                                                 if (($time == '0') && ($payment > 0)) $time = 1;
190
191                                                 // Is time and payment set?
192                                                 if (($time > 0) && ($payment > 0)) {
193                                                         $realCode = '0';
194                                                         if (!empty($code)) {
195                                                                 // Generate code (the user sees in the CAPTCHA)
196                                                                 $realCode = generateRandomCode(getCodeLength(), $code, $userId, $urlId);
197                                                         } // END - if
198
199                                                         // @TODO Rewrite this to a filter
200                                                         switch ($do) {
201                                                                 case 'add':
202                                                                         // Init stats data
203                                                                         $stats_data = '0';
204
205                                                                         // Count clicks
206                                                                         // @TODO Rewrite this to a filter
207                                                                         switch ($data['link_type']) {
208                                                                                 case 'NORMAL':
209                                                                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
210                                                                                                 array($mailId), __FILE__, __LINE__);
211
212                                                                                         // Update mediadata as well
213                                                                                         if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
214                                                                                                 // Update database
215                                                                                                 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
216                                                                                         } // END - if
217                                                                                         $stats_data = $mailId;
218                                                                                         break;
219
220                                                                                 case 'BONUS':
221                                                                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
222                                                                                                 array($bonusId), __FILE__, __LINE__);
223
224                                                                                         // Update mediadata as well
225                                                                                         if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
226                                                                                                 // Update database
227                                                                                                 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
228                                                                                         } // END - if
229                                                                                         $stats_data = $bonusId;
230                                                                                         break;
231
232                                                                                 default: // Unknown type
233                                                                                         reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
234                                                                                         break;
235                                                                         } // END - switch
236
237                                                                         // Export data into constants for the template
238                                                                         $content['banner'] = loadTemplate('mailid_banner', TRUE);
239
240                                                                         // Only when user extension = v0.1.2: Update mails-confirmed counter
241                                                                         // @TODO Rewrite these blocks to filter
242                                                                         if (isExtensionInstalledAndNewer('user', '0.1.2')) {
243                                                                                 // Update counter
244                                                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `mails_confirmed`=`mails_confirmed`+1 WHERE `userid`=%s LIMIT 1",
245                                                                                         array($userId), __FILE__, __LINE__);
246
247                                                                                 // Update random confirmed as well?
248                                                                                 if ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isRandomReferralIdEnabled())) {
249                                                                                         // Update second counter
250                                                                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=`rand_confirmed` + 1 WHERE `userid`=%s LIMIT 1",
251                                                                                                 array($userId), __FILE__, __LINE__);
252                                                                                 } // END - if
253                                                                         } // END - if
254
255                                                                         // Insert stats record
256                                                                         insertUserStatsRecord($userId, $type, $stats_data);
257
258                                                                         // Right code entered?
259                                                                         if (bigintval(postRequestElement('gfx_check')) == $realCode) {
260                                                                                 // Set HTTP status to okay
261                                                                                 setHttpStatus('200 OK');
262
263                                                                                 // Add points over referral system is the default
264                                                                                 $template = 'mailid_points_done';
265
266                                                                                 // Right code entered add points and remove entry
267                                                                                 if (ifUserPointsLocked($userId)) {
268                                                                                         // Don't add points over the referral system
269                                                                                         $template = 'mailid_points_locked';
270                                                                                 } // END - if
271
272                                                                                 // Count down ref_payout value
273                                                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
274                                                                                         array($userId), __FILE__, __LINE__);
275
276                                                                                 // Add points
277                                                                                 initReferralSystem();
278                                                                                 addPointsThroughReferralSystem('mailid_okay', $userId, $payment);
279
280                                                                                 // Shall I add bonus points for "turbo clickers" ?
281                                                                                 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
282                                                                                         // Is an active-rallye running and this is not a notification mail?
283                                                                                         if ((isBonusRallyeActive()) && ($data['is_notify'] != 'Y')) {
284                                                                                                 // Shall I exclude the webmaster's own userid from the active-rallye?
285                                                                                                 if ((((getBonusUserid() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserid() != $userId)) && (getDefRefid() != $userId)) {
286                                                                                                         // Add points and remember ranking are done in this function....
287                                                                                                         addTurboBonus($urlId, $userId, $type);
288
289                                                                                                         // Set template to mailid_points_done2 which contains a link to the ranking list
290                                                                                                         $template = 'mailid_points_done2';
291
292                                                                                                         // Different template if user has some mails to confirm
293                                                                                                         if (ifUserPointsLocked($userId)) {
294                                                                                                                 $template = 'mailid_points_locked2';
295                                                                                                         } // END - if
296
297                                                                                                         // Assign more data for the template
298                                                                                                         $content['userid']  = $userId;
299                                                                                                         $content['type']    = $type;
300                                                                                                         $content['data']    = $urlId;
301                                                                                                 } // END - if
302                                                                                         } // END - if
303                                                                                 } // END - if
304
305                                                                                 // Load total points
306                                                                                 $content['total_points']  = getTotalPoints($userId);
307
308                                                                                 // Add payment points
309                                                                                 $content['points'] = $payment;
310
311                                                                                 // Load template
312                                                                                 loadTemplate($template, FALSE, $content);
313                                                                         } elseif (isValidUserId($data['sender'])) {
314                                                                                 // Wrong image code! So add points to sender's account
315                                                                                 initReferralSystem();
316                                                                                 addPointsThroughReferralSystem('mailid_payback', $data['sender'], $payment);
317
318                                                                                 // Add payment points
319                                                                                 $content['points'] = $payment;
320
321                                                                                 // Load template
322                                                                                 loadTemplate('mailid_points_failed', FALSE, $content);
323                                                                         } else {
324                                                                                 // Add payment points (again)
325                                                                                 $content['points'] = $payment;
326
327                                                                                 // Load template
328                                                                                 loadTemplate('mailid_points_failed2', FALSE, $content);
329                                                                         }
330
331                                                                         // Remove link from table
332                                                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
333                                                                                 array(bigintval($data['link_id'])), __FILE__, __LINE__);
334                                                                         break;
335
336                                                                 case 'img':
337                                                                         generateImageOrCode($realCode);
338                                                                         break;
339
340                                                                 case 'confirm':
341                                                                         if ($code > 0) {
342                                                                                 // Export data into constants for the template
343                                                                                 $content['code']   = $code;
344                                                                                 $content['userid'] = $userId;
345                                                                                 $content['type']   = $type;
346                                                                                 $content['data']   = $urlId;
347                                                                                 $content['banner'] = loadTemplate('mailid_banner', TRUE);
348                                                                                 if (getCodeLength() > 0) {
349                                                                                         // Generate Code
350                                                                                         $content['image'] = generateCaptchaCode($code, $type, $urlId, $userId);
351                                                                                         $templ = 'mailid_enter_code';
352                                                                                 } else {
353                                                                                         // Disabled code
354                                                                                         $content['gfx'] = $realCode;
355                                                                                         $templ = 'mailid_confirm_buttom';
356                                                                                 }
357
358                                                                                 // Load template
359                                                                                 loadTemplate($templ, FALSE, $content);
360                                                                         } else {
361                                                                                 // Cannot confirm!
362                                                                                 reportBug(__FILE__, __LINE__, 'No code given.');
363                                                                         }
364                                                                         break;
365
366                                                                 case '':
367                                                                         // Ok, all data is valid and loaded. Finally let's output the timer... :-)
368                                                                         // Export data into constants for the template
369                                                                         $content['time']   = $time;
370                                                                         $content['tim2']   = strlen($time);
371                                                                         $content['userid'] = $userId;
372                                                                         $content['type']   = $type;
373                                                                         $content['data']   = $urlId;
374                                                                         $content['rand']   = getRandomTan();
375                                                                         $content['banner'] = loadTemplate('mailid_banner', TRUE);
376
377                                                                         // Load template
378                                                                         loadTemplate('mailid_timer', FALSE, $content);
379                                                                         break;
380
381                                                                 default: // Unknown mode
382                                                                         reportBug(__FILE__, __LINE__, 'Unknown mode ' . $do . ' detected.');
383                                                                         break;
384                                                         } // END - switch
385                                                 } else {
386                                                         loadTemplate('admin_settings_unsaved', FALSE, '{--MAIL_ALREADY_CONFIRMED--} (6)');
387                                                         $do = 'failed';
388                                                 }
389                                         } else {
390                                                 loadTemplate('admin_settings_unsaved', FALSE, '{--MAIL_ALREADY_CONFIRMED--} (5)');
391                                                 $do = 'failed';
392                                         }
393                                 } else {
394                                         loadTemplate('admin_settings_unsaved', FALSE, '{--MAIL_ALREADY_CONFIRMED--} (4)');
395                                         $do = 'failed';
396                                 }
397                         } else {
398                                 loadTemplate('admin_settings_unsaved', FALSE, '{--MAIL_ALREADY_CONFIRMED--} (3)');
399                                 $do = 'failed';
400                         }
401                 } else {
402                         loadTemplate('admin_settings_unsaved', FALSE, '{--MAIL_ALREADY_CONFIRMED--} (2)');
403                         $do = 'failed';
404                 }
405
406                 // Free result
407                 SQL_FREERESULT($result_mailid);
408         } else {
409                 loadTemplate('admin_settings_unsaved', FALSE, '{--MAIL_ALREADY_CONFIRMED--} (1)');
410                 $do = 'failed';
411         }
412
413         // Free result
414         SQL_FREERESULT($result_main);
415
416         // Insert footer if no image
417         if ($do != 'img') {
418                 // Write footer
419                 loadIncludeOnce('inc/footer.php');
420         } // END - if
421 }
422
423 // Really all done here... ;-)
424 doShutdown();
425
426 // [EOF]
427 ?>