Some improvements:
[mailer.git] / birthday_confirm.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Load security stuff here
39 require('inc/libs/security_functions.php');
40
41 // Init start time
42 $GLOBALS['__start_time'] = microtime(TRUE);
43
44 // Set module
45 $GLOBALS['__module']      = 'birthday_confirm';
46 $GLOBALS['__output_mode'] = '0';
47
48 // Load the required file(s)
49 require('inc/config-global.php');
50
51 // Set content type
52 setContentType('text/html');
53
54 // Is the 'birthday' extension active?
55 redirectOnUninstalledExtension('birthday');
56
57 // Script is installed so let's check for his confirmation link...
58 $userid = bigintval(getRequestElement('userid'));
59
60 // Only allow numbers here...
61 $chk = bigintval(getRequestElement('check'), FALSE);
62
63 // Check if link is not clicked so far
64 $result = sqlQueryEscaped("SELECT
65         `b`.`points`,
66         `d`.`userid`,
67         `d`.`gender`,
68         `d`.`surname`,
69         `d`.`family`,
70         `d`.`status`,
71         `d`.`ref_payout`
72 FROM
73         `{?_MYSQL_PREFIX?}_user_birthday` AS `b`
74 INNER JOIN
75         `{?_MYSQL_PREFIX?}_user_data` AS `d`
76 ON
77         `b`.`userid`=`d`.`userid`
78 WHERE
79         `b`.`userid`=%s AND
80         `b`.`chk_value`='%s'
81 LIMIT 1",
82         array(
83                 $userid,
84                 $chk
85         ), __FILE__, __LINE__);
86 //* DEBUG: */ debugOutput("userid=".$userid.",chk=".$chk." (".strlen($chk).'/'.strlen(getRequestElement('check')).'/'.sqlNumRows($result) . ')');
87
88 // Prepare content
89 $content = array();
90
91 // Is an entry there?
92 if (sqlNumRows($result) == 1) {
93         // Ok, congratulation again! Here's your gift from us...
94         $data = sqlFetchArray($result, FALSE);
95
96         // Is the account confirmed?
97         if ($data['status'] == 'CONFIRMED') {
98                 // Add points to account
99                 initReferralSystem();
100                 addPointsThroughReferralSystem('birthday_confirm', $userid, $data['points']);
101
102                 // Remove entry from table
103                 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_birthday` WHERE `userid`=%s AND `chk_value`='%s' LIMIT 1",
104                         array($userid, $chk), __FILE__, __LINE__);
105
106                 // Load message from template
107                 $content['message'] = loadTemplate('birthday_msg', TRUE, $data);
108         } else {
109                 // Unconfirmed / locked accounts cannot get points
110                 $content['message'] = '{%message,MEMBER_BIRTHDAY_CANNOT_STATUS=' . $data['status'] . '%}';
111         }
112 } else {
113         // Cannot load data!
114         $content['message'] = '{--MEMBER_BIRTHDAY_CANNOT_LOAD_DATA--}';
115 }
116
117 // Free memory
118 sqlFreeResult($result);
119
120 // Set this because there is no module in URI
121 $GLOBALS['__module'] = 'birthday_confirm';
122
123 // Include header
124 loadIncludeOnce('inc/header.php');
125
126 // Load final template and output it
127 loadTemplate('birthday_confirm', FALSE, $content);
128
129 // Include footer
130 loadIncludeOnce('inc/footer.php');
131
132 // [EOF]
133 ?>