7fa142b3f1dddeb81c48d4464d22a8623cd74c3f
[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 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://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         exit();
41 } elseif (!isExtensionActive('sponsor')) {
42         displayMessage('{%pipe,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 = sqlQueryEscaped("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 (sqlNumRows($result) == 1) {
69         // Load sponsor data
70         $content = sqlFetchArray($result);
71         if ($content['status'] == 'CONFIRMED') {
72                 // Check if form was submitted or not
73                 if (isFormSent()) {
74                         // Check passwords
75                         if (!isPostRequestElementSet('pass_old')) {
76                                 // No current password entered
77                                 $message = '{--SPONSOR_NO_CURRENT_PASSWORD_ENTERED--}';
78                         } elseif (md5(postRequestElement('pass_old')) != getSession('sponsorpass')) {
79                                 // Entered password didn't match password in DB
80                                 $message = '{--SPONSOR_CURRENT_PASSWORD_DIDNOT_MATCH_DB--}';
81                         } elseif ((isPostRequestElementSet('password1')) && (isPostRequestElementSet('password2')) && (postRequestElement('password1') != postRequestElement('password2'))) {
82                                 // Both new passwords did not match
83                                 $message = '{--SPONSOR_BOTH_NEW_PASSWORDS_DIDNOT_MATCH--}';
84                         } elseif ((!isPostRequestElementSet('password1')) && (isPostRequestElementSet('password2'))) {
85                                 // No password one entered
86                                 $message = '{--SPONSOR_PASSWORD_ONE_EMPTY--}';
87                         } elseif ((isPostRequestElementSet('password1')) && (!isPostRequestElementSet('password2'))) {
88                                 // No password two entered
89                                 $message = '{--SPONSOR_PASSWORD_TWO_EMPTY--}';
90                         } elseif ((isPostRequestElementSet('password1')) && (strlen(postRequestElement('password1')) < getMinPasswordLength())) {
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 the sponsor wants to change his/her password
98                                 if ((postRequestElement('password1') == postRequestElement('password2')) && (isPostRequestElementSet('password1')) && (postRequestElement('password1') != postRequestElement('pass_old'))) {
99                                         // Change current password
100                                         $PASS_AND  = ",`password`='%s'";
101                                         $PASS_DATA = md5(postRequestElement('password1'));
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                                         unsetPostRequestElement($remove);
110                                 } // END - foreach
111
112                                 // Set last change timestamp
113                                 setPostRequestElement('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'] = displayMessage($message, TRUE);
122                         } else {
123                                 // No message generated
124                                 $GLOBALS['sponsor_output'] = displayMessage('{--SPONSOR_NO_MESSAGE_GENERATED--}', TRUE);
125                         }
126                 } else {
127                         // Output formular
128                         $GLOBALS['sponsor_output'] = loadTemplate('sponsor_account_form', TRUE, $content);
129                 }
130         } else {
131                 // Locked or so?
132                 $GLOBALS['sponsor_output'] = displayMessage('{%message,SPONSOR_ACCOUNT_FAILED=' . $content['status'] . '%}', TRUE);
133         }
134 } else {
135         // Sponsor account not found
136         $GLOBALS['sponsor_output'] = displayMessage('{%message,SPONSOR_ACCOUNT_404=' . getSession('sponsor_id') . '%}', TRUE);
137 }
138
139 // Free memory
140 sqlFreeResult($result);
141
142 // [EOF]
143 ?>