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