First batch of removal of the headers needed for revision-functions.php
[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  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
14  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
15  * For more information visit: http://mxchange.org                      *
16  *                                                                      *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or    *
20  * (at your option) any later version.                                  *
21  *                                                                      *
22  * This program is distributed in the hope that it will be useful,      *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
25  * GNU General Public License for more details.                         *
26  *                                                                      *
27  * You should have received a copy of the GNU General Public License    *
28  * along with this program; if not, write to the Free Software          *
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
35         exit();
36 } elseif (!isExtensionActive('sponsor')) {
37         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=sponsor%}');
38         return;
39 } elseif (!isSponsor()) {
40         // No sponsor!
41         addFatalMessage(__FILE__, __LINE__, '{--SPONSOR_ONLY_AREA_ENTERED--}');
42         return;
43 }
44
45 // Data for the formular
46 $result = sqlQueryEscaped("SELECT
47         `id`, `company`, `position`, `tax_ident`,
48         `gender`, `surname`, `family`, `street_nr1`, `street_nr2`, `zip`, `city`, `country`,
49         `phone`, `fax`, `cell`, `email`, `url`,
50         `status`, `receive_warnings`
51 FROM
52         `{?_MYSQL_PREFIX?}_sponsor_data`
53 WHERE
54         `id`=%s AND
55         `password`='%s'
56 LIMIT 1",
57         array(
58                 bigintval(getSession('sponsor_id')),
59                 getSession('sponsorpass')
60         ), __FILE__, __LINE__);
61
62 // Entry found?
63 if (sqlNumRows($result) == 1) {
64         // Load sponsor data
65         $content = sqlFetchArray($result);
66         if ($content['status'] == 'CONFIRMED') {
67                 // Check if form was submitted or not
68                 if (isFormSent()) {
69                         // Check passwords
70                         if (!isPostRequestElementSet('pass_old')) {
71                                 // No current password entered
72                                 $message = '{--SPONSOR_NO_CURRENT_PASSWORD_ENTERED--}';
73                         } elseif (md5(postRequestElement('pass_old')) != getSession('sponsorpass')) {
74                                 // Entered password didn't match password in DB
75                                 $message = '{--SPONSOR_CURRENT_PASSWORD_DIDNOT_MATCH_DB--}';
76                         } elseif ((isPostRequestElementSet('password1')) && (isPostRequestElementSet('password2')) && (postRequestElement('password1') != postRequestElement('password2'))) {
77                                 // Both new passwords did not match
78                                 $message = '{--SPONSOR_BOTH_NEW_PASSWORDS_DIDNOT_MATCH--}';
79                         } elseif ((!isPostRequestElementSet('password1')) && (isPostRequestElementSet('password2'))) {
80                                 // No password one entered
81                                 $message = '{--SPONSOR_PASSWORD_ONE_EMPTY--}';
82                         } elseif ((isPostRequestElementSet('password1')) && (!isPostRequestElementSet('password2'))) {
83                                 // No password two entered
84                                 $message = '{--SPONSOR_PASSWORD_TWO_EMPTY--}';
85                         } elseif ((isPostRequestElementSet('password1')) && (strlen(postRequestElement('password1')) < getMinPasswordLength())) {
86                                 // Too short password
87                                 $message = '{--SPONSOR_PASSWORD_TOO_SHORT--}';
88                         } else {
89                                 // Default is we don't want to change password!
90                                 $PASS_AND = ''; $PASS_DATA = '';
91
92                                 // Check if the sponsor wants to change his/her password
93                                 if ((postRequestElement('password1') == postRequestElement('password2')) && (isPostRequestElementSet('password1')) && (postRequestElement('password1') != postRequestElement('pass_old'))) {
94                                         // Change current password
95                                         $PASS_AND  = ",`password`='%s'";
96                                         $PASS_DATA = md5(postRequestElement('password1'));
97                                 } // END - if
98
99                                 // Unsecure data which we don't want here
100                                 $UNSAFE = array('receive_warnings', 'warning_interval');
101
102                                 // Remove all (maybe spoofed) unsafe data from array
103                                 foreach ($UNSAFE as $remove) {
104                                         unsetPostRequestElement($remove);
105                                 } // END - foreach
106
107                                 // Set last change timestamp
108                                 setPostRequestElement('last_change', 'UNIX_TIMESTAMP()');
109
110                                 // Save data
111                                 $message = saveSponsorData(postRequestArray(), $content);
112                         }
113
114                         if (!empty($message)) {
115                                 // Output message
116                                 $GLOBALS['sponsor_output'] = returnMessage($message);
117                         } else {
118                                 // No message generated
119                                 $GLOBALS['sponsor_output'] = returnMessage('{--SPONSOR_NO_MESSAGE_GENERATED--}');
120                         }
121                 } else {
122                         // Output formular
123                         $GLOBALS['sponsor_output'] = loadTemplate('sponsor_account_form', TRUE, $content);
124                 }
125         } else {
126                 // Locked or so?
127                 $GLOBALS['sponsor_output'] = returnMessage('{%message,SPONSOR_ACCOUNT_FAILED=' . $content['status'] . '%}');
128         }
129 } else {
130         // Sponsor account not found
131         $GLOBALS['sponsor_output'] = returnMessage('{%message,SPONSOR_ACCOUNT_404=' . getSession('sponsor_id') . '%}');
132 }
133
134 // Free memory
135 sqlFreeResult($result);
136
137 // [EOF]
138 ?>