2 /* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 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 /* test id and password, should really be done in one step */
28 if(isset($_SESSION['name']))
30 $name = $_SESSION['name'];
31 $email = DB_get_email('name',$name);
32 $password = DB_get_passwd_by_name($name);
37 /* user has forgotten his password */
40 /* check if player is in the database */
43 $myid = DB_get_userid('email',$email);
49 /* check how many entries in recovery table */
50 $number = DB_get_number_of_passwords_recovery($myid);
52 /* if less than N recent ones, add a new one and send out email */
55 echo _('Ok, I will send you a new password.').' <br />';
57 echo sprintf(_("N.B. You tried this already %s times during the last day and it will only work".
58 " 5 times during a day."),$number)."<br />\n";
59 echo _('The new password will be valid for one day, make sure you reset it to something else.').'<br />';
60 echo sprintf(_('Back to the <a href="%s">main page</a>.'),$INDEX);
62 /* create temporary password, use the fist 8 letters of a md5 hash */
63 $TIME = (string) time(); /* to avoid collisions */
64 $hash = md5('Anewpassword'.$email.$TIME);
65 $newpw = substr($hash,1,8);
67 $message = sprintf( _("Someone (hopefully you) requested a new password.\n".
68 "You can use this email and the following password:\n".
70 "to log into the server. The new password is valid for 24h, so make\n".
71 "sure you reset your password to something new. Your old password will\n".
72 "also still be valid until you set a new one.\n"), $newpw);
73 mymail($myid,0, GAME_RECOVERY, $message);
75 /* we save these in the database */
76 DB_set_recovery_password($myid,md5($newpw));
80 /* make it so that people (or a robot) can request thousands of passwords within a short time
81 * and spam a user this way */
82 echo _('Sorry you already tried 5 times during the last 24h.<br />'.
83 'You need to use one of those passwords or wait to get a new one.').'<br />';
84 echo sprintf(_('Back to the <a href="%s">main page</a>.'),$INDEX);
88 {/* can't find user id in the database */
92 echo _('You need to give me an email address!')." <br />".
93 sprintf(_('Please try <a href="%s">again</a>.'),$INDEX);
94 else /* default error message */
95 echo _("Couldn't find a player with this email!")."<br />".
96 sprintf(_('Please contact %s, if you think this is a mistake '.
97 'or else try <a href="%s">again</a>.'),$ADMIN_NAME, $INDEX );
101 { /* normal user page */
103 /* verify password and email */
105 if(isset($email, $password))
107 $myid = DB_get_userid('email-password',$email,$password);
116 /* user information is ok */
117 $myname = DB_get_name('email',$email);
118 $_SESSION['name'] = $myname;
120 $PREF = DB_get_PREF($myid);
121 /* set language chosen in preferences, will become active on the next reload (see index.php)*/
122 $_SESSION['language'] = $PREF['language'];
123 set_language($PREF['language']);
125 DB_update_user_timestamp($myid);
127 display_user_menu($myid);
129 /* display all games the user has played */
130 echo '<div class="user">';
132 if($myvacation = check_vacation($myid))
134 $vac_start = $myvacation[0];
135 $vac_stop = $myvacation[1];
136 $vac_comment = $myvacation[2];
137 echo '<p class="vacation">'._("Enjoy your vacation (don't forgot to change your settings once you're back).")." ".
138 _("Between $vac_start and $vac_stop other users will see the following message: $vac_comment.")."</p>\n";
141 echo '<h4>'._('These are your games').":</h4>\n";
144 echo ' <span class="gamestatuspre"> </span> '._('pre-game phase');
145 echo ' <span class="gamestatusplay"> </span> '._('game in progess');
146 echo ' <span class="gamestatusover "><a>N</a> </span> '._('game over (N people played this hand)').' <br />';
147 echo ' '._("Reminder: canceling a game can't be reversed!");
152 $result = DB_query("SELECT Hand.hash,Hand.game_id,G.mod_date,G.player,G.status, ".
153 " (SELECT count(H.randomnumbers) FROM Game H WHERE H.randomnumbers=G.randomnumbers) AS count, ".
156 " LEFT JOIN Game G ON G.id=Hand.game_id".
157 " WHERE user_id='$myid'".
158 " ORDER BY G.session,G.create_date" );
160 /* sort into active and passive sessions */
161 $count = 0; /* count number of games to check for beginner status */
165 $output_inactive = "";
171 /* get next element */
172 $r = DB_fetch_array($result);
178 /* need to run the while loop one more time when we run out of elements in the database */
188 if( $r[6]==$session )
190 /* same session, update information */
194 $gamemoddate = $r[2];
197 $gamefrequence = $r[5];
200 $sessionoutput .= $gameoutput;
201 $gameoutput = " <span class=\"gamestatusover \"><a href=\"".$INDEX."?action=game&me=".$myhash."\">"
202 .$gamefrequence."</a></span>\n";
207 /* output old session if available */
210 /* is session active? */
211 if($gamestatus == 'pre' || $gamestatus== 'play' || time()-strtotime($gamemoddate) < 60*60*24*5 )
213 $output_active .= "<li> ";
214 if($gamestatus == 'pre')
215 $output_active .= '<span class="gamestatuspre gameid">';
216 else if($gamestatus == 'play')
217 $output_active .= '<span class="gamestatusplay gameid">';
219 $output_active .= '<span class="gamestatusover gameid">';
220 $output_active .= "<a href=\"$INDEX?action=game&me=$myhash\">".
221 DB_format_gameid($gameid).'</a></span> ';
225 /* who's turn is it? */
226 if( $gamestatus == 'pre' || $gamestatus == 'play')
228 $output_active .= '<span class="turn">';
229 if($userid==$myid || !$userid)
230 $output_active .= ' <strong>'._('your turn')."</strong>\n";
233 $name = DB_get_name('userid',$userid);
235 /* check vacaction status of this user */
236 if($vacation=check_vacation($userid))
238 $stop = substr($vacation[1],0,10);
239 $title = _('begin:').substr($vacation[0],0,10).' '._('end:').$vacation[1].' '.$vacation[2];
240 $output_active .= " <span class=\"vacation\" title=\"$title\">".
241 sprintf(_("%s's turn"),$name).' '._("(on vacation until $stop)")."</span>\n";
244 $output_active .= sprintf(_("%s's turn"),$name)."\n";
246 /* check if we need to send out a reminder */
247 if(DB_get_reminder($userid,$gameid)==0)
248 if(time()-strtotime($gamemoddate) > 60*60*24*7)
249 $output_active .= "<a href=\"$INDEX?action=reminder&me=".$myhash."\">"._('Send a reminder?').'</a> ';
252 $output_active .= '</span>';
254 if(time()-strtotime($gamemoddate) > 60*60*24*30)
255 $output_active .= "<a href=\"$INDEX?action=cancel&me=".$myhash."\">"._('Cancel?').'</a> ';
260 $output_active .= ' <span class="gamesshowsession"><a href="#">'._('show old').'</a></span>'.
261 ' <span class="gameshidesession"><a href="#">'._('hide old').'</a></span><br />'."\n";
262 $output_active .= ' <span class="gamessession">'.$sessionoutput.'</span>';
265 $output_active .= "</li>\n";
270 /* session is not active anymore */
271 $output_inactive .= "<li> $session:" ;
272 $output_inactive .= $sessionoutput.$gameoutput ;
273 $output_inactive .= "</li>\n";
276 /* reset all session variables */
283 /* save game information */
287 $gamemoddate = $r[2];
290 $gamefrequence = $r[5];
294 $sessionoutput .= $gameoutput;
295 $gameoutput = " <span class=\"gamestatusover \"><a href=\"".$INDEX."?action=game&me=".$myhash."\">"
296 .$gamefrequence."</a></span>\n";
302 echo ' <li><span class="gameshowall"><a href="#">'._('show all').'</a></span> <span class="gamehideall"><a href="#">'._('hide all')."</a></span></li>\n";
304 echo ' <li><span class="gamesshowsession"><a href="#">'._('show inactive').'</a></span><span class="gameshidesession"><a href="#">'._('hide inactive').'</a></span><ul class="gamessession">'."$output_inactive </ul></li>";
307 /* give a hint for new players */
309 echo '<p class="newbiehint">'._('You can start new games using the link in the top right corner!')."</p>\n";
311 /* display last 5 users that have signed up to e-DoKo */
312 $names = DB_get_names_of_new_logins(5);
313 echo '<h4>'._('New Players').":</h4>\n<p>\n";
314 echo implode(", ",$names).",...\n";
317 /* display last 5 users that logged on */
318 echo '<h4>'._('Players last logged in').":</h4>\n<p>\n";
320 $names = DB_get_names_of_last_logins(7);
321 $emails = DB_get_emails_of_last_logins(7);
324 echo '<img class="gravatar" title="'.$names[$i].
325 '" src="http://www.gravatar.com/avatar/'.
326 md5(strtolower(trim($emails[$i])))."?d=identicon\" />\n";
334 echo '<div class="message">'."\n";
335 echo sprintf(_("Sorry email and password don't match. Please <a href=\"%s\">try again</a>."),$INDEX);