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