2 /* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 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 "Can't find you in the database, please check the url.<br />\n";
40 echo "perhaps the game has been canceled, check by login in <a href=\"$INDEX\">here</a>.";
44 global $GAME,$RULES,$CARDS;
46 /**************************************
47 * get some information from the DB
48 **************************************/
49 $gameid = DB_get_gameid_by_hash($me);
50 $myname = DB_get_name('hash',$me);
51 $mystatus = DB_get_status_by_hash($me);
52 $mypos = DB_get_pos_by_hash($me);
53 $myhand = DB_get_handid('hash',$me);
54 $myparty = DB_get_party_by_hash($me);
55 $session = DB_get_session_by_gameid($gameid);
56 $playid = DB_get_current_playid($gameid); /* might be -1 at beginning of the game */
58 /* get prefs and save them in a variable*/
59 $PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid);
60 /* set language chosen in preferences, will become active on the next reload (see index.php)*/
61 $_SESSION['language'] = $PREF['language'];
62 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 = DB_get_gametype_by_gameid($gameid);
70 $gamestatus = DB_get_game_status_by_gameid($gameid);
74 $gametype = DB_get_solo_by_gameid($gameid);
75 if($gametype=='silent')
78 $GT = $gametype.' '.$GT;
81 /* do we need to worry about Schweinchen?
82 * check gametype and rules
83 * if yes, figure out if someone actually has Schweinchen
84 * save information in $GAME
87 if( $gamestatus == 'pre' )
89 /* always need to use Schweinchen to figure out for example who has poverty */
91 /* unless the gametype is set and we know that we are in poverty were schweinchen is not valid */
92 if( in_array( $gametype,array('poverty','dpoverty') ))
97 /* in a game Schweinchen is not valid in all types of games */
98 if( in_array($gametype,array('normal','wedding','trump','silent') ))
99 if( in_array($RULES['schweinchen'],array('both','second','secondaftercall')) )
103 /* these are the defaults */
104 $GAME['schweinchen-who'] = NULL;
105 $GAME['schweinchen-first'] = NULL;
106 $GAME['schweinchen-second'] = NULL;
110 /* need to check for Schweinchen */
113 $hash = DB_get_hash_from_game_and_pos($gameid,$i);
114 $cards = DB_get_all_hand($hash);
115 if( in_array('19',$cards) && in_array('20',$cards) )
116 $GAME['schweinchen-who']=$hash;
118 $GAME['schweinchen-first'] = 0; /* to keep track if they have been played already */
119 $GAME['schweinchen-second'] = 0;
121 /* end check for Schweinchen */
123 /* set the $CARDS variable, needed for sorting the cards
124 * we set it to normal so that the pre-game phase is handled ok
125 * and later set it to the correct game type that is played
127 set_gametype('normal');
129 /* handle user notes (only possible while game is running)*/
130 if( $mystatus!='gameover' )
133 $note = $_REQUEST['note'];
136 DB_insert_note($note,$gameid,$myid);
139 /*****************************************************************
140 * handle calls part1: check what was called, set everything up
141 * we only can submit it to the database at the end, since the playid
142 * might change if a player plays a card
143 *****************************************************************/
145 /* initialize comments */
148 /* check for calls, set comment */
149 if( myisset('call') )
151 if($_REQUEST['call'] == '120' && can_call(120,$me))
153 $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
156 else if($myparty=='contra')
157 $commentCall = 'Contra';
159 else if($_REQUEST['call'] == '90' && can_call(90,$me))
161 $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
162 $commentCall = 'No 90';
164 else if($_REQUEST['call'] == '60' && can_call(60,$me))
166 $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
167 $commentCall = 'No 60';
169 else if($_REQUEST['call'] == '30' && can_call(30,$me))
171 $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
172 $commentCall = 'No 30';
174 else if($_REQUEST['call'] == '0' && can_call(0,$me))
176 $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
177 $commentCall = 'Zero';
181 /**********************************************************
182 * handle comments unless we play a card at the same time *
183 * (if we play a card, we need to update playid) *
184 **********************************************************/
187 /* get time from the last action of the game */
188 $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
189 $gameend = time() - strtotime($r[0]);
191 /* handle comments in case player didn't play a card, allow comments a week after the end of the game */
192 if( (!myisset('card') && $mystatus!='gameover') || ($mystatus=='gameover' && ($gameend < 60*60*24*7)) )
193 if(myisset('comment'))
195 $comment = $_REQUEST['comment'];
198 DB_insert_comment($comment,$playid,$gameid,$myid);
202 /*****************************************************************
203 * output other games where it is the users turn
204 * make sure that the people looking at old games don't see the wrong games here
205 *****************************************************************/
207 if( $gamestatus != 'gameover' && isset($_SESSION['id']) )
209 /* game isn't over, only valid user can get here, so show menu */
210 display_user_menu($myid, $me);
212 else if( $mystatus == 'gameover' && isset($_SESSION['id']) )
214 /* user is looking at someone else's game, show the menu for the correct user */
215 display_user_menu($_SESSION['id'],$me);
219 echo "<div class=\"usermenu\">\n";
220 echo "It's your turn in these games: \n";
221 echo "Please log in to see this information.\n";
225 /*****************************************************************
226 * output extra division in case this game is part of a session
227 *****************************************************************/
230 echo "<div class=\"session\">\n";
232 /* output rule set */
233 echo " <div class=\"sessionrules\">\n "._('Rules').":\n";
234 switch($RULES['dullen'])
237 echo ' <img class="rulesicon" alt="'._('no ten of hearts').
238 "\" src=\"pics/button/no-ten-of-hearts.png\"/>\n"; break;
240 echo ' <img class="rulesicon" alt="'._('ten of hearts').
241 "\" src=\"pics/button/ten-of-hearts.png\"/>\n"; break;
243 echo ' <img class="rulesicon" alt="'._('second ten of hearts').
244 "\" src=\"pics/button/second-ten-of-hearts.png\"/>\n"; break;
246 switch($RULES['schweinchen'])
249 echo ' <img class="rulesicon" alt="'._('no schweinchen').'" '.
250 "src=\"pics/button/no-schweinchen.png\"/>\n"; break;
252 echo ' <img class="rulesicon" alt="'._('two schweinchen').'" '.
253 "src=\"pics/button/two-schweinchen.png\"/>\n"; break;
255 echo ' <img class="rulesicon" alt="'.('second schweinchen').'" '.
256 "src=\"pics/button/second-schweinchen.png\"/>\n"; break;
257 case 'secondaftercall':
258 echo ' <img class="rulesicon" alt="'._('second schweinchen after call').'" '.
259 "src=\"pics/button/second-schweinchen-after-call.png\"/>\n"; break;
261 switch($RULES['call'])
264 echo ' <img class="rulesicon" alt="'._('1st-own-card')."\" src=\"pics/button/1st-own-card.png\"/>\n"; break;
266 echo ' <img class="rulesicon" alt="'._('5th-card')."\" src=\"pics/button/5th-card.png\"/>\n"; break;
268 echo ' <img class="rulesicon" alt="'._('9-cards')."\" src=\"pics/button/9-cards.png\"/>\n"; break;
271 echo ' '._('10ofhearts').": {$RULES['dullen']} <br />\n";
272 echo ' '._('schweinchen').": {$RULES['schweinchen']} <br />\n";
273 echo ' '._('call').": {$RULES['call']} <br />\n";
274 echo ' '._('lowtrump').": {$RULES['lowtrump']} <br />\n";
275 echo " </div>\n </div>\n";
279 echo " <div class=\"sessionscore\">";
281 $score = generate_score_table($session);
283 /* get the last entry to show on the main page */
285 $finalscore = array_pop($tmpscore);
286 $finalscore = $finalscore['players'];
290 echo _('Score').": \n";
291 foreach($finalscore as $user=>$value)
293 $name = DB_get_name('userid',$user);
294 echo ' '.substr($name,0,2).": $value ";
299 /* first game, no score yet */
303 /* output all games for the score table */
304 echo format_score_table_html($score,$myid);
307 /* figure out which game in a session we are in and link to the
308 * previous and next game if possible
310 $hashes = DB_get_hashes_by_session($session,$myid);
313 foreach($hashes as $hash)
323 $previous = $hashes[$j-2];
331 /* check for solo, add game type to session number */
332 echo " Game $session.$j";
333 if($gamestatus != 'pre' && $GT !='normal' )
335 if(isset($_SESSION['id']) && $_SESSION['id']==$myid)
338 echo " <a href=\"{$INDEX}?action=game&me=$previous\">"._('previous')."</a> \n";
340 echo " <a href=\"{$INDEX}?action=game&me=$next\">"._('next')."</a> \n";
343 echo " <a href=\"{$INDEX}?action=game&me=$lasthash\">"._('last')."</a> \n";
349 /* the user has done something, update the timestamp. Use $myid in
350 * active games and check for session-id in old games (myid might be wrong in that case)
352 if($mystatus!='gameover')
353 DB_update_user_timestamp($myid);
355 if(isset($_SESSION['id']))
356 DB_update_user_timestamp($_SESSION['id']);
359 /******************************************************************************
360 * Output menu for selecting tricks
361 ******************************************************************************/
369 /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
370 echo "\n<ul class=\"tricks\">\n";
371 echo " <li onclick=\"hl(0);\" class=\"active\" id=\"tricks0\"><a href=\"#\">Pre</a>\n";
373 echo " </li>\n</ul>\n"; /* end div trick, end li trick , end tricks*/
374 /* end displaying sickness */
377 /* output pre-game trick in case user reloads,
378 * only needs to be done when a team has been formed */
379 if($myparty=='re' || $myparty=='contra')
381 echo "\n<ul class=\"tricks\">\n";
383 $mygametype = DB_get_gametype_by_gameid($gameid);
385 echo " <li onclick=\"hl(0);\" class=\"active\"><a href=\"#\">Pre</a>\n";
386 echo " </li>\n</ul>\n\n"; /* end div trick, end li trick , end ul tricks */
388 /* end output pre-game trick */
393 echo "\n<ul class=\"tricks\">\n";
395 /* output vorbehalte */
396 $mygametype = DB_get_gametype_by_gameid($gameid);
397 $mygamesolo = DB_get_solo_by_gameid($gameid);
398 if($mygametype != 'normal') /* only show when needed */
399 if(!( $mygametype == 'solo' && $mygamesolo == '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='".$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 $email_message = "Hello, \n\n".
497 "the game has been canceled due to the request of one of the players.\n\n";
499 $userids = DB_get_all_userid_by_gameid($gameid);
500 foreach($userids as $user)
501 mymail($user,$gameid,GAME_CANCELED,$email_message);
503 $card_status = CARDS_EMPTY;
505 /* update game status */
506 cancel_game('noplay',$gameid);
511 /* user wants to join the game */
513 /* move on to the next stage,
514 * no break statement to immediately go to the next stage
517 DB_set_hand_status_by_hash($me,'init');
519 /* check if everyone has reached this stage, set player in game-table to the next player */
520 $userids = DB_get_all_userid_by_gameid($gameid);
521 foreach($userids as $userid)
523 $userstat = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
524 if($userstat!='init')
526 /* whos turn is it? */
527 DB_set_player_by_gameid($gameid,$userid);
534 /***************************
535 * check if player is sick *
536 ***************************/
537 if(!myisset('solo','wedding','poverty','nines','lowtrump') )
539 $mycards = DB_get_hand($me);
540 output_check_for_sickness($me,$mycards);
546 /* check if someone selected more than one sickness */
548 if($_REQUEST['solo']!='No') $Nsickness++;
549 if($_REQUEST['wedding'] == 'yes') $Nsickness++;
550 if($_REQUEST['poverty'] == 'yes') $Nsickness++;
551 if($_REQUEST['nines'] == 'yes') $Nsickness++;
552 if($_REQUEST['lowtrump'] == 'yes') $Nsickness++;
556 $messages[] = 'You selected more than one sickness, please go back '.
557 "and answer the <a href=\"$INDEX?action=game&me=$me&in=yes\">question</a> again.";
563 /* everything is ok, save what user said and proceed */
564 $messages[] = 'Processing what you selected in the last step...';
566 /* check if this sickness needs to be handled first */
567 $gametype = DB_get_gametype_by_gameid($gameid);
568 $startplayer = DB_get_startplayer_by_gameid($gameid); /* need this to check which solo goes first */
570 if( $_REQUEST['solo']!='No' )
572 /* user wants to play a solo */
574 /* store the info in the user's hand info */
575 DB_set_solo_by_hash($me,$_REQUEST['solo']);
576 DB_set_sickness_by_hash($me,'solo');
578 $messages[] = "<br />Seems like you want to play a {$_REQUEST['solo']} solo. Got it.<br />\n";
580 if($gametype == 'solo' && $startplayer<$mypos)
581 {}/* do nothing, since someone else already is playing solo */
584 /* this solo comes first
585 * store info in game table
587 DB_set_gametype_by_gameid($gameid,'solo');
588 DB_set_startplayer_by_gameid($gameid,$mypos);
589 DB_set_solo_by_gameid($gameid,$_REQUEST['solo']);
592 else if($_REQUEST['wedding'] == 'yes')
594 /* silent solo is set further down */
595 $messages[] = _("Ok, you don't want to play a silent solo...wedding was chosen.")."<br />\n";
596 DB_set_sickness_by_hash($me,'wedding');
598 else if($_REQUEST['poverty'] == 'yes')
600 $messages[] = _("Don't think you can win with just a few trump...? Ok, poverty chosen.")." <br />\n";
601 DB_set_sickness_by_hash($me,'poverty');
603 else if($_REQUEST['nines'] == 'yes')
605 $messages[] = _("What? You just don't want to play a game because you have a few nines? Well, if no one".
606 ' is playing solo, this game will be canceled.')."<br />\n";
607 DB_set_sickness_by_hash($me,'nines');
609 else if($_REQUEST['lowtrump'] == 'yes')
611 if($RULES['lowtrump']=='cancel')
612 $messages[] = _("What? You just don't want to play a game because you have low trump? Well, if no one".
613 ' is playing solo, this game will be canceled.')."<br />\n";
615 $messages[] = _("Don't think you can win with low trumps...? Ok, poverty chosen.")." <br />.<br />\n";
617 DB_set_sickness_by_hash($me,'lowtrump');
620 /* move on to the next stage*/
621 DB_set_hand_status_by_hash($me,'check');
627 /* here we check what all players said and figure out what game we are playing
628 * this can therefore only be handled once all players finished the last stage
631 $messages[] = _('Checking if someone else selected solo, nines, wedding or poverty.');
633 /* check if everyone has reached this stage */
634 $userids = DB_get_all_userid_by_gameid($gameid);
636 foreach($userids as $userid)
638 $userstat = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
639 if($userstat!='check')
642 DB_set_player_by_gameid($gameid,$userid);
649 $messages[] = _('This step can only be handled after everyone finished the last step. '.
650 'Seems like this is not the case, so you need to wait a bit... '.
651 'you will get an email once that is the case, please use the link in '.
652 'that email to continue the game.');
656 /* Ok, everyone finished the init-phase, time to figure out what game we
657 * are playing, in case there are any solos this already
658 * will have the correct information in it */
660 $messages[] = _('Ok, everyone is done... figuring out what kind of game we are playing.');
662 $gametype = DB_get_gametype_by_gameid($gameid);
663 $startplayer = DB_get_startplayer_by_gameid($gameid);
665 /* check for sickness */
670 foreach($userids as $user)
672 $name = DB_get_name('userid',$user);
673 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
674 if($usersick == 'nines' || ($RULES['lowtrump']=='cancel' && $usersick=='lowtrump') )
677 $cancelsick = $usersick;
678 break; /* no need to check for other poverties, since only solo can win and that is already set */
680 else if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
682 else if($usersick == 'wedding')
684 else if($usersick == 'solo')
688 /* now check which sickness comes first and set the gametype to it */
689 if($gametype == 'solo')
696 if($cancelsick == 'nines')
698 $email_message = 'The game has been canceled because '.DB_get_name('userid',$cancel).
699 " has five or more nines and nobody is playing solo.\n\n".
700 "To redeal either start a new game or, in case the game was part of a tournament,\n".
701 "go to the last game and use the link at the bottom of the page to redeal.\n\n";
703 /* update game status */
704 cancel_game('nines',$gameid);
706 $messages[] = 'The game has been canceled because '.DB_get_name('userid',$cancel).
707 " has five or more nines and nobody is playing solo.";
709 else if ($cancelsick == 'lowtrump')
711 $email_message = 'The game has been canceled because '.DB_get_name('userid',$cancel).
712 " has low trump and nobody is playing solo.\n\n".
713 "To redeal either start a new game or, in case the game was part of a tournament,\n".
714 "go to the last game and use the link at the bottom of the page to redeal.\n\n";
716 /* update game status */
717 cancel_game('lowtrump',$gameid);
719 $messages[] = 'The game has been canceled because '.DB_get_name('userid',$cancel).
720 ' has low trump and nobody is playing solo.';
723 $userids = DB_get_all_userid_by_gameid($gameid);
724 foreach($userids as $user)
726 mymail($user,$gameid, GAME_CANCELED, $email_message);
731 else if($poverty==1) /* one person has poverty */
733 DB_set_gametype_by_gameid($gameid,'poverty');
734 $gametype = 'poverty';
735 $who = DB_get_sickness_by_gameid($gameid);
738 $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
739 if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
740 DB_set_sickness_by_gameid($gameid,2); /* who needs to be asked first */
742 DB_set_sickness_by_gameid($gameid,1); /* who needs to be asked first */
745 else if($poverty==2) /* two people have poverty */
747 DB_set_gametype_by_gameid($gameid,'dpoverty');
748 $gametype = 'dpoverty';
749 $who = DB_get_sickness_by_gameid($gameid);
752 $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
753 if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
755 $secondsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
756 if($secondsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
757 DB_set_sickness_by_gameid($gameid,30); /* who needs to be asked first */
759 DB_set_sickness_by_gameid($gameid,20); /* who needs to be asked first */
762 DB_set_sickness_by_gameid($gameid,10); /* who needs to be asked first */
767 DB_set_gametype_by_gameid($gameid,'wedding');
768 DB_set_sickness_by_gameid($gameid,'-1'); /* wedding not resolved yet */
769 $gametype = 'wedding';
771 /* now the gametype is set correctly in the database */
772 $messages[] = _('Got it').' :)';
774 /* loop over all players, set re/contra if possible and start the game if possible */
775 $userids = DB_get_all_userid_by_gameid($gameid);
776 foreach($userids as $userid)
778 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$userid);
783 /* are we the solo player? set us to re, else set us to contra */
784 $pos = DB_get_pos_by_hash($userhash);
785 if($pos == $startplayer)
786 DB_set_party_by_hash($userhash,'re');
788 DB_set_party_by_hash($userhash,'contra');
789 DB_set_hand_status_by_hash($userhash,'play');
793 /* set person with the wedding to re, do the rest during the game */
794 $usersick = DB_get_sickness_by_userid_and_gameid($userid,$gameid);
795 if($usersick == 'wedding')
796 DB_set_party_by_hash($userhash,'re');
798 DB_set_party_by_hash($userhash,'contra');
800 DB_set_hand_status_by_hash($userhash,'play');
804 $hand = DB_get_all_hand($userhash);
806 if(in_array('3',$hand)||in_array('4',$hand))
807 DB_set_party_by_hash($userhash,'re');
809 DB_set_party_by_hash($userhash,'contra');
810 DB_set_hand_status_by_hash($userhash,'play');
814 /* set person with poverty to play status */
815 $usersick = DB_get_sickness_by_userid_and_gameid($userid,$gameid);
816 if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
817 DB_set_hand_status_by_hash($userhash,'play');
819 /* set status of first player to be asked to poverty */
820 $who = DB_get_sickness_by_gameid($gameid);
821 if($who > 6) $who= $who/10; /* in case we have dpoverty */
822 $whoid = DB_get_userid('gameid-position',$gameid,$who);
824 DB_set_hand_status_by_hash($userhash,'poverty');
827 /* check for silent solo, set game type to solo in this case */
828 $gametype = DB_get_gametype_by_gameid($gameid);
829 $userids = DB_get_all_userid_by_gameid($gameid);
830 foreach($userids as $userid)
832 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$userid);
834 if($gametype=='normal')
836 $userhand = DB_get_all_hand($userhash);
837 if(check_wedding($userhand))
839 /* normal game type and player has both queens -> silent solo */
840 /* keep startplayer, just set gametype to silent solo */
841 DB_set_gametype_by_gameid($gameid,'solo');
842 DB_set_solo_by_gameid($gameid,'silent');
847 /* send out email to first player or poverty person*/
848 if($gametype!='poverty' && $gametype!='dpoverty')
850 $startplayer = DB_get_startplayer_by_gameid($gameid);
851 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
852 $userid = DB_get_userid('hash',$hash);
853 DB_set_player_by_gameid($gameid,$userid);
857 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
859 /* email startplayer */
860 $email_message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
861 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
862 mymail($userid,$gameid,GAME_READY,$email_message);
866 $messages[] = "Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br />\n";
870 /* set status of first player to be asked to poverty */
871 $who = DB_get_sickness_by_gameid($gameid);
872 if($who > 6) $who= $who/10; /* in case we have dpoverty */
874 $whoid = DB_get_userid('gameid-position',$gameid,$who);
876 $messages[] = "Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br /\n";
879 $whohash = DB_get_hash_from_game_and_pos($gameid,$who);
880 DB_set_player_by_gameid($gameid,$whoid);
882 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
884 /* email player for poverty */
885 $email_message = "Poverty: It's your turn now in game ".DB_format_gameid($gameid).".\n".
886 'Use this link to play a card: '.$HOST.$INDEX."?action=game&me=".$whohash."\n\n" ;
887 mymail($whoid,$gameid,GAME_POVERTY,$email_message);
895 /* user only gets here in a poverty game, several things have to be handled here:
896 * A) ask, if user wants to take trump
898 * poverty: set re/contra
899 * dpoverty: first time: set re, send email to second player
900 * second time: set contra
901 * poverty: set status of other players to 'play'
902 * set status to play in case 0 trump
903 * no -> set status to play,
904 * ask next player or cancle the game if no more players
905 * B) user took trump and has too many cards (e.g. count(cards)>12 and re/contra set)
906 * ask to give cards back, set status to play, once player has 12 cards
908 * it is easier to check B) first
911 set_gametype($gametype); /* this sets the $CARDS variable */
912 $myparty = DB_get_party_by_hash($me);
914 /* the following is part B) of whats needs to be done)
915 /* check if user wants to give cards back */
916 if(myisset('exchange'))
918 $exchange = $_REQUEST['exchange'];
919 $partnerhash = DB_get_partner_hash_by_hash($me);
920 $partnerid = DB_get_userid('hash',$partnerhash);
921 $partnerhand = DB_get_handid('gameid-userid',$gameid,$partnerid);
923 /* if exchange is set to a value>0, exchange that card back to the partner */
926 $result = DB_query("UPDATE Hand_Card SET hand_id='$partnerhand'".
927 " WHERE hand_id='$myhand' AND card_id=".DB_quote_smart($exchange));
928 DB_add_exchanged_card(DB_quote_smart($exchange),$myhand,$partnerhand);
933 $mycards = DB_get_hand($me);
935 /* check if user need to give more cards back */
936 if( ($myparty=='re' || $myparty=='contra') && count($mycards)>12)
938 $card_status = CARDS_EXCHANGE;
940 else if( ($myparty=='re' || $myparty=='contra') && count($mycards)==12)
942 /* user is done, ready to play */
943 DB_set_hand_status_by_hash($me,'play');
945 /* email start player */
946 $startplayer = DB_get_startplayer_by_gameid($gameid);
947 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
948 $userid = DB_get_userid('hash',$hash);
949 DB_set_player_by_gameid($gameid,$userid);
953 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
955 /* email startplayer */
956 $email_message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
957 'Use this link to play a card: '.$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
958 mymail($userid,$gameid,GAME_READY,$email_message);
962 $messages[]= "Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.";
965 /* the following is part A) of what needs to be done */
966 if(!myisset('trump'))
970 echo "<div class=\"poverty\">\n";
971 $userids = DB_get_all_userid_by_gameid($gameid);
972 foreach($userids as $user)
974 $name = DB_get_name('userid',$user);
975 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
976 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
977 $userparty = DB_get_party_by_hash($userhash);
979 if(($usersick=='poverty'|| ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump')) && !$userparty)
981 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
982 $cards = DB_get_hand($hash);
985 foreach($cards as $card)
986 if($card<27) $nrtrump++;
988 if($usersick=='lowtrump')
990 echo "Player $name has $nrtrump $low trump. Do you want to take them?".
991 "<a href=\"index.php?action=game&me=$me&trump=$user\">Yes</a> <br />\n";
994 echo "<a href=\"index.php?action=game&me=$me&trump=no\">No way</a> <br />\n";
1001 $trump = $_REQUEST['trump'];
1005 /* user doesn't want to take trump */
1006 DB_set_hand_status_by_hash($me,'play');
1008 /* set next player who needs to be asked and email him*/
1009 $firstsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+1,$gameid);
1010 $secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
1012 /* don't ask people who have poverty */
1014 if($firstsick=='poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
1016 if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
1021 if($gametype=='dpoverty')
1023 $next=999; /* need to cancel for sure, since both would need to take the trump */
1026 /* no more people to ask, need to cancel the game */
1029 $email_message = "Hello, \n\n".
1030 'Game '.DB_format_gameid($gameid)." has been canceled since nobody wanted to take the trump.\n\n";
1032 $userids = DB_get_all_userid_by_gameid($gameid);
1033 foreach($userids as $user)
1035 mymail($user, $gameid, GAME_CANCELED_POVERTY, $email_message);
1038 /* update game status */
1039 cancel_game('trump',$gameid);
1041 $messages[] = 'Game '.DB_format_gameid($gameid).' has been canceled.';
1046 /* email next player, set his status to poverty */
1047 $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
1048 $userid = DB_get_userid('hash',$userhash);
1050 DB_set_player_by_gameid($gameid,$userid);
1051 DB_set_hand_status_by_hash($userhash,'poverty');
1053 $email_message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
1054 " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
1055 mymail($userid,$gameid, GAME_POVERTY, $email_message);
1058 $cards_status = CARDS_SHOW;
1062 /* player wants to take trump, change cards */
1064 /* user wants to take trump */
1065 $trump = $_REQUEST['trump'];
1066 $userhand = DB_get_handid('gameid-userid',$gameid,$trump);
1067 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$trump);
1069 /* remember which cards were handed over*/
1070 $partnerhand = DB_get_all_hand($userhash);
1071 foreach ($partnerhand as $card)
1073 DB_add_exchanged_card($card,$userhand,$myhand);
1075 /* copy trump from player A to B */
1076 $result = DB_query("UPDATE Hand_Card SET hand_id='$myhand' WHERE hand_id='$userhand' AND card_id<'27'" );
1079 $mycards = DB_get_hand($me);
1082 if($gametype=='poverty')
1084 $userids = DB_get_all_userid_by_gameid($gameid);
1085 foreach($userids as $user)
1087 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1088 if($hash==$userhash||$hash==$me)
1090 DB_set_party_by_hash($hash,'re');
1094 DB_set_party_by_hash($hash,'contra');
1095 DB_set_hand_status_by_hash($hash,'play'); /* the contra party is ready to play */
1098 /* check if we are done (in case of no trump handed over), if so, go to 'play' phase right away*/
1099 if(count($mycards)==12)
1101 DB_set_hand_status_by_hash($me,'play');
1106 /* has the re party already been set?*/
1108 $userids = DB_get_all_userid_by_gameid($gameid);
1109 foreach($userids as $user)
1111 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1112 $party = DB_get_party_by_hash($hash);
1118 DB_set_party_by_hash($me,'contra');
1119 DB_set_party_by_hash($userhash,'contra');
1123 DB_set_party_by_hash($me,'re');
1124 DB_set_party_by_hash($userhash,'re');
1126 /* send out email to second non-poverty player */
1127 $firstsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+1,$gameid);
1128 $secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
1131 if($firstsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
1132 if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
1138 $messages[] = "Error in poverty, please contact the Admin ($ADMIN_NAME at $ADMIN_EMAIL)";
1140 $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
1141 $userid = DB_get_userid('hash',$userhash);
1143 DB_set_player_by_gameid($gameid,$userid);
1144 DB_set_hand_status_by_hash($userhash,'poverty');
1146 $email_message = "Two people have poverty, it's your turn to decide, if you want to take the trump. Please visit:".
1147 " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
1148 mymail($userid,$gameid, GAME_DPOVERTY, $email_message);
1151 $messages[] = "Please, <a href=\"$INDEX?action=game&me=$me\">continue</a> here";
1158 /* both entries here, so that the tricks are visible for both.
1159 * in case of 'play' there is a break later that skips the last part
1162 /* first check if the game has been canceled and display */
1165 case 'cancel-noplay':
1166 $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.";
1168 case 'cancel-timedout':
1169 $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.";
1171 case 'cancel-nines':
1172 $messages[] = 'The game has been canceled because one player had too many nines.';
1174 case 'cancel-lowtrump':
1175 $messages[] = 'The game has been canceled because one player had low trump.';
1177 case 'cancel-trump':
1178 $messages[] = 'The game has been canceled because nobody wanted to take the trump.';
1181 /* for these two types, we shouldn't show the cards, since we might want to restart the game */
1182 if (in_array($gamestatus,array('cancel-noplay','cancel-timedout')))
1185 /* check if all players are ready to play,
1186 * if so, send out email to the startplayer
1187 * only need to do this if the game hasn't started yet
1189 $gamestatus = DB_get_game_status_by_gameid($gameid);
1190 if($gamestatus == 'pre')
1193 $userids = DB_get_all_userid_by_gameid($gameid);
1194 foreach($userids as $userid)
1196 $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
1197 if($userstatus !='play' && $userstatus!='gameover')
1200 DB_set_player_by_gameid($gameid,$userid);
1206 /* only set this after all poverty, etc. are handled*/
1207 DB_set_game_status_by_gameid($gameid,'play');
1209 /* email startplayer */
1210 $startplayer = DB_get_startplayer_by_gameid($gameid);
1211 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
1212 $userid = DB_get_userid('hash',$hash);
1213 DB_set_player_by_gameid($gameid,$userid);
1215 if($hash!=$me && DB_get_email_pref_by_hash($hash)!='emailaddict')
1217 /* email startplayer) */
1218 $email_message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
1219 'Use this link to play a card: '.$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
1220 mymail($userid,$gameid, GAME_READY, $email_message);
1224 /* figure out what kind of game we are playing,
1225 * set the global variables $CARDS['trump'],$CARDS['diamonds'],$CARDS['hearts'],
1226 * $CARDS['clubs'],$CARDS['spades'],$CARDS['foxes']
1230 $gametype = DB_get_gametype_by_gameid($gameid);
1232 if($gametype=='solo')
1234 $gametype = DB_get_solo_by_gameid($gameid);
1235 if($gametype=='silent')
1238 $GT = $gametype.' '.$GT;
1241 $gametype = 'normal';
1243 set_gametype($gametype); /* this sets the $CARDS variable */
1245 /* get some infos about the game, need to reset this, since it might have changed */
1246 $gamestatus = DB_get_game_status_by_gameid($gameid);
1248 /* has the game started? No, then just wait here...*/
1249 if($gamestatus == 'pre')
1251 $messages[] = _('You finished the setup, but not everyone else finished it... '.
1252 'You need to wait for the others. Just wait for an email.');
1254 break; /* not sure this works... the idea is that you can
1255 * only play a card after everyone is ready to play */
1258 /* get everything relevant to display the tricks */
1259 $result = DB_query('SELECT Hand_Card.card_id as card,'.
1260 ' Hand.position as position,'.
1261 ' Play.sequence as sequence, '.
1263 " GROUP_CONCAT(CONCAT('<span>',User.fullname,': ',Comment.comment,'</span>')".
1264 " SEPARATOR '\n' ), ".
1265 ' Play.create_date, '.
1268 'LEFT JOIN Play ON Trick.id=Play.trick_id '.
1269 'LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id '.
1270 'LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id '.
1271 'LEFT JOIN Comment ON Play.id=Comment.play_id '.
1272 'LEFT JOIN User On User.id=Comment.user_id '.
1273 "WHERE Trick.game_id='".$gameid."' ".
1274 'GROUP BY Trick.id, sequence '.
1275 'ORDER BY Trick.id, sequence ASC');
1277 $lasttrick = DB_get_max_trickid($gameid);
1279 $play = array(); /* needed to calculate winner later */
1281 $pos = DB_get_startplayer_by_gameid($gameid)-1;
1282 $firstcard = ''; /* first card in a trick */
1284 echo "\n<div class=\"tricks\">\n";
1286 /* output vorbehalte */
1287 $mygametype = DB_get_gametype_by_gameid($gameid);
1288 $mygamesolo = DB_get_solo_by_gameid($gameid);
1289 $show_pre_game_comments=1;
1290 if($mygametype != 'normal') /* only show when needed */
1291 if(!( $mygametype == 'solo' && $mygamesolo == 'silent') )
1293 echo " <div class=\"trick\" id=\"trick0\">\n";
1295 /* get information so show the cards that have been handed over in a poverty game */
1296 output_exchanged_cards();
1297 $show_pre_game_comments=0;
1299 echo " </div>\n"; /* end div trick, end li trick */
1301 if($show_pre_game_comments==1)
1303 /* display all comments on the top right (card1)*/
1304 $comments = DB_get_pre_comment($gameid);
1306 if(sizeof($comments))
1308 echo " <div class=\"trick\" id=\"trick0\">\n";
1310 echo " <div class=\"card1\">\n";
1311 /* display comments */
1312 foreach( $comments as $comment )
1313 echo " <span class=\"comment\">".$comment[1].": ".$comment[0]."</span>\n";
1314 echo " </div>\n"; /* end div card */
1316 echo " </div>\n"; /* end div trick, end li trick */
1321 while($r = DB_fetch_array($result))
1329 /* count number of tricks */
1333 /* check if first schweinchen has been played */
1334 if( $GAME['schweinchen-who'] && ($r[0] == 19 || $r[0] == 20) )
1335 if(!$GAME['schweinchen-first'])
1336 $GAME['schweinchen-first'] = 1; /* playing the first fox */
1338 $GAME['schweinchen-second'] = 1; /* this must be the second fox */
1340 /* save card to be able to find the winner of the trick later */
1341 $play[$seq] = array('card'=>$r[0],'pos'=>$pos);
1345 /* first card in a trick, output some html */
1346 if($trick!=$lasttrick)
1348 /* start of an old trick? */
1349 echo " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
1350 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1352 else if($trick==$lasttrick)
1354 /* start of a last trick? */
1355 echo " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
1356 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1359 /* remember first card, so that we are able to check, what cards can be played */
1364 echo " <div class=\"card".($pos-1)."\">\n";
1366 /* for the first card, we also need to display calls from other players */
1367 if($seq==1 && $trickNR==1)
1369 $commentPreCalls=DB_get_pre_comment_call($gameid);
1370 foreach ($commentPreCalls as $pre )
1371 $comment .= $pre[1].": ".$pre[0]."<br/>";
1374 /* display comments */
1376 echo " <span class=\"comment\">".$comment."</span>\n";
1379 display_card($r[0],$PREF['cardset']);
1381 echo " </div>\n"; /* end div card */
1386 $winner = get_winner($play,$gametype); /* returns the position */
1387 echo " </div>\n"; /* end div trick, end li trick */
1391 /* whos turn is it? */
1394 $winner = get_winner($play,$gametype); /* returns the position */
1396 $firstcard = ''; /* new trick, no first card */
1401 if($next==5) $next = 1;
1404 /* my turn?, display cards as links, ask for comments*/
1405 if(DB_get_pos_by_hash($me) == $next)
1410 /* do we want to play a card? */
1411 if(myisset('card') && $myturn)
1413 $card = $_REQUEST['card'];
1414 $handid = DB_get_handid('hash',$me);
1415 $commentSchweinchen =''; /* used to add a comment when Schweinchen is being played */
1417 /* check if we have card and that we haven't played it yet*/
1418 /* set played in hand_card to true where hand_id and card_id*/
1419 $r = DB_query_array("SELECT id FROM Hand_Card WHERE played='false' and ".
1420 "hand_id='$handid' AND card_id=".DB_quote_smart($card));
1421 $handcardid = $r[0];
1423 if($handcardid) /* everything ok, play card */
1425 /* update Game timestamp */
1426 DB_update_game_timestamp($gameid);
1428 /* mark card as played */
1429 DB_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
1430 DB_quote_smart($card));
1432 /* get trick id or start new trick */
1433 $a = DB_get_current_trickid($gameid);
1438 $playid = DB_play_card($trickid,$handcardid,$sequence);
1440 /* check special output for schweinchen in case in case a fox is being played
1441 * check for correct rules, etc. has already been done
1443 if( $GAME['schweinchen-who'] && ($card == 19 || $card == 20) )
1445 if(!$GAME['schweinchen-first'])
1446 $GAME['schweinchen-first'] = 1; /* playing the first fox */
1448 $GAME['schweinchen-second'] = 1; /* this must be the second fox */
1450 if( $RULES['schweinchen']=='both' ||
1451 ($RULES['schweinchen']=='second' && $GAME['schweinchen-second']==1 )||
1452 ($RULES['schweinchen']=='secondaftercall' && $GAME['schweinchen-second']==1 &&
1453 (DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) ))
1456 DB_insert_comment('Schweinchen! ',$playid,$gameid,$myid);
1457 $commentSchweinchen = 'Schweinchen! ';
1460 echo 'schweinchen = '.$GAME['schweinchen-who'].' ---<br />';
1463 /* if sequence == 4 check who one in case of wedding */
1464 if($sequence == 4 && $GT == 'wedding')
1466 /* is wedding resolve */
1467 $resolved = DB_get_sickness_by_gameid($gameid);
1470 /* who has wedding */
1471 $userids = DB_get_all_userid_by_gameid($gameid);
1472 foreach($userids as $user)
1474 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
1475 if($usersick == 'wedding')
1478 /* who won the trick */
1479 $play = DB_get_cards_by_trick($trickid);
1480 $winner = get_winner($play,$gametype); /* returns the position */
1481 $winnerid = DB_get_userid('gameid-position',$gameid,$winner);
1482 /* is tricknr <=3 */
1483 if($tricknr <=3 && $winnerid!=$whosick)
1485 /* set resolved at tricknr*/
1486 $resolved = DB_set_sickness_by_gameid($gameid,$tricknr);
1488 $whash = DB_get_hash_from_gameid_and_userid($gameid,$winnerid);
1489 DB_set_party_by_hash($whash,'re');
1491 if($tricknr == 3 && $winnerid==$whosick)
1493 /* set resolved at tricknr*/
1494 $resolved = DB_set_sickness_by_gameid($gameid,'3');
1499 /* if sequence == 4, set winner of the trick, count points and set the next player */
1502 $play = DB_get_cards_by_trick($trickid);
1503 $winner = get_winner($play,$gametype); /* returns the position */
1506 * check if someone caught a fox
1507 *******************************/
1509 /* first check if we should account for solos at all,
1510 * since it doesn't make sense in some games
1512 $ok = 0; /* fox shouldn't be counted */
1513 if(DB_get_gametype_by_gameid($gameid)=='solo')
1515 $solo = DB_get_solo_by_gameid($gameid);
1516 if($solo == 'trump' || $solo == 'silent')
1517 $ok = 1; /* for trump solos and silent solos, foxes are ok */
1520 $ok = 1; /* for all other games (not solos) foxes are ok too */
1523 foreach($play as $played)
1525 if ( $played['card']==19 || $played['card']==20 )
1526 if ($played['pos']!= $winner )
1528 /* possible caught a fox, check party */
1529 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1530 $uid2 = DB_get_userid('gameid-position',$gameid,$played['pos']);
1532 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1533 $party2 = DB_get_party_by_gameid_and_userid($gameid,$uid2);
1535 if($party1 != $party2)
1536 DB_query("INSERT INTO Score".
1537 " VALUES( NULL,NULL,$gameid,'$party1',$uid1,$uid2,'fox')");
1542 * check for karlchen (jack of clubs in the last trick)
1543 ******************************************************/
1545 /* same as for foxes, karlchen doesn't always make sense
1546 * check what kind of game it is and set karlchen accordingly */
1548 if($tricknr == 12 ) /* Karlchen works only in the last trick */
1550 /* check for solo */
1552 if(DB_get_gametype_by_gameid($gameid)=='solo' )
1553 $solo = DB_get_solo_by_gameid($gameid);
1555 /* no Karlchen in these solos */
1556 if($solo != 'trumpless' && $solo != 'jack' && $solo != 'queen' )
1558 foreach($play as $played)
1559 if ( $played['card']==11 || $played['card']==12 )
1560 if ($played['pos'] == $winner )
1563 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1564 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1566 DB_query("INSERT INTO Score".
1567 " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')");
1570 }; /* end scoring Karlchen */
1573 * check for doppelopf (>40 points)
1574 ***********************************/
1577 foreach($play as $played)
1579 $points += DB_get_card_value_by_cardid($played['card']);
1583 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1584 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1586 DB_query("INSERT INTO Score".
1587 " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'doko')");
1591 * set winner (for this trick)
1595 DB_query("UPDATE Trick SET winner='$winner' WHERE id='$trickid'");
1597 $messages[] = "ERROR during scoring";
1600 echo "DEBUG: position $winner won the trick <br />";
1602 /* who is the next player? */
1604 $firstcard = ''; /* unset firstcard, so followsuit doesn't trigger with the last trick */
1608 $next = DB_get_pos_by_hash($me)+1;
1610 if($next==5) $next=1;
1612 /* check for coment */
1613 if(myisset('comment'))
1615 $comment = $_REQUEST['comment'];
1617 DB_insert_comment($comment,$playid,$gameid,$myid);
1618 if($commentSchweinchen)
1619 $comment = $commentSchweinchen . $comment;
1620 if($commentCall != '')
1621 $comment = $commentCall . $comment;
1624 /* display played card */
1625 $pos = DB_get_pos_by_hash($me);
1628 echo ' <div class="trick" id="trick'.($tricknr)."\">\n".
1629 ' <img class="arrow" src="pics/arrow'.($pos-1).".png\" alt=\"table\" />\n";
1632 echo ' <div class="card'.($pos-1)."\">\n ";
1634 /* display comments */
1635 display_card($card,$PREF['cardset']);
1637 echo "\n <span class=\"comment\"> ".$comment."</span>\n";
1640 echo " </div>\n"; /* end div trick, end li trick */
1642 /*check if we still have cards left, else set status to gameover */
1643 if(sizeof(DB_get_hand($me))==0)
1645 DB_set_hand_status_by_hash($me,'gameover');
1646 $mystatus = 'gameover';
1649 /* if all players are done, set game status to game over,
1650 * get the points of the last trick and send out an email
1653 $userids = DB_get_all_userid_by_gameid($gameid);
1656 foreach($userids as $user)
1657 if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='gameover')
1661 DB_set_game_status_by_gameid($gameid,'gameover');
1663 /* email next player, if game is still running */
1664 if(DB_get_game_status_by_gameid($gameid)=='play')
1666 $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
1667 $userid = DB_get_userid('hash',$next_hash);
1668 DB_set_player_by_gameid($gameid,$userid);
1670 $email_message = 'A card has been played in game '.DB_format_gameid($gameid).".\n\n".
1671 "It's your turn now.\n".
1672 'Use this link to play a card: '.$HOST.$INDEX.'?action=game&me='.$next_hash."\n\n" ;
1673 if( DB_get_email_pref_by_uid($userid)!='emailaddict' )
1675 mymail($userid,$gameid, GAME_YOUR_TURN, $email_message);
1678 else /* send out final email */
1680 /* individual score */
1681 $result = DB_query('SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party FROM Hand'.
1682 ' LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id'.
1683 ' LEFT JOIN User ON User.id=Hand.user_id'.
1684 ' LEFT JOIN Play ON Trick.id=Play.trick_id'.
1685 ' LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id'.
1686 ' LEFT JOIN Card ON Card.id=Hand_Card.card_id'.
1687 " WHERE Hand.game_id='$gameid'".
1688 ' GROUP BY User.fullname' );
1689 $email_message = "The game is over. Thanks for playing :)\n";
1690 $email_message .= "Final score:\n";
1691 while( $r = DB_fetch_array($result) )
1692 $email_message .= ' '.$r[0].'('.$r[2].') '.$r[1]."\n";
1694 $result = DB_query('SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand'.
1695 ' LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id'.
1696 ' LEFT JOIN User ON User.id=Hand.user_id'.
1697 ' LEFT JOIN Play ON Trick.id=Play.trick_id'.
1698 ' LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id'.
1699 ' LEFT JOIN Card ON Card.id=Hand_Card.card_id'.
1700 " WHERE Hand.game_id='$gameid'".
1701 ' GROUP BY Hand.party' );
1702 $email_message .= "\nTotals:\n";
1705 while( $r = DB_fetch_array($result) )
1707 $email_message .= ' '.$r[0].' '.$r[1]."\n";
1710 else if($r[0] == 'contra')
1715 * save score in database
1719 /* get calls from re/contra */
1722 foreach($userids as $user)
1724 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1725 $call = DB_get_call_by_hash($hash);
1726 $party = DB_get_party_by_hash($hash);
1730 $call = (int) $call;
1736 else if( $call < $call_re)
1739 else if($party=='contra')
1741 if($call_contra== -1)
1742 $call_contra = $call;
1743 else if( $call < $call_contra)
1744 $call_contra = $call;
1749 /* figure out who one */
1750 $winning_party = NULL;
1752 if($call_re == -1 && $call_contra == -1)
1754 /* nobody made a call, so it's easy to figure out who won */
1756 $winning_party='re';
1758 $winning_party='contra';
1762 /* if one party makes a call, they only win, iff they make enough points
1763 * if only one party made a call, the other one wins,
1764 * if the first one didn't make it
1768 $offset = 120 - $call_re;
1770 $offset--; /* since we use a > in the next equation */
1772 if($re > 120+$offset)
1773 $winning_party='re';
1774 else if ($call_contra == -1 )
1775 $winning_party='contra';
1778 if($call_contra != -1)
1780 $offset = 120 - $call_contra;
1781 if($call_contra == 0)
1782 $offset--; /* since we use a > in the next equation */
1784 if($contra > 120+$offset)
1785 $winning_party='contra';
1786 else if ($call_re == -1 )
1787 $winning_party='re';
1791 /* one point for each call of the other party in case the other party didn't win
1792 * and one point each in case the party made more than points than one of the calls
1794 if($winning_party!='contra' && $call_contra!= -1)
1796 for( $p=$call_contra;$p<=120; $p+=30 )
1798 DB_query('INSERT INTO Score'.
1799 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'against$p')");
1802 for( $p=$call_contra; $p<120; $p+=30)
1805 DB_query('INSERT INTO Score'.
1806 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'made$p')");
1809 if($winning_party!='re' and $call_re!= -1)
1811 for( $p=$call_re;$p<=120; $p+=30 )
1813 DB_query('INSERT INTO Score'.
1814 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'against$p')");
1817 for( $p=$call_re; $p<120; $p+=30)
1820 DB_query('INSERT INTO Score'.
1821 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'made$p')");
1825 /* point in case contra won */
1826 if($winning_party=='contra')
1828 DB_query('INSERT INTO Score'.
1829 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'againstqueens')");
1832 /* one point each for winning and each 30 points + calls */
1833 if($winning_party=='re')
1835 foreach(array(120,150,180,210,240) as $p)
1838 if($p==240 || $call_contra != -1)
1842 DB_query('INSERT INTO Score'.
1843 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'".(240-$p)."')");
1845 /* re called something and won */
1846 foreach(array(0,30,60,90,120) as $p)
1848 if($call_re!= -1 && $call_re<$p+1)
1849 DB_query('INSERT INTO Score'.
1850 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'call$p')");
1853 else if( $winning_party=='contra')
1855 foreach(array(120,150,180,210,240) as $p)
1858 if($p==240 || $call_re != -1)
1861 if($contra>$p-$offset)
1862 DB_query('INSERT INTO Score'.
1863 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'".(240-$p)."')");
1865 /* re called something and won */
1866 foreach(array(0,30,60,90,120) as $p)
1868 if($call_contra != -1 && $call_contra<$p+1)
1869 DB_query('INSERT INTO Score'.
1870 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'call$p')");
1875 /* add score points to email */
1876 $email_message .= "\n";
1878 $email_message .= " Points Re: \n";
1879 $queryresult = DB_query('SELECT score FROM Score '.
1880 " WHERE game_id=$gameid AND party='re'");
1881 while($r = DB_fetch_array($queryresult) )
1883 $email_message .= ' '.$r[0]."\n";
1886 $email_message .= " Points Contra: \n";
1887 $queryresult = DB_query('SELECT score FROM Score '.
1888 " WHERE game_id=$gameid AND party='contra'");
1889 while($r = DB_fetch_array($queryresult) )
1891 $email_message .= ' '.$r[0]."\n";
1894 $email_message .= " Total Points (from the Re point of view): $Tpoint\n";
1895 $email_message .= "\n";
1897 $session = DB_get_session_by_gameid($gameid);
1898 $score = generate_score_table($session);
1900 $email_message .= "Score Table:\n";
1901 $email_message .= format_score_table_ascii($score);
1902 $email_message .= "\nUse these links to have a look at game ".DB_format_gameid($gameid).": \n";
1904 /* send out final email */
1905 foreach($userids as $user)
1907 /* add links for all players */
1908 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1909 $name = DB_get_name('userid',$user);
1911 $link = "$name: ".$HOST.$INDEX."?action=game&me=".$hash."\n" ;
1912 $email_message .= $link;
1914 $email_message .= "\n\n (you can use reply all on this email to reach all the players.)\n\n";
1915 mymail($userids,$gameid, GAME_OVER, $email_message);
1920 $messages[] = "can't find that card?!";
1923 else if(myisset('card') && !$myturn )
1925 $messages[] = _("please wait until it's your turn!");
1928 if($seq!=4 && $trickNR>=1 && !(myisset('card') && $myturn) )
1929 echo " </div>\n"; /* end div trick, end li trick */
1931 /* display points in case game is over */
1932 if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' )
1934 echo " <div class=\"trick\" id=\"trick13\">\n";
1935 /* add pic for re/contra
1936 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";*/
1938 $result = DB_query('SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party,Hand.position FROM Hand'.
1939 ' LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id'.
1940 ' LEFT JOIN User ON User.id=Hand.user_id'.
1941 ' LEFT JOIN Play ON Trick.id=Play.trick_id'.
1942 ' LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id'.
1943 ' LEFT JOIN Card ON Card.id=Hand_Card.card_id'.
1944 " WHERE Hand.game_id='$gameid'".
1945 ' GROUP BY User.fullname' );
1946 while( $r = DB_fetch_array($result))
1947 echo ' <div class="card'.($r[3]-1)."\">\n".
1948 ' <div class="score">'.$r[2].'<br /> '.$r[1]."</div>\n".
1951 /* display totals */
1952 $result = DB_query('SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand'.
1953 ' LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id'.
1954 ' LEFT JOIN User ON User.id=Hand.user_id'.
1955 ' LEFT JOIN Play ON Trick.id=Play.trick_id'.
1956 ' LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id'.
1957 ' LEFT JOIN Card ON Card.id=Hand_Card.card_id'.
1958 " WHERE Hand.game_id='$gameid'".
1959 ' GROUP BY Hand.party' );
1960 echo " <div class=\"total\">\n Totals:<br />\n";
1961 while( $r = DB_fetch_array($result))
1962 echo ' '.$r[0].' '.$r[1]."<br />\n";
1964 $queryresult = DB_query('SELECT timediff(mod_date,create_date) '.
1965 " FROM Game WHERE id='$gameid'");
1966 $r = DB_fetch_array($queryresult);
1967 echo ' <p>This game took '.$r[0]." hours.</p>\n";
1969 echo " <div class=\"re\">\n Points Re: <br />\n";
1970 $queryresult = DB_query('SELECT score FROM Score '.
1971 " WHERE game_id=$gameid AND party='re'");
1972 while($r = DB_fetch_array($queryresult) )
1973 echo ' '.$r[0]."<br />\n";
1976 echo " <div class=\"contra\">\n Points Contra: <br />\n";
1977 $queryresult = DB_query('SELECT score FROM Score '.
1978 " WHERE game_id=$gameid AND party='contra'");
1979 while($r = DB_fetch_array($queryresult) )
1980 echo ' '.$r[0]."<br />\n";
1985 echo " </div>\n"; /* end div trick, end li trick */
1988 echo "</div>\n"; /* end ul tricks*/
1990 if( ($myturn && !myisset('card') && $mystatus=='play') /* it's my turn*/
1991 || ($myturn && myisset('card') && $next==$mypos && $mystatus=='play') /* a card has been played and player won the trick*/)
1993 $card_status = CARDS_MYTURN;
1995 else if($mystatus=='play' )
1997 $card_status = CARDS_SHOW;
1999 else if($mystatus=='gameover')
2001 if(isset($_SESSION['id']) && $myid==$_SESSION['id'])
2002 $card_status = CARDS_GAMEOVER_ME;
2004 $card_status = CARDS_GAMEOVER;
2007 /* if the game is over do some extra stuff, therefore exit the swtich statement if we are still playing*/
2008 if($mystatus=='play')
2011 /* the following happens only when the gamestatus is 'gameover' */
2012 /* check if game is over, display results */
2013 if(DB_get_game_status_by_gameid($gameid)=='play')
2015 $messages[] = _('The game is over for you... other people still need to play though');
2019 myerror('error in testing the status');
2020 } /*end of output: tricks, table, messages, card */
2022 /* display the 2nd half of table and the names */
2024 /***********************************
2025 * Output pre-trick if needed *
2026 * this outputs status of healthy, *
2027 * sick, etc during pre-game phase *
2028 **********************************/
2035 /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
2036 echo "\n".'<div class="tricks">'."\n";
2037 echo ' <div class="trick" id="trick0">'."\n";
2039 for($pos=1;$pos<5;$pos++)
2041 $usersick = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
2042 $userid = DB_get_userid('gameid-position',$gameid,$pos);
2043 $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
2045 if($userstatus=='start' || $userstatus=='init')
2046 echo ' <div class="vorbehalt'.($pos-1).'">'._('still needs <br />to decide')."</div>\n"; /* show this to everyone */
2048 if($usersick!=NULL) /* in the init-phase we only showed players with $pos<$mypos, now we can show all */
2049 echo ' <div class="vorbehalt'.($pos-1).'">'._('sick')."</div>\n";
2051 echo ' <div class="vorbehalt'.($pos-1).'">'._('healthy')."</div>\n";
2054 /* display all comments on the top right (card1)*/
2055 $comments = DB_get_pre_comment($gameid);
2057 echo ' <div class="card1">'."\n";
2058 /* display comments */
2059 foreach( $comments as $comment )
2060 echo ' <span class="comment">'.$comment[1].': '.$comment[0]."</span>\n";
2061 echo " </div>\n"; /* end div card */
2064 echo " </div>\n </div>\n"; /* end div trick, end li trick , end tricks*/
2065 /* end displaying sickness */
2069 /* output pre-game trick in case user reloads,
2070 * only needs to be done when a team has been formed */
2071 if($myparty=='re' || $myparty=='contra')
2073 echo "\n<div class=\"tricks\">\n";
2075 $mygametype = DB_get_gametype_by_gameid($gameid);
2077 echo " <div class=\"trick\" id=\"trick0\">\n";
2079 /* get information so show the cards that have been handed over in a poverty game */
2080 output_exchanged_cards();
2082 echo " </div>\n </div>\n\n"; /* end div trick, end li trick , end ul tricks */
2084 /* end output pre-game trick */
2089 /* already taken care of */
2094 display_table_end();
2100 $mycards = DB_get_hand($me);
2101 $mycards = mysort($mycards,$gametype);
2104 echo '<div class="mycards">';
2105 switch ($card_status) {
2107 echo _('Your cards are').": <br />\n";
2108 foreach($mycards as $card)
2109 display_card($card,$PREF['cardset']);
2111 case CARDS_EXCHANGE:
2112 echo '<div class="poverty"> '._('You need to get rid of a few cards')."</div>\n";
2114 echo _('Your cards are').": <br />\n";
2116 foreach($mycards as $card)
2117 display_link_card($card,$PREF['cardset'],$type);
2118 echo ' <input type="submit" class="submitbutton" value="select card to give back" />'."\n";
2121 echo 'Hello '.$myname.", it's your turn! <br />\n";
2122 echo _('Your cards are').": <br />\n";
2124 /* do we have to follow suite? */
2126 if(have_suit($mycards,$firstcard))
2129 /* count how many cards we can play, so that we can pre-select it if there is only one */
2131 foreach($mycards as $card)
2136 /* display only cards that the player is allowed to play as links, the rest just display normal
2137 * also check if we have both schweinchen, in that case only display on of them as playable
2139 if( ($followsuit && !same_type($card,$firstcard)) ||
2140 ( (int)($card)==19 &&
2141 !$GAME['schweinchen-first'] &&
2142 ( $RULES['schweinchen']=='second' ||
2143 ( $RULES['schweinchen']=='secondaftercall' &&
2144 (DB_get_call_by_hash($GAME['schweinchen-who']) ||
2145 DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
2148 $GAME['schweinchen-who']==$me &&
2149 in_array($gametype,array('normal','wedding','trump','silent'))
2157 /* make it boolean, so that we can pass it later to display_link_card */
2158 if($howmanycards!=1)
2161 foreach($mycards as $card)
2163 /* display only cards that the player is allowed to play as links, the rest just display normal
2164 * also check if we have both schweinchen, in that case only display on of them as playable
2166 if( ($followsuit && !same_type($card,$firstcard)) ||
2167 ( (int)($card)==19 &&
2168 !$GAME['schweinchen-first'] &&
2169 ( $RULES['schweinchen']=='second' ||
2170 ( $RULES['schweinchen']=='secondaftercall' &&
2171 (DB_get_call_by_hash($GAME['schweinchen-who']) ||
2172 DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
2175 $GAME['schweinchen-who']==$me &&
2176 in_array($gametype,array('normal','wedding','trump','silent'))
2179 display_card($card,$PREF['cardset']);
2181 display_link_card($card,$PREF['cardset'],$type='card',$selected=$howmanycards);
2184 case CARDS_GAMEOVER_ME:
2185 case CARDS_GAMEOVER:
2186 if($card_status == CARDS_GAMEOVER_ME)
2187 echo _('Your cards were').": <br />\n";
2190 $name = DB_get_name('userid',$myid);
2191 echo "$name's were: <br />\n";
2193 $oldcards = DB_get_all_hand($me);
2194 $oldcards = mysort($oldcards,$gametype);
2196 foreach($oldcards as $card)
2197 display_card($card,$PREF['cardset']);
2199 /* display hands of everyone else */
2200 $userids = DB_get_all_userid_by_gameid($gameid);
2201 foreach($userids as $user)
2203 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
2209 $name = DB_get_name('userid',$user);
2210 $oldcards = DB_get_all_hand($userhash);
2211 $oldcards = mysort($oldcards,$gametype);
2212 echo "$name's cards were: <br />\n";
2213 foreach($oldcards as $card)
2214 display_card($card,$PREF['cardset']);
2228 if( sizeof($messages) )
2230 echo "\n<div class=\"message\">\n";
2231 foreach($messages as $message)
2233 echo " <div>$message <div>close</div> </div>\n";
2238 /****************************
2239 * commit commentCall to DB *
2240 ****************************/
2242 if($commentCall != '')
2244 /* treat before game calls special, so that we can show them on the first trick and not the pre-phase */
2248 DB_insert_comment($commentCall,$playid,$gameid,$myid);
2250 /***********************************************
2251 * Comments, re/contra calls, user menu
2252 ***********************************************/
2255 * display gameinfo: re/contra, comment-box, play-card button, games played by others
2258 echo "<div class=\"gameinfo\">\n";
2260 /* get time from the last action of the game */
2261 $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
2262 $gameend = time() - strtotime($r[0]);
2265 if($gamestatus == 'play' || $gamestatus == 'pre' || $gameend < 60*60*24*7)
2267 echo ' '._('A short comment').":<input name=\"comment\" type=\"text\" size=\"20\" maxlength=\"100\" />\n";
2271 if($gamestatus == 'play' )
2273 $myparty = DB_get_party_by_hash($me);
2274 output_form_calls($me,$myparty);
2277 /* play-card button */
2278 if($gamestatus == 'play' || $gamestatus == 'pre' || $gameend < 60*60*24*7)
2280 echo ' <input type="submit" value="'._('submit')."\" />\n";
2283 /* has this hand been played by others? */
2284 $other_game_ids = DB_played_by_others($gameid);
2285 if(sizeof($other_game_ids)>0 && $mystatus=='gameover')
2287 $mypos = DB_get_pos_by_hash($me);
2288 echo " <p>See how other played the same hand: \n";
2289 foreach($other_game_ids as $id)
2291 $otherhash = DB_get_hash_from_game_and_pos($id,$mypos);
2292 $othername = DB_get_name('hash',$otherhash);
2293 echo " <a href=\"$INDEX?action=game&me=$otherhash\">$othername</a> ";
2298 echo "</div>\n\n"; /* end gameinfo */
2300 /* make sure that we don't show the notes to the wrong person
2301 * (e.g. other people looking at an old game)
2303 if( $mystatus != 'gameover' ||
2304 ( $mystatus == 'gameover' &&
2305 isset($_SESSION['id']) &&
2306 $myid == $_SESSION['id']))
2307 output_user_notes($myid,$gameid,$mystatus);
2311 /*********************************
2313 *********************************/
2315 $gamestatus = DB_get_game_status_by_gameid($gameid);
2316 if($mystatus=='gameover' &&
2317 ($gamestatus =='gameover' || $gamestatus =='cancel-nines' || $gamestatus =='cancel-trump') &&
2318 isset($_SESSION['id']) && $_SESSION['id']==$myid)
2320 $session = DB_get_session_by_gameid($gameid);
2321 $result = DB_query('SELECT id,create_date FROM Game'.
2322 " WHERE session=$session".
2323 ' ORDER BY create_date DESC'.
2327 $r = DB_fetch_array($result);
2329 if(!$session || $gameid==$r[0])
2331 /* suggest a new game with the same people in it, just rotated once (unless last game was solo) */
2332 $names = DB_get_all_names_by_gameid($gameid);
2333 $type = DB_get_gametype_by_gameid($gameid);
2337 $solo = DB_get_solo_by_gameid($gameid);
2339 if($solo!='silent') /* repeat game with same first player */
2340 output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid);
2341 else /* rotate normally */
2342 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
2344 else if($gamestatus == 'cancel-nines' || $gamestatus == 'cancel-trump')
2345 output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid);
2346 else /* rotate normally */
2347 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);