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 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre','$followup' ,NULL)");
69 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre', NULL ,NULL)");
70 $game_id = mysql_insert_id();
73 $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA);
74 $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB);
75 $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC);
76 $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD);
79 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
80 ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,'false','false',NULL)");
81 $hand_idA = mysql_insert_id();
82 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
83 ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,'false','false',NULL)");
84 $hand_idB = mysql_insert_id();
85 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
86 ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,'false','false',NULL)");
87 $hand_idC = mysql_insert_id();
88 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
89 ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,'false','false',NULL)");
90 $hand_idD = mysql_insert_id();
94 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
96 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
98 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
100 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
102 /* send out email, TODO: check for error with email */
104 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
105 "Place comments and bug reports here:\n".
106 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
107 "The whole round would consist of the following players:\n".
112 "If you want to join this game, please follow this link:\n\n".
115 mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
116 mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
117 mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
118 mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
120 echo "You started a new game. The emails have been sent out!";
121 } /* end set up a new game */
122 else if(myisset("cancle","me"))
124 $me = $_REQUEST["me"];
126 /* test for valid ID */
127 $myid = DB_get_userid_by_hash($me);
130 echo "Can't find you in the database, please check the url.<br />\n";
131 echo "perhaps the game has been cancled, check by login in <a href=\"$host\">here</a>.";
135 DB_update_user_timestamp($myid);
137 /* get some information from the DB */
138 $gameid = DB_get_gameid_by_hash($me);
139 $myname = DB_get_name_by_hash($me);
140 $mystatus = DB_get_status_by_hash($me);
141 $mypos = DB_get_pos_by_hash($me);
143 /* check if game really is old enough */
144 $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " );
145 $r = mysql_fetch_array($result,MYSQL_NUM);
146 if(time()-strtotime($r[0]) > 60*60*24*30)
148 $message = "Hello, \n\n".
149 "Game $gameid has been cancled because, since nothing happend for a while and $myname requested it.\n";
151 $userids = DB_get_all_userid_by_gameid($gameid);
152 foreach($userids as $user)
154 $To = DB_get_email_by_userid($user);
155 mymail($To,$EmailName."game cancled (timed out)",$message);
158 /* delete everything from the dB */
161 echo "<p style=\"background-color:red\";>Game $gameid has been cancled.<br /><br /></p>";
164 echo "<p>You need to wait longer before you can cancle a game...</p>\n";
166 else if(myisset("me"))
168 /* handle request from one specific player,
169 ` * the hash is set on a per game base
172 $me = $_REQUEST["me"];
174 /* test for valid ID */
175 $myid = DB_get_userid_by_hash($me);
178 echo "Can't find you in the database, please check the url.<br />\n";
179 echo "perhaps the game has been cancled, check by login in <a href=\"$host\">here</a>.";
183 DB_update_user_timestamp($myid);
185 /* get some information from the DB */
186 $gameid = DB_get_gameid_by_hash($me);
187 $myname = DB_get_name_by_hash($me);
188 $mystatus = DB_get_status_by_hash($me);
189 $mypos = DB_get_pos_by_hash($me);
191 echo "<p class=\"gamenumber\"> Game $gameid </p>\n";
196 check_want_to_play($me);
197 DB_set_hand_status_by_hash($me,'init');
200 if( !myisset("in","update") )
202 DB_set_hand_status_by_hash($me,'start');
203 echo "you need to answer both question";
207 if($_REQUEST["in"] == "no")
209 $message = "Hello, \n\n".
210 "the game has been canceled due to the request of one of the players.\n";
212 $userids = DB_get_all_userid_by_gameid($gameid);
213 foreach($userids as $user)
215 $To = DB_get_email_by_userid($user);
216 mymail($To,$EmailName."game cancled",$message);
219 /* delete everything from the dB */
224 echo "thanks for joining the game... please scroll down";
225 echo "TODO: make this page nicer<br />";
226 echo "TODO: set card pref<br />";
228 $mycards = DB_get_hand($me);
230 echo "<p class=\"mycards\">your cards are: <br />\n";
231 foreach($mycards as $card)
235 check_for_sickness($me,$mycards);
237 DB_set_hand_status_by_hash($me,'check');
243 echo "checking if you selected solo or nines...<br />".
244 " if you have a wedding, please send an email to the other players. <br />".
245 " if you have poverty you need to play a normal game,sorry...<br />".
246 " Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";
247 if(!myisset("solo","wedding","poverty","nines") )
249 /* all these variables have a pre-selected default,
250 * so we should never get here,
251 * unless a user tries to cheat ;) */
252 echo "something went wrong...please contact the admin.";
256 /* check if this sickness needs to be handled first */
257 $gametype = DB_get_gametype_by_gameid($gameid);
258 $startplayer = DB_get_startplayer_by_gameid($gameid);
260 if( $_REQUEST["solo"]!="No")
262 DB_set_solo_by_hash($me,$_REQUEST["solo"]);
263 DB_set_sickness_by_hash($me,"solo");
264 echo "<br />Seems like you want to play a ".$_REQUEST["solo"]." solo. Got it.<br />\n";
266 if($gametype == "solo" && $startplayer<$mypos)
270 /* this solo comes first */
271 DB_set_gametype_by_gameid($gameid,"solo");
272 DB_set_startplayer_by_gameid($gameid,$mypos);
273 DB_set_solo_by_gameid($gameid,$_REQUEST["solo"]);
276 else if($_REQUEST["wedding"] == "yes")
278 /* TODO: add silent solo somewhere*/
279 echo "wedding was chosen<br />\n";
280 DB_set_sickness_by_hash($me,"wedding");
282 else if($_REQUEST["poverty"] == "yes")
284 echo "poverty was chosen<br />\n";
285 DB_set_sickness_by_hash($me,"poverty");
287 else if($_REQUEST["nines"] == "yes")
289 echo "nines was chosen<br />\n";
290 DB_set_sickness_by_hash($me,"nines");
294 DB_set_hand_status_by_hash($me,'poverty');
296 /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
300 /* here we need to check if there is a solo or some other form of sickness.
301 * If so, which one counts
302 * set that one in the Game table, delete other ones form Hand table
303 * tell people about it.
305 echo "<br />checking if someone else selected solo or nines... wedding and poverty not handled at the moment<br />".
306 " Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";
308 /* only set this after all poverty, etc. are handeled*/
309 DB_set_hand_status_by_hash($me,'play');
311 /* check if the game can start */
312 $userids = DB_get_all_userid_by_gameid($gameid);
314 foreach($userids as $user)
315 if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
320 DB_set_game_status_by_gameid($gameid,'play');
322 /* check what kind of game we are playing */
323 $gametype = DB_get_gametype_by_gameid($gameid);
324 $startplayer = DB_get_startplayer_by_gameid($gameid);
328 /* check for nines */
329 foreach($userids as $user)
331 if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'nines')
335 /* gamestatus == normal, => cancel game */
336 if($nines && $gamestatus == "normal")
338 /* TODO: set game type to nines to be able to keep statistics */
340 $message = "Hello, \n\n".
341 "the game has been cancled becausee someone has five or more nines.\n";
343 $userids = DB_get_all_userid_by_gameid($gameid);
344 foreach($userids as $user)
346 $To = DB_get_email_by_userid($user);
347 mymail($To,$EmailName."game cancled",$message);
350 /* delete everything from the dB */
358 /* check players for poverty */
359 foreach($userids as $user)
361 if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'poverty')
364 $name = DB_get_name_by_userid($user);
365 echo "$name has a Vorbehalt. <br />";
368 /* if gamestatus == normal, set poverty or dpovert (in case two people have poverty) */
372 /* check players for wedding */
373 foreach($userids as $user)
375 if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'wedding')
378 $name = DB_get_name_by_userid($user);
379 echo "$name has a Vorbehalt. <br />" ;
383 /* if gamestatus == normal, set wedding */
390 /* both entries here, so that the tricks are visible for both.
391 * in case of 'play' there is a break later that skips the last part
394 /* figure out what kind of game we are playing,
395 * set the global variables $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES
399 $gametype = DB_get_gametype_by_gameid($gameid);
401 if($gametype=="solo")
403 $gametype = DB_get_solo_by_gameid($gameid);
404 $GT = $gametype." ".$GT;
409 set_gametype($gametype);
411 /* get some infos about the game */
412 $gamestatus = DB_get_game_status_by_gameid($gameid);
414 /* display useful things in divs */
416 /* display local time */
417 echo "<div class=\"time\">\n Local times:<table>";
419 $users = DB_get_all_userid_by_gameid($gameid);
420 foreach($users as $user)
422 $offset = DB_get_user_timezone($user);
423 $zone = return_timezone($offset);
424 date_default_timezone_set($zone);
425 $name = DB_get_name_by_userid($user);
427 echo "<tr> <td>$name</td> <td>".date("Y-m-d H:i:s")."</td></tr>\n";
429 echo "</table>\n</div>\n";
431 if($gamestatus != 'pre')
434 /* display links to the users status page */
435 $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
436 $r = mysql_fetch_array($result,MYSQL_NUM);
437 output_link_to_user_page($r[0],$r[1]);
441 /* end display useful things*/
443 /* has the game started? No, then just wait here...*/
444 if($gamestatus == 'pre')
446 echo "you need to wait for the others... <br />";
447 break; /* not sure this works... the idea is that you can
448 * only play a card after everyone is ready to play */
451 /* display the table and the names */
452 $result = mysql_query("SELECT User.fullname as name,".
453 " Hand.position as position ".
455 "LEFT JOIN User ON User.id=Hand.user_id ".
456 "WHERE Hand.game_id='".$gameid."' ".
457 "ORDER BY position ASC");
459 echo "<div class=\"table\">\n".
460 " <img src=\"pics/table.png\" alt=\"table\" />\n";
461 while($r = mysql_fetch_array($result,MYSQL_NUM))
466 echo " <span class=\"table".($pos-1)."\">$name</span>\n";
470 /* get everything relevant to display the tricks */
471 $result = mysql_query("SELECT Hand_Card.card_id as card,".
472 " Hand.position as position,".
473 " Play.sequence as sequence, ".
477 "LEFT JOIN Play ON Trick.id=Play.trick_id ".
478 "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
479 "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
480 "LEFT JOIN Comment ON Play.id=Comment.play_id ".
481 "WHERE Trick.game_id='".$gameid."' ".
482 "ORDER BY Trick.id,sequence ASC");
485 $lasttrick = DB_get_max_trickid($gameid);
487 $play = array(); /* needed to calculate winner later */
489 $pos = DB_get_startplayer_by_gameid($gameid)-1;
490 $firstcard = ""; /* first card in a trick */
492 echo "\n<ul class=\"tricks\">\n";
493 echo " <li> Hello $myname! History: </li>\n";
495 while($r = mysql_fetch_array($result,MYSQL_NUM))
502 /* save card to be able to find the winner of the trick later */
507 /* first card in a trick, output some html */
508 if($trick!=$lasttrick)
510 /* start of an old trick? */
511 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
512 " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
513 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
515 else if($trick==$lasttrick)
517 /* start of a last trick? */
518 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
519 " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
520 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
523 /* remember first card, so that we are able to check, what cards can be played */
528 echo " <div class=\"card".($pos-1)."\">\n";
530 /* display comments */
532 echo " <span class=\"comment\">".$comment."</span>\n";
537 echo " </div>\n"; /* end div card */
543 echo " </div>\n </li>\n"; /* end div table, end li table */
547 if($seq!=4 && $trickNR>1)
548 echo " </div>\n </li>\n"; /* end div table, end li table */
552 /* whos turn is it? */
555 $winner = get_winner($play,$gametype); /* returns the position */
557 $firstcard = ""; /* new trick, no first card */
562 if($next==5) $next=1;
565 /* my turn?, display cards as links, ask for comments*/
566 if(DB_get_pos_by_hash($me) == $next)
571 /* do we want to play a card? */
572 if(myisset("card") && $myturn)
574 $card = $_REQUEST["card"];
575 $handid = DB_get_handid_by_hash($me);
577 /* check if we have card and that we haven't played it yet*/
578 /* set played in hand_card to true where hand_id and card_id*/
579 $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
580 "hand_id='$handid' AND card_id=".DB_quote_smart($card));
581 $r = mysql_fetch_array($result,MYSQL_NUM);
586 /* mark card as played */
587 mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
588 DB_quote_smart($card));
590 /* get trick id or start new trick */
591 $a = DB_get_current_trickid($gameid);
595 $playid = DB_play_card($trickid,$handcardid,$sequence);
597 /* check for coment */
598 if(myisset("comment"))
600 DB_insert_comment($_REQUEST["comment"],$playid,$myid);
603 /* display played card */
604 echo "<div class=\"card\">";
605 echo " you played <br />";
609 /*check if we still have cards left, else set status to gameover */
610 if(sizeof(DB_get_hand($me))==0)
612 DB_set_hand_status_by_hash($me,'gameover');
613 $mystatus='gameover';
616 /* if all players are done, set game status to game over,
617 * get the points of the last trick and send out an email
620 $userids = DB_get_all_userid_by_gameid($gameid);
623 foreach($userids as $user)
624 if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='gameover')
629 DB_set_game_status_by_gameid($gameid,"gameover");
630 /* get score for last trick
631 * all other tricks are handled a few lines further down*/
632 $play = DB_get_cards_by_trick($trickid);
633 $winner = get_winner($play,$gametype); /* returns the position */
634 /* get points of last trick and save it */
636 foreach($play as $card)
637 $points = $points + card_value($card);
638 $winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
640 mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
642 echo "ERROR during scoring";
644 /* email all players */
645 $result = mysql_query("SELECT fullname, SUM(score) FROM Score".
646 " LEFT JOIN Hand ON Hand.id=hand_id".
647 " LEFT JOIN User ON Hand.user_id=User.id".
648 " WHERE Hand.game_id=$gameid".
649 " GROUP BY fullname" );
650 $message = "The game is over. Thanks for playing :)\n";
651 while( $r = mysql_fetch_array($result,MYSQL_NUM))
652 $message .= " FINAL SCORE: ".$r[0]." ".$r[1]."\n";
653 $message .= "\nIf your not in the list above your score is zero...\n";
654 foreach($userids as $user)
656 $To = DB_get_email_by_userid($user);
657 mymail($To,$EmailName."game over",$message);
662 /* email next player */
663 if(DB_get_game_status_by_gameid($gameid)=='play')
667 $play = DB_get_cards_by_trick($trickid);
668 $winner = get_winner($play,$gametype); /* returns the position */
670 /* get points of last trick and save it, last trick is handled
671 * a few lines further up */
673 foreach($play as $card)
674 $points = $points + card_value($card);
676 $winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
678 mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
680 echo "ERROR during scoring";
683 echo "DEBUG: $winner got $points <br />";
685 /* who is the next player? */
690 $next = DB_get_pos_by_hash($me)+1;
692 if($next==5) $next=1;
694 /* email next player */
695 $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
696 $email = DB_get_email_by_hash($next_hash);
698 $message = "It's your turn now.\n".
699 "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
700 mymail($email,$EmailName."a card has been played",$message);
703 echo "DEBUG:<a href=\"index.php?me=".DB_get_hash_from_game_and_pos($gameid,$next).
704 "\"> next player </a> <br />\n";
710 echo "can't find that card?! <br />\n";
713 else if(myisset("card") && !$myturn )
715 echo "please wait until it's your turn! <br />\n";
718 $mycards = DB_get_hand($me);
719 $mycards = mysort($mycards,$gametype);
720 echo "<div class=\"mycards\">\n";
722 if($myturn && !myisset("card"))
724 echo "Hello ".$myname.", it's your turn! <br />\n";
725 echo "Your cards are: <br />\n";
726 echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
728 /* do we have to follow suite? */
730 if(have_suit($mycards,$firstcard))
733 foreach($mycards as $card)
735 if($followsuit && !same_type($card,$firstcard))
738 display_link_card($card);
741 echo "<br />\nA short comments:<input name=\"comment\" type=\"text\" size=\"30\" maxlength=\"50\" />\n";
742 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
743 echo "<input type=\"submit\" value=\"move\" />\n";
746 else if($mystatus=='play')
748 echo "Your cards are: <br />\n";
749 foreach($mycards as $card)
754 /* check if we need to set status to 'gameover' is done during playing of the card */
755 if($mystatus=='play')
757 /* the following happens only when the gamestatus is 'gameover' */
758 /* check if game is over, display results */
759 if(DB_get_game_status_by_gameid($gameid)=='play')
761 echo "the game is over for you.. other people still need to play though";
765 echo "the game is over now...<br />\n";
767 $result = mysql_query("SELECT fullname, SUM(score) FROM Score".
768 " LEFT JOIN Hand ON Hand.id=hand_id".
769 " LEFT JOIN User ON Hand.user_id=User.id".
770 " WHERE Hand.game_id=$gameid".
771 " GROUP BY fullname" );
772 while( $r = mysql_fetch_array($result,MYSQL_NUM))
773 echo " FINAL SCORE: ".$r[0]." ".$r[1]."<br />";
775 /* suggest a new game with the same people in it, just rotated once */
776 $names = DB_get_all_names_by_gameid($gameid);
777 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
781 echo "error in testing the status";
785 /* user status page */
786 else if(myisset("email","password"))
788 /* test id and password, should really be done in one step */
789 $email = $_REQUEST["email"];
790 $password = $_REQUEST["password"];
792 if(strlen($password)!=32)
793 $password = md5($password);
796 $uid = DB_get_userid_by_email_and_password($email,$password);
802 $time = DB_get_user_timestamp($uid);
803 $unixtime =strtotime($time);
805 $offset = DB_get_user_timezone($uid);
806 $zone = return_timezone($offset);
807 date_default_timezone_set($zone);
809 echo "last login: ".date("r",$unixtime)."<br />";
811 DB_update_user_timestamp($uid);
813 echo "<p>these are the games you are playing in:<br />\n";
814 $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date from Hand".
815 " LEFT JOIN Game On Hand.game_id=Game.id".
816 " WHERE Hand.user_id='$uid' AND Game.status<>'gameover'" );
817 while( $r = mysql_fetch_array($result,MYSQL_NUM))
819 echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a>";
820 if(time()-strtotime($r[2]) > 60*60*24*30)
821 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)";
827 echo "<p>and these are your games that are already done:<br />\n";
828 $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
829 while( $r = mysql_fetch_array($result,MYSQL_NUM))
830 echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a><br />";
833 $names = DB_get_all_names();
834 echo "<p>registered players:<br />\n";
835 foreach ($names as $name)
836 echo "$name <br />\n";
839 echo "<p>Want to start a new game? remember 4 names from the list above and visit ".
840 "<a href=\"".$host."?new\">this page.</a></p>";
844 echo "sorry email and password don't match <br />";
848 /* page for registration */
849 else if(myisset("register") )
853 /* new user wants to register */
854 else if(myisset("Rfullname","Remail","Rpassword","Rtimezone") )
857 if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
859 echo "please chose another name<br />";
862 if(DB_get_userid_by_email($_REQUEST["Remail"]))
864 echo "this email address is already used ?!<br />";
869 $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
870 ",".DB_quote_smart($_REQUEST["Remail"]).
871 ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
872 ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
875 echo " added you to the database";
877 echo " something went wrong";
880 /* default login page */