7122e5e79a1cbe22ff4377bf079326a2bc7045d7
[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 (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
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");
42         return;
43 }
44
45 // Add description as navigation point
46 ADD_DESCR("member", __FILE__);
47
48 define('UID_VALUE', $GLOBALS['userid']); $URL = "";
49
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
55
56 switch ($MODE)
57 {
58 case "show": // Show his data
59         if (EXT_IS_ACTIVE("country", true))
60         {
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__);
64         }
65          else
66         {
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__);
70         }
71         $DATA = SQL_FETCHROW($result);
72         SQL_FREERESULT($result);
73
74         // Translate / add some things
75         $DATA[10] = TRANSLATE_GENDER($DATA[10]);
76         $DATA[13] = MAKE_DATETIME($DATA[13], "0");
77
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))
80         {
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>");
83         }
84          else
85         {
86                 // He is allowed to change his profile
87                 define('CHANGE', LOAD_TEMPLATE("member_mydata_button", true));
88         }
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())
92         {
93                 case "de": define('DOB', $DATA[7].".".$DATA[8].".".$DATA[9]); break;
94                 default  : define('DOB', $DATA[8]."-".$DATA[7]."-".$DATA[9]); break;
95         }
96
97         if (EXT_IS_ACTIVE("country"))
98         {
99                 // Load country's description and code
100                 $DATA[3] = COUNTRY_GENERATE_INFO($DATA[3]);
101         }
102
103         // Load template
104         LOAD_TEMPLATE("member_mydata_overview");
105         break;
106
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__);
113         } else {
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__);
118         }
119
120         $DATA = SQL_FETCHROW($result);
121         SQL_FREERESULT($result);
122         $DATA[13] = $DATA[12] + getConfig('profile_lock');
123
124         // How far is last change on his profile away from now?
125         if (($DATA[13] > time()) && (!IS_ADMIN()) && (getConfig('profile_lock') > 0))
126         {
127                 $DATA[13] = MAKE_DATETIME($DATA[13] + getConfig('profile_lock'), "0");
128                 // You cannot change your account
129                 LOAD_TEMPLATE("member_mydata_locked");
130         }
131          else
132         {
133                 // He is allowed to change his profile
134                 switch ($DATA[10])
135                 {
136                 case "M":
137                         define('M_DEFAULT', " selected=\"selected\"");
138                         define('F_DEFAULT', "");
139                         define('C_DEFAULT', "");
140                         break;
141
142                 case "F":
143                         define('M_DEFAULT', "");
144                         define('F_DEFAULT', " selected=\"selected\"");
145                         define('C_DEFAULT', "");
146                         break;
147
148                 case "C":
149                         define('M_DEFAULT', "");
150                         define('F_DEFAULT', "");
151                         define('C_DEFAULT', " selected=\"selected\"");
152                         break;
153                 }
154                 $DOB = "";
155                 switch (GET_LANGUAGE())
156                 {
157                 case "de": // German date format
158                         // Day
159                         $DOB .= ADD_SELECTION("day", $DATA[7]);
160
161                         // Month
162                         $DOB .= ADD_SELECTION("month", $DATA[8]);
163
164                         // Year
165                         $DOB .= ADD_SELECTION("year", $DATA[9]);
166                         break;
167
168                 default: // Default is the US date format... :)
169                         break;
170                 }
171
172                 define('DOB', $DOB);
173                 define('MAX_REC_LIST', ADD_MAX_RECEIVE_LIST("member", $DATA[11], true));
174
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);
181                         $OUT .= "</SELECT>";
182                         define('__COUNTRY_CONTENT', $OUT);
183                 } else {
184                         // Ouput default input box
185                         define('__COUNTRY_CONTENT', "<INPUT type=\"text\" name=\"cntry\" class=\"member_normal\" size=\"2\" maxlength=\"3\" value=\"".$DATA[3]."\">");
186                 }
187
188                 // Load template
189                 LOAD_TEMPLATE("member_mydata_edit");
190         }
191         break;
192
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');
200
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);
209         } else {
210                 // Generate hash
211                 $hash = generateHash($_POST['pass1'], substr($DATA[1], 0, -40));
212                 if ((($hash == $DATA[1]) || ($_POST['pass1'] == $_POST['pass2'])) && (!empty($_POST['pass1'])))
213                 {
214                         // Only on simple changes normal mode is active = no email or password changed
215                         $MODE = "normal"; $AND = "";
216
217                         // Did the user changed the password?
218                         if ($hash != $DATA[1]) { $AND = ", password='".$hash."'"; $MODE = "pass"; }
219
220                         // Or did he changed his password?
221                         if ($_POST['addy'] != $DATA[0])
222                         {
223                                 // Jupp
224                                 if ($MODE == "normal") { $MODE = "email"; } else { $MODE .= ";email"; }
225                                 $_POST['old_addy'] = $DATA[0];
226                         }
227
228                         // Update member's profile
229                         if (EXT_IS_ACTIVE("country"))
230                         {
231                                 // New way
232                                 SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET
233 gender='%s', surname='%s', family='%s',
234 street_nr='%s',
235 country_code=%s, zip=%s, city='%s',
236 email='%s',
237 birth_day=%s, birth_month=%s, birth_year=%s,
238 max_mails=%s,
239 last_update=UNIX_TIMESTAMP()".$AND.",
240 notified='N',
241 last_profile_sent=UNIX_TIMESTAMP()
242 WHERE userid=%s AND password='%s' LIMIT 1",
243 array(
244         $_POST['gender'],
245         $_POST['surname'],
246         $_POST['family_name'],
247         $_POST['street_nr'],
248         bigintval($_POST['country_code']),
249         bigintval($_POST['zip']),
250         $_POST['city'],
251         $_POST['addy'],
252         bigintval($_POST['day']),
253         bigintval($_POST['month']),
254         bigintval($_POST['year']),
255         bigintval($_POST['max_mails']),
256         UID_VALUE,
257         get_session('u_hash')
258  ), __FILE__, __LINE__);
259                         }
260                          else
261                         {
262                                 // Old way
263                                 SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET
264 gender='%s', surname='%s', family='%s',
265 street_nr='%s',
266 country='%s', zip=%s, city='%s',
267 email='%s',
268 birth_day=%s, birth_month=%s, birth_year=%s,
269 max_mails='%s',
270 last_update=UNIX_TIMESTAMP()".$AND.",
271 notified='N',
272 last_profile_sent=UNIX_TIMESTAMP()
273 WHERE userid=%s AND password='%s' LIMIT 1",
274 array(
275         $_POST['gender'],
276         $_POST['surname'],
277         $_POST['family_name'],
278         $_POST['street_nr'],
279         $_POST['cntry'],
280         bigintval($_POST['zip']),
281         $_POST['city'],
282         $_POST['addy'],
283         bigintval($_POST['day']),
284         bigintval($_POST['month']),
285         bigintval($_POST['year']),
286         bigintval($_POST['max_mails']),
287         UID_VALUE,
288         get_session('u_hash')
289  ), __FILE__, __LINE__);
290                         }
291
292                         // Get all modes ...
293                         $modes = explode(";", $MODE);
294
295                         // ... and run them through
296                         SEND_MODE_MAILS ("mydata", $modes);
297                 }
298                  else
299                 {
300                         // Entered wrong pass for updating profile
301                         LOAD_TEMPLATE("admin_settings_saved", false, MEBER_UPDATE_PWD_WRONG);
302                 }
303         }
304         break;
305
306 case "notify": // Switch off notfication
307         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 = "modules.php?module=login&amp;what=welcome&amp;msg=".urlencode(PROFILE_UPDATED);
310         break;
311 }
312
313 if (!empty($URL)) {
314         // Load generated URL
315         LOAD_URL($URL);
316 }
317
318 //
319 ?>