]> git.mxchange.org Git - mailer.git/blob - mailid_top.php
Several fixes for broken actions (sorry for lame text)
[mailer.git] / mailid_top.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  * 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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Load security stuff here
40 require('inc/libs/security_functions.php');
41
42 // Init start time
43 $GLOBALS['startTime'] = microtime(true);
44
45 // Tell everyone we are in this module
46 $GLOBALS['module'] = 'mailid';
47 $GLOBALS['output_mode'] = 0;
48
49 // Load the required file(s)
50 require('inc/config-global.php');
51
52 // Set content type
53 setContentType('text/html');
54
55 // Is the extension active
56 redirectOnUninstalledExtension('mailid');
57
58 // Secure all data
59 $url_userid = 0;
60 $url_bid = 0;
61 $url_mid = 0;
62 $code = 0;
63 $mode = '';
64
65 if (isGetRequestElementSet('userid'))  $url_userid = bigintval(getRequestElement('userid'));
66 if (isGetRequestElementSet('mailid'))  $url_mid    = bigintval(getRequestElement('mailid'));
67 if (isGetRequestElementSet('bonusid')) $url_bid    = bigintval(getRequestElement('bonusid'));
68 if (isGetRequestElementSet('code'))    $code       = bigintval(getRequestElement('code'));
69 if (isGetRequestElementSet('mode'))    $mode       = getRequestElement('mode');
70
71 // 01        1        12            2    2            21    1                   22     10
72 if (($url_userid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (getTotalFatalErrors() == 0)) {
73         // No image? Then output header
74         if ($mode != 'img') loadIncludeOnce('inc/header.php');
75
76         // Maybe he wants to confirm an email?
77         if ($url_mid > 0) {
78                 $result = SQL_QUERY_ESC("SELECT `id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
79                         array($url_mid, $url_userid), __FILE__, __LINE__);
80                 $type = 'mailid'; $urlId = $url_mid;
81         } elseif ($url_bid > 0) {
82                 $result = SQL_QUERY_ESC("SELECT `id`, link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
83                         array($url_bid, $url_userid), __FILE__, __LINE__);
84                 $type = 'bonusid'; $urlId = $url_bid;
85         }
86
87         if (SQL_NUMROWS($result) == 1) {
88                 // Is the stats ID valid?
89                 list($lid, $ltype) = SQL_FETCHROW($result);
90                 SQL_FREERESULT($result);
91
92                 // @TODO Rewrite this to a filter
93                 switch ($ltype) {
94                         case 'NORMAL':
95                                 $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`, `userid`, `id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
96                                         array($url_mid), __FILE__, __LINE__);
97                                 break;
98
99                         case 'BONUS':
100                                 $result_mailid = SQL_QUERY_ESC("SELECT `id, `id`, `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
101                                         array($url_bid), __FILE__, __LINE__);
102                                 break;
103
104                         default: // Unknown type
105                                 debug_report_bug('Unknown mail type ' . $ltype . ' detected.');
106                                 break;
107                 }
108
109                 // Entry found?
110                 if (SQL_NUMROWS($result_mailid) == 1) {
111                         // Load data
112                         list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
113
114                         // Correct notification switch in non-bonus mails
115                         if (($notify != 'Y') && ($notify != 'N')) $notify = 'N';
116
117                         // Free some memory
118                         SQL_FREERESULT($result_mailid);
119
120                         // Set sender to 0 when we have a bonus mail
121                         if ($ltype == 'BONUS') $sender = 0;
122
123                         // Is the user's ID unlocked?
124                         $result = SQL_QUERY_ESC("SELECT `status`, `gender`, `surname`, `family`, `ref_payout` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
125                                 array($url_userid), __FILE__, __LINE__);
126                         if (SQL_NUMROWS($result) == 1) {
127                                 // Load data
128                                 list($status, $gender, $surname, $family, $ref_pay) = SQL_FETCHROW($result);
129
130                                 // Free some memory
131                                 SQL_FREERESULT($result);
132
133                                 if ($status == 'CONFIRMED') {
134                                         // Update last activity
135                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `last_online`=UNIX_TIMESTAMP(), `last_module`='mailid_top' WHERE `userid`=%s LIMIT 1",
136                                                 array($url_userid), __FILE__, __LINE__);
137
138                                         // User has confirmed his account so we can procede...
139                                         // @TODO Rewrite this to a filter
140                                         switch ($ltype)
141                                         {
142                                                 case 'NORMAL':
143                                                         $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
144                                                                 array(bigintval($pool)), __FILE__, __LINE__);
145
146                                                         // Entry found?
147                                                         if (SQL_NUMROWS($result) == 1) {
148                                                                 list($pay) = SQL_FETCHROW($result);
149                                                                 $time      = getPaymentPoints($pay, 'time');
150                                                                 $payment   = getPaymentPoints($pay, 'payment');
151                                                                 $isValid   = true;
152                                                         } // END - if
153
154                                                         // Free memory...
155                                                         SQL_FREERESULT($result);
156                                                         break;
157
158                                                 case 'BONUS':
159                                                         $result = SQL_QUERY_ESC("SELECT `time`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
160                                                                 array(bigintval($pool)), __FILE__, __LINE__);
161
162                                                         // Entry found?
163                                                         if (SQL_NUMROWS($result) == 1) {
164                                                                 list($time, $payment) = SQL_FETCHROW($result);
165                                                                 $isValid = true;
166                                                         } // END - if
167
168                                                         // Free memory...
169                                                         SQL_FREERESULT($result);
170                                                         break;
171
172                                                 default: // Unknown type
173                                                         debug_report_bug('Unknown mail type ' . $ltype . ' detected.');
174                                                         break;
175                                         }
176
177                                         // Is this entry valid?
178                                         if ($isValid === true) {
179                                                 if (($time == '0') && ($payment > 0)) $time = '1';
180                                                 if (($time > 0) && ($payment > 0)) {
181                                                         $img_code = 0;
182                                                         if (!empty($code)) {
183                                                                 // Generate code
184                                                                 $img_code = generateRandomCode(getConfig('code_length'), $code, $url_userid, $urlId);
185                                                         } // END - if
186
187                                                         // @TODO Rewrite this to a filter
188                                                         switch ($mode) {
189                                                                 case 'add':
190                                                                         // Init stats data
191                                                                         $stats_data = 0;
192
193                                                                         // Count clicks
194                                                                         // @TODO Rewrite this to a filter
195                                                                         switch ($ltype) {
196                                                                                 case 'NORMAL':
197                                                                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
198                                                                                                 array($url_mid), __FILE__, __LINE__);
199
200                                                                                         // Update mediadata as well
201                                                                                         if (getExtensionVersion('mediadata') >= '0.0.4') {
202                                                                                                 // Update database
203                                                                                                 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
204                                                                                         } // END - if
205                                                                                         $stats_data = $url_mid;
206                                                                                         break;
207
208                                                                                 case 'BONUS':
209                                                                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
210                                                                                                 array($url_bid), __FILE__, __LINE__);
211
212                                                                                         // Update mediadata as well
213                                                                                         if (getExtensionVersion('mediadata') >= '0.0.4') {
214                                                                                                 // Update database
215                                                                                                 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
216                                                                                         } // END - if
217                                                                                         $stats_data = $url_bid;
218                                                                                         break;
219
220                                                                                 default: // Unknown type
221                                                                                         debug_report_bug('Unknown mail type ' . $ltype . ' detected.');
222                                                                                         break;
223                                                                         } // END - switch
224
225                                                                         // Export data into constants for the template
226                                                                         $content['points'] = translateComma($payment);
227                                                                         $content['banner'] = loadTemplate('mailid_banner', true);
228
229                                                                         // Only when user extension = v0.1.2: Update mails-confirmed counter
230                                                                         // @TODO Rewrite these blocks to filter
231                                                                         if (getExtensionVersion('user') >= '0.1.2') {
232                                                                                 // Update counter
233                                                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET mails_confirmed=mails_confirmed + 1 WHERE `userid`=%s LIMIT 1",
234                                                                                 array($url_userid), __FILE__, __LINE__);
235
236                                                                                 // Update random confirmed as well?
237                                                                                 if (getExtensionVersion('user') >= '0.3.4') {
238                                                                                         // Update second counter
239                                                                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET rand_confirmed=rand_confirmed + 1 WHERE `userid`=%s LIMIT 1",
240                                                                                         array($url_userid), __FILE__, __LINE__);
241                                                                                 } // END - if
242                                                                         } // END - if
243
244                                                                         // Insert stats record
245                                                                         insertUserStatsRecord($url_userid, $type, $stats_data);
246
247                                                                         // Right code entered?
248                                                                         if (bigintval(postRequestElement('gfx_check')) == $img_code) {
249                                                                                 // Add points over referal system is the default
250                                                                                 $locked = false;
251                                                                                 $template = 'mailid_points_done';
252
253                                                                                 // Right code entered add points and remove entry
254                                                                                 if (($ref_pay > 0) && (getConfig('allow_direct_pay') != 'Y')) {
255                                                                                         // Don't add points over the referal system
256                                                                                         $locked = true;
257                                                                                         $template = 'mailid_points_locked';
258                                                                                 } // END - if
259
260                                                                                 // Count down ref_payout value
261                                                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
262                                                                                         array($url_userid), __FILE__, __LINE__);
263
264                                                                                 // Add points
265                                                                                 // @TODO Try to rewrite the following unset()
266                                                                                 unset($GLOBALS['ref_level']);
267                                                                                 addPointsThroughReferalSystem('mailid_okay', $url_userid, $payment, false, '0', $locked);
268
269                                                                                 // Shall I add bonus points for "turbo clickers" ?
270                                                                                 if (getExtensionVersion('bonus') >= '0.2.2') {
271                                                                                         // Is an active-rallye running and this is not a notification mail?
272                                                                                         if ((getConfig('bonus_active') == 'Y') && ($notify != 'Y')) {
273                                                                                                 // Shall I exclude the webmaster's own userid from the active-rallye?
274                                                                                                 if ((((getConfig('bonus_userid') == $url_userid) && (getConfig('bonus_include_own') == 'Y')) || (getConfig('bonus_userid') != $url_userid)) && (getConfig('def_refid') != $url_userid)) {
275                                                                                                         // Add points and remember ranking are done in this function....
276                                                                                                         addTurboBonus($urlId, $url_userid, $type);
277
278                                                                                                         // Set template to mailid_points_done2 which contains a link to the ranking list
279                                                                                                         $template = 'mailid_points_done2';
280                                                                                                         if ($locked) $template = 'mailid_points_locked2';
281                                                                                                         $content['userid']  = $url_userid;
282                                                                                                         $content['type']    = $type;
283                                                                                                         $content['data']    = $urlId;
284                                                                                                 } // END - if
285                                                                                         } // END - if
286                                                                                 } // END - if
287
288                                                                                 // Load total points
289                                                                                 $content['total'] = translateComma(
290                                                                                         countSumTotalData($url_userid, 'user_points', 'points') -
291                                                                                         countSumTotalData($url_userid, 'user_data', 'used_points')
292                                                                                 );
293
294                                                                                 // Load template
295                                                                                 loadTemplate($template, false, $content);
296                                                                         } else {
297                                                                                 // Wrong image code! So add points to sender's account
298                                                                                 addPointsDirectly('mailid_payback', $sender, $payment);
299
300                                                                                 // Load template
301                                                                                 loadTemplate('mailid_points_failed', false, $content);
302                                                                         }
303
304                                                                         // Remove link from table
305                                                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
306                                                                                 array(bigintval($lid)), __FILE__, __LINE__);
307                                                                         break;
308
309                                                                 case 'img':
310                                                                         generateImageOrCode($img_code);
311                                                                         break;
312
313                                                                 case 'confirm':
314                                                                         if ($code > 0) {
315                                                                                 // Export data into constants for the template
316                                                                                 $content['code']   = $code;
317                                                                                 $content['userid'] = $url_userid;
318                                                                                 $content['type']   = $type;
319                                                                                 $content['data']   = $urlId;
320                                                                                 $content['banner'] = loadTemplate('mailid_banner', true);
321                                                                                 if (getConfig('code_length') > 0) {
322                                                                                         // Generate Code
323                                                                                         $content['image'] = generateCaptchaCode($code, $type, $urlId, $url_userid);
324                                                                                         $templ = 'mailid_enter_code';
325                                                                                 } else {
326                                                                                         // Disabled code
327                                                                                         $content['gfx'] = $img_code;
328                                                                                         $templ = 'mailid_confirm_buttom';
329                                                                                 }
330
331                                                                                 // Load template
332                                                                                 loadTemplate($templ, false, $content);
333                                                                         }
334                                                                         break;
335
336                                                                 case '':
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'] = $url_userid;
342                                                                         $content['type']   = $type;
343                                                                         $content['data']   = $urlId;
344                                                                         $content['rand']   = mt_rand(0, 99999);
345                                                                         $content['banner'] = loadTemplate('mailid_banner', true);
346
347                                                                         // Load template
348                                                                         loadTemplate('mailid_timer', false, $content);
349                                                                         break;
350
351                                                                 default: // Unknown mode
352                                                                         debug_report_bug('Unknown mode ' . $mode . ' detected.');
353                                                                         break;
354                                                         } // END - switch
355                                                 } else {
356                                                         loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (6)</div>");
357                                                         $mode = 'failed';
358                                                 }
359                                         } else {
360                                                 loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (5)</div>");
361                                                 $mode = 'failed';
362                                         }
363                                 } else {
364                                         loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (4)</div>");
365                                         $mode = 'failed';
366                                 }
367                         } else {
368                                 SQL_FREERESULT($result);
369                                 loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (3)</div>");
370                                 $mode = 'failed';
371                         }
372                 } else {
373                         SQL_FREERESULT($result);
374                         loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (2)</div>");
375                         $mode = 'failed';
376                 }
377         } else {
378                 SQL_FREERESULT($result);
379                 loadTemplate('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (1)</div>");
380                 $mode = 'failed';
381         }
382
383         // Insert footer if no image
384         if ($mode != 'img') {
385                 // Write footer
386                 loadIncludeOnce('inc/footer.php');
387         } // END - if
388 }
389
390 // Really all done here... ;-)
391 shutdown();
392
393 // [EOF]
394 ?>