updated copyright notice for 2012
[e-DoKo.git] / include / game.php
index c78482c1042dd8e409bb1cdccea8c481691fdb56..0ce72e55a1f9e583245b6781ca2b77a42df5549e 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-/* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
+/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 Arun Persaud <arun@nubati.net>
  *
  *   This file is part of e-DoKo.
  *
@@ -53,6 +53,7 @@ $mypos    = DB_get_pos_by_hash($me);
 $myhand   = DB_get_handid('hash',$me);
 $myparty  = DB_get_party_by_hash($me);
 $session  = DB_get_session_by_gameid($gameid);
+$playid   = DB_get_current_playid($gameid); /* might be -1 at beginning of the game */
 
 /* get prefs and save them in a variable*/
 $PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid);
@@ -128,51 +129,67 @@ if( $mystatus!='gameover' )
        DB_insert_note($note,$gameid,$myid);
     };
 
-/* handle calls, output a comment to show when the call was made */
-/* initialize comments */
-$comment  =  '';
-
-/* get information needed to submit comment */
-$playid = DB_get_current_playid($gameid);
-
-/* set comment */
-if($comment != '')
-  DB_insert_comment($comment,$playid,$myid);
-/* clear up */
-unset($comment);
-/* end check for calls */
+/*****************************************************************
+ * handle calls part1: check what was called, set everything up
+ * we only can submit it to the database at the end, since the playid
+ * might change if a player plays a card
+ *****************************************************************/
 
+/* initialize comments */
+$commentCall = '';
 
 /* check for calls, set comment */
-if(myisset('call')  && $_REQUEST['call']  == '120' && can_call(120,$me))
-  {
-    $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
-    if($myparty=='re')
-      $comment .= "Re";
-    else if($myparty=='contra')
-      $comment .= "Contra";
-  }
-if(myisset('call')  && $_REQUEST['call']  == '90' && can_call(90,$me))
-  {
-    $result = DB_query("UPDATE Hand SET point_call='90'  WHERE hash='$me' ");
-    $comment .= "No 90";
-  }
-if(myisset('call')  && $_REQUEST['call']  == '60' && can_call(60,$me))
-  {
-    $result = DB_query("UPDATE Hand SET point_call='60'  WHERE hash='$me' ");
-    $comment .= "No 60";
-  }
-if(myisset('call')  && $_REQUEST['call']  == '30' && can_call(30,$me))
-  {
-    $result = DB_query("UPDATE Hand SET point_call='30'  WHERE hash='$me' ");
-    $comment .= "No 30";
-  }
-if(myisset('call')  && $_REQUEST['call']  == '0' && can_call(0,$me))
+if( myisset('call') )
   {
-    $result = DB_query("UPDATE Hand SET point_call='0'   WHERE hash='$me' ");
-    $comment .= "Zero";
+    if($_REQUEST['call']  == '120' && can_call(120,$me))
+      {
+       $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
+       if($myparty=='re')
+         $commentCall = "Re";
+       else if($myparty=='contra')
+         $commentCall = "Contra";
+      }
+    else if($_REQUEST['call']  == '90' && can_call(90,$me))
+      {
+       $result = DB_query("UPDATE Hand SET point_call='90'  WHERE hash='$me' ");
+       $commentCall = "No 90";
+      }
+    else if($_REQUEST['call']  == '60' && can_call(60,$me))
+      {
+       $result = DB_query("UPDATE Hand SET point_call='60'  WHERE hash='$me' ");
+       $commentCall = "No 60";
+      }
+    else if($_REQUEST['call']  == '30' && can_call(30,$me))
+      {
+       $result = DB_query("UPDATE Hand SET point_call='30'  WHERE hash='$me' ");
+       $commentCall = "No 30";
+      }
+    else if($_REQUEST['call']  == '0' && can_call(0,$me))
+      {
+       $result = DB_query("UPDATE Hand SET point_call='0'   WHERE hash='$me' ");
+       $commentCall = "Zero";
+      }
   }
 
