730e78dcace4c74cd04b3c7c7354273376921a41
[mailer.git] / inc / modules / guest / what-confirm.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 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         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('guest', __FILE__);
46
47 // Init content
48 $content = array(
49         'message' => getMessage('GUEST_CONFIRMED_FAILED'),
50         'userid'  => 0,
51 );
52
53 if (isGetRequestElementSet('hash')) {
54         // Initialize the user id
55         $userid = '0';
56
57         // Search for an unconfirmed or confirmed account
58         $result = SQL_QUERY_ESC("SELECT `userid`, `email`, `refid`,`gender` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `user_hash`='%s' AND (`status`='UNCONFIRMED' OR `status`='CONFIRMED') LIMIT 1",
59                 array(getRequestElement('hash')), __FILE__, __LINE__);
60         if (SQL_NUMROWS($result) == 1) {
61                 // Ok, he want's to confirm now so we load some data
62                 list($userid, $email, $rid, $gender) = SQL_FETCHROW($result);
63
64                 // Fetch user data
65                 if (!fetchUserData($userid)) {
66                         // Not found, should not happen
67                         debug_report_bug('User account ' . $userid . ' not found.');
68                 } // END - if
69
70                 // Load all data and add points
71                 $content = getUserDataArray();
72                 $content['gender'] = translateGender($content['gender']);
73                 $content['points'] = getConfig('points_register');
74
75                 // Unlock his account (but only when it is on UNCONFIRMED!)
76                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `status`='CONFIRMED', ref_payout={?ref_payout?}, `user_hash`=NULL WHERE `user_hash`='%s' AND `status`='UNCONFIRMED' LIMIT 1",
77                         array(getRequestElement('hash')), __FILE__, __LINE__);
78                 if (SQL_AFFECTEDROWS() == 1) {
79                         // Send email if updated
80                         $message = loadEmailTemplate('confirm-member', $content, bigintval($userid));
81
82                         // And send him right away the confirmation mail
83                         sendEmail($email, getMessage('GUEST_THANX_CONFIRM'), $message);
84
85                         // Maybe he got "referaled"?
86                         if (($rid > 0) && ($rid != $userid)) {
87                                 // Select the referal userid
88                                 if (fetchUserData($rid)) {
89                                         // Update ref counter...
90                                         updateReferalCounter($rid);
91
92                                         // Shall I 'pay' the referal points imidiately?
93                                         if (getConfig('ref_payout') == '0') {
94                                                 // Yes, 'pay' it now
95                                                 $locked = false;
96                                         } else {
97                                                 // No, 'pay' it later
98                                                 $locked = true;
99                                         }
100
101                                         // If version matches add ref bonus to refid's account
102                                         if ((getExtensionVersion('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
103                                                 // Add points (directly only!)
104                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_ref`=`bonus_ref`+{?bonus_ref?} WHERE `userid`=%s LIMIT 1",
105                                                         array(bigintval($rid)), __FILE__, __LINE__);
106
107                                                 // Subtract points from system
108                                                 handleBonusPoints(getConfig('bonus_ref'));
109                                         } // END - if
110
111                                         // Add one-time referal bonus over referal system or directly
112                                         // @TODO Try to rewrite the following unset()
113                                         unset($GLOBALS['ref_level']);
114                                         addPointsThroughReferalSystem('referal_bonus', $rid, getConfig('points_ref'), true, bigintval($userid), $locked, getConfig('reg_points_mode'));
115                                 } // END - if
116                         } // END - if
117
118                         if (isExtensionActive('rallye')) {
119                                 // Add user to rallye (or not?)
120                                 addUserToReferalRallye(bigintval($userid));
121                         } // END - if
122
123                         // Account confirmed!
124                         if (isExtensionActive('lead')) {
125                                 // Set special lead cookie
126                                 setSession('lead_userid', bigintval($userid));
127
128                                 // Lead-Code mode enabled
129                                 redirectToUrl('lead-confirm.php');
130                         } else {
131                                 $content['message'] = getMessage('GUEST_CONFIRMED_DONE');
132                                 $content['userid']  = bigintval($userid);
133                         }
134                 } elseif (isExtensionActive('lead')) {
135                         // Set special lead cookie
136                         setSession('lead_userid', bigintval($userid));
137
138                         // Lead-Code mode enabled
139                         redirectToUrl('lead-confirm.php');
140                 } else {
141                         // Nobody was found unter this hash key... or our new member want's to confirm twice?
142                         $content['message'] = getMessage('GUEST_CONFIRMED_TWICE');
143                 }
144         } else {
145                 // Nobody was found unter this hash key... or our new member want's to confirm twice?
146                 $content['message'] = getMessage('GUEST_CONFIRMED_TWICE');
147         }
148
149         // Load template
150         loadTemplate('admin_settings_saved', false, $content['message']);
151 } elseif ((isFormSent()) && (isPostRequestElementSet('email'))) {
152         // Confirmation link requested      0         1          2
153         if (fetchUserData(postRequestElement('email'), 'email')) {
154                 // Email address found
155                 $content = getUserDataArray();
156
157                 // Detect status
158                 switch ($content['status']) {
159                         case 'UNCONFIRMED': // Account not confirmed
160                                 // Load email template
161                                 $message = loadEmailTemplate('guest_request_confirm', array('hash' => $content['user_hash']), $content['userid']);
162
163                                 // Send email
164                                 sendEmail(postRequestElement('email'), getMessage('REQUEST_CONFIRM_LINK_SUBJ'), $message);
165
166                                 // And set message
167                                 $content['message'] = getMessage('CONFIRM_LINK_SENT');
168                                 break;
169
170                         case 'CONFIRMED': // Account already confirmed
171                                 $content['message'] = getMessage('LOGIN_ID_CONFIRMED');
172                                 break;
173
174                         case 'LOCKED': // Account is locked
175                                 $content['message'] = getMessage('LOGIN_ID_LOCKED');
176                                 break;
177                 } // END - switch
178         } else {
179                 // Email address not registered
180                 $content['message'] = getMessage('EMAIL_ADDRESS_404');
181         }
182
183         // Load template
184         loadTemplate('admin_settings_saved', false, $content['message']);
185 } else {
186         // No hash found, the guest may want to enter his email address to re-get his confirmation link?
187         loadTemplate('guest_confirm_link');
188 }
189
190 // [EOF]
191 ?>