2 /* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Arun Persaud <arun@nubati.net>
4 * This file is part of e-DoKo.
6 * e-DoKo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * e-DoKo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with e-DoKo. If not, see <http://www.gnu.org/licenses/>.
21 /* make sure that we are not called from outside the scripts,
22 * use a variable defined in config.php to check this
27 /* calling game.php only makes sense when we give it a hash for a game */
30 echo _("Hmm, you really shouldn't mess with the urls.")."<br />\n";
33 $me = $_REQUEST['me'];
35 /* Ok, got a hash, but is it valid? */
36 $myid = DB_get_userid('hash',$me);
39 echo _('Cannot find you in the database, please check the url.')."<br />\n";
40 printf(_('Perhaps the game has been canceled, check by login in <a href="%s">here</a>.'),$INDEX);
44 global $GAME,$RULES,$CARDS;
46 /**************************************
47 * get some information from the DB
48 **************************************/
50 $gameid = DB_get_gameid_by_hash($me);
51 $myname = DB_get_name('hash',$me);
52 $mystatus = DB_get_status_by_hash($me);
53 $mypos = DB_get_pos_by_hash($me);
54 $myhand = DB_get_handid('hash',$me);
55 $myparty = DB_get_party_by_hash($me);
56 $session = DB_get_session_by_gameid($gameid);
57 $playid = DB_get_current_playid($gameid); /* might be -1 at beginning of the game */
59 /* get prefs and save them in a variable*/
60 $PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid);
61 /* set language chosen in preferences */
62 $_SESSION['language'] = $PREF['language'];
63 set_language($PREF['language']);
65 /* get rule set for this game */
66 $RULES = DB_get_RULES($gameid);
68 /* get some infos about the game */
69 $gametype_raw = DB_get_gametype_by_gameid($gameid);
70 $gametype_solo = DB_get_solo_by_gameid($gameid);
72 /* replace solo with the type of solo */
73 $gametype = $gametype_raw;
74 if($gametype_raw=='solo')
75 $gametype = $gametype_solo;
77 /* gametype for displaying it (hides hidden solo)*/
78 $GT = get_display_gametype($gameid);
80 $gamestatus = DB_get_game_status_by_gameid($gameid);
84 /* do we need to worry about Schweinchen?
85 * check gametype and rules
86 * if yes, figure out if someone actually has Schweinchen
87 * save information in $GAME
90 if( $gamestatus == 'pre' )
92 /* always need to use Schweinchen to figure out for example who has poverty */
94 /* unless the gametype is set and we know that we are in poverty were schweinchen is not valid */
95 if( in_array( $gametype,array('poverty','dpoverty') ))
100 /* in a game Schweinchen is not valid in all types of games */
101 if( in_array($gametype,array('normal','wedding','trump','silent') ))
102 if( in_array($RULES['schweinchen'],array('both','second','secondaftercall')) )
106 /* these are the defaults */
107 $GAME['schweinchen-who'] = NULL;
108 $GAME['schweinchen-first'] = NULL;
109 $GAME['schweinchen-second'] = NULL;
113 /* need to check for Schweinchen */
116 $hash = DB_get_hash_from_game_and_pos($gameid,$i);
117 $cards = DB_get_all_hand($hash);
118 if( in_array('19',$cards) && in_array('20',$cards) )
119 $GAME['schweinchen-who']=$hash;
121 $GAME['schweinchen-first'] = 0; /* to keep track if they have been played already */
122 $GAME['schweinchen-second'] = 0;
124 /* end check for Schweinchen */
126 /* set the $CARDS variable, needed for sorting the cards
127 * we set it to normal so that the pre-game phase is handled ok
128 * and later set it to the correct game type that is played
130 set_gametype('normal');
132 /* handle user notes (only possible while game is running)*/
133 if( $mystatus!='gameover' )
136 $note = $_REQUEST['note'];
139 DB_insert_note($note,$gameid,$myid);
142 /*****************************************************************
143 * handle calls part1: check what was called, set everything up
144 * we only can submit it to the database at the end, since the playid
145 * might change if a player plays a card
146 *****************************************************************/
148 /* initialize comments */
151 /* check for calls, set comment */
152 if( myisset('call') )
154 if($_REQUEST['call'] == '120' && can_call(120,$me))
156 $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
159 else if($myparty=='contra')
160 $commentCall = 'Contra';
162 else if($_REQUEST['call'] == '90' && can_call(90,$me))
164 $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
165 $commentCall = 'No 90';
167 else if($_REQUEST['call'] == '60' && can_call(60,$me))
169 $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
170 $commentCall = 'No 60';
172 else if($_REQUEST['call'] == '30' && can_call(30,$me))
174 $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
175 $commentCall = 'No 30';
177 else if($_REQUEST['call'] == '0' && can_call(0,$me))
179 $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
180 $commentCall = 'Zero';
184 /**********************************************************
185 * handle comments unless we play a card at the same time *
186 * (if we play a card, we need to update playid) *
187 **********************************************************/
190 /* get time from the last action of the game */
191 $r = DB_query_array("SELECT mod_date from Game WHERE id=".DB_quote_smart($gameid));
192 $gameend = time() - strtotime($r[0]);
194 /* handle comments in case player didn't play a card, allow comments a week after the end of the game */
195 if( (!myisset('card') && $mystatus!='gameover') || ($mystatus=='gameover' && ($gameend < 60*60*24*7)) )
196 if(myisset('comment'))
198 $comment = $_REQUEST['comment'];
201 DB_insert_comment($comment,$playid,$gameid,$myid);
205 /*****************************************************************
206 * output other games where it is the users turn
207 * make sure that the people looking at old games don't see the wrong games here
208 *****************************************************************/
210 if( $gamestatus != 'gameover' && isset($_SESSION['id']) )
212 /* game isn't over, only valid user can get here, so show menu */
213 display_user_menu($myid, $me);
215 else if( $mystatus == 'gameover' && isset($_SESSION['id']) )
217 /* user is looking at someone else's game, show the menu for the correct user */
218 display_user_menu($_SESSION['id'],$me);
222 echo '<div class="usermenu">'."\n";
223 printf( _("It's your turn in these games:\nPlease log in to see this information.\n") );
227 /*****************************************************************
228 * output extra division in case this game is part of a session
229 *****************************************************************/
232 echo '<div class="session">'."\n";
234 /* output rule set */
235 echo " <div class=\"sessionrules\">\n "._('Rules').":\n";
236 switch($RULES['dullen'])
239 echo ' <img class="rulesicon" alt="'._('no ten of hearts').
240 "\" src=\"pics/button/no-ten-of-hearts.png\"/>\n"; break;
242 echo ' <img class="rulesicon" alt="'._('ten of hearts').
243 "\" src=\"pics/button/ten-of-hearts.png\"/>\n"; break;
245 echo ' <img class="rulesicon" alt="'._('second ten of hearts').
246 "\" src=\"pics/button/second-ten-of-hearts.png\"/>\n"; break;
248 switch($RULES['schweinchen'])
251 echo ' <img class="rulesicon" alt="'._('no schweinchen').'" '.
252 "src=\"pics/button/no-schweinchen.png\"/>\n"; break;
254 echo ' <img class="rulesicon" alt="'._('two schweinchen').'" '.
255 "src=\"pics/button/two-schweinchen.png\"/>\n"; break;
257 echo ' <img class="rulesicon" alt="'.('second schweinchen').'" '.
258 "src=\"pics/button/second-schweinchen.png\"/>\n"; break;
259 case 'secondaftercall':
260 echo ' <img class="rulesicon" alt="'._('second schweinchen after call').'" '.
261 "src=\"pics/button/second-schweinchen-after-call.png\"/>\n"; break;
263 switch($RULES['call'])
266 echo ' <img class="rulesicon" alt="'._('1st-own-card')."\" src=\"pics/button/1st-own-card.png\"/>\n"; break;
268 echo ' <img class="rulesicon" alt="'._('5th-card')."\" src=\"pics/button/5th-card.png\"/>\n"; break;
270 echo ' <img class="rulesicon" alt="'._('9-cards')."\" src=\"pics/button/9-cards.png\"/>\n"; break;
273 echo ' '._('10ofhearts').": {$RULES['dullen']} <br />\n";
274 echo ' '._('schweinchen').": {$RULES['schweinchen']} <br />\n";
275 echo ' '._('call').": {$RULES['call']} <br />\n";
276 echo ' '._('lowtrump').": {$RULES['lowtrump']} <br />\n";
277 echo " </div>\n </div>\n";
281 echo " <div class=\"sessionscore\">";
283 $score = generate_score_table($session);
285 /* get the last entry to show on the main page */
287 $finalscore = array_pop($tmpscore);
288 $finalscore = $finalscore['players'];
292 echo _('Score').": \n";
293 foreach($finalscore as $user=>$value)
295 $name = DB_get_name('userid',$user);
296 echo ' '.substr($name,0,2).": $value ";
301 /* first game, no score yet */
305 /* output all games for the score table */
306 echo format_score_table_html($score,$myid);
309 /* figure out which game in a session we are in and link to the
310 * previous and next game if possible
312 $hashes = DB_get_hashes_by_session($session,$myid);
315 foreach($hashes as $hash)
325 $previous = $hashes[$j-2];
333 /* check for solo, add game type to session number */
334 echo ' '._('Game')." $session.$j";
335 if($gamestatus != 'pre')
336 if($gametype_raw != 'normal') /* only show when needed */
337 if(!($gametype_raw == 'solo' && $gametype_solo == 'silent') )
340 if(isset($_SESSION['id']) && $_SESSION['id']==$myid)
343 echo " <a href=\"{$INDEX}?action=game&me=$previous\">"._('previous')."</a> \n";
345 echo " <a href=\"{$INDEX}?action=game&me=$next\">"._('next')."</a> \n";
348 echo " <a href=\"{$INDEX}?action=game&me=$lasthash\">"._('last')."</a> \n";
354 /* the user has done something, update the timestamp. Use $myid in
355 * active games and check for session-id in old games (myid might be wrong in that case)
357 if($mystatus!='gameover')
358 DB_update_user_timestamp($myid);
360 if(isset($_SESSION['id']))
361 DB_update_user_timestamp($_SESSION['id']);
364 /******************************************************************************
365 * Output menu for selecting tricks
366 ******************************************************************************/
374 /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
375 echo "\n<ul class=\"tricks\">\n";
376 echo " <li onclick=\"hl(0);\" class=\"active\" id=\"tricks0\"><a href=\"#\">Pre</a>\n";
378 echo " </li>\n</ul>\n"; /* end div trick, end li trick , end tricks*/
379 /* end displaying sickness */
382 /* output pre-game trick in case user reloads,
383 * only needs to be done when a team has been formed */
384 if($myparty=='re' || $myparty=='contra')
386 echo "\n<ul class=\"tricks\">\n";
387 echo " <li onclick=\"hl(0);\" class=\"active\"><a href=\"#\">Pre</a>\n";
388 echo " </li>\n</ul>\n\n"; /* end div trick, end li trick , end ul tricks */
390 /* end output pre-game trick */
395 echo "\n<ul class=\"tricks\">\n";
397 /* output vorbehalte */
398 if($gametype_raw != 'normal') /* only show when needed */
399 if(!($gametype_raw == 'solo' && $gametype_solo == 'silent') )
400 echo " <li onclick=\"hl(0);\" class=\"old\"><a href=\"#\">Pre</a></li>\n";
402 $result = DB_query('SELECT Trick.id'.
404 ' WHERE Trick.game_id='.DB_quote_smart($gameid).
405 ' GROUP BY Trick.id'.
406 ' ORDER BY Trick.id ASC');
408 $lasttrick = DB_get_max_trickid($gameid);
411 while($r = DB_fetch_array($result))
414 if($trick!=$lasttrick)
415 echo " <li onclick=\"hl($trickNR);\" id=\"tricks$trickNR\"><a href=\"#\">$trickNR</a></li>\n";
416 else if($trick==$lasttrick)
417 echo " <li onclick=\"hl($trickNR);\" id=\"tricks$trickNR\" class=\"active\"><a href=\"#\">$trickNR</a></li>\n";
421 /* if game is over, also output link to Score tab */
422 if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' )
423 echo " <li onclick=\"hl(13);\" id=\"tricks13\" class=\"active\"><a href=\"#\">"._('Score')."</a></li>\n";
425 /* output previous/next buttons */
426 echo ' <li onclick="hl_prev();" id="prevtr"><a href="#">'._('prev')."</a></li>\n";
427 echo ' <li onclick="hl_next();" id="nexttr"><a href="#">'._('next')."</a></li>\n";
436 /******************************************************************************
437 * Output tricks played, table, messages, and cards (depending on game status)
438 ******************************************************************************/
440 /* put everyting in a form */
441 echo "<form action=\"index.php?action=game&me=$me\" method=\"post\">\n";
443 /* display the table and the names */
444 display_table_begin();
446 /* mystatus gets the player through the different stages of a game.
447 * start: does the player want to play?
448 * init: check for sickness
449 * check: check for return values from init
450 * poverty: handle poverty, wait here until all player have reached this state
451 * display sickness and move on to game
452 * play: game in progress
453 * gameover: are we revisiting a game
456 /* Depending on the situation we set
457 * cards_status (see functions.php for possible options)
458 * most of the times we need to just show the cards, so we make this the default
460 $card_status = CARDS_SHOW;
462 /* Also collect message that should be displayed to the user, so that we can show
463 * them after showing the table. This makes the html flow more consistent and easier
464 * tournament change layouts, especially for smaller displays, e.g. mobile phones
472 /****************************************
473 * ask if player wants to join the game *
474 ****************************************/
476 /* don't ask if user has autosetup set to yes */
478 if($PREF['autosetup']=='yes') $skip = 1;
480 if( !myisset('in') && !$skip)
482 /* asks the player, if he wants to join the game */
483 output_check_want_to_play($me);
485 /* don't show the cards before the user joined the game */
486 $card_status = CARDS_EMPTY;
492 /* check the result, if player wants to join, got next stage, else cancel game */
493 if(!$skip && $_REQUEST['in'] == 'no' )
495 /* cancel the game */
496 $userids = DB_get_all_userid_by_gameid($gameid);
497 foreach($userids as $user)
499 set_language($user,'uid');
500 $email_message = _("Hello, \n\n".
501 "the game has been canceled due to the request of one of the players.")."\n\n";
502 mymail($user,$gameid,GAME_CANCELED,$email_message);
504 set_language($myid,'uid');
506 $card_status = CARDS_EMPTY;
508 /* update game status */
509 cancel_game('noplay',$gameid);
514 /* user wants to join the game */
516 /* move on to the next stage,
517 * no break statement to immediately go to the next stage
520 DB_set_hand_status_by_hash($me,'init');
523 /* check if everyone has reached this stage, set player in game-table to the next player */
524 $userids = DB_get_all_userid_by_gameid($gameid);
525 foreach($userids as $userid)
527 $userstat = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
528 if($userstat!='init')
530 /* whos turn is it? */
531 DB_set_player_by_gameid($gameid,$userid);
538 /***************************
539 * check if player is sick *
540 ***************************/
541 if(!myisset('solo','wedding','poverty','nines','lowtrump') )
543 $mycards = DB_get_hand($me);
544 output_check_for_sickness($me,$mycards);
550 /* check if someone selected more than one sickness */
552 if($_REQUEST['solo']!='No') $Nsickness++;
553 if($_REQUEST['wedding'] == 'yes') $Nsickness++;
554 if($_REQUEST['poverty'] == 'yes') $Nsickness++;
555 if($_REQUEST['nines'] == 'yes') $Nsickness++;
556 if($_REQUEST['lowtrump'] == 'yes') $Nsickness++;
560 $messages[] = sprintf(_('You selected more than one sickness, please go back '.
561 'and answer the <a href="%s">question</a> again.'),
562 $INDEX.'?action=game&me=$me&in=yes');
566 { /* everything is ok, save what user said and proceed */
568 /* check if this sickness needs to be handled first */
569 $startplayer = DB_get_startplayer_by_gameid($gameid); /* need this to check which solo goes first */
571 if( $_REQUEST['solo']!='No' )
573 /* user wants to play a solo */
575 /* double check input value */
576 $s = $_REQUEST['solo'];
577 $solos = array('trumpless','jack','queen','trump','club','spade','heart');
578 if (!in_array($s, $solos))
580 $messages[] = sprintf(_('There is a problem with the type of solo you selected (%s does not exist), please go back '.
581 'and answer the <a href="%s">question</a> again.'),
582 $s,$INDEX.'?action=game&me=$me&in=yes');
586 /* store the info in the user's hand info */
587 DB_set_solo_by_hash($me,$_REQUEST['solo']);
588 DB_set_sickness_by_hash($me,'solo');
590 $messages[] = '<br />'.
591 sprintf(_('Seems like you want to play a %s solo. Got it.'),$_REQUEST['solo']).
594 if($gametype_raw == 'solo' && $startplayer<$mypos)
595 {}/* do nothing, since someone else already is playing solo */
598 /* this solo comes first
599 * store info in game table
601 DB_set_gametype_by_gameid($gameid,'solo');
602 $gametype_raw = 'solo';
603 DB_set_startplayer_by_gameid($gameid,$mypos);
604 DB_set_solo_by_gameid($gameid,$_REQUEST['solo']);
605 $gametype_solo = $_REQUEST['solo'];
606 $gametype = $gametype_solo;
609 else if($_REQUEST['wedding'] == 'yes')
611 /* silent solo is set further down */
612 $messages[] = _("Ok, you don't want to play a silent solo...wedding was chosen.")."<br />\n";
613 DB_set_sickness_by_hash($me,'wedding');
615 else if($_REQUEST['poverty'] == 'yes')
617 $messages[] = _("Don't think you can win with just a few trump...? Ok, poverty chosen.")." <br />\n";
618 DB_set_sickness_by_hash($me,'poverty');
620 else if($_REQUEST['nines'] == 'yes')
622 $messages[] = _("What? You just don't want to play a game because you have a few nines? Well, if no one".
623 ' is playing solo, this game will be canceled.')."<br />\n";
624 DB_set_sickness_by_hash($me,'nines');
626 else if($_REQUEST['lowtrump'] == 'yes')
628 if($RULES['lowtrump']=='cancel')
629 $messages[] = _("What? You just don't want to play a game because you have low trump? Well, if no one".
630 ' is playing solo, this game will be canceled.')."<br />\n";
632 $messages[] = _("Don't think you can win with low trumps...? Ok, poverty chosen.")." <br />.<br />\n";
634 DB_set_sickness_by_hash($me,'lowtrump');
637 /* move on to the next stage*/
638 DB_set_hand_status_by_hash($me,'check');
644 /* here we check what all players said and figure out what game we are playing
645 * this can therefore only be handled once all players finished the last stage
648 /* check if everyone has reached this stage */
649 $userids = DB_get_all_userid_by_gameid($gameid);
651 foreach($userids as $userid)
653 $userstat = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
654 if($userstat!='check')
657 DB_set_player_by_gameid($gameid,$userid);
664 $messages[] = _('This step can only be handled after everyone finished the last step. '.
665 'Seems like this is not the case, so you need to wait a bit... '.
666 'you will get an email once that is the case, please use the link in '.
667 'that email to continue the game.');
671 /* Ok, everyone finished the init-phase, time to figure out what game we
672 * are playing, in case there are any solos this already
673 * will have the correct information in it */
675 /* gametype for displaying it (hides hidden solo)*/
676 $GT = get_display_gametype($gameid);
678 $startplayer = DB_get_startplayer_by_gameid($gameid);
680 /* check for sickness */
685 foreach($userids as $user)
687 $name = DB_get_name('userid',$user);
688 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
689 if($usersick == 'nines' || ($RULES['lowtrump']=='cancel' && $usersick=='lowtrump') )
692 $cancelsick = $usersick;
693 break; /* no need to check for other poverties, since only solo can win and that is already set */
695 else if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
697 else if($usersick == 'wedding')
699 else if($usersick == 'solo')
703 /* now check which sickness comes first and set the gametype to it */
704 if($gametype_raw == 'solo')
711 if($cancelsick == 'nines')
713 /* update game status */
714 cancel_game('nines',$gameid);
716 $messages[] = sprintf(_('The game has been canceled because %s'.
717 ' has five or more nines and nobody is playing solo.'),DB_get_name('userid',$cancel) );
719 else if ($cancelsick == 'lowtrump')
721 /* update game status */
722 cancel_game('lowtrump',$gameid);
724 $messages[] = sprintf(_('The game has been canceled because %s'.
725 ' has low trump and nobody is playing solo.'),DB_get_name('userid',$cancel));
728 $userids = DB_get_all_userid_by_gameid($gameid);
729 foreach($userids as $user)
731 set_language($user,'uid');
732 if($cancelsick == 'nines')
734 $email_message = sprintf(_('The game has been canceled because %s'.
735 ' has five or more nines and nobody is playing solo.'),DB_get_name('userid',$cancel) ).
737 _("To redeal either start a new game or, in case the game was part of a tournament,\n".
738 "go to the last game and use the link at the bottom of the page to redeal.").
741 else if ($cancelsick == 'lowtrump')
743 $email_message = sprintf(_('The game has been canceled because %s'.
744 " has low trump and nobody is playing solo."),DB_get_name('userid',$cancel)).
746 _("To redeal either start a new game or, in case the game was part of a tournament,\n".
747 "go to the last game and use the link at the bottom of the page to redeal.").
751 mymail($user,$gameid, GAME_CANCELED, $email_message);
753 set_language($myid,'uid');
757 else if($poverty==1) /* one person has poverty */
759 DB_set_gametype_by_gameid($gameid,'poverty');
760 $gametype_raw = 'poverty';
761 $gametype = 'poverty';
762 $who = DB_get_sickness_by_gameid($gameid);
765 $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
766 if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
767 DB_set_sickness_by_gameid($gameid,2); /* who needs to be asked first */
769 DB_set_sickness_by_gameid($gameid,1); /* who needs to be asked first */
772 else if($poverty==2) /* two people have poverty */
774 DB_set_gametype_by_gameid($gameid,'dpoverty');
775 $gametype_raw = 'dpoverty';
776 $gametype = 'dpoverty';
777 $who = DB_get_sickness_by_gameid($gameid);
780 $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
781 if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
783 $secondsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
784 if($secondsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
785 DB_set_sickness_by_gameid($gameid,30); /* who needs to be asked first */
787 DB_set_sickness_by_gameid($gameid,20); /* who needs to be asked first */
790 DB_set_sickness_by_gameid($gameid,10); /* who needs to be asked first */
795 DB_set_gametype_by_gameid($gameid,'wedding');
796 DB_set_sickness_by_gameid($gameid,'-1'); /* wedding not resolved yet */
797 $gametype_raw = 'wedding';
798 $gametype = 'wedding';
800 /* now the gametype is set correctly in the database */
802 /* loop over all players, set re/contra if possible and start the game if possible */
803 $userids = DB_get_all_userid_by_gameid($gameid);
804 foreach($userids as $userid)
806 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$userid);
808 switch($gametype_raw)
811 /* are we the solo player? set us to re, else set us to contra */
812 $pos = DB_get_pos_by_hash($userhash);
813 if($pos == $startplayer)
814 DB_set_party_by_hash($userhash,'re');
816 DB_set_party_by_hash($userhash,'contra');
817 DB_set_hand_status_by_hash($userhash,'play');
821 /* set person with the wedding to re, do the rest during the game */
822 $usersick = DB_get_sickness_by_userid_and_gameid($userid,$gameid);
823 if($usersick == 'wedding')
824 DB_set_party_by_hash($userhash,'re');
826 DB_set_party_by_hash($userhash,'contra');
828 DB_set_hand_status_by_hash($userhash,'play');
832 $hand = DB_get_all_hand($userhash);
834 if(in_array('3',$hand)||in_array('4',$hand))
835 DB_set_party_by_hash($userhash,'re');
837 DB_set_party_by_hash($userhash,'contra');
838 DB_set_hand_status_by_hash($userhash,'play');
842 /* set person with poverty to play status */
843 $usersick = DB_get_sickness_by_userid_and_gameid($userid,$gameid);
844 if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
845 DB_set_hand_status_by_hash($userhash,'play');
847 /* set status of first player to be asked to poverty */
848 $who = DB_get_sickness_by_gameid($gameid);
849 if($who > 6) $who= $who/10; /* in case we have dpoverty */
850 $whoid = DB_get_userid('gameid-position',$gameid,$who);
852 DB_set_hand_status_by_hash($userhash,'poverty');
855 /* check for silent solo, set game type to solo in this case */
856 $userids = DB_get_all_userid_by_gameid($gameid);
857 foreach($userids as $userid)
859 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$userid);
861 if($gametype_raw=='normal')
863 $userhand = DB_get_all_hand($userhash);
864 if(check_wedding($userhand))
866 /* normal game type and player has both queens -> silent solo */
867 /* keep startplayer, just set gametype to silent solo */
868 DB_set_gametype_by_gameid($gameid,'solo');
869 DB_set_solo_by_gameid($gameid,'silent');
870 $gametype_raw = 'solo';
871 $gametype_solo = 'silent';
872 $gametype = 'normal';
877 /* send out email to first player or poverty person*/
878 if($gametype!='poverty' && $gametype!='dpoverty')
880 $startplayer = DB_get_startplayer_by_gameid($gameid);
881 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
882 $userid = DB_get_userid('hash',$hash);
883 DB_set_player_by_gameid($gameid,$userid);
887 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
889 /* email startplayer */
890 set_language($userid,'uid');
891 $email_message = sprintf(_("It's your turn now in game %s.\n".
892 "Use this link to play a card:"),DB_format_gameid($gameid))." ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
893 mymail($userid,$gameid,GAME_READY,$email_message);
894 set_language($myid,'uid');
905 /* set status of first player to be asked to poverty */
906 $who = DB_get_sickness_by_gameid($gameid);
907 if($who > 6) $who= $who/10; /* in case we have dpoverty */
909 $whoid = DB_get_userid('gameid-position',$gameid,$who);
912 $mystatus = 'poverty';
917 $whohash = DB_get_hash_from_game_and_pos($gameid,$who);
918 DB_set_player_by_gameid($gameid,$whoid);
920 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
922 /* email player for poverty */
923 set_language($whoid,'uid');
924 $email_message = sprintf(_("Poverty: It's your turn now in game %s.\n".
925 'Use this link to play a card: '),DB_format_gameid($gameid)).$HOST.$INDEX."?action=game&me=".$whohash."\n\n" ;
926 mymail($whoid,$gameid,GAME_POVERTY,$email_message);
927 set_language($myid,'uid');
936 /* user only gets here in a poverty game, several things have to be handled here:
937 * A) ask, if user wants to take trump
939 * poverty: set re/contra
940 * dpoverty: first time: set re, send email to second player
941 * second time: set contra
942 * poverty: set status of other players to 'play'
943 * set status to play in case 0 trump
944 * no -> set status to play,
945 * ask next player or cancle the game if no more players
946 * B) user took trump and has too many cards (e.g. count(cards)>12 and re/contra set)
947 * ask to give cards back, set status to play, once player has 12 cards
949 * it is easier to check B) first
952 set_gametype($gametype); /* this sets the $CARDS variable */
953 $myparty = DB_get_party_by_hash($me);
955 /* the following is part B) of whats needs to be done)
956 /* check if user wants to give cards back */
957 if(myisset('exchange'))
959 $exchange = $_REQUEST['exchange'];
960 $partnerhash = DB_get_partner_hash_by_hash($me);
961 $partnerid = DB_get_userid('hash',$partnerhash);
962 $partnerhand = DB_get_handid('gameid-userid',$gameid,$partnerid);
964 /* if exchange is set to a value>0, exchange that card back to the partner */
967 $result = DB_query("UPDATE Hand_Card SET hand_id='$partnerhand'".
968 " WHERE hand_id=".DB_quote_smart($myhand)." AND card_id=".DB_quote_smart($exchange));
969 DB_add_exchanged_card(DB_quote_smart($exchange),$myhand,$partnerhand);
974 $mycards = DB_get_hand($me);
976 /* check if user need to give more cards back */
977 if( ($myparty=='re' || $myparty=='contra') && count($mycards)>12)
979 $card_status = CARDS_EXCHANGE;
981 else if( ($myparty=='re' || $myparty=='contra') && count($mycards)==12)
983 /* user is done, ready to play */
984 DB_set_hand_status_by_hash($me,'play');
986 /* email start player */
987 $startplayer = DB_get_startplayer_by_gameid($gameid);
988 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
989 $userid = DB_get_userid('hash',$hash);
990 DB_set_player_by_gameid($gameid,$userid);
994 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
996 /* email startplayer */
997 set_language($userid,'uid');
998 $email_message = sprintf(_("It's your turn now in game %s.\n".
999 'Use this link to play a card: '),DB_format_gameid($gameid)).$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
1000 mymail($userid,$gameid,GAME_READY,$email_message);
1001 set_language($myid,'uid');
1011 /* the following is part A) of what needs to be done */
1012 if(!myisset('trump'))
1016 echo "<div class=\"poverty\">\n";
1017 $userids = DB_get_all_userid_by_gameid($gameid);
1018 foreach($userids as $user)
1020 $name = DB_get_name('userid',$user);
1021 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
1022 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1023 $userparty = DB_get_party_by_hash($userhash);
1025 if(($usersick=='poverty'|| ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump')) && !$userparty)
1027 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1028 $cards = DB_get_hand($hash);
1031 foreach($cards as $card)
1032 if($card<27) $nrtrump++;
1034 if($usersick=='lowtrump')
1036 /// TRANSLATORS: first %s=name, %d=number of trump, second %s= '' or 'low' for trumpfarmut
1037 printf(_('Player %s has %d %s trump. Do you want to take them?'.
1038 '<a href="%s">Yes</a>')."<br />\n",
1039 $name,$nrtrump,$low,"index.php?action=game&me=$me&trump=$user");
1042 /// TRANSLATORS: answer to question about taking trump in poverty game
1043 echo "<a href=\"index.php?action=game&me=$me&trump=no\">"._("No way")."</a> <br />\n";
1050 $trump = $_REQUEST['trump'];
1054 /* user doesn't want to take trump */
1055 DB_set_hand_status_by_hash($me,'play');
1057 /* set next player who needs to be asked and email him*/
1058 $firstsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+1,$gameid);
1059 $secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
1061 /* don't ask people who have poverty */
1063 if($firstsick=='poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
1065 if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
1070 if($gametype=='dpoverty')
1072 $next=999; /* need to cancel for sure, since both would need to take the trump */
1075 /* no more people to ask, need to cancel the game */
1078 $userids = DB_get_all_userid_by_gameid($gameid);
1079 foreach($userids as $user)
1081 set_language($user,'uid');
1082 $email_message = sprintf("Hello, \n\n".
1083 'Game %s has been canceled since nobody wanted to take the trump.',DB_format_gameid($gameid)).
1085 mymail($user, $gameid, GAME_CANCELED_POVERTY, $email_message);
1087 set_language($myid,'uid');
1089 /* update game status */
1090 cancel_game('trump',$gameid);
1092 $messages[] = sprintf(_('Game %s has been canceled.'),DB_format_gameid($gameid));
1097 /* email next player, set his status to poverty */
1098 $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
1099 $userid = DB_get_userid('hash',$userhash);
1101 DB_set_player_by_gameid($gameid,$userid);
1102 DB_set_hand_status_by_hash($userhash,'poverty');
1104 set_language($userid,'uid');
1105 $email_message = _("Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:").
1106 " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
1107 mymail($userid,$gameid, GAME_POVERTY, $email_message);
1108 set_language($myid,'uid');
1111 $cards_status = CARDS_SHOW;
1115 /* player wants to take trump, change cards */
1117 /* user wants to take trump */
1118 $trump = $_REQUEST['trump'];
1119 $userhand = DB_get_handid('gameid-userid',$gameid,$trump);
1120 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$trump);
1122 /* remember which cards were handed over*/
1123 $partnerhand = DB_get_all_hand($userhash);
1124 foreach ($partnerhand as $card)
1126 DB_add_exchanged_card($card,$userhand,$myhand);
1128 /* copy trump from player A to B */
1129 $result = DB_query("UPDATE Hand_Card SET hand_id='$myhand' WHERE hand_id=".DB_quote_smart($userhand)." AND card_id<'27'" );
1132 $mycards = DB_get_hand($me);
1135 if($gametype=='poverty')
1137 $userids = DB_get_all_userid_by_gameid($gameid);
1138 foreach($userids as $user)
1140 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1141 if($hash==$userhash||$hash==$me)
1143 DB_set_party_by_hash($hash,'re');
1147 DB_set_party_by_hash($hash,'contra');
1148 DB_set_hand_status_by_hash($hash,'play'); /* the contra party is ready to play */
1151 /* check if we are done (in case of no trump handed over), if so, go to 'play' phase right away*/
1152 if(count($mycards)==12)
1154 DB_set_hand_status_by_hash($me,'play');
1159 /* has the re party already been set?*/
1161 $userids = DB_get_all_userid_by_gameid($gameid);
1162 foreach($userids as $user)
1164 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1165 $party = DB_get_party_by_hash($hash);
1171 DB_set_party_by_hash($me,'contra');
1172 DB_set_party_by_hash($userhash,'contra');
1176 DB_set_party_by_hash($me,'re');
1177 DB_set_party_by_hash($userhash,'re');
1179 /* send out email to second non-poverty player */
1180 $firstsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+1,$gameid);
1181 $secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
1184 if($firstsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
1185 if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
1191 $messages[] = "Error in poverty, please contact the Admin ($ADMIN_NAME at $ADMIN_EMAIL)";
1193 $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
1194 $userid = DB_get_userid('hash',$userhash);
1196 DB_set_player_by_gameid($gameid,$userid);
1197 DB_set_hand_status_by_hash($userhash,'poverty');
1199 set_langauge($userid,'uid');
1200 $email_message = _("Two people have poverty, it's your turn to decide, if you want to take the trump. Please visit:").
1201 " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
1202 mymail($userid,$gameid, GAME_DPOVERTY, $email_message);
1203 set_language($myid,'uid');
1206 $messages[] = sprintf(_('Please, <a href="%s">continue</a> here'),$INDEX."?action=game&me=$me");
1214 /* both entries here, so that the tricks are visible for both.
1215 * in case of 'play' there is a break later that skips the last part
1218 /* first check if the game has been canceled and display */
1221 case 'cancel-noplay':
1222 $messages[] = _("The game has been canceled due to the request of one player.</p><p>If this was a mistake all 4 players need to send an Email to $ADMIN_NAME at $ADMIN_EMAIL requesting that the game should be restarted.");
1224 case 'cancel-timedout':
1225 $messages[] = _("The game has been canceled because one player wasn't responding.<br />If this was a mistake all 4 players need to send an Email to $ADMIN_NAME at $ADMIN_EMAIL requesting that the game should be restarted.");
1227 case 'cancel-nines':
1228 $messages[] = _('The game has been canceled because one player had too many nines.');
1230 case 'cancel-lowtrump':
1231 $messages[] = _('The game has been canceled because one player had low trump.');
1233 case 'cancel-trump':
1234 $messages[] = _('The game has been canceled because nobody wanted to take the trump.');
1237 /* for these two types, we shouldn't show the cards, since we might want to restart the game */
1238 if (in_array($gamestatus,array('cancel-noplay','cancel-timedout')))
1241 /* check if all players are ready to play,
1242 * if so, send out email to the startplayer
1243 * only need to do this if the game hasn't started yet
1245 $gamestatus = DB_get_game_status_by_gameid($gameid);
1246 if($gamestatus == 'pre')
1249 $userids = DB_get_all_userid_by_gameid($gameid);
1250 foreach($userids as $userid)
1252 $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
1253 if($userstatus !='play' && $userstatus!='gameover')
1256 DB_set_player_by_gameid($gameid,$userid);
1262 /* only set this after all poverty, etc. are handled*/
1263 DB_set_game_status_by_gameid($gameid,'play');
1265 /* email startplayer */
1266 $startplayer = DB_get_startplayer_by_gameid($gameid);
1267 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
1268 $userid = DB_get_userid('hash',$hash);
1269 DB_set_player_by_gameid($gameid,$userid);
1271 if($hash!=$me && DB_get_email_pref_by_hash($hash)!='emailaddict')
1273 /* email startplayer) */
1274 set_language($userid,'uid');
1275 $email_message = sprintf(_("It's your turn now in game %s.\n".
1276 'Use this link to play a card: '),DB_format_gameid($gameid)).$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
1277 mymail($userid,$gameid, GAME_READY, $email_message);
1278 set_language($myid,'uid');
1282 /* figure out what kind of game we are playing,
1283 * set the global variables $CARDS['trump'],$CARDS['diamonds'],$CARDS['hearts'],
1284 * $CARDS['clubs'],$CARDS['spades'],$CARDS['foxes']
1288 set_gametype($gametype); /* this sets the $CARDS variable */
1290 /* get some infos about the game, need to reset this, since it might have changed */
1291 $gamestatus = DB_get_game_status_by_gameid($gameid);
1293 /* has the game started? No, then just wait here...*/
1294 if($gamestatus == 'pre')
1296 $messages[] = _('You finished the setup, but not everyone else finished it... '.
1297 'You need to wait for the others. Just wait for an email.');
1299 break; /* not sure this works... the idea is that you can
1300 * only play a card after everyone is ready to play */
1303 /* get everything relevant to display the tricks */
1304 $result = DB_query('SELECT Hand_Card.card_id as card,'.
1305 ' Hand.position as position,'.
1306 ' Play.sequence as sequence, '.
1308 " GROUP_CONCAT(CONCAT('<span>',User.fullname,': ',Comment.comment,'</span>')".
1309 " SEPARATOR '\n' ), ".
1310 ' Play.create_date,'.
1313 ' LEFT JOIN Play ON Trick.id=Play.trick_id'.
1314 ' LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id'.
1315 ' LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id'.
1316 ' LEFT JOIN Comment ON Play.id=Comment.play_id'.
1317 ' LEFT JOIN User On User.id=Comment.user_id'.
1318 " WHERE Trick.game_id=".DB_quote_smart($gameid).
1319 ' GROUP BY Trick.id, sequence'.
1320 ' ORDER BY Trick.id, sequence ASC');
1322 $lasttrick = DB_get_max_trickid($gameid);
1324 $play = array(); /* needed to calculate winner later */
1326 $pos = DB_get_startplayer_by_gameid($gameid)-1;
1327 $firstcard = ''; /* first card in a trick */
1329 echo "\n<div class=\"tricks\">\n";
1331 /* output vorbehalte */
1332 $show_pre_game_comments=1;
1333 if($gametype_raw != 'normal') /* only show when needed */
1334 if(!($gametype_raw == 'solo' && $gametype_solo == 'silent') )
1336 echo " <div class=\"trick\" id=\"trick0\">\n";
1338 /* get information so show the cards that have been handed over in a poverty game */
1339 output_exchanged_cards($gametype);
1340 $show_pre_game_comments=0;
1342 echo " </div>\n"; /* end div trick, end li trick */
1344 if($show_pre_game_comments==1)
1346 /* display all comments on the top right (card1)*/
1347 $comments = DB_get_pre_comment($gameid);
1349 if(sizeof($comments))
1351 echo " <div class=\"trick\" id=\"trick0\">\n";
1353 echo " <div class=\"card1\">\n";
1354 /* display comments */
1355 foreach( $comments as $comment )
1356 echo " <span class=\"comment\">".$comment[1].": ".$comment[0]."</span>\n";
1357 echo " </div>\n"; /* end div card */
1359 echo " </div>\n"; /* end div trick, end li trick */
1364 while($r = DB_fetch_array($result))
1372 /* count number of tricks */
1376 /* check if first schweinchen has been played */
1377 if( $GAME['schweinchen-who'] && ($r[0] == 19 || $r[0] == 20) )
1378 if(!$GAME['schweinchen-first'])
1379 $GAME['schweinchen-first'] = 1; /* playing the first fox */
1381 $GAME['schweinchen-second'] = 1; /* this must be the second fox */
1383 /* save card to be able to find the winner of the trick later */
1384 $play[$seq] = array('card'=>$r[0],'pos'=>$pos);
1388 /* first card in a trick, output some html */
1389 if($trick!=$lasttrick)
1391 /* start of an old trick? */
1392 echo " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
1393 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1395 else if($trick==$lasttrick)
1397 /* start of a last trick? */
1398 echo " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
1399 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1402 /* remember first card, so that we are able to check, what cards can be played */
1407 echo " <div class=\"card".($pos-1)."\">\n";
1409 /* for the first card, we also need to display calls from other players */
1410 if($seq==1 && $trickNR==1)
1412 $commentPreCalls=DB_get_pre_comment_call($gameid);
1413 foreach ($commentPreCalls as $pre )
1414 $comment .= $pre[1].": ".$pre[0]."<br/>";
1417 /* display comments */
1419 echo " <span class=\"comment\">".$comment."</span>\n";
1422 display_card($r[0],$PREF['cardset']);
1424 echo " </div>\n"; /* end div card */
1429 $winner = get_winner($play,$gametype); /* returns the position */
1430 echo " </div>\n"; /* end div trick, end li trick */
1434 /* whos turn is it? */
1437 $winner = get_winner($play,$gametype); /* returns the position */
1439 $firstcard = ''; /* new trick, no first card */
1444 if($next==5) $next = 1;
1447 /* my turn?, display cards as links, ask for comments*/
1448 if(DB_get_pos_by_hash($me) == $next)
1453 /* do we want to play a card? */
1454 if(myisset('card') && $myturn)
1456 $card = $_REQUEST['card'];
1457 $handid = DB_get_handid('hash',$me);
1458 $commentSchweinchen =''; /* used to add a comment when Schweinchen is being played */
1460 /* check if we have card and that we haven't played it yet*/
1461 /* set played in hand_card to true where hand_id and card_id*/
1462 $r = DB_query_array("SELECT id FROM Hand_Card WHERE played='false' and ".
1463 "hand_id='$handid' AND card_id=".DB_quote_smart($card));
1464 $handcardid = $r[0];
1466 if($handcardid) /* everything ok, play card */
1468 /* update Game timestamp */
1469 DB_update_game_timestamp($gameid);
1471 /* mark card as played */
1472 DB_query("UPDATE Hand_Card SET played='true' WHERE hand_id=".DB_quote_smart($handid)." AND card_id=".
1473 DB_quote_smart($card));
1475 /* get trick id or start new trick */
1476 $a = DB_get_current_trickid($gameid);
1481 $playid = DB_play_card($trickid,$handcardid,$sequence);
1483 /* check special output for schweinchen in case in case a fox is being played
1484 * check for correct rules, etc. has already been done
1486 if( $GAME['schweinchen-who'] && ($card == 19 || $card == 20) )
1488 if(!$GAME['schweinchen-first'])
1489 $GAME['schweinchen-first'] = 1; /* playing the first fox */
1491 $GAME['schweinchen-second'] = 1; /* this must be the second fox */
1493 if( $RULES['schweinchen']=='both' ||
1494 ($RULES['schweinchen']=='second' && $GAME['schweinchen-second']==1 )||
1495 ($RULES['schweinchen']=='secondaftercall' && $GAME['schweinchen-second']==1 &&
1496 (DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) ))
1499 DB_insert_comment('Schweinchen! ',$playid,$gameid,$myid);
1500 $commentSchweinchen = 'Schweinchen! ';
1503 echo 'schweinchen = '.$GAME['schweinchen-who'].' ---<br />';
1506 /* if sequence == 4 check who one in case of wedding */
1507 if($sequence == 4 && $GT == 'wedding')
1509 /* is wedding resolve */
1510 $resolved = DB_get_sickness_by_gameid($gameid);
1513 /* who has wedding */
1514 $userids = DB_get_all_userid_by_gameid($gameid);
1515 foreach($userids as $user)
1517 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
1518 if($usersick == 'wedding')
1521 /* who won the trick */
1522 $play = DB_get_cards_by_trick($trickid);
1523 $winner = get_winner($play,$gametype); /* returns the position */
1524 $winnerid = DB_get_userid('gameid-position',$gameid,$winner);
1525 /* is tricknr <=3 */
1526 if($tricknr <=3 && $winnerid!=$whosick)
1528 /* set resolved at tricknr*/
1529 $resolved = DB_set_sickness_by_gameid($gameid,$tricknr);
1531 $whash = DB_get_hash_from_gameid_and_userid($gameid,$winnerid);
1532 DB_set_party_by_hash($whash,'re');
1534 if($tricknr == 3 && $winnerid==$whosick)
1536 /* set resolved at tricknr*/
1537 $resolved = DB_set_sickness_by_gameid($gameid,'3');
1542 /* if sequence == 4, set winner of the trick, count points and set the next player */
1545 $play = DB_get_cards_by_trick($trickid);
1546 $winner = get_winner($play,$gametype); /* returns the position */
1549 * check if someone caught a fox
1550 *******************************/
1552 /* first check if we should account for solos at all,
1553 * since it doesn't make sense in some games
1555 $ok = 0; /* fox shouldn't be counted */
1556 if($gametype_raw=='solo')
1558 $solo = DB_get_solo_by_gameid($gameid);
1559 if($solo == 'trump' || $solo == 'silent')
1560 $ok = 1; /* for trump solos and silent solos, foxes are ok */
1563 $ok = 1; /* for all other games (not solos) foxes are ok too */
1566 foreach($play as $played)
1568 if ( $played['card']==19 || $played['card']==20 )
1569 if ($played['pos']!= $winner )
1571 /* possible caught a fox, check party */
1572 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1573 $uid2 = DB_get_userid('gameid-position',$gameid,$played['pos']);
1575 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1576 $party2 = DB_get_party_by_gameid_and_userid($gameid,$uid2);
1578 if($party1 != $party2)
1579 DB_query("INSERT INTO Score".
1580 " VALUES(NULL,CURRENT_TIMESTAMP,$gameid,'$party1',$uid1,$uid2,'fox')");
1585 * check for karlchen (jack of clubs in the last trick)
1586 ******************************************************/
1588 /* same as for foxes, karlchen doesn't always make sense
1589 * check what kind of game it is and set karlchen accordingly */
1591 if($tricknr == 12 ) /* Karlchen works only in the last trick */
1593 /* no Karlchen in these solos */
1594 if($gametype_solo != 'trumpless' && $gametype_solo != 'jack' && $gametype_solo != 'queen' )
1596 foreach($play as $played)
1597 if ( $played['card']==11 || $played['card']==12 )
1598 if ($played['pos'] == $winner )
1601 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1602 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1604 DB_query("INSERT INTO Score".
1605 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'$party1',$uid1,NULL,'karlchen')");
1608 }; /* end scoring Karlchen */
1611 * check for doppelopf (>40 points)
1612 ***********************************/
1615 foreach($play as $played)
1617 $points += DB_get_card_value_by_cardid($played['card']);
1621 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1622 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1624 DB_query("INSERT INTO Score".
1625 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'$party1',$uid1,NULL,'doko')");
1629 * set winner (for this trick)
1633 DB_query("UPDATE Trick SET winner='$winner' WHERE id=".DB_quote_smart($trickid));
1635 $messages[] = "ERROR during scoring";
1638 echo "DEBUG: position $winner won the trick <br />";
1640 /* who is the next player? */
1642 $firstcard = ''; /* unset firstcard, so followsuit doesn't trigger with the last trick */
1646 $next = DB_get_pos_by_hash($me)+1;
1648 if($next==5) $next=1;
1650 /* check for coment */
1651 if(myisset('comment'))
1653 $comment = $_REQUEST['comment'];
1655 DB_insert_comment($comment,$playid,$gameid,$myid);
1656 if($commentSchweinchen)
1657 $comment = $commentSchweinchen . $comment;
1658 if($commentCall != '')
1659 $comment = $commentCall . $comment;
1662 /* display played card */
1663 $pos = DB_get_pos_by_hash($me);
1666 echo ' <div class="trick" id="trick'.($tricknr)."\">\n".
1667 ' <img class="arrow" src="pics/arrow'.($pos-1).".png\" alt=\"table\" />\n";
1670 echo ' <div class="card'.($pos-1)."\">\n ";
1672 /* display comments */
1673 display_card($card,$PREF['cardset']);
1675 echo "\n <span class=\"comment\"> ".$comment."</span>\n";
1678 echo " </div>\n"; /* end div trick, end li trick */
1680 /*check if we still have cards left, else set status to gameover */
1681 if(sizeof(DB_get_hand($me))==0)
1683 DB_set_hand_status_by_hash($me,'gameover');
1684 $mystatus = 'gameover';
1687 /* if all players are done, set game status to game over,
1688 * get the points of the last trick and send out an email
1691 $userids = DB_get_all_userid_by_gameid($gameid);
1694 foreach($userids as $user)
1695 if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='gameover')
1699 DB_set_game_status_by_gameid($gameid,'gameover');
1701 /* email next player, if game is still running */
1702 if(DB_get_game_status_by_gameid($gameid)=='play')
1704 $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
1705 $userid = DB_get_userid('hash',$next_hash);
1706 DB_set_player_by_gameid($gameid,$userid);
1708 if( DB_get_email_pref_by_uid($userid)!='emailaddict' )
1710 set_language($userid,'uid');
1711 $email_message = sprintf(_("A card has been played in game %s.\n\n".
1712 "It's your turn now.\n".
1713 'Use this link to play a card: '),DB_format_gameid($gameid)).$HOST.$INDEX.'?action=game&me='.$next_hash."\n\n" ;
1714 mymail($userid,$gameid, GAME_YOUR_TURN, $email_message);
1715 set_language($myid,'uid');
1718 else /* send out final email */
1720 /* individual score */
1721 $result = DB_query('SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party FROM Hand'.
1722 ' LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id'.
1723 ' LEFT JOIN User ON User.id=Hand.user_id'.
1724 ' LEFT JOIN Play ON Trick.id=Play.trick_id'.
1725 ' LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id'.
1726 ' LEFT JOIN Card ON Card.id=Hand_Card.card_id'.
1727 " WHERE Hand.game_id=".DB_quote_smart($gameid).
1728 ' GROUP BY User.fullname' );
1729 $email_final_score="";
1730 while( $r = DB_fetch_array($result) )
1731 $email_final_score .= ' '.$r[0].'('.$r[2].') '.$r[1]."\n";
1733 $result = DB_query('SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand'.
1734 ' LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id'.
1735 ' LEFT JOIN User ON User.id=Hand.user_id'.
1736 ' LEFT JOIN Play ON Trick.id=Play.trick_id'.
1737 ' LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id'.
1738 ' LEFT JOIN Card ON Card.id=Hand_Card.card_id'.
1739 " WHERE Hand.game_id=".DB_quote_smart($gameid).
1740 ' GROUP BY Hand.party' );
1744 while( $r = DB_fetch_array($result) )
1746 $email_totals .= ' '.$r[0].' '.$r[1]."\n";
1749 else if($r[0] == 'contra')
1754 * save score in database
1758 /* get calls from re/contra */
1761 foreach($userids as $user)
1763 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1764 $call = DB_get_call_by_hash($hash);
1765 $party = DB_get_party_by_hash($hash);
1769 $call = (int) $call;
1775 else if( $call < $call_re)
1778 else if($party=='contra')
1780 if($call_contra== -1)
1781 $call_contra = $call;
1782 else if( $call < $call_contra)
1783 $call_contra = $call;
1788 /* figure out who one */
1789 $winning_party = NULL;
1791 if($call_re == -1 && $call_contra == -1)
1793 /* nobody made a call, so it's easy to figure out who won */
1795 $winning_party='re';
1797 $winning_party='contra';
1801 /* if one party makes a call, they only win, iff they make enough points
1802 * if only one party made a call, the other one wins,
1803 * if the first one didn't make it
1807 $offset = 120 - $call_re;
1809 $offset--; /* since we use a > in the next equation */
1811 if($re > 120+$offset)
1812 $winning_party='re';
1813 else if ($call_contra == -1 )
1814 $winning_party='contra';
1817 if($call_contra != -1)
1819 $offset = 120 - $call_contra;
1820 if($call_contra == 0)
1821 $offset--; /* since we use a > in the next equation */
1823 if($contra > 120+$offset)
1824 $winning_party='contra';
1825 else if ($call_re == -1 )
1826 $winning_party='re';
1830 /* one point for each call of the other party in case the other party didn't win
1831 * and one point each in case the party made more than points than one of the calls
1833 if($winning_party!='contra' && $call_contra!= -1)
1835 for( $p=$call_contra;$p<=120; $p+=30 )
1837 DB_query('INSERT INTO Score'.
1838 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'re',NULL,NULL,'against$p')");
1841 for( $p=$call_contra; $p<120; $p+=30)
1844 DB_query('INSERT INTO Score'.
1845 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'re',NULL,NULL,'made$p')");
1848 if($winning_party!='re' and $call_re!= -1)
1850 for( $p=$call_re;$p<=120; $p+=30 )
1852 DB_query('INSERT INTO Score'.
1853 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'contra',NULL,NULL,'against$p')");
1856 for( $p=$call_re; $p<120; $p+=30)
1859 DB_query('INSERT INTO Score'.
1860 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'contra',NULL,NULL,'made$p')");
1864 /* point in case contra won */
1865 if($winning_party=='contra')
1867 DB_query('INSERT INTO Score'.
1868 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'contra',NULL,NULL,'againstqueens')");
1871 /* one point each for winning and each 30 points + calls */
1872 if($winning_party=='re')
1874 foreach(array(120,150,180,210,240) as $p)
1877 if($p==240 || $call_contra != -1)
1881 DB_query('INSERT INTO Score'.
1882 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'re',NULL,NULL,'".(240-$p)."')");
1884 /* re called something and won */
1885 foreach(array(0,30,60,90,120) as $p)
1887 if($call_re!= -1 && $call_re<$p+1)
1888 DB_query('INSERT INTO Score'.
1889 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'re',NULL,NULL,'call$p')");
1892 else if( $winning_party=='contra')
1894 foreach(array(120,150,180,210,240) as $p)
1897 if($p==240 || $call_re != -1)
1900 if($contra>$p-$offset)
1901 DB_query('INSERT INTO Score'.
1902 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'contra',NULL,NULL,'".(240-$p)."')");
1904 /* re called something and won */
1905 foreach(array(0,30,60,90,120) as $p)
1907 if($call_contra != -1 && $call_contra<$p+1)
1908 DB_query('INSERT INTO Score'.
1909 " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'contra',NULL,NULL,'call$p')");
1913 /* add score points to email */
1916 $email_points_re="";
1917 $queryresult = DB_query('SELECT score FROM Score '.
1918 " WHERE game_id=".DB_quote_smart($gameid)." AND party='re'");
1919 while($r = DB_fetch_array($queryresult) )
1921 $email_points_re .= ' '.$r[0]."\n";
1925 $email_points_contra="";
1926 $queryresult = DB_query('SELECT score FROM Score '.
1927 " WHERE game_id=".DB_quote_smart($gameid)." AND party='contra'");
1928 while($r = DB_fetch_array($queryresult) )
1930 $email_points_contra .= ' '.$r[0]."\n";
1934 $session = DB_get_session_by_gameid($gameid);
1935 $score = generate_score_table($session);
1937 $email_score_table = format_score_table_ascii($score);
1939 /* add user links */
1940 $email_user_links="";
1941 foreach($userids as $user)
1943 /* add links for all players */
1944 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1945 $name = DB_get_name('userid',$user);
1947 $link = "$name: ".$HOST.$INDEX."?action=game&me=".$hash."\n" ;
1948 $email_user_links .= $link;
1951 foreach($userids as $user)
1953 /* set correct language for this user */
1954 set_language($user,'uid');
1956 /* generate message */
1957 $email_message = _("The game is over. Thanks for playing :)")."\n";
1958 $email_message .= _("Final score:")."\n";
1959 $email_message .= $email_final_score;
1960 $email_message .= "\n"._("Totals:")."\n";
1961 $email_message .= $email_totals;
1962 $email_message .= "\n "._("Points Re:")." \n";
1963 $email_message .= $email_points_re;
1964 $email_message .= " "._("Points Contra:")." \n";
1965 $email_message .= $email_points_contra;
1966 $email_message .= " "._("Total Points (from the Re point of view):")." $Tpoint\n\n";
1967 $email_message .= _("Score Table:")."\n";
1968 $email_message .= $email_score_table;
1969 $email_message .= "\n"._("Use these links to have a look at game")." ".DB_format_gameid($gameid).": \n";
1970 $email_message .= $email_user_links;
1971 $email_message .= "\n\n "._("(use in-game comments to reach all players)")."\n\n";
1974 mymail($user,$gameid, GAME_OVER, $email_message);
1976 /* reset language */
1977 set_language($myid,'uid');
1982 $messages[] = _("can't find that card?!");
1985 else if(myisset('card') && !$myturn )
1987 $messages[] = _("please wait until it's your turn!");
1990 if($seq!=4 && $trickNR>=1 && !(myisset('card') && $myturn) )
1991 echo " </div>\n"; /* end div trick, end li trick */
1993 /* display points in case game is over */
1994 if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' )
1996 echo " <div class=\"trick\" id=\"trick13\">\n";
1997 /* add pic for re/contra
1998 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";*/
2000 $result = DB_query('SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party,Hand.position FROM Hand'.
2001 ' LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id'.
2002 ' LEFT JOIN User ON User.id=Hand.user_id'.
2003 ' LEFT JOIN Play ON Trick.id=Play.trick_id'.
2004 ' LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id'.
2005 ' LEFT JOIN Card ON Card.id=Hand_Card.card_id'.
2006 " WHERE Hand.game_id=".DB_quote_smart($gameid).
2007 ' GROUP BY User.fullname' );
2008 while( $r = DB_fetch_array($result))
2009 echo ' <div class="card'.($r[3]-1)."\">\n".
2010 ' <div class="score">'.$r[2].'<br /> '.$r[1]."</div>\n".
2013 /* display totals */
2014 $result = DB_query('SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand'.
2015 ' LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id'.
2016 ' LEFT JOIN User ON User.id=Hand.user_id'.
2017 ' LEFT JOIN Play ON Trick.id=Play.trick_id'.
2018 ' LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id'.
2019 ' LEFT JOIN Card ON Card.id=Hand_Card.card_id'.
2020 " WHERE Hand.game_id=".DB_quote_smart($gameid).
2021 ' GROUP BY Hand.party' );
2022 echo " <div class=\"total\">\n "._("Totals:")."<br />\n";
2023 while( $r = DB_fetch_array($result))
2024 echo ' '.$r[0].' '.$r[1]."<br />\n";
2026 $queryresult = DB_query('SELECT timediff(mod_date,create_date) '.
2027 " FROM Game WHERE id=".DB_quote_smart($gameid));
2028 $r = DB_fetch_array($queryresult);
2030 printf(_('This game took %d hours.'), $r[0]);
2033 echo " <div class=\"re\">\n "._("Points Re:")." <br />\n";
2034 $queryresult = DB_query('SELECT score FROM Score '.
2035 " WHERE game_id=".DB_quote_smart($gameid)." AND party='re'");
2036 while($r = DB_fetch_array($queryresult) )
2037 echo ' '.$r[0]."<br />\n";
2040 echo " <div class=\"contra\">\n "._("Points Contra:")." <br />\n";
2041 $queryresult = DB_query('SELECT score FROM Score '.
2042 " WHERE game_id=".DB_quote_smart($gameid)." AND party='contra'");
2043 while($r = DB_fetch_array($queryresult) )
2044 echo ' '.$r[0]."<br />\n";
2049 echo " </div>\n"; /* end div trick, end li trick */
2052 echo "</div>\n"; /* end ul tricks*/
2054 if( ($myturn && !myisset('card') && $mystatus=='play') /* it's my turn*/
2055 || ($myturn && myisset('card') && $next==$mypos && $mystatus=='play') /* a card has been played and player won the trick*/)
2057 $card_status = CARDS_MYTURN;
2059 else if($mystatus=='play' )
2061 $card_status = CARDS_SHOW;
2063 else if($mystatus=='gameover')
2065 if(isset($_SESSION['id']) && $myid==$_SESSION['id'])
2066 $card_status = CARDS_GAMEOVER_ME;
2068 $card_status = CARDS_GAMEOVER;
2071 /* if the game is over do some extra stuff, therefore exit the swtich statement if we are still playing*/
2072 if($mystatus=='play')
2075 /* the following happens only when the gamestatus is 'gameover' */
2076 /* check if game is over, display results */
2077 if(DB_get_game_status_by_gameid($gameid)=='play')
2079 $messages[] = _('The game is over for you... other people still need to play though');
2083 myerror('error in testing the status');
2084 } /*end of output: tricks, table, messages, card */
2086 /* display the 2nd half of table and the names */
2088 /***********************************
2089 * Output pre-trick if needed *
2090 * this outputs status of healthy, *
2091 * sick, etc during pre-game phase *
2092 **********************************/
2094 $posmax=5; // if user is still in init, we only show vorbehalte from players before him, otherwise all of them
2103 /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
2104 echo "\n".'<div class="tricks">'."\n";
2105 echo ' <div class="trick" id="trick0">'."\n";
2107 for($pos=1;$pos<$posmax;$pos++)
2109 $usersick = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
2110 $userid = DB_get_userid('gameid-position',$gameid,$pos);
2111 $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
2113 if($userstatus=='start' || $userstatus=='init')
2114 echo ' <div class="vorbehalt'.($pos-1).'">'._('still needs <br />to decide')."</div>\n"; /* show this to everyone */
2116 if($usersick!=NULL) /* in the init-phase we only showed players with $pos<$mypos, now we can show all */
2117 echo ' <div class="vorbehalt'.($pos-1).'">'._('sick')."</div>\n";
2119 echo ' <div class="vorbehalt'.($pos-1).'">'._('healthy')."</div>\n";
2122 /* display all comments on the top right (card1)*/
2123 $comments = DB_get_pre_comment($gameid);
2125 echo ' <div class="card1">'."\n";
2126 /* display comments */
2127 foreach( $comments as $comment )
2128 echo ' <span class="comment">'.$comment[1].': '.$comment[0]."</span>\n";
2129 echo " </div>\n"; /* end div card */
2132 echo " </div>\n </div>\n"; /* end div trick, end li trick , end tricks*/
2133 /* end displaying sickness */
2137 /* output pre-game trick in case user reloads,
2138 * only needs to be done when a team has been formed */
2139 if($myparty=='re' || $myparty=='contra')
2141 echo "\n<div class=\"tricks\">\n";
2143 echo " <div class=\"trick\" id=\"trick0\">\n";
2145 /* get information so show the cards that have been handed over in a poverty game */
2146 output_exchanged_cards($gametype);
2148 echo " </div>\n </div>\n\n"; /* end div trick, end li trick , end ul tricks */
2150 /* end output pre-game trick */
2155 /* already taken care of */
2160 display_table_end();
2166 $mycards = DB_get_hand($me);
2167 $mycards = mysort($mycards,$gametype);
2170 echo '<div class="mycards">';
2171 switch ($card_status) {
2173 echo _('Your cards are').": <br />\n";
2174 foreach($mycards as $card)
2175 display_card($card,$PREF['cardset']);
2177 case CARDS_EXCHANGE:
2178 echo '<div class="poverty"> '._('You need to get rid of a few cards')."</div>\n";
2180 echo _('Your cards are').": <br />\n";
2182 foreach($mycards as $card)
2183 display_link_card($card,$PREF['cardset'],$type);
2184 echo ' <input type="submit" class="submitbutton" value="'._('select card to give back').'" />'."\n";
2187 printf (_("Hello %s, it's your turn!"),$myname);
2189 echo _('Your cards are').": <br />\n";
2191 /* do we have to follow suite? */
2193 if(have_suit($mycards,$firstcard))
2196 /* count how many cards we can play, so that we can pre-select it if there is only one */
2198 foreach($mycards as $card)
2203 /* display only cards that the player is allowed to play as links, the rest just display normal
2204 * also check if we have both schweinchen, in that case only display on of them as playable
2206 if( ($followsuit && !same_type($card,$firstcard)) ||
2207 ( (int)($card)==19 &&
2208 !$GAME['schweinchen-first'] &&
2209 ( $RULES['schweinchen']=='second' ||
2210 ( $RULES['schweinchen']=='secondaftercall' &&
2211 (DB_get_call_by_hash($GAME['schweinchen-who']) ||
2212 DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
2215 $GAME['schweinchen-who']==$me &&
2216 in_array($gametype,array('normal','wedding','trump','silent'))
2224 /* make it boolean, so that we can pass it later to display_link_card */
2225 if($howmanycards!=1)
2228 foreach($mycards as $card)
2230 /* display only cards that the player is allowed to play as links, the rest just display normal
2231 * also check if we have both schweinchen, in that case only display on of them as playable
2233 if( ($followsuit && !same_type($card,$firstcard)) ||
2234 ( (int)($card)==19 &&
2235 !$GAME['schweinchen-first'] &&
2236 ( $RULES['schweinchen']=='second' ||
2237 ( $RULES['schweinchen']=='secondaftercall' &&
2238 (DB_get_call_by_hash($GAME['schweinchen-who']) ||
2239 DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
2242 $GAME['schweinchen-who']==$me &&
2243 in_array($gametype,array('normal','wedding','trump','silent'))
2246 display_card($card,$PREF['cardset']);
2248 display_link_card($card,$PREF['cardset'],$type='card',$selected=$howmanycards);
2251 case CARDS_GAMEOVER_ME:
2252 case CARDS_GAMEOVER:
2253 if($card_status == CARDS_GAMEOVER_ME)
2254 echo _('Your cards were').": <br />\n";
2257 $name = DB_get_name('userid',$myid);
2258 printf (_("%s's were:"),$name);
2261 $oldcards = DB_get_all_hand($me);
2262 $oldcards = mysort($oldcards,$gametype);
2264 foreach($oldcards as $card)
2265 display_card($card,$PREF['cardset']);
2267 /* display hands of everyone else */
2268 $userids = DB_get_all_userid_by_gameid($gameid);
2269 foreach($userids as $user)
2271 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
2277 $name = DB_get_name('userid',$user);
2278 $oldcards = DB_get_all_hand($userhash);
2279 $oldcards = mysort($oldcards,$gametype);
2280 printf(_("%s's cards were:"),$name);
2282 foreach($oldcards as $card)
2283 display_card($card,$PREF['cardset']);
2297 if( sizeof($messages) )
2299 echo "\n<div class=\"message\">\n";
2300 foreach($messages as $message)
2302 echo " <div>$message <div>"._("close")."</div> </div>\n";
2307 /****************************
2308 * commit commentCall to DB *
2309 ****************************/
2311 if($commentCall != '')
2313 /* treat before game calls special, so that we can show them on the first trick and not the pre-phase */
2317 DB_insert_comment($commentCall,$playid,$gameid,$myid);
2319 /***********************************************
2320 * Comments, re/contra calls, user menu
2321 ***********************************************/
2324 * display gameinfo: re/contra, comment-box, play-card button, games played by others
2327 echo "<div class=\"gameinfo\">\n";
2329 /* get time from the last action of the game */
2330 $r = DB_query_array("SELECT mod_date from Game WHERE id=".DB_quote_smart($gameid));
2331 $gameend = time() - strtotime($r[0]);
2334 if($gamestatus == 'play' || $gamestatus == 'pre' || $gameend < 60*60*24*7)
2336 echo ' '._('A short comment').":<input name=\"comment\" type=\"text\" size=\"20\" maxlength=\"100\" />\n";
2340 if($gamestatus == 'play' )
2342 $myparty = DB_get_party_by_hash($me);
2343 output_form_calls($me,$myparty);
2346 /* play-card button */
2347 if($gamestatus == 'play' || $gamestatus == 'pre' || $gameend < 60*60*24*7)
2349 echo ' <input type="submit" value="'._('submit')."\" />\n";
2352 /* has this hand been played by others? */
2353 $other_game_ids = DB_played_by_others($gameid);
2354 if(sizeof($other_game_ids)>0 && $mystatus=='gameover')
2356 $mypos = DB_get_pos_by_hash($me);
2357 echo ' <p>'._('See how other played the same hand:')." \n";
2358 foreach($other_game_ids as $id)
2360 $otherhash = DB_get_hash_from_game_and_pos($id,$mypos);
2361 $othername = DB_get_name('hash',$otherhash);
2362 echo " <a href=\"$INDEX?action=game&me=$otherhash\">$othername</a> ";
2367 echo "</div>\n\n"; /* end gameinfo */
2369 /* make sure that we don't show the notes to the wrong person
2370 * (e.g. other people looking at an old game)
2372 if( $mystatus != 'gameover' ||
2373 ( $mystatus == 'gameover' &&
2374 isset($_SESSION['id']) &&
2375 $myid == $_SESSION['id']))
2376 output_user_notes($myid,$gameid,$mystatus);
2380 /*********************************
2382 *********************************/
2384 $gamestatus = DB_get_game_status_by_gameid($gameid);
2385 if($mystatus=='gameover' &&
2386 ($gamestatus =='gameover' || $gamestatus =='cancel-nines' || $gamestatus =='cancel-trump') &&
2387 isset($_SESSION['id']) && $_SESSION['id']==$myid)
2389 $session = DB_get_session_by_gameid($gameid);
2390 $result = DB_query('SELECT id,create_date FROM Game'.
2391 " WHERE session=$session".
2392 ' ORDER BY create_date DESC'.
2396 $r = DB_fetch_array($result);
2398 if(!$session || $gameid==$r[0])
2400 /* suggest a new game with the same people in it, just rotated once (unless last game was solo) */
2401 $names = DB_get_all_names_by_gameid($gameid);
2403 if($gametype_raw=='solo')
2405 if($gametype_solo!='silent') /* repeat game with same first player */
2406 output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid);
2407 else /* rotate normally */
2408 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
2410 else if($gamestatus == 'cancel-nines' || $gamestatus == 'cancel-trump')
2411 output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid);
2412 else /* rotate normally */
2413 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);