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