2 /* make sure that we are not called from outside the scripts,
3 * use a variable defined in config.php to check this
8 include_once('openid.php');
10 $name = $_SESSION["name"];
11 $email = DB_get_email('name',$name);
12 $myid = DB_get_userid('email',$email);
16 /* track what got changed */
18 $changed_password = 0;
20 $changed_timezone = 0;
21 $changed_autosetup = 0;
23 $changed_openforgames = 0;
24 $changed_vacation = 0;
28 display_user_menu($myid);
31 $PREF = DB_get_PREF($myid);
32 $timezone = DB_get_user_timezone($myid);
34 DB_update_user_timestamp($myid);
36 /* does the user want to change some preferences?
37 * update the database and track changes with a variable, so that
38 * we can later highlight the changed value
41 /* check for deleted openids */
42 foreach($_REQUEST as $key=>$value)
44 if(strstr($key,"delete-openid-"))
46 /* found and openid to delete */
47 $DelOpenID = substr(str_replace("_",".",$key),14);
48 DB_DetachOpenID($DelOpenID, $myid);
54 if(myisset('vacation_start','vacation_stop','vacation_comment') &&
55 ($_REQUEST['vacation_start']!='' || $_REQUEST['vacation_stop']!='')
58 $vacation_start = $_REQUEST['vacation_start'].' 00:00:00';
59 $vacation_stop = $_REQUEST['vacation_stop'].' 23:59:59';
60 $vacation_comment = $_REQUEST['vacation_comment'];
62 /* check if everything is valid */
63 if(!strtotime($vacation_start))
64 $changed_vacation = -1;
65 if(!strtotime($vacation_stop))
66 $changed_vacation = -1;
68 /* test if we should delete the entry */
69 if($vacation_start == '- 00:00:00')
71 $result = DB_query("DELETE FROM User_Prefs".
72 " WHERE user_id='$myid' AND pref_key='vacation start'" );
73 $result = DB_query("DELETE FROM User_Prefs".
74 " WHERE user_id='$myid' AND pref_key='vacation stop'" );
75 $result = DB_query("DELETE FROM User_Prefs".
76 " WHERE user_id='$myid' AND pref_key='vacation comment'" );
77 $changed_vacation = 1;
79 /* change in database if format is ok */
80 else if($changed_vacation>=0)
82 /* only change if different from current value */
83 if($vacation_start!=$PREF['vacation_start'])
85 $result = DB_query("SELECT * from User_Prefs".
86 " WHERE user_id='$myid' AND pref_key='vacation start'" );
87 if( DB_fetch_array($result))
88 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($vacation_start).
89 " WHERE user_id='$myid' AND pref_key='vacation start'" );
91 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','vacation start',".
92 DB_quote_smart($vacation_start).")");
94 $changed_vacation = 1;
97 /* same for the stop date */
98 if($vacation_stop!=$PREF['vacation_stop'])
100 $result = DB_query("SELECT * from User_Prefs".
101 " WHERE user_id='$myid' AND pref_key='vacation stop'" );
102 if( DB_fetch_array($result))
103 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($vacation_stop).
104 " WHERE user_id='$myid' AND pref_key='vacation stop'" );
106 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','vacation stop',".
107 DB_quote_smart($vacation_stop).")");
109 $changed_vacation = 1;
112 /* does the user want to add a comment? */
113 if($vacation_comment!=$PREF['vacation_comment'])
115 $result = DB_query("SELECT * from User_Prefs".
116 " WHERE user_id='$myid' AND pref_key='vacation comment'" );
117 if( DB_fetch_array($result))
118 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($vacation_comment).
119 " WHERE user_id='$myid' AND pref_key='vacation comment'" );
121 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','vacation comment',".
122 DB_quote_smart($vacation_comment).")");
124 $changed_vacation = 1;
129 if(myisset("timezone"))
131 $newtimezone = $_REQUEST['timezone'];
132 if($newtimezone != $timezone)
134 DB_query("UPDATE User SET timezone=".DB_quote_smart($newtimezone).
135 " WHERE id=".DB_quote_smart($myid));
136 $changed_timezone = 1;
142 $cards=$_REQUEST['cards'];
143 if($cards != $PREF['cardset'])
145 /* check if we already have an entry for the user, if so change it, if not create new one */
146 $result = DB_query("SELECT * from User_Prefs".
147 " WHERE user_id='$myid' AND pref_key='cardset'" );
148 if( DB_fetch_array($result))
149 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($cards).
150 " WHERE user_id='$myid' AND pref_key='cardset'" );
152 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','cardset',".
153 DB_quote_smart($cards).")");
158 if(myisset("notify"))
160 $notify=$_REQUEST['notify'];
161 if($notify != $PREF['email'])
163 /* check if we already have an entry for the user, if so change it, if not create new one */
164 $result = DB_query("SELECT * from User_Prefs".
165 " WHERE user_id='$myid' AND pref_key='email'" );
166 if( DB_fetch_array($result))
167 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($notify).
168 " WHERE user_id='$myid' AND pref_key='email'" );
170 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','email',".
171 DB_quote_smart($notify).")");
176 if(myisset("digest"))
178 $digest=$_REQUEST['digest'];
179 if($digest != $PREF['digest'])
181 /* check if we already have an entry for the user, if so change it, if not create new one */
182 $result = DB_query("SELECT * from User_Prefs".
183 " WHERE user_id='$myid' AND pref_key='digest'" );
184 if( DB_fetch_array($result))
185 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($digest).
186 " WHERE user_id='$myid' AND pref_key='digest'" );
188 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','digest',".
189 DB_quote_smart($digest).")");
194 if(myisset("autosetup"))
196 $autosetup = $_REQUEST['autosetup'];
197 if($autosetup != $PREF['autosetup'])
199 /* check if we already have an entry for the user, if so change it, if not create new one */
200 $result = DB_query("SELECT * from User_Prefs".
201 " WHERE user_id='$myid' AND pref_key='autosetup'" );
202 if( DB_fetch_array($result))
203 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($autosetup).
204 " WHERE user_id='$myid' AND pref_key='autosetup'" );
206 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','autosetup',".
207 DB_quote_smart($autosetup).")");
208 $changed_autosetup=1;
212 if(myisset("sorting"))
214 $sorting = $_REQUEST['sorting'];
215 if($sorting != $PREF['sorting'])
217 /* check if we already have an entry for the user, if so change it, if not create new one */
218 $result = DB_query("SELECT * from User_Prefs".
219 " WHERE user_id='$myid' AND pref_key='sorting'" );
220 if( DB_fetch_array($result))
221 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($sorting).
222 " WHERE user_id='$myid' AND pref_key='sorting'" );
224 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','sorting',".
225 DB_quote_smart($sorting).")");
230 if(myisset("open_for_games"))
232 $openforgames = $_REQUEST['open_for_games'];
233 if($openforgames != $PREF['open_for_games'])
235 /* check if we already have an entry for the user, if so change it, if not create new one */
236 $result = DB_query("SELECT * from User_Prefs".
237 " WHERE user_id='$myid' AND pref_key='open for games'" );
238 if( DB_fetch_array($result))
239 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($openforgames).
240 " WHERE user_id='$myid' AND pref_key='open for games'" );
242 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','open for games',".
243 DB_quote_smart($openforgames).")");
244 $changed_openforgames=1;
249 if(myisset("password0","password1","password2") && $_REQUEST["password0"]!="" && $_REQUEST["password0"]!= $_REQUEST["password1"])
251 $changed_password = 1;
253 /* check if old password matches */
254 $oldpasswd = md5($_REQUEST["password0"]);
255 $password = DB_get_passwd_by_userid($myid);
256 if(!( ($password == $oldpasswd) || DB_check_recovery_passwords($oldpasswd,$email) ))
257 $changed_password = -1;
259 /* check if new password has been typed in correctly */
260 if($_REQUEST["password1"] != $_REQUEST["password2"] )
261 $changed_password = -2;
263 /* check if new password is long enough */
264 if(strlen($_REQUEST["password1"])<4)
265 $changed_password = -3;
267 if($changed_password==1)
269 DB_query("UPDATE User SET password='".md5($_REQUEST["password1"]).
270 "' WHERE id=".DB_quote_smart($myid));
272 /* error output below */
275 if(myisset("openid_url") && $_REQUEST['openid_url']!='')
277 $openid_url = OpenIDUrlEncode($_REQUEST['openid_url']);
278 DB_AttachOpenID($openid_url, $myid);
281 /* get infos again in case they have changed */
282 $PREF = DB_get_PREF($myid);
283 $timezone = DB_get_user_timezone($myid);
289 echo "<div class=\"user\">\n";
290 echo " <form action=\"index.php?action=prefs\" method=\"post\">\n";
291 echo " <h2>Your settings are</h2>\n";
292 echo " <fieldset>\n";
293 echo " <legend>Game-related</legend>\n";
296 echo " <tr><td>Vacation: </td>\n";
297 if($PREF['vacation_start'])
298 $value = substr($PREF['vacation_start'],0,10);
301 echo " <td>start:<input type=\"text\" id=\"vacation_start\" name=\"vacation_start\" size=\"10\" maxlength=\"10\" value=\"$value\" /></td>\n";
302 if($PREF['vacation_stop'])
303 $value = substr($PREF['vacation_stop'],0,10);
306 echo " <td>stop:<input type=\"text\" id=\"vacation_stop\" name=\"vacation_stop\" size=\"10\" maxlength=\"10\" value=\"$value\" /></td>\n";
307 if($PREF['vacation_comment'])
308 $value = $PREF['vacation_comment'];
311 echo " <td>comment:<input type=\"text\" id=\"vacation_comment\" name=\"vacation_comment\" size=\"10\" maxlength=\"50\" value=\"$value\" />";
312 if($changed_vacation == 1) echo "changed";
313 if($changed_vacation == -1) echo "wrong date format";
315 echo "<tr><td></td><td>use YYYY-MM-DD</td><td>use '-' in start field to unset vacation</td></tr>\n";
316 echo " <tr><td>Notification: </td><td>\n";
317 echo " <select id=\"notify\" name=\"notify\" size=\"1\">\n";
318 if($PREF['email']=="emailaddict")
320 echo " <option value=\"emailaddict\" selected=\"selected\">less emails</option>\n";
321 echo " <option value=\"emailnonaddict\">lots of emails</option>\n";
325 echo " <option value=\"emailaddict\">less email</option>\n";
326 echo " <option value=\"emailnonaddict\" selected=\"selected\">lots of email</option>\n";
329 if($changed_notify) echo "changed";
330 echo " </td></tr>\n";
332 echo " <tr><td>Digest: </td><td>\n";
333 echo " <select id=\"digest\" name=\"digest\" size=\"1\">\n";
335 $selected = "selected=\"selected\"";
336 echo " <option value=\"digest-off\"";
337 if($PREF['digest']=="digest-off") echo $selected;
338 echo ">digest off</option>\n";
340 echo " <option value=\"digest-1h\" ";
341 if($PREF['digest']=="digest-1h") echo $selected;
342 echo ">every hour</option>\n";
344 echo " <option value=\"digest-2h\" ";
345 if($PREF['digest']=="digest-2h") echo $selected;
346 echo ">every 2h</option>\n";
348 echo " <option value=\"digest-3h\" ";
349 if($PREF['digest']=="digest-3h") echo $selected;
350 echo ">every 3h</option>\n";
352 echo " <option value=\"digest-4h\" ";
353 if($PREF['digest']=="digest-4h") echo $selected;
354 echo ">every 4h</option>\n";
356 echo " <option value=\"digest-6h\" ";
357 if($PREF['digest']=="digest-6h") echo $selected;
358 echo ">every 6h</option>\n";
360 echo " <option value=\"digest-12h\"";
361 if($PREF['digest']=="digest-12h") echo $selected;
362 echo ">every 12h</option>\n";
364 echo " <option value=\"digest-24h\"";
365 if($PREF['digest']=="digest-24h") echo $selected;
366 echo ">every 24h</option>\n";
369 if($changed_digest) echo "changed";
370 echo " </td></tr>\n";
373 echo " <tr><td>Autosetup: </td><td>\n";
374 echo " <select id=\"autosetup\" name=\"autosetup\" size=\"1\">\n";
375 if($PREF['autosetup']=="yes")
377 echo " <option value=\"yes\" selected=\"selected\">accept every game</option>\n";
378 echo " <option value=\"no\">ask for games</option>\n";
382 echo " <option value=\"yes\">accept every game</option>\n";
383 echo " <option value=\"no\" selected=\"selected\">ask for games</option>\n";
386 if($changed_autosetup) echo "changed";
387 echo " </td></tr>\n";
388 echo " <tr><td>Sorting: </td><td>\n";
390 echo " <select id=\"sorting\" name=\"sorting\" size=\"1\">\n";
391 if($PREF['sorting']=="high-low")
393 echo " <option value=\"high-low\" selected=\"selected\">high to low</option>\n";
394 echo " <option value=\"low-high\">low to high</option>\n";
398 echo " <option value=\"high-low\">high to low</option>\n";
399 echo " <option value=\"low-high\" selected=\"selected\">low to high</option>\n";
402 if($changed_sorting) echo "changed";
403 echo " </td></tr>\n";
404 echo " <tr><td>Open for new games: </td><td>\n";
405 echo " <select id=\"open_for_games\" name=\"open_for_games\" size=\"1\">\n";
406 if($PREF['open_for_games']=="no")
408 echo " <option value=\"yes\">yes</option>\n";
409 echo " <option value=\"no\" selected=\"selected\">no</option>\n";
413 echo " <option value=\"yes\" selected=\"selected\">yes</option>\n";
414 echo " <option value=\"no\">no</option>\n";
417 if($changed_openforgames) echo "changed";
418 echo " </td></tr>\n";
420 echo " <tr><td>Card set: </td><td>\n";
421 echo " <select id=\"cards\" name=\"cards\" size=\"1\">\n";
422 if($PREF['cardset']=="altenburg")
424 echo " <option value=\"altenburg\" selected=\"selected\">German cards</option>\n";
425 echo " <option value=\"english\">English cards</option>\n";
429 echo " <option value=\"altenburg\">German cards</option>\n";
430 echo " <option value=\"english\" selected=\"selected\">English cards</option>\n";
433 if($changed_cards) echo "changed";
434 echo " </td></tr>\n";
436 echo " </fieldset>\n";
437 echo " <fieldset>\n";
438 echo " <legend>Personal</legend>\n";
440 echo " <tr><td>Email: </td><td> $email </td></tr>\n";
441 echo " <tr><td>Timezone: </td><td>\n";
442 output_select_timezone("timezone",$timezone);
443 if($changed_timezone) echo "changed";
446 echo " <tr><td>Password(old): </td><td>",
447 "<input type=\"password\" id=\"password0\" name=\"password0\" size=\"20\" maxlength=\"30\" />";
448 switch($changed_password)
451 echo "The new passwords is not long enough (you need at least 4 characters).";
454 echo "The new passwords don't match.";
457 echo "The old password is not correct.";
463 echo " </td></tr>\n";
464 echo " <tr><td>Password(new): </td><td>",
465 "<input type=\"password\" id=\"password1\" name=\"password1\" size=\"20\" maxlength=\"30\" />",
467 echo " <tr><td>Password(new, retype): </td><td>",
468 "<input type=\"password\" id=\"password2\" name=\"password2\" size=\"20\" maxlength=\"30\" />",
471 echo " </fieldset>\n";
472 echo " <fieldset>\n";
473 echo " <legend>OpenID</legend>\n";
476 $openids = DB_GetOpenIDsByUser($myid);
480 echo " <table class=\"openid\">\n";
481 echo " <thead><tr><th>Delete?</th><th>OpenId</th></tr></thead>\n";
483 foreach ($openids as $ids)
486 echo " <tr><td><input type=\"checkbox\" name=\"delete-openid-$id\" /></td><td>",$id, "</td></tr>\n";
492 echo " add OpenID: ",
493 "<input type=\"text\" id=\"openid_url\" name=\"openid_url\" size=\"20\" maxlength=\"50\" />";
495 echo " Deleted some OpenIDs! <br />\n";
496 echo " </fieldset>\n";
497 echo " <fieldset><legend>Submit</legend><input type=\"submit\" name=\"passwd\" value=\"set\" /></fieldset>\n";
499 echo " <p>E-DoKo uses <a href=\"http://www.gravatar.org\">gravatars</a> as icons. I</p>";