2 error_reporting(E_ALL);
7 include_once("config.php");
8 include_once("output.php"); /* html output only */
9 include_once("db.php"); /* database only */
10 include_once("functions.php"); /* the rest */
12 /* check if some variables are set in the config file, else set defaults */
13 if(!isset($EmailName))
19 echo "Working on the database...please check back in a few mintues";
27 /* check if we want to start a new game */
30 $names = DB_get_all_names();
31 output_form_for_new_game($names);
33 /*check if everything is ready to set up a new game */
34 else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD" ))
36 $PlayerA = $_REQUEST["PlayerA"];
37 $PlayerB = $_REQUEST["PlayerB"];
38 $PlayerC = $_REQUEST["PlayerC"];
39 $PlayerD = $_REQUEST["PlayerD"];
41 $EmailA = DB_get_email_by_name($PlayerA);
42 $EmailB = DB_get_email_by_name($PlayerB);
43 $EmailC = DB_get_email_by_name($PlayerC);
44 $EmailD = DB_get_email_by_name($PlayerD);
46 if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
48 echo "couldn't find one of the names, please start a new game";
52 $useridA = DB_get_userid_by_name($PlayerA);
53 $useridB = DB_get_userid_by_name($PlayerB);
54 $useridC = DB_get_userid_by_name($PlayerC);
55 $useridD = DB_get_userid_by_name($PlayerD);
57 /* create random numbers */
58 $randomNR = create_array_of_random_numbers();
59 $randomNRstring = join(":",$randomNR);
63 if(myisset("followup") )
65 $followup= $_REQUEST["followup"];
66 $session = DB_get_session_by_gameid($followup);
68 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre','$session' ,NULL)");
72 $max = DB_get_max_session();
74 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre','$max' ,NULL)");
75 mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
79 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre', NULL ,NULL)");
80 $game_id = mysql_insert_id();
83 $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA);
84 $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB);
85 $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC);
86 $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD);
89 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
90 ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,'false','false',NULL)");
91 $hand_idA = mysql_insert_id();
92 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
93 ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,'false','false',NULL)");
94 $hand_idB = mysql_insert_id();
95 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
96 ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,'false','false',NULL)");
97 $hand_idC = mysql_insert_id();
98 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
99 ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,'false','false',NULL)");
100 $hand_idD = mysql_insert_id();
104 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
105 for($i=12;$i<24;$i++)
106 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
107 for($i=24;$i<36;$i++)
108 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
109 for($i=36;$i<48;$i++)
110 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
112 /* send out email, TODO: check for error with email */
114 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
115 "Place comments and bug reports here:\n".
116 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
117 "The whole round would consist of the following players:\n".
122 "If you want to join this game, please follow this link:\n\n".
125 mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
126 mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
127 mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
128 mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
130 echo "You started a new game. The emails have been sent out!";
131 } /* end set up a new game */
132 else if(myisset("cancle","me"))
134 $me = $_REQUEST["me"];
136 /* test for valid ID */
137 $myid = DB_get_userid_by_hash($me);
140 echo "Can't find you in the database, please check the url.<br />\n";
141 echo "perhaps the game has been cancled, check by login in <a href=\"$host\">here</a>.";
145 DB_update_user_timestamp($myid);
147 /* get some information from the DB */
148 $gameid = DB_get_gameid_by_hash($me);
149 $myname = DB_get_name_by_hash($me);
150 $mystatus = DB_get_status_by_hash($me);
151 $mypos = DB_get_pos_by_hash($me);
153 /* check if game really is old enough */
154 $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " );
155 $r = mysql_fetch_array($result,MYSQL_NUM);
156 if(time()-strtotime($r[0]) > 60*60*24*30)
158 $message = "Hello, \n\n".
159 "Game $gameid has been cancled since nothing happend for a while and $myname requested it.\n";
161 $userids = DB_get_all_userid_by_gameid($gameid);
162 foreach($userids as $user)
164 $To = DB_get_email_by_userid($user);
165 mymail($To,$EmailName."game cancled (timed out)",$message);
168 /* delete everything from the dB */
171 echo "<p style=\"background-color:red\";>Game $gameid has been cancled.<br /><br /></p>";
174 echo "<p>You need to wait longer before you can cancle a game...</p>\n";
176 else if(myisset("me"))
178 /* handle request from one specific player,
179 ` * the hash is set on a per game base
182 $me = $_REQUEST["me"];
184 /* test for valid ID */
185 $myid = DB_get_userid_by_hash($me);
188 echo "Can't find you in the database, please check the url.<br />\n";
189 echo "perhaps the game has been cancled, check by login in <a href=\"$host\">here</a>.";
193 DB_update_user_timestamp($myid);
195 /* get some information from the DB */
196 $gameid = DB_get_gameid_by_hash($me);
197 $myname = DB_get_name_by_hash($me);
198 $mystatus = DB_get_status_by_hash($me);
199 $mypos = DB_get_pos_by_hash($me);
201 echo "<p class=\"gamenumber\"> Game $gameid </p>\n";
206 check_want_to_play($me);
207 DB_set_hand_status_by_hash($me,'init');
210 if( !myisset("in","update") )
212 DB_set_hand_status_by_hash($me,'start');
213 echo "you need to answer both question";
217 if($_REQUEST["in"] == "no")
219 $message = "Hello, \n\n".
220 "the game has been canceled due to the request of one of the players.\n";
222 $userids = DB_get_all_userid_by_gameid($gameid);
223 foreach($userids as $user)
225 $To = DB_get_email_by_userid($user);
226 mymail($To,$EmailName."game cancled",$message);
229 /* delete everything from the dB */
234 echo "thanks for joining the game... please scroll down";
235 echo "TODO: make this page nicer<br />";
236 echo "TODO: set card pref<br />";
238 $mycards = DB_get_hand($me);
240 echo "<p class=\"mycards\">your cards are: <br />\n";
241 foreach($mycards as $card)
245 check_for_sickness($me,$mycards);
247 DB_set_hand_status_by_hash($me,'check');
253 echo "checking if you selected solo or nines...<br />".
254 " if you have a wedding, please send an email to the other players. <br />".
255 " if you have poverty you need to play a normal game,sorry...<br />".
256 " Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";
257 if(!myisset("solo","wedding","poverty","nines") )
259 /* all these variables have a pre-selected default,
260 * so we should never get here,
261 * unless a user tries to cheat ;) */
262 echo "something went wrong...please contact the admin.";
266 /* check if this sickness needs to be handled first */
267 $gametype = DB_get_gametype_by_gameid($gameid);
268 $startplayer = DB_get_startplayer_by_gameid($gameid);
270 if( $_REQUEST["solo"]!="No")
272 DB_set_solo_by_hash($me,$_REQUEST["solo"]);
273 DB_set_sickness_by_hash($me,"solo");
274 echo "<br />Seems like you want to play a ".$_REQUEST["solo"]." solo. Got it.<br />\n";
276 if($gametype == "solo" && $startplayer<$mypos)
280 /* this solo comes first */
281 DB_set_gametype_by_gameid($gameid,"solo");
282 DB_set_startplayer_by_gameid($gameid,$mypos);
283 DB_set_solo_by_gameid($gameid,$_REQUEST["solo"]);
286 else if($_REQUEST["wedding"] == "yes")
288 /* TODO: add silent solo somewhere*/
289 echo "wedding was chosen<br />\n";
290 DB_set_sickness_by_hash($me,"wedding");
292 else if($_REQUEST["poverty"] == "yes")
294 echo "poverty was chosen<br />\n";
295 DB_set_sickness_by_hash($me,"poverty");
297 else if($_REQUEST["nines"] == "yes")
299 echo "nines was chosen<br />\n";
300 DB_set_sickness_by_hash($me,"nines");
304 DB_set_hand_status_by_hash($me,'poverty');
306 /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
310 /* here we need to check if there is a solo or some other form of sickness.
311 * If so, which one counts
312 * set that one in the Game table, delete other ones form Hand table
313 * tell people about it.
315 echo "<br />checking if someone else selected solo or nines... wedding and poverty not handled at the moment<br />".
316 " Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";
318 /* only set this after all poverty, etc. are handeled*/
319 DB_set_hand_status_by_hash($me,'play');
321 /* check if the game can start */
322 $userids = DB_get_all_userid_by_gameid($gameid);
324 foreach($userids as $user)
325 if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
330 DB_set_game_status_by_gameid($gameid,'play');
332 /* check what kind of game we are playing */
333 $gametype = DB_get_gametype_by_gameid($gameid);
334 $startplayer = DB_get_startplayer_by_gameid($gameid);
338 /* check for nines */
339 foreach($userids as $user)
341 if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'nines')
345 /* gamestatus == normal, => cancel game */
346 if($nines && $gamestatus == "normal")
348 /* TODO: set game type to nines to be able to keep statistics */
350 $message = "Hello, \n\n".
351 "the game has been cancled becausee someone has five or more nines.\n";
353 $userids = DB_get_all_userid_by_gameid($gameid);
354 foreach($userids as $user)
356 $To = DB_get_email_by_userid($user);
357 mymail($To,$EmailName."game cancled",$message);
360 /* delete everything from the dB */
368 /* check players for poverty */
369 foreach($userids as $user)
371 if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'poverty')
374 $name = DB_get_name_by_userid($user);
375 echo "$name has a Vorbehalt. <br />";
378 /* if gamestatus == normal, set poverty or dpovert (in case two people have poverty) */
382 /* check players for wedding */
383 foreach($userids as $user)
385 if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'wedding')
388 $name = DB_get_name_by_userid($user);
389 echo "$name has a Vorbehalt. <br />" ;
393 /* if gamestatus == normal, set wedding */
400 /* both entries here, so that the tricks are visible for both.
401 * in case of 'play' there is a break later that skips the last part
404 /* figure out what kind of game we are playing,
405 * set the global variables $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES
409 $gametype = DB_get_gametype_by_gameid($gameid);
411 if($gametype=="solo")
413 $gametype = DB_get_solo_by_gameid($gameid);
414 $GT = $gametype." ".$GT;
419 set_gametype($gametype);
421 /* get some infos about the game */
422 $gamestatus = DB_get_game_status_by_gameid($gameid);
424 /* display useful things in divs */
426 /* display local time */
427 echo "<div class=\"time\">\n Local times:<table>";
429 $users = DB_get_all_userid_by_gameid($gameid);
430 foreach($users as $user)
432 $offset = DB_get_user_timezone($user);
433 $zone = return_timezone($offset);
434 date_default_timezone_set($zone);
435 $name = DB_get_name_by_userid($user);
437 echo "<tr> <td>$name</td> <td>".date("Y-m-d H:i:s")."</td></tr>\n";
439 echo "</table>\n</div>\n";
441 if($gamestatus != 'pre')
444 /* display links to the users status page */
445 $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
446 $r = mysql_fetch_array($result,MYSQL_NUM);
447 output_link_to_user_page($r[0],$r[1]);
451 /* end display useful things*/
453 /* has the game started? No, then just wait here...*/
454 if($gamestatus == 'pre')
456 echo "you need to wait for the others... <br />";
457 break; /* not sure this works... the idea is that you can
458 * only play a card after everyone is ready to play */
461 /* display the table and the names */
462 $result = mysql_query("SELECT User.fullname as name,".
463 " Hand.position as position ".
465 "LEFT JOIN User ON User.id=Hand.user_id ".
466 "WHERE Hand.game_id='".$gameid."' ".
467 "ORDER BY position ASC");
469 echo "<div class=\"table\">\n".
470 " <img src=\"pics/table.png\" alt=\"table\" />\n";
471 while($r = mysql_fetch_array($result,MYSQL_NUM))
476 echo " <span class=\"table".($pos-1)."\">$name</span>\n";
480 /* get everything relevant to display the tricks */
481 $result = mysql_query("SELECT Hand_Card.card_id as card,".
482 " Hand.position as position,".
483 " Play.sequence as sequence, ".
487 "LEFT JOIN Play ON Trick.id=Play.trick_id ".
488 "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
489 "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
490 "LEFT JOIN Comment ON Play.id=Comment.play_id ".
491 "WHERE Trick.game_id='".$gameid."' ".
492 "ORDER BY Trick.id,sequence ASC");
495 $lasttrick = DB_get_max_trickid($gameid);
497 $play = array(); /* needed to calculate winner later */
499 $pos = DB_get_startplayer_by_gameid($gameid)-1;
500 $firstcard = ""; /* first card in a trick */
502 echo "\n<ul class=\"tricks\">\n";
503 echo " <li> Hello $myname! History: </li>\n";
505 while($r = mysql_fetch_array($result,MYSQL_NUM))
512 /* save card to be able to find the winner of the trick later */
517 /* first card in a trick, output some html */
518 if($trick!=$lasttrick)
520 /* start of an old trick? */
521 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
522 " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
523 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
525 else if($trick==$lasttrick)
527 /* start of a last trick? */
528 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
529 " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
530 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
533 /* remember first card, so that we are able to check, what cards can be played */
538 echo " <div class=\"card".($pos-1)."\">\n";
540 /* display comments */
542 echo " <span class=\"comment\">".$comment."</span>\n";
547 echo " </div>\n"; /* end div card */
553 echo " </div>\n </li>\n"; /* end div table, end li table */
557 if($seq!=4 && $trickNR>1)
558 echo " </div>\n </li>\n"; /* end div table, end li table */
562 /* whos turn is it? */
565 $winner = get_winner($play,$gametype); /* returns the position */
567 $firstcard = ""; /* new trick, no first card */
572 if($next==5) $next=1;
575 /* my turn?, display cards as links, ask for comments*/
576 if(DB_get_pos_by_hash($me) == $next)
581 /* do we want to play a card? */
582 if(myisset("card") && $myturn)
584 $card = $_REQUEST["card"];
585 $handid = DB_get_handid_by_hash($me);
587 /* check if we have card and that we haven't played it yet*/
588 /* set played in hand_card to true where hand_id and card_id*/
589 $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
590 "hand_id='$handid' AND card_id=".DB_quote_smart($card));
591 $r = mysql_fetch_array($result,MYSQL_NUM);
596 /* mark card as played */
597 mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
598 DB_quote_smart($card));
600 /* get trick id or start new trick */
601 $a = DB_get_current_trickid($gameid);
605 $playid = DB_play_card($trickid,$handcardid,$sequence);
607 /* check for coment */
608 if(myisset("comment"))
610 DB_insert_comment($_REQUEST["comment"],$playid,$myid);
613 /* display played card */
614 echo "<div class=\"card\">";
615 echo " you played <br />";
619 /*check if we still have cards left, else set status to gameover */
620 if(sizeof(DB_get_hand($me))==0)
622 DB_set_hand_status_by_hash($me,'gameover');
623 $mystatus='gameover';
626 /* if all players are done, set game status to game over,
627 * get the points of the last trick and send out an email
630 $userids = DB_get_all_userid_by_gameid($gameid);
633 foreach($userids as $user)
634 if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='gameover')
639 DB_set_game_status_by_gameid($gameid,"gameover");
640 /* get score for last trick
641 * all other tricks are handled a few lines further down*/
642 $play = DB_get_cards_by_trick($trickid);
643 $winner = get_winner($play,$gametype); /* returns the position */
644 /* get points of last trick and save it */
646 foreach($play as $card)
647 $points = $points + card_value($card);
648 $winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
650 mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
652 echo "ERROR during scoring";
654 /* email all players */
655 $result = mysql_query("SELECT fullname, SUM(score) FROM Score".
656 " LEFT JOIN Hand ON Hand.id=hand_id".
657 " LEFT JOIN User ON Hand.user_id=User.id".
658 " WHERE Hand.game_id=$gameid".
659 " GROUP BY fullname" );
660 $message = "The game is over. Thanks for playing :)\n";
661 while( $r = mysql_fetch_array($result,MYSQL_NUM))
662 $message .= " FINAL SCORE: ".$r[0]." ".$r[1]."\n";
663 $message .= "\nIf your not in the list above your score is zero...\n";
664 foreach($userids as $user)
666 $To = DB_get_email_by_userid($user);
667 mymail($To,$EmailName."game over",$message);
672 /* email next player */
673 if(DB_get_game_status_by_gameid($gameid)=='play')
677 $play = DB_get_cards_by_trick($trickid);
678 $winner = get_winner($play,$gametype); /* returns the position */
680 /* get points of last trick and save it, last trick is handled
681 * a few lines further up */
683 foreach($play as $card)
684 $points = $points + card_value($card);
686 $winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
688 mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
690 echo "ERROR during scoring";
693 echo "DEBUG: $winner got $points <br />";
695 /* who is the next player? */
700 $next = DB_get_pos_by_hash($me)+1;
702 if($next==5) $next=1;
704 /* email next player */
705 $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
706 $email = DB_get_email_by_hash($next_hash);
708 $message = "It's your turn now.\n".
709 "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
710 mymail($email,$EmailName."a card has been played",$message);
713 echo "DEBUG:<a href=\"index.php?me=".DB_get_hash_from_game_and_pos($gameid,$next).
714 "\"> next player </a> <br />\n";
720 echo "can't find that card?! <br />\n";
723 else if(myisset("card") && !$myturn )
725 echo "please wait until it's your turn! <br />\n";
728 $mycards = DB_get_hand($me);
729 $mycards = mysort($mycards,$gametype);
730 echo "<div class=\"mycards\">\n";
732 if($myturn && !myisset("card"))
734 echo "Hello ".$myname.", it's your turn! <br />\n";
735 echo "Your cards are: <br />\n";
736 echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
738 /* do we have to follow suite? */
740 if(have_suit($mycards,$firstcard))
743 foreach($mycards as $card)
745 if($followsuit && !same_type($card,$firstcard))
748 display_link_card($card);
751 echo "<br />\nA short comments:<input name=\"comment\" type=\"text\" size=\"30\" maxlength=\"50\" />\n";
752 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
753 echo "<input type=\"submit\" value=\"move\" />\n";
756 else if($mystatus=='play')
758 echo "Your cards are: <br />\n";
759 foreach($mycards as $card)
764 /* check if we need to set status to 'gameover' is done during playing of the card */
765 if($mystatus=='play')
767 /* the following happens only when the gamestatus is 'gameover' */
768 /* check if game is over, display results */
769 if(DB_get_game_status_by_gameid($gameid)=='play')
771 echo "the game is over for you.. other people still need to play though";
775 echo "the game is over now...<br />\n";
777 $result = mysql_query("SELECT fullname, SUM(score) FROM Score".
778 " LEFT JOIN Hand ON Hand.id=hand_id".
779 " LEFT JOIN User ON Hand.user_id=User.id".
780 " WHERE Hand.game_id=$gameid".
781 " GROUP BY fullname" );
782 while( $r = mysql_fetch_array($result,MYSQL_NUM))
783 echo " FINAL SCORE: ".$r[0]." ".$r[1]."<br />";
786 $session = DB_get_session_by_gameid($gameid);
787 $result = mysql_query("SELECT id,create_date FROM Game".
788 " WHERE session=$session".
789 " ORDER BY create_date DESC".
793 $r = mysql_fetch_array($result,MYSQL_NUM);
795 if(!$session || $gameid==$r)
797 /* suggest a new game with the same people in it, just rotated once */
798 $names = DB_get_all_names_by_gameid($gameid);
799 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
804 echo "error in testing the status";
808 /* user status page */
809 else if(myisset("email","password"))
811 /* test id and password, should really be done in one step */
812 $email = $_REQUEST["email"];
813 $password = $_REQUEST["password"];
815 if(strlen($password)!=32)
816 $password = md5($password);
819 $uid = DB_get_userid_by_email_and_password($email,$password);
825 $time = DB_get_user_timestamp($uid);
826 $unixtime =strtotime($time);
828 $offset = DB_get_user_timezone($uid);
829 $zone = return_timezone($offset);
830 date_default_timezone_set($zone);
832 echo "last login: ".date("r",$unixtime)."<br />";
834 DB_update_user_timestamp($uid);
836 echo "<p>these are the games you are playing in:<br />\n";
837 $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date from Hand".
838 " LEFT JOIN Game On Hand.game_id=Game.id".
839 " WHERE Hand.user_id='$uid' AND Game.status<>'gameover'" );
840 while( $r = mysql_fetch_array($result,MYSQL_NUM))
842 echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a>";
843 if(time()-strtotime($r[2]) > 60*60*24*30)
844 echo " The game has been running for over a month. Do you want to cancel it? <a href=\"$host?cancle=1&me=".$r[0]."\">yes</a> (clicking here is final and can't be restored)";
850 echo "<p>and these are your games that are already done:<br />Game: \n";
851 $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
852 while( $r = mysql_fetch_array($result,MYSQL_NUM))
853 echo "<a href=\"".$host."?me=".$r[0]."\">#".$r[1]." </a>, ";
856 $names = DB_get_all_names();
857 echo "<p>registered players:<br />\n";
858 foreach ($names as $name)
862 echo "<p>Want to start a new game? Visit <a href=\"".$host."?new\">this page.</a></p>";
866 echo "sorry email and password don't match <br />";
870 /* page for registration */
871 else if(myisset("register") )
875 /* new user wants to register */
876 else if(myisset("Rfullname","Remail","Rpassword","Rtimezone") )
879 if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
881 echo "please chose another name<br />";
884 if(DB_get_userid_by_email($_REQUEST["Remail"]))
886 echo "this email address is already used ?!<br />";
891 $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
892 ",".DB_quote_smart($_REQUEST["Remail"]).
893 ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
894 ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
897 echo " added you to the database";
899 echo " something went wrong";
902 /* default login page */