+/**********************************************************
+ * handle comments unless we play a card at the same time *
+ * (if we play a card, we need to update playid)          *
+ **********************************************************/
+
+
+/* get time from the last action of the game */
+$r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
+$gameend = time() - strtotime($r[0]);
+
+/* handle comments in case player didn't play a card, allow comments a week after the end of the game */
+if( (!myisset('card') && $mystatus!='gameover') || ($mystatus=='gameover' && ($gameend < 60*60*24*7)) )
+  if(myisset('comment'))
+    {
+      $comment = $_REQUEST['comment'];
+
+      if($comment != '')
+       DB_insert_comment($comment,$playid,$gameid,$myid);
+    };
 
 
 /*****************************************************************
@@ -183,12 +200,12 @@ if(myisset('call')  && $_REQUEST['call']  == '0' && can_call(0,$me))
 if( $gamestatus != 'gameover'  && isset($_SESSION['id']) )
   {
     /* game isn't over, only valid user can get here, so show menu */
-    display_user_menu($myid);
+    display_user_menu($myid, $me);
   }
 else if( $mystatus == 'gameover' && isset($_SESSION['id']) )
   {
     /* user is looking at someone else's game, show the menu for the correct user */
-    display_user_menu($_SESSION['id']);
+    display_user_menu($_SESSION['id'],$me);
   }
 else
   {
@@ -330,6 +347,84 @@ if($mystatus!='gameover')
    if(isset($_SESSION['id']))
      DB_update_user_timestamp($_SESSION['id']);
 
+
+/******************************************************************************
+ * Output menu for selecting tricks
+ ******************************************************************************/
+
+switch($mystatus)
+  {
+  case 'start':
+    break;
+  case 'init':
+  case 'check':
+    /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
+    echo "\n<ul class=\"tricks\">\n";
+    echo "  <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n";
+
+    echo "    </li>\n</ul>\n";  /* end div trick, end li trick , end tricks*/
+    /* end displaying sickness */
+    break;
+  case 'poverty':
+    /* output pre-game trick in case user reloads,
+     * only needs to be done when a team has been formed */
+    if($myparty=='re' || $myparty=='contra')
+      {
+       echo "\n<ul class=\"tricks\">\n";
+
+       $mygametype =  DB_get_gametype_by_gameid($gameid);
+
+       echo "  <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n";
+       echo "  </li>\n</ul>\n\n";  /* end div trick, end li trick , end ul tricks */
+      }
+    /* end output pre-game trick */
+    break;
+  case 'play':
+  case 'gameover':
+
+    echo "\n<ul class=\"tricks\">\n";
+
+    /* output vorbehalte */
+    $mygametype = DB_get_gametype_by_gameid($gameid);
+    $mygamesolo = DB_get_solo_by_gameid($gameid);
+    if($mygametype != 'normal') /* only show when needed */
+      if(!( $mygametype == 'solo' && $mygamesolo == 'silent') )
+       echo "  <li onclick=\"hl('0');\" class=\"old\"><a href=\"#\">Pre</a></li>\n";
+
+    $result = DB_query("SELECT Trick.id ".
+                      "FROM Trick ".
+                      "WHERE Trick.game_id='".$gameid."' ".
+                      "GROUP BY Trick.id ".
+                      "ORDER BY Trick.id ASC");
+    $trickNR   = 1;
+    $lasttrick = DB_get_max_trickid($gameid);
+
+    /* output tricks */
+    while($r = DB_fetch_array($result))
+      {
+       $trick=$r[0];
+       if($trick!=$lasttrick)
+         echo "  <li onclick=\"hl('$trickNR');\" class=\"old\"><a href=\"#\">"._('Trick')." $trickNR</a></li>\n";
+       else if($trick==$lasttrick)
+         echo "  <li onclick=\"hl('$trickNR');\" class=\"current\"><a href=\"#\">"._('Trick')." $trickNR</a></li>\n";
+       $trickNR++;
+      }
+
+    /* if game is over, also output link to Score tab */
+    if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' )
+      echo "  <li onclick=\"hl('13');\" class=\"current\"><a href=\"#\">"._('Score')."</a></li>\n";
+
+    /* output previous/next buttons */
+    echo "  <li onclick=\"hl_prev();\" ><button>"._('prev')."</button></li>\n";
+    echo "  <li onclick=\"hl_next();\" ><button>"._('next')."</button></li>\n";
+
+    echo "</ul>\n\n";
+
+    break;
+  default:
+  }
+
+
 /******************************************************************************
  * Output tricks played, table, messages, and cards (depending on game status)
  ******************************************************************************/
@@ -338,7 +433,80 @@ if($mystatus!='gameover')
 echo "<form action=\"index.php?action=game&amp;me=$me\" method=\"post\">\n";
 
 /* display the table and the names */
-display_table();
+display_table_begin();
+
+
+/******************************
+ * Output pre-trick if needed *
+ ******************************/
+
+switch($mystatus)
+  {
+  case 'start':
+    break;
+  case 'init':
+  case 'check':
+    /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
+    echo "\n<div class=\"tricks\">\n";
+    echo "    <div class=\"trick\" id=\"trick0\">\n";
+
+    for($pos=1;$pos<5;$pos++)
+      {
+       $usersick   = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
+       $userid     = DB_get_userid('gameid-position',$gameid,$pos);
+       $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
+
+       if($userstatus=='start' || $userstatus=='init')
+         echo " <div class=\"vorbehalt".($pos-1)."\"> still needs <br />to decide </div>\n"; /* show this to everyone */
+       else
+         if($usersick!=NULL) /* in the init-phase we only showed players with $pos<$mypos, now we can show all */
+           echo " <div class=\"vorbehalt".($pos-1)."\"> sick </div>\n";
+         else
+           echo " <div class=\"vorbehalt".($pos-1)."\"> healthy </div>\n";
+      }
+
+    /* display all comments on the top right (card1)*/
+    $comments = DB_get_pre_comment($gameid);
+    /* display card */
+    echo "      <div class=\"card1\">\n";
+    /* display comments */
+    foreach( $comments as $comment )
+      echo "        <span class=\"comment\">".$comment[1].": ".$comment[0]."</span>\n";
+    echo "      </div>\n"; /* end div card */
+
+
+    echo "    </div>\n  </div>\n";  /* end div trick, end li trick , end tricks*/
+    /* end displaying sickness */
+
+    break;
+  case 'poverty':
+    /* output pre-game trick in case user reloads,
+     * only needs to be done when a team has been formed */
+    if($myparty=='re' || $myparty=='contra')
+      {
+       echo "\n<div class=\"tricks\">\n";
+
+       $mygametype =  DB_get_gametype_by_gameid($gameid);
+
+       echo "    <div class=\"trick\" id=\"trick0\">\n";
+
+       /* get information so show the cards that have been handed over in a poverty game */
+       output_exchanged_cards();
+
+       echo "    </div>\n </div>\n\n";  /* end div trick, end li trick , end ul tricks */
+      }
+    /* end output pre-game trick */
+    break;
+  case 'play':
+  case 'gameover':
+
+    /* taken care further down */
+    break;
+  default:
+  }
+
+
+
 
 /* mystatus gets the player through the different stages of a game.
  * start:    does the player want to play?
@@ -361,6 +529,7 @@ $cards_status = CARDS_EMPTY;
  */
 $messages = array();
 
+
 switch($mystatus)
   {
   case 'start':
@@ -428,28 +597,6 @@ switch($mystatus)
      ***************************/
     if(!myisset('solo','wedding','poverty','nines','lowtrump') )
       {
-       /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
-       echo "\n<ul class=\"tricks\">\n";
-       echo "  <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
-         "    <div class=\"trick\" id=\"trick0\">\n";
-
-       for($pos=1;$pos<5;$pos++)
-         {
-           $usersick   = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
-           $userid     = DB_get_userid('gameid-position',$gameid,$pos);
-           $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
-
-           if($userstatus=='start' || $userstatus=='init')
-             echo " <div class=\"vorbehalt".($pos-1)."\"> still needs <br/ > to decide </div>\n"; /* show this to everyone */
-           else
-             if($usersick!=NULL && $pos<=$mypos ) /* only show this for people sitting before the player */
-               echo " <div class=\"vorbehalt".($pos-1)."\"> sick </div>\n";
-             else if($usersick==NULL && $pos<=$mypos)
-               echo " <div class=\"vorbehalt".($pos-1)."\"> healthy </div>\n";
-         }
-       echo "    </div>\n  </li>\n</ul>\n";  /* end div trick, end li trick , end tricks*/
-       /* end displaying sickness */
-
        $mycards = DB_get_hand($me);
        output_check_for_sickness($me,$mycards);
 
@@ -546,28 +693,6 @@ switch($mystatus)
      * this can therefore only be handled once all players finished the last stage
      */
 
-    /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
-    echo "\n<ul class=\"tricks\">\n";
-    echo "  <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
-      "    <div class=\"trick\" id=\"trick0\">\n";
-
-    for($pos=1;$pos<5;$pos++)
-      {
-       $usersick   = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
-       $userid     = DB_get_userid('gameid-position',$gameid,$pos);
-       $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
-
-       if($userstatus=='start' || $userstatus=='init')
-         echo " <div class=\"vorbehalt".($pos-1)."\"> still needs <br />to decide </div>\n"; /* show this to everyone */
-       else
-         if($usersick!=NULL) /* in the init-phase we only showed players with $pos<$mypos, now we can show all */
-           echo " <div class=\"vorbehalt".($pos-1)."\"> sick </div>\n";
-         else
-           echo " <div class=\"vorbehalt".($pos-1)."\"> healthy </div>\n";
-      }
-    echo "    </div>\n  </li>\n</ul>\n";  /* end div trick, end li trick , end tricks*/
-    /* end displaying sickness */
-
     $messages[] = _('Checking if someone else selected solo, nines, wedding or poverty.');
 
     /* check if everyone has reached this stage */
@@ -879,24 +1004,6 @@ switch($mystatus)
          };
       }
 
-    /* output pre-game trick in case user reloads,
-     * only needs to be done when a team has been formed */
-    if($myparty=='re' || $myparty=='contra')
-      {
-       echo "\n<ul class=\"tricks\">\n";
-
-       $mygametype =  DB_get_gametype_by_gameid($gameid);
-
-       echo "  <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
-         "    <div class=\"trick\" id=\"trick0\">\n";
-
-       /* get information so show the cards that have been handed over in a poverty game */
-       output_exchanged_cards();
-
-       echo "    </div>\n  </li>\n</ul>\n\n";  /* end div trick, end li trick , end ul tricks */
-      }
-    /* end output pre-game trick */
-
     /* get hand */
     $mycards = DB_get_hand($me);
 
@@ -1228,22 +1335,6 @@ switch($mystatus)
                * only  play a card after everyone is ready to play */
       }
 
