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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
42 } elseif (!isMember()) {
43 redirectToIndexMemberOnlyModule();
46 // Add description as navigation point
47 addMenuDescription('member', __FILE__);
49 if ((!isExtensionActive('mydata')) && (!isAdmin())) {
50 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('mydata'));
56 'userid' => getMemberId()
59 // Init variable to prevent notices
62 // Detect what the member wants to do
63 $mode = 'show'; // Show his data
64 if (isPostRequestElementSet('save')) $mode = 'save'; // Save entered data
65 if (isPostRequestElementSet('edit')) $mode = 'edit'; // Edit data
66 if (isPostRequestElementSet('notify')) $mode = 'notify'; // Switch off notification
69 case 'show': // Show his data
71 $content = merge_array($content, getUserDataArray());
73 // Translate some things
74 $content['gender'] = translateGender($content['gender']);
75 $content['last_update'] = generateDateTime($content['last_update'], 0);
77 // How far is last change on his profile away from now?
78 if ((($content['last_update'] + getConfig('profile_lock')) > time()) && (!isAdmin()) && (getConfig('profile_lock') > 0)) {
79 // You cannot change your account
80 $content['change'] = loadTemplate('admin_settings_saved', true, '<div class="member_failed">' . sprintf(getMessage('MEMBER_PROFILE_LOCKED'), generateDateTime($content['last_update'] + getConfig('profile_lock'), 0)) . '</div>');
82 // He is allowed to change his profile
83 $content['change'] = loadTemplate('member_mydata_button', true);
86 if (strlen($content['birth_day']) == 1) $content['birth_day'] = '0' . $content['birth_day'];
87 if (strlen($content['birth_month']) == 1) $content['birth_month'] = '0' . $content['birth_month'];
89 switch (getLanguage()) {
90 case 'de': $content['dob'] = $content['birth_day'] . '.' . $content['birth_month'] . '.' . $content['birth_year']; break;
91 default : $content['dob'] = $content['birth_month'] . '-' . $content['birth_day'] . '-' . $content['birth_year']; break;
94 if (isExtensionActive('country')) {
95 // Load country's description and code
96 $content['country'] = generateCountryInfo($content['country_code']);
100 loadTemplate('member_mydata_overview', false, $content);
103 case 'edit': // Edit data
104 if (isExtensionActive('country', true)) {
105 // New way 0 1 2 3 4 5 6 7 8 9 10 11 12 13
106 $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`
108 `{?_MYSQL_PREFIX?}_user_data`
112 array(getMemberId()), __FILE__, __LINE__);
114 // Old way 0 1 2 3 4 5 6 7 8 9 10 11 12 13
115 $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`
117 `{?_MYSQL_PREFIX?}_user_data`
121 array(getMemberId()), __FILE__, __LINE__);
125 $content = merge_array($content, SQL_FETCHARRAY($result, 0, false));
128 SQL_FREERESULT($result);
130 $content['update_check'] = $content['last_update'] + getConfig('profile_lock');
132 // How far is last change on his profile away from now?
133 if (($content['update_check'] > time()) && (!isAdmin()) && (getConfig('profile_lock') > 0)) {
134 $content['update_check'] = sprintf(getMessage('MEMBER_PROFILE_LOCKED'), generateDateTime($content['update_check'] + getConfig('profile_lock'), 0));
136 // You cannot change your account
137 loadTemplate('admin_settings_saved', false, $content['update_check']);
139 // He is allowed to change his profile
140 foreach (array('gender_m','gender_f','gender_c') as $entry) {
141 $content[$entry] = '';
144 $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
145 $content['dob'] = '';
147 switch (getLanguage()) {
148 case 'de': // German date format
150 $content['dob'] .= addSelectionBox('day', $content['birth_day']);
153 $content['dob'] .= addSelectionBox('month', $content['birth_month']);
156 $content['dob'] .= addSelectionBox('year', $content['birth_year']);
159 default: // Default is the US date format... :)
161 $content['dob'] .= addSelectionBox('month', $content['birth_month']);
164 $content['dob'] .= addSelectionBox('day', $content['birth_day']);
167 $content['dob'] .= addSelectionBox('year', $content['birth_year']);
171 $content['max_receive_list'] = addMaxReceiveList('member', $content['max_mails'], true);
173 if (isExtensionActive('country')) {
174 // Generate selection box
175 $OUT = "<select name=\"country_code\" class=\"member_select\" size=\"1\">\n";
176 $whereStatement = "WHERE `is_active`='Y'";
177 if (isAdmin()) $whereStatement = '';
178 $OUT .= generateOptionList('countries', 'id', 'descr', $content['country_code'], 'code', $whereStatement);
180 $content['country'] = $OUT;
182 // Ouput default input box
183 $content['country'] = "<input type=\"text\" name=\"cntry\" class=\"member_normal\" size=\"2\" maxlength=\"3\" value=\"".$content['country']."\" />";
187 loadTemplate('member_mydata_edit', false, $content);
191 case 'save': // Save entered data
193 $content = merge_array($content, getUserDataArray());
195 // Calculate time to check
196 $content['update_check'] = $content['last_update'] + getConfig('profile_lock');
198 // How far is last change on his profile away from now?
199 if (($content['update_check'] > time()) && (!isAdmin()) && (getConfig('profile_lock') > 0)) {
200 $content['update_check'] = generateDateTime($content['update_check'] + getConfig('profile_lock'), 0);
202 // You cannot change your account
203 loadTemplate('admin_settings_saved', false, $content['update_check']);
204 } elseif ((!isEmailValid(postRequestElement('email'))) && (!isAdmin())) {
205 // Invalid email address!
206 loadTemplate('admin_settings_saved', false, getMessage('INVALID_EMAIL_ADDRESS_ENTERED'));
209 $hash = generateHash(postRequestElement('pass1'), substr($content['password'], 0, -40));
210 if ((($hash == $content['password']) || (postRequestElement('pass1') == postRequestElement('pass2'))) && (isPostRequestElementSet('pass1'))) {
211 // Only on simple changes normal mode is active = no email or password changed
212 $mode = 'normal'; $AND = '';
214 // Did the user changed the password?
215 if ($hash != $content['password']) { $AND = ", `password`='".$hash."'"; $mode = 'pass'; }
217 // Or did he changed his password?
218 if (postRequestElement('email') != $content['email']) {
220 if ($mode == 'normal') {
225 setRequestPostElement('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_AFFECTEDROWS() == 1) {
298 $modes = explode(';', $mode);
300 // ... and run them through
301 sendModeMails ('mydata', $modes);
303 // Something went wrong
304 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_UPDATE_FAILED'));
307 // Entered wrong pass for updating profile
308 loadTemplate('admin_settings_saved', false, getMessage('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=welcome&code=' . urlencode(getMessage('PROFILE_UPDATED'));
321 // Load generated URL