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 display_user_menu($myid);
24 $PREF = DB_get_PREF($myid);
25 $timezone = DB_get_user_timezone($myid);
27 DB_update_user_timestamp($myid);
29 /* does the user want to change some preferences? */
30 if(myisset("timezone"))
32 $newtimezone=$_REQUEST['timezone'];
33 if($newtimezone != $timezone)
35 DB_query("UPDATE User SET timezone=".DB_quote_smart($newtimezone).
36 " WHERE id=".DB_quote_smart($myid));
37 $changed_timezone = 1;
43 $cards=$_REQUEST['cards'];
44 if($cards != $PREF['cardset'])
46 /* check if we already have an entry for the user, if so change it, if not create new one */
47 $result = DB_query("SELECT * from User_Prefs".
48 " WHERE user_id='$myid' AND pref_key='cardset'" );
49 if( DB_fetch_array($result))
50 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($cards).
51 " WHERE user_id='$myid' AND pref_key='cardset'" );
53 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','cardset',".
54 DB_quote_smart($cards).")");
61 $notify=$_REQUEST['notify'];
62 if($notify != $PREF['email'])
64 /* check if we already have an entry for the user, if so change it, if not create new one */
65 $result = DB_query("SELECT * from User_Prefs".
66 " WHERE user_id='$myid' AND pref_key='email'" );
67 if( DB_fetch_array($result))
68 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($notify).
69 " WHERE user_id='$myid' AND pref_key='email'" );
71 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','email',".
72 DB_quote_smart($notify).")");
77 if(myisset("autosetup"))
79 $autosetup = $_REQUEST['autosetup'];
80 if($autosetup != $PREF['autosetup'])
82 /* check if we already have an entry for the user, if so change it, if not create new one */
83 $result = DB_query("SELECT * from User_Prefs".
84 " WHERE user_id='$myid' AND pref_key='autosetup'" );
85 if( DB_fetch_array($result))
86 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($autosetup).
87 " WHERE user_id='$myid' AND pref_key='autosetup'" );
89 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','autosetup',".
90 DB_quote_smart($autosetup).")");
95 if(myisset("sorting"))
97 $sorting = $_REQUEST['sorting'];
98 if($sorting != $PREF['sorting'])
100 /* check if we already have an entry for the user, if so change it, if not create new one */
101 $result = DB_query("SELECT * from User_Prefs".
102 " WHERE user_id='$myid' AND pref_key='sorting'" );
103 if( DB_fetch_array($result))
104 $result = DB_query("UPDATE User_Prefs SET value=".DB_quote_smart($sorting).
105 " WHERE user_id='$myid' AND pref_key='sorting'" );
107 $result = DB_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','sorting',".
108 DB_quote_smart($sorting).")");
114 if(myisset("password0") && $_REQUEST["password0"]!="" )
116 $changed_password = 1;
118 /* check if old password matches */
119 $oldpasswd = md5($_REQUEST["password0"]);
120 $password = DB_get_passwd_by_userid($myid);
121 if(!( ($password == $oldpasswd) || DB_check_recovery_passwords($oldpasswd,$email) ))
122 $changed_password = -1;
124 /* check if new password has been typed in correctly */
125 if($_REQUEST["password1"] != $_REQUEST["password2"] )
126 $changed_password = -2;
128 /* check if new password is long enough */
129 if(strlen($_REQUEST["password1"])<4)
130 $changed_password = -3;
132 if($changed_password==1)
134 DB_query("UPDATE User SET password='".md5($_REQUEST["password1"]).
135 "' WHERE id=".DB_quote_smart($myid));
137 /* error output below */
140 /* get infos again in case they have changed */
141 $PREF = DB_get_PREF($myid);
142 $timezone = DB_get_user_timezone($myid);
144 /* output settings */
146 echo "<div class=\"user\">\n";
147 echo " <form action=\"index.php?action=prefs\" method=\"post\">\n";
148 echo " <h2>Your settings are</h2>\n";
150 echo " <tr><td>Email: </td><td> $email </td></tr>\n";
151 echo " <tr><td>Timezone: </td><td>";
152 output_select_timezone("timezone",$timezone);
153 if($changed_timezone) echo "changed";
155 echo " <tr><td>Notification: </td><td>";
157 echo " <select id=\"notify\" name=\"notify\" size=\"1\">\n";
158 if($PREF['email']=="emailaddict")
160 echo " <option value=\"emailaddict\" selected=\"selected\">less emails</option>\n";
161 echo " <option value=\"emailnonaddict\">lots of emails</option>\n";
165 echo " <option value=\"emailaddict\">less email</option>\n";
166 echo " <option value=\"emailnonaddict\" selected=\"selected\">lots of email</option>\n";
169 if($changed_notify) echo "changed";
170 echo " </td></tr>\n";
171 echo " <tr><td>Autosetup: </td><td>";
173 echo " <select id=\"autosetup\" name=\"autosetup\" size=\"1\">\n";
174 if($PREF['autosetup']=="yes")
176 echo " <option value=\"yes\" selected=\"selected\">accept every game</option>\n";
177 echo " <option value=\"no\">ask for games</option>\n";
181 echo " <option value=\"yes\">accept every game</option>\n";
182 echo " <option value=\"no\" selected=\"selected\">ask for games</option>\n";
185 if($changed_autosetup) echo "changed";
186 echo " </td></tr>\n";
187 echo " <tr><td>Sorting: </td><td>";
189 echo " <select id=\"sorting\" name=\"sorting\" size=\"1\">\n";
190 if($PREF['sorting']=="high-low")
192 echo " <option value=\"high-low\" selected=\"selected\">high to low</option>\n";
193 echo " <option value=\"low-high\">low to high</option>\n";
197 echo " <option value=\"high-low\">high to low</option>\n";
198 echo " <option value=\"low-high\" selected=\"selected\">low to high</option>\n";
201 if($changed_sorting) echo "changed";
202 echo " </td></tr>\n";
203 echo " <tr><td>Card set: </td><td>";
205 echo " <select id=\"cards\" name=\"cards\" size=\"1\">\n";
206 if($PREF['cardset']=="altenburg")
208 echo " <option value=\"altenburg\" selected=\"selected\">German cards</option>\n";
209 echo " <option value=\"english\">English cards</option>\n";
213 echo " <option value=\"altenburg\">German cards</option>\n";
214 echo " <option value=\"english\" selected=\"selected\">English cards</option>\n";
217 if($changed_cards) echo "changed";
218 echo " </td></tr>\n";
219 echo " <tr><td>Password(old): </td><td>",
220 "<input type=\"password\" id=\"password0\" name=\"password0\" size=\"20\" maxlength=\"30\" />";
221 switch($changed_password)
224 echo "The new passwords is not long enough (you need at least 4 characters).";
227 echo "The new passwords don't match.";
230 echo "The old password is not correct.";
236 echo " </td></tr>\n";
237 echo " <tr><td>Password(new): </td><td>",
238 "<input type=\"password\" id=\"password1\" name=\"password1\" size=\"20\" maxlength=\"30\" />",
240 echo " <tr><td>Password(new, retype): </td><td>",
241 "<input type=\"password\" id=\"password2\" name=\"password2\" size=\"20\" maxlength=\"30\" />",
243 echo " <tr><td><input type=\"submit\" name=\"passwd\" value=\"set\" /></td>",