Refback will be payed now (user cannot setup currently)
[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")) {
41         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "mydata");
42         return;
43 }
44
45 // Add description as navigation point
46 ADD_DESCR("member", basename(__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] + $_CONFIG['profile_lock']) > time()) && (!IS_ADMIN()) && ($_CONFIG['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] + $_CONFIG['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] + $_CONFIG['profile_lock'];
123
124         // How far is last change on his profile away from now?
125         if (($DATA[13] > time()) && (!IS_ADMIN()) && ($_CONFIG['profile_lock'] > 0))
126         {
127                 $DATA[13] = MAKE_DATETIME($DATA[13] + $_CONFIG['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                 define('DOB', $DOB);
172                 define('MAX_REC_LIST', ADD_MAX_RECEIVE_LIST("member", $DATA[11], true));
173
174                 if (EXT_IS_ACTIVE("country"))
175                 {
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                 }
184                  else
185                 {
186                         // Ouput default input box
187                         define('__COUNTRY_CONTENT', "<INPUT type=\"text\" name=\"cntry\" class=\"member_normal\" size=\"2\" maxlength=\"3\" value=\"".$DATA[3]."\">");
188                 }
189
190                 // Load template
191                 LOAD_TEMPLATE("member_mydata_edit");
192         }
193         break;
194
195 case "save": // Save entered data
196         // Load old email / password:      0        1          2
197         $result = SQL_QUERY_ESC("SELECT email, password, last_update FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
198          array(UID_VALUE), __FILE__, __LINE__);
199         $DATA = SQL_FETCHROW($result);
200         SQL_FREERESULT($result);
201         $DATA[3] = $DATA[2] + $_CONFIG['profile_lock'];
202
203         // How far is last change on his profile away from now?
204         if (($DATA[3] > time()) && (!IS_ADMIN()) && ($_CONFIG['profile_lock'] > 0))
205         {
206                 $DATA[3] = MAKE_DATETIME($DATA[3] + $_CONFIG['profile_lock'], "0");
207                 // You cannot change your account
208                 LOAD_TEMPLATE("member_mydata_locked");
209         }
210          elseif (!VALIDATE_EMAIL($_POST['addy']))
211         {
212                 // Invalid email address!
213                 LOAD_TEMPLATE("admin_settings_saved", false, INVALID_EMAIL_ADDRESS_ENTERED);
214         }
215          else
216         {
217                 // Secure every submitted variable
218                 foreach ($_POST as $key => $value)
219                 {
220                         $_POST[$key] = addslashes($value);
221                 }
222
223                 $hash = generateHash($_POST['pass1'], substr($DATA[1], 0, -40));
224                 if ((($hash == $DATA[1]) || ($_POST['pass1'] == $_POST['pass2'])) && (!empty($_POST['pass1'])))
225                 {
226                         // Only on simple changes normal mode is active = no email or password changed
227                         $MODE = "normal"; $AND = "";
228
229                         // Did the user changed the password?
230                         if ($hash != $DATA[1]) { $AND = ", password='".$hash."'"; $MODE = "pass"; }
231
232                         // Or did he changed his password?
233                         if ($_POST['addy'] != $DATA[0])
234                         {
235                                 // Jupp
236                                 if ($MODE == "normal") { $MODE = "email"; } else { $MODE .= ";email"; }
237                                 $_POST['old_addy'] = $DATA[0];
238                         }
239
240                         // Update member's profile
241                         if (EXT_IS_ACTIVE("country"))
242                         {
243                                 // New way
244                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET
245 gender='%s', surname='%s', family='%s',
246 street_nr='%s',
247 country_code=%s, zip=%s, city='%s',
248 email='%s',
249 birth_day=%s, birth_month=%s, birth_year=%s,
250 max_mails=%s,
251 last_update=UNIX_TIMESTAMP()".$AND.",
252 notified='N',
253 last_profile_sent=UNIX_TIMESTAMP()
254 WHERE userid=%s AND password='%s' LIMIT 1",
255 array(
256         $_POST['gender'],
257         $_POST['surname'],
258         $_POST['family_name'],
259         $_POST['street_nr'],
260         bigintval($_POST['country_code']),
261         bigintval($_POST['zip']),
262         $_POST['city'],
263         $_POST['addy'],
264         bigintval($_POST['day']),
265         bigintval($_POST['month']),
266         bigintval($_POST['year']),
267         bigintval($_POST['max_mails']),
268         UID_VALUE,
269         get_session('u_hash')
270  ), __FILE__, __LINE__);
271                         }
272                          else
273                         {
274                                 // Old way
275                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET
276 gender='%s', surname='%s', family='%s',
277 street_nr='%s',
278 country='%s', zip=%s, city='%s',
279 email='%s',
280 birth_day=%s, birth_month=%s, birth_year=%s,
281 max_mails='%s',
282 last_update=UNIX_TIMESTAMP()".$AND.",
283 notified='N',
284 last_profile_sent=UNIX_TIMESTAMP()
285 WHERE userid=%s AND password='%s' LIMIT 1",
286 array(
287         $_POST['gender'],
288         $_POST['surname'],
289         $_POST['family_name'],
290         $_POST['street_nr'],
291         $_POST['cntry'],
292         bigintval($_POST['zip']),
293         $_POST['city'],
294         $_POST['addy'],
295         bigintval($_POST['day']),
296         bigintval($_POST['month']),
297         bigintval($_POST['year']),
298         bigintval($_POST['max_mails']),
299         UID_VALUE,
300         get_session('u_hash')
301  ), __FILE__, __LINE__);
302                         }
303
304                         // Get all modes ...
305                         $modes = explode(";", $MODE);
306
307                         // ... and run them through
308                         SEND_MODE_MAILS ("mydata", $modes);
309                 }
310                  else
311                 {
312                         // Entered wrong pass for updating profile
313                         LOAD_TEMPLATE("admin_settings_saved", false, MEBER_UPDATE_PWD_WRONG);
314                 }
315         }
316         break;
317
318 case "notify": // Switch off notfication
319         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET notified='N', last_update=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
320          array($GLOBALS['userid']), __FILE__, __LINE__);
321         $URL = URL."/modules.php?module=login&amp;what=welcome&msg=".urlencode(PROFILE_UPDATED);
322         break;
323 }
324
325 if (!empty($URL)) {
326         // Load generated URL
327         LOAD_URL($URL);
328 }
329
330 //
331 ?>