Possible fix for missing ext_notes while displaying extension tasks, TODOs.txt updated
[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 - 2008 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 "action" and "what"
43 $GLOBALS['what'] = '';
44 $GLOBALS['action'] = '';
45
46 // Tell everyone we are in this module
47 $GLOBALS['module'] = 'mailid';
48 $GLOBALS['output_mode'] = 0;
49
50 // Load the required file(s)
51 require('inc/config-global.php');
52
53 if (isInstalled()) {
54         // Is the extension active
55         redirectOnUninstalledExtension('mailid');
56
57         // Secure all data
58         $url_uid = 0; $url_bid = 0; $url_mid = 0; $code = 0; $mode = '';
59         if (REQUEST_ISSET_GET('uid'))     $url_uid = bigintval(REQUEST_GET('uid'));
60         if (REQUEST_ISSET_GET('mailid'))  $url_mid = bigintval(REQUEST_GET('mailid'));
61         if (REQUEST_ISSET_GET('bonusid')) $url_bid = bigintval(REQUEST_GET('bonusid'));
62         if (REQUEST_ISSET_GET('code'))    $code    = bigintval(REQUEST_GET('code'));
63         if (REQUEST_ISSET_GET('mode'))    $mode    = REQUEST_GET('mode');
64
65         // 01        1        12            2    2            21    1                   22     10
66         if (($url_uid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (getTotalFatalErrors() == 0)) {
67                 // No image? Then output header
68                 if ($mode != 'img') loadIncludeOnce('inc/header.php');
69
70                 // Maybe he wants to confirm an email?
71                 if ($url_mid > 0) {
72                         $result = SQL_QUERY_ESC("SELECT id, link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE stats_id=%s AND `userid`=%s LIMIT 1",
73                         array($url_mid, $url_uid), __FILE__, __LINE__);
74                         $type = 'mailid'; $urlId = $url_mid;
75                 } elseif ($url_bid > 0) {
76                         $result = SQL_QUERY_ESC("SELECT id, link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE bonus_id=%s AND `userid`=%s LIMIT 1",
77                         array($url_bid, $url_uid), __FILE__, __LINE__);
78                         $type = 'bonusid'; $urlId = $url_bid;
79                 }
80
81                 if (SQL_NUMROWS($result) == 1) {
82                         // Is the stats ID valid?
83                         list($lid, $ltype) = SQL_FETCHROW($result);
84                         SQL_FREERESULT($result);
85                         switch ($ltype)
86                         {
87                                 case 'NORMAL':
88                                         $result_mailid = SQL_QUERY_ESC("SELECT pool_id, userid, id FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE `id`=%s LIMIT 1",
89                                         array($url_mid), __FILE__, __LINE__);
90                                         break;
91
92                                 case 'BONUS':
93                                         $result_mailid = SQL_QUERY_ESC("SELECT id, id, is_notify FROM `{!_MYSQL_PREFIX!}_bonus` WHERE `id`=%s LIMIT 1",
94                                         array($url_bid), __FILE__, __LINE__);
95                                         break;
96                         }
97
98                         // Entry found?
99                         if (SQL_NUMROWS($result_mailid) == 1) {
100                                 // Load data
101                                 list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
102
103                                 // Correct notification switch in non-bonus mails
104                                 if (($notify != 'Y') && ($notify != 'N')) $notify = 'N';
105
106                                 // Free some memory
107                                 SQL_FREERESULT($result_mailid);
108
109                                 // Set sender to 0 when we have a bonus mail
110                                 if ($ltype == 'BONUS') $sender = 0;
111
112                                 // Is the user's ID unlocked?
113                                 $result = SQL_QUERY_ESC("SELECT status, gender, surname, family, ref_payout FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
114                                 array($url_uid), __FILE__, __LINE__);
115                                 if (SQL_NUMROWS($result) == 1) {
116                                         // Load data
117                                         list($status, $gender, $sname, $fname, $ref_pay) = SQL_FETCHROW($result);
118
119                                         // Free some memory
120                                         SQL_FREERESULT($result);
121
122                                         if ($status == 'CONFIRMED') {
123                                                 // Update last activity
124                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET last_online=UNIX_TIMESTAMP(), `last_module`='mailid_top' WHERE userid=%s LIMIT 1",
125                                                 array($url_uid), __FILE__, __LINE__);
126
127                                                 // User has confirmed his account so we can procede...
128                                                 switch ($ltype)
129                                                 {
130                                                         case 'NORMAL':
131                                                                 $result = SQL_QUERY_ESC("SELECT payment_id FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE pool_id=%s LIMIT 1",
132                                                                 array(bigintval($pool)), __FILE__, __LINE__);
133
134                                                                 // Entry found?
135                                                                 if (SQL_NUMROWS($result) == 1) {
136                                                                         list($pay) = SQL_FETCHROW($result);
137                                                                         $time      = getPaymentPoints($pay, 'time');
138                                                                         $payment   = getPaymentPoints($pay, 'payment');
139                                                                         $isValid   = true;
140                                                                 } // END - if
141
142                                                                 // Free memory...
143                                                                 SQL_FREERESULT($result);
144                                                                 break;
145
146                                                         case 'BONUS':
147                                                                 $result = SQL_QUERY_ESC("SELECT time, points FROM `{!_MYSQL_PREFIX!}_bonus` WHERE `id`=%s LIMIT 1",
148                                                                 array(bigintval($pool)), __FILE__, __LINE__);
149
150                                                                 // Entry found?
151                                                                 if (SQL_NUMROWS($result) == 1) {
152                                                                         list($time, $payment) = SQL_FETCHROW($result);
153                                                                         $isValid = true;
154                                                                 }
155
156                                                                 // Free memory...
157                                                                 SQL_FREERESULT($result);
158                                                                 break;
159                                                 }
160
161                                                 // Is this entry valid?
162                                                 if ($isValid) {
163                                                         if (($time == '0') && ($payment > 0)) $time = '1';
164                                                         if (($time > 0) && ($payment > 0)) {
165                                                                 if (!empty($code)) {
166                                                                         // Generate code
167                                                                         $img_code = generateRandomCodde(getConfig('code_length'), $code, $url_uid, $urlId);
168                                                                 } // END - if
169
170                                                                 switch ($mode) {
171                                                                         case 'add':
172                                                                                 // Init stats data
173                                                                                 $stats_data = 0;
174
175                                                                                 // Count clicks
176                                                                                 switch ($ltype)
177                                                                                 {
178                                                                                         case 'NORMAL':
179                                                                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_stats` SET clicks=clicks + 1 WHERE `id`=%s LIMIT 1",
180                                                                                                 array($url_mid), __FILE__, __LINE__);
181
182                                                                                                 // Update mediadata as well
183                                                                                                 if (GET_EXT_VERSION('mediadata') >= '0.0.4') {
184                                                                                                         // Update database
185                                                                                                         MEDIA_UPDATE_ENTRY(array('total_clicks', 'normal_clicks'), 'add', 1);
186                                                                                                 }
187                                                                                                 $stats_data = $url_mid;
188                                                                                                 break;
189
190                                                                                         case 'BONUS':
191                                                                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_bonus` SET clicks=clicks + 1 WHERE `id`=%s LIMIT 1",
192                                                                                                 array($url_bid), __FILE__, __LINE__);
193
194                                                                                                 // Update mediadata as well
195                                                                                                 if (GET_EXT_VERSION('mediadata') >= '0.0.4') {
196                                                                                                         // Update database
197                                                                                                         MEDIA_UPDATE_ENTRY(array('total_clicks', 'bonus_clicks'), 'add', 1);
198                                                                                                 }
199                                                                                                 $stats_data = $url_bid;
200                                                                                                 break;
201                                                                                 }
202
203                                                                                 // Export data into constants for the template
204                                                                                 define('_POINTS_VALUE'   , translateComma($payment));
205                                                                                 define('_TEMPLATE_BANNER', LOAD_TEMPLATE('mailid_banner', true));
206
207                                                                                 // Only when user extension = v0.1.2: Update mails-confirmed counter
208                                                                                 // @TODO Rewrite these blocks to filter
209                                                                                 if (GET_EXT_VERSION('user') >= '0.1.2') {
210                                                                                         // Update counter
211                                                                                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET mails_confirmed=mails_confirmed + 1 WHERE userid=%s LIMIT 1",
212                                                                                         array($url_uid), __FILE__, __LINE__);
213
214                                                                                         // Update random confirmed as well?
215                                                                                         if (GET_EXT_VERSION('user') >= '0.3.4') {
216                                                                                                 // Update second counter
217                                                                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET rand_confirmed=rand_confirmed + 1 WHERE userid=%s LIMIT 1",
218                                                                                                 array($url_uid), __FILE__, __LINE__);
219                                                                                         } // END - if
220                                                                                 } // END - if
221
222                                                                                 // Insert stats record
223                                                                                 insertUserStatsRecord($url_uid, $type, $stats_data);
224
225                                                                                 // Right code entered?
226                                                                                 if (bigintval(REQUEST_POST('gfx_check')) == $img_code) {
227                                                                                         // Add points over referal system is the default
228                                                                                         $locked = false;
229                                                                                         $template = 'mailid_points_done';
230
231                                                                                         // Right code entered add points and remove entry
232                                                                                         if (($ref_pay > 0) && (getConfig('allow_direct_pay') != 'Y')) {
233                                                                                                 // Don't add points over the referal system
234                                                                                                 $locked = true;
235                                                                                                 $template = 'mailid_points_locked';
236                                                                                         } // END - if
237
238                                                                                         // Count down ref_payout value
239                                                                                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET ref_payout=ref_payout-1 WHERE userid=%s AND ref_payout > 0 LIMIT 1",
240                                                                                         array($url_uid), __FILE__, __LINE__);
241
242                                                                                         // Add points
243                                                                                         unset($GLOBALS['ref_level']);
244                                                                                         ADD_POINTS_REFSYSTEM('mailid_okay', $url_uid, $payment, false, '0', $locked);
245
246                                                                                         // Shall I add bonus points for "turbo clickers" ?
247                                                                                         if (GET_EXT_VERSION('bonus') >= '0.2.2') {
248                                                                                                 // Is an active-rallye running and this is not a notification mail?
249                                                                                                 if ((getConfig('bonus_active') == 'Y') && ($notify == 'N')) {
250                                                                                                         // Shall I exclude the webmaster's own userid from the active-rallye?
251                                                                                                         if ((((getConfig('bonus_uid') == $url_uid) && (getConfig('bonus_include_own') == 'Y')) || (getConfig('bonus_uid') != $url_uid)) && (getConfig('def_refid') != $url_uid)) {
252                                                                                                                 // Add points and remember ranking are done in this function....
253                                                                                                                 BONUS_ADD_TURBO_POINTS($urlId, $url_uid, $type);
254
255                                                                                                                 // Set template to mailid_points_done2 which contains a link to the ranking list
256                                                                                                                 $template = 'mailid_points_done2';
257                                                                                                                 if ($locked) $template = 'mailid_points_locked2';
258                                                                                                                 define('_UID_VALUE' , $url_uid);
259                                                                                                                 define('_TYPE_VALUE', $type);
260                                                                                                                 define('_DATA_VALUE', translateComma($urlId));
261                                                                                                         } // END - if
262                                                                                                 } // END - if
263                                                                                         } // END - if
264
265                                                                                         // Load total points
266                                                                                         define('__TOTAL_POINTS', translateComma(
267                                                                                         GET_TOTAL_DATA($url_uid, 'user_points', 'points') -
268                                                                                         GET_TOTAL_DATA($url_uid, 'user_data', 'used_points'))
269                                                                                         );
270
271                                                                                         // Load template
272                                                                                         LOAD_TEMPLATE($template);
273                                                                                 } else {
274                                                                                         // Wrong image code! So add points to sender's account
275                                                                                         unset($GLOBALS['ref_level']);
276                                                                                         ADD_POINTS_REFSYSTEM_DIRECT('mailid_payback', $sender, $payment);
277
278                                                                                         // Load template
279                                                                                         LOAD_TEMPLATE('mailid_points_failed');
280                                                                                 }
281
282                                                                                 // Remove link from table
283                                                                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_links` WHERE `id`=%s LIMIT 1",
284                                                                                 array(bigintval($lid)), __FILE__, __LINE__);
285                                                                                 break;
286
287                                                                                         case 'img':
288                                                                                                 GENERATE_IMAGE($img_code);
289                                                                                                 break;
290
291                                                                                         case 'confirm':
292                                                                                                 if ($code > 0) {
293                                                                                                         // Export data into constants for the template
294                                                                                                         define('_CODE_VALUE', $code);
295                                                                                                         define('_UID_VALUE' , $url_uid );
296                                                                                                         define('_TYPE_VALUE', $type);
297                                                                                                         define('_DATA_VALUE', $urlId);
298                                                                                                         define('_TEMPLATE_BANNER', LOAD_TEMPLATE('mailid_banner', true));
299                                                                                                         if (getConfig('code_length') > 0) {
300                                                                                                                 // Generate Code
301                                                                                                                 define('_IMAGE_CODE', generateCaptchaCode($code, $type, $urlId, $url_uid));
302                                                                                                                 $templ = 'mailid_enter_code';
303                                                                                                         } else {
304                                                                                                                 // Disabled code
305                                                                                                                 define('__GFX_CODE', $img_code);
306                                                                                                                 $templ = 'mailid_confirm_buttom';
307                                                                                                         }
308
309                                                                                                         // Load template
310                                                                                                         LOAD_TEMPLATE($templ);
311                                                                                                 }
312                                                                                                 break;
313
314                                                                                         case '':
315                                                                                                 // Ok, all data is valid and loaded. Finally let's output the timer... :-)
316                                                                                                 // Export data into constants for the template
317                                                                                                 define('_TIME_VALUE', $time);
318                                                                                                 define('_TIM2_VALUE', strlen($time));
319                                                                                                 define('_UID_VALUE' , $url_uid );
320                                                                                                 define('_TYPE_VALUE', $type);
321                                                                                                 define('_DATA_VALUE', $urlId);
322                                                                                                 define('_RAND_VALUE', mt_rand(0, 99999));
323                                                                                                 define('_TEMPLATE_BANNER', LOAD_TEMPLATE('mailid_banner', true));
324
325                                                                                                 // Load template
326                                                                                                 LOAD_TEMPLATE('mailid_timer');
327                                                                                                 break;
328                                                                 } // END - switch
329                                                         } else {
330                                                                 LOAD_TEMPLATE('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (6)</div>");
331                                                         }
332                                                 } else {
333                                                         LOAD_TEMPLATE('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (5)</div>");
334                                                 }
335                                         } else {
336                                                 LOAD_TEMPLATE('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (4)</div>");
337                                         }
338                                 } else {
339                                         SQL_FREERESULT($result);
340                                         LOAD_TEMPLATE('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (3)</div>");
341                                 }
342                         } else {
343                                 SQL_FREERESULT($result);
344                                 LOAD_TEMPLATE('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (2)</div>");
345                         }
346                 } else {
347                         SQL_FREERESULT($result);
348                         LOAD_TEMPLATE('admin_settings_saved', false, "<div class=\"member_failed\">{--MAIL_ALREADY_CONFIRMED--} (1)</div>");
349                 }
350
351                 // Insert footer if no image
352                 if ($mode != 'img') {
353                         // Write footer
354                         loadIncludeOnce('inc/footer.php');
355                 } // END - if
356         }
357 } elseif ($mode != 'img') {
358         // You have to install first!
359         redirectToUrl('install.php');
360 }
361
362 // Really all done here... ;-)
363 shutdown();
364
365 //
366 ?>