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