Admin user details extended, DEBUG_LOG() rewritten, random userid on refid=0 added
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
35 require_once("inc/libs/security_functions.php");
36
37 // Init "action" and "what"
38 global $what, $action;
39 $GLOBALS['what'] = ""; $GLOBALS['action'] = "";
40
41 // Tell everyone we are in this module
42 $GLOBALS['module'] = "mailid";  $CSS = 0;
43
44 // Load the required file(s)
45 require ("inc/config.php");
46
47 if (isBooleanConstantAndTrue('mxchange_installed'))
48 {
49         // Is the extension active
50         if (!EXT_IS_ACTIVE("mailid", true)) {
51                 // Is not activated/installed yet!
52                 ADD_FATAL(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "register"));
53         }
54
55         // Secure all data
56         $url_uid = 0; $url_bid = 0; $url_mid = 0; $code = 0; $mode = "";
57         if (!empty($_GET['uid']))     $url_uid = bigintval($_GET['uid']);
58         if (!empty($_GET['mailid']))  $url_mid = bigintval($_GET['mailid']);
59         if (!empty($_GET['bonusid'])) $url_bid = bigintval($_GET['bonusid']);
60         if (!empty($_GET['code']))    $code    = bigintval($_GET['code']);
61         if (!empty($_GET['mode']))    $mode    = $_GET['mode'];
62
63         // 01        1        12            2    2            21    1     2      2     10
64         if (($url_uid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (count($FATAL) == 0))
65         {
66                 if ($mode != "img") require_once(PATH."inc/header.php");
67
68                 // Maybe he wants to confirm an email?
69                 if ($url_mid > 0)
70                 {
71                         $result = SQL_QUERY_ESC("SELECT id, link_type FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%s AND userid=%s LIMIT 1",
72                          array($url_mid, $url_uid), __FILE__, __LINE__);
73                         $type = "mailid"; $DATA = $url_mid;
74                 }
75                  elseif ($url_bid > 0)
76                 {
77                         $result = SQL_QUERY_ESC("SELECT id, link_type FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%s AND userid=%s LIMIT 1",
78                          array($url_bid, $url_uid), __FILE__, __LINE__);
79                         $type = "bonusid"; $DATA = $url_bid;
80                 }
81                 if (SQL_NUMROWS($result) == 1)
82                 {
83                         // Is the stats ID valid?
84                         list($lid, $ltype) = SQL_FETCHROW($result);
85                         SQL_FREERESULT($result);
86                         switch ($ltype)
87                         {
88                         case "NORMAL":
89                                 $result_mailid = SQL_QUERY_ESC("SELECT pool_id, userid, id FROM "._MYSQL_PREFIX."_user_stats WHERE id=%s LIMIT 1",
90                                  array($url_mid), __FILE__, __LINE__);
91                                 break;
92
93                         case "BONUS":
94                                 $result_mailid = SQL_QUERY_ESC("SELECT id, id, is_notify FROM "._MYSQL_PREFIX."_bonus WHERE id=%s LIMIT 1",
95                                  array($url_bid), __FILE__, __LINE__);
96                                 break;
97                         }
98                         if (SQL_NUMROWS($result_mailid) == 1)
99                         {
100                                 list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
101
102                                 // Correct notification switch in non-bonus mails
103                                 if (($notify != "Y") && ($notify != "N")) $notify = "N";
104
105                                 // Free some memory
106                                 SQL_FREERESULT($result_mailid);
107
108                                 // Set sender to 0 when we have a bonus mail
109                                 if ($ltype == "BONUS") $sender = 0;
110
111                                 // Is the user's ID unlocked?
112                                 $result = SQL_QUERY_ESC("SELECT status, gender, surname, family, ref_payout FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
113                                  array($url_uid), __FILE__, __LINE__);
114                                 if (SQL_NUMROWS($result) == 1)
115                                 {
116                                         // Load data
117                                         list($status, $gender, $sname, $fname, $ref_pay) = SQL_FETCHROW($result);
118                                         SQL_FREERESULT($result);
119
120                                         if ($status == "CONFIRMED")
121                                         {
122                                                 // Update last activity
123                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET last_online=UNIX_TIMESTAMP(), last_module='mailid_top' WHERE userid=%s LIMIT 1",
124                                                  array($url_uid), __FILE__, __LINE__);
125
126                                                 // User has confirmed his account so we can procede...
127                                                 switch ($ltype)
128                                                 {
129                                                 case "NORMAL":
130                                                         $result = SQL_QUERY_ESC("SELECT payment_id FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%s LIMIT 1",
131                                                          array(bigintval($pool)), __FILE__, __LINE__);
132                                                         if (SQL_NUMROWS($result) == 1)
133                                                         {
134                                                                 list($pay) = SQL_FETCHROW($result);
135                                                                 $time      = GET_PAY_POINTS($pay, "time");
136                                                                 $payment   = GET_PAY_POINTS($pay, "payment");
137                                                                 $VALID     = true;
138                                                         }
139
140                                                         // Free memory...
141                                                         SQL_FREERESULT($result);
142                                                         break;
143
144                                                 case "BONUS":
145                                                         $result = SQL_QUERY_ESC("SELECT time, points FROM "._MYSQL_PREFIX."_bonus WHERE id=%s LIMIT 1",
146                                                          array(bigintval($pool)), __FILE__, __LINE__);
147                                                         if (SQL_NUMROWS($result) == 1)
148                                                         {
149                                                                 list($time, $payment) = SQL_FETCHROW($result);
150                                                                 $VALID = true;
151                                                         }
152
153                                                         // Free memory...
154                                                         SQL_FREERESULT($result);
155                                                         break;
156                                                 }
157                                                 if ($VALID)
158                                                 {
159                                                         if (($time == "0") && ($payment > 0)) $time = "1";
160                                                         if (($time > 0) && ($payment > 0))
161                                                         {
162                                                                 if (!empty($code))
163                                                                 {
164                                                                         // Generate code
165                                                                         $img_code = GEN_RANDOM_CODE($_CONFIG['code_length'], $code, $url_uid, $DATA);
166                                                                 }
167
168                                                                 switch ($mode)
169                                                                 {
170                                                                 case "add":
171                                                                         // Init stats data
172                                                                         $stats_data = 0;
173
174                                                                         // Count clicks
175                                                                         switch ($ltype)
176                                                                         {
177                                                                         case "NORMAL":
178                                                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_stats SET clicks=clicks + 1 WHERE id=%s LIMIT 1",
179                                                                                  array($url_mid), __FILE__, __LINE__);
180
181                                                                                 // Update mediadata as well
182                                                                                 if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
183                                                                                         // Update database
184                                                                                         MEDIA_UPDATE_ENTRY(array("total_clicks", "normal_clicks"), "add", 1);
185                                                                                 }
186                                                                                 $stats_data = $url_mid;
187                                                                                 break;
188
189                                                                         case "BONUS":
190                                                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET clicks=clicks + 1 WHERE id=%s LIMIT 1",
191                                                                                  array($url_bid), __FILE__, __LINE__);
192
193                                                                                 // Update mediadata as well
194                                                                                 if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
195                                                                                         // Update database
196                                                                                         MEDIA_UPDATE_ENTRY(array("total_clicks", "bonus_clicks"), "add", 1);
197                                                                                 }
198                                                                                 $stats_data = $url_bid;
199                                                                                 break;
200                                                                         }
201
202                                                                         // Export data into constants for the template
203                                                                         define('_POINTS_VALUE'   , TRANSLATE_COMMA($payment));
204                                                                         define('_TEMPLATE_BANNER', LOAD_TEMPLATE("mailid_banner", true));
205
206                                                                         // Only when user extension = v0.1.2: Update mails-confirmed counter
207                                                                         if (GET_EXT_VERSION("user") >= "0.1.2") {
208                                                                                 // Update counter
209                                                                                 SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET mails_confirmed=mails_confirmed + 1 WHERE userid=%s LIMIT 1",
210                                                                                         array($url_uid), __FILE__, __LINE__);
211
212                                                                                 // Update random confirmed as well?
213                                                                                 if (GET_EXT_VERSION("user") >= "0.3.4") {
214                                                                                         // Update second counter
215                                                                                         SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET rand_confirmed=rand_confirmed + 1 WHERE userid=%s LIMIT 1",
216                                                                                                 array($url_uid), __FILE__, __LINE__);
217                                                                                 } // END - if
218                                                                         }
219
220                                                                         // Insert stats record
221                                                                         USER_STATS_INSERT_RECORD($url_uid, $type, $stats_data);
222
223                                                                         // Right code entered?
224                                                                         if (bigintval($_POST['gfx_check']) == $img_code) {
225                                                                                 // Right code entered add points and remove entry
226                                                                                 if (($ref_pay > 0) && ($_CONFIG['allow_direct_pay'] == "N"))
227                                                                                 {
228                                                                                         // Don't add points over the referal system
229                                                                                         $locked = true;
230                                                                                         $template = "mailid_points_locked";
231                                                                                 }
232                                                                                  else
233                                                                                 {
234                                                                                         // Add points over referal system
235                                                                                         $locked = false;
236                                                                                         $template = "mailid_points_done";
237                                                                                 }
238
239                                                                                 // Count down ref_payout value
240                                                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET ref_payout=ref_payout-1 WHERE userid=%s AND ref_payout > 0 LIMIT 1",
241                                                                                  array($url_uid), __FILE__, __LINE__);
242
243                                                                                 // Add points
244                                                                                 unset($DEPTH);
245                                                                                 ADD_POINTS_REFSYSTEM($url_uid, $payment, false, "0", $locked);
246
247                                                                                 // Shall I add bonus points for "turbo clickers" ?
248                                                                                 if ((GET_EXT_VERSION("bonus") >= "0.2.2") && (function_exists('BONUS_ADD_TURBO_POINTS')))
249                                                                                 {
250                                                                                         // Is an active-rallye running and this is not a notification mail?
251                                                                                         if (($_CONFIG['bonus_active'] == "Y") && ($notify == "N"))
252                                                                                         {
253                                                                                                 // Shall I exclude the webmaster's own userid from the active-rallye?
254                                                                                                 if (((($_CONFIG['bonus_uid'] == $url_uid) && ($_CONFIG['bonus_include_own'] == "Y")) || ($_CONFIG['bonus_uid'] != $url_uid)) && ($_CONFIG['def_refid'] != $url_uid))
255                                                                                                 {
256                                                                                                         // Add points and remember ranking are done in this function....
257                                                                                                         BONUS_ADD_TURBO_POINTS($DATA, $url_uid, $type);
258
259                                                                                                         // Set template to mailid_points_done2 which contains a link to the ranking list
260                                                                                                         $template = "mailid_points_done2";
261                                                                                                         if ($locked) $template = "mailid_points_locked2";
262                                                                                                         define('_UID_VALUE' , $url_uid);
263                                                                                                         define('_TYPE_VALUE', $type);
264                                                                                                         define('_DATA_VALUE', TRANSLATE_COMMA($DATA));
265                                                                                                 }
266                                                                                         }
267                                                                                 }
268
269                                                                                 // Remove link from table
270                                                                                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE id=%s LIMIT 1",
271                                                                                  array(bigintval($lid)), __FILE__, __LINE__);
272
273                                                                                 // Load total points
274                                                                                 define('__TOTAL_POINTS', TRANSLATE_COMMA(
275                                                                                         GET_TOTAL_DATA($url_uid, "user_points", "points") -
276                                                                                         GET_TOTAL_DATA($url_uid, "user_data", "used_points"))
277                                                                                 );
278
279                                                                                 // Load template
280                                                                                 LOAD_TEMPLATE($template);
281                                                                         } else {
282                                                                                 // Wrong image code! So add points to sender's account
283                                                                                 unset($DEPTH);
284                                                                                 ADD_POINTS_REFSYSTEM($sender, $payment, false, 0, false, "direct");
285
286                                                                                 // Remove link from table
287                                                                                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE id=%s LIMIT 1",
288                                                                                  array(bigintval($lid)), __FILE__, __LINE__);
289
290                                                                                 // Load template
291                                                                                 LOAD_TEMPLATE("mailid_points_failed");
292                                                                         }
293                                                                         break;
294
295                                                                 case "img":
296                                                                         GENERATE_IMAGE($img_code);
297                                                                         break;
298
299                                                                 case "confirm":
300                                                                         if ($code > 0)
301                                                                         {
302                                                                                 // Export data into constants for the template
303                                                                                 define('_CODE_VALUE', $code);
304                                                                                 define('_UID_VALUE' , $url_uid );
305                                                                                 define('_TYPE_VALUE', $type);
306                                                                                 define('_DATA_VALUE', $DATA);
307                                                                                 define('_TEMPLATE_BANNER', LOAD_TEMPLATE("mailid_banner", true));
308                                                                                 if ($_CONFIG['code_length'] > 0)
309                                                                                 {
310                                                                                         // Generate Code
311                                                                                         define('_IMAGE_CODE', IMG_CODE($code, $type, $DATA, $url_uid));
312                                                                                         $templ = "mailid_enter_code";
313                                                                                 }
314                                                                                  else
315                                                                                 {
316                                                                                         // Disabled code
317                                                                                         define('__GFX_CODE', $img_code);
318                                                                                         $templ = "mailid_confirm_buttom";
319                                                                                 }
320
321                                                                                 // Load template
322                                                                                 LOAD_TEMPLATE($templ);
323                                                                         }
324                                                                         break;
325
326                                                                 case "":
327                                                                         // Ok, all data is valid and loaded. Finally let's output the timer... :-)
328                                                                         // Export data into constants for the template
329                                                                         define('_TIME_VALUE', $time);
330                                                                         define('_TIM2_VALUE', strlen($time));
331                                                                         define('_UID_VALUE' , $url_uid );
332                                                                         define('_TYPE_VALUE', $type);
333                                                                         define('_DATA_VALUE', $DATA);
334                                                                         define('_RAND_VALUE', mt_rand(0, 99999));
335                                                                         define('_TEMPLATE_BANNER', LOAD_TEMPLATE("mailid_banner", true));
336
337                                                                         // Load template
338                                                                         LOAD_TEMPLATE("mailid_timer");
339                                                                         break;
340                                                                 }
341                                                         }
342                                                          else OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (6)</STRONG>");
343                                                 }
344                                                  else OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (5)</STRONG>");
345                                         }
346                                          else OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (4)</STRONG>");
347                                 }
348                                  else
349                                 {
350                                         SQL_FREERESULT($result);
351                                         OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (3)</STRONG>");
352                                 }
353                         }
354                          else
355                         {
356                                 SQL_FREERESULT($result);
357                                 OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (2)</STRONG>");
358                         }
359                 }
360                  else
361                 {
362                         SQL_FREERESULT($result);
363                         OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (1)</STRONG>");
364                 }
365                 if ($mode != "img")
366                 {
367                         // Write footer
368                         require_once(PATH."inc/footer.php");
369                 }
370         }
371 }
372  elseif ($mode != "img")
373 {
374         // You have to configure first!
375         LOAD_URL("install.php");
376 }
377
378 // Really all done here... ;-)
379 ?>