-
-    /* get time from the last action of the game */
-    $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
-    $gameend = time() - strtotime($r[0]);
-
-    /* handle comments in case player didn't play a card, allow comments a week after the end of the game */
-    if( (!myisset('card') && $mystatus=='play') || ($mystatus=='gameover' && ($gameend < 60*60*24*7)) )
-      if(myisset('comment'))
-       {
-         $comment = $_REQUEST['comment'];
-         $playid = DB_get_current_playid($gameid);
-
-         if($comment != '')
-           DB_insert_comment($comment,$playid,$myid);
-       };
-
     /* get everything relevant to display the tricks */
     $result = DB_query("SELECT Hand_Card.card_id as card,".
                       "       Hand.position as position,".
@@ -1270,22 +1361,41 @@ switch($mystatus)
     $pos  = DB_get_startplayer_by_gameid($gameid)-1;
     $firstcard = ''; /* first card in a trick */
 
-    echo "\n<ul class=\"tricks\">\n";
+    echo "\n<div class=\"tricks\">\n";
 
     /* output vorbehalte */
     $mygametype = DB_get_gametype_by_gameid($gameid);
     $mygamesolo = DB_get_solo_by_gameid($gameid);
+    $show_pre_game_comments=1;
     if($mygametype != 'normal') /* only show when needed */
       if(!( $mygametype == 'solo' && $mygamesolo == 'silent') )
        {
-         echo "  <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
-           "    <div class=\"trick\" id=\"trick0\">\n";
+         echo "    <div class=\"trick\" id=\"trick0\">\n";
 
          /* get information so show the cards that have been handed over in a poverty game */
          output_exchanged_cards();
+         $show_pre_game_comments=0;
 
-         echo "    </div>\n  </li>\n";  /* end div trick, end li trick */
+         echo "    </div>\n";  /* end div trick, end li trick */
        }
+    if($show_pre_game_comments==1)
+      {
+       /* display all comments on the top right (card1)*/
+       $comments = DB_get_pre_comment($gameid);
+
+       if(sizeof($comments))
+         {
+           echo "    <div class=\"trick\" id=\"trick0\">\n";
+           /* display card */
+           echo "      <div class=\"card1\">\n";
+           /* display comments */
+           foreach( $comments as $comment )
+             echo "        <span class=\"comment\">".$comment[1].": ".$comment[0]."</span>\n";
+           echo "      </div>\n"; /* end div card */
+
+           echo "    </div>\n";  /* end div trick, end li trick */
+         }
+      }
 
     /* output tricks */
     while($r = DB_fetch_array($result))
@@ -1316,15 +1426,13 @@ switch($mystatus)
            if($trick!=$lasttrick)
              {
                /* start of an old trick? */
-               echo "  <li onclick=\"hl('$trickNR');\" class=\"old\"><a href=\"#\">"._('Trick')." $trickNR</a>\n".
-                 "    <div class=\"trick\" id=\"trick".$trickNR."\">\n".
+               echo  "    <div class=\"trick\" id=\"trick".$trickNR."\">\n".
                  "      <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
              }
            else if($trick==$lasttrick)
              {
                /* start of a last trick? */
-               echo "  <li onclick=\"hl('$trickNR');\" class=\"current\"><a href=\"#\">"._('Trick')." $trickNR</a>\n".
-                 "    <div class=\"trick\" id=\"trick".$trickNR."\">\n".
+               echo "    <div class=\"trick\" id=\"trick".$trickNR."\">\n".
                  "      <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
              };
 
@@ -1335,6 +1443,14 @@ switch($mystatus)
        /* display card */
        echo "      <div class=\"card".($pos-1)."\">\n";
 
+       /* for the first card, we also need to display calls from other players */
+       if($seq==1 && $trickNR==1)
+         {
+           $commentPreCalls=DB_get_pre_comment_call($gameid);
+           foreach ($commentPreCalls as $pre )
+             $comment .= $pre[1].": ".$pre[0]."<br/>";
+         }
+
        /* display comments */
        if($comment!='')
          echo "        <span class=\"comment\">".$comment."</span>\n";
@@ -1348,7 +1464,7 @@ switch($mystatus)
        if($seq==4)
          {
            $winner    = get_winner($play,$gametype); /* returns the position */
-           echo "    </div>\n  </li>\n";  /* end div trick, end li trick */
+           echo "    </div>\n";  /* end div trick, end li trick */
          }
       }
 
