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