12dace12c630e44d964ea8d149cca712a3d98042
[mailer.git] / inc / modules / guest / what-confirm.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/13/2003 *
4  * ===============                              Last change: 08/23/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-confirm.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Stuff around the confirmation link               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alles um den Bestaetigungslink                   *
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 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('guest', __FILE__);
47
48 if (REQUEST_ISSET_GET('hash')) {
49         // Initialize the user ID
50         $uid = 0;
51
52         // Search for an unconfirmed or confirmed account
53         $result = SQL_QUERY_ESC("SELECT userid, email, refid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE user_hash='%s' AND (`status`='UNCONFIRMED' OR `status`='CONFIRMED') LIMIT 1",
54         array(REQUEST_GET('hash')), __FILE__, __LINE__);
55         if (SQL_NUMROWS($result) == 1) {
56                 // Ok, he want's to confirm now so we load some data
57                 list ($uid, $email, $rid) = SQL_FETCHROW($result);
58
59                 // Unlock his account (but only when it is on UNCONFIRMED!)
60                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `status`='CONFIRMED', ref_payout=%s, user_hash=NULL WHERE user_hash='%s' AND `status`='UNCONFIRMED' LIMIT 1",
61                 array(getConfig('ref_payout'), REQUEST_GET('hash')), __FILE__, __LINE__);
62                 if (SQL_AFFECTEDROWS() == 1) {
63                         $message = LOAD_EMAIL_TEMPLATE("confirm-member", array('points' => getConfig('points_register')), bigintval($uid));
64
65                         // And send him right away the confirmation mail
66                         sendEmail($email, getMessage('GUEST_THANX_CONFIRM'), $message);
67
68                         // Maybe he got "referaled"?
69                         if (($rid > 0) && ($rid != $uid)) {
70                                 // Select the referal userid
71                                 $result = SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
72                                 array(bigintval($rid)), __FILE__, __LINE__);
73                                 if (SQL_NUMROWS($result) == 1) {
74                                         // Update ref counter...
75                                         updateReferalCounter($rid);
76
77                                         // Ok, write the ref-points to this user and his parent-ref
78                                         unset($GLOBALS['ref_level']);
79
80                                         // Shall I 'pay' the referal points imidiately?
81                                         if (getConfig('ref_payout') == '0') {
82                                                 // Yes, 'pay' it now
83                                                 $locked = false;
84                                         } else {
85                                                 // No, 'pay' it later
86                                                 $locked = true;
87                                         }
88
89                                         // If version matches add ref bonus to refid's account
90                                         if ((GET_EXT_VERSION('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
91                                                 // Add points (directly only!)
92                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET bonus_ref=bonus_ref+%s WHERE userid=%s LIMIT 1",
93                                                 array(getConfig('bonus_ref'), bigintval($rid)), __FILE__, __LINE__);
94
95                                                 // Subtract points from system
96                                                 BONUS_POINTS_HANDLER(getConfig('bonus_ref'));
97                                         } // END - if
98
99                                         // Add one-time referal bonus over referal system or directly
100                                         unset($GLOBALS['ref_level']);
101                                         ADD_POINTS_REFSYSTEM('referal_bonus', $rid, getConfig('points_ref'), true, bigintval($uid), $locked, getConfig('reg_points_mode'));
102                                 } // END - if
103                         } // END - if
104
105                         if (EXT_IS_ACTIVE('rallye')) {
106                                 // Add user to rallye (or not?)
107                                 RALLYE_AUTOADD_USER(bigintval($uid));
108                         } // END - if
109
110                         // Account confirmed!
111                         if (EXT_IS_ACTIVE('lead')) {
112                                 // Set special lead cookie
113                                 setSession('lead_uid', bigintval($uid));
114
115                                 // Lead-Code mode enabled
116                                 redirectToUrl('lead-confirm.php');
117                         } else {
118                                 define('__CONFIRM_MSG', getMessage('GUEST_CONFIRMED_DONE'));
119                                 define('__UID', bigintval($uid));
120                                 LOAD_TEMPLATE('guest_confirm_table');
121                         }
122                 } elseif (EXT_IS_ACTIVE('lead')) {
123                         // Set special lead cookie
124                         setSession('lead_uid', bigintval($uid));
125
126                         // Lead-Code mode enabled
127                         redirectToUrl('lead-confirm.php');
128                 } else {
129                         // Nobody was found unter this hash key... or our new member want's to confirm twice?
130                         define('__CONFIRM_MSG', getMessage('GUEST_CONFIRMED_TWICE'));
131                         define('__UID', '0');
132                         LOAD_TEMPLATE('guest_confirm_table');
133                 }
134         } else {
135                 // Nobody was found unter this hash key... or our new member want's to confirm twice?
136                 define('__CONFIRM_MSG', getMessage('GUEST_CONFIRMED_TWICE'));
137                 define('__UID', '0');
138                 LOAD_TEMPLATE('guest_confirm_table');
139         }
140 } elseif ((isFormSent()) && (REQUEST_ISSET_POST('email'))) {
141         // Confirmation link requested      0         1          2
142         $result = SQL_QUERY_ESC("SELECT `userid`, `status`, `user_hash` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `email`='%s' LIMIT 1",
143                 array(REQUEST_POST('email')), __FILE__, __LINE__);
144         if (SQL_NUMROWS($result) == 1) {
145                 // Email address found
146                 $DATA = SQL_FETCHROW($result);
147                 switch ($DATA[1]) {
148                         case 'UNCONFIRMED': // Account not confirmed
149                                 $message = LOAD_EMAIL_TEMPLATE('guest_request_confirm', array('hash' => $DATA[2]), $DATA[0]);
150                                 sendEmail(REQUEST_POST('email'), getMessage('REQUEST_CONFIRM_LINK_SUBJ'), $message);
151                                 $content = getMessage('CONFIRM_LINK_SENT');
152                                 break;
153
154                         case 'CONFIRMED': // Account already confirmed
155                                 $content = getMessage('LOGIN_ID_CONFIRMED');
156                                 break;
157
158                         case 'LOCKED': // Account is locked
159                                 $content = getMessage('LOGIN_ID_LOCKED');
160                                 break;
161                 } // END - switch
162         } else {
163                 // Email address not registered
164                 $content = getMessage('EMAIL_ADDY_404');
165         }
166
167         define('__CONFIRM_MSG', $content);
168         LOAD_TEMPLATE('guest_confirm_table');
169 } else {
170         // No hash found, the guest may want to enter his email address to re-get his confirmation link?
171         LOAD_TEMPLATE('guest_confirm_link');
172 }
173
174 //
175 ?>