<?php
-/* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
+/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 Arun Persaud <arun@nubati.net>
*
* This file is part of e-DoKo.
*
$myhand = DB_get_handid('hash',$me);
$myparty = DB_get_party_by_hash($me);
$session = DB_get_session_by_gameid($gameid);
+$playid = DB_get_current_playid($gameid); /* might be -1 at beginning of the game */
/* get prefs and save them in a variable*/
$PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid);
+/* set language chosen in preferences, will become active on the next reload (see index.php)*/
+$_SESSION['language'] = $PREF['language'];
+
/* get rule set for this game */
$RULES = DB_get_RULES($gameid);
DB_insert_note($note,$gameid,$myid);
};
-/* handle calls, output a comment to show when the call was made */
-/* initialize comments */
-$comment = '';
-
-/* get information needed to submit comment */
-$playid = DB_get_current_playid($gameid);
-
-/* set comment */
-if($comment != '')
- DB_insert_comment($comment,$playid,$myid);
-/* clear up */
-unset($comment);
-/* end check for calls */
+/*****************************************************************
+ * handle calls part1: check what was called, set everything up
+ * we only can submit it to the database at the end, since the playid
+ * might change if a player plays a card
+ *****************************************************************/
+/* initialize comments */
+$commentCall = '';
/* check for calls, set comment */
-if(myisset('call') && $_REQUEST['call'] == '120' && can_call(120,$me))
- {
- $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
- if($myparty=='re')
- $comment .= "Re";
- else if($myparty=='contra')
- $comment .= "Contra";
- }
-if(myisset('call') && $_REQUEST['call'] == '90' && can_call(90,$me))
+if( myisset('call') )
{
- $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
- $comment .= "No 90";
- }
-if(myisset('call') && $_REQUEST['call'] == '60' && can_call(60,$me))
- {
- $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
- $comment .= "No 60";
- }
-if(myisset('call') && $_REQUEST['call'] == '30' && can_call(30,$me))
- {
- $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
- $comment .= "No 30";
- }
-if(myisset('call') && $_REQUEST['call'] == '0' && can_call(0,$me))
- {
- $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
- $comment .= "Zero";
+ if($_REQUEST['call'] == '120' && can_call(120,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
+ if($myparty=='re')
+ $commentCall = "Re";
+ else if($myparty=='contra')
+ $commentCall = "Contra";
+ }
+ else if($_REQUEST['call'] == '90' && can_call(90,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
+ $commentCall = "No 90";
+ }
+ else if($_REQUEST['call'] == '60' && can_call(60,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
+ $commentCall = "No 60";
+ }
+ else if($_REQUEST['call'] == '30' && can_call(30,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
+ $commentCall = "No 30";
+ }
+ else if($_REQUEST['call'] == '0' && can_call(0,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
+ $commentCall = "Zero";
+ }
}
+/**********************************************************
+ * handle comments unless we play a card at the same time *
+ * (if we play a card, we need to update playid) *
+ **********************************************************/
+
+
+/* get time from the last action of the game */
+$r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
+$gameend = time() - strtotime($r[0]);
+
+/* handle comments in case player didn't play a card, allow comments a week after the end of the game */
+if( (!myisset('card') && $mystatus!='gameover') || ($mystatus=='gameover' && ($gameend < 60*60*24*7)) )
+ if(myisset('comment'))
+ {
+ $comment = $_REQUEST['comment'];
+
+ if($comment != '')
+ DB_insert_comment($comment,$playid,$gameid,$myid);
+ };
/*****************************************************************
if( $gamestatus != 'gameover' && isset($_SESSION['id']) )
{
/* game isn't over, only valid user can get here, so show menu */
- display_user_menu($myid);
+ display_user_menu($myid, $me);
}
else if( $mystatus == 'gameover' && isset($_SESSION['id']) )
{
/* user is looking at someone else's game, show the menu for the correct user */
- display_user_menu($_SESSION['id']);
+ display_user_menu($_SESSION['id'],$me);
}
else
{
/* check for solo, add game type to session number */
echo " Game $session.$j";
- if($GT !='normal')
+ if($gamestatus != 'pre' && $GT !='normal' )
echo " ($GT)";
if(isset($_SESSION['id']) && $_SESSION['id']==$myid)
{
case 'check':
/* output sickness of other playes, in case they already selected and are sitting in front of the current player */
echo "\n<ul class=\"tricks\">\n";
- echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
- " <div class=\"trick\" id=\"trick0\">\n";
+ echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n";
- for($pos=1;$pos<5;$pos++)
- {
- $usersick = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
- $userid = DB_get_userid('gameid-position',$gameid,$pos);
- $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
-
- if($userstatus=='start' || $userstatus=='init')
- echo " <div class=\"vorbehalt".($pos-1)."\"> still needs <br />to decide </div>\n"; /* show this to everyone */
- else
- if($usersick!=NULL) /* in the init-phase we only showed players with $pos<$mypos, now we can show all */
- echo " <div class=\"vorbehalt".($pos-1)."\"> sick </div>\n";
- else
- echo " <div class=\"vorbehalt".($pos-1)."\"> healthy </div>\n";
- }
- echo " </div>\n </li>\n</ul>\n"; /* end div trick, end li trick , end tricks*/
+ echo " </li>\n</ul>\n"; /* end div trick, end li trick , end tricks*/
/* end displaying sickness */
break;
case 'poverty':
$mygametype = DB_get_gametype_by_gameid($gameid);
- echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
- " <div class=\"trick\" id=\"trick0\">\n";
-
- /* get information so show the cards that have been handed over in a poverty game */
- output_exchanged_cards();
-
- echo " </div>\n </li>\n</ul>\n\n"; /* end div trick, end li trick , end ul tricks */
+ echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n";
+ echo " </li>\n</ul>\n\n"; /* end div trick, end li trick , end ul tricks */
}
/* end output pre-game trick */
break;
/* output tricks */
while($r = DB_fetch_array($result))
{
+ $trick=$r[0];
if($trick!=$lasttrick)
echo " <li onclick=\"hl('$trickNR');\" class=\"old\"><a href=\"#\">"._('Trick')." $trickNR</a></li>\n";
else if($trick==$lasttrick)
echo " <li onclick=\"hl('13');\" class=\"current\"><a href=\"#\">"._('Score')."</a></li>\n";
/* output previous/next buttons */
- echo " <li onclick=\"hl_prev();\" class=\"old\"><a href=\"#\">"._('prev')."</a></li>\n";
- echo " <li onclick=\"hl_next();\" class=\"old\"><a href=\"#\">"._('next')."</a></li>\n";
+ echo " <li onclick=\"hl_prev();\" ><button>"._('prev')."</button></li>\n";
+ echo " <li onclick=\"hl_next();\" ><button>"._('next')."</button></li>\n";
echo "</ul>\n\n";
/* display the table and the names */
display_table_begin();
+
+/******************************
+ * Output pre-trick if needed *
+ ******************************/
+
+switch($mystatus)
+ {
+ case 'start':
+ break;
+ case 'init':
+ case 'check':
+ /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
+ echo "\n<div class=\"tricks\">\n";
+ echo " <div class=\"trick\" id=\"trick0\">\n";
+
+ for($pos=1;$pos<5;$pos++)
+ {
+ $usersick = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
+ $userid = DB_get_userid('gameid-position',$gameid,$pos);
+ $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
+
+ if($userstatus=='start' || $userstatus=='init')
+ echo " <div class=\"vorbehalt".($pos-1)."\"> still needs <br />to decide </div>\n"; /* show this to everyone */
+ else
+ if($usersick!=NULL) /* in the init-phase we only showed players with $pos<$mypos, now we can show all */
+ echo " <div class=\"vorbehalt".($pos-1)."\"> sick </div>\n";
+ else
+ echo " <div class=\"vorbehalt".($pos-1)."\"> healthy </div>\n";
+ }
+
+ /* display all comments on the top right (card1)*/
+ $comments = DB_get_pre_comment($gameid);
+ /* display card */
+ echo " <div class=\"card1\">\n";
+ /* display comments */
+ foreach( $comments as $comment )
+ echo " <span class=\"comment\">".$comment[1].": ".$comment[0]."</span>\n";
+ echo " </div>\n"; /* end div card */
+
+
+ echo " </div>\n </div>\n"; /* end div trick, end li trick , end tricks*/
+ /* end displaying sickness */
+
+ break;
+ case 'poverty':
+ /* output pre-game trick in case user reloads,
+ * only needs to be done when a team has been formed */
+ if($myparty=='re' || $myparty=='contra')
+ {
+ echo "\n<div class=\"tricks\">\n";
+
+ $mygametype = DB_get_gametype_by_gameid($gameid);
+
+ echo " <div class=\"trick\" id=\"trick0\">\n";
+
+ /* get information so show the cards that have been handed over in a poverty game */
+ output_exchanged_cards();
+
+ echo " </div>\n </div>\n\n"; /* end div trick, end li trick , end ul tricks */
+ }
+ /* end output pre-game trick */
+ break;
+ case 'play':
+ case 'gameover':
+
+ /* taken care further down */
+ break;
+ default:
+ }
+
+
+
+
/* mystatus gets the player through the different stages of a game.
* start: does the player want to play?
* init: check for sickness
/* Depending on the situation we set
* cards_status (see functions.php for possible options)
+ * most of the times we need to just show the cards, so we make this the default
*/
-$cards_status = CARDS_EMPTY;
+$card_status = CARDS_SHOW;
/* Also collect message that should be displayed to the user, so that we can show
* them after showing the table. This makes the html flow more consistent and easier
* ask if player wants to join the game *
****************************************/
- /* don't ask if user has autosetup set to yest */
+ /* don't ask if user has autosetup set to yes */
$skip = 0;
if($PREF['autosetup']=='yes') $skip = 1;
{
/* asks the player, if he wants to join the game */
output_check_want_to_play($me);
+
+ /* don't show the cards before the user joined the game */
$card_status = CARDS_EMPTY;
+
break;
}
else
mymail($user,$gameid,GAME_CANCELED,$email_message);
}
+ $card_status = CARDS_EMPTY;
+
/* update game status */
cancel_game('noplay',$gameid);
break;
DB_set_player_by_gameid($gameid,$user);
break;
}
- };
+ }
}
}
case 'init':
$mycards = DB_get_hand($me);
output_check_for_sickness($me,$mycards);
- $card_status = CARDS_SHOW;
-
break;
}
else
$messages[] = "You selected more than one sickness, please go back ".
"and answer the <a href=\"$INDEX?action=game&me=$me&in=yes\">question</a> again.";
- $card_status = CARDS_SHOW;
-
break;
}
else
'Seems like this is not the case, so you need to wait a bit... '.
'you will get an email once that is the case, please use the link in '.
'that email to continue the game.');
-
- /* display cards, if player was just at the init-phase he will still see the cards from there
- * we can put this one here, since the last player to finish the init state won't get here and
- * will still see his card anyway from the init-phase
- */
- if($mystatus=='check')
- {
- $card_status = CARDS_SHOW;
- }
}
else
{
}
}
}
- $card_status = CARDS_SHOW;
}
break;
/* get hand */
$mycards = DB_get_hand($me);
- /* default: show cards, will be overwritten, if we need to give back cards */
- $card_status = CARDS_SHOW;
-
/* check if user need to give more cards back */
if( ($myparty=='re' || $myparty=='contra') && count($mycards)>12)
{
$messages[] = _('You finished the setup, but not everyone else finished it... '.
'You need to wait for the others. Just wait for an email.');
- $card_status = CARDS_SHOW;
-
break; /* not sure this works... the idea is that you can
* only play a card after everyone is ready to play */
}
-
- /* get time from the last action of the game */
- $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
- $gameend = time() - strtotime($r[0]);
-
- /* handle comments in case player didn't play a card, allow comments a week after the end of the game */
- if( (!myisset('card') && $mystatus=='play') || ($mystatus=='gameover' && ($gameend < 60*60*24*7)) )
- if(myisset('comment'))
- {
- $comment = $_REQUEST['comment'];
- $playid = DB_get_current_playid($gameid);
-
- if($comment != '')
- DB_insert_comment($comment,$playid,$myid);
- };
-
/* get everything relevant to display the tricks */
$result = DB_query("SELECT Hand_Card.card_id as card,".
" Hand.position as position,".
/* output vorbehalte */
$mygametype = DB_get_gametype_by_gameid($gameid);
$mygamesolo = DB_get_solo_by_gameid($gameid);
+ $show_pre_game_comments=1;
if($mygametype != 'normal') /* only show when needed */
if(!( $mygametype == 'solo' && $mygamesolo == 'silent') )
{
/* get information so show the cards that have been handed over in a poverty game */
output_exchanged_cards();
+ $show_pre_game_comments=0;
echo " </div>\n"; /* end div trick, end li trick */
}
+ if($show_pre_game_comments==1)
+ {
+ /* display all comments on the top right (card1)*/
+ $comments = DB_get_pre_comment($gameid);
+ if(sizeof($comments))
+ {
+ echo " <div class=\"trick\" id=\"trick0\">\n";
+ /* display card */
+ echo " <div class=\"card1\">\n";
+ /* display comments */
+ foreach( $comments as $comment )
+ echo " <span class=\"comment\">".$comment[1].": ".$comment[0]."</span>\n";
+ echo " </div>\n"; /* end div card */
+
+ echo " </div>\n"; /* end div trick, end li trick */
+ }
+ }
/* output tricks */
while($r = DB_fetch_array($result))
/* display card */
echo " <div class=\"card".($pos-1)."\">\n";
+ /* for the first card, we also need to display calls from other players */
+ if($seq==1 && $trickNR==1)
+ {
+ $commentPreCalls=DB_get_pre_comment_call($gameid);
+ foreach ($commentPreCalls as $pre )
+ $comment .= $pre[1].": ".$pre[0]."<br/>";
+ }
+
/* display comments */
if($comment!='')
echo " <span class=\"comment\">".$comment."</span>\n";
(DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) ))
)
{
- DB_insert_comment('Schweinchen! ',$playid,$myid);
+ DB_insert_comment('Schweinchen! ',$playid,$gameid,$myid);
$commentSchweinchen = 'Schweinchen! ';
}
if ($debug)
/* who is the next player? */
$next = $winner;
+ $firstcard = ''; /* unset firstcard, so followsuit doesn't trigger with the last trick */
}
else
{
{
$comment = $_REQUEST['comment'];
if($comment != '')
- DB_insert_comment($comment,$playid,$myid);
+ DB_insert_comment($comment,$playid,$gameid,$myid);
if($commentSchweinchen)
$comment = $commentSchweinchen . $comment;
+ if($commentCall != '')
+ $comment = $commentCall . $comment;
};
/* display played card */
echo "</div>\n"; /* end ul tricks*/
- if($myturn && !myisset('card') && $mystatus=='play' )
+ if( ($myturn && !myisset('card') && $mystatus=='play') /* it's my turn*/
+ || ($myturn && myisset('card') && $next==$mypos && $mystatus=='play') /* a card has been played and player won the trick*/)
{
$card_status = CARDS_MYTURN;
}
/* check if game is over, display results */
if(DB_get_game_status_by_gameid($gameid)=='play')
{
- echo _('The game is over for you... other people still need to play though');
+ $messages[] = _('The game is over for you... other people still need to play though');
}
break;
default:
echo "</div>\n\n";
}
+/****************************
+ * commit commentCall to DB *
+ ****************************/
+
+if($commentCall != '')
+ {
+ /* treat before game calls special, so that we can show them on the first trick and not the pre-phase */
+ if($playid == -1)
+ $playid = -2;
+
+ DB_insert_comment($commentCall,$playid,$gameid,$myid);
+ }
/***********************************************
* Comments, re/contra calls, user menu
***********************************************/
$gameend = time() - strtotime($r[0]);
/* comment box */
-if($gamestatus == 'play' || $gameend < 60*60*24*7)
+if($gamestatus == 'play' || $gamestatus == 'pre' || $gameend < 60*60*24*7)
{
echo ' '._('A short comment').":<input name=\"comment\" type=\"text\" size=\"20\" maxlength=\"100\" />\n";
}
}
/* play-card button */
-if($gamestatus == 'play' || $gameend < 60*60*24*7)
+if($gamestatus == 'play' || $gamestatus == 'pre' || $gameend < 60*60*24*7)
{
echo " <input type=\"submit\" value=\""._('submit')."\" />\n";
}