@@ -1417,7 +1533,7 @@ switch($mystatus)
                     (DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) ))
                  )
                  {
-                   DB_insert_comment('Schweinchen! ',$playid,$myid);
+                   DB_insert_comment('Schweinchen! ',$playid,$gameid,$myid);
                    $commentSchweinchen = 'Schweinchen! ';
                  }
                if ($debug)
@@ -1577,17 +1693,18 @@ switch($mystatus)
              {
                $comment = $_REQUEST['comment'];
                if($comment != '')
-                 DB_insert_comment($comment,$playid,$myid);
+                 DB_insert_comment($comment,$playid,$gameid,$myid);
                if($commentSchweinchen)
                  $comment = $commentSchweinchen . $comment;
+               if($commentCall != '')
+                 $comment = $commentCall . $comment;
              };
 
            /* display played card */
            $pos = DB_get_pos_by_hash($me);
            if($sequence==1)
              {
-               echo "  <li onclick=\"hl('".($tricknr)."');\" class=\"current\"><a href=\"#\">"._('Trick').' '.($tricknr)."</a>\n".
-                 "    <div class=\"trick\" id=\"trick".($tricknr)."\">\n".
+               echo "    <div class=\"trick\" id=\"trick".($tricknr)."\">\n".
                  "      <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
              }
 
