2 /* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
4 * This file is part of e-DoKo.
6 * e-DoKo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * e-DoKo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with e-DoKo. If not, see <http://www.gnu.org/licenses/>.
21 /* make sure that we are not called from outside the scripts,
22 * use a variable defined in config.php to check this
27 include_once('openid.php');
29 $name = $_SESSION["name"];
30 $email = DB_get_email('name',$name);
31 $myid = DB_get_userid('email',$email);
35 /* track what got changed */
37 $changed_password = 0;
39 $changed_timezone = 0;
40 $changed_autosetup = 0;
42 $changed_openforgames = 0;
43 $changed_vacation = 0;
47 display_user_menu($myid);
50 $PREF = DB_get_PREF($myid);
51 $timezone = DB_get_user_timezone($myid);
53 DB_update_user_timestamp($myid);
55 /* does the user want to change some preferences?
56 * update the database and track changes with a variable, so that
57 * we can later highlight the changed value
60 /* check for deleted openids */
61 foreach($_REQUEST as $key=>$value)
63 if(strstr($key,"delete-openid-"))
65 /* found and openid to delete */
66 $DelOpenID = substr(str_replace("_",".",$key),14);
67 DB_DetachOpenID($DelOpenID, $myid);
73 if(myisset('vacation_start','vacation_stop','vacation_comment') &&
74 ($_REQUEST['vacation_start']!='' || $_REQUEST['vacation_stop']!='')
77 $vacation_start = $_REQUEST['vacation_start'].' 00:00:00';
78 $vacation_stop = $_REQUEST['vacation_stop'].' 23:59:59';
79 $vacation_comment = $_REQUEST['vacation_comment'];
81 /* check if everything is valid */
82 if(!strtotime($vacation_start))
83 $changed_vacation = -1;
84 if(!strtotime($vacation_stop))
85 $changed_vacation = -1;
87 /* test if we should delete the entry */
88 if($vacation_start == '- 00:00:00')
90 $result = DB_query("DELETE FROM User_Prefs".
91 " WHERE user_id='$myid' AND pref_key='vacation start'" );
92 $result = DB_query("DELETE FROM User_Prefs".
93 " WHERE user_id='$myid' AND pref_key='vacation stop'" );
94 $result = DB_query("DELETE FROM User_Prefs".
95 " WHERE user_id='$myid' AND pref_key='vacation comment'" );
96 $changed_vacation = 1;
98 /* change in database if format is ok */
99 else if($changed_vacation>=0)
101 /* only change if different from current value */
102 if($vacation_start!=$PREF['vacation_start'])
104 $result = DB_query("SELECT * from User_Prefs".
105 " WHERE user_id='$myid' AND pref_key='vacation start'" );
106 if( DB_fetch_array($result))
107 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($vacation_start).
108 " WHERE user_id='$myid' AND pref_key='vacation start'" );
110 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','vacation start',".
111 DB_quote_smart($vacation_start).")");
113 $changed_vacation = 1;
116 /* same for the stop date */
117 if($vacation_stop!=$PREF['vacation_stop'])
119 $result = DB_query("SELECT * from User_Prefs".
120 " WHERE user_id='$myid' AND pref_key='vacation stop'" );
121 if( DB_fetch_array($result))
122 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($vacation_stop).
123 " WHERE user_id='$myid' AND pref_key='vacation stop'" );
125 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','vacation stop',".
126 DB_quote_smart($vacation_stop).")");
128 $changed_vacation = 1;
131 /* does the user want to add a comment? */
132 if($vacation_comment!=$PREF['vacation_comment'])
134 $result = DB_query("SELECT * from User_Prefs".
135 " WHERE user_id='$myid' AND pref_key='vacation comment'" );
136 if( DB_fetch_array($result))
137 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($vacation_comment).
138 " WHERE user_id='$myid' AND pref_key='vacation comment'" );
140 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','vacation comment',".
141 DB_quote_smart($vacation_comment).")");
143 $changed_vacation = 1;
148 if(myisset("timezone"))
150 $newtimezone = $_REQUEST['timezone'];
151 if($newtimezone != $timezone)
153 DB_query("UPDATE User SET timezone=".DB_quote_smart($newtimezone).
154 " WHERE id=".DB_quote_smart($myid));
155 $changed_timezone = 1;
161 $cards=$_REQUEST['cards'];
162 if($cards != $PREF['cardset'])
164 /* check if we already have an entry for the user, if so change it, if not create new one */
165 $result = DB_query("SELECT * from User_Prefs".
166 " WHERE user_id='$myid' AND pref_key='cardset'" );
167 if( DB_fetch_array($result))
168 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($cards).
169 " WHERE user_id='$myid' AND pref_key='cardset'" );
171 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','cardset',".
172 DB_quote_smart($cards).")");
177 if(myisset("notify"))
179 $notify=$_REQUEST['notify'];
180 if($notify != $PREF['email'])
182 /* check if we already have an entry for the user, if so change it, if not create new one */
183 $result = DB_query("SELECT * from User_Prefs".
184 " WHERE user_id='$myid' AND pref_key='email'" );
185 if( DB_fetch_array($result))
186 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($notify).
187 " WHERE user_id='$myid' AND pref_key='email'" );
189 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','email',".
190 DB_quote_smart($notify).")");
195 if(myisset("digest"))
197 $digest=$_REQUEST['digest'];
198 if($digest != $PREF['digest'])
200 /* check if we already have an entry for the user, if so change it, if not create new one */
201 $result = DB_query("SELECT * from User_Prefs".
202 " WHERE user_id='$myid' AND pref_key='digest'" );
203 if( DB_fetch_array($result))
204 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($digest).
205 " WHERE user_id='$myid' AND pref_key='digest'" );
207 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','digest',".
208 DB_quote_smart($digest).")");
213 if(myisset("autosetup"))
215 $autosetup = $_REQUEST['autosetup'];
216 if($autosetup != $PREF['autosetup'])
218 /* check if we already have an entry for the user, if so change it, if not create new one */
219 $result = DB_query("SELECT * from User_Prefs".
220 " WHERE user_id='$myid' AND pref_key='autosetup'" );
221 if( DB_fetch_array($result))
222 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($autosetup).
223 " WHERE user_id='$myid' AND pref_key='autosetup'" );
225 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','autosetup',".
226 DB_quote_smart($autosetup).")");
227 $changed_autosetup=1;
231 if(myisset("sorting"))
233 $sorting = $_REQUEST['sorting'];
234 if($sorting != $PREF['sorting'])
236 /* check if we already have an entry for the user, if so change it, if not create new one */
237 $result = DB_query("SELECT * from User_Prefs".
238 " WHERE user_id='$myid' AND pref_key='sorting'" );
239 if( DB_fetch_array($result))
240 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($sorting).
241 " WHERE user_id='$myid' AND pref_key='sorting'" );
243 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','sorting',".
244 DB_quote_smart($sorting).")");
249 if(myisset("open_for_games"))
251 $openforgames = $_REQUEST['open_for_games'];
252 if($openforgames != $PREF['open_for_games'])
254 /* check if we already have an entry for the user, if so change it, if not create new one */
255 $result = DB_query("SELECT * from User_Prefs".
256 " WHERE user_id='$myid' AND pref_key='open for games'" );
257 if( DB_fetch_array($result))
258 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($openforgames).
259 " WHERE user_id='$myid' AND pref_key='open for games'" );
261 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','open for games',".
262 DB_quote_smart($openforgames).")");
263 $changed_openforgames=1;
268 if(myisset("password0","password1","password2") && $_REQUEST["password0"]!="" && $_REQUEST["password0"]!= $_REQUEST["password1"])
270 $changed_password = 1;
272 /* check if old password matches */
273 $oldpasswd = md5($_REQUEST["password0"]);
274 $password = DB_get_passwd_by_userid($myid);
275 if(!( ($password == $oldpasswd) || DB_check_recovery_passwords($oldpasswd,$email) ))
276 $changed_password = -1;
278 /* check if new password has been typed in correctly */
279 if($_REQUEST["password1"] != $_REQUEST["password2"] )
280 $changed_password = -2;
282 /* check if new password is long enough */
283 if(strlen($_REQUEST["password1"])<4)
284 $changed_password = -3;
286 if($changed_password==1)
288 DB_query("UPDATE User SET password='".md5($_REQUEST["password1"]).
289 "' WHERE id=".DB_quote_smart($myid));
291 /* error output below */
294 if(myisset("openid_url") && $_REQUEST['openid_url']!='')
296 $openid_url = OpenIDUrlEncode($_REQUEST['openid_url']);
297 DB_AttachOpenID($openid_url, $myid);
300 /* get infos again in case they have changed */
301 $PREF = DB_get_PREF($myid);
302 $timezone = DB_get_user_timezone($myid);
308 echo "<div class=\"user\">\n";
309 echo " <form action=\"index.php?action=prefs\" method=\"post\">\n";
310 echo " <h2>Your settings are</h2>\n";
311 echo " <fieldset>\n";
312 echo " <legend>Game-related</legend>\n";
315 echo " <tr><td>Vacation: </td>\n";
316 if($PREF['vacation_start'])
317 $value = substr($PREF['vacation_start'],0,10);
320 echo " <td>start:<input type=\"text\" id=\"vacation_start\" name=\"vacation_start\" size=\"10\" maxlength=\"10\" value=\"$value\" /></td>\n";
321 if($PREF['vacation_stop'])
322 $value = substr($PREF['vacation_stop'],0,10);
325 echo " <td>stop:<input type=\"text\" id=\"vacation_stop\" name=\"vacation_stop\" size=\"10\" maxlength=\"10\" value=\"$value\" /></td>\n";
326 if($PREF['vacation_comment'])
327 $value = $PREF['vacation_comment'];
330 echo " <td>comment:<input type=\"text\" id=\"vacation_comment\" name=\"vacation_comment\" size=\"10\" maxlength=\"50\" value=\"$value\" />";
331 if($changed_vacation == 1) echo "changed";
332 if($changed_vacation == -1) echo "wrong date format";
334 echo "<tr><td></td><td>use YYYY-MM-DD</td><td>use '-' in start field to unset vacation</td></tr>\n";
335 echo " <tr><td>Notification: </td><td>\n";
336 echo " <select id=\"notify\" name=\"notify\" size=\"1\">\n";
337 if($PREF['email']=="emailaddict")
339 echo " <option value=\"emailaddict\" selected=\"selected\">less emails</option>\n";
340 echo " <option value=\"emailnonaddict\">lots of emails</option>\n";
344 echo " <option value=\"emailaddict\">less email</option>\n";
345 echo " <option value=\"emailnonaddict\" selected=\"selected\">lots of email</option>\n";
348 if($changed_notify) echo "changed";
349 echo " </td></tr>\n";
351 echo " <tr><td>Digest: </td><td>\n";
352 echo " <select id=\"digest\" name=\"digest\" size=\"1\">\n";
354 $selected = "selected=\"selected\"";
355 echo " <option value=\"digest-off\"";
356 if($PREF['digest']=="digest-off") echo $selected;
357 echo ">digest off</option>\n";
359 echo " <option value=\"digest-1h\" ";
360 if($PREF['digest']=="digest-1h") echo $selected;
361 echo ">every hour</option>\n";
363 echo " <option value=\"digest-2h\" ";
364 if($PREF['digest']=="digest-2h") echo $selected;
365 echo ">every 2h</option>\n";
367 echo " <option value=\"digest-3h\" ";
368 if($PREF['digest']=="digest-3h") echo $selected;
369 echo ">every 3h</option>\n";
371 echo " <option value=\"digest-4h\" ";
372 if($PREF['digest']=="digest-4h") echo $selected;
373 echo ">every 4h</option>\n";
375 echo " <option value=\"digest-6h\" ";
376 if($PREF['digest']=="digest-6h") echo $selected;
377 echo ">every 6h</option>\n";
379 echo " <option value=\"digest-12h\"";
380 if($PREF['digest']=="digest-12h") echo $selected;
381 echo ">every 12h</option>\n";
383 echo " <option value=\"digest-24h\"";
384 if($PREF['digest']=="digest-24h") echo $selected;
385 echo ">every 24h</option>\n";
388 if($changed_digest) echo "changed";
389 echo " </td></tr>\n";
392 echo " <tr><td>Autosetup: </td><td>\n";
393 echo " <select id=\"autosetup\" name=\"autosetup\" size=\"1\">\n";
394 if($PREF['autosetup']=="yes")
396 echo " <option value=\"yes\" selected=\"selected\">accept every game</option>\n";
397 echo " <option value=\"no\">ask for games</option>\n";
401 echo " <option value=\"yes\">accept every game</option>\n";
402 echo " <option value=\"no\" selected=\"selected\">ask for games</option>\n";
405 if($changed_autosetup) echo "changed";
406 echo " </td></tr>\n";
407 echo " <tr><td>Sorting: </td><td>\n";
409 echo " <select id=\"sorting\" name=\"sorting\" size=\"1\">\n";
410 if($PREF['sorting']=="high-low")
412 echo " <option value=\"high-low\" selected=\"selected\">high to low</option>\n";
413 echo " <option value=\"low-high\">low to high</option>\n";
417 echo " <option value=\"high-low\">high to low</option>\n";
418 echo " <option value=\"low-high\" selected=\"selected\">low to high</option>\n";
421 if($changed_sorting) echo "changed";
422 echo " </td></tr>\n";
423 echo " <tr><td>Open for new games: </td><td>\n";
424 echo " <select id=\"open_for_games\" name=\"open_for_games\" size=\"1\">\n";
425 if($PREF['open_for_games']=="no")
427 echo " <option value=\"yes\">yes</option>\n";
428 echo " <option value=\"no\" selected=\"selected\">no</option>\n";
432 echo " <option value=\"yes\" selected=\"selected\">yes</option>\n";
433 echo " <option value=\"no\">no</option>\n";
436 if($changed_openforgames) echo "changed";
437 echo " </td></tr>\n";
439 echo " <tr><td>Card set: </td><td>\n";
440 echo " <select id=\"cards\" name=\"cards\" size=\"1\">\n";
441 if($PREF['cardset']=="altenburg")
443 echo " <option value=\"altenburg\" selected=\"selected\">German cards</option>\n";
444 echo " <option value=\"english\">English cards</option>\n";
448 echo " <option value=\"altenburg\">German cards</option>\n";
449 echo " <option value=\"english\" selected=\"selected\">English cards</option>\n";
452 if($changed_cards) echo "changed";
453 echo " </td></tr>\n";
455 echo " </fieldset>\n";
456 echo " <fieldset>\n";
457 echo " <legend>Personal</legend>\n";
459 echo " <tr><td>Email: </td><td> $email </td></tr>\n";
460 echo " <tr><td>Timezone: </td><td>\n";
461 output_select_timezone("timezone",$timezone);
462 if($changed_timezone) echo "changed";
465 echo " <tr><td>Password(old): </td><td>",
466 "<input type=\"password\" id=\"password0\" name=\"password0\" size=\"20\" maxlength=\"30\" />";
467 switch($changed_password)
470 echo "The new passwords is not long enough (you need at least 4 characters).";
473 echo "The new passwords don't match.";
476 echo "The old password is not correct.";
482 echo " </td></tr>\n";
483 echo " <tr><td>Password(new): </td><td>",
484 "<input type=\"password\" id=\"password1\" name=\"password1\" size=\"20\" maxlength=\"30\" />",
486 echo " <tr><td>Password(new, retype): </td><td>",
487 "<input type=\"password\" id=\"password2\" name=\"password2\" size=\"20\" maxlength=\"30\" />",
490 echo " </fieldset>\n";
491 echo " <fieldset>\n";
492 echo " <legend>OpenID</legend>\n";
495 $openids = DB_GetOpenIDsByUser($myid);
499 echo " <table class=\"openid\">\n";
500 echo " <thead><tr><th>Delete?</th><th>OpenId</th></tr></thead>\n";
502 foreach ($openids as $ids)
505 echo " <tr><td><input type=\"checkbox\" name=\"delete-openid-$id\" /></td><td>",$id, "</td></tr>\n";
511 echo " add OpenID: ",
512 "<input type=\"text\" id=\"openid_url\" name=\"openid_url\" size=\"20\" maxlength=\"50\" />";
514 echo " Deleted some OpenIDs! <br />\n";
515 echo " </fieldset>\n";
516 echo " <fieldset><legend>Submit</legend><input type=\"submit\" name=\"passwd\" value=\"set\" /></fieldset>\n";
518 echo " <p>E-DoKo uses <a href=\"http://www.gravatar.org\">gravatars</a> as icons. I</p>";