31b438b6e391d0f89da4247854b2aacba089d1ac
[mailer.git] / inc / modules / member / what-mydata.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/16/2003 *
4  * ===================                          Last change: 06/30/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-mydata.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : Members can edit their profile data here         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Mitglieder koennen hier ihre Profildaten aendern *
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 (!isMember()) {
44         redirectToIndexMemberOnlyModule();
45 }
46
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
49
50 if ((!isExtensionActive('mydata')) && (!isAdmin())) {
51         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('mydata'));
52         return;
53 } // END - if
54
55 // Add userid
56 $content = array();
57
58 // Init variable to prevent notices
59 $url = '';
60
61 // Detect what the member wants to do
62 $mode = 'show'; // Show his data
63 if (isPostRequestParameterSet('save'))   $mode = 'save';   // Save entered data
64 if (isFormSent('edit'))   $mode = 'edit';   // Edit data
65 if (isPostRequestParameterSet('notify')) $mode = 'notify'; // Switch off notification
66
67 switch ($mode) {
68         case 'show': // Show his data
69                 // Get line
70                 $content = merge_array($content, getUserDataArray());
71
72                 // Translate some things
73                 $content['last_update'] = generateDateTime($content['last_update'], 0);
74
75                 // How far is last change on his profile away from now?
76                 if ((($content['last_update'] + getConfig('profile_lock')) > time()) && (!isAdmin()) && (getConfig('profile_lock') > 0)) {
77                         // You cannot change your account
78                         $content['change'] = loadTemplate('admin_settings_saved', true, '<div class="member_failed">' . getMaskedMessage('MEMBER_PROFILE_LOCKED', generateDateTime($content['last_update'] + getConfig('profile_lock'), 0)) . '</div>');
79                 } else {
80                         // He is allowed to change his profile
81                         $content['change'] = loadTemplate('member_mydata_button', true);
82                 }
83
84                 if (strlen($content['birth_day'])   == 1) $content['birth_day']   = '0' . $content['birth_day'];
85                 if (strlen($content['birth_month']) == 1) $content['birth_month'] = '0' . $content['birth_month'];
86
87                 switch (getLanguage()) {
88                         case 'de': $content['dob'] = $content['birth_day']   . '.' . $content['birth_month'] . '.' . $content['birth_year']; break;
89                         default  : $content['dob'] = $content['birth_month'] . '-' . $content['birth_day']   . '-' . $content['birth_year']; break;
90                 } // END - switch
91
92                 if (isExtensionActive('country')) {
93                         // Load country's description and code
94                         $content['country'] = generateCountryInfo($content['country_code']);
95                 } // END - if
96
97                 // Load template
98                 loadTemplate('member_mydata_overview', false, $content);
99                 break;
100
101         case 'edit': // Edit data
102                 if (isExtensionActive('country', true)) {
103                         // New way                          0          1            2             3         4       5       6           7            8              9          10         11               12            13
104                         $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `street_nr`, `country_code`, `zip`, `city`, `email`, `birth_day`, `birth_month`, `birth_year`, `gender`, `max_mails`, `receive_mails`, `last_update`
105 FROM
106         `{?_MYSQL_PREFIX?}_user_data`
107 WHERE
108         `userid`=%s
109 LIMIT 1",
110                         array(getMemberId()), __FILE__, __LINE__);
111                 } else {
112                         // Old way                          0          1            2          3       4       5       6           7            8              9          10         11               12            13
113                         $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `street_nr`, `country`, `zip`, `city`, `email`, `birth_day`, `birth_month`, `birth_year`, `gender`, `max_mails`, `receive_mails`, `last_update`
114 FROM
115         `{?_MYSQL_PREFIX?}_user_data`
116 WHERE
117         `userid`=%s
118 LIMIT 1",
119                                 array(getMemberId()), __FILE__, __LINE__);
120                 }
121
122                 // Get line
123                 $content = merge_array($content, SQL_FETCHARRAY($result, 0, false));
124
125                 // Free result
126                 SQL_FREERESULT($result);
127
128                 $content['update_check'] = $content['last_update'] + getConfig('profile_lock');
129
130                 // How far is last change on his profile away from now?
131                 if (($content['update_check'] > time()) && (!isAdmin()) && (getConfig('profile_lock') > 0)) {
132                         $content['update_check'] = getMaskedMessage('MEMBER_PROFILE_LOCKED', generateDateTime($content['update_check'] + getConfig('profile_lock'), 0));
133
134                         // You cannot change your account
135                         loadTemplate('admin_settings_saved', false, $content['update_check']);
136                 } else {
137                         // He is allowed to change his profile
138                         foreach (array('gender_m','gender_f','gender_c') as $entry) {
139                                 $content[$entry] = '';
140                         } // END - foreach
141
142                         $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
143                         $content['dob'] = '';
144
145                         switch (getLanguage()) {
146                                 case 'de': // German date format
147                                         // Day
148                                         $content['dob'] .= addSelectionBox('day', $content['birth_day']);
149
150                                         // Month
151                                         $content['dob'] .= addSelectionBox('month', $content['birth_month']);
152
153                                         // Year
154                                         $content['dob'] .= addSelectionBox('year', $content['birth_year']);
155                                         break;
156
157                                 default: // Default is the US date format... :)
158                                         // Month
159                                         $content['dob'] .= addSelectionBox('month', $content['birth_month']);
160
161                                         // Day
162                                         $content['dob'] .= addSelectionBox('day', $content['birth_day']);
163
164                                         // Year
165                                         $content['dob'] .= addSelectionBox('year', $content['birth_year']);
166                                         break;
167                         } // END - if
168
169                         $content['max_receive_list'] = addMaxReceiveList('member', $content['max_mails'], true);
170
171                         if (isExtensionActive('country')) {
172                                 // Generate selection box
173                                 $OUT  = '<select name="country_code" class="member_select" size="1">';
174                                 $whereStatement = "WHERE `is_active`='Y'";
175                                 if (isAdmin()) $whereStatement = '';
176                                 $OUT .= generateOptionList('countries', 'id', 'descr', $content['country_code'], 'code', $whereStatement);
177                                 $OUT .= '</select>';
178                                 $content['country'] = $OUT;
179                         } else {
180                                 // Ouput default input box
181                                 $content['country'] = '<input type="text" name="cntry" class="member_normal" size="2" maxlength="3" value="' . $content['country'] . '" />';
182                         }
183
184                         // Load template
185                         loadTemplate('member_mydata_edit', false, $content);
186                 }
187                 break;
188
189         case 'save': // Save entered data
190                 // Get line
191                 $content = merge_array($content, getUserDataArray());
192
193                 // Calculate time to check
194                 $content['update_check'] = $content['last_update'] + getConfig('profile_lock');
195
196                 // How far is last change on his profile away from now?
197                 if (($content['update_check'] > time()) && (!isAdmin()) && (getConfig('profile_lock') > 0)) {
198                         $content['update_check'] = generateDateTime($content['update_check'] + getConfig('profile_lock'), 0);
199
200                         // You cannot change your account
201                         loadTemplate('admin_settings_saved', false, $content['update_check']);
202                 } elseif ((!isEmailValid(postRequestParameter('email'))) && (!isAdmin())) {
203                         // Invalid email address!
204                         loadTemplate('admin_settings_saved', false, '{--INVALID_EMAIL_ENTERED--}');
205                 } else {
206                         // Generate hash
207                         $hash = generateHash(postRequestParameter('pass1'), substr($content['password'], 0, -40));
208                         if ((($hash == $content['password']) || (postRequestParameter('pass1') == postRequestParameter('pass2'))) && (isPostRequestParameterSet('pass1'))) {
209                                 // Only on simple changes normal mode is active = no email or password changed
210                                 $mode = 'normal';
211                                 $AND = '';
212
213                                 // Did the user changed the password?
214                                 if ($hash != $content['password']) {
215                                         $AND = ", `password`='" . $hash . "'";
216                                         $mode = 'password';
217                                 } // END - if
218
219                                 // Or did he changed his password?
220                                 if (postRequestParameter('email') != $content['email']) {
221                                         // Jupp
222                                         if ($mode == 'normal') {
223                                                 $mode = 'email';
224                                         } else {
225                                                 $mode .= ';email';
226                                         }
227                                         setPostRequestParameter('old_email', $content['email']);
228                                 } // END - if
229
230                                 // Update member's profile
231                                 if (isExtensionActive('country')) {
232                                         // New way
233                                         SQL_QUERY_ESC("UPDATE
234         `{?_MYSQL_PREFIX?}_user_data`
235 SET
236         `gender`='%s', `surname`='%s', `family`='%s',
237         `street_nr`='%s',
238         `country_code`=%s, `zip`=%s, `city`='%s',
239         `email`='%s',
240         `birth_day`=%s, `birth_month`=%s, `birth_year`=%s,
241         `max_mails`='%s',
242         `last_update`=UNIX_TIMESTAMP()".$AND.",
243         `notified`='N',
244         `last_profile_sent`=UNIX_TIMESTAMP()
245 WHERE
246         `userid`=%s
247 LIMIT 1",
248                                                 array(
249                                                         postRequestParameter('gender'),
250                                                         postRequestParameter('surname'),
251                                                         postRequestParameter('family'),
252                                                         postRequestParameter('street_nr'),
253                                                         bigintval(postRequestParameter('country_code')),
254                                                         bigintval(postRequestParameter('zip')),
255                                                         postRequestParameter('city'),
256                                                         postRequestParameter('email'),
257                                                         bigintval(postRequestParameter('day')),
258                                                         bigintval(postRequestParameter('month')),
259                                                         bigintval(postRequestParameter('year')),
260                                                         bigintval(postRequestParameter('max_mails')),
261                                                         getMemberId()
262                                                 ), __FILE__, __LINE__);
263                                 } else {
264                                         // Old way
265                                         SQL_QUERY_ESC("UPDATE
266         `{?_MYSQL_PREFIX?}_user_data`
267 SET
268         `gender`='%s', `surname`='%s', `family`='%s',
269         `street_nr`='%s',
270         `country`='%s', `zip`=%s, `city`='%s',
271         `email`='%s',
272         `birth_day`=%s, `birth_month`=%s, `birth_year`=%s,
273         `max_mails`='%s',
274         `last_update`=UNIX_TIMESTAMP()".$AND.",
275         `notified`='N',
276         `last_profile_sent`=UNIX_TIMESTAMP()
277 WHERE
278         `userid`=%s
279 LIMIT 1",
280                                                 array(
281                                                         postRequestParameter('gender'),
282                                                         postRequestParameter('surname'),
283                                                         postRequestParameter('family'),
284                                                         postRequestParameter('street_nr'),
285                                                         postRequestParameter('cntry'),
286                                                         bigintval(postRequestParameter('zip')),
287                                                         postRequestParameter('city'),
288                                                         postRequestParameter('email'),
289                                                         bigintval(postRequestParameter('day')),
290                                                         bigintval(postRequestParameter('month')),
291                                                         bigintval(postRequestParameter('year')),
292                                                         bigintval(postRequestParameter('max_mails')),
293                                                         getMemberId()
294                                                 ), __FILE__, __LINE__);
295                                 }
296
297                                 // Did something change?
298                                 if (SQL_AFFECTEDROWS() == 1) {
299                                         // Get all modes ...
300                                         $modes = explode(';', $mode);
301
302                                         // ... and run them through
303                                         sendModeMails ('mydata', $modes);
304                                 } else {
305                                         // Something went wrong
306                                         loadTemplate('admin_settings_saved', false, '{--MEMBER_UPDATE_FAILED--}');
307                                 }
308                         } else {
309                                 // Entered wrong pass for updating profile
310                                 loadTemplate('admin_settings_saved', false, '{--MEBER_UPDATE_PWD_WRONG--}');
311                         }
312                 }
313                 break;
314
315         case 'notify': // Switch off notfication
316                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `notified`='N', `last_update`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1",
317                         array(getMemberId()), __FILE__, __LINE__);
318                 $url = 'modules.php?module=login&amp;what=mydata&amp;code=' . getCode('PROFILE_UPDATED');
319                 break;
320 } // END - switch
321
322 if (!empty($url)) {
323         // Load generated URL
324         redirectToUrl($url);
325 } // END - if
326
327 // [EOF]
328 ?>