2 /* make sure that we are not called from outside the scripts,
3 * use a variable defined in config.php to check this
8 $name = $_SESSION["name"];
9 $email = DB_get_email('name',$name);
10 $myid = DB_get_userid('email',$email);
14 /* track what got changed */
16 $changed_password = 0;
18 $changed_timezone = 0;
19 $changed_autosetup = 0;
21 $changed_openforgames = 0;
22 $changed_vacation = 0;
24 display_user_menu($myid);
27 $PREF = DB_get_PREF($myid);
28 $timezone = DB_get_user_timezone($myid);
30 DB_update_user_timestamp($myid);
32 /* does the user want to change some preferences?
33 * update the database and track changes with a variable, so that
34 * we can later highlight the changed value
36 if(myisset("timezone"))
38 $newtimezone = $_REQUEST['timezone'];
39 if($newtimezone != $timezone)
41 DB_query("UPDATE User SET timezone=".DB_quote_smart($newtimezone).
42 " WHERE id=".DB_quote_smart($myid));
43 $changed_timezone = 1;
49 $cards=$_REQUEST['cards'];
50 if($cards != $PREF['cardset'])
52 /* check if we already have an entry for the user, if so change it, if not create new one */
53 $result = DB_query("SELECT * from User_Prefs".
54 " WHERE user_id='$myid' AND pref_key='cardset'" );
55 if( DB_fetch_array($result))
56 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($cards).
57 " WHERE user_id='$myid' AND pref_key='cardset'" );
59 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','cardset',".
60 DB_quote_smart($cards).")");
67 $notify=$_REQUEST['notify'];
68 if($notify != $PREF['email'])
70 /* check if we already have an entry for the user, if so change it, if not create new one */
71 $result = DB_query("SELECT * from User_Prefs".
72 " WHERE user_id='$myid' AND pref_key='email'" );
73 if( DB_fetch_array($result))
74 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($notify).
75 " WHERE user_id='$myid' AND pref_key='email'" );
77 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','email',".
78 DB_quote_smart($notify).")");
83 if(myisset("autosetup"))
85 $autosetup = $_REQUEST['autosetup'];
86 if($autosetup != $PREF['autosetup'])
88 /* check if we already have an entry for the user, if so change it, if not create new one */
89 $result = DB_query("SELECT * from User_Prefs".
90 " WHERE user_id='$myid' AND pref_key='autosetup'" );
91 if( DB_fetch_array($result))
92 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($autosetup).
93 " WHERE user_id='$myid' AND pref_key='autosetup'" );
95 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','autosetup',".
96 DB_quote_smart($autosetup).")");
101 if(myisset("sorting"))
103 $sorting = $_REQUEST['sorting'];
104 if($sorting != $PREF['sorting'])
106 /* check if we already have an entry for the user, if so change it, if not create new one */
107 $result = DB_query("SELECT * from User_Prefs".
108 " WHERE user_id='$myid' AND pref_key='sorting'" );
109 if( DB_fetch_array($result))
110 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($sorting).
111 " WHERE user_id='$myid' AND pref_key='sorting'" );
113 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','sorting',".
114 DB_quote_smart($sorting).")");
119 if(myisset("open_for_games"))
121 $openforgames = $_REQUEST['open_for_games'];
122 if($openforgames != $PREF['open_for_games'])
124 /* check if we already have an entry for the user, if so change it, if not create new one */
125 $result = DB_query("SELECT * from User_Prefs".
126 " WHERE user_id='$myid' AND pref_key='open for games'" );
127 if( DB_fetch_array($result))
128 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($openforgames).
129 " WHERE user_id='$myid' AND pref_key='open for games'" );
131 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','open for games',".
132 DB_quote_smart($openforgames).")");
133 $changed_openforgames=1;
138 if(myisset("password0") && $_REQUEST["password0"]!="" )
140 $changed_password = 1;
142 /* check if old password matches */
143 $oldpasswd = md5($_REQUEST["password0"]);
144 $password = DB_get_passwd_by_userid($myid);
145 if(!( ($password == $oldpasswd) || DB_check_recovery_passwords($oldpasswd,$email) ))
146 $changed_password = -1;
148 /* check if new password has been typed in correctly */
149 if($_REQUEST["password1"] != $_REQUEST["password2"] )
150 $changed_password = -2;
152 /* check if new password is long enough */
153 if(strlen($_REQUEST["password1"])<4)
154 $changed_password = -3;
156 if($changed_password==1)
158 DB_query("UPDATE User SET password='".md5($_REQUEST["password1"]).
159 "' WHERE id=".DB_quote_smart($myid));
161 /* error output below */
164 /* get infos again in case they have changed */
165 $PREF = DB_get_PREF($myid);
166 $timezone = DB_get_user_timezone($myid);
172 echo "<div class=\"user\">\n";
173 echo " <form action=\"index.php?action=prefs\" method=\"post\">\n";
174 echo " <h2>Your settings are</h2>\n";
175 echo " <fieldset>\n";
176 echo " <legend>Game-related</legend>\n";
179 echo " <tr><td>Notification: </td><td>\n";
180 echo " <select id=\"notify\" name=\"notify\" size=\"1\">\n";
181 if($PREF['email']=="emailaddict")
183 echo " <option value=\"emailaddict\" selected=\"selected\">less emails</option>\n";
184 echo " <option value=\"emailnonaddict\">lots of emails</option>\n";
188 echo " <option value=\"emailaddict\">less email</option>\n";
189 echo " <option value=\"emailnonaddict\" selected=\"selected\">lots of email</option>\n";
192 if($changed_notify) echo "changed";
193 echo " </td></tr>\n";
195 echo " <tr><td>Autosetup: </td><td>\n";
196 echo " <select id=\"autosetup\" name=\"autosetup\" size=\"1\">\n";
197 if($PREF['autosetup']=="yes")
199 echo " <option value=\"yes\" selected=\"selected\">accept every game</option>\n";
200 echo " <option value=\"no\">ask for games</option>\n";
204 echo " <option value=\"yes\">accept every game</option>\n";
205 echo " <option value=\"no\" selected=\"selected\">ask for games</option>\n";
208 if($changed_autosetup) echo "changed";
209 echo " </td></tr>\n";
210 echo " <tr><td>Sorting: </td><td>\n";
212 echo " <select id=\"sorting\" name=\"sorting\" size=\"1\">\n";
213 if($PREF['sorting']=="high-low")
215 echo " <option value=\"high-low\" selected=\"selected\">high to low</option>\n";
216 echo " <option value=\"low-high\">low to high</option>\n";
220 echo " <option value=\"high-low\">high to low</option>\n";
221 echo " <option value=\"low-high\" selected=\"selected\">low to high</option>\n";
224 if($changed_sorting) echo "changed";
225 echo " </td></tr>\n";
226 echo " <tr><td>Open for new games: </td><td>\n";
227 echo " <select id=\"open_for_games\" name=\"open_for_games\" size=\"1\">\n";
228 if($PREF['open_for_games']=="no")
230 echo " <option value=\"yes\">yes</option>\n";
231 echo " <option value=\"no\" selected=\"selected\">no</option>\n";
235 echo " <option value=\"yes\" selected=\"selected\">yes</option>\n";
236 echo " <option value=\"no\">no</option>\n";
239 if($changed_openforgames) echo "changed";
240 echo " </td></tr>\n";
242 echo " <tr><td>Card set: </td><td>\n";
243 echo " <select id=\"cards\" name=\"cards\" size=\"1\">\n";
244 if($PREF['cardset']=="altenburg")
246 echo " <option value=\"altenburg\" selected=\"selected\">German cards</option>\n";
247 echo " <option value=\"english\">English cards</option>\n";
251 echo " <option value=\"altenburg\">German cards</option>\n";
252 echo " <option value=\"english\" selected=\"selected\">English cards</option>\n";
255 if($changed_cards) echo "changed";
256 echo " </td></tr>\n";
258 echo " </fieldset>\n";
259 echo " <fieldset>\n";
260 echo " <legend>Personal</legend>\n";
262 echo " <tr><td>Email: </td><td> $email </td></tr>\n";
263 echo " <tr><td>Timezone: </td><td>\n";
264 output_select_timezone("timezone",$timezone);
265 if($changed_timezone) echo "changed";
268 echo " <tr><td>Password(old): </td><td>",
269 "<input type=\"password\" id=\"password0\" name=\"password0\" size=\"20\" maxlength=\"30\" />";
270 switch($changed_password)
273 echo "The new passwords is not long enough (you need at least 4 characters).";
276 echo "The new passwords don't match.";
279 echo "The old password is not correct.";
285 echo " </td></tr>\n";
286 echo " <tr><td>Password(new): </td><td>",
287 "<input type=\"password\" id=\"password1\" name=\"password1\" size=\"20\" maxlength=\"30\" />",
289 echo " <tr><td>Password(new, retype): </td><td>",
290 "<input type=\"password\" id=\"password2\" name=\"password2\" size=\"20\" maxlength=\"30\" />",
293 echo " </fieldset>\n";
294 echo " <fieldset><legend>Submit</legend><input type=\"submit\" name=\"passwd\" value=\"set\" /></fieldset>\n";