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 * 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 *
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. *
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. *
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, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
43 } elseif (!isMember()) {
44 redirectToIndexMemberOnlyModule();
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
50 if ((!isExtensionActive('mydata')) && (!isAdmin())) {
51 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('mydata'));
58 // Init variable to prevent notices
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
68 case 'show': // Show his data
70 $content = merge_array($content, getUserDataArray());
72 // Translate some things
73 $content['last_update'] = generateDateTime($content['last_update'], 0);
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>');
80 // He is allowed to change his profile
81 $content['change'] = loadTemplate('member_mydata_button', true);
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'];
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;
92 if (isExtensionActive('country')) {
93 // Load country's description and code
94 $content['country'] = generateCountryInfo($content['country_code']);
98 loadTemplate('member_mydata_overview', false, $content);
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`
106 `{?_MYSQL_PREFIX?}_user_data`
110 array(getMemberId()), __FILE__, __LINE__);
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`
115 `{?_MYSQL_PREFIX?}_user_data`
119 array(getMemberId()), __FILE__, __LINE__);
123 $content = merge_array($content, SQL_FETCHARRAY($result, 0, false));
126 SQL_FREERESULT($result);
128 $content['update_check'] = $content['last_update'] + getConfig('profile_lock');
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));
134 // You cannot change your account
135 loadTemplate('admin_settings_saved', false, $content['update_check']);
137 // He is allowed to change his profile
138 foreach (array('gender_m','gender_f','gender_c') as $entry) {
139 $content[$entry] = '';
142 $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
143 $content['dob'] = '';
145 switch (getLanguage()) {
146 case 'de': // German date format
148 $content['dob'] .= addSelectionBox('day', $content['birth_day']);
151 $content['dob'] .= addSelectionBox('month', $content['birth_month']);
154 $content['dob'] .= addSelectionBox('year', $content['birth_year']);
157 default: // Default is the US date format... :)
159 $content['dob'] .= addSelectionBox('month', $content['birth_month']);
162 $content['dob'] .= addSelectionBox('day', $content['birth_day']);
165 $content['dob'] .= addSelectionBox('year', $content['birth_year']);
169 $content['max_receive_list'] = addMaxReceiveList('member', $content['max_mails'], true);
171 if (isExtensionActive('country')) {
172 // Generate selection box
173 $OUT = "<select name=\"country_code\" class=\"member_select\" size=\"1\">\n";
174 $whereStatement = "WHERE `is_active`='Y'";
175 if (isAdmin()) $whereStatement = '';
176 $OUT .= generateOptionList('countries', 'id', 'descr', $content['country_code'], 'code', $whereStatement);
178 $content['country'] = $OUT;
180 // Ouput default input box
181 $content['country'] = '<input type="text" name="cntry" class="member_normal" size="2" maxlength="3" value="' . $content['country'] . '" />';
185 loadTemplate('member_mydata_edit', false, $content);
189 case 'save': // Save entered data
191 $content = merge_array($content, getUserDataArray());
193 // Calculate time to check
194 $content['update_check'] = $content['last_update'] + getConfig('profile_lock');
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);
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--}');
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
213 // Did the user changed the password?
214 if ($hash != $content['password']) {
215 $AND = ", `password`='" . $hash . "'";
219 // Or did he changed his password?
220 if (postRequestParameter('email') != $content['email']) {
222 if ($mode == 'normal') {
227 setPostRequestParameter('old_email', $content['email']);
230 // Update member's profile
231 if (isExtensionActive('country')) {
233 SQL_QUERY_ESC("UPDATE
234 `{?_MYSQL_PREFIX?}_user_data`
236 `gender`='%s', `surname`='%s', `family`='%s',
238 `country_code`=%s, `zip`=%s, `city`='%s',
240 `birth_day`=%s, `birth_month`=%s, `birth_year`=%s,
242 `last_update`=UNIX_TIMESTAMP()".$AND.",
244 `last_profile_sent`=UNIX_TIMESTAMP()
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')),
262 ), __FILE__, __LINE__);
265 SQL_QUERY_ESC("UPDATE
266 `{?_MYSQL_PREFIX?}_user_data`
268 `gender`='%s', `surname`='%s', `family`='%s',
270 `country`='%s', `zip`=%s, `city`='%s',
272 `birth_day`=%s, `birth_month`=%s, `birth_year`=%s,
274 `last_update`=UNIX_TIMESTAMP()".$AND.",
276 `last_profile_sent`=UNIX_TIMESTAMP()
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')),
294 ), __FILE__, __LINE__);
297 // Did something change?
298 if (SQL_AFFECTEDROWS() == 1) {
300 $modes = explode(';', $mode);
302 // ... and run them through
303 sendModeMails ('mydata', $modes);
305 // Something went wrong
306 loadTemplate('admin_settings_saved', false, '{--MEMBER_UPDATE_FAILED--}');
309 // Entered wrong pass for updating profile
310 loadTemplate('admin_settings_saved', false, '{--MEBER_UPDATE_PWD_WRONG--}');
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&what=mydata&code=' . getCode('PROFILE_UPDATED');
323 // Load generated URL