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("output.php"); /* html output only */
46 include_once("db.php"); /* database only */
47 include_once("functions.php"); /* the rest */
51 /***************** M A I N **************************/
53 /* check if we want to start a new game */
54 if(isset($_REQUEST["new"]))
55 output_form_for_new_game();
57 /*check if everything is ready to set up a new game */
58 else if( isset($_REQUEST["PlayerA"]) &&
59 isset($_REQUEST["PlayerB"]) &&
60 isset($_REQUEST["PlayerC"]) &&
61 isset($_REQUEST["PlayerD"]) )
63 $PlayerA = $_REQUEST["PlayerA"];
64 $PlayerB = $_REQUEST["PlayerB"];
65 $PlayerC = $_REQUEST["PlayerC"];
66 $PlayerD = $_REQUEST["PlayerD"];
68 $EmailA = DB_get_email_by_name($PlayerA);
69 $EmailB = DB_get_email_by_name($PlayerB);
70 $EmailC = DB_get_email_by_name($PlayerC);
71 $EmailD = DB_get_email_by_name($PlayerD);
73 if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
75 echo "couldn't find one of the names, please start a new game";
79 $useridA = DB_get_userid_by_name($PlayerA);
80 $useridB = DB_get_userid_by_name($PlayerB);
81 $useridC = DB_get_userid_by_name($PlayerC);
82 $useridD = DB_get_userid_by_name($PlayerD);
84 /* create random numbers */
85 $randomNR = create_array_of_random_numbers();
86 $randomNRstring = join(":",$randomNR);
90 if(isset($_REQUEST["followup"]))
92 $followup= $_REQUEST["followup"];
93 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL,'pre','$followup' ,NULL)");
96 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL,'pre', NULL ,NULL)");
97 $game_id = mysql_insert_id();
100 $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA);
101 $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB);
102 $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC);
103 $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD);
106 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
107 ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,'false','false',NULL)");
108 $hand_idA = mysql_insert_id();
109 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
110 ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,'false','false',NULL)");
111 $hand_idB = mysql_insert_id();
112 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
113 ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,'false','false',NULL)");
114 $hand_idC = mysql_insert_id();
115 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
116 ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,'false','false',NULL)");
117 $hand_idD = mysql_insert_id();
121 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
122 for($i=12;$i<24;$i++)
123 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
124 for($i=24;$i<36;$i++)
125 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
126 for($i=36;$i<48;$i++)
127 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
129 /* send out email, TODO: check for error with email */
131 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
132 "Place comments and bug reports here:\n".
133 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
134 "The whole round would consist of the following players:\n".
139 "If you want to join this game, please follow this link:\n\n".
142 mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
143 mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
144 mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
145 mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
148 /* end set up a new game */
150 else if(isset($_REQUEST["me"]))
152 /* handle request from one specifig player,
153 * the hash is set on a per game base, so first just handle this game
154 * perhaps also show links to other games in a sidebar
157 $me = $_REQUEST["me"];
159 /* test for valid ID */
160 $myid = DB_get_userid_by_hash($me);
163 echo "Can't find you in the database, please check the url.<br />\n";
164 echo "perhaps the game has been cancled.";
168 DB_update_user_timestamp($myid);
170 /* get some information from the DB */
171 $gameid = DB_get_gameid_by_hash($me);
172 $myname = DB_get_name_by_hash($me);
173 $mystatus = DB_get_status_by_hash($me);
178 check_want_to_play($me);
179 DB_set_hand_status_by_hash($me,'init');
182 if( !isset($_REQUEST["in"]) || !isset($_REQUEST["update"]))
184 DB_set_hand_status_by_hash($me,'start');
185 echo "you need to answer both question";
189 if($_REQUEST["in"] == "no")
191 echo "TODO: email everyone that the game has been canceled.<br />";
192 /*something like need to modify for DB backend
195 $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
196 "the game has been canceled due to the request of one of the players.\n";
197 mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
200 /* delete everything from the dB */
205 echo "thanks for joining the game... please scroll down";
206 echo "TODO: make this page nicer<br />";
207 echo "TODO: set card pref<br />";
209 $mycards = DB_get_hand($me);
211 echo "<p class=\"mycards\">your cards are: <br />\n";
212 foreach($mycards as $card)
216 check_for_sickness($me,$mycards);
218 DB_set_hand_status_by_hash($me,'check');
224 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.";
225 if(!isset($_REQUEST["solo"]) ||
226 !isset($_REQUEST["wedding"]) ||
227 !isset($_REQUEST["poverty"]) ||
228 !isset($_REQUEST["nines"]) )
230 DB_set_hand_status_by_hash($me,'init');
231 /* problem: by setting it back to init, variables "in" and "update" are
232 * not set, so the player will be send back to the start, after seeing his hand
234 echo "you need to fill out the form";
238 if( $_REQUEST["solo"]!="No")
240 DB_set_solo_by_hash($me,$_REQUEST["solo"]);
241 DB_set_sickness_by_hash($me,"solo");
243 else if($_REQUEST["wedding"] == "yes")
245 echo "wedding was chosen<br />\n";
246 DB_set_sickness_by_hash($me,"wedding");
248 else if($_REQUEST["poverty"] == "yes")
250 echo "poverty was chosen<br />\n";
251 DB_set_sickness_by_hash($me,"poverty");
253 else if($_REQUEST["nines"] == "yes")
255 echo "nines was chosen<br />\n";
256 DB_set_sickness_by_hash($me,"nines");
259 DB_set_hand_status_by_hash($me,'poverty');
261 /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
263 /* reset solo, etc from players who did say something, but it didn't matter? */
266 echo "<br />poverty not handeled at the moment... you need to play a normal game<br />";
268 /* only set this after all poverty, etc. are handeled*/
269 DB_set_hand_status_by_hash($me,'play');
271 /* check if the game can start */
272 $userids = DB_get_all_userid_by_gameid($gameid);
274 foreach($userids as $user)
275 if(DB_get_hand_status_by_userid($user)!='play')
279 DB_set_game_status_by_gameid($gameid,'play');
283 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*/
284 /* display local time */
285 echo "<div class=\"time\">\n Local times:<table>";
287 $users = DB_get_all_userid_by_gameid($gameid);
288 foreach($users as $user)
290 $offset = DB_get_user_timezone($user);
291 $zone = return_timezone($offset);
292 date_default_timezone_set($zone);
293 $name = DB_get_name_by_userid($user);
295 echo "<tr> <td>$name</td> <td>".date("Y-m-d H:i:s")."</td></tr>\n";
297 echo "</table>\n</div>\n";
300 /* display links to other games */
301 echo "<div class=\"over\">\n";
302 $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
303 $r = mysql_fetch_array($result,MYSQL_NUM);
304 echo "<form action=\"index.php\" method=\"post\">\n";
305 echo " <input type=\"hidden\" name=\"email\" value=\"".$r[0]."\" />\n";
306 echo " <input type=\"hidden\" name=\"password\" value=\"".$r[1]."\" />\n";
307 echo " <input type=\"submit\" value=\"go to my user page\" />\n";
313 $gamestatus = DB_get_game_status_by_gameid($gameid);
314 if($gamestatus == 'pre')
316 echo "you need to wait for the others... <br />";
319 /* get everythin relevant to display the tricks */
320 $result = mysql_query("SELECT Hand_Card.card_id as card,".
321 " User.fullname as name,".
322 " Hand.position as position,".
323 " Play.sequence as sequence, ".
324 " Hand.hash as hash, ".
328 "LEFT JOIN Play ON Trick.id=Play.trick_id ".
329 "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
330 "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
331 "LEFT JOIN User ON User.id=Hand.user_id ".
332 "LEFT JOIN Comment ON Play.id=Comment.play_id ".
333 "WHERE Trick.game_id='".$gameid."' ".
334 "ORDER BY Trick.id,sequence ASC");
339 $lasttrick = DB_get_max_trickid($gameid);
341 $play = array(); /* needed to calculate winner later */
345 echo "\n<ul class=\"oldtrick\">\n";
346 echo " <li> Hello $myname! History: </li>\n";
348 while($r = mysql_fetch_array($result,MYSQL_NUM))
355 if($trick!=$lasttrick && $seq==1)
357 /* start of an old trick? */
358 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
359 " <div class=\"table\" id=\"trick".$trickNR."\">\n".
360 " <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
362 else if($trick==$lasttrick && $seq==1)
364 /* start of a last trick? */
365 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
366 " <div class=\"table\" id=\"trick".$trickNR."\">\n".
367 " <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
371 echo " <div class=\"card".($pos-1)."\">\n";
376 echo " <span class=\"comment\">";
383 /* check for comment */
385 echo "<span>".$comment."</span>";
390 echo " </div>\n"; /* end div card */
396 echo " </div>\n </li>\n"; /* end div table, end li table */
400 if($seq!=4 && $trickNR>1)
401 echo " </div>\n </li>\n"; /* end div table, end li table */
405 /* whos turn is it? */
408 $winner = get_winner($play); /* returns the position */
415 if($next==5) $next=1;
417 /* my turn?, display cards as links, ask for comments*/
418 if(DB_get_pos_by_hash($me) == $next)
423 /* do we want to play a card? */
424 if(isset($_REQUEST["card"]) && $myturn)
426 $card = $_REQUEST["card"];
427 $handid = DB_get_handid_by_hash($me);
429 /* check if we have card and that we haven't played it yet*/
430 /* set played in hand_card to true where hand_id and card_id*/
431 $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
432 "hand_id='$handid' AND card_id=".DB_quote_smart($card));
433 $r = mysql_fetch_array($result,MYSQL_NUM);
438 mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".DB_quote_smart($card));
440 /* get trick id or start new trick */
441 $a = DB_get_current_trickid($gameid);
445 $playid = DB_play_card($trickid,$handcardid,$sequence);
447 /*check for coment */
448 if(isset($_REQUEST["comment"]))
450 DB_insert_comment($_REQUEST["comment"],$playid,$myid);
453 echo "<div class=\"card\">";
454 echo " you played <br />";
459 /*check if we still have cards left, else set status to gameover */
460 if(sizeof(DB_get_hand($me))==0)
462 DB_set_hand_status_by_hash($me,'gameover');
463 $mystatus='gameover';
466 /* if all players are done, set game status also to game over */
467 $userids = DB_get_all_userid_by_gameid($gameid);
469 foreach($userids as $user)
470 if(DB_get_hand_status_by_userid($user)!='gameover')
474 DB_set_game_status_by_gameid($gameid,"gameover");
476 /* email next player */
477 if(DB_get_game_status_by_gameid($gameid)=='play')
481 $play = DB_get_cards_by_trick($trickid);
482 $winner = get_winner($play); /* returns the position */
487 $next = DB_get_pos_by_hash($me)+1;
489 if($next==5) $next=1;
491 /* email next player */
492 $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
493 $email = DB_get_email_by_hash($next_hash);
495 $message = "It's your turn now.\n".
496 "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
497 mymail($email,"[DoKo-debug] a card has been played",$message);
500 echo "DEBUG:<a href=\"index.php?me=".DB_get_hash_from_game_and_pos($gameid,$next).
501 "\"> next player </a> <br />\n";
507 echo "couldn't find card <br />\n";
510 else if(isset($_REQUEST["card"]) && !$myturn )
512 echo "please wait until it is your turn! <br />\n";
515 $mycards = DB_get_hand($me);
517 echo "<div class=\"mycards\">\n";
519 if($myturn && !isset($_REQUEST["card"]))
521 echo "Hello ".$myname.", it's your turn! <br />\n";
522 echo "Your cards are: <br />\n";
523 echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
524 foreach($mycards as $card)
525 display_link_card($card);
527 <br />A short comments:<input name="comment" type="text" size="30" maxlength="50" />
528 <input type="hidden" name="me" value="<?php echo $me; ?>" />
529 <input type="submit" value="move" />
533 else if($mystatus=='play')
535 echo "Your cards are: <br />\n";
536 foreach($mycards as $card)
541 /* check if we need to set status to 'gameover' is done during playing of the card */
542 if($mystatus=='play')
544 /* the following happens only when the gamestatus is 'gameover' */
545 /* check if game is over, display results */
546 if(DB_get_game_status_by_gameid($gameid)=='play')
548 echo "the game is over for you.. other people still need to play though";
552 echo "the game is over now... guess the final score should be displayed here...<br />\n";
554 /* suggest a new game with the same people in it, just rotated once */
555 $names = DB_get_all_names_by_gameid($gameid);
557 echo "Do you want to continue playing?(This will start a new game, with the next person as dealer.)\n";
558 echo "<form action=\"index.php\" method=\"post\">\n";
559 echo " <input type=\"hidden\" name=\"PlayerA\" value=\"".($names[1])."\" />\n";
560 echo " <input type=\"hidden\" name=\"PlayerB\" value=\"".($names[2])."\" />\n";
561 echo " <input type=\"hidden\" name=\"PlayerC\" value=\"".($names[3])."\" />\n";
562 echo " <input type=\"hidden\" name=\"PlayerD\" value=\"".($names[0])."\" />\n";
563 echo " <input type=\"hidden\" name=\"followup\" value=\"".($gameid)."\" />\n";
564 echo " <input type=\"submit\" value=\"keep playing\" />\n";
569 echo "error in testing the status";
573 /* user status page */
574 else if(isset($_REQUEST["email"]) && isset($_REQUEST["password"]))
576 /* test id and password, should really be done in one step */
577 $email = $_REQUEST["email"];
578 $password = $_REQUEST["password"];
580 if(strlen($password)!=32)
581 $password = md5($password);
584 $uid = DB_get_userid_by_email_and_password($email,$password);
590 $time = DB_get_user_timestamp($uid);
591 $unixtime =strtotime($time);
593 $offset = DB_get_user_timezone($uid);
594 $zone = return_timezone($offset);
595 date_default_timezone_set($zone);
597 echo "last login: ".date("r",$unixtime)."<br />";
599 DB_update_user_timestamp($uid);
601 echo "<p>these are the games you are playing in:<br />\n";
602 $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status<>'gameover'" );
603 while( $r = mysql_fetch_array($result,MYSQL_NUM))
604 echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a><br />";
607 $names = DB_get_all_names();
608 echo "<p>registered players:<br />\n";
609 foreach ($names as $name)
610 echo "$name <br />\n";
612 echo "<p>Want to start a new game? remember 4 names from the list above and visit ".
613 "<a href=\"".$host."?new\">this page.</a></p>";
617 echo "sorry email and password don't match <br />";
621 /* page for registration */
622 else if(isset($_REQUEST["register"]) )
624 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 />";
625 echo "TODO: convert timezone into a menu<br />\n";
626 echo "TODO: figure out a way to handle passwrods <br />\n";
628 <form action="index.php" method="post">
630 <legend>Register</legend>
633 <td><label for="Rfullname">Full name:</label></td>
634 <td><input type="text" id="Rfullname" name="Rfullname" size="20" maxsize="30" /> </td>
636 <td><label for="Remail">Email:</label></td>
637 <td><input type="text" id="Remail" name="Remail" size="20" maxsize="30" /></td>
639 <td><label for="Rpassword">Password(will be displayed in cleartext on the next page):</label></td>
640 <td><input type="password" id="Rpassword" name="Rpassword" size="20" maxsize="30" /></td>
642 <td><label for="Rtimezone">Timezone:</label></td>
644 <input type="text" id="Rtimezone" name="Rtimezone" size="4" maxsize="4" value="+1" />
647 <td colspan="2"> <input type="submit" value="register" /></td>
653 /* new user wants to register */
654 else if(isset($_REQUEST["Rfullname"]) &&
655 isset($_REQUEST["Remail"] ) &&
656 isset($_REQUEST["Rpassword"]) &&
657 isset($_REQUEST["Rtimezone"]) )
660 if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
662 echo "please chose another name<br />";
665 if(DB_get_userid_by_email($_REQUEST["Remail"]))
667 echo "this email address is already used ?!<br />";
672 $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
673 ",".DB_quote_smart($_REQUEST["Remail"]).
674 ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
675 ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
678 echo " added you to the database";
680 echo " something went wrong";
683 /* default login page */
685 { /* no new game, not in a game */