Obsoleted parameters to SQL_AFFECTED_ROWS() removed, OPEN_TABLE() and CLOSE_TABLE...
[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_MEMBER())
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 define('UID_VALUE', $GLOBALS['userid']); $URL = "";
54
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
60
61 switch ($MODE)
62 {
63 case "show": // Show his data
64         if (EXT_IS_ACTIVE("country", true))
65         {
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, sex, max_mails, receive_mails, last_update FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
68                  array(UID_VALUE), __FILE__, __LINE__);
69         }
70          else
71         {
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, sex, max_mails, receive_mails, last_update FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
74                  array(UID_VALUE), __FILE__, __LINE__);
75         }
76         $DATA = SQL_FETCHROW($result);
77         SQL_FREERESULT($result);
78
79         // Translate / add some things
80         $DATA[10] = TRANSLATE_SEX($DATA[10]);
81         $DATA[13] = MAKE_DATETIME($DATA[13], "0");
82
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))
85         {
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>");
88         }
89          else
90         {
91                 // He is allowed to change his profile
92                 define('CHANGE', LOAD_TEMPLATE("member_mydata_button", true));
93         }
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())
97         {
98                 case "de": define('DOB', $DATA[7].".".$DATA[8].".".$DATA[9]); break;
99                 default  : define('DOB', $DATA[8]."-".$DATA[7]."-".$DATA[9]); break;
100         }
101
102         if (EXT_IS_ACTIVE("country"))
103         {
104                 // Load country's description and code
105                 $DATA[3] = COUNTRY_GENERATE_INFO($DATA[3]);
106         }
107
108         // Load template
109         LOAD_TEMPLATE("member_mydata_overview");
110         break;
111
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, sex, max_mails, receive_mails, last_update
116 FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
117                  array(UID_VALUE), __FILE__, __LINE__);
118         } else {
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, sex, max_mails, receive_mails, last_update
121 FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
122                  array(UID_VALUE), __FILE__, __LINE__);
123         }
124
125         $DATA = SQL_FETCHROW($result);
126         SQL_FREERESULT($result);
127         $DATA[13] = $DATA[12] + $_CONFIG['profile_lock'];
128
129         // How far is last change on his profile away from now?
130         if (($DATA[13] > time()) && (!IS_ADMIN()) && ($_CONFIG['profile_lock'] > 0))
131         {
132                 $DATA[13] = MAKE_DATETIME($DATA[13] + $_CONFIG['profile_lock'], "0");
133                 // You cannot change your account
134                 LOAD_TEMPLATE("member_mydata_locked");
135         }
136          else
137         {
138                 // He is allowed to change his profile
139                 switch ($DATA[10])
140                 {
141                 case "M":
142                         define('M_DEFAULT', " selected=\"selected\"");
143                         define('F_DEFAULT', "");
144                         define('C_DEFAULT', "");
145                         break;
146
147                 case "F":
148                         define('M_DEFAULT', "");
149                         define('F_DEFAULT', " selected=\"selected\"");
150                         define('C_DEFAULT', "");
151                         break;
152
153                 case "C":
154                         define('M_DEFAULT', "");
155                         define('F_DEFAULT', "");
156                         define('C_DEFAULT', " selected=\"selected\"");
157                         break;
158                 }
159                 $DOB = "";
160                 switch (GET_LANGUAGE())
161                 {
162                 case "de": // German date format
163                         // Day
164                         $DOB .= ADD_SELECTION("day", $DATA[7]);
165
166                         // Month
167                         $DOB .= ADD_SELECTION("month", $DATA[8]);
168
169                         // Year
170                         $DOB .= ADD_SELECTION("year", $DATA[9]);
171                         break;
172
173                 default: // Default is the US date format... :)
174                         break;
175                 }
176                 define('DOB', $DOB);
177                 define('MAX_REC_LIST', ADD_MAX_RECEIVE_LIST("member", $DATA[11], true));
178
179                 if (EXT_IS_ACTIVE("country"))
180                 {
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);
186                         $OUT .= "</SELECT>";
187                         define('__COUNTRY_CONTENT', $OUT);
188                 }
189                  else
190                 {
191                         // Ouput default input box
192                         define('__COUNTRY_CONTENT', "<INPUT type=\"text\" name=\"cntry\" class=\"member_normal\" size=\"2\" maxlength=\"3\" value=\"".$DATA[3]."\">");
193                 }
194
195                 // Load template
196                 LOAD_TEMPLATE("member_mydata_edit");
197         }
198         break;
199
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'];
207
208         // How far is last change on his profile away from now?
209         if (($DATA[3] > time()) && (!IS_ADMIN()) && ($_CONFIG['profile_lock'] > 0))
210         {
211                 $DATA[3] = MAKE_DATETIME($DATA[3] + $_CONFIG['profile_lock'], "0");
212                 // You cannot change your account
213                 LOAD_TEMPLATE("member_mydata_locked");
214         }
215          elseif (!VALIDATE_EMAIL($_POST['addy']))
216         {
217                 // Invalid email address!
218                 LOAD_TEMPLATE("admin_settings_saved", false, INVALID_EMAIL_ADDRESS_ENTERED);
219         }
220          else
221         {
222                 // Secure every submitted variable
223                 foreach ($_POST as $key=>$value)
224                 {
225                         $_POST[$key] = addslashes($value);
226                 }
227
228                 $hash = generateHash($_POST['pass1'], substr($DATA[1], 0, -40));
229                 if ((($hash == $DATA[1]) || ($_POST['pass1'] == $_POST['pass2'])) && (!empty($_POST['pass1'])))
230                 {
231                         // Only on simple changes normal mode is active = no email or password changed
232                         $MODE = "normal"; $AND = "";
233
234                         // Did the user changed the password?
235                         if ($hash != $DATA[1]) { $AND = ", password='".$hash."'"; $MODE = "pass"; }
236
237                         // Or did he changed his password?
238                         if ($_POST['addy'] != $DATA[0])
239                         {
240                                 // Jupp
241                                 if ($MODE == "normal") { $MODE = "email"; } else { $MODE .= ";email"; }
242                                 $_POST['old_addy'] = $DATA[0];
243                         }
244
245                         // Update member's profile
246                         if (EXT_IS_ACTIVE("country"))
247                         {
248                                 // New way
249                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET
250 sex='%s', surname='%s', family='%s',
251 street_nr='%s',
252 country_code=%s, zip=%s, city='%s',
253 email='%s',
254 birth_day=%s, birth_month=%s, birth_year=%s,
255 max_mails=%s,
256 last_update=UNIX_TIMESTAMP()".$AND.",
257 notified='N',
258 last_profile_sent=UNIX_TIMESTAMP()
259 WHERE userid=%s AND password='%s' LIMIT 1",
260 array(
261         $_POST['sex'],
262         $_POST['surname'],
263         $_POST['family_name'],
264         $_POST['street_nr'],
265         bigintval($_POST['country_code']),
266         bigintval($_POST['zip']),
267         $_POST['city'],
268         $_POST['addy'],
269         bigintval($_POST['day']),
270         bigintval($_POST['month']),
271         bigintval($_POST['year']),
272         bigintval($_POST['max_mails']),
273         UID_VALUE,
274         get_session('u_hash')
275  ), __FILE__, __LINE__);
276                         }
277                          else
278                         {
279                                 // Old way
280                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET
281 sex='%s', surname='%s', family='%s',
282 street_nr='%s',
283 country='%s', zip=%s, city='%s',
284 email='%s',
285 birth_day=%s, birth_month=%s, birth_year=%s,
286 max_mails='%s',
287 last_update=UNIX_TIMESTAMP()".$AND.",
288 notified='N',
289 last_profile_sent=UNIX_TIMESTAMP()
290 WHERE userid=%s AND password='%s' LIMIT 1",
291 array(
292         $_POST['sex'],
293         $_POST['surname'],
294         $_POST['family_name'],
295         $_POST['street_nr'],
296         $_POST['cntry'],
297         bigintval($_POST['zip']),
298         $_POST['city'],
299         $_POST['addy'],
300         bigintval($_POST['day']),
301         bigintval($_POST['month']),
302         bigintval($_POST['year']),
303         bigintval($_POST['max_mails']),
304         UID_VALUE,
305         get_session('u_hash')
306  ), __FILE__, __LINE__);
307                         }
308
309                         // Get all modes ...
310                         $modes = explode(";", $MODE);
311
312                         // ... and run them through
313                         SEND_MODE_MAILS ("mydata", $modes);
314                 }
315                  else
316                 {
317                         // Entered wrong pass for updating profile
318                         LOAD_TEMPLATE("admin_settings_saved", false, MEBER_UPDATE_PWD_WRONG);
319                 }
320         }
321         break;
322
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&amp;what=welcome&msg=".urlencode(PROFILE_UPDATED);
327         break;
328 }
329
330 if (!empty($URL)) {
331         // Load generated URL
332         LOAD_URL($URL);
333 }
334
335 //
336 ?>