2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/16/2003 *
4 * =================== Last change: 06/30/2004 *
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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
41 } elseif (!isMember()) {
42 redirectToIndexMemberOnlyModule();
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
48 if ((!isExtensionActive('mydata')) && (!isAdmin())) {
49 displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=mydata%}');
56 // Init variable to prevent notices
59 // Detect what the member wants to do
60 $mode = 'show'; // Show his data
61 if (isPostRequestElementSet('save')) $mode = 'save'; // Save entered data
62 if (isFormSent('edit')) $mode = 'edit'; // Edit data
63 if (isPostRequestElementSet('notify')) $mode = 'notify'; // Switch off notification
66 case 'show': // Show his data
68 $content = merge_array($content, getUserDataArray());
70 // Translate some things
71 $content['last_update'] = generateDateTime($content['last_update'], 0);
73 // How far is last change on his profile away from now?
74 if ((($content['last_update'] + getProfileLock()) > time()) && (!isAdmin()) && (getProfileLock() > 0)) {
75 // You cannot change your account
76 $content['change'] = displayMessage('<div class="notice">{%message,MEMBER_PROFILE_LOCKED=' . generateDateTime($content['last_update'] + getProfileLock(), 0) . '%}</div>', true);
78 // He is allowed to change his profile
79 $content['change'] = loadTemplate('member_mydata_button', true);
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'];
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;
90 if (isExtensionActive('country')) {
91 // Load country's description and code
92 $content['country'] = generateCountryInfo($content['country_code']);
96 loadTemplate('member_mydata_overview', false, $content);
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`
104 `{?_MYSQL_PREFIX?}_user_data`
108 array(getMemberId()), __FILE__, __LINE__);
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`
113 `{?_MYSQL_PREFIX?}_user_data`
117 array(getMemberId()), __FILE__, __LINE__);
121 $content = merge_array($content, SQL_FETCHARRAY($result, 0, false));
124 SQL_FREERESULT($result);
126 $content['update_check'] = $content['last_update'] + getProfileLock();
128 // How far is last change on his profile away from now?
129 if (($content['update_check'] > time()) && (!isAdmin()) && (getProfileLock() > 0)) {
130 $content['update_check'] = '{%message,MEMBER_PROFILE_LOCKED=' . generateDateTime($content['update_check'] + getProfileLock(), '0') . '%}';
132 // You cannot change your account
133 displayMessage($content['update_check']);
136 $content['dob'] = '';
138 switch (getLanguage()) {
139 case 'de': // German date format
141 $content['dob'] .= addSelectionBox('day', $content['birth_day']);
144 $content['dob'] .= addSelectionBox('month', $content['birth_month']);
147 $content['dob'] .= addSelectionBox('year', $content['birth_year']);
150 default: // Default is the US date format... :)
152 $content['dob'] .= addSelectionBox('month', $content['birth_month']);
155 $content['dob'] .= addSelectionBox('day', $content['birth_day']);
158 $content['dob'] .= addSelectionBox('year', $content['birth_year']);
162 $content['max_receive_list'] = addMaxReceiveList('member', $content['max_mails'], true);
164 if (isExtensionActive('country')) {
165 // Init WHERE statement
166 $whereStatement = "WHERE `is_active`='Y'";
167 if (isAdmin()) $whereStatement = '';
169 // Generate selection box
170 $OUT = '<select name="country_code" class="form_select" size="1">';
171 $OUT .= generateOptionList('countries', 'id', 'descr', $content['country_code'], 'code', $whereStatement);
173 $content['country'] = $OUT;
175 // Ouput default input box
176 $content['country'] = '<input type="text" name="cntry" class="form_field" size="2" maxlength="3" value="' . $content['country'] . '" />';
180 loadTemplate('member_mydata_edit', false, $content);
184 case 'save': // Save entered data
186 $content = merge_array($content, getUserDataArray());
188 // Calculate time to check
189 $content['update_check'] = $content['last_update'] + getProfileLock();
191 // How far is last change on his profile away from now?
192 if (($content['update_check'] > time()) && (!isAdmin()) && (getProfileLock() > 0)) {
193 // You cannot change your account
194 $content['update_check'] = generateDateTime($content['update_check'] + getProfileLock(), 0);
196 displayMessage($content['update_check']);
197 } elseif ((!isEmailValid(postRequestElement('email'))) && (!isAdmin())) {
198 // Invalid email address!
199 displayMessage('{--INVALID_EMAIL_ENTERED--}');
200 } elseif ((isEmailTaken(postRequestElement('email'))) && (isCheckDoubleEmailEnabled()) && (!isAdmin())) {
201 // Email address is already registered
202 displayMessage('{--MEMBER_EMAIL_IS_ALREADY_REGISTERED--}');
205 $hash = generateHash(postRequestElement('pass1'), substr($content['password'], 0, -40));
206 if ((($hash == $content['password']) || (postRequestElement('pass1') == postRequestElement('pass2'))) && (isPostRequestElementSet('pass1'))) {
207 // Only on simple changes normal mode is active = no email or password changed
211 // Did the user changed the password?
212 if ($hash != $content['password']) {
213 $AND = ", `password`='" . $hash . "'";
217 // Or did he changed his password?
218 if (postRequestElement('email') != $content['email']) {
220 if ($mode == 'normal') {
225 setPostRequestElement('old_email', $content['email']);
228 // Update member's profile
229 if (isExtensionActive('country')) {
231 SQL_QUERY_ESC("UPDATE
232 `{?_MYSQL_PREFIX?}_user_data`
234 `gender`='%s', `surname`='%s', `family`='%s',
236 `country_code`=%s, `zip`=%s, `city`='%s',
238 `birth_day`=%s, `birth_month`=%s, `birth_year`=%s,
240 `last_update`=UNIX_TIMESTAMP()".$AND.",
242 `last_profile_sent`=UNIX_TIMESTAMP()
247 postRequestElement('gender'),
248 postRequestElement('surname'),
249 postRequestElement('family'),
250 postRequestElement('street_nr'),
251 bigintval(postRequestElement('country_code')),
252 bigintval(postRequestElement('zip')),
253 postRequestElement('city'),
254 postRequestElement('email'),
255 bigintval(postRequestElement('day')),
256 bigintval(postRequestElement('month')),
257 bigintval(postRequestElement('year')),
258 bigintval(postRequestElement('max_mails')),
260 ), __FILE__, __LINE__);
263 SQL_QUERY_ESC("UPDATE
264 `{?_MYSQL_PREFIX?}_user_data`
266 `gender`='%s', `surname`='%s', `family`='%s',
268 `country`='%s', `zip`=%s, `city`='%s',
270 `birth_day`=%s, `birth_month`=%s, `birth_year`=%s,
272 `last_update`=UNIX_TIMESTAMP()".$AND.",
274 `last_profile_sent`=UNIX_TIMESTAMP()
279 postRequestElement('gender'),
280 postRequestElement('surname'),
281 postRequestElement('family'),
282 postRequestElement('street_nr'),
283 postRequestElement('cntry'),
284 bigintval(postRequestElement('zip')),
285 postRequestElement('city'),
286 postRequestElement('email'),
287 bigintval(postRequestElement('day')),
288 bigintval(postRequestElement('month')),
289 bigintval(postRequestElement('year')),
290 bigintval(postRequestElement('max_mails')),
292 ), __FILE__, __LINE__);
295 // Did something change?
296 if (!SQL_HASZEROAFFECTED()) {
298 $modes = explode(';', $mode);
300 // ... and run them through
301 sendModeMails ('mydata', $modes);
303 // Something went wrong
304 displayMessage('{--MEMBER_UPDATE_FAILED--}');
307 // Entered wrong pass for updating profile
308 displayMessage('{--MEBER_UPDATE_PWD_WRONG--}');
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&what=mydata&code=' . getCode('PROFILE_UPDATED');
321 // Load generated URL