2 "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
3 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
7 <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
8 <link rel="stylesheet" type="text/css" href="css/standard.css" />
9 <script type="text/javascript">
11 if(document.getElementById){
14 if(document.getElementById("trick"+i))
15 document.getElementById("trick"+i).style.display = 'none';
17 document.getElementById("trick"+num).style.display = 'block';
21 if(document.getElementById){
24 if(document.getElementById("trick"+i))
34 <body onload="high_last();">
36 <h1> Welcome to E-Doko </h1>
42 error_reporting(E_ALL);
44 include_once("config.php");
45 include_once("functions.php");
46 include_once("db.php");
50 /***************** M A I N **************************/
52 /* check if we want to start a new game */
53 if(isset($_REQUEST["new"]))
54 output_form_for_new_game();
56 /*check if everything is ready to set up a new game */
57 else if( isset($_REQUEST["PlayerA"]) &&
58 isset($_REQUEST["PlayerB"]) &&
59 isset($_REQUEST["PlayerC"]) &&
60 isset($_REQUEST["PlayerD"]) )
62 $PlayerA = $_REQUEST["PlayerA"];
63 $PlayerB = $_REQUEST["PlayerB"];
64 $PlayerC = $_REQUEST["PlayerC"];
65 $PlayerD = $_REQUEST["PlayerD"];
67 $EmailA = DB_get_email_by_name($PlayerA);
68 $EmailB = DB_get_email_by_name($PlayerB);
69 $EmailC = DB_get_email_by_name($PlayerC);
70 $EmailD = DB_get_email_by_name($PlayerD);
72 if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
74 echo "couldn't find one of the names, please start a new game";
78 $useridA = DB_get_userid_by_name($PlayerA);
79 $useridB = DB_get_userid_by_name($PlayerB);
80 $useridC = DB_get_userid_by_name($PlayerC);
81 $useridD = DB_get_userid_by_name($PlayerD);
83 /* create random numbers */
84 $randomNR = create_array_of_random_numbers();
85 $randomNRstring = join(":",$randomNR);
89 if(isset($_REQUEST["followup"]))
91 $followup= $_REQUEST["followup"];
92 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL,'pre','$followup' ,NULL)");
95 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL,'pre', NULL ,NULL)");
96 $game_id = mysql_insert_id();
99 $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA);
100 $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB);
101 $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC);
102 $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD);
105 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
106 ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,'false','false',NULL)");
107 $hand_idA = mysql_insert_id();
108 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
109 ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,'false','false',NULL)");
110 $hand_idB = mysql_insert_id();
111 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
112 ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,'false','false',NULL)");
113 $hand_idC = mysql_insert_id();
114 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
115 ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,'false','false',NULL)");
116 $hand_idD = mysql_insert_id();
120 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
121 for($i=12;$i<24;$i++)
122 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
123 for($i=24;$i<36;$i++)
124 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
125 for($i=36;$i<48;$i++)
126 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
128 /* send out email, TODO: check for error with email */
130 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
131 "Place comments and bug reports here:\n".
132 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
133 "The whole round would consist of the following players:\n".
138 "If you want to join this game, please follow this link:\n\n".
141 mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
142 mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
143 mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
144 mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
147 /* end set up a new game */
149 else if(isset($_REQUEST["me"]))
151 /* handle request from one specifig player,
152 * the hash is set on a per game base, so first just handle this game
153 * perhaps also show links to other games in a sidebar
156 $me = $_REQUEST["me"];
158 /* test for valid ID */
159 $myid = DB_get_userid_by_hash($me);
162 echo "Can't find you in the database, please check the url.<br />\n";
163 echo "perhaps the game has been cancled.";
167 DB_update_user_timestamp($myid);
169 /* get some information from the DB */
170 $gameid = DB_get_gameid_by_hash($me);
171 $myname = DB_get_name_by_hash($me);
172 $mystatus = DB_get_status_by_hash($me);
177 check_want_to_play($me);
178 DB_set_hand_status_by_hash($me,'init');
181 if( !isset($_REQUEST["in"]) || !isset($_REQUEST["update"]))
183 DB_set_hand_status_by_hash($me,'start');
184 echo "you need to answer both question";
188 if($_REQUEST["in"] == "no")
190 echo "TODO: email everyone that the game has been canceled.<br />";
191 /*something like need to modify for DB backend
194 $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
195 "the game has been canceled due to the request of one of the players.\n";
196 mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
199 /* delete everything from the dB */
204 echo "thanks for joining the game... please scroll down";
205 echo "TODO: make this page nicer<br />";
206 echo "TODO: set card pref<br />";
208 $mycards = DB_get_hand($me);
210 echo "<p class=\"mycards\">your cards are: <br />\n";
211 foreach($mycards as $card)
215 check_for_sickness($me,$mycards);
217 DB_set_hand_status_by_hash($me,'check');
223 echo "no checking at the moment... you need to play a normal game. At the moment you need to reload this page to finish the setup.";
224 if(!isset($_REQUEST["solo"]) ||
225 !isset($_REQUEST["wedding"]) ||
226 !isset($_REQUEST["poverty"]) ||
227 !isset($_REQUEST["nines"]) )
229 DB_set_hand_status_by_hash($me,'init');
230 /* problem: by setting it back to init, variables "in" and "update" are
231 * not set, so the player will be send back to the start, after seeing his hand
233 echo "you need to fill out the form";
237 if( $_REQUEST["solo"]!="No")
239 DB_set_solo_by_hash($me,$_REQUEST["solo"]);
240 DB_set_sickness_by_hash($me,"solo");
242 else if($_REQUEST["wedding"] == "yes")
244 echo "wedding was chosen<br />\n";
245 DB_set_sickness_by_hash($me,"wedding");
247 else if($_REQUEST["poverty"] == "yes")
249 echo "poverty was chosen<br />\n";
250 DB_set_sickness_by_hash($me,"poverty");
252 else if($_REQUEST["nines"] == "yes")
254 echo "nines was chosen<br />\n";
255 DB_set_sickness_by_hash($me,"nines");
258 DB_set_hand_status_by_hash($me,'poverty');
260 /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
262 /* reset solo, etc from players who did say something, but it didn't matter? */
265 echo "<br />poverty not handeled at the moment... you need to play a normal game<br />";
267 /* only set this after all poverty, etc. are handeled*/
268 DB_set_hand_status_by_hash($me,'play');
270 /* check if the game can start */
271 $userids = DB_get_all_userid_by_gameid($gameid);
273 foreach($userids as $user)
274 if(DB_get_hand_status_by_userid($user)!='play')
278 DB_set_game_status_by_gameid($gameid,'play');
282 case 'gameover': /*both entries here, so that the tricks are visible for both in case of 'play' there is a break later that skips the last part*/
283 /* display local time */
284 echo "<div class=\"time\">\n Local times:<table>";
286 $users = DB_get_all_userid_by_gameid($gameid);
287 foreach($users as $user)
289 $offset = DB_get_user_timezone($user);
290 $zone = return_timezone($offset);
291 date_default_timezone_set($zone);
292 $name = DB_get_name_by_userid($user);
294 echo "<tr> <td>$name</td> <td>".date("Y-m-d H:i:s")."</td></tr>\n";
296 echo "</table>\n</div>\n";
299 /* display links to other games */
300 echo "<div class=\"over\">\n";
301 $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
302 $r = mysql_fetch_array($result,MYSQL_NUM);
303 echo "<form action=\"index.php\" method=\"post\">\n";
304 echo " <input type=\"hidden\" name=\"email\" value=\"".$r[0]."\" />\n";
305 echo " <input type=\"hidden\" name=\"password\" value=\"".$r[1]."\" />\n";
306 echo " <input type=\"submit\" value=\"go to my user page\" />\n";
312 $gamestatus = DB_get_game_status_by_gameid($gameid);
313 if($gamestatus == 'pre')
315 echo "you need to wait for the others... <br />";
318 /* get everythin relevant to display the tricks */
319 $result = mysql_query("SELECT Hand_Card.card_id as card,".
320 " User.fullname as name,".
321 " Hand.position as position,".
322 " Play.sequence as sequence, ".
323 " Hand.hash as hash, ".
327 "LEFT JOIN Play ON Trick.id=Play.trick_id ".
328 "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
329 "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
330 "LEFT JOIN User ON User.id=Hand.user_id ".
331 "LEFT JOIN Comment ON Play.id=Comment.play_id ".
332 "WHERE Trick.game_id='".$gameid."' ".
333 "ORDER BY Trick.id,sequence ASC");
338 $lasttrick = DB_get_max_trickid($gameid);
340 $play = array(); /* needed to calculate winner later */
344 echo "\n<ul class=\"oldtrick\">\n";
345 echo " <li> Hello $myname! History: </li>\n";
347 while($r = mysql_fetch_array($result,MYSQL_NUM))
354 if($trick!=$lasttrick && $seq==1)
356 /* start of an old trick? */
357 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
358 " <div class=\"table\" id=\"trick".$trickNR."\">\n".
359 " <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
361 else if($trick==$lasttrick && $seq==1)
363 /* start of a last trick? */
364 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
365 " <div class=\"table\" id=\"trick".$trickNR."\">\n".
366 " <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
370 echo " <div class=\"card".($pos-1)."\">\n";
375 echo " <span class=\"comment\">";
382 /* check for comment */
384 echo "<span>".$comment."</span>";
389 echo " </div>\n"; /* end div card */
395 echo " </div>\n </li>\n"; /* end div table, end li table */
399 if($seq!=4 && $trickNR>1)
400 echo " </div>\n </li>\n"; /* end div table, end li table */
404 /* whos turn is it? */
407 $winner = get_winner($play); /* returns the position */
414 if($next==5) $next=1;
416 /* my turn?, display cards as links, ask for comments*/
417 if(DB_get_pos_by_hash($me) == $next)
422 /* do we want to play a card? */
423 if(isset($_REQUEST["card"]) && $myturn)
425 $card = $_REQUEST["card"];
426 $handid = DB_get_handid_by_hash($me);
428 /* check if we have card and that we haven't played it yet*/
429 /* set played in hand_card to true where hand_id and card_id*/
430 $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
431 "hand_id='$handid' AND card_id=".DB_quote_smart($card));
432 $r = mysql_fetch_array($result,MYSQL_NUM);
437 mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".DB_quote_smart($card));
439 /* get trick id or start new trick */
440 $a = DB_get_current_trickid($gameid);
444 $playid = DB_play_card($trickid,$handcardid,$sequence);
446 /*check for coment */
447 if(isset($_REQUEST["comment"]))
449 DB_insert_comment($_REQUEST["comment"],$playid,$myid);
452 echo "<div class=\"card\">";
453 echo " you played <br />";
458 /*check if we still have cards left, else set status to gameover */
459 if(sizeof(DB_get_hand($me))==0)
461 DB_set_hand_status_by_hash($me,'gameover');
462 $mystatus='gameover';
465 /* if all players are done, set game status also to game over */
466 $userids = DB_get_all_userid_by_gameid($gameid);
468 foreach($userids as $user)
469 if(DB_get_hand_status_by_userid($user)!='gameover')
473 DB_set_game_status_by_gameid($gameid,"gameover");
475 /* email next player */
476 if(DB_get_game_status_by_gameid($gameid)=='play')
480 $play = DB_get_cards_by_trick($trickid);
481 $winner = get_winner($play); /* returns the position */
486 $next = DB_get_pos_by_hash($me)+1;
488 if($next==5) $next=1;
490 /* email next player */
491 $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
492 $email = DB_get_email_by_hash($next_hash);
494 $message = "It's your turn now.\n".
495 "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
496 mymail($email,"[DoKo-debug] a card has been played",$message);
499 echo "DEBUG:<a href=\"index.php?me=".DB_get_hash_from_game_and_pos($gameid,$next).
500 "\"> next player </a> <br />\n";
506 echo "couldn't find card <br />\n";
509 else if(isset($_REQUEST["card"]) && !$myturn )
511 echo "please wait until it is your turn! <br />\n";
514 $mycards = DB_get_hand($me);
516 echo "<div class=\"mycards\">\n";
518 if($myturn && !isset($_REQUEST["card"]))
520 echo "Hello ".$myname.", it's your turn! <br />\n";
521 echo "Your cards are: <br />\n";
522 echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
523 foreach($mycards as $card)
524 display_link_card($card);
526 <br />A short comments:<input name="comment" type="text" size="30" maxlength="50" />
527 <input type="hidden" name="me" value="<?php echo $me; ?>" />
528 <input type="submit" value="move" />
532 else if($mystatus=='play')
534 echo "Your cards are: <br />\n";
535 foreach($mycards as $card)
540 /* check if we need to set status to 'gameover' is done during playing of the card */
541 if($mystatus=='play')
543 /* the following happens only when the gamestatus is 'gameover' */
544 /* check if game is over, display results */
545 if(DB_get_game_status_by_gameid($gameid)=='play')
547 echo "the game is over for you.. other people still need to play though";
551 echo "the game is over now... guess the final score should be displayed here...<br />\n";
553 /* suggest a new game with the same people in it, just rotated once */
554 $names = DB_get_all_names_by_gameid($gameid);
556 echo "Do you want to continue playing?(This will start a new game, with the next person as dealer.)\n";
557 echo "<form action=\"index.php\" method=\"post\">\n";
558 echo " <input type=\"hidden\" name=\"PlayerA\" value=\"".($names[1])."\" />\n";
559 echo " <input type=\"hidden\" name=\"PlayerB\" value=\"".($names[2])."\" />\n";
560 echo " <input type=\"hidden\" name=\"PlayerC\" value=\"".($names[3])."\" />\n";
561 echo " <input type=\"hidden\" name=\"PlayerD\" value=\"".($names[0])."\" />\n";
562 echo " <input type=\"hidden\" name=\"followup\" value=\"".($gameid)."\" />\n";
563 echo " <input type=\"submit\" value=\"keep playing\" />\n";
568 echo "error in testing the status";
572 /* user status page */
573 else if(isset($_REQUEST["email"]) && isset($_REQUEST["password"]))
575 /* test id and password, should really be done in one step */
576 $email = $_REQUEST["email"];
577 $password = $_REQUEST["password"];
579 if(strlen($password)!=32)
580 $password = md5($password);
583 $uid = DB_get_userid_by_email_and_password($email,$password);
589 $time = DB_get_user_timestamp($uid);
590 $unixtime =strtotime($time);
592 $offset = DB_get_user_timezone($uid);
593 $zone = return_timezone($offset);
594 date_default_timezone_set($zone);
596 echo "last login: ".date("r",$unixtime)."<br />";
598 DB_update_user_timestamp($uid);
600 echo "<p>these are the games you are playing in:<br />\n";
601 $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status<>'gameover'" );
602 while( $r = mysql_fetch_array($result,MYSQL_NUM))
603 echo "<a href=\"http://doko.nubati.net/database/index.php?me=".$r[0]."\">game #".$r[1]." </a><br />";
606 $names = DB_get_all_names();
607 echo "<p>registered players:<br />\n";
608 foreach ($names as $name)
609 echo "$name <br />\n";
611 echo "<p>Want to start a new game? remember 4 names from the list above and visit ".
612 "<a href=\"http://doko.nubati.net/database/index.php?new\">this page.</a></p>";
616 echo "sorry email and password don't match <br />";
620 /* page for registration */
621 else if(isset($_REQUEST["register"]) )
623 echo "IMPORTANT: passwords are going over the net as clear text, so pick an easy password. No need to pick anything complicated here ;)<br /><br />";
624 echo "TODO: convert timezone into a menu<br />\n";
625 echo "TODO: figure out a way to handle passwrods <br />\n";
627 <form action="index.php" method="post">
629 <legend>Register</legend>
632 <td><label for="Rfullname">Full name:</label></td>
633 <td><input type="text" id="Rfullname" name="Rfullname" size="20" maxsize="30" /> </td>
635 <td><label for="Remail">Email:</label></td>
636 <td><input type="text" id="Remail" name="Remail" size="20" maxsize="30" /></td>
638 <td><label for="Rpassword">Password(will be displayed in cleartext on the next page):</label></td>
639 <td><input type="password" id="Rpassword" name="Rpassword" size="20" maxsize="30" /></td>
641 <td><label for="Rtimezone">Timezone:</label></td>
643 <input type="text" id="Rtimezone" name="Rtimezone" size="4" maxsize="4" value="+1" />
646 <td colspan="2"> <input type="submit" value="register" /></td>
652 /* new user wants to register */
653 else if(isset($_REQUEST["Rfullname"]) &&
654 isset($_REQUEST["Remail"] ) &&
655 isset($_REQUEST["Rpassword"]) &&
656 isset($_REQUEST["Rtimezone"]) )
659 if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
661 echo "please chose another name<br />";
664 if(DB_get_userid_by_email($_REQUEST["Remail"]))
666 echo "this email address is already used ?!<br />";
671 $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
672 ",".DB_quote_smart($_REQUEST["Remail"]).
673 ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
674 ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
677 echo " added you to the database";
679 echo " something went wrong";
682 /* default login page */
684 { /* no new game, not in a game */
686 <p> If you want to play a game of Doppelkopf, you found the right place ;) </p>
687 <p> Please <a href="index.php?register">register</a>, in case you haven't done yet <br />
688 or login with you email-address or name and password here:
690 <form action="index.php" method="post">
692 <legend>Login</legend>
695 <td><label for="email">Email:</label></td><td><input type="text" id="email" name="email" size="20" maxlength="30" /> </td>
697 <td><label for="password">Password:</label></td><td><input type="password" id="password" name="password" size="20" maxlength="30" /></td>
699 <td> <input type="submit" value="login" /></td>