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>
41 include_once("functions.php");
42 include_once("db.php");
48 /***************** M A I N **************************/
50 /* check if we want to start a new game */
51 if(isset($_REQUEST["new"]))
54 <p> no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct! </p>
55 <form action="index.php" method="post">
56 Name: <input name="PlayerA" type="text" size="10" maxlength="20" />
57 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
58 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
59 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
61 <input type="submit" value="start game" />
65 /* end start a new game */
67 /*check if everything is ready to set up a new game */
68 else if( isset($_REQUEST["PlayerA"]) &&
69 isset($_REQUEST["PlayerB"]) &&
70 isset($_REQUEST["PlayerC"]) &&
71 isset($_REQUEST["PlayerD"]) )
73 $PlayerA = $_REQUEST["PlayerA"];
74 $PlayerB = $_REQUEST["PlayerB"];
75 $PlayerC = $_REQUEST["PlayerC"];
76 $PlayerD = $_REQUEST["PlayerD"];
78 $EmailA = DB_get_email_by_name($PlayerA);
79 $EmailB = DB_get_email_by_name($PlayerB);
80 $EmailC = DB_get_email_by_name($PlayerC);
81 $EmailD = DB_get_email_by_name($PlayerD);
83 if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
85 echo "couldn't find one of the names, please start a new game";
89 $useridA = DB_get_userid_by_name($PlayerA);
90 $useridB = DB_get_userid_by_name($PlayerB);
91 $useridC = DB_get_userid_by_name($PlayerC);
92 $useridD = DB_get_userid_by_name($PlayerD);
94 /* create random numbers */
95 $randomNR = create_array_of_random_numbers();
96 $randomNRstring = join(":",$randomNR);
99 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL, NULL)");
100 $game_id = mysql_insert_id();
103 $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA);
104 $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB);
105 $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC);
106 $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD);
109 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
110 ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,'false','false',NULL)");
111 $hand_idA = mysql_insert_id();
112 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
113 ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,'false','false',NULL)");
114 $hand_idB = mysql_insert_id();
115 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
116 ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,'false','false',NULL)");
117 $hand_idC = mysql_insert_id();
118 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
119 ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,'false','false',NULL)");
120 $hand_idD = mysql_insert_id();
124 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
125 for($i=12;$i<24;$i++)
126 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
127 for($i=24;$i<36;$i++)
128 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
129 for($i=36;$i<48;$i++)
130 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
132 /* send out email, check for error with email */
134 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
135 "Place comments and bug reports here:\n".
136 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
137 "The whole round would consist of the following players:\n".
142 "If you want to join this game, please follow this link:\n\n".
145 mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
146 mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
147 mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
148 mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
153 select fullname,strength,suite,game_id from hand_card left join hand on hand_id=hand.id left join user on user.id=user_id left join card on card_id=card.id where game_id='4'
158 /* end set up a new game */
160 else if(isset($_REQUEST["me"]))
162 /* handle request from one specifig player,
163 * the hash is set on a per game base, so first just handle this game
164 * perhaps also show links to other games in a sidebar
167 $me = $_REQUEST["me"];
169 $myid = DB_get_userid_by_hash($me);
173 echo "Can't find you in the database, please check the url.<br />\n";
174 echo "perhaps the game has been cancled.";
178 $myname = DB_get_name_by_hash($me);
179 $mystatus = DB_get_status_by_hash($me);
184 check_want_to_play($me);
185 DB_set_hand_status_by_hash($me,'init');
189 if( !isset($_REQUEST["in"]) || !isset($_REQUEST["update"]))
191 DB_set_hand_status_by_hash($me,'start');
192 echo "you need to answer both question";
196 if($_REQUEST["in"] == "no")
198 echo "TODO: email everyone that the game has been canceld<br />";
202 $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
203 "the game has been canceled due to the request of one of the players.\n";
204 mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
211 echo "thanks for joining the game... please scroll down";
212 echo "TODO: make this page nicer<br />";
213 echo "TODO: set card pref<br />";
215 $mycards = DB_get_hand($me);
217 echo "<p class=\"mycards\">your cards are: <br />\n";
218 foreach($mycards as $card)
222 check_for_sickness($me,$mycards);
224 DB_set_hand_status_by_hash($me,'check');
230 echo "no checking at the moment... you need to play a normal game";
231 if(!isset($_REQUEST["solo"]) ||
232 !isset($_REQUEST["wedding"]) ||
233 !isset($_REQUEST["poverty"]) ||
234 !isset($_REQUEST["nines"]) )
236 DB_set_hand_status_by_hash($me,'init');
237 /* problem: by setting it back to init, variables "in" and "update" are
238 * not set, so the player will be send back to the start, after seeing his hand
240 echo "you need to fill out the form";
244 if( $_REQUEST["solo"]!="No")
246 DB_set_solo_by_hash($me,$_REQUEST["solo"]);
247 DB_set_sickness_by_hash($me,"solo");
249 else if($_REQUEST["wedding"] == "yes")
251 echo "wedding was chosen<br />\n";
252 DB_set_sickness_by_hash($me,"wedding");
254 else if($_REQUEST["poverty"] == "yes")
256 echo "poverty was chosen<br />\n";
257 DB_set_sickness_by_hash($me,"poverty");
259 else if($_REQUEST["nines"] == "yes")
261 echo "nines was chosen<br />\n";
262 DB_set_sickness_by_hash($me,"nines");
265 DB_set_hand_status_by_hash($me,'poverty');
267 /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
269 /* reset solo, etc from players who did say something, but it didn't matter? */
272 echo "<br />poverty not handeled at the moment... you need to play a normal game<br />";
274 /* only set this after all poverty, etc. are handeled*/
275 DB_set_hand_status_by_hash($me,'play');
282 $gameid = DB_get_gameid_by_hash($me);
285 $result = mysql_query("SELECT hand_card.card_id as card,".
286 " user.fullname as name,".
287 " hand.position as position,".
288 " play.sequence as sequence, ".
289 " hand.hash as hash, ".
292 "LEFT JOIN play ON trick.id=play.trick_id ".
293 "LEFT JOIN hand_card ON play.hand_card_id=hand_card.id ".
294 "LEFT JOIN hand ON hand_card.hand_id=hand.id ".
295 "LEFT JOIN user ON user.id=hand.user_id ".
296 "WHERE trick.game_id='".$gameid."' ".
297 "ORDER BY trick.id,sequence ASC");
302 $lasttrick = DB_get_max_trickid($gameid);
304 $play = array(); /* needed to calculate winner later */
308 echo "\n<ul class=\"oldtrick\">\n";
309 echo " <li> Hello $myname! History: </li>\n";
311 while($r = mysql_fetch_array($result,MYSQL_NUM))
317 if($trick!=$lasttrick && $seq==1)
319 /* start of an old trick? */
320 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
321 " <div class=\"table\" id=\"trick".$trickNR."\">\n".
322 " <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
324 else if($trick==$lasttrick && $seq==1)
326 /* start of a last trick? */
327 echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
328 " <div class=\"table\" id=\"trick".$trickNR."\">\n".
329 " <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />";
333 echo " <div class=\"card".($pos-1)."\">\n";
339 echo " <span class=\"comment\">";
346 /* check for comment */
348 echo "<span>".$comment."</span>";
353 echo " </div>\n"; /* end div card */
359 echo " </div>\n </li>\n"; /* end div table, end li table */
363 echo " </div>\n </li>\n"; /* end div table, end li table */
367 /* whos turn is it? */
370 $winner = get_winner($play); /* returns the position */
377 if($next==5) $next=1;
379 /* my turn?, display cards as links, ask for comments*/
380 if(DB_get_pos_by_hash($me) == $next)
385 /* do we want to play a card? */
386 if(isset($_REQUEST["card"]) && $myturn)
388 $card = $_REQUEST["card"];
389 $handid = DB_get_handid_by_hash($me);
391 /* check if we have card */
392 /* set played in hand_card to true where hand_id and card_id*/
393 $result = mysql_query("SELECT id from hand_card WHERE hand_id='$handid' AND card_id=".DB_quote_smart($card));
394 $r = mysql_fetch_array($result,MYSQL_NUM);
399 mysql_query("UPDATE hand_card SET played='true' WHERE hand_id='$handid' AND card_id=".DB_quote_smart($card));
401 /* get trick id or start new trick */
402 $a = DB_get_current_trickid($gameid);
406 DB_play_card($trickid,$handcardid,$sequence);
407 echo "<div class=\"card\">";
408 echo " you played <br />";
412 if(sizeof(DB_get_hand($me))==0)
413 DB_set_hand_status_by_hash($me,'gameover');
415 echo "TODO: email next player<br />";
419 echo "couldn't find card <br />\n";
422 else if(isset($_REQUEST["card"]) && !$myturn )
424 echo "please wait until it is your turn! <br />\n";
427 $mycards = DB_get_hand($me);
429 echo "<div class=\"mycards\">\n";
431 if($myturn && !isset($_REQUEST["card"]))
433 echo "Hello ".DB_get_name_by_hash($me).", it's your turn! <br />\n";
434 echo "Your cards are: <br />\n";
435 echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
436 foreach($mycards as $card)
437 display_link_card($card);
439 <br />A short comment:<input name="comment" type="text" size="30" maxlength="50" />
440 <input type="hidden" name="me" value="<?php echo $me; ?>" />
441 <input type="submit" value="move" />
447 echo "Your cards are: <br />\n";
448 foreach($mycards as $card)
452 /*check if we still have cards left, else set status to gameover */
456 echo "the game is over... guess the final score should be displayed here...<br />\n";
457 echo "TODO: suggest a new game with the next person as dealer <br />\n";
460 echo "error in testing the status";
464 else if(isset($_REQUEST["email"]) && isset($_REQUEST["password"]))
467 $uid = DB_get_userid_by_email($_REQUEST["email"]);
470 if(!DB_get_userid_by_passwd(md5($_REQUEST["password"])))
475 echo "ok. your logged in, now what? :)<br />";
480 echo "sorry email and password don't match <br />";
484 else if(isset($_REQUEST["register"]) )
486 echo "TODO: convert timezone into a menu<br />\n";
487 echo "TODO: figure out a way to handle passwrods <br />\n";
489 <form action="index.php" method="post">
491 <legend>Register</legend>
494 <td><label for="Rfullname">Full name:</label></td>
495 <td><input type="text" id="Rfullname" name="Rfullname" size="20" maxsize="30" /> </td>
497 <td><label for="Remail">Email:</label></td>
498 <td><input type="text" id="Remail" name="Remail" size="20" maxsize="30" /></td>
500 <td><label for="Rpassword">Password(will be displayed in cleartext on the next page):</label></td>
501 <td><input type="password" id="Rpassword" name="Rpassword" size="20" maxsize="30" /></td>
503 <td><label for="Rtimezone">Timezone:</label></td>
504 <td><input type="text" id="Rtimezone" name="Rtimezone" size="4" maxsize="4" value="+1"/></td>
506 <td colspan="2"> <input type="submit" value="register" /></td>
512 else if(isset($_REQUEST["Rfullname"]) &&
513 isset($_REQUEST["Remail"] ) &&
514 isset($_REQUEST["Rpassword"]) &&
515 isset($_REQUEST["Rtimezone"]) )
518 if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
520 echo "please chose another name<br />";
523 if(DB_get_userid_by_email($_REQUEST["Remail"]))
525 echo "this email address is already used ?!<br />";
530 $r=mysql_query("INSERT INTO user VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
531 ",".DB_quote_smart($_REQUEST["Remail"]).
532 ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
533 ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
536 echo " added you to the database";
538 echo " something went wrong";
542 { /* no new game, not in a game */
544 <p> If you want to play a game of Doppelkopf, you found the right place ;) </p>
545 <p> Please <a href="index.php?register">register</a>, in case you haven't done yet <br />
546 or login with you email-address or name and password here:
547 <form action="index.php" method="post">
549 <legend>Login</legend>
552 <td><label for="email">Email:</label></td><td><input type="text" id="email" name="email" size="20" maxsize="30" /> </td>
554 <td><label for="password">Password:</label></td><td><input type="password" id="password" name="password" size="20" maxsize="30" /></td>
556 <td> <input type="submit" value="login" /></td>