9b5d43178883bf33eab428f449fe9db1e4d5864f
[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 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://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         exit();
41 } elseif (!isMember()) {
42         redirectToIndexMemberOnlyModule();
43 }
44
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
47
48 if ((!isExtensionActive('mydata')) && (!isAdmin())) {
49         displayMessage('{%pipe,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 (isFormSent('save'))   $mode = 'save';   // Save entered data
62 if (isFormSent('edit'))   $mode = 'edit';   // Edit data
63 if (isFormSent('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'] + 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);
77                 } else {
78                         // He is allowed to change his profile
79                         $content['change'] = loadTemplate('member_mydata_button', TRUE);
80                 }
81
82                 // @TODO Move this to a function (for better EL code)
83                 switch (getLanguage()) {
84                         case 'de': $content['dob'] = '{%pipe,padLeftZero=' . $content['birth_day']   . '%}.{%pipe,padLeftZero=' . $content['birth_month'] . '%}.' . $content['birth_year']; break;
85                         default  : $content['dob'] = '{%pipe,padLeftZero=' . $content['birth_month'] . '%}-{%pipe,padLeftZero=' . $content['birth_day']   . '%}-' . $content['birth_year']; break;
86                 } // END - switch
87
88                 if (isExtensionActive('country')) {
89                         // Load country's description and code
90                         $content['country'] = generateCountryInfo($content['country_code']);
91                 } // END - if
92
93                 // Load template
94                 loadTemplate('member_mydata_overview', FALSE, $content);
95                 break;
96
97         case 'edit': // Edit data
98                 if (isExtensionActive('country', TRUE)) {
99                         // New way
100                         $result = SQL_QUERY_ESC('SELECT
101         `surname`,
102         `family`,
103         `street_nr`,
104         `country_code`,
105         `zip`,
106         `city`,
107         `email`,
108         `birth_day`,
109         `birth_month`,
110         `birth_year`,
111         `gender`,
112         `max_mails`,
113         `receive_mails`,
114         `last_update`
115 FROM
116         `{?_MYSQL_PREFIX?}_user_data`
117 WHERE
118         `userid`=%s
119 LIMIT 1',
120                         array(getMemberId()), __FILE__, __LINE__);
121                 } else {
122                         // Old way
123                         $result = SQL_QUERY_ESC('SELECT
124         `surname`,
125         `family`,
126         `street_nr`,
127         `country`,
128         `zip`,
129         `city`,
130         `email`,
131         `birth_day`,
132         `birth_month`,
133         `birth_year`,
134         `gender`,
135         `max_mails`,
136         `receive_mails`,
137         `last_update`
138 FROM
139         `{?_MYSQL_PREFIX?}_user_data`
140 WHERE
141         `userid`=%s
142 LIMIT 1',
143                                 array(getMemberId()), __FILE__, __LINE__);
144                 }
145
146                 // Get line
147                 $content = merge_array($content, SQL_FETCHARRAY($result));
148
149                 // Free result
150                 SQL_FREERESULT($result);
151
152                 $content['update_check'] = $content['last_update'] + getProfileLock();
153
154                 // How far is last change on his profile away from now?
155                 if (($content['update_check'] > time()) && (!isAdmin()) && (getProfileLock() > 0)) {
156                         // Profile is locked, so output propper message
157                         $content['update_check'] = '{%message,MEMBER_PROFILE_LOCKED=' . generateDateTime($content['update_check'] + getProfileLock(), '0') . '%}';
158
159                         // You cannot change your account
160                         displayMessage($content['update_check']);
161                 } else {
162                         // Init elements
163                         $content['dob'] = '';
164
165                         switch (getLanguage()) {
166                                 case 'de': // German date format
167                                         // Day
168                                         $content['dob'] .= addSelectionBox('da', $content['birth_day']);
169
170                                         // Month
171                                         $content['dob'] .= addSelectionBox('mo', $content['birth_month']);
172
173                                         // Year
174                                         $content['dob'] .= addSelectionBox('ye', $content['birth_year']);
175                                         break;
176
177                                 default: // Default is the US date format... :)
178                                         // Month
179                                         $content['dob'] .= addSelectionBox('mo', $content['birth_month']);
180
181                                         // Day
182                                         $content['dob'] .= addSelectionBox('da', $content['birth_day']);
183
184                                         // Year
185                                         $content['dob'] .= addSelectionBox('ye', $content['birth_year']);
186                                         break;
187                         } // END - if
188
189                         $content['max_receive_list'] = addMaxReceiveList('member', $content['max_mails']);
190
191                         if (isExtensionActive('country')) {
192                                 // Init WHERE statement
193                                 $whereStatement = " WHERE `is_active`='Y'";
194                                 if (isAdmin()) $whereStatement = '';
195
196                                 // Generate selection box
197                                 $OUT  = '<select name="country_code" class="form_select" size="1">';
198                                 $OUT .= generateOptions('countries', 'id', 'descr', $content['country_code'], 'code', $whereStatement);
199                                 $OUT .= '</select>';
200                                 $content['country'] = $OUT;
201                         } else {
202                                 // Ouput default input box
203                                 $content['country'] = '<input type="text" name="cntry" class="form_field" size="2" maxlength="3" value="' . $content['country'] . '" />';
204                         }
205
206                         // Load template
207                         loadTemplate('member_mydata_edit', FALSE, $content);
208                 }
209                 break;
210
211         case 'save': // Save entered data
212                 // Get line
213                 $content = merge_array($content, getUserDataArray());
214
215                 // Calculate time to check
216                 $content['update_check'] = $content['last_update'] + getProfileLock();
217
218                 // How far is last change on his profile away from now?
219                 if (($content['update_check'] > time()) && (!isAdmin()) && (getProfileLock() > 0)) {
220                         // You cannot change your account
221                         $content['update_check'] = generateDateTime($content['update_check'] + getProfileLock(), 0);
222
223                         displayMessage($content['update_check']);
224                 } elseif ((!isEmailValid(postRequestElement('email'))) && (!isAdmin())) {
225                         // Invalid email address!
226                         displayMessage('{--INVALID_EMAIL_ENTERED--}');
227                 } elseif ((isEmailTaken(postRequestElement('email'))) && (isCheckDoubleEmailEnabled()) && (!isAdmin())) {
228                         // Email address is already registered
229                         displayMessage('{--MEMBER_EMAIL_IS_ALREADY_REGISTERED--}');
230                 } else {
231                         // Generate hash
232                         $hash = generateHash(postRequestElement('password1'), substr($content['password'], 0, -40));
233                         if ((($hash == $content['password']) || (postRequestElement('password1') == postRequestElement('password2'))) && (isPostRequestElementSet('password1'))) {
234                                 // Only on simple changes normal mode is active = no email or password changed
235                                 $mode = 'normal';
236                                 $AND = '';
237
238                                 // Did the user changed the password?
239                                 if ($hash != $content['password']) {
240                                         // Yes
241                                         $AND = ",`password`='" . $hash . "'";
242                                         $mode = 'password';
243                                 } // END - if
244
245                                 // Or did he changed his email address?
246                                 if (postRequestElement('email') != $content['email']) {
247                                         // Yes, but is it maybe blacklisted?
248                                         $filterData = array(
249                                                 'init_done' => TRUE,
250                                                 'post_data' => postRequestArray()
251                                         );
252                                         $filterData = runFilterChain('pre_update_user_data', $filterData);
253
254                                         // Is it blacklisted?
255                                         if ($filterData['init_done'] === FALSE) {
256                                                 // Blacklisted email address found
257                                                 displayMessage('{--MEMBER_EMAIL_BLACKLISTED--}');
258                                                 return;
259                                         } // END - if
260
261                                         if ($mode == 'normal') {
262                                                 $mode = 'email';
263                                         } else {
264                                                 $mode .= ';email';
265                                         }
266                                         setPostRequestElement('old_email', $content['email']);
267                                 } // END - if
268
269                                 // Update member's profile
270                                 if (isExtensionActive('country')) {
271                                         // New way
272                                         SQL_QUERY_ESC("UPDATE
273         `{?_MYSQL_PREFIX?}_user_data`
274 SET
275         `gender`='%s',
276         `surname`='%s',
277         `family`='%s',
278         `street_nr`='%s',
279         `country_code`=%s,
280         `zip`=%s,
281         `city`='%s',
282         `email`='%s',
283         `birth_day`=%s,
284         `birth_month`=%s,
285         `birth_year`=%s,
286         `max_mails`='%s',
287         `last_update`=UNIX_TIMESTAMP()".$AND.",
288         `notified`='N',
289         `last_profile_sent`=UNIX_TIMESTAMP()
290 WHERE
291         `userid`=%s
292 LIMIT 1",
293                                                 array(
294                                                         postRequestElement('gender'),
295                                                         postRequestElement('surname'),
296                                                         postRequestElement('family'),
297                                                         postRequestElement('street_nr'),
298                                                         bigintval(postRequestElement('country_code')),
299                                                         bigintval(postRequestElement('zip')),
300                                                         postRequestElement('city'),
301                                                         postRequestElement('email'),
302                                                         bigintval(postRequestElement('day')),
303                                                         bigintval(postRequestElement('month')),
304                                                         bigintval(postRequestElement('year')),
305                                                         bigintval(postRequestElement('max_mails')),
306                                                         getMemberId()
307                                                 ), __FILE__, __LINE__);
308                                 } else {
309                                         // Old way
310                                         SQL_QUERY_ESC("UPDATE
311         `{?_MYSQL_PREFIX?}_user_data`
312 SET
313         `gender`='%s',
314         `surname`='%s',
315         `family`='%s',
316         `street_nr`='%s',
317         `country`='%s',
318         `zip`=%s,
319         `city`='%s',
320         `email`='%s',
321         `birth_day`=%s,
322         `birth_month`=%s,
323         `birth_year`=%s,
324         `max_mails`='%s',
325         `last_update`=UNIX_TIMESTAMP()".$AND.",
326         `notified`='N',
327         `last_profile_sent`=UNIX_TIMESTAMP()
328 WHERE
329         `userid`=%s
330 LIMIT 1",
331                                                 array(
332                                                         postRequestElement('gender'),
333                                                         postRequestElement('surname'),
334                                                         postRequestElement('family'),
335                                                         postRequestElement('street_nr'),
336                                                         postRequestElement('cntry'),
337                                                         bigintval(postRequestElement('zip')),
338                                                         postRequestElement('city'),
339                                                         postRequestElement('email'),
340                                                         bigintval(postRequestElement('day')),
341                                                         bigintval(postRequestElement('month')),
342                                                         bigintval(postRequestElement('year')),
343                                                         bigintval(postRequestElement('max_mails')),
344                                                         getMemberId()
345                                                 ), __FILE__, __LINE__);
346                                 }
347
348                                 // Did something change?
349                                 if (!SQL_HASZEROAFFECTED()) {
350                                         // Get all modes ...
351                                         $modes = explode(';', $mode);
352
353                                         // ... and run them through
354                                         sendModeMails ('mydata', $modes);
355                                 } else {
356                                         // Something went wrong
357                                         displayMessage('{--MEMBER_UPDATE_FAILED--}');
358                                 }
359                         } else {
360                                 // Entered wrong pass for updating profile
361                                 displayMessage('{--MEBER_UPDATE_PWD_WRONG--}');
362                         }
363                 }
364                 break;
365
366         case 'notify': // Switch off notfication
367                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `notified`='N',`last_update`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1",
368                         array(getMemberId()), __FILE__, __LINE__);
369                 $url = 'modules.php?module=login&amp;what=mydata&amp;code=' . getCode('PROFILE_UPDATED');
370                 break;
371 } // END - switch
372
373 if (!empty($url)) {
374         // Load generated URL
375         redirectToUrl($url);
376 } // END - if
377
378 // [EOF]
379 ?>