fix error when language is not set
[e-DoKo.git] / include / game.php
index a50b247d0adc76e90fdc0b363940950f5393b2a0..1dbd1e95d0e2afc58b55a5830f6896331bdb78cb 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Arun Persaud <arun@nubati.net>
+/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Arun Persaud <arun@nubati.net>
  *
  *   This file is part of e-DoKo.
  *
@@ -46,6 +46,7 @@ global $GAME,$RULES,$CARDS;
 /**************************************
  * get some information from the DB
  **************************************/
+start:
 $gameid   = DB_get_gameid_by_hash($me);
 $myname   = DB_get_name('hash',$me);
 $mystatus = DB_get_status_by_hash($me);
@@ -333,7 +334,7 @@ if($session)
     echo '    '._('Game')." $session.$j";
     if($gamestatus != 'pre')
       if($gametype_raw != 'normal') /* only show when needed */
-       if(!($gametype_raw == 'solo' && $gametyep_solo == 'silent') )
+       if(!($gametype_raw == 'solo' && $gametype_solo == 'silent') )
          echo " ($GT)";
 
     if(isset($_SESSION['id']) && $_SESSION['id']==$myid)
@@ -395,7 +396,7 @@ switch($mystatus)
 
     /* output vorbehalte */
     if($gametype_raw != 'normal') /* only show when needed */
-      if(!($gametype_raw == 'solo' && $gametyep_solo == 'silent') )
+      if(!($gametype_raw == 'solo' && $gametype_solo == 'silent') )
        echo "  <li onclick=\"hl(0);\" class=\"old\"><a href=\"#\">Pre</a></li>\n";
 
     $result = DB_query('SELECT Trick.id'.
@@ -517,6 +518,7 @@ switch($mystatus)
             */
 
            DB_set_hand_status_by_hash($me,'init');
+           $mystatus='init';
 
            /* check if everyone has reached this stage, set player in game-table to the next player */
            $userids = DB_get_all_userid_by_gameid($gameid);
@@ -561,9 +563,7 @@ switch($mystatus)
            break;
          }
        else
-         {
-           /* everything is ok, save what user said and proceed */
-           $messages[] = _('Processing what you selected in the last step...');
+         { /* everything is ok, save what user said and proceed */
 
            /* check if this sickness needs to be handled first */
            $startplayer = DB_get_startplayer_by_gameid($gameid); /* need this to check which solo goes first */
@@ -572,6 +572,17 @@ switch($mystatus)
              {
                /* user wants to play a solo */
 
+               /* double check input value */
+               $s = $_REQUEST['solo'];
+               $solos = array('trumpless','jack','queen','trump','club','spade','heart');
+               if (!in_array($s, $solos))
+                 {
+                   $messages[] = sprintf(_('There is a problem with the type of solo you selected (%s does not exist), please go back '.
+                                           'and answer the <a href="%s">question</a> again.'),
+                                         $s,$INDEX.'?action=game&amp;me=$me&amp;in=yes');
+                   break;
+                 }
+
                /* store the info in the user's hand info */
                DB_set_solo_by_hash($me,$_REQUEST['solo']);
                DB_set_sickness_by_hash($me,'solo');
@@ -634,13 +645,6 @@ switch($mystatus)
      * this can therefore only be handled once all players finished the last stage
      */
 
-    $messages[] = _('Checking if someone else selected solo, nines, wedding or poverty.');
-
-    /* in case the user can go do the next stage, we want to skip the break statement at the
-     * end. We keep track of these cases using this variable
-     */
-    $nobreak=0;
-
     /* check if everyone has reached this stage */
     $userids = DB_get_all_userid_by_gameid($gameid);
     $ok = 1;
@@ -668,8 +672,6 @@ switch($mystatus)
         * are playing, in case there are any solos this already
         * will have the correct information in it */
 
-       $messages[] = _('Ok, everyone is done... figuring out what kind of game we are playing.');
-
        /* gametype for displaying it (hides hidden solo)*/
        $GT          = get_display_gametype($gameid);
 
@@ -796,7 +798,6 @@ switch($mystatus)
            $gametype     = 'wedding';
          };
        /* now the gametype is set correctly in the database */
-       $messages[] = _('Got it').' :)';
 
        /* loop over all players, set re/contra if possible and start the game if possible */
        $userids = DB_get_all_userid_by_gameid($gameid);
@@ -895,9 +896,8 @@ switch($mystatus)
              }
            else
              {
-               $messages[] = sprintf(_('Please, <a href="%s">start</a> the game.'),$INDEX."?action=game&amp;me=$me").
-                 "<br />\n";
-               $nobreak=1;
+               $mystatus = 'play';
+               goto play;
              }
          }
        else
@@ -909,9 +909,8 @@ switch($mystatus)
            $whoid = DB_get_userid('gameid-position',$gameid,$who);
            if($whoid==$myid)
              {
-               $messages[] = sprintf(_('Please, <a href="%s">start</a> the game.'),$INDEX."?action=game&amp;me=$me").
-                 "<br /\n";
-               $nobreak=1;
+               $mystatus = 'poverty';
+               goto poverty;
              }
            else
              {
@@ -930,10 +929,10 @@ switch($mystatus)
              }
          }
       }
-    if(!$nobreak)
-      break;
+    break;
 
   case 'poverty':
+  poverty:
     /* user only gets here in a poverty game, several things have to be handled here:
      * A) ask, if user wants to take trump
      *      yes-> take trump,
@@ -950,11 +949,6 @@ switch($mystatus)
      * it is easier to check B) first
      */
 