@@ -1599,7 +1716,7 @@ switch($mystatus)
              echo "\n        <span class=\"comment\"> ".$comment."</span>\n";
            echo "      </div>\n";
 
-           echo "    </div>\n  </li>\n";  /* end div trick, end li trick */
+           echo "    </div>\n";  /* end div trick, end li trick */
 
            /*check if we still have cards left, else set status to gameover */
            if(sizeof(DB_get_hand($me))==0)
@@ -1890,13 +2007,12 @@ switch($mystatus)
       }
 
     if($seq!=4 && $trickNR>=1 && !(myisset('card') && $myturn) )
-      echo "    </div>\n  </li>\n";  /* end div trick, end li trick */
+      echo "    </div>\n";  /* end div trick, end li trick */
 
     /* display points in case game is over */
     if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' )
       {
-       echo "  <li onclick=\"hl('13');\" class=\"current\"><a href=\"#\">"._('Score')."</a>\n".
-         "    <div class=\"trick\" id=\"trick13\">\n";
+       echo "    <div class=\"trick\" id=\"trick13\">\n";
        /* add pic for re/contra
         "      <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";*/
 
@@ -1922,39 +2038,37 @@ switch($mystatus)
                           " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
                           " WHERE Hand.game_id='$gameid'".
                           " GROUP BY Hand.party" );
