Deprecated variables for templates removed, mor EL-rewrites, getMessage() rewritten:
[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  * 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 } elseif (!isExtensionActive('sponsor')) {
44         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('sponsor'));
45         return;
46 } elseif (!isSponsor()) {
47         // No sponsor!
48         addFatalMessage(__FILE__, __LINE__, getMessage('SPONSOR_ONLY_AREA_ENTERED'));
49         return;
50 }
51
52 // Data for the formular
53 $result = SQL_QUERY_ESC("SELECT `company`, `position`, `tax_ident`,
54 `gender`, `surname`, `family`, `street_nr1`, `street_nr2`, `zip`, `city`, `country`,
55 `phone`, `fax`, `cell`, `email`, `url`,
56 `status`, `receive_warnings`
57 FROM `{?_MYSQL_PREFIX?}_sponsor_data`
58 WHERE `id`='%s' AND `password`='%s' LIMIT 1",
59         array(bigintval(getSession('sponsorid')), getSession('sponsorpass')), __FILE__, __LINE__);
60
61 // Entry found?
62 if (SQL_NUMROWS($result) == 1) {
63         // Load sponsor data
64         $content = SQL_FETCHARRAY($result);
65         if ($content['status'] == 'CONFIRMED') {
66                 // Check if form was submitted or not
67                 if (isFormSent()) {
68                         // Check passwords
69                         if (!isPostRequestParameterSet('pass_old')) {
70                                 // No current password entered
71                                 $message = getMessage('SPONSOR_NO_CURRENT_PASSWORD_ENTERED');
72                         } elseif (md5(postRequestParameter('pass_old')) != getSession('sponsorpass')) {
73                                 // Entered password didn't match password in DB
74                                 $message = getMessage('SPONSOR_CURRENT_PASSWORD_DIDNOT_MATCH_DB');
75                         } elseif ((isPostRequestParameterSet('pass1')) && (isPostRequestParameterSet('pass2')) && (postRequestParameter('pass1') != postRequestParameter('pass2'))) {
76                                 // Both new passwords did not match
77                                 $message = getMessage('SPONSOR_BOTH_NEW_PASSWORDS_DIDNOT_MATCH');
78                         } elseif ((!isPostRequestParameterSet('pass1')) && (isPostRequestParameterSet('pass2'))) {
79                                 // No password one entered
80                                 $message = getMessage('SPONSOR_PASSWORD_ONE_EMPTY');
81                         } elseif ((isPostRequestParameterSet('pass1')) && (!isPostRequestParameterSet('pass2'))) {
82                                 // No password two entered
83                                 $message = getMessage('SPONSOR_PASSWORD_TWO_EMPTY');
84                         } elseif ((isPostRequestParameterSet('pass1')) && (strlen(postRequestParameter('pass1')) < getConfig('pass_len'))) {
85                                 // Too short password
86                                 $message = getMessage('SPONSOR_PASSWORD_TOO_SHORT');
87                         } else {
88                                 // Default is we don't want to change password!
89                                 $PASS_AND = ''; $PASS_DATA = '';
90
91                                 // Check if we want to change password or not
92                                 if ((postRequestParameter('pass1') == postRequestParameter('pass2')) && (isPostRequestParameterSet('pass1')) && (postRequestParameter('pass1') != postRequestParameter('pass_old'))) {
93                                         // Change current password
94                                         $PASS_AND  = ", `password`='%s'";
95                                         $PASS_DATA = md5(postRequestParameter('pass1'));
96                                 }
97
98                                 // Unsecure data which we don't want here
99                                 $UNSAFE = array('receive_warnings', 'warning_interval');
100
101                                 // Remove all (maybe spoofed) unsafe data from array
102                                 foreach ($UNSAFE as $remove) {
103                                         unsetPostRequestParameter($remove);
104                                 }
105
106                                 // Set last change timestamp
107                                 setPostRequestParameter('last_change', 'UNIX_TIMESTAMP()');
108
109                                 // Save data
110                                 $message = saveSponsorData(postRequestArray(), $content);
111                         }
112
113                         if (!empty($message)) {
114                                 // Output message
115                                 $OUT = loadTemplate('admin_settings_saved', true, $message);
116                         } else {
117                                 // No message generated
118                                 $OUT = loadTemplate('admin_settings_saved', true, '{--SPONSOR_NO_MESSAGE_GENERATED--}');
119                         }
120                 } else {
121                         // Init gender
122                         foreach (array('m', 'f', 'c') as $gender) {
123                                 $content['gender_' . $gender] = '';
124                         } // END - foreach
125
126                         // Check for gender selection
127                         $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
128
129                         // Output formular
130                         $OUT = loadTemplate('sponsor_account_form', true, $content);
131                 }
132         } else {
133                 // Locked or so?
134                 $STATUS = sponsorTranslateUserStatus($content['status']);
135                 $OUT = loadTemplate('admin_settings_saved', true, getMaskedMessage('SPONSOR_ACCOUNT_FAILED', $STATUS));
136         }
137 } else {
138         // Sponsor account not found!
139         $OUT = loadTemplate('admin_settings_saved', true, getMaskedMessage('SPONSOR_ACCOUNT_404', getSession('sponsorid')));
140 }
141
142 // Free memory
143 SQL_FREERESULT($result);
144
145 // [EOF]
146 ?>