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