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="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>
40 error_reporting(E_ALL);
42 include_once("config.php");
43 include_once("functions.php");
44 include_once("db.php");
50 /***************** M A I N **************************/
52 /* check if we want to start a new game */
53 if(isset($_REQUEST["new"]))
56 <p>Please add 4 names, please make sure that the names are correct! </p>
57 <form action="index.php" method="post">
58 Name: <input name="PlayerA" type="text" size="10" maxlength="20" />
59 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
60 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
61 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
63 <input type="submit" value="start game" />
67 /* end start a new game */
69 /*check if everything is ready to set up a new game */
70 else if( isset($_REQUEST["PlayerA"]) &&
71 isset($_REQUEST["PlayerB"]) &&
72 isset($_REQUEST["PlayerC"]) &&
73 isset($_REQUEST["PlayerD"]) )
75 $PlayerA = $_REQUEST["PlayerA"];
76 $PlayerB = $_REQUEST["PlayerB"];
77 $PlayerC = $_REQUEST["PlayerC"];
78 $PlayerD = $_REQUEST["PlayerD"];
80 $EmailA = DB_get_email_by_name($PlayerA);
81 $EmailB = DB_get_email_by_name($PlayerB);
82 $EmailC = DB_get_email_by_name($PlayerC);
83 $EmailD = DB_get_email_by_name($PlayerD);
85 if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
87 echo "couldn't find one of the names, please start a new game";
91 $useridA = DB_get_userid_by_name($PlayerA);
92 $useridB = DB_get_userid_by_name($PlayerB);
93 $useridC = DB_get_userid_by_name($PlayerC);
94 $useridD = DB_get_userid_by_name($PlayerD);
96 /* create random numbers */
97 $randomNR = create_array_of_random_numbers();
98 $randomNRstring = join(":",$randomNR);
102 if(isset($_REQUEST["followup"]))
104 $followup= $_REQUEST["followup"];
105 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL,'pre','$followup' ,NULL)");
108 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL,'pre', NULL ,NULL)");
109 $game_id = mysql_insert_id();
112 $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA);
113 $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB);
114 $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC);
115 $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD);
118 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
119 ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,'false','false',NULL)");
120 $hand_idA = mysql_insert_id();
121 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
122 ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,'false','false',NULL)");
123 $hand_idB = mysql_insert_id();
124 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
125 ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,'false','false',NULL)");
126 $hand_idC = mysql_insert_id();
127 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
128 ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,'false','false',NULL)");
129 $hand_idD = mysql_insert_id();
133 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
134 for($i=12;$i<24;$i++)
135 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
136 for($i=24;$i<36;$i++)
137 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
138 for($i=36;$i<48;$i++)
139 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
141 /* send out email, check for error with email */
143 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
144 "Place comments and bug reports here:\n".
145 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
146 "The whole round would consist of the following players:\n".
151 "If you want to join this game, please follow this link:\n\n".
154 mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
155 mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
156 mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
157 mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
160 /* end set up a new game */
162 else if(isset($_REQUEST["me"]))
164 /* handle request from one specifig player,
165 * the hash is set on a per game base, so first just handle this game
166 * perhaps also show links to other games in a sidebar
169 $me = $_REQUEST["me"];
171 $myid = DB_get_userid_by_hash($me);
175 echo "Can't find you in the database, please check the url.<br />\n";
176 echo "perhaps the game has been cancled.";
180 DB_update_user_timestamp($myid);
181 $myname = DB_get_name_by_hash($me);
182 $mystatus = DB_get_status_by_hash($me);
185 $gameid = DB_get_gameid_by_hash($me);
190 check_want_to_play($me);
191 DB_set_hand_status_by_hash($me,'init');
195 if( !isset($_REQUEST["in"]) || !isset($_REQUEST["update"]))
197 DB_set_hand_status_by_hash($me,'start');
198 echo "you need to answer both question";
202 if($_REQUEST["in"] == "no")
204 echo "TODO: email everyone that the game has been canceld<br />";
208 $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
209 "the game has been canceled due to the request of one of the players.\n";
210 mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
217 echo "thanks for joining the game... please scroll down";
218 echo "TODO: make this page nicer<br />";
219 echo "TODO: set card pref<br />";
221 $mycards = DB_get_hand($me);
223 echo "<p class=\"mycards\">your cards are: <br />\n";
224 foreach($mycards as $card)
228 check_for_sickness($me,$mycards);
230 DB_set_hand_status_by_hash($me,'check');
236 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.";
237 if(!isset($_REQUEST["solo"]) ||
238 !isset($_REQUEST["wedding"]) ||
239 !isset($_REQUEST["poverty"]) ||
240 !isset($_REQUEST["nines"]) )
242 DB_set_hand_status_by_hash($me,'init');
243 /* problem: by setting it back to init, variables "in" and "update" are
244 * not set, so the player will be send back to the start, after seeing his hand
246 echo "you need to fill out the form";
250 if( $_REQUEST["solo"]!="No")
252 DB_set_solo_by_hash($me,$_REQUEST["solo"]);
253 DB_set_sickness_by_hash($me,"solo");
255 else if($_REQUEST["wedding"] == "yes")
257 echo "wedding was chosen<br />\n";
258 DB_set_sickness_by_hash($me,"wedding");
260 else if($_REQUEST["poverty"] == "yes")
262 echo "poverty was chosen<br />\n";
263 DB_set_sickness_by_hash($me,"poverty");
265 else if($_REQUEST["nines"] == "yes")
267 echo "nines was chosen<br />\n";
268 DB_set_sickness_by_hash($me,"nines");
271 DB_set_hand_status_by_hash($me,'poverty');
273 /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
275 /* reset solo, etc from players who did say something, but it didn't matter? */
278 echo "<br />poverty not handeled at the moment... you need to play a normal game<br />";
280 /* only set this after all poverty, etc. are handeled*/
281 DB_set_hand_status_by_hash($me,'play');
283 /* check if the game can start */
284 $userids = DB_get_all_userid_by_gameid($gameid);
286 foreach($userids as $user)
287 if(DB_get_hand_status_by_userid($user)!='play')
291 DB_set_game_status_by_gameid($gameid,'play');
295 case 'gameover': /* gameover and play, so that the tricks are visible for both */
299 $gamestatus =DB_get_game_status_by_gameid($gameid);
300 if($gamestatus == 'pre')
302 echo "you need to wait for the others... <br />";
306 $result = mysql_query("SELECT Hand_Card.card_id as card,".
307 " User.fullname as name,".
308 " Hand.position as position,".
309 " Play.sequence as sequence, ".
310 " Hand.hash as hash, ".
314 "LEFT JOIN Play ON Trick.id=Play.trick_id ".
315 "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
316 "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
317 "LEFT JOIN User ON User.id=Hand.user_id ".
318 "LEFT JOIN Comment ON Play.id=Comment.play_id ".
319 "WHERE Trick.game_id='".$gameid."' ".
320 "ORDER BY Trick.id,sequence ASC");
325 $lasttrick = DB_get_max_trickid($gameid);
327 $play = array(); /* needed to calculate winner later */
331 echo "\n<ul class=\"oldtrick\">\n";
332 echo " <li> Hello $myname! History: </li>\n";
334 while($r = mysql_fetch_array($result,MYSQL_NUM))
341 if($trick!=$lasttrick && $seq==1)
343 /* start of an old trick? */
344 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
345 " <div class=\"table\" id=\"trick".$trickNR."\">\n".
346 " <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
348 else if($trick==$lasttrick && $seq==1)
350 /* start of a last trick? */
351 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
352 " <div class=\"table\" id=\"trick".$trickNR."\">\n".
353 " <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />";
357 echo " <div class=\"card".($pos-1)."\">\n";
362 echo " <span class=\"comment\">";
369 /* check for comment */
371 echo "<span>".$comment."</span>";
376 echo " </div>\n"; /* end div card */
382 echo " </div>\n </li>\n"; /* end div table, end li table */
386 echo " </div>\n </li>\n"; /* end div table, end li table */
390 /* whos turn is it? */
393 $winner = get_winner($play); /* returns the position */
400 if($next==5) $next=1;
402 /* my turn?, display cards as links, ask for comments*/
403 if(DB_get_pos_by_hash($me) == $next)
408 /* do we want to play a card? */
409 if(isset($_REQUEST["card"]) && $myturn)
411 $card = $_REQUEST["card"];
412 $handid = DB_get_handid_by_hash($me);
414 /* check if we have card and that we haven't played it yet*/
415 /* set played in hand_card to true where hand_id and card_id*/
416 $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
417 "hand_id='$handid' AND card_id=".DB_quote_smart($card));
418 $r = mysql_fetch_array($result,MYSQL_NUM);
423 mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".DB_quote_smart($card));
425 /* get trick id or start new trick */
426 $a = DB_get_current_trickid($gameid);
430 $playid = DB_play_card($trickid,$handcardid,$sequence);
432 /*check for coment */
433 if(isset($_REQUEST["comment"]))
435 DB_insert_comment($_REQUEST["comment"],$playid,$myid);
438 echo "<div class=\"card\">";
439 echo " you played <br />";
444 /*check if we still have cards left, else set status to gameover */
445 if(sizeof(DB_get_hand($me))==0)
447 DB_set_hand_status_by_hash($me,'gameover');
448 $mystatus='gameover';
451 /* if all players are done, set game status also to game over */
452 $userids = DB_get_all_userid_by_gameid($gameid);
454 foreach($userids as $user)
455 if(DB_get_hand_status_by_userid($user)!='gameover')
459 DB_set_game_status_by_gameid($gameid,"gameover");
461 /* email next player */
462 if(DB_get_game_status_by_gameid($gameid)=='play')
466 $play = DB_get_cards_by_trick($trickid);
467 $winner = get_winner($play); /* returns the position */
472 $next = DB_get_pos_by_hash($me)+1;
474 if($next==5) $next=1;
476 echo "TODO: email next player at pos $next <br />";
478 echo "DEBUG:<a href=\"index.php?me=".DB_get_hash_from_game_and_pos($gameid,$next).
479 "\"> next player </a> <br />\n";
485 echo "couldn't find card <br />\n";
488 else if(isset($_REQUEST["card"]) && !$myturn )
490 echo "please wait until it is your turn! <br />\n";
493 $mycards = DB_get_hand($me);
495 echo "<div class=\"mycards\">\n";
497 if($myturn && !isset($_REQUEST["card"]))
499 echo "Hello ".$myname.", it's your turn! <br />\n";
500 echo "Your cards are: <br />\n";
501 echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
502 foreach($mycards as $card)
503 display_link_card($card);
505 <br />A short comments:<input name="comment" type="text" size="30" maxlength="50" />
506 <input type="hidden" name="me" value="<?php echo $me; ?>" />
507 <input type="submit" value="move" />
511 else if($mystatus=='play')
513 echo "Your cards are: <br />\n";
514 foreach($mycards as $card)
519 /* check if we need to set status to 'gameover' is done during playing of the card */
520 if($mystatus=='play')
522 /* the following happens only when the gamestatus is 'gameover' */
523 /* check if game is over, display results */
524 if(DB_get_game_status_by_gameid($gameid)=='play')
526 echo "the game is over for you.. other people still need to play though";
530 echo "the game is over now... guess the final score should be displayed here...<br />\n";
532 /* suggest a new game with the same people in it, just rotated once */
533 $names = DB_get_all_names_by_gameid($gameid);
535 echo "Do you want to continue playing?(This will start a new game, with the next person as dealer.)\n";
536 echo "<form action=\"index.php\" methog=\"post\">\n";
537 echo " <input type=\"hidden\" name=\"PlayerA\" value=\"".($names[1])."\" />\n";
538 echo " <input type=\"hidden\" name=\"PlayerB\" value=\"".($names[2])."\" />\n";
539 echo " <input type=\"hidden\" name=\"PlayerC\" value=\"".($names[3])."\" />\n";
540 echo " <input type=\"hidden\" name=\"PlayerD\" value=\"".($names[0])."\" />\n";
541 echo " <input type=\"hidden\" name=\"followup\" value=\"".($gameid)."\" />\n";
542 echo " <input type=\"submit\" value=\"keep playing\" />\n";
547 echo "error in testing the status";
551 else if(isset($_REQUEST["email"]) && isset($_REQUEST["password"]))
554 $uid = DB_get_userid_by_email($_REQUEST["email"]);
557 if(!DB_get_userid_by_passwd(md5($_REQUEST["password"])))
562 $time = DB_get_user_timestamp($uid);
563 $unixtime =strtotime($time);
565 $offset = DB_get_user_timezone($uid);
566 $zone = return_timezone($offset);
567 date_default_timezone_set($zone);
569 echo "ok. your logged in, now what? :) <br />last login: ";
570 echo date("r",$unixtime)."<br />";
572 DB_update_user_timestamp($uid);
574 echo "<p>these are the games you are playing in:<br />\n";
575 $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status<>'gameover'" );
576 while( $r = mysql_fetch_array($result,MYSQL_NUM))
577 echo "<a href=\"http://doko.nubati.net/database/index.php?me=".$r[0]."\">game #".$r[1]." </a><br />";
580 $names = DB_get_all_names();
581 echo "<p>registered players:<br />\n";
582 foreach ($names as $name)
583 echo "$name <br />\n";
585 echo "<p>Want to start a new game? remember 4 names from the list above and visit ".
586 "<a href=\"http://doko.nubati.net/database/index.php?new\">this page.</a></p>";
590 echo "sorry email and password don't match <br />";
594 else if(isset($_REQUEST["register"]) )
596 echo "TODO: convert timezone into a menu<br />\n";
597 echo "TODO: figure out a way to handle passwrods <br />\n";
599 <form action="index.php" method="post">
601 <legend>Register</legend>
604 <td><label for="Rfullname">Full name:</label></td>
605 <td><input type="text" id="Rfullname" name="Rfullname" size="20" maxsize="30" /> </td>
607 <td><label for="Remail">Email:</label></td>
608 <td><input type="text" id="Remail" name="Remail" size="20" maxsize="30" /></td>
610 <td><label for="Rpassword">Password(will be displayed in cleartext on the next page):</label></td>
611 <td><input type="password" id="Rpassword" name="Rpassword" size="20" maxsize="30" /></td>
613 <td><label for="Rtimezone">Timezone:</label></td>
615 <input type="text" id="Rtimezone" name="Rtimezone" size="4" maxsize="4" value="+1" />
618 <td colspan="2"> <input type="submit" value="register" /></td>
624 else if(isset($_REQUEST["Rfullname"]) &&
625 isset($_REQUEST["Remail"] ) &&
626 isset($_REQUEST["Rpassword"]) &&
627 isset($_REQUEST["Rtimezone"]) )
630 if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
632 echo "please chose another name<br />";
635 if(DB_get_userid_by_email($_REQUEST["Remail"]))
637 echo "this email address is already used ?!<br />";
642 $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
643 ",".DB_quote_smart($_REQUEST["Remail"]).
644 ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
645 ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
648 echo " added you to the database";
650 echo " something went wrong";
654 { /* no new game, not in a game */
656 <p> If you want to play a game of Doppelkopf, you found the right place ;) </p>
657 <p> Please <a href="index.php?register">register</a>, in case you haven't done yet <br />
658 or login with you email-address or name and password here:
659 <form action="index.php" method="post">
661 <legend>Login</legend>
664 <td><label for="email">Email:</label></td><td><input type="text" id="email" name="email" size="20" maxsize="30" /> </td>
666 <td><label for="password">Password:</label></td><td><input type="password" id="password" name="password" size="20" maxsize="30" /></td>
668 <td> <input type="submit" value="login" /></td>