More globals rewritten, see #100
[mailer.git] / birthday_confirm.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/03/2004 *
4  * ===============                              Last change: 10/03/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : birthday_confirm.php                             *
8  * -------------------------------------------------------------------- *
9  * Short description : Birthday bonus confirmation link                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Geburtstagsgutschrift bestaetigen                *
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 // Set module
42 $GLOBALS['module'] = "birthday_confirm";
43 $GLOBALS['output_mode'] = -1;
44
45 // Load the required file(s)
46 require("inc/config.php");
47
48 // Is the "birthday" extension active?
49 REDIRECT_ON_UNINSTALLED_EXTENSION("birthday");
50
51 // Is the script installed?
52 if (isBooleanConstantAndTrue('mxchange_installed')) {
53         // Script is installed so let's check for his confirmation link...
54         $uid = bigintval($_GET['uid']);
55
56         // Only allow numbers here...
57         $chk = bigintval($_GET['check'], false);
58
59         // Check if link is not clicked so far
60         $result = SQL_QUERY_ESC("SELECT b.points, d.gender, d.surname, d.family, d.status, d.ref_payout
61 FROM `{!_MYSQL_PREFIX!}_user_birthday` AS b
62 INNER JOIN `{!_MYSQL_PREFIX!}_user_data` AS d
63 ON b.userid=d.userid
64 WHERE b.userid=%s AND b.chk_value='%s' LIMIT 1",
65  array($uid, $chk), __FILE__, __LINE__);
66         //* DEBUG: */ echo "uid=".$uid.",chk=".$chk." (".strlen($chk)."/".strlen($_GET['check'])."/".SQL_NUMROWS($result).")<br />\n";
67
68         // Is an entry there?
69         if (SQL_NUMROWS($result) == 1) {
70                 // Ok, congratulation again! Here's your gift from us...
71                 $data = SQL_FETCHARRAY($result, false);
72
73                 // Is the account confirmed?
74                 if ($data['status'] == "CONFIRMED") {
75                         // Set mode depending on how many mails the member has to confirm
76                         $locked = false;
77                         if (($data['ref_payout'] > 0) && (getConfig('allow_direct_pay') != "Y")) $locked = true;
78
79                         // Add points to account
80                         unset($GLOBALS['ref_level']);
81                         ADD_POINTS_REFSYSTEM("birthday_confirm", $uid, $data['points'], false, "0", $locked, strtolower(getConfig('birthday_mode')));
82
83                         // Update mediadata if version is 0.0.4 or newer
84                         if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
85                                 // Update database
86                                 MEDIA_UPDATE_ENTRY(array("total_points"), "add", $data['points']);
87                         }
88
89                         // Remove entry from table
90                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_birthday` WHERE userid=%s AND chk_value='%s' LIMIT 1",
91                                 array($uid, $chk), __FILE__, __LINE__);
92
93                         // Transfer data to constants for the template
94                         define('__GENDER', TRANSLATE_GENDER($data['gender']));
95                         define('__SNAME' , $data['surname']);
96                         define('__FNAME' , $data['family']);
97                         define('__GIFT'  , TRANSLATE_COMMA($data['points']));
98
99                         // Load message from template
100                         define('__MSG', LOAD_TEMPLATE("birthday_msg", true));
101                 } else {
102                         // Unconfirmed / locked accounts cannot get points
103                         define('__MSG', BIRTHDAY_CANNOT_STATUS_1.TRANSLATE_STATUS($data['status']).BIRTHDAY_CANNOT_STATUS_2);
104                 }
105         } else {
106                 // Cannot load data!
107                 define('__MSG', getMessage('BIRTHDAY_CANNOT_LOAD_DATA'));
108         }
109
110         // Free memory
111         SQL_FREERESULT($result);
112
113         // Set this because we have no module in URI
114         $GLOBALS['module'] = "birthday_confirm";
115
116         // Include header
117         LOAD_INC("inc/header.php");
118
119         // Load birthday header template (for your banners, e.g.?)
120         define('__BIRTHDAY_HEADER', LOAD_TEMPLATE("birthday_header", true));
121
122         // Load birthday footer template (for your banners, e.g.?)
123         define('__BIRTHDAY_FOOTER', LOAD_TEMPLATE("birthday_footer", true));
124
125         // Load final template and output it
126         LOAD_TEMPLATE("birthday_confirm");
127
128         // Include footer
129         LOAD_INC("inc/footer.php");
130 } else {
131         // You have to install first!
132         LOAD_URL("install.php");
133 }
134 // Really all done here... ;-)
135 ?>