+ case 'start':
+ check_want_to_play($me);
+ DB_set_hand_status_by_hash($me,'init');
+ break;
+ case 'init':
+ if( !isset($_REQUEST["in"]) || !isset($_REQUEST["update"]))
+ {
+ DB_set_hand_status_by_hash($me,'start');
+ echo "you need to answer both question";
+ }
+ else
+ {
+ if($_REQUEST["in"] == "no")
+ {
+ echo "TODO: email everyone that the game has been canceled.<br />";
+ /*something like need to modify for DB backend
+ for($i=0;$i<4;$i++)
+ {
+ $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
+ "the game has been canceled due to the request of one of the players.\n";
+ mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
+ }
+ */
+ /* delete everything from the dB */
+ DB_cancel_game($me);
+ }
+ else
+ {
+ echo "thanks for joining the game... please scroll down";
+ echo "TODO: make this page nicer<br />";
+ echo "TODO: set card pref<br />";
+
+ $mycards = DB_get_hand($me);
+ sort($mycards);
+ echo "<p class=\"mycards\">your cards are: <br />\n";
+ foreach($mycards as $card)
+ display_card($card);
+ echo "</p>\n";
+
+ check_for_sickness($me,$mycards);
+
+ DB_set_hand_status_by_hash($me,'check');
+ }
+ }
+ break;
+
+ case 'check':
+ 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.";
+ if(!isset($_REQUEST["solo"]) ||
+ !isset($_REQUEST["wedding"]) ||
+ !isset($_REQUEST["poverty"]) ||
+ !isset($_REQUEST["nines"]) )
+ {
+ DB_set_hand_status_by_hash($me,'init');
+ /* problem: by setting it back to init, variables "in" and "update" are
+ * not set, so the player will be send back to the start, after seeing his hand
+ */
+ echo "you need to fill out the form";
+ }
+ else
+ {
+ if( $_REQUEST["solo"]!="No")
+ {
+ DB_set_solo_by_hash($me,$_REQUEST["solo"]);
+ DB_set_sickness_by_hash($me,"solo");
+ }
+ else if($_REQUEST["wedding"] == "yes")
+ {
+ echo "wedding was chosen<br />\n";
+ DB_set_sickness_by_hash($me,"wedding");
+ }
+ else if($_REQUEST["poverty"] == "yes")
+ {
+ echo "poverty was chosen<br />\n";
+ DB_set_sickness_by_hash($me,"poverty");
+ }
+ else if($_REQUEST["nines"] == "yes")
+ {
+ echo "nines was chosen<br />\n";
+ DB_set_sickness_by_hash($me,"nines");
+ }
+ }
+ DB_set_hand_status_by_hash($me,'poverty');
+
+ /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
+
+ /* reset solo, etc from players who did say something, but it didn't matter? */
+ break;
+ case 'poverty':
+ echo "<br />poverty not handeled at the moment... you need to play a normal game<br />";
+
+ /* only set this after all poverty, etc. are handeled*/
+ DB_set_hand_status_by_hash($me,'play');
+
+ /* check if the game can start */
+ $userids = DB_get_all_userid_by_gameid($gameid);
+ $done=1;
+ foreach($userids as $user)
+ if(DB_get_hand_status_by_userid($user)!='play')
+ $done=0;
+
+ if($done)
+ DB_set_game_status_by_gameid($gameid,'play');
+
+ break;
+ case 'play':
+ 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*/
+ /* display local time */
+ echo "<div class=\"time\">\n Local times:<table>";
+ $users = array();
+ $users = DB_get_all_userid_by_gameid($gameid);
+ foreach($users as $user)
+ {
+ $offset = DB_get_user_timezone($user);
+ $zone = return_timezone($offset);
+ date_default_timezone_set($zone);
+ $name = DB_get_name_by_userid($user);
+
+ echo "<tr> <td>$name</td> <td>".date("Y-m-d H:i:s")."</td></tr>\n";
+ };
+ echo "</table>\n</div>\n";
+ display_status();
+
+ /* display links to other games */
+ echo "<div class=\"over\">\n";
+ $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+ echo "<form action=\"index.php\" method=\"post\">\n";
+ echo " <input type=\"hidden\" name=\"email\" value=\"".$r[0]."\" />\n";
+ echo " <input type=\"hidden\" name=\"password\" value=\"".$r[1]."\" />\n";
+ echo " <input type=\"submit\" value=\"go to my user page\" />\n";
+ echo "</form>\n";
+ echo "</div>\n";
+
+ display_news();
+
+ $gamestatus = DB_get_game_status_by_gameid($gameid);
+ if($gamestatus == 'pre')
+ {
+ echo "you need to wait for the others... <br />";
+ break;
+ }
+ /* get everythin relevant to display the tricks */
+ $result = mysql_query("SELECT Hand_Card.card_id as card,".
+ " User.fullname as name,".
+ " Hand.position as position,".
+ " Play.sequence as sequence, ".
+ " Hand.hash as hash, ".
+ " Trick.id, ".
+ " Comment.comment ".
+ "FROM Trick ".
+ "LEFT JOIN Play ON Trick.id=Play.trick_id ".
+ "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
+ "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
+ "LEFT JOIN User ON User.id=Hand.user_id ".
+ "LEFT JOIN Comment ON Play.id=Comment.play_id ".
+ "WHERE Trick.game_id='".$gameid."' ".
+ "ORDER BY Trick.id,sequence ASC");
+
+
+ $trickNR = 1;
+
+ $lasttrick = DB_get_max_trickid($gameid);
+
+ $play = array(); /* needed to calculate winner later */
+ $seq = 1;
+ $pos = 0;
+
+ echo "\n<ul class=\"oldtrick\">\n";
+ echo " <li> Hello $myname! History: </li>\n";
+
+ while($r = mysql_fetch_array($result,MYSQL_NUM))
+ {
+ $seq = $r[3];
+ $pos = $r[2];
+ $trick = $r[5];
+ $comment = $r[6];
+
+ if($trick!=$lasttrick && $seq==1)
+ {
+ /* start of an old trick? */
+ echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
+ " <div class=\"table\" id=\"trick".$trickNR."\">\n".
+ " <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
+ }
+ else if($trick==$lasttrick && $seq==1)
+ {
+ /* start of a last trick? */
+ echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
+ " <div class=\"table\" id=\"trick".$trickNR."\">\n".
+ " <img class=\"table\" src=\"pics/table".($pos-1).".png\" alt=\"table\" />\n";
+ }
+
+ /* display card */
+ echo " <div class=\"card".($pos-1)."\">\n";
+
+ $play[$pos]=$r[0];
+
+ if($comment!="")
+ echo " <span class=\"comment\">";
+ else
+ echo " <span>";
+
+ /* print name */
+ echo $r[1];
+
+ /* check for comment */
+ if($comment!="")
+ echo "<span>".$comment."</span>";
+ echo "</span>\n ";
+
+ display_card($r[0]);
+
+ echo " </div>\n"; /* end div card */
+
+ /* end of trick? */
+ if($seq==4)
+ {
+ $trickNR++;
+ echo " </div>\n </li>\n"; /* end div table, end li table */
+ }
+ }
+
+ if($seq!=4 && $trickNR>1)
+ echo " </div>\n </li>\n"; /* end div table, end li table */
+
+ echo "</ul>\n";