2 /* Copyright 2006, 2007, 2008, 2009, 2010 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 /* get some information from the DB */
47 $gameid = DB_get_gameid_by_hash($me);
48 $myname = DB_get_name('hash',$me);
49 $mystatus = DB_get_status_by_hash($me);
50 $origmystatus = DB_get_status_by_hash($me); /* to show "it's your turn" menu when game has just finished */
51 $mypos = DB_get_pos_by_hash($me);
52 $myhand = DB_get_handid('hash',$me);
53 $myparty = DB_get_party_by_hash($me);
54 $session = DB_get_session_by_gameid($gameid);
56 /* get prefs and save them in a variable*/
57 $PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid);
59 /* get rule set for this game */
60 $RULES = DB_get_RULES($gameid);
62 /* get some infos about the game */
63 $gametype = DB_get_gametype_by_gameid($gameid);
64 $gamestatus = DB_get_game_status_by_gameid($gameid);
68 $gametype = DB_get_solo_by_gameid($gameid);
69 $GT = $gametype.' '.$GT;
72 /* do we need to worry about Schweinchen?
73 * check gametype and rules
74 * if yes, figure out if someone actually has Schweinchen
75 * save information in $GAME
78 if( $gamestatus == 'pre' )
80 /* always need to use Schweinchen to figure out for example who has poverty */
82 /* unless the gametype is set and we know that we are in poverty were schweinchen is not valid */
83 if( in_array( $gametype,array('poverty','dpoverty') ))
88 /* in a game Schweinchen is not valid in all types of games */
89 if( in_array($gametype,array('normal','wedding','trump','silent') ))
90 if( in_array($RULES['schweinchen'],array('both','second','secondaftercall')) )
94 /* these are the defaults */
95 $GAME['schweinchen-who'] = NULL;
96 $GAME['schweinchen-first'] = NULL;
97 $GAME['schweinchen-second'] = NULL;
101 /* need to check for Schweinchen */
104 $hash = DB_get_hash_from_game_and_pos($gameid,$i);
105 $cards = DB_get_all_hand($hash);
106 if( in_array('19',$cards) && in_array('20',$cards) )
107 $GAME['schweinchen-who']=$hash;
109 $GAME['schweinchen-first'] = 0; /* to keep track if they have been played already */
110 $GAME['schweinchen-second'] = 0;
112 /* end check for Schweinchen */
114 /* set the $CARDS variable, needed for sorting the cards
115 * we set it to normal so that the pre-game phase is handled ok
116 * and later set it to the correct game type that is played
118 set_gametype('normal');
120 /* put everyting in a form */
121 echo "<form action=\"index.php?action=game&me=$me\" method=\"post\">\n";
123 /* handle user notes (only possible while game is running)*/
124 if( $mystatus!='gameover' )
127 $note = $_REQUEST['note'];
130 DB_insert_note($note,$gameid,$myid);
133 /* make sure that we don't show the notes to the wrong person
134 * (e.g. other people looking at an old game)
136 if( $mystatus != 'gameover' ||
137 ( $mystatus == 'gameover' &&
138 isset($_SESSION['id']) &&
139 $myid == $_SESSION['id']))
140 output_user_notes($myid,$gameid,$mystatus);
142 /* handle calls, output a comment to show when the call was made */
143 /* initialize comments */
146 /* check for calls, set comment */
147 if(myisset('call') && $_REQUEST['call'] == '120' && can_call(120,$me))
149 $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
152 else if($myparty=='contra')
153 $comment .= "Contra";
155 if(myisset('call') && $_REQUEST['call'] == '90' && can_call(90,$me))
157 $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
160 if(myisset('call') && $_REQUEST['call'] == '60' && can_call(60,$me))
162 $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
165 if(myisset('call') && $_REQUEST['call'] == '30' && can_call(30,$me))
167 $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
170 if(myisset('call') && $_REQUEST['call'] == '0' && can_call(0,$me))
172 $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
176 /* get information needed to submit comment */
177 $playid = DB_get_current_playid($gameid);
181 DB_insert_comment($comment,$playid,$myid);
184 /* end check for calls */
187 /* output extra division in case this game is part of a session */
190 echo "<div class=\"session\">\n";
191 echo ' <div class="sessionrules">'._('Rules').': ';
192 switch($RULES['dullen'])
195 echo " <img class=\"rulesicon\" alt=\""._('no ten of hearts')."\" src=\"pics/button/no-ten-of-hearts.png\"/>\n"; break;
197 echo " <img class=\"rulesicon\" alt=\""._('ten of hearts')."\" src=\"pics/button/ten-of-hearts.png\"/>\n"; break;
199 echo " <img class=\"rulesicon\" alt=\""._('second ten of hearts')."\" src=\"pics/button/second-ten-of-hearts.png\"/>\n"; break;
201 switch($RULES['schweinchen'])
204 echo " <img class=\"rulesicon\" alt=\""._('no schweinchen')."\" ".
205 "src=\"pics/button/no-schweinchen.png\"/>\n"; break;
207 echo " <img class=\"rulesicon\" alt=\""._('two schweinchen')."\" ".
208 "src=\"pics/button/two-schweinchen.png\"/>\n"; break;
210 echo " <img class=\"rulesicon\" alt=\"".('second schweinchen')."\" ".
211 "src=\"pics/button/second-schweinchen.png\"/>\n"; break;
212 case 'secondaftercall':
213 echo " <img class=\"rulesicon\" alt=\""._('second schweinchen after call')."\" ".
214 "src=\"pics/button/second-schweinchen-after-call.png\"/>\n"; break;
216 switch($RULES['call'])
219 echo " <img class=\"rulesicon\" alt=\""._('1st-own-card')."\" src=\"pics/button/1st-own-card.png\"/>\n"; break;
221 echo " <img class=\"rulesicon\" alt=\""._('5th-card')."\" src=\"pics/button/5th-card.png\"/>\n"; break;
223 echo " <img class=\"rulesicon\" alt=\""._('9-cards')."\" src=\"pics/button/9-cards.png\"/>\n"; break;
226 echo ' '._('10ofhearts').": {$RULES['dullen']} <br />\n";
227 echo ' '._('schweinchen').": {$RULES['schweinchen']} <br />\n";
228 echo ' '._('call').": {$RULES['call']} <br />\n";
229 echo ' '._('lowtrump').": {$RULES['lowtrump']} <br />\n";
230 echo " </div>\n </div>\n";
234 echo " <div class=\"sessionscore\">";
236 $score = generate_score_table($session);
238 /* get the last entry to show on the main page */
240 $finalscore = array_pop($tmpscore);
241 $finalscore = $finalscore['players'];
245 echo _('Score').": \n";
246 foreach($finalscore as $user=>$value)
248 $name = DB_get_name('userid',$user);
249 echo " ".substr($name,0,2).": $value ";
254 /* first game, no score yet */
258 /* output all games for the score table */
259 echo format_score_table_html($score,$myid);
262 /* figure out which game in a session we are in and link to the
263 * previous and next game if possible
265 $hashes = DB_get_hashes_by_session($session,$myid);
268 foreach($hashes as $hash)
278 $previous = $hashes[$j-2];
286 if(isset($_SESSION['id']) && $_SESSION['id']==$myid)
289 echo "<a href=\"{$INDEX}?action=game&me=$previous\">"._('previous game')."</a> \n";
290 echo "This is game number $j of <a href=\"{$INDEX}?action=game&me=$lasthash\">$i</a> in session $session.\n";
292 echo " <a href=\"{$INDEX}?action=game&me=$next\">"._('next game')."</a> \n";
295 echo "This is game number $j of $i in session $session.";
299 /* display the table and the names */
302 /* mystatus gets the player through the different stages of a game.
303 * start: does the player want to play?
304 * init: check for sickness
305 * check: check for return values from init
306 * poverty: handle poverty, wait here until all player have reached this state
307 * display sickness and move on to game
308 * play: game in progress
309 * gameover: are we revisiting a game
312 /* the user has done something, update the timestamp. Use $myid in
313 * active games and check for session-id in old games (myid might be wrong in that case)
315 if($mystatus!='gameover')
316 DB_update_user_timestamp($myid);
318 if(isset($_SESSION['id']))
319 DB_update_user_timestamp($_SESSION['id']);
324 /* don't ask if user has autosetup set to yest */
326 if($PREF['autosetup']=='yes') $skip = 1;
328 if( !myisset('in') && !$skip)
330 /* asks the player, if he wants to join the game */
331 output_check_want_to_play($me);
332 echo '<div class="mycards"></div>';
337 /* check the result, if player wants to join, got next stage, else cancel game */
338 if(!$skip && $_REQUEST['in'] == 'no' )
340 /* cancel the game */
341 $message = "Hello, \n\n".
342 "the game has been canceled due to the request of one of the players.\n\n";
344 $userids = DB_get_all_userid_by_gameid($gameid);
345 foreach($userids as $user)
347 $subject = 'Game '.DB_format_gameid($gameid).' canceled';
348 mymail($user,$subject,$message);
351 /* update game status */
352 cancel_game('noplay',$gameid);
357 /* user wants to join the game */
359 /* move on to the next stage,
360 * no break statement to immediately go to the next stage
363 DB_set_hand_status_by_hash($me,'init');
365 /* check if everyone has reached this stage, send out email */
366 $userids = DB_get_all_userid_by_gameid($gameid);
368 foreach($userids as $user)
370 $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
371 if($userstat!='init')
373 /* whos turn is it? */
374 DB_set_player_by_gameid($gameid,$user);
381 /* all done, send out email unless this player is the startplayer */
382 $startplayer = DB_get_startplayer_by_gameid($gameid);
383 if($mypos == $startplayer)
385 /* do nothing, go to next stage */
389 /* email startplayer */
391 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
392 $who = DB_get_userid('hash',$hash);
393 DB_set_player_by_gameid($gameid,$who);
395 $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
396 "Use this link to go the game: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
397 mymail($who,"Ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
404 /* here we ask the player if he is sick */
405 $mycards = DB_get_hand($me);
406 $mycards = mysort($mycards,$gametype);
408 if(!myisset('solo','wedding','poverty','nines','lowtrump') )
410 /* output sickness of other playes, in case the already selected and are sitting in front of the current player */
411 echo "\n<ul class=\"tricks\">\n";
412 echo " <li class=\"nohighlight\"> Game ".DB_format_gameid($gameid).": </li>\n";
413 echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
414 " <div class=\"trick\" id=\"trick0\">\n";
416 for($pos=1;$pos<5;$pos++)
418 $usersick = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
419 $userid = DB_get_userid('gameid-position',$gameid,$pos);
420 $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
422 if($userstatus=='start' || $userstatus=='init')
423 echo " <div class=\"vorbehalt".($pos-1)."\"> still needs <br/ > to decide </div>\n"; /* show this to everyone */
425 if($usersick!=NULL && $pos<=$mypos ) /* only show this for people sitting before the player */
426 echo " <div class=\"vorbehalt".($pos-1)."\"> sick </div>\n";
427 else if($usersick==NULL && $pos<=$mypos)
428 echo " <div class=\"vorbehalt".($pos-1)."\"> healthy </div>\n";
430 echo " </div>\n </li>\n</ul>\n"; /* end div trick, end li trick , end tricks*/
431 /* end displaying sickness */
433 output_check_for_sickness($me,$mycards);
435 echo '<div class="mycards">'._('Your cards are').": <br />\n";
436 foreach($mycards as $card)
437 display_card($card,$PREF['cardset']);
444 /* check if someone selected more than one sickness */
446 if($_REQUEST['solo']!='No') $Nsickness++;
447 if($_REQUEST['wedding'] == 'yes') $Nsickness++;
448 if($_REQUEST['poverty'] == 'yes') $Nsickness++;
449 if($_REQUEST['nines'] == 'yes') $Nsickness++;
450 if($_REQUEST['lowtrump'] == 'yes') $Nsickness++;
454 echo "<p class=\"message\"> You selected more than one sickness, please go back ".
455 "and answer the <a href=\"$INDEX?action=game&me=$me&in=yes\">question</a> again.</p>";
457 echo '<div class="mycards">'._('Your cards are').": <br />\n";
458 foreach($mycards as $card)
459 display_card($card,$PREF['cardset']);
466 /* everything is ok, save what user said and proceed */
467 echo "<p class=\"message\">Processing what you selected in the last step...";
469 /* check if this sickness needs to be handled first */
470 $gametype = DB_get_gametype_by_gameid($gameid);
471 $startplayer = DB_get_startplayer_by_gameid($gameid); /* need this to check which solo goes first */
473 if( $_REQUEST['solo']!='No' )
475 /* user wants to play a solo */
477 /* store the info in the user's hand info */
478 DB_set_solo_by_hash($me,$_REQUEST['solo']);
479 DB_set_sickness_by_hash($me,'solo');
481 echo "<br />Seems like you want to play a {$_REQUEST['solo']} solo. Got it.<br />\n";
483 if($gametype == 'solo' && $startplayer<$mypos)
484 {}/* do nothing, since someone else already is playing solo */
487 /* this solo comes first
488 * store info in game table
490 DB_set_gametype_by_gameid($gameid,'solo');
491 DB_set_startplayer_by_gameid($gameid,$mypos);
492 DB_set_solo_by_gameid($gameid,$_REQUEST['solo']);
495 else if($_REQUEST['wedding'] == 'yes')
497 /* silent solo is set further down */
498 echo _("Ok, you don't want to play a silent solo...wedding was chosen.")."<br />\n";
499 DB_set_sickness_by_hash($me,'wedding');
501 else if($_REQUEST['poverty'] == 'yes')
503 echo _("Don't think you can win with just a few trump...? Ok, poverty chosen.")." <br />\n";
504 DB_set_sickness_by_hash($me,'poverty');
506 else if($_REQUEST['nines'] == 'yes')
508 echo _("What? You just don't want to play a game because you have a few nines? Well, if no one".
509 " is playing solo, this game will be canceled.")."<br />\n";
510 DB_set_sickness_by_hash($me,'nines');
512 else if($_REQUEST['lowtrump'] == 'yes')
514 if($RULES['lowtrump']=='cancel')
515 echo _("What? You just don't want to play a game because you have low trump? Well, if no one".
516 " is playing solo, this game will be canceled.")."<br />\n";
518 echo _("Don't think you can win with low trumps...? Ok, poverty chosen.")." <br />.<br />\n";
520 DB_set_sickness_by_hash($me,'lowtrump');
525 /* move on to the next stage*/
526 DB_set_hand_status_by_hash($me,'check');
532 /* here we check what all players said and figure out what game we are playing
533 * this can therefore only be handled once all players finished the last stage
536 $mycards = DB_get_hand($me);
537 $mycards = mysort($mycards,$gametype);
539 /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
540 echo "\n<ul class=\"tricks\">\n";
541 echo " <li class=\"nohighlight\"> Game ".DB_format_gameid($gameid).": </li>\n";
542 echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
543 " <div class=\"trick\" id=\"trick0\">\n";
545 for($pos=1;$pos<5;$pos++)
547 $usersick = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
548 $userid = DB_get_userid('gameid-position',$gameid,$pos);
549 $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
551 if($userstatus=='start' || $userstatus=='init')
552 echo " <div class=\"vorbehalt".($pos-1)."\"> still needs <br />to decide </div>\n"; /* show this to everyone */
554 if($usersick!=NULL) /* in the init-phase we only showed players with $pos<$mypos, now we can show all */
555 echo " <div class=\"vorbehalt".($pos-1)."\"> sick </div>\n";
557 echo " <div class=\"vorbehalt".($pos-1)."\"> healthy </div>\n";
559 echo " </div>\n </li>\n</ul>\n"; /* end div trick, end li trick , end tricks*/
560 /* end displaying sickness */
562 echo "<div class=\"message\">\n";
563 echo '<p> '._('Checking if someone else selected solo, nines, wedding or poverty.').'</p>';
565 /* check if everyone has reached this stage */
566 $userids = DB_get_all_userid_by_gameid($gameid);
568 foreach($userids as $user)
570 $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
571 if($userstat!='check')
574 DB_set_player_by_gameid($gameid,$user);
581 echo '<p>'._('This step can only be handled after everyone finished the last step. '.
582 'Seems like this is not the case, so you need to wait a bit... '.
583 'you will get an email once that is the case, please use the link in '.
584 'that email to continue the game.').'</p></div>';
586 /* display cards, if player was just at the init-phase he will still see the cards from there
587 * we can put this one here, since the last player to finish the init state won't get here and
588 * will still see his card anyway from the init-phase
590 if($mystatus=='check')
593 echo '<div class="mycards">'._('Your cards are').": <br />\n";
594 foreach($mycards as $card)
595 display_card($card,$PREF['cardset']);
602 /* Ok, everyone finished the init-phase, time to figure out what game we
603 * are playing, in case there are any solos this already
604 * will have the correct information in it */
606 echo '<p>'._('Ok, everyone is done... figuring out what kind of game we are playing.').'</p>';
608 $gametype = DB_get_gametype_by_gameid($gameid);
609 $startplayer = DB_get_startplayer_by_gameid($gameid);
611 /* check for sickness */
616 foreach($userids as $user)
618 $name = DB_get_name('userid',$user);
619 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
620 if($usersick == 'nines' || ($RULES['lowtrump']=='cancel' && $usersick=='lowtrump') )
623 $cancelsick = $usersick;
624 break; /* no need to check for other poverties, since only solo can win and that is already set */
626 else if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
628 else if($usersick == 'wedding')
630 else if($usersick == 'solo')
634 /* now check which sickness comes first and set the gametype to it */
635 if($gametype == 'solo')
642 if($cancelsick == 'nines')
644 $message = "The game has been canceled because ".DB_get_name('userid',$cancel).
645 " has five or more nines and nobody is playing solo.\n\n".
646 "To redeal either start a new game or, in case the game was part of a tournament,\n".
647 "go to the last game and use the link at the bottom of the page to redeal.\n\n";
649 /* update game status */
650 cancel_game('nines',$gameid);
652 echo "<p>The game has been canceled because ".DB_get_name('userid',$cancel).
653 " has five or more nines and nobody is playing solo.</p>\n";
655 else if ($cancelsick == 'lowtrump')
657 $message = "The game has been canceled because ".DB_get_name('userid',$cancel).
658 " has low trump and nobody is playing solo.\n\n".
659 "To redeal either start a new game or, in case the game was part of a tournament,\n".
660 "go to the last game and use the link at the bottom of the page to redeal.\n\n";
662 /* update game status */
663 cancel_game('lowtrump',$gameid);
665 echo "<p>The game has been canceled because ".DB_get_name('userid',$cancel).
666 " has low trump and nobody is playing solo.</p>\n";
669 $userids = DB_get_all_userid_by_gameid($gameid);
670 foreach($userids as $user)
672 $subject = 'Game '.DB_format_gameid($gameid).' canceled';
673 mymail($user,$subject,$message);
676 echo "</div>\n"; /* end div message */
679 else if($poverty==1) /* one person has poverty */
681 DB_set_gametype_by_gameid($gameid,'poverty');
682 $gametype = 'poverty';
683 $who = DB_get_sickness_by_gameid($gameid);
686 $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
687 if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
688 DB_set_sickness_by_gameid($gameid,2); /* who needs to be asked first */
690 DB_set_sickness_by_gameid($gameid,1); /* who needs to be asked first */
693 else if($poverty==2) /* two people have poverty */
695 DB_set_gametype_by_gameid($gameid,'dpoverty');
696 $gametype = 'dpoverty';
697 $who = DB_get_sickness_by_gameid($gameid);
700 $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
701 if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
703 $secondsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
704 if($secondsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
705 DB_set_sickness_by_gameid($gameid,30); /* who needs to be asked first */
707 DB_set_sickness_by_gameid($gameid,20); /* who needs to be asked first */
710 DB_set_sickness_by_gameid($gameid,10); /* who needs to be asked first */
715 DB_set_gametype_by_gameid($gameid,'wedding');
716 DB_set_sickness_by_gameid($gameid,'-1'); /* wedding not resolved yet */
717 $gametype = 'wedding';
719 /* now the gametype is set correctly in the database */
720 echo '<p>'._('Got it').' :)</p>';
722 /* loop over all players, set re/contra if possible and start the game if possible */
723 $userids = DB_get_all_userid_by_gameid($gameid);
724 foreach($userids as $userid)
726 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$userid);
731 /* are we the solo player? set us to re, else set us to contra */
732 $pos = DB_get_pos_by_hash($userhash);
733 if($pos == $startplayer)
734 DB_set_party_by_hash($userhash,'re');
736 DB_set_party_by_hash($userhash,'contra');
737 DB_set_hand_status_by_hash($userhash,'play');
741 /* set person with the wedding to re, do the rest during the game */
742 $usersick = DB_get_sickness_by_userid_and_gameid($userid,$gameid);
743 if($usersick == 'wedding')
744 DB_set_party_by_hash($userhash,'re');
746 DB_set_party_by_hash($userhash,'contra');
748 DB_set_hand_status_by_hash($userhash,'play');
752 $hand = DB_get_all_hand($userhash);
754 if(in_array('3',$hand)||in_array('4',$hand))
755 DB_set_party_by_hash($userhash,'re');
757 DB_set_party_by_hash($userhash,'contra');
758 DB_set_hand_status_by_hash($userhash,'play');
762 /* set person with poverty to play status */
763 $usersick = DB_get_sickness_by_userid_and_gameid($userid,$gameid);
764 if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
765 DB_set_hand_status_by_hash($userhash,'play');
767 /* set status of first player to be asked to poverty */
768 $who = DB_get_sickness_by_gameid($gameid);
769 if($who > 6) $who= $who/10; /* in case we have dpoverty */
770 $whoid = DB_get_userid('gameid-position',$gameid,$who);
772 DB_set_hand_status_by_hash($userhash,'poverty');
775 /* check for silent solo, set game type to solo in this case */
776 $gametype = DB_get_gametype_by_gameid($gameid);
777 $userids = DB_get_all_userid_by_gameid($gameid);
778 foreach($userids as $userid)
780 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$userid);
782 if($gametype=='normal')
784 $userhand = DB_get_all_hand($userhash);
785 if(check_wedding($userhand))
787 /* normal game type and player has both queens -> silent solo */
788 /* keep startplayer, just set gametype to silent solo */
789 DB_set_gametype_by_gameid($gameid,'solo');
790 DB_set_solo_by_gameid($gameid,'silent');
795 /* send out email to first player or poverty person*/
796 if($gametype!='poverty' && $gametype!='dpoverty')
798 $startplayer = DB_get_startplayer_by_gameid($gameid);
799 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
800 $who = DB_get_userid('hash',$hash);
801 DB_set_player_by_gameid($gameid,$who);
805 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
807 /* email startplayer */
808 $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
809 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
810 $subject = 'Ready, set, go... (game '.DB_format_gameid($gameid).')';
811 mymail($who,$subject,$message);
815 echo "Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br />\n";
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 */
823 $whoid = DB_get_userid('gameid-position',$gameid,$who);
825 echo "Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br /\n";
828 $whohash = DB_get_hash_from_game_and_pos($gameid,$who);
829 DB_set_player_by_gameid($gameid,$whoid);
831 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
833 /* email player for poverty */
834 $message = "Poverty: It's your turn now in game ".DB_format_gameid($gameid).".\n".
835 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$whohash."\n\n" ;
836 $subject = 'Poverty (game '.DB_format_gameid($gameid).') ';
837 mymail($whoid,$subject,$message);
843 echo '<div class="mycards">'._('Your cards are').": <br />\n";
844 foreach($mycards as $card)
845 display_card($card,$PREF['cardset']);
852 /* user only gets here in a poverty game, several things have to be handled here:
853 * A) ask, if user wants to take trump
855 * poverty: set re/contra
856 * dpoverty: first time: set re, send email to second player
857 * second time: set contra
858 * poverty: set status of other players to 'play'
859 * set status to play in case 0 trump
860 * no -> set status to play,
861 * ask next player or cancle the game if no more players
862 * B) user took trump and has too many cards (e.g. count(cards)>12 and re/contra set)
863 * ask to give cards back, set status to play, once player has 12 cards
865 * it is easier to check B) first
868 set_gametype($gametype); /* this sets the $CARDS variable */
869 $myparty = DB_get_party_by_hash($me);
871 /* the following is part B) of whats needs to be done)
872 /* check if user wants to give cards back */
873 if(myisset('exchange'))
875 $exchange = $_REQUEST['exchange'];
876 $partnerhash = DB_get_partner_hash_by_hash($me);
877 $partnerid = DB_get_userid('hash',$partnerhash);
878 $partnerhand = DB_get_handid('gameid-userid',$gameid,$partnerid);
880 /* if exchange is set to a value>0, exchange that card back to the partner */
883 $result = DB_query("UPDATE Hand_Card SET hand_id='$partnerhand'".
884 " WHERE hand_id='$myhand' AND card_id=".DB_quote_smart($exchange));
885 DB_add_exchanged_card(DB_quote_smart($exchange),$myhand,$partnerhand);
890 $mycards = DB_get_hand($me);
891 $mycards = mysort($mycards,$gametype);
893 /* output pre-game trick in case user reloads,
894 * only needs to be done when a team has been formed */
895 if($myparty=='re' || $myparty=='contra')
897 echo "\n<ul class=\"tricks\">\n";
898 echo " <li class=\"nohighlight\"> Game ".DB_format_gameid($gameid).": </li>\n";
900 $mygametype = DB_get_gametype_by_gameid($gameid);
902 echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
903 " <div class=\"trick\" id=\"trick0\">\n";
905 /* get information so show the cards that have been handed over in a poverty game */
906 output_exchanged_cards();
908 echo " </div>\n </li>\n</ul>\n\n"; /* end div trick, end li trick , end ul tricks */
910 /* end output pre-game trick */
912 /* check if user need to give more cards back */
913 if( ($myparty=='re' || $myparty=='contra') && count($mycards)>12)
915 echo '<div class="poverty"> '._('You need to get rid of a few cards')."</div>\n";
918 echo '<div class="mycards">'._('Your cards are').": <br />\n";
919 foreach($mycards as $card)
920 display_link_card($card,$PREF['cardset'],$type);
921 echo " <input type=\"submit\" class=\"submitbutton\" value=\"select card to give back\" />\n";
924 else if( ($myparty=='re' || $myparty=='contra') && count($mycards)==12)
926 /* user is done, ready to play */
927 DB_set_hand_status_by_hash($me,'play');
929 /* email start player */
930 $startplayer = DB_get_startplayer_by_gameid($gameid);
931 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
932 $who = DB_get_userid('hash',$hash);
933 DB_set_player_by_gameid($gameid,$who);
937 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
939 /* email startplayer */
940 $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
941 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
942 $subject = 'Ready, set, go... (game '.DB_format_gameid($gameid).') ';
943 mymail($who,$subject,$message);
947 echo "<div class=\"message\">Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.</div>\n";
950 /* the following is part A) of what needs to be done */
951 if(!myisset('trump'))
955 echo "<div class=\"poverty\">\n";
956 $userids = DB_get_all_userid_by_gameid($gameid);
957 foreach($userids as $user)
959 $name = DB_get_name('userid',$user);
960 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
961 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
962 $userparty = DB_get_party_by_hash($userhash);
964 if(($usersick=='poverty'|| ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump')) && !$userparty)
966 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
967 $cards = DB_get_hand($hash);
970 foreach($cards as $card)
971 if($card<27) $nrtrump++;
973 if($usersick=='lowtrump')
975 echo "Player $name has $nrtrump $low trump. Do you want to take them?".
976 "<a href=\"index.php?action=game&me=$me&trump=$user\">Yes</a> <br />\n";
979 echo "<a href=\"index.php?action=game&me=$me&trump=no\">No way</a> <br />\n";
980 echo "</div><div>\n";
982 echo '<div class="mycards">'._('Your cards are').": <br />\n";
983 foreach($mycards as $card)
984 display_card($card,$PREF['cardset']);
985 echo "</div></div>\n";
991 $trump = $_REQUEST['trump'];
995 /* user doesn't want to take trump */
996 DB_set_hand_status_by_hash($me,'play');
998 /* set next player who needs to be asked and email him*/
999 $firstsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+1,$gameid);
1000 $secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
1002 /* don't ask people who have poverty */
1004 if($firstsick=='poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
1006 if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
1011 if($gametype=='dpoverty')
1013 $next=999; /* need to cancel for sure, since both would need to take the trump */
1016 /* no more people to ask, need to cancel the game */
1019 $message = "Hello, \n\n".
1020 "Game ".DB_format_gameid($gameid)." has been canceled since nobody wanted to take the trump.\n\n";
1022 $userids = DB_get_all_userid_by_gameid($gameid);
1023 foreach($userids as $user)
1025 $subject = 'Game '.DB_format_gameid($gameid).' canceled (poverty not resolved)';
1026 mymail($user,$subject,$message);
1029 /* update game status */
1030 cancel_game('trump',$gameid);
1032 echo "<p class=\"message\";>Game ".DB_format_gameid($gameid)." has been canceled.<br /><br /></p>";
1037 /* email next player, set his status to poverty */
1038 $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
1039 $userid = DB_get_userid('hash',$userhash);
1041 DB_set_player_by_gameid($gameid,$userid);
1042 DB_set_hand_status_by_hash($userhash,'poverty');
1044 $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
1045 " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
1046 $subject = 'Poverty (game '.DB_format_gameid($gameid).')';
1047 mymail($userid,$subject,$message);
1052 /* player wants to take trump, change cards */
1054 /* user wants to take trump */
1055 $trump = $_REQUEST['trump'];
1056 $userhand = DB_get_handid('gameid-userid',$gameid,$trump);
1057 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$trump);
1059 /* remember which cards were handed over*/
1060 $partnerhand = DB_get_all_hand($userhash);
1061 foreach ($partnerhand as $card)
1063 DB_add_exchanged_card($card,$userhand,$myhand);
1065 /* copy trump from player A to B */
1066 $result = DB_query("UPDATE Hand_Card SET hand_id='$myhand' WHERE hand_id='$userhand' AND card_id<'27'" );
1069 $mycards = DB_get_hand($me);
1072 if($gametype=='poverty')
1074 $userids = DB_get_all_userid_by_gameid($gameid);
1075 foreach($userids as $user)
1077 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1078 if($hash==$userhash||$hash==$me)
1080 DB_set_party_by_hash($hash,'re');
1084 DB_set_party_by_hash($hash,'contra');
1085 DB_set_hand_status_by_hash($hash,'play'); /* the contra party is ready to play */
1088 /* check if we are done (in case of no trump handed over), if so, go to 'play' phase right away*/
1089 if(count($mycards)==12)
1091 DB_set_hand_status_by_hash($me,'play');
1096 /* has the re party already been set?*/
1098 $userids = DB_get_all_userid_by_gameid($gameid);
1099 foreach($userids as $user)
1101 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1102 $party = DB_get_party_by_hash($hash);
1108 DB_set_party_by_hash($me,'contra');
1109 DB_set_party_by_hash($userhash,'contra');
1113 DB_set_party_by_hash($me,'re');
1114 DB_set_party_by_hash($userhash,'re');
1116 /* send out email to second non-poverty player */
1117 $firstsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+1,$gameid);
1118 $secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
1121 if($firstsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
1122 if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
1128 echo "<div class=\"message\">Error in poverty, please contact the Admin</div>\n";
1130 $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
1131 $userid = DB_get_userid('hash',$userhash);
1133 DB_set_player_by_gameid($gameid,$userid);
1134 DB_set_hand_status_by_hash($userhash,'poverty');
1136 $message = "Two people have poverty, it's your turn to decide, if you want to take the trump. Please visit:".
1137 " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
1138 $subject = 'Double poverty (game '.DB_format_gameid($gameid).')';
1139 mymail($userid,$subject,$message);
1142 echo "<div class=\"message\">Please, <a href=\"$INDEX?action=game&me=$me\">continue</a> here.</div>\n";
1150 /* both entries here, so that the tricks are visible for both.
1151 * in case of 'play' there is a break later that skips the last part
1154 /* first check if the game has been canceled and display */
1157 case 'cancel-noplay':
1158 echo "<div class=\"message\"><p>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.</p></div>";
1160 case 'cancel-timedout':
1161 echo "<div class=\"message\"><p>The game has been canceled because one player wasn't responding.</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.</p></div>";
1163 case 'cancel-nines':
1164 echo "<div class=\"message\"><p>The game has been canceled because one player had too many nines.</p></div>";
1166 case 'cancel-lowtrump':
1167 echo "<div class=\"message\"><p>The game has been canceled because one player had low trump.</p></div>";
1169 case 'cancel-trump':
1170 echo "<div class=\"message\"><p>The game has been canceled because nobody wanted to take the trump.</p></div>";
1173 /* for these two types, we shouldn't show the cards, since we might want to restart the game */
1174 if (in_array($gamestatus,array('cancel-noplay','cancel-timedout')))
1177 /* check if all players are ready to play,
1178 * if so, send out email to the startplayer
1179 * only need to do this if the game hasn't started yet
1181 $gamestatus = DB_get_game_status_by_gameid($gameid);
1182 if($gamestatus == 'pre')
1185 $userids = DB_get_all_userid_by_gameid($gameid);
1186 foreach($userids as $user)
1188 $userstatus = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
1189 if($userstatus !='play' && $userstatus!='gameover')
1192 DB_set_player_by_gameid($gameid,$user);
1198 /* only set this after all poverty, etc. are handled*/
1199 DB_set_game_status_by_gameid($gameid,'play');
1201 /* email startplayer */
1202 $startplayer = DB_get_startplayer_by_gameid($gameid);
1203 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
1204 $who = DB_get_userid('hash',$hash);
1205 DB_set_player_by_gameid($gameid,$who);
1207 if($hash!=$me && DB_get_email_pref_by_hash($hash)!='emailaddict')
1209 /* email startplayer) */
1210 $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
1211 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
1212 $subject = 'Ready, set, go... (game '.DB_format_gameid($gameid).')';
1213 mymail($who,$subject,$message);
1217 /* figure out what kind of game we are playing,
1218 * set the global variables $CARDS['trump'],$CARDS['diamonds'],$CARDS['hearts'],
1219 * $CARDS['clubs'],$CARDS['spades'],$CARDS['foxes']
1223 $gametype = DB_get_gametype_by_gameid($gameid);
1225 if($gametype=='solo')
1227 $gametype = DB_get_solo_by_gameid($gameid);
1228 if($gametype=='silent')
1231 $GT = $gametype.' '.$GT;
1234 $gametype = 'normal';
1236 set_gametype($gametype); /* this sets the $CARDS variable */
1238 /* get some infos about the game, need to reset this, since it might have changed */
1239 $gamestatus = DB_get_game_status_by_gameid($gameid);
1241 /* has the game started? No, then just wait here...*/
1242 if($gamestatus == 'pre')
1244 echo '<p class="message"> '._('You finished the setup, but not everyone else finished it... '.
1245 'You need to wait for the others. Just wait for an email.').' </p>';
1247 $mycards = DB_get_hand($me);
1248 $mycards = mysort($mycards,$gametype);
1250 echo '<div class="mycards">'._('Your cards are').": <br />\n";
1251 foreach($mycards as $card)
1252 display_card($card,$PREF['cardset']);
1255 break; /* not sure this works... the idea is that you can
1256 * only play a card after everyone is ready to play */
1260 /* get time from the last action of the game */
1261 $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
1262 $gameend = time() - strtotime($r[0]);
1264 /* handle comments in case player didn't play a card, allow comments a week after the end of the game */
1265 if( (!myisset('card') && $mystatus=='play') || ($mystatus=='gameover' && ($gameend < 60*60*24*7)) )
1266 if(myisset('comment'))
1268 $comment = $_REQUEST['comment'];
1269 $playid = DB_get_current_playid($gameid);
1272 DB_insert_comment($comment,$playid,$myid);
1275 /* get everything relevant to display the tricks */
1276 $result = DB_query("SELECT Hand_Card.card_id as card,".
1277 " Hand.position as position,".
1278 " Play.sequence as sequence, ".
1280 " GROUP_CONCAT(CONCAT('<span>',User.fullname,': ',Comment.comment,'</span>')".
1281 " SEPARATOR '\n' ), ".
1282 " Play.create_date, ".
1285 "LEFT JOIN Play ON Trick.id=Play.trick_id ".
1286 "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
1287 "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
1288 "LEFT JOIN Comment ON Play.id=Comment.play_id ".
1289 "LEFT JOIN User On User.id=Comment.user_id ".
1290 "WHERE Trick.game_id='".$gameid."' ".
1291 "GROUP BY Trick.id, sequence ".
1292 "ORDER BY Trick.id, sequence ASC");
1294 $lasttrick = DB_get_max_trickid($gameid);
1296 $play = array(); /* needed to calculate winner later */
1298 $pos = DB_get_startplayer_by_gameid($gameid)-1;
1299 $firstcard = ''; /* first card in a trick */
1301 echo "\n<ul class=\"tricks\">\n";
1302 echo ' <li class="nohighlight"> '._('Game').' '.DB_format_gameid($gameid).": </li>\n";
1304 /* output vorbehalte */
1305 $mygametype = DB_get_gametype_by_gameid($gameid);
1306 $mygamesolo = DB_get_solo_by_gameid($gameid);
1307 if($mygametype != 'normal') /* only show when needed */
1308 if(!( $mygametype == 'solo' && $mygamesolo == 'silent') )
1310 echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
1311 " <div class=\"trick\" id=\"trick0\">\n";
1313 /* get information so show the cards that have been handed over in a poverty game */
1314 output_exchanged_cards();
1316 echo " </div>\n </li>\n"; /* end div trick, end li trick */
1320 while($r = DB_fetch_array($result))
1328 /* count number of tricks */
1332 /* check if first schweinchen has been played */
1333 if( $GAME['schweinchen-who'] && ($r[0] == 19 || $r[0] == 20) )
1334 if(!$GAME['schweinchen-first'])
1335 $GAME['schweinchen-first'] = 1; /* playing the first fox */
1337 $GAME['schweinchen-second'] = 1; /* this must be the second fox */
1339 /* save card to be able to find the winner of the trick later */
1340 $play[$seq] = array('card'=>$r[0],'pos'=>$pos);
1344 /* first card in a trick, output some html */
1345 if($trick!=$lasttrick)
1347 /* start of an old trick? */
1348 echo " <li onclick=\"hl('$trickNR');\" class=\"old\"><a href=\"#\">"._('Trick')." $trickNR</a>\n".
1349 " <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 " <li onclick=\"hl('$trickNR');\" class=\"current\"><a href=\"#\">"._('Trick')." $trickNR</a>\n".
1356 " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
1357 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1360 /* remember first card, so that we are able to check, what cards can be played */
1365 echo " <div class=\"card".($pos-1)."\">\n";
1367 /* display comments */
1369 echo " <span class=\"comment\">".$comment."</span>\n";
1372 display_card($r[0],$PREF['cardset']);
1374 echo " </div>\n"; /* end div card */
1379 $winner = get_winner($play,$gametype); /* returns the position */
1380 echo " </div>\n </li>\n"; /* end div trick, end li trick */
1384 /* whos turn is it? */
1387 $winner = get_winner($play,$gametype); /* returns the position */
1389 $firstcard = ''; /* new trick, no first card */
1394 if($next==5) $next = 1;
1397 /* my turn?, display cards as links, ask for comments*/
1398 if(DB_get_pos_by_hash($me) == $next)
1403 /* do we want to play a card? */
1404 if(myisset('card') && $myturn)
1406 $card = $_REQUEST['card'];
1407 $handid = DB_get_handid('hash',$me);
1408 $commentSchweinchen =''; /* used to add a comment when Schweinchen is being played */
1410 /* check if we have card and that we haven't played it yet*/
1411 /* set played in hand_card to true where hand_id and card_id*/
1412 $r = DB_query_array("SELECT id FROM Hand_Card WHERE played='false' and ".
1413 "hand_id='$handid' AND card_id=".DB_quote_smart($card));
1414 $handcardid = $r[0];
1416 if($handcardid) /* everything ok, play card */
1418 /* update Game timestamp */
1419 DB_update_game_timestamp($gameid);
1421 /* mark card as played */
1422 DB_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
1423 DB_quote_smart($card));
1425 /* get trick id or start new trick */
1426 $a = DB_get_current_trickid($gameid);
1431 $playid = DB_play_card($trickid,$handcardid,$sequence);
1433 /* check special output for schweinchen in case in case a fox is being played
1434 * check for correct rules, etc. has already been done
1436 if( $GAME['schweinchen-who'] && ($card == 19 || $card == 20) )
1438 if(!$GAME['schweinchen-first'])
1439 $GAME['schweinchen-first'] = 1; /* playing the first fox */
1441 $GAME['schweinchen-second'] = 1; /* this must be the second fox */
1443 if( $RULES['schweinchen']=='both' ||
1444 ($RULES['schweinchen']=='second' && $GAME['schweinchen-second']==1 )||
1445 ($RULES['schweinchen']=='secondaftercall' && $GAME['schweinchen-second']==1 &&
1446 (DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) ))
1449 DB_insert_comment('Schweinchen! ',$playid,$myid);
1450 $commentSchweinchen = 'Schweinchen! ';
1453 echo 'schweinchen = '.$GAME['schweinchen-who'].' ---<br />';
1456 /* if sequence == 4 check who one in case of wedding */
1457 if($sequence == 4 && $GT == 'wedding')
1459 /* is wedding resolve */
1460 $resolved = DB_get_sickness_by_gameid($gameid);
1463 /* who has wedding */
1464 $userids = DB_get_all_userid_by_gameid($gameid);
1465 foreach($userids as $user)
1467 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
1468 if($usersick == 'wedding')
1471 /* who won the trick */
1472 $play = DB_get_cards_by_trick($trickid);
1473 $winner = get_winner($play,$gametype); /* returns the position */
1474 $winnerid = DB_get_userid('gameid-position',$gameid,$winner);
1475 /* is tricknr <=3 */
1476 if($tricknr <=3 && $winnerid!=$whosick)
1478 /* set resolved at tricknr*/
1479 $resolved = DB_set_sickness_by_gameid($gameid,$tricknr);
1481 $whash = DB_get_hash_from_gameid_and_userid($gameid,$winnerid);
1482 DB_set_party_by_hash($whash,'re');
1484 if($tricknr == 3 && $winnerid==$whosick)
1486 /* set resolved at tricknr*/
1487 $resolved = DB_set_sickness_by_gameid($gameid,'3');
1492 /* if sequence == 4, set winner of the trick, count points and set the next player */
1495 $play = DB_get_cards_by_trick($trickid);
1496 $winner = get_winner($play,$gametype); /* returns the position */
1499 * check if someone caught a fox
1500 *******************************/
1502 /* first check if we should account for solos at all,
1503 * since it doesn't make sense in some games
1505 $ok = 0; /* fox shouldn't be counted */
1506 if(DB_get_gametype_by_gameid($gameid)=='solo')
1508 $solo = DB_get_solo_by_gameid($gameid);
1509 if($solo == 'trump' || $solo == 'silent')
1510 $ok = 1; /* for trump solos and silent solos, foxes are ok */
1513 $ok = 1; /* for all other games (not solos) foxes are ok too */
1516 foreach($play as $played)
1518 if ( $played['card']==19 || $played['card']==20 )
1519 if ($played['pos']!= $winner )
1521 /* possible caught a fox, check party */
1522 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1523 $uid2 = DB_get_userid('gameid-position',$gameid,$played['pos']);
1525 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1526 $party2 = DB_get_party_by_gameid_and_userid($gameid,$uid2);
1528 if($party1 != $party2)
1529 DB_query("INSERT INTO Score".
1530 " VALUES( NULL,NULL,$gameid,'$party1',$uid1,$uid2,'fox')");
1535 * check for karlchen (jack of clubs in the last trick)
1536 ******************************************************/
1538 /* same as for foxes, karlchen doesn't always make sense
1539 * check what kind of game it is and set karlchen accordingly */
1541 if($tricknr == 12 ) /* Karlchen works only in the last trick */
1543 /* check for solo */
1545 if(DB_get_gametype_by_gameid($gameid)=='solo' )
1546 $solo = DB_get_solo_by_gameid($gameid);
1548 /* no Karlchen in these solos */
1549 if($solo != 'trumpless' && $solo != 'jack' && $solo != 'queen' )
1551 foreach($play as $played)
1552 if ( $played['card']==11 || $played['card']==12 )
1553 if ($played['pos'] == $winner )
1556 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1557 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1559 DB_query("INSERT INTO Score".
1560 " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')");
1563 }; /* end scoring Karlchen */
1566 * check for doppelopf (>40 points)
1567 ***********************************/
1570 foreach($play as $played)
1572 $points += DB_get_card_value_by_cardid($played['card']);
1576 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1577 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1579 DB_query("INSERT INTO Score".
1580 " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'doko')");
1584 * set winner (for this trick)
1588 DB_query("UPDATE Trick SET winner='$winner' WHERE id='$trickid'");
1590 echo "ERROR during scoring";
1593 echo "DEBUG: position $winner won the trick <br />";
1595 /* who is the next player? */
1600 $next = DB_get_pos_by_hash($me)+1;
1602 if($next==5) $next=1;
1604 /* check for coment */
1605 if(myisset('comment'))
1607 $comment = $_REQUEST['comment'];
1609 DB_insert_comment($comment,$playid,$myid);
1610 if($commentSchweinchen)
1611 $comment = $commentSchweinchen . $comment;
1614 /* display played card */
1615 $pos = DB_get_pos_by_hash($me);
1618 echo " <li onclick=\"hl('".($tricknr)."');\" class=\"current\"><a href=\"#\">"._('Trick').' '.($tricknr)."</a>\n".
1619 " <div class=\"trick\" id=\"trick".($tricknr)."\">\n".
1620 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1623 echo " <div class=\"card".($pos-1)."\">\n ";
1625 /* display comments */
1626 display_card($card,$PREF['cardset']);
1628 echo "\n <span class=\"comment\"> ".$comment."</span>\n";
1631 echo " </div>\n </li>\n"; /* end div trick, end li trick */
1633 /*check if we still have cards left, else set status to gameover */
1634 if(sizeof(DB_get_hand($me))==0)
1636 DB_set_hand_status_by_hash($me,'gameover');
1637 $mystatus = 'gameover';
1640 /* if all players are done, set game status to game over,
1641 * get the points of the last trick and send out an email
1644 $userids = DB_get_all_userid_by_gameid($gameid);
1647 foreach($userids as $user)
1648 if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='gameover')
1652 DB_set_game_status_by_gameid($gameid,'gameover');
1654 /* email next player, if game is still running */
1655 if(DB_get_game_status_by_gameid($gameid)=='play')
1657 $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
1658 $who = DB_get_userid('hash',$next_hash);
1659 DB_set_player_by_gameid($gameid,$who);
1661 $message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
1662 "It's your turn now.\n".
1663 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$next_hash."\n\n" ;
1664 if( DB_get_email_pref_by_uid($who)!='emailaddict' )
1666 $subject = 'A card has been played in game '.DB_format_gameid($gameid);
1667 mymail($who,$subject,$message);
1670 else /* send out final email */
1672 /* individual score */
1673 $result = DB_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party FROM Hand".
1674 " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
1675 " LEFT JOIN User ON User.id=Hand.user_id".
1676 " LEFT JOIN Play ON Trick.id=Play.trick_id".
1677 " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
1678 " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
1679 " WHERE Hand.game_id='$gameid'".
1680 " GROUP BY User.fullname" );
1681 $message = "The game is over. Thanks for playing :)\n";
1682 $message .= "Final score:\n";
1683 while( $r = DB_fetch_array($result) )
1684 $message .= " ".$r[0]."(".$r[2].") ".$r[1]."\n";
1686 $result = DB_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand".
1687 " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
1688 " LEFT JOIN User ON User.id=Hand.user_id".
1689 " LEFT JOIN Play ON Trick.id=Play.trick_id".
1690 " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
1691 " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
1692 " WHERE Hand.game_id='$gameid'".
1693 " GROUP BY Hand.party" );
1694 $message .= "\nTotals:\n";
1697 while( $r = DB_fetch_array($result) )
1699 $message .= " ".$r[0]." ".$r[1]."\n";
1702 else if($r[0] == 'contra')
1707 * save score in database
1711 /* get calls from re/contra */
1714 foreach($userids as $user)
1716 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1717 $call = DB_get_call_by_hash($hash);
1718 $party = DB_get_party_by_hash($hash);
1722 $call = (int) $call;
1728 else if( $call < $call_re)
1731 else if($party=='contra')
1733 if($call_contra== -1)
1734 $call_contra = $call;
1735 else if( $call < $call_contra)
1736 $call_contra = $call;
1741 /* figure out who one */
1742 $winning_party = NULL;
1744 if($call_re == -1 && $call_contra == -1)
1746 /* nobody made a call, so it's easy to figure out who won */
1748 $winning_party='re';
1750 $winning_party='contra';
1754 /* if one party makes a call, they only win, iff they make enough points
1755 * if only one party made a call, the other one wins,
1756 * if the first one didn't make it
1760 $offset = 120 - $call_re;
1762 $offset--; /* since we use a > in the next equation */
1764 if($re > 120+$offset)
1765 $winning_party='re';
1766 else if ($call_contra == -1 )
1767 $winning_party='contra';
1770 if($call_contra != -1)
1772 $offset = 120 - $call_contra;
1773 if($call_contra == 0)
1774 $offset--; /* since we use a > in the next equation */
1776 if($contra > 120+$offset)
1777 $winning_party='contra';
1778 else if ($call_re == -1 )
1779 $winning_party='re';
1783 /* one point for each call of the other party in case the other party didn't win
1784 * and one point each in case the party made more than points than one of the calls
1786 if($winning_party!='contra' && $call_contra!= -1)
1788 for( $p=$call_contra;$p<=120; $p+=30 )
1790 DB_query("INSERT INTO Score".
1791 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'against$p')");
1794 for( $p=$call_contra; $p<120; $p+=30)
1797 DB_query("INSERT INTO Score".
1798 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'made$p')");
1801 if($winning_party!='re' and $call_re!= -1)
1803 for( $p=$call_re;$p<=120; $p+=30 )
1805 DB_query("INSERT INTO Score".
1806 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'against$p')");
1809 for( $p=$call_re; $p<120; $p+=30)
1812 DB_query("INSERT INTO Score".
1813 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'made$p')");
1817 /* point in case contra won */
1818 if($winning_party=='contra')
1820 DB_query("INSERT INTO Score".
1821 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'againstqueens')");
1824 /* one point each for winning and each 30 points + calls */
1825 if($winning_party=='re')
1827 foreach(array(120,150,180,210,240) as $p)
1830 if($p==240 || $call_contra != -1)
1834 DB_query("INSERT INTO Score".
1835 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'".(240-$p)."')");
1837 /* re called something and won */
1838 foreach(array(0,30,60,90,120) as $p)
1840 if($call_re!= -1 && $call_re<$p+1)
1841 DB_query("INSERT INTO Score".
1842 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'call$p')");
1845 else if( $winning_party=='contra')
1847 foreach(array(120,150,180,210,240) as $p)
1850 if($p==240 || $call_re != -1)
1853 if($contra>$p-$offset)
1854 DB_query("INSERT INTO Score".
1855 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'".(240-$p)."')");
1857 /* re called something and won */
1858 foreach(array(0,30,60,90,120) as $p)
1860 if($call_contra != -1 && $call_contra<$p+1)
1861 DB_query("INSERT INTO Score".
1862 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'call$p')");
1867 /* add score points to email */
1870 $message .= " Points Re: \n";
1871 $queryresult = DB_query("SELECT score FROM Score ".
1872 " WHERE game_id=$gameid AND party='re'".
1874 while($r = DB_fetch_array($queryresult) )
1876 $message .= " ".$r[0]."\n";
1879 $message .= " Points Contra: \n";
1880 $queryresult = DB_query("SELECT score FROM Score ".
1881 " WHERE game_id=$gameid AND party='contra'".
1883 while($r = DB_fetch_array($queryresult) )
1885 $message .= " ".$r[0]."\n";
1888 $message .= " Total Points (from the Re point of view): $Tpoint\n";
1891 $session = DB_get_session_by_gameid($gameid);
1892 $score = generate_score_table($session);
1894 $message .= "Score Table:\n";
1895 $message .= format_score_table_ascii($score);
1896 $message .= "\nUse these links to have a look at game ".DB_format_gameid($gameid).": \n";
1898 /* send out final email */
1899 foreach($userids as $user)
1901 /* add links for all players */
1902 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1903 $name = DB_get_name('userid',$user);
1905 $link = "$name: ".$HOST.$INDEX."?action=game&me=".$hash."\n" ;
1908 $message .= "\n\n (you can use reply all on this email to reach all the players.)\n\n";
1909 $subject = ' Game over (game '.DB_format_gameid($gameid).') ';
1910 mymail($userids,$subject,$message);
1915 echo "can't find that card?! <br />\n";
1918 else if(myisset('card') && !$myturn )
1920 echo _("please wait until it's your turn!")."<br />\n";
1923 if($seq!=4 && $trickNR>=1 && !(myisset('card') && $myturn) )
1924 echo " </div>\n </li>\n"; /* end div trick, end li trick */
1926 /* display points in case game is over */
1927 if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' )
1929 echo " <li onclick=\"hl('13');\" class=\"current\"><a href=\"#\">"._('Score')."</a>\n".
1930 " <div class=\"trick\" id=\"trick13\">\n";
1931 /* add pic for re/contra
1932 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";*/
1934 $result = DB_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party,Hand.position FROM Hand".
1935 " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
1936 " LEFT JOIN User ON User.id=Hand.user_id".
1937 " LEFT JOIN Play ON Trick.id=Play.trick_id".
1938 " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
1939 " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
1940 " WHERE Hand.game_id='$gameid'".
1941 " GROUP BY User.fullname" );
1942 while( $r = DB_fetch_array($result))
1943 echo " <div class=\"card".($r[3]-1)."\">\n".
1944 " <div class=\"score\">".$r[2]."<br /> ".$r[1]."</div>\n".
1947 /* display totals */
1948 $result = DB_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand".
1949 " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
1950 " LEFT JOIN User ON User.id=Hand.user_id".
1951 " LEFT JOIN Play ON Trick.id=Play.trick_id".
1952 " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
1953 " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
1954 " WHERE Hand.game_id='$gameid'".
1955 " GROUP BY Hand.party" );
1956 echo "<div class=\"total\">\n Totals:<br />\n";
1957 while( $r = DB_fetch_array($result))
1958 echo " ".$r[0]." ".$r[1]."<br />\n";
1960 $queryresult = DB_query("SELECT timediff(mod_date,create_date) ".
1961 " FROM Game WHERE id='$gameid'");
1962 $r = DB_fetch_array($queryresult);
1963 echo " <p>This game took ".$r[0]." hours.</p>\n";
1965 echo " <div class=\"re\">\n Points Re: <br />\n";
1966 $queryresult = DB_query("SELECT score FROM Score ".
1967 " WHERE game_id=$gameid AND party='re'".
1969 while($r = DB_fetch_array($queryresult) )
1970 echo " ".$r[0]."<br />\n";
1973 echo " <div class=\"contra\">\n Points Contra: <br />\n";
1974 $queryresult = DB_query("SELECT score FROM Score ".
1975 " WHERE game_id=$gameid AND party='contra'".
1977 while($r = DB_fetch_array($queryresult) )
1978 echo " ".$r[0]."<br />\n";
1983 echo " </div>\n </li>\n"; /* end div trick, end li trick */
1986 echo " <li onclick=\"hl_prev();\" class=\"old\"><a href=\"#\">"._('prev')."</a></li>\n";
1987 echo " <li onclick=\"hl_next();\" class=\"old\"><a href=\"#\">"._('next')."</a></li>\n";
1988 echo "</ul>\n"; /* end ul tricks*/
1990 $mycards = DB_get_hand($me);
1991 $mycards = mysort($mycards,$gametype);
1992 echo "<div class=\"mycards\">\n";
1994 if($myturn && !myisset('card') && $mystatus=='play' )
1996 echo "Hello ".$myname.", it's your turn! <br />\n";
1997 echo _('Your cards are').": <br />\n";
1999 /* do we have to follow suite? */
2001 if(have_suit($mycards,$firstcard))
2004 /* count how many cards we can play, so that we can pre-select it if there is only one */
2006 foreach($mycards as $card)
2011 /* display only cards that the player is allowed to play as links, the rest just display normal
2012 * also check if we have both schweinchen, in that case only display on of them as playable
2014 if( ($followsuit && !same_type($card,$firstcard)) ||
2015 ( (int)($card)==19 &&
2016 !$GAME['schweinchen-first'] &&
2017 ( $RULES['schweinchen']=='second' ||
2018 ( $RULES['schweinchen']=='secondaftercall' &&
2019 (DB_get_call_by_hash($GAME['schweinchen-who']) ||
2020 DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
2023 $GAME['schweinchen-who']==$me &&
2024 in_array($gametype,array('normal','wedding','trump','silent'))
2032 if($howmanycards==1)
2037 foreach($mycards as $card)
2039 /* display only cards that the player is allowed to play as links, the rest just display normal
2040 * also check if we have both schweinchen, in that case only display on of them as playable
2042 if( ($followsuit && !same_type($card,$firstcard)) ||
2043 ( (int)($card)==19 &&
2044 !$GAME['schweinchen-first'] &&
2045 ( $RULES['schweinchen']=='second' ||
2046 ( $RULES['schweinchen']=='secondaftercall' &&
2047 (DB_get_call_by_hash($GAME['schweinchen-who']) ||
2048 DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
2051 $GAME['schweinchen-who']==$me &&
2052 in_array($gametype,array('normal','wedding','trump','silent'))
2055 display_card($card,$PREF['cardset']);
2057 display_link_card($card,$PREF['cardset'],$type='card',$selected=$howmanycards);
2060 else if($mystatus=='play' )
2062 echo _('Your cards are').": <br />\n";
2063 foreach($mycards as $card)
2064 display_card($card,$PREF['cardset']);
2066 else if($mystatus=='gameover')
2068 $oldcards = DB_get_all_hand($me);
2069 $oldcards = mysort($oldcards,$gametype);
2071 if(isset($_SESSION['id']) && $myid==$_SESSION['id'])
2072 echo _('Your cards were').": <br />\n";
2075 $name = DB_get_name('userid',$myid);
2076 echo "$name's were: <br />\n";
2079 foreach($oldcards as $card)
2080 display_card($card,$PREF['cardset']);
2082 $userids = DB_get_all_userid_by_gameid($gameid);
2083 foreach($userids as $user)
2085 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
2091 $name = DB_get_name('userid',$user);
2092 $oldcards = DB_get_all_hand($userhash);
2093 $oldcards = mysort($oldcards,$gametype);
2094 echo "$name's cards were: <br />\n";
2095 foreach($oldcards as $card)
2096 display_card($card,$PREF['cardset']);
2102 /* if the game is over do some extra stuff, therefore exit the swtich statement if we are still playing*/
2103 if($mystatus=='play')
2106 /* the following happens only when the gamestatus is 'gameover' */
2107 /* check if game is over, display results */
2108 if(DB_get_game_status_by_gameid($gameid)=='play')
2110 echo _('The game is over for you... other people still need to play though');
2114 myerror("error in testing the status");
2117 /* output other games where it is the users turn
2118 * make sure that the people looking at old games don't see the wrong games here
2120 if( $gamestatus != 'gameover' )
2122 /* game isn't over, only valid user can get here, so show menu */
2123 display_user_menu($myid);
2125 else if( $origmystatus != 'gameover' )
2127 /* user just played the very last card, game is now over, it's still ok to show the menu though */
2128 display_user_menu($myid);
2130 else if( $mystatus == 'gameover' &&
2131 isset($_SESSION['id']) )
2133 /* user is looking at someone else's game, show the menu for the correct user */
2134 display_user_menu($_SESSION['id']);
2138 echo "<div class=\"usermenu\">\n";
2139 echo "It's your turn in these games:<br />\n";
2140 echo "Please log in to see this information.\n";
2145 * display gameinfo: re/contra, comment-box, play-card button, games played by others
2148 echo "<div class=\"gameinfo\">\n";
2150 /* get time from the last action of the game */
2151 $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
2152 $gameend = time() - strtotime($r[0]);
2155 if($gamestatus == 'play' || $gameend < 60*60*24*7)
2157 echo ' '._('A short comment').":<input name=\"comment\" type=\"text\" size=\"20\" maxlength=\"100\" />\n";
2161 if($gamestatus == 'play' )
2163 $myparty = DB_get_party_by_hash($me);
2164 output_form_calls($me,$myparty);
2167 /* play-card button */
2168 if($gamestatus == 'play' || $gameend < 60*60*24*7)
2170 echo " <input type=\"submit\" value=\""._('submit')."\" />\n";
2173 /* has this hand been played by others? */
2174 $other_game_ids = DB_played_by_others($gameid);
2175 if(sizeof($other_game_ids)>0 && $mystatus=='gameover')
2177 $mypos = DB_get_pos_by_hash($me);
2178 echo " <p>See how other played the same hand: \n";
2179 foreach($other_game_ids as $id)
2181 $otherhash = DB_get_hash_from_game_and_pos($id,$mypos);
2182 $othername = DB_get_name('hash',$otherhash);
2183 echo " <a href=\"$INDEX?action=game&me=$otherhash\">$othername</a> ";
2188 echo "</div>\n"; /* end gameinfo */
2192 $gamestatus = DB_get_game_status_by_gameid($gameid);
2193 if($mystatus=='gameover' &&
2194 ($gamestatus =='gameover' || $gamestatus =='cancel-nines' || $gamestatus =='cancel-trump') &&
2195 isset($_SESSION['id']) && $_SESSION['id']==$myid)
2197 $session = DB_get_session_by_gameid($gameid);
2198 $result = DB_query("SELECT id,create_date FROM Game".
2199 " WHERE session=$session".
2200 " ORDER BY create_date DESC".
2204 $r = DB_fetch_array($result);
2206 if(!$session || $gameid==$r[0])
2208 /* suggest a new game with the same people in it, just rotated once (unless last game was solo) */
2209 $names = DB_get_all_names_by_gameid($gameid);
2210 $type = DB_get_gametype_by_gameid($gameid);
2214 $solo = DB_get_solo_by_gameid($gameid);
2216 if($solo!='silent') /* repeat game with same first player */
2217 output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid);
2218 else /* rotate normally */
2219 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
2221 else if($gamestatus == 'cancel-nines' || $gamestatus == 'cancel-trump')
2222 output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid);
2223 else /* rotate normally */
2224 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);