X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Fgame.php;h=9b878aab57ce4de4e02175b329370c71d41eb3b4;hp=cef2c6537c2a11141a38ac387f546943f8624b1b;hb=fd52a255dd62431bf20532b733c4b14d0db85f1c;hpb=f5d068d8b0c003324c075489a4894be2b66eb051 diff --git a/include/game.php b/include/game.php index cef2c65..9b878aa 100644 --- a/include/game.php +++ b/include/game.php @@ -1,5 +1,5 @@ +/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Arun Persaud * * This file is part of e-DoKo. * @@ -53,9 +53,13 @@ $mypos = DB_get_pos_by_hash($me); $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 */ +$_SESSION['language'] = $PREF['language']; +set_language($PREF['language']); /* get rule set for this game */ $RULES = DB_get_RULES($gameid); @@ -67,7 +71,10 @@ $GT = $gametype; if($gametype=='solo') { $gametype = DB_get_solo_by_gameid($gameid); - $GT = $gametype.' '.$GT; + if($gametype=='silent') + $GT = 'normal'; + else + $GT = $gametype.' '.$GT; } /* do we need to worry about Schweinchen? @@ -128,51 +135,67 @@ if( $mystatus!='gameover' ) 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)) - { - $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)) +if( myisset('call') ) { - $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); + }; /***************************************************************** @@ -210,38 +233,38 @@ if($session) switch($RULES['dullen']) { case 'none': - echo " \""._('no\n"; break; case 'firstwins': - echo " \""._('ten\n"; break; case 'secondwins': - echo " \""._('second\n"; break; } switch($RULES['schweinchen']) { case 'none': - echo " \""._('no\n"; break; case 'both': - echo " \""._('two\n"; break; case 'second': - echo " \"".('second\n"; break; case 'secondaftercall': - echo " \""._('second\n"; break; } switch($RULES['call']) { case '1st-own-card': - echo " \""._('1st-own-card')."\"\n"; break; + echo ' '._('1st-own-card').\n"; break; case '5th-card': - echo " \""._('5th-card')."\"\n"; break; + echo ' '._('5th-card').\n"; break; case '9-cards': - echo " \""._('9-cards')."\"\n"; break; + echo ' '._('9-cards').\n"; break; } echo "
\n"; echo ' '._('10ofhearts').": {$RULES['dullen']}
\n"; @@ -267,13 +290,13 @@ if($session) foreach($finalscore as $user=>$value) { $name = DB_get_name('userid',$user); - echo " ".substr($name,0,2).": $value "; + echo ' '.substr($name,0,2).": $value "; } } else { /* first game, no score yet */ - echo " "; + echo ' '; } /* output all games for the score table */ @@ -305,8 +328,8 @@ if($session) $next = NULL; /* check for solo, add game type to session number */ - echo " Game $session.$j"; - if($GT !='normal') + echo ' '._('Game')." $session.$j"; + if($gamestatus != 'pre' && $GT !='normal' ) echo " ($GT)"; if(isset($_SESSION['id']) && $_SESSION['id']==$myid) { @@ -314,9 +337,10 @@ if($session) echo "   "._('previous')." \n"; if($next) echo "   "._('next')." \n"; + + if($j != $i ) + echo "   "._('last')." \n"; } - if($j != $i ) - echo "   last \n"; echo "\n
\n"; } @@ -343,7 +367,7 @@ switch($mystatus) case 'check': /* output sickness of other playes, in case they already selected and are sitting in front of the current player */ echo "\n\n"; /* end div trick, end li trick , end tricks*/ /* end displaying sickness */ @@ -357,7 +381,7 @@ switch($mystatus) $mygametype = DB_get_gametype_by_gameid($gameid); - echo "
  • Pre\n"; + echo "
  • Pre\n"; echo "
  • \n\n\n"; /* end div trick, end li trick , end ul tricks */ } /* end output pre-game trick */ @@ -372,13 +396,13 @@ switch($mystatus) $mygamesolo = DB_get_solo_by_gameid($gameid); if($mygametype != 'normal') /* only show when needed */ if(!( $mygametype == 'solo' && $mygamesolo == 'silent') ) - echo "
  • Pre
  • \n"; + echo "
  • Pre
  • \n"; - $result = DB_query("SELECT Trick.id ". - "FROM Trick ". + $result = DB_query('SELECT Trick.id '. + 'FROM Trick '. "WHERE Trick.game_id='".$gameid."' ". - "GROUP BY Trick.id ". - "ORDER BY Trick.id ASC"); + 'GROUP BY Trick.id '. + 'ORDER BY Trick.id ASC'); $trickNR = 1; $lasttrick = DB_get_max_trickid($gameid); @@ -387,19 +411,19 @@ switch($mystatus) { $trick=$r[0]; if($trick!=$lasttrick) - echo "
  • "._('Trick')." $trickNR
  • \n"; + echo "
  • $trickNR
  • \n"; else if($trick==$lasttrick) - echo "
  • "._('Trick')." $trickNR
  • \n"; + echo "
  • $trickNR
  • \n"; $trickNR++; } /* if game is over, also output link to Score tab */ if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' ) - echo "
  • "._('Score')."
  • \n"; + echo "
  • "._('Score')."
  • \n"; /* output previous/next buttons */ - echo "
  • \n"; - echo "
  • \n"; + echo '
  • '._('prev')."
  • \n"; + echo '
  • '._('next')."
  • \n"; echo "\n\n"; @@ -418,67 +442,6 @@ echo "
    \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
    \n"; - echo "
    \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 "
    still needs
    to decide
    \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 "
    sick
    \n"; - else - echo "
    healthy
    \n"; - } - echo "
    \n
    \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