2 /************************************************************************
3 * MXChange v0.2.1 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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif (!IS_MEMBER()) {
39 LOAD_URL("modules.php?module=index");
40 } elseif ((!EXT_IS_ACTIVE("mydata")) && (!IS_ADMIN())) {
41 ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "mydata");
45 // Add description as navigation point
46 ADD_DESCR("member", __FILE__);
48 define('UID_VALUE', $GLOBALS['userid']); $URL = "";
50 // Detect what the member wants to do
51 $MODE = "show"; // Show his data
52 if (!empty($_POST['save'])) $MODE = "save"; // Save entered data
53 if (isset($_POST['edit'])) $MODE = "edit"; // Edit data
54 if (!empty($_POST['notify'])) $MODE = "notify"; // Switch off notification
58 case "show": // Show his data
59 if (EXT_IS_ACTIVE("country", true))
61 // New way 0 1 2 3 4 5 6 7 8 9 10 11 12 13
62 $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 FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s LIMIT 1",
63 array(UID_VALUE), __FILE__, __LINE__);
67 // Old 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, zip, city, email, birth_day, birth_month, birth_year, gender, max_mails, receive_mails, last_update FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s LIMIT 1",
69 array(UID_VALUE), __FILE__, __LINE__);
71 $DATA = SQL_FETCHROW($result);
72 SQL_FREERESULT($result);
74 // Translate / add some things
75 $DATA[10] = TRANSLATE_GENDER($DATA[10]);
76 $DATA[13] = MAKE_DATETIME($DATA[13], "0");
78 // How far is last change on his profile away from now?
79 if ((($DATA[13] + getConfig('profile_lock')) > time()) && (!IS_ADMIN()) && (getConfig('profile_lock') > 0))
81 // You cannot change your account
82 define('CHANGE', "<FONT class=\"member_failed\">".MEMBER_PROFILE_LOCKED_1.MAKE_DATETIME($DATA[13] + getConfig('profile_lock'), "0").MEMBER_PROFILE_LOCKED_2."</FONT>");
86 // He is allowed to change his profile
87 define('CHANGE', LOAD_TEMPLATE("member_mydata_button", true));
89 if (strlen($DATA[7]) == 1) $DATA[7] = "0".$DATA[7];
90 if (strlen($DATA[8]) == 1) $DATA[8] = "0".$DATA[8];
91 switch (GET_LANGUAGE())
93 case "de": define('DOB', $DATA[7].".".$DATA[8].".".$DATA[9]); break;
94 default : define('DOB', $DATA[8]."-".$DATA[7]."-".$DATA[9]); break;
97 if (EXT_IS_ACTIVE("country"))
99 // Load country's description and code
100 $DATA[3] = COUNTRY_GENERATE_INFO($DATA[3]);
104 LOAD_TEMPLATE("member_mydata_overview");
107 case "edit": // Edit data
108 if (EXT_IS_ACTIVE("country", true)) {
109 // New way 0 1 2 3 4 5 6 7 8 9 10 11 12 13
110 $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
111 FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s LIMIT 1",
112 array(UID_VALUE), __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
116 FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s LIMIT 1",
117 array(UID_VALUE), __FILE__, __LINE__);
120 $DATA = SQL_FETCHROW($result);
121 SQL_FREERESULT($result);
122 $DATA[13] = $DATA[12] + getConfig('profile_lock');
124 // How far is last change on his profile away from now?
125 if (($DATA[13] > time()) && (!IS_ADMIN()) && (getConfig('profile_lock') > 0))
127 $DATA[13] = MAKE_DATETIME($DATA[13] + getConfig('profile_lock'), "0");
128 // You cannot change your account
129 LOAD_TEMPLATE("member_mydata_locked");
133 // He is allowed to change his profile
137 define('M_DEFAULT', " selected=\"selected\"");
138 define('F_DEFAULT', "");
139 define('C_DEFAULT', "");
143 define('M_DEFAULT', "");
144 define('F_DEFAULT', " selected=\"selected\"");
145 define('C_DEFAULT', "");
149 define('M_DEFAULT', "");
150 define('F_DEFAULT', "");
151 define('C_DEFAULT', " selected=\"selected\"");
155 switch (GET_LANGUAGE())
157 case "de": // German date format
159 $DOB .= ADD_SELECTION("day", $DATA[7]);
162 $DOB .= ADD_SELECTION("month", $DATA[8]);
165 $DOB .= ADD_SELECTION("year", $DATA[9]);
168 default: // Default is the US date format... :)
173 define('MAX_REC_LIST', ADD_MAX_RECEIVE_LIST("member", $DATA[11], true));
175 if (EXT_IS_ACTIVE("country")) {
176 // Generate selection box
177 $OUT = "<SELECT name=\"country_code\" class=\"member_select\" size=\"1\">\n";
178 $whereStatement = "WHERE is_active='Y'";
179 if (IS_ADMIN()) $whereStatement = "";
180 $OUT .= ADD_OPTION_LINES("countries", "id", "descr", $DATA[3], "code", $whereStatement);
182 define('__COUNTRY_CONTENT', $OUT);
184 // Ouput default input box
185 define('__COUNTRY_CONTENT', "<INPUT type=\"text\" name=\"cntry\" class=\"member_normal\" size=\"2\" maxlength=\"3\" value=\"".$DATA[3]."\">");
189 LOAD_TEMPLATE("member_mydata_edit");
193 case "save": // Save entered data
194 // Load old email / password: 0 1 2
195 $result = SQL_QUERY_ESC("SELECT email, password, last_update FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s LIMIT 1",
196 array(UID_VALUE), __FILE__, __LINE__);
197 $DATA = SQL_FETCHROW($result);
198 SQL_FREERESULT($result);
199 $DATA[3] = $DATA[2] + getConfig('profile_lock');
201 // How far is last change on his profile away from now?
202 if (($DATA[3] > time()) && (!IS_ADMIN()) && (getConfig('profile_lock') > 0)) {
203 $DATA[3] = MAKE_DATETIME($DATA[3] + getConfig('profile_lock'), "0");
204 // You cannot change your account
205 LOAD_TEMPLATE("member_mydata_locked");
206 } elseif (!VALIDATE_EMAIL($_POST['addy'])) {
207 // Invalid email address!
208 LOAD_TEMPLATE("admin_settings_saved", false, INVALID_EMAIL_ADDRESS_ENTERED);
211 $hash = generateHash($_POST['pass1'], substr($DATA[1], 0, -40));
212 if ((($hash == $DATA[1]) || ($_POST['pass1'] == $_POST['pass2'])) && (!empty($_POST['pass1'])))
214 // Only on simple changes normal mode is active = no email or password changed
215 $MODE = "normal"; $AND = "";
217 // Did the user changed the password?
218 if ($hash != $DATA[1]) { $AND = ", password='".$hash."'"; $MODE = "pass"; }
220 // Or did he changed his password?
221 if ($_POST['addy'] != $DATA[0])
224 if ($MODE == "normal") { $MODE = "email"; } else { $MODE .= ";email"; }
225 $_POST['old_addy'] = $DATA[0];
228 // Update member's profile
229 if (EXT_IS_ACTIVE("country"))
232 $result = SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET
233 gender='%s', surname='%s', family='%s',
235 country_code=%s, zip=%s, city='%s',
237 birth_day=%s, birth_month=%s, birth_year=%s,
239 last_update=UNIX_TIMESTAMP()".$AND.",
241 last_profile_sent=UNIX_TIMESTAMP()
242 WHERE userid=%s AND password='%s' LIMIT 1",
246 $_POST['family_name'],
248 bigintval($_POST['country_code']),
249 bigintval($_POST['zip']),
252 bigintval($_POST['day']),
253 bigintval($_POST['month']),
254 bigintval($_POST['year']),
255 bigintval($_POST['max_mails']),
257 get_session('u_hash')
258 ), __FILE__, __LINE__);
263 $result = SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET
264 gender='%s', surname='%s', family='%s',
266 country='%s', zip=%s, city='%s',
268 birth_day=%s, birth_month=%s, birth_year=%s,
270 last_update=UNIX_TIMESTAMP()".$AND.",
272 last_profile_sent=UNIX_TIMESTAMP()
273 WHERE userid=%s AND password='%s' LIMIT 1",
277 $_POST['family_name'],
280 bigintval($_POST['zip']),
283 bigintval($_POST['day']),
284 bigintval($_POST['month']),
285 bigintval($_POST['year']),
286 bigintval($_POST['max_mails']),
288 get_session('u_hash')
289 ), __FILE__, __LINE__);
293 $modes = explode(";", $MODE);
295 // ... and run them through
296 SEND_MODE_MAILS ("mydata", $modes);
300 // Entered wrong pass for updating profile
301 LOAD_TEMPLATE("admin_settings_saved", false, MEBER_UPDATE_PWD_WRONG);
306 case "notify": // Switch off notfication
307 $result = SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET notified='N', last_update=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
308 array($GLOBALS['userid']), __FILE__, __LINE__);
309 $URL = URL."/modules.php?module=login&what=welcome&msg=".urlencode(PROFILE_UPDATED);
314 // Load generated URL