+ case 'start':
+ check_want_to_play($me);
+ DB_set_hand_status_by_hash($me,'init');
+ break;
+ case 'init':
+ if( !myisset("in","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(!myisset("solo","wedding","poverty","nines") )
+ {
+ /* all these variables have a pre-selected default,
+ * so we should never get here,
+ * unless a user tries to cheat ;) */
+ echo "something went wrong...please contact the admin.";
+ }
+ 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':
+ /* here we need to check if there is a solo or some other form o sickness.
+ * If so, which one counts
+ * set that one in the Game table, delete other ones form Hand table
+ * tell people about it.
+ */
+ 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);
+ $ok=1;
+ foreach($userids as $user)
+ if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
+ $ok=0;
+
+ if($ok)
+ 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 useful things in divs */
+
+ /* 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 the users status page */
+ $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+ output_link_to_user_page($r[0],$r[1]);
+
+ display_news();
+
+ /* end display useful things*/
+
+ /* has the game started? No, then just wait here...*/
+ $gamestatus = DB_get_game_status_by_gameid($gameid);
+ if($gamestatus == 'pre')
+ {
+ echo "you need to wait for the others... <br />";
+ break; /* not sure this works... the idea is that you can
+ * only play a card after everyone is ready to play */
+ }
+
+ /* get everything 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;