646a0a8b1c019d0cd2d3c70b2a8724e1f8ba8ec5
[mailer.git] / inc / modules / member / what-mydata.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40  elseif (!IS_LOGGED_IN())
41 {
42         LOAD_URL("modules.php?module=index");
43 }
44  elseif ((!EXT_IS_ACTIVE("mydata")) && (!IS_ADMIN()))
45 {
46         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "mydata");
47         return;
48 }
49
50 // Add description as navigation point
51 ADD_DESCR("member", basename(__FILE__));
52
53 OPEN_TABLE("100%", "member_content member_content_align", "");
54 define('UID_VALUE', $GLOBALS['userid']); $URL = "";
55
56 // Detect what the member wants to do
57 $MODE = "show"; // Show his data
58 if (!empty($_POST['save']))   $MODE = "save";   // Save entered data
59 if (isset($_POST['edit']))   $MODE = "edit";   // Edit data
60 if (!empty($_POST['notify'])) $MODE = "notify"; // Switch off notification
61
62 switch ($MODE)
63 {
64 case "show": // Show his data
65         if (EXT_IS_ACTIVE("country", true))
66         {
67                 // New way                         0        1         2          3         4     5     6        7           8            9       10      11           12           13
68                 $result = SQL_QUERY_ESC("SELECT surname, family, street_nr, country_code, zip, city, email, birth_day, birth_month, birth_year, sex, max_mails, receive_mails, last_update FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
69                  array(UID_VALUE), __FILE__, __LINE__);
70         }
71          else
72         {
73                 // Old way                         0        1         2        3      4     5     6        7           8            9       10      11           12           13
74                 $result = SQL_QUERY_ESC("SELECT surname, family, street_nr, country, zip, city, email, birth_day, birth_month, birth_year, sex, max_mails, receive_mails, last_update FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
75                  array(UID_VALUE), __FILE__, __LINE__);
76         }
77         $DATA = SQL_FETCHROW($result);
78         SQL_FREERESULT($result);
79
80         // Translate / add some things
81         $DATA[10] = TRANSLATE_SEX($DATA[10]);
82         $DATA[13] = MAKE_DATETIME($DATA[13], "0");
83
84         // How far is last change on his profile away from now?
85         if ((($DATA[13] + $_CONFIG['profile_lock']) > time()) && (!IS_ADMIN()) && ($_CONFIG['profile_lock'] > 0))
86         {
87                 // You cannot change your account
88                 define('CHANGE', "<FONT class=\"member_failed\">".MEMBER_PROFILE_LOCKED_1.MAKE_DATETIME($DATA[13] + $_CONFIG['profile_lock'], "0").MEMBER_PROFILE_LOCKED_2."</FONT>");
89         }
90          else
91         {
92                 // He is allowed to change his profile
93                 define('CHANGE', LOAD_TEMPLATE("member_mydata_button", true));
94         }
95         if (strlen($DATA[7]) == 1) $DATA[7] = "0".$DATA[7];
96         if (strlen($DATA[8]) == 1) $DATA[8] = "0".$DATA[8];
97         switch (GET_LANGUAGE())
98         {
99                 case "de": define('DOB', $DATA[7].".".$DATA[8].".".$DATA[9]); break;
100                 default  : define('DOB', $DATA[8]."-".$DATA[7]."-".$DATA[9]); break;
101         }
102
103         if (EXT_IS_ACTIVE("country"))
104         {
105                 // Load country's description and code
106                 $DATA[3] = COUNTRY_GENERATE_INFO($DATA[3]);
107         }
108
109         // Load template
110         LOAD_TEMPLATE("member_mydata_overview");
111         break;
112
113 case "edit": // Edit data
114         if (EXT_IS_ACTIVE("country", true)) {
115                 // New way                         0        1         2          3         4     5     6        7           8            9       10      11           12           13
116                 $result = SQL_QUERY_ESC("SELECT surname, family, street_nr, country_code, zip, city, email, birth_day, birth_month, birth_year, sex, max_mails, receive_mails, last_update
117 FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
118                  array(UID_VALUE), __FILE__, __LINE__);
119         } else {
120                 // Old way                         0        1         2        3      4     5     6        7           8            9       10      11           12           13
121                 $result = SQL_QUERY_ESC("SELECT surname, family, street_nr, country, zip, city, email, birth_day, birth_month, birth_year, sex, max_mails, receive_mails, last_update
122 FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
123                  array(UID_VALUE), __FILE__, __LINE__);
124         }
125
126         $DATA = SQL_FETCHROW($result);
127         SQL_FREERESULT($result);
128         $DATA[13] = $DATA[12] + $_CONFIG['profile_lock'];
129
130         // How far is last change on his profile away from now?
131         if (($DATA[13] > time()) && (!IS_ADMIN()) && ($_CONFIG['profile_lock'] > 0))
132         {
133                 $DATA[13] = MAKE_DATETIME($DATA[13] + $_CONFIG['profile_lock'], "0");
134                 // You cannot change your account
135                 LOAD_TEMPLATE("member_mydata_locked");
136         }
137          else
138         {
139                 // He is allowed to change his profile
140                 switch ($DATA[10])
141                 {
142                 case "M":
143                         define('M_DEFAULT', " selected=\"selected\"");
144                         define('F_DEFAULT', "");
145                         define('C_DEFAULT', "");
146                         break;
147
148                 case "F":
149                         define('M_DEFAULT', "");
150                         define('F_DEFAULT', " selected=\"selected\"");
151                         define('C_DEFAULT', "");
152                         break;
153
154                 case "C":
155                         define('M_DEFAULT', "");
156                         define('F_DEFAULT', "");
157                         define('C_DEFAULT', " selected=\"selected\"");
158                         break;
159                 }
160                 $DOB = "";
161                 switch (GET_LANGUAGE())
162                 {
163                 case "de": // German date format
164                         // Day
165                         $DOB .= ADD_SELECTION("day", $DATA[7]);
166
167                         // Month
168                         $DOB .= ADD_SELECTION("month", $DATA[8]);
169
170                         // Year
171                         $DOB .= ADD_SELECTION("year", $DATA[9]);
172                         break;
173
174                 default: // Default is the US date format... :)
175                         break;
176                 }
177                 define('DOB', $DOB);
178                 define('MAX_REC_LIST', ADD_MAX_RECEIVE_LIST("member", $DATA[11], true));
179
180                 if (EXT_IS_ACTIVE("country"))
181                 {
182                         // Generate selection box
183                         $OUT  = "<SELECT name=\"country_code\" class=\"member_select\" size=\"1\">\n";
184                         $whereStatement = "WHERE is_active='Y'";
185                         if (IS_ADMIN()) $whereStatement = "";
186                         $OUT .= ADD_OPTION_LINES("countries", "id", "descr", $DATA[3], "code", $whereStatement);
187                         $OUT .= "</SELECT>";
188                         define('__COUNTRY_CONTENT', $OUT);
189                 }
190                  else
191                 {
192                         // Ouput default input box
193                         define('__COUNTRY_CONTENT', "<INPUT type=\"text\" name=\"cntry\" class=\"member_normal\" size=\"2\" maxlength=\"3\" value=\"".$DATA[3]."\">");
194                 }
195
196                 // Load template
197                 LOAD_TEMPLATE("member_mydata_edit");
198         }
199         break;
200
201 case "save": // Save entered data
202         // Load old email / password:      0        1          2
203         $result = SQL_QUERY_ESC("SELECT email, password, last_update FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
204          array(UID_VALUE), __FILE__, __LINE__);
205         $DATA = SQL_FETCHROW($result);
206         SQL_FREERESULT($result);
207         $DATA[3] = $DATA[2] + $_CONFIG['profile_lock'];
208
209         // How far is last change on his profile away from now?
210         if (($DATA[3] > time()) && (!IS_ADMIN()) && ($_CONFIG['profile_lock'] > 0))
211         {
212                 $DATA[3] = MAKE_DATETIME($DATA[3] + $_CONFIG['profile_lock'], "0");
213                 // You cannot change your account
214                 LOAD_TEMPLATE("member_mydata_locked");
215         }
216          elseif (!VALIDATE_EMAIL($_POST['addy']))
217         {
218                 // Invalid email address!
219                 LOAD_TEMPLATE("admin_settings_saved", false, INVALID_EMAIL_ADDRESS_ENTERED);
220         }
221          else
222         {
223                 // Secure every submitted variable
224                 foreach ($_POST as $key=>$value)
225                 {
226                         $_POST[$key] = addslashes($value);
227                 }
228
229                 $hash = generateHash($_POST['pass1'], substr($DATA[1], 0, -40));
230                 if ((($hash == $DATA[1]) || ($_POST['pass1'] == $_POST['pass2'])) && (!empty($_POST['pass1'])))
231                 {
232                         // Only on simple changes normal mode is active = no email or password changed
233                         $MODE = "normal"; $AND = "";
234
235                         // Did the user changed the password?
236                         if ($hash != $DATA[1]) { $AND = ", password='".$hash."'"; $MODE = "pass"; }
237
238                         // Or did he changed his password?
239                         if ($_POST['addy'] != $DATA[0])
240                         {
241                                 // Jupp
242                                 if ($MODE == "normal") { $MODE = "email"; } else { $MODE .= ";email"; }
243                                 $_POST['old_addy'] = $DATA[0];
244                         }
245
246                         // Update member's profile
247                         if (EXT_IS_ACTIVE("country"))
248                         {
249                                 // New way
250                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET
251 sex='%s', surname='%s', family='%s',
252 street_nr='%s',
253 country_code=%s, zip=%s, city='%s',
254 email='%s',
255 birth_day=%s, birth_month=%s, birth_year=%s,
256 max_mails=%s,
257 last_update=UNIX_TIMESTAMP()".$AND.",
258 notified='N',
259 last_profile_sent=UNIX_TIMESTAMP()
260 WHERE userid=%s AND password='%s' LIMIT 1",
261 array(
262         $_POST['sex'],
263         $_POST['surname'],
264         $_POST['family_name'],
265         $_POST['street_nr'],
266         bigintval($_POST['country_code']),
267         bigintval($_POST['zip']),
268         $_POST['city'],
269         $_POST['addy'],
270         bigintval($_POST['day']),
271         bigintval($_POST['month']),
272         bigintval($_POST['year']),
273         bigintval($_POST['max_mails']),
274         UID_VALUE,
275         get_session('u_hash')
276  ), __FILE__, __LINE__);
277                         }
278                          else
279                         {
280                                 // Old way
281                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET
282 sex='%s', surname='%s', family='%s',
283 street_nr='%s',
284 country='%s', zip=%s, city='%s',
285 email='%s',
286 birth_day=%s, birth_month=%s, birth_year=%s,
287 max_mails='%s',
288 last_update=UNIX_TIMESTAMP()".$AND.",
289 notified='N',
290 last_profile_sent=UNIX_TIMESTAMP()
291 WHERE userid=%s AND password='%s' LIMIT 1",
292 array(
293         $_POST['sex'],
294         $_POST['surname'],
295         $_POST['family_name'],
296         $_POST['street_nr'],
297         $_POST['cntry'],
298         bigintval($_POST['zip']),
299         $_POST['city'],
300         $_POST['addy'],
301         bigintval($_POST['day']),
302         bigintval($_POST['month']),
303         bigintval($_POST['year']),
304         bigintval($_POST['max_mails']),
305         UID_VALUE,
306         get_session('u_hash')
307  ), __FILE__, __LINE__);
308                         }
309
310                         // Get all modes ...
311                         $modes = explode(";", $MODE);
312
313                         // ... and run them through
314                         SEND_MODE_MAILS ("mydata", $modes);
315                 }
316                  else
317                 {
318                         // Entered wrong pass for updating profile
319                         LOAD_TEMPLATE("admin_settings_saved", false, MEBER_UPDATE_PWD_WRONG);
320                 }
321         }
322         break;
323
324 case "notify": // Switch off notfication
325         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET notified='N', last_update=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
326          array($GLOBALS['userid']), __FILE__, __LINE__);
327         $URL = URL."/modules.php?module=login&amp;what=welcome&msg=".urlencode(PROFILE_UPDATED);
328         break;
329 }
330 CLOSE_TABLE();
331
332 if (!empty($URL))
333 {
334         // Load generated URL
335         LOAD_URL($URL);
336 }
337 //
338 ?>