Removed comment introduced by Profi-Concept, this comment should fine (in a much...
[mailer.git] / inc / modules / sponsor / account.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 09/30/2005 *
4  * ===================                          Last change: 05/19/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : account.php                                      *
8  * -------------------------------------------------------------------- *
9  * Short description : Sponsor can manage his account                   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Der Sponsor kann sein Account verwalten          *
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, 2010 by Mailer Developer Team                    *
20  * For more information visit: http://www.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 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } elseif (!isExtensionActive('sponsor')) {
42         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('sponsor'));
43         return;
44 } elseif (!isSponsor()) {
45         // No sponsor!
46         addFatalMessage(__FILE__, __LINE__, '{--SPONSOR_ONLY_AREA_ENTERED--}');
47         return;
48 }
49
50 // Data for the formular
51 $result = SQL_QUERY_ESC("SELECT
52         `id`, `company`, `position`, `tax_ident`,
53         `gender`, `surname`, `family`, `street_nr1`, `street_nr2`, `zip`, `city`, `country`,
54         `phone`, `fax`, `cell`, `email`, `url`,
55         `status`, `receive_warnings`
56 FROM
57         `{?_MYSQL_PREFIX?}_sponsor_data`
58 WHERE
59         `id`=%s AND
60         `password`='%s'
61 LIMIT 1",
62         array(
63                 bigintval(getSession('sponsor_id')),
64                 getSession('sponsorpass')
65         ), __FILE__, __LINE__);
66
67 // Entry found?
68 if (SQL_NUMROWS($result) == 1) {
69         // Load sponsor data
70         $content = SQL_FETCHARRAY($result);
71         if ($content['status'] == 'CONFIRMED') {
72                 // Check if form was submitted or not
73                 if (isFormSent()) {
74                         // Check passwords
75                         if (!isPostRequestParameterSet('pass_old')) {
76                                 // No current password entered
77                                 $message = '{--SPONSOR_NO_CURRENT_PASSWORD_ENTERED--}';
78                         } elseif (md5(postRequestParameter('pass_old')) != getSession('sponsorpass')) {
79                                 // Entered password didn't match password in DB
80                                 $message = '{--SPONSOR_CURRENT_PASSWORD_DIDNOT_MATCH_DB--}';
81                         } elseif ((isPostRequestParameterSet('pass1')) && (isPostRequestParameterSet('pass2')) && (postRequestParameter('pass1') != postRequestParameter('pass2'))) {
82                                 // Both new passwords did not match
83                                 $message = '{--SPONSOR_BOTH_NEW_PASSWORDS_DIDNOT_MATCH--}';
84                         } elseif ((!isPostRequestParameterSet('pass1')) && (isPostRequestParameterSet('pass2'))) {
85                                 // No password one entered
86                                 $message = '{--SPONSOR_PASSWORD_ONE_EMPTY--}';
87                         } elseif ((isPostRequestParameterSet('pass1')) && (!isPostRequestParameterSet('pass2'))) {
88                                 // No password two entered
89                                 $message = '{--SPONSOR_PASSWORD_TWO_EMPTY--}';
90                         } elseif ((isPostRequestParameterSet('pass1')) && (strlen(postRequestParameter('pass1')) < getConfig('pass_len'))) {
91                                 // Too short password
92                                 $message = '{--SPONSOR_PASSWORD_TOO_SHORT--}';
93                         } else {
94                                 // Default is we don't want to change password!
95                                 $PASS_AND = ''; $PASS_DATA = '';
96
97                                 // Check if we want to change password or not
98                                 if ((postRequestParameter('pass1') == postRequestParameter('pass2')) && (isPostRequestParameterSet('pass1')) && (postRequestParameter('pass1') != postRequestParameter('pass_old'))) {
99                                         // Change current password
100                                         $PASS_AND  = ", `password`='%s'";
101                                         $PASS_DATA = md5(postRequestParameter('pass1'));
102                                 } // END - if
103
104                                 // Unsecure data which we don't want here
105                                 $UNSAFE = array('receive_warnings', 'warning_interval');
106
107                                 // Remove all (maybe spoofed) unsafe data from array
108                                 foreach ($UNSAFE as $remove) {
109                                         unsetPostRequestParameter($remove);
110                                 } // END - foreach
111
112                                 // Set last change timestamp
113                                 setPostRequestParameter('last_change', 'UNIX_TIMESTAMP()');
114
115                                 // Save data
116                                 $message = saveSponsorData(postRequestArray(), $content);
117                         }
118
119                         if (!empty($message)) {
120                                 // Output message
121                                 $GLOBALS['sponsor_output'] = loadTemplate('admin_settings_saved', true, $message);
122                         } else {
123                                 // No message generated
124                                 $GLOBALS['sponsor_output'] = loadTemplate('admin_settings_saved', true, '{--SPONSOR_NO_MESSAGE_GENERATED--}');
125                         }
126                 } else {
127                         // Init gender
128                         foreach (array('m', 'f', 'c') as $gender) {
129                                 $content['gender_' . $gender] = '';
130                         } // END - foreach
131
132                         // Check for gender selection
133                         $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
134
135                         // Output formular
136                         $GLOBALS['sponsor_output'] = loadTemplate('sponsor_account_form', true, $content);
137                 }
138         } else {
139                 // Locked or so?
140                 $STATUS = sponsorTranslateUserStatus($content['status']);
141                 $GLOBALS['sponsor_output'] = loadTemplate('admin_settings_saved', true, getMaskedMessage('SPONSOR_ACCOUNT_FAILED', $STATUS));
142         }
143 } else {
144         // Sponsor account not found!
145         $GLOBALS['sponsor_output'] = loadTemplate('admin_settings_saved', true, getMaskedMessage('SPONSOR_ACCOUNT_404', getSession('sponsor_id')));
146 }
147
148 // Free memory
149 SQL_FREERESULT($result);
150
151 // [EOF]
152 ?>