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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42 LOAD_URL("modules.php?module=index");
44 elseif ((!EXT_IS_ACTIVE("mydata")) && (!IS_ADMIN()))
46 ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "mydata");
50 // Add description as navigation point
51 ADD_DESCR("member", basename(__FILE__));
53 define('UID_VALUE', $GLOBALS['userid']); $URL = "";
55 // Detect what the member wants to do
56 $MODE = "show"; // Show his data
57 if (!empty($_POST['save'])) $MODE = "save"; // Save entered data
58 if (isset($_POST['edit'])) $MODE = "edit"; // Edit data
59 if (!empty($_POST['notify'])) $MODE = "notify"; // Switch off notification
63 case "show": // Show his data
64 if (EXT_IS_ACTIVE("country", true))
66 // New way 0 1 2 3 4 5 6 7 8 9 10 11 12 13
67 $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",
68 array(UID_VALUE), __FILE__, __LINE__);
72 // Old way 0 1 2 3 4 5 6 7 8 9 10 11 12 13
73 $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",
74 array(UID_VALUE), __FILE__, __LINE__);
76 $DATA = SQL_FETCHROW($result);
77 SQL_FREERESULT($result);
79 // Translate / add some things
80 $DATA[10] = TRANSLATE_GENDER($DATA[10]);
81 $DATA[13] = MAKE_DATETIME($DATA[13], "0");
83 // How far is last change on his profile away from now?
84 if ((($DATA[13] + $_CONFIG['profile_lock']) > time()) && (!IS_ADMIN()) && ($_CONFIG['profile_lock'] > 0))
86 // You cannot change your account
87 define('CHANGE', "<FONT class=\"member_failed\">".MEMBER_PROFILE_LOCKED_1.MAKE_DATETIME($DATA[13] + $_CONFIG['profile_lock'], "0").MEMBER_PROFILE_LOCKED_2."</FONT>");
91 // He is allowed to change his profile
92 define('CHANGE', LOAD_TEMPLATE("member_mydata_button", true));
94 if (strlen($DATA[7]) == 1) $DATA[7] = "0".$DATA[7];
95 if (strlen($DATA[8]) == 1) $DATA[8] = "0".$DATA[8];
96 switch (GET_LANGUAGE())
98 case "de": define('DOB', $DATA[7].".".$DATA[8].".".$DATA[9]); break;
99 default : define('DOB', $DATA[8]."-".$DATA[7]."-".$DATA[9]); break;
102 if (EXT_IS_ACTIVE("country"))
104 // Load country's description and code
105 $DATA[3] = COUNTRY_GENERATE_INFO($DATA[3]);
109 LOAD_TEMPLATE("member_mydata_overview");
112 case "edit": // Edit data
113 if (EXT_IS_ACTIVE("country", true)) {
114 // New 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_code, 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__);
119 // Old way 0 1 2 3 4 5 6 7 8 9 10 11 12 13
120 $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
121 FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
122 array(UID_VALUE), __FILE__, __LINE__);
125 $DATA = SQL_FETCHROW($result);
126 SQL_FREERESULT($result);
127 $DATA[13] = $DATA[12] + $_CONFIG['profile_lock'];
129 // How far is last change on his profile away from now?
130 if (($DATA[13] > time()) && (!IS_ADMIN()) && ($_CONFIG['profile_lock'] > 0))
132 $DATA[13] = MAKE_DATETIME($DATA[13] + $_CONFIG['profile_lock'], "0");
133 // You cannot change your account
134 LOAD_TEMPLATE("member_mydata_locked");
138 // He is allowed to change his profile
142 define('M_DEFAULT', " selected=\"selected\"");
143 define('F_DEFAULT', "");
144 define('C_DEFAULT', "");
148 define('M_DEFAULT', "");
149 define('F_DEFAULT', " selected=\"selected\"");
150 define('C_DEFAULT', "");
154 define('M_DEFAULT', "");
155 define('F_DEFAULT', "");
156 define('C_DEFAULT', " selected=\"selected\"");
160 switch (GET_LANGUAGE())
162 case "de": // German date format
164 $DOB .= ADD_SELECTION("day", $DATA[7]);
167 $DOB .= ADD_SELECTION("month", $DATA[8]);
170 $DOB .= ADD_SELECTION("year", $DATA[9]);
173 default: // Default is the US date format... :)
177 define('MAX_REC_LIST', ADD_MAX_RECEIVE_LIST("member", $DATA[11], true));
179 if (EXT_IS_ACTIVE("country"))
181 // Generate selection box
182 $OUT = "<SELECT name=\"country_code\" class=\"member_select\" size=\"1\">\n";
183 $whereStatement = "WHERE is_active='Y'";
184 if (IS_ADMIN()) $whereStatement = "";
185 $OUT .= ADD_OPTION_LINES("countries", "id", "descr", $DATA[3], "code", $whereStatement);
187 define('__COUNTRY_CONTENT', $OUT);
191 // Ouput default input box
192 define('__COUNTRY_CONTENT', "<INPUT type=\"text\" name=\"cntry\" class=\"member_normal\" size=\"2\" maxlength=\"3\" value=\"".$DATA[3]."\">");
196 LOAD_TEMPLATE("member_mydata_edit");
200 case "save": // Save entered data
201 // Load old email / password: 0 1 2
202 $result = SQL_QUERY_ESC("SELECT email, password, last_update FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
203 array(UID_VALUE), __FILE__, __LINE__);
204 $DATA = SQL_FETCHROW($result);
205 SQL_FREERESULT($result);
206 $DATA[3] = $DATA[2] + $_CONFIG['profile_lock'];
208 // How far is last change on his profile away from now?
209 if (($DATA[3] > time()) && (!IS_ADMIN()) && ($_CONFIG['profile_lock'] > 0))
211 $DATA[3] = MAKE_DATETIME($DATA[3] + $_CONFIG['profile_lock'], "0");
212 // You cannot change your account
213 LOAD_TEMPLATE("member_mydata_locked");
215 elseif (!VALIDATE_EMAIL($_POST['addy']))
217 // Invalid email address!
218 LOAD_TEMPLATE("admin_settings_saved", false, INVALID_EMAIL_ADDRESS_ENTERED);
222 // Secure every submitted variable
223 foreach ($_POST as $key => $value)
225 $_POST[$key] = addslashes($value);
228 $hash = generateHash($_POST['pass1'], substr($DATA[1], 0, -40));
229 if ((($hash == $DATA[1]) || ($_POST['pass1'] == $_POST['pass2'])) && (!empty($_POST['pass1'])))
231 // Only on simple changes normal mode is active = no email or password changed
232 $MODE = "normal"; $AND = "";
234 // Did the user changed the password?
235 if ($hash != $DATA[1]) { $AND = ", password='".$hash."'"; $MODE = "pass"; }
237 // Or did he changed his password?
238 if ($_POST['addy'] != $DATA[0])
241 if ($MODE == "normal") { $MODE = "email"; } else { $MODE .= ";email"; }
242 $_POST['old_addy'] = $DATA[0];
245 // Update member's profile
246 if (EXT_IS_ACTIVE("country"))
249 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET
250 gender='%s', surname='%s', family='%s',
252 country_code=%s, zip=%s, city='%s',
254 birth_day=%s, birth_month=%s, birth_year=%s,
256 last_update=UNIX_TIMESTAMP()".$AND.",
258 last_profile_sent=UNIX_TIMESTAMP()
259 WHERE userid=%s AND password='%s' LIMIT 1",
263 $_POST['family_name'],
265 bigintval($_POST['country_code']),
266 bigintval($_POST['zip']),
269 bigintval($_POST['day']),
270 bigintval($_POST['month']),
271 bigintval($_POST['year']),
272 bigintval($_POST['max_mails']),
274 get_session('u_hash')
275 ), __FILE__, __LINE__);
280 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET
281 gender='%s', surname='%s', family='%s',
283 country='%s', zip=%s, city='%s',
285 birth_day=%s, birth_month=%s, birth_year=%s,
287 last_update=UNIX_TIMESTAMP()".$AND.",
289 last_profile_sent=UNIX_TIMESTAMP()
290 WHERE userid=%s AND password='%s' LIMIT 1",
294 $_POST['family_name'],
297 bigintval($_POST['zip']),
300 bigintval($_POST['day']),
301 bigintval($_POST['month']),
302 bigintval($_POST['year']),
303 bigintval($_POST['max_mails']),
305 get_session('u_hash')
306 ), __FILE__, __LINE__);
310 $modes = explode(";", $MODE);
312 // ... and run them through
313 SEND_MODE_MAILS ("mydata", $modes);
317 // Entered wrong pass for updating profile
318 LOAD_TEMPLATE("admin_settings_saved", false, MEBER_UPDATE_PWD_WRONG);
323 case "notify": // Switch off notfication
324 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET notified='N', last_update=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
325 array($GLOBALS['userid']), __FILE__, __LINE__);
326 $URL = URL."/modules.php?module=login&what=welcome&msg=".urlencode(PROFILE_UPDATED);
331 // Load generated URL