]> git.mxchange.org Git - mailer.git/blob - inc/modules/guest/what-sponsor_login.php
Fix for missing 'you are here' navigation and redirect added to sponsor login if...
[mailer.git] / inc / modules / guest / what-sponsor_login.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/10/2005 *
4  * ===================                          Last change: 05/18/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-sponsor_login.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : Login form and password resending for sponsor    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Loginformular und Neues Passwort fuer Sponsor    *
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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('guest', __FILE__);
47
48 if ((!isExtensionActive('sponsor'))) {
49         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('sponsor'));
50         return;
51 } elseif (isSponsor()) {
52         // Is already a logged-in sponsor
53         redirectToUrl('modules.php?module=sponsor');
54 }
55
56 $mode = '';
57 if (isGetRequestParameterSet('mode')) {
58         // A "special" mode of the login system was requested
59         switch (getRequestParameter('mode')) {
60                 case 'activate' : $mode = 'activate';  break; // Activation link requested
61                 case 'lost_pass': $mode = 'lost_pass'; break; // Request new password
62         } // END - switch
63 } // END - if
64
65 // Check if hash for confirmation of email address is given...
66 if (isGetRequestParameterSet('hash')) {
67         // Lookup sponsor
68         $result = SQL_QUERY_ESC("SELECT
69         `id`, `status`, `gender`, `surname`, `family`,
70         `company`, `position`, `tax_ident`,
71         `street_nr1`, `street_nr2`, `country`, `zip`, `city`, `email`, `phone`, `fax`, `cell`,
72         `points_amount` AS points, `last_pay` AS pay, `last_curr` AS curr
73 FROM
74         `{?_MYSQL_PREFIX?}_sponsor_data`
75 WHERE
76         `hash`='%s' AND (
77                 `status`='UNCONFIRMED' OR
78                 `status`='EMAIL'
79         )
80 LIMIT 1", array(getRequestParameter('hash')), __FILE__, __LINE__);
81         if (SQL_NUMROWS($result) == 1) {
82                 // Sponsor found, load his data...
83                 $data = SQL_FETCHARRAY($result);
84
85                 // Unconfirmed account or changed email address?
86                 if ($data['status'] == 'UNCONFIRMED') {
87                         // Set account to pending
88                         SQL_QUERY_ESC("UPDATE
89         `{?_MYSQL_PREFIX?}_sponsor_data`
90 SET
91         `status`='PENDING',
92         `hash`=NULL
93 WHERE
94         `id`=%s AND
95         `hash`='%s' AND
96         `status`='UNCONFIRMED'
97 LIMIT 1",
98                                 array(
99                                         bigintval($data['id']),
100                                         getRequestParameter('hash')
101                                 ), __FILE__, __LINE__);
102
103                         // Check on success
104                         if (SQL_AFFECTEDROWS() == 1) {
105                                 // Prepare mail and send it to the sponsor
106                                 $message = loadEmailTemplate('sponsor_pending', $data);
107                                 sendEmail($data['email'], '{--SPONSOR_ACCOUNT_PENDING_SUBJECT--}', $message);
108
109                                 // Send email to admin
110                                 sendAdminNotification('{--ADMIN_NEW_SPONSOR--}', 'admin_sponsor_pending', $data);
111
112                                 // Sponsor account set to pending
113                                 loadTemplate('admin_settings_saved', false, '{--SPONSOR_ACCOUNT_IS_PENDING--}');
114                         } else {
115                                 // Could not unlock account!
116                                 loadTemplate('admin_settings_saved', false, '{--SPONSOR_ACCOUNT_PENDING_FAILED--}');
117                         }
118                 } elseif ($data['status'] == 'EMAIL') {
119                         // Changed email adress need to be confirmed
120                         SQL_QUERY_ESC("UPDATE
121         `{?_MYSQL_PREFIX?}_sponsor_data`
122 SET
123         `status`='CONFIRMED',
124         `hash`=NULL
125 WHERE
126         `id`=%s AND
127         `hash`='%s' AND
128         `status`='EMAIL'
129 LIMIT 1",
130                                 array(bigintval($data['id']), getRequestParameter('hash')), __FILE__, __LINE__);
131
132                         // Check on success
133                         if (SQL_AFFECTEDROWS() == 1) {
134                                 // Sponsor account is unlocked again
135                                 loadTemplate('admin_settings_saved', false, '{--SPONSOR_ACCOUNT_IS_CONFIRMED_AGAIN--}');
136                         } else {
137                                 // Could not unlock account!
138                                 loadTemplate('admin_settings_saved', false, '{--SPONSOR_ACCOUNT_EMAIL_FAILED--}');
139                         }
140                 } else {
141                         /// ??? Other status?
142                         loadTemplate('admin_settings_saved', false, '{--SPONSOR_ACCOUNT_STATUS_FAILED--}');
143                 }
144         } else {
145                 // No sponsor found
146                 loadTemplate('admin_settings_saved', false, getMaskedMessage('SPONSOR_ACCOUNT_404', getRequestParameter('hash')));
147         }
148
149         // Free memory
150         SQL_FREERESULT($result);
151 } elseif ($mode == 'activate') {
152         // Send activation link again
153         if (isFormSent()) {
154                 // Check submitted data
155                 if (!isPostRequestParameterSet('email')) unsetPostRequestParameter('ok');
156         }
157
158         if (isFormSent()) {
159                 // Check email
160                 $result = SQL_QUERY_ESC("SELECT id, hash, status, remote_addr, gender, surname, family, sponsor_created
161 FROM `{?_MYSQL_PREFIX?}_sponsor_data`
162 WHERE email='%s' AND (`status`='UNCONFIRMED' OR `status`='EMAIL') LIMIT 1",
163                 array(postRequestParameter('email')), __FILE__, __LINE__);
164
165                 // Entry found?
166                 if (SQL_NUMROWS($result) == 1) {
167                         // Unconfirmed sponsor account found so let's load the requested data
168                         $data = SQL_FETCHARRAY($result);
169
170                         // Translate some data
171                         $data['sponsor_created'] = generateDateTime($data['sponsor_created']);
172
173                         // Prepare email and send it to the sponsor
174                         if ($data['status'] == 'UNCONFIRMED') {
175                                 // Unconfirmed accounts
176                                 $message_sponsor = loadEmailTemplate('sponsor_activate', $data);
177                         } else {
178                                 // Confirmed email address
179                                 $message_sponsor = loadEmailTemplate('sponsor_email', $data);
180                         }
181                         sendEmail(postRequestParameter('email'), '{--SPONSOR_ACTIVATION_LINK_SUBJECT--}', $message_sponsor);
182
183                         // Output message
184                         loadTemplate('admin_settings_saved', false, '{--SPONSOR_ACTIVATION_LINK_SENT--}');
185                 } else {
186                         // No account found or not UNCONFIRMED
187                         loadTemplate('admin_settings_saved', false, '{--SPONSOR_ACTIVATION_LINK_404--}');
188                 }
189
190                 // Free memory
191                 SQL_FREERESULT($result);
192         } else {
193                 // Load form
194                 loadTemplate('guest_sponsor_activate');
195         }
196 } elseif ($mode == 'lost_pass') {
197         // Send new password
198         if (isFormSent()) {
199                 // Check submitted data
200                 if (!isPostRequestParameterSet('email')) unsetPostRequestParameter('ok');
201         } // END - if
202
203         if (isFormSent()) {
204                 // Check email
205                 $result = SQL_QUERY_ESC("SELECT
206         `id`, `hash`, `remote_addr`, `gender`, `surname`, `family`, `sponsor_created`
207 FROM
208         `{?_MYSQL_PREFIX?}_sponsor_data`
209 WHERE
210         `email`='%s' AND
211         `id`=%s AND
212         `status`='CONFIRMED'
213 LIMIT 1",
214                 array(postRequestParameter('email'), bigintval(postRequestParameter('id'))), __FILE__, __LINE__);
215
216                 // Entry found?
217                 if (SQL_NUMROWS($result) == 1) {
218                         // Unconfirmed sponsor account found so let's load the requested data
219                         $DATA = SQL_FETCHARRAY($result);
220
221                         // Translate some data
222                         $DATA['gender']          = translateGender($DATA['gender']);
223                         $DATA['sponsor_created'] = generateDateTime($DATA['sponsor_created']);
224
225                         // Generate password
226                         $DATA['password']        = generatePassword();
227
228                         // Prepare email and send it to the sponsor
229                         $message_sponsor = loadEmailTemplate('sponsor_lost', $DATA);
230                         sendEmail(postRequestParameter('email'), '{--SPONSOR_LOST_PASSWORD_SUBJECT--}', $message_sponsor);
231
232                         // Update password
233                         SQL_QUERY_ESC("UPDATE
234         `{?_MYSQL_PREFIX?}_sponsor_data`
235 SET
236         `password`='%s'
237 WHERE
238         `id`=%s
239 LIMIT 1",
240                                 array(md5($DATA['password']), bigintval($DATA['id'])), __FILE__, __LINE__);
241
242                         // Output message
243                         loadTemplate('admin_settings_saved', false, '{--SPONSOR_LOST_PASSWORD_SENT--}');
244                 } else {
245                         // No account found or not UNCONFIRMED
246                         loadTemplate('admin_settings_saved', false, '{--SPONSOR_LOST_PASSWORD_404--}');
247                 }
248
249                 // Free memory
250                 SQL_FREERESULT($result);
251         } else {
252                 // Load form
253                 loadTemplate('guest_sponsor_lost');
254         }
255 } elseif (isFormSent()) {
256         // Check status and login data ...
257         $result = SQL_QUERY_ESC("SELECT
258         `status`
259 FROM
260         `{?_MYSQL_PREFIX?}_sponsor_data`
261 WHERE
262         `id`=%s AND
263         `password`='%s'
264 LIMIT 1",
265         array(
266                 bigintval(postRequestParameter('sponsor_id')),
267                 md5(postRequestParameter('password'))
268         ), __FILE__, __LINE__);
269
270         if (SQL_NUMROWS($result) == 1) {
271                 // Okay, first login data check passed, now has he/she an approved (CONFIRMED) account?
272                 list($status) = SQL_FETCHROW($result);
273                 if ($status == 'CONFIRMED') {
274                         // Is confirmed so both is fine and we can continue with login procedure
275                         $login = ((setSession('sponsor_id'  , bigintval(postRequestParameter('sponsor_id')))) &&
276                         (setSession('sponsorpass', md5(postRequestParameter('password'))           ))
277                         );
278
279                         if ($login === true) {
280                                 // Cookie setup successfull so we can forward to sponsor area
281                                 redirectToUrl('modules.php?module=sponsor');
282                         } else {
283                                 // Cookie setup failed!
284                                 loadTemplate('admin_settings_saved', false, '{--SPONSPOR_COOKIE_SETUP_FAILED--}');
285
286                                 // Login formular and other links
287                                 loadTemplate('guest_sponsor_login');
288                         }
289                 } else {
290                         // Status is not fine
291                         loadTemplate('admin_settings_saved', false, '{--SPONSOR_LOGIN_FAILED_' . strtoupper($status) . '--}');
292
293                         // Login formular and other links
294                         loadTemplate('guest_sponsor_login');
295                 }
296         } else {
297                 // Account missing or wrong pass! We shall not find this out for the "cracker folks"...
298                 loadTemplate('admin_settings_saved', false, '{--SPONSOR_LOGIN_FAILED_404_WRONG_PASS--}');
299
300                 // Login formular and other links
301                 loadTemplate('guest_sponsor_login');
302         }
303
304         // Free memory
305         SQL_FREERESULT($result);
306 } else {
307         // Login formular and other links
308         loadTemplate('guest_sponsor_login');
309 }
310
311 // [EOF]
312 ?>