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