-    /* in case the user can go do the next stage, we want to skip the break statement at the
-     * end. We keep track of these cases using this variable
-     */
-    $nobreak=0;
-
     set_gametype($gametype); /* this sets the $CARDS variable */
     $myparty = DB_get_party_by_hash($me);
 
@@ -1008,7 +1002,10 @@ switch($mystatus)
              }
          }
        else
-         $messages[]= sprintf(_('Please, <a href="%s">start</a> the game.'),$INDEX."?action=game&amp;me=$me");
+         {
+           $mystatus = 'play';
+           goto play;
+         }
       }
 
     /* the following is part A) of what needs to be done */
@@ -1207,14 +1204,13 @@ switch($mystatus)
                  }
              }
            $messages[] = sprintf(_('Please, <a href="%s">continue</a> here'),$INDEX."?action=game&amp;me=$me");
-           $nobreak = 1;
          }
       }
-    if(!$nobreak)
-      break;
+    break;
 
   case 'play':
   case 'gameover':
+  play:
     /* both entries here,  so that the tricks are visible for both.
      * in case of 'play' there is a break later that skips the last part
      */
@@ -1581,7 +1577,7 @@ switch($mystatus)
 
                            if($party1 != $party2)
                              DB_query("INSERT INTO Score".
-                                      " VALUES( NULL,NULL,$gameid,'$party1',$uid1,$uid2,'fox')");
+                                      " VALUES(NULL,CURRENT_TIMESTAMP,$gameid,'$party1',$uid1,$uid2,'fox')");
                          }
                    }
 
@@ -1606,7 +1602,7 @@ switch($mystatus)
                                $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
 
                                DB_query("INSERT INTO Score".
-                                        " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')");
+                                        " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'$party1',$uid1,NULL,'karlchen')");
                              };
                      };
                  }; /* end scoring Karlchen */
@@ -1626,7 +1622,7 @@ switch($mystatus)
                    $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
 
                    DB_query("INSERT INTO Score".
-                            " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'doko')");
+                            " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'$party1',$uid1,NULL,'doko')");
                  }
 
                /*
@@ -1839,14 +1835,14 @@ switch($mystatus)
                    for( $p=$call_contra;$p<=120; $p+=30 )
                      {
                          DB_query('INSERT INTO Score'.
-                                  " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'against$p')");
+                                  " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'re',NULL,NULL,'against$p')");
                        }
 
                      for( $p=$call_contra; $p<120; $p+=30)
                        {
                          if( $re >= $p )
                            DB_query('INSERT INTO Score'.
-                                    " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'made$p')");
+                                    " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'re',NULL,NULL,'made$p')");
                        }
                    }
                  if($winning_party!='re' and $call_re!= -1)
@@ -1854,14 +1850,14 @@ switch($mystatus)
                      for( $p=$call_re;$p<=120; $p+=30 )
                        {
                          DB_query('INSERT INTO Score'.
-                                  " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'against$p')");
+                                  " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'contra',NULL,NULL,'against$p')");
                        }
 
                      for( $p=$call_re; $p<120; $p+=30)
                        {
                          if( $contra>=$p )
                            DB_query('INSERT INTO Score'.
-                                    " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'made$p')");
+                                    " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'contra',NULL,NULL,'made$p')");
                        }
                    }
 
@@ -1869,7 +1865,7 @@ switch($mystatus)
                  if($winning_party=='contra')
                    {
                      DB_query('INSERT INTO Score'.
-                              " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'againstqueens')");
+                              " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'contra',NULL,NULL,'againstqueens')");
                    }
 
                  /* one point each for winning and each 30 points + calls */
@@ -1883,14 +1879,14 @@ switch($mystatus)
 
                          if($re>$p-$offset)
                            DB_query('INSERT INTO Score'.
-                                    " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'".(240-$p)."')");
+                                    " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'re',NULL,NULL,'".(240-$p)."')");
                        }
                      /* re called something and won */
                      foreach(array(0,30,60,90,120) as $p)
                        {
                          if($call_re!= -1 && $call_re<$p+1)
                            DB_query('INSERT INTO Score'.
-                                    " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'call$p')");
+                                    " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'re',NULL,NULL,'call$p')");
                        }
                    }
                  else if( $winning_party=='contra')
@@ -1903,14 +1899,14 @@ switch($mystatus)
 
                          if($contra>$p-$offset)
                            DB_query('INSERT INTO Score'.
-                                    " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'".(240-$p)."')");
+                                    " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'contra',NULL,NULL,'".(240-$p)."')");
                        }
                      /* re called something and won */
                      foreach(array(0,30,60,90,120) as $p)
                        {
                          if($call_contra != -1 && $call_contra<$p+1)
                            DB_query('INSERT INTO Score'.
-                                    " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'call$p')");
+                                    " VALUES( NULL,CURRENT_TIMESTAMP,$gameid,'contra',NULL,NULL,'call$p')");
                        }
                    };
 
@@ -2094,17 +2090,21 @@ switch($mystatus)
  * this outputs status of healthy, *
  * sick, etc during pre-game phase *
  **********************************/
+
+$posmax=5; // if user is still in init, we only show vorbehalte from players before him, otherwise all of them
+
 switch($mystatus)
   {
   case 'start':
     break;
   case 'init':
+    $posmax=$mypos;
   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++)
+    for($pos=1;$pos<$posmax;$pos++)
       {
        $usersick   = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
        $userid     = DB_get_userid('gameid-position',$gameid,$pos);