-
- 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_news();
- display_status();
-
- $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";
-
- /* whos turn is it? */
- if($seq==4)
- {
- $winner = get_winner($play); /* returns the position */
- $next = $winner;
- }
- else
- {
- $next = $pos+1;
- }
- if($next==5) $next=1;
-
- /* my turn?, display cards as links, ask for comments*/
- if(DB_get_pos_by_hash($me) == $next)
- $myturn = 1;
- else
- $myturn = 0;
-
- /* do we want to play a card? */
- if(isset($_REQUEST["card"]) && $myturn)
- {
- $card = $_REQUEST["card"];
- $handid = DB_get_handid_by_hash($me);
-
- /* check if we have card and that we haven't played it yet*/
- /* set played in hand_card to true where hand_id and card_id*/
- $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
- "hand_id='$handid' AND card_id=".DB_quote_smart($card));
- $r = mysql_fetch_array($result,MYSQL_NUM);
- $handcardid = $r[0];
-
- if($handcardid)
- {
- mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".DB_quote_smart($card));
-
- /* get trick id or start new trick */
- $a = DB_get_current_trickid($gameid);
- $trickid = $a[0];
- $sequence = $a[1];
-
- $playid = DB_play_card($trickid,$handcardid,$sequence);
-
- /*check for coment */
- if(isset($_REQUEST["comment"]))
- {
- DB_insert_comment($_REQUEST["comment"],$playid,$myid);
- };
-
- echo "<div class=\"card\">";
- echo " you played <br />";
- display_card($card);
- echo "</div>\n";
-
-
- /*check if we still have cards left, else set status to gameover */
- if(sizeof(DB_get_hand($me))==0)
- {
- DB_set_hand_status_by_hash($me,'gameover');
- $mystatus='gameover';
- }
-
- /* if all players are done, set game status also to game over */
- $userids = DB_get_all_userid_by_gameid($gameid);
- $done=1;
- foreach($userids as $user)
- if(DB_get_hand_status_by_userid($user)!='gameover')
- $done=0;
-
- if($done)
- DB_set_game_status_by_gameid($gameid,"gameover");
-
- /* email next player */
- if(DB_get_game_status_by_gameid($gameid)=='play')
- {
- if($sequence==4)
- {
- $play = DB_get_cards_by_trick($trickid);
- $winner = get_winner($play); /* returns the position */
- $next = $winner;
- }
- else
- {
- $next = DB_get_pos_by_hash($me)+1;
- }
- if($next==5) $next=1;
-
- /* email next player */
- $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
- $email = DB_get_email_by_hash($next_hash);
-
- $message .= "It's your turn now.\n".
- "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
- mymail($email,"[DoKo-debug] a card has been played",$message);
-
- if($debug)
- echo "DEBUG:<a href=\"index.php?me=".DB_get_hash_from_game_and_pos($gameid,$next).
- "\"> next player </a> <br />\n";
-
- }
- }
- else
- {
- echo "couldn't find card <br />\n";
- }
- }
- else if(isset($_REQUEST["card"]) && !$myturn )
- {
- echo "please wait until it is your turn! <br />\n";
- }
-
- $mycards = DB_get_hand($me);
- sort($mycards);
- echo "<div class=\"mycards\">\n";
-
- if($myturn && !isset($_REQUEST["card"]))
- {
- echo "Hello ".$myname.", it's your turn! <br />\n";
- echo "Your cards are: <br />\n";
- echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
- foreach($mycards as $card)
- display_link_card($card);
-?>
- <br />A short comments:<input name="comment" type="text" size="30" maxlength="50" />
- <input type="hidden" name="me" value="<?php echo $me; ?>" />
- <input type="submit" value="move" />
- </form>
- <?php
- }
- else if($mystatus=='play')
- {
- echo "Your cards are: <br />\n";
- foreach($mycards as $card)
+
+ /* check what kind of game we are playing */
+ $gametype = DB_get_gametype_by_gameid($gameid);
+ $startplayer = DB_get_startplayer_by_gameid($gameid);
+
+ /* nines? */
+ $nines = 0;
+ /* check for nines */
+ foreach($userids as $user)
+ if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'nines')
+ $nines = $user;
+
+ /* gamestatus == normal, => cancel game */
+ if($nines && $gamestatus == "normal")
+ {
+ /* TODO: set game type to nines to be able to keep statistics? */
+ $message = "Hello, \n\n".
+ "the game has been canceled because ".DB_get_name_by_userid($nines)." has five or more nines.\n";
+
+ $userids = DB_get_all_userid_by_gameid($gameid);
+ foreach($userids as $user)
+ {
+ $To = DB_get_email_by_userid($user);
+ mymail($To,$EmailName."game canceled",$message);
+ }
+
+ /* delete everything from the dB */
+ DB_cancel_game($me);
+ }
+
+ /* check players for poverty */
+ $poverty = 0;
+ foreach($userids as $user)
+ {
+ if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'poverty')
+ {
+ $poverty++;
+ $name = DB_get_name_by_userid($user);
+ echo "$name has a Vorbehalt. <br />";
+ }
+ }
+ /* if gamestatus == normal, set poverty or dpovert (in case two people have poverty) */
+
+ /* check players for wedding */
+ $wedding = 0;
+ foreach($userids as $user)
+ {
+ if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'wedding')
+ {
+ $wedding++;
+ $name = DB_get_name_by_userid($user);
+ echo "$name has a Vorbehalt. <br />" ;
+ }
+ }
+
+ /* if gamestatus == normal, set wedding */
+
+ }
+
+ 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
+ */
+
+ /* figure out what kind of game we are playing,
+ * set the global variables $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES
+ * accordingly
+ */
+
+ $gametype = DB_get_gametype_by_gameid($gameid);
+ $GT = $gametype;
+ if($gametype=="solo")
+ {
+ $gametype = DB_get_solo_by_gameid($gameid);
+ $GT = $gametype." ".$GT;
+ }
+ else
+ $gametype="normal";
+
+ set_gametype($gametype);
+
+ /* get some infos about the game */
+ $gamestatus = DB_get_game_status_by_gameid($gameid);
+
+ /* 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";
+
+ if($gamestatus != 'pre')
+ display_status($GT);
+
+ /* 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...*/
+ 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 */
+ }
+
+ /* display the table and the names */
+ $result = mysql_query("SELECT User.fullname as name,".
+ " Hand.position as position ".
+ "FROM Hand ".
+ "LEFT JOIN User ON User.id=Hand.user_id ".
+ "WHERE Hand.game_id='".$gameid."' ".
+ "ORDER BY position ASC");
+
+ echo "<div class=\"table\">\n".
+ " <img src=\"pics/table.png\" alt=\"table\" />\n";
+ while($r = mysql_fetch_array($result,MYSQL_NUM))
+ {
+ $name = $r[0];
+ $pos = $r[1];
+
+ echo " <span class=\"table".($pos-1)."\">$name</span>\n";
+ }
+ echo "</div>\n";
+
+ /* get everything relevant to display the tricks */
+ $result = mysql_query("SELECT Hand_Card.card_id as card,".
+ " Hand.position as position,".
+ " Play.sequence as sequence, ".
+ " 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 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 = DB_get_startplayer_by_gameid($gameid)-1;
+ $firstcard = ""; /* first card in a trick */
+
+ echo "\n<ul class=\"tricks\">\n";
+ echo " <li> Hello $myname! History: </li>\n";
+
+ while($r = mysql_fetch_array($result,MYSQL_NUM))
+ {
+ $pos = $r[1];
+ $seq = $r[2];
+ $trick = $r[3];
+ $comment = $r[4];
+
+ /* save card to be able to find the winner of the trick later */
+ $play[$pos] = $r[0];
+
+ if($seq==1)
+ {
+ /* first card in a trick, output some html */
+ if($trick!=$lasttrick)
+ {
+ /* start of an old trick? */
+ echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
+ " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
+ " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
+ }
+ else if($trick==$lasttrick)
+ {
+ /* start of a last trick? */
+ echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
+ " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
+ " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
+ };
+
+ /* remember first card, so that we are able to check, what cards can be played */
+ $firstcard = $r[0];
+ };
+
+ /* display card */
+ echo " <div class=\"card".($pos-1)."\">\n";
+
+ /* display comments */
+ if($comment!="")
+ echo " <span class=\"comment\">".$comment."</span>\n";
+
+ echo " ";
+ 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";
+
+ /* whos turn is it? */
+ if($seq==4)
+ {
+ $winner = get_winner($play,$gametype); /* returns the position */
+ $next = $winner;
+ $firstcard = ""; /* new trick, no first card */
+ }
+ else
+ {
+ $next = $pos+1;
+ if($next==5) $next=1;
+ }
+
+ /* my turn?, display cards as links, ask for comments*/
+ if(DB_get_pos_by_hash($me) == $next)
+ $myturn = 1;
+ else
+ $myturn = 0;
+
+ /* do we want to play a card? */
+ if(myisset("card") && $myturn)
+ {
+ $card = $_REQUEST["card"];
+ $handid = DB_get_handid_by_hash($me);
+
+ /* check if we have card and that we haven't played it yet*/
+ /* set played in hand_card to true where hand_id and card_id*/
+ $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
+ "hand_id='$handid' AND card_id=".DB_quote_smart($card));
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+ $handcardid = $r[0];
+
+ if($handcardid)
+ {
+ /* mark card as played */
+ mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
+ DB_quote_smart($card));
+
+ /* get trick id or start new trick */
+ $a = DB_get_current_trickid($gameid);
+ $trickid = $a[0];
+ $sequence = $a[1];
+
+ $playid = DB_play_card($trickid,$handcardid,$sequence);
+
+ /* check for coment */
+ if(myisset("comment"))
+ {
+ DB_insert_comment($_REQUEST["comment"],$playid,$myid);
+ };
+
+ /* display played card */
+ echo "<div class=\"card\">";
+ echo " you played <br />";