-       echo "<div class=\"total\">\n  Totals:<br />\n";
+       echo "    <div class=\"total\">\n  Totals:<br />\n";
        while( $r = DB_fetch_array($result))
-         echo "  ".$r[0]." ".$r[1]."<br />\n";
+         echo "      ".$r[0]." ".$r[1]."<br />\n";
 
        $queryresult = DB_query("SELECT timediff(mod_date,create_date) ".
                                " FROM Game WHERE id='$gameid'");
        $r = DB_fetch_array($queryresult);
-       echo "  <p>This game took ".$r[0]." hours.</p>\n";
+       echo "      <p>This game took ".$r[0]." hours.</p>\n";
 
-       echo "  <div class=\"re\">\n   Points Re: <br />\n";
+       echo "      <div class=\"re\">\n   Points Re: <br />\n";
        $queryresult = DB_query("SELECT score FROM Score ".
                                "  WHERE game_id=$gameid AND party='re'".
                                " ");
        while($r = DB_fetch_array($queryresult) )
-         echo "   ".$r[0]."<br />\n";
-       echo "  </div>\n";
+         echo "       ".$r[0]."<br />\n";
+       echo "      </div>\n";
 
-       echo "  <div class=\"contra\">\n   Points Contra: <br />\n";
+       echo "      <div class=\"contra\">\n   Points Contra: <br />\n";
        $queryresult = DB_query("SELECT score FROM Score ".
                                "  WHERE game_id=$gameid AND party='contra'".
                                " ");
        while($r = DB_fetch_array($queryresult) )
-         echo "   ".$r[0]."<br />\n";
-       echo "  </div>\n";
+         echo "       ".$r[0]."<br />\n";
+       echo "      </div>\n";
 
-       echo "</div>\n";
+       echo "    </div>\n";
 
-       echo "    </div>\n  </li>\n";  /* end div trick, end li trick */
+       echo "    </div>\n";  /* end div trick, end li trick */
       }
 
-    echo "  <li onclick=\"hl_prev();\" class=\"old\"><a href=\"#\">"._('prev')."</a></li>\n";
-    echo "  <li onclick=\"hl_next();\" class=\"old\"><a href=\"#\">"._('next')."</a></li>\n";
-    echo "</ul>\n"; /* end ul tricks*/
+    echo "</div>\n"; /* end ul tricks*/
 
     if($myturn && !myisset('card') && $mystatus=='play' )
       {
@@ -1987,6 +2101,9 @@ switch($mystatus)
     myerror("error in testing the status");
   } /*end of output: tricks, table, messages, card */
 
+/* display the 2nd half of table and the names */
+display_table_end();
+
 /**************
  * show cards *
  **************/
@@ -2129,6 +2246,18 @@ if( sizeof($messages) )
     echo "</div>\n\n";
   }
 
+/****************************
+ * commit commentCall to DB *
+ ****************************/
+
+if($commentCall != '')
+  {
+    /* treat before game calls special, so that we can show them on the first trick and not the pre-phase */
+    if($playid == -1)
+      $playid = -2;
+
+    DB_insert_comment($commentCall,$playid,$gameid,$myid);
+  }
 /***********************************************
  * Comments, re/contra calls, user menu
  ***********************************************/
@@ -2144,7 +2273,7 @@ $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
 $gameend = time() - strtotime($r[0]);
 
 /* comment box */
-if($gamestatus == 'play' || $gameend < 60*60*24*7)
+if($gamestatus == 'play' || $gamestatus == 'pre' || $gameend < 60*60*24*7)
   {
     echo '  '._('A short comment').":<input name=\"comment\" type=\"text\" size=\"20\" maxlength=\"100\" />\n";
   }
@@ -2157,7 +2286,7 @@ if($gamestatus == 'play' )
   }
 
 /* play-card button */
-if($gamestatus == 'play' || $gameend < 60*60*24*7)
+if($gamestatus == 'play' || $gamestatus == 'pre' || $gameend < 60*60*24*7)
   {
     echo "  <input type=\"submit\" value=\""._('submit')."\" />\n";
   }