BUGFIX: forgot to close a <li> and a <div> on the first trick played
[e-DoKo.git] / include / game.php
index b4ed57dc29a1184ee1c882c81e2c865d3aab5028..ceed8bbba49d25191fe4cf940d9358b8d7d95c3e 100644 (file)
@@ -105,7 +105,7 @@ if($ok)
 set_gametype('normal');
 
 /* put everyting in a form */
-echo "<form action=\"index.php?action=game&me=$me\" method=\"post\">\n";
+echo "<form action=\"index.php?action=game&amp;me=$me\" method=\"post\">\n";
 
 /* output game */
 
@@ -121,7 +121,7 @@ if($session)
        if($hash == $me)
          echo "$i \n";
        else
-         echo "<a href=\"".$INDEX."?action=game&me=".$hash."\">$i</a> \n";
+         echo "<a href=\"".$INDEX."?action=game&amp;me=".$hash."\">$i</a> \n";
        $i++;
       }
     echo "</div>\n";
@@ -142,7 +142,11 @@ display_table();
 switch($mystatus)
   {
   case 'start':
-    if( !myisset("in") )
+    /* don't ask if user has autosetup set to yest */
+    $skip = 0;
+    if($PREF['autosetup']=='yes') $skip = 1;
+
+    if( !myisset("in") && !$skip)
       {
        /* asks the player, if he wants to join the game */
        output_check_want_to_play($me);
@@ -151,7 +155,7 @@ switch($mystatus)
     else
       {
        /* check the result, if player wants to join, got next stage, else cancel game */
-       if($_REQUEST["in"] == "no")
+       if($_REQUEST["in"] == "no" && !$skip)
          {
            /* cancel the game */
            $message = "Hello, \n\n".
@@ -268,7 +272,7 @@ switch($mystatus)
        if($Nsickness>1)
          {
            echo "<p class=\"message\"> You selected more than one sickness, please go back ".
-             "and answer the <a href=\"$INDEX?action=game&me=$me&in=yes\">question</a> again.</p>";
+             "and answer the <a href=\"$INDEX?action=game&amp;me=$me&amp;in=yes\">question</a> again.</p>";
 
            echo "<div class=\"mycards\">Your cards are: <br />\n";
            foreach($mycards as $card)
@@ -601,12 +605,12 @@ switch($mystatus)
                  {
                    /* email startplayer */
                    $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
-                     "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
+                     "Use this link to play a card: ".$HOST.$INDEX."?action=game&amp;me=".$hash."\n\n" ;
                    mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
                  }
              }
            else
-             echo " Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br />\n";
+             echo " Please, <a href=\"$INDEX?action=game&amp;me=$me\">start</a> the game.<br />\n";
          }
        else
          {
@@ -616,7 +620,7 @@ switch($mystatus)
 
            $whoid = DB_get_userid('gameid-position',$gameid,$who);
            if($whoid==$myid)
-             echo " Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br />\n";
+             echo " Please, <a href=\"$INDEX?action=game&amp;me=$me\">start</a> the game.<br />\n";
            else
              {
                $email   = DB_get_email('position-gameid',$who,$gameid);
@@ -627,7 +631,7 @@ switch($mystatus)
                  {
                    /* email player for poverty */
                    $message = "Poverty: It's your turn now in game ".DB_format_gameid($gameid).".\n".
-                     "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$whohash."\n\n" ;
+                     "Use this link to play a card: ".$HOST.$INDEX."?action=game&amp;me=".$whohash."\n\n" ;
                    mymail($email,$EmailName."Poverty (game ".DB_format_gameid($gameid).") ",$message);
                  }
              }
@@ -642,6 +646,7 @@ switch($mystatus)
      *            poverty: set re/contra
      *            dpoverty: first time: set re, send email to second player
      *                      second time: set contra
+     *            poverty: set status of other players to 'play'
      *            set status to play in case 0 trump
      *      no -> set status to play,
      *            ask next player or cancle the game if no more players
@@ -673,6 +678,7 @@ switch($mystatus)
                               " WHERE hand_id='$myhand' AND card_id=".DB_quote_smart($exchange));
          };
       }
+
     /* update hand */
     $mycards = DB_get_hand($me);
     $mycards = mysort($mycards,$gametype);
@@ -693,7 +699,26 @@ switch($mystatus)
       {
        /* user is done, ready to play */
        DB_set_hand_status_by_hash($me,'play');
-       /* TODO if resolved; email start player, set startplayer */
+
+       /* email start player */
+       $startplayer = DB_get_startplayer_by_gameid($gameid);
+       $email       = DB_get_email('position-gameid',$startplayer,$gameid);
+       $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
+       $who         = DB_get_userid('email',$email);
+       DB_set_player_by_gameid($gameid,$who);
+
+       if($hash!=$me)
+         {
+           if(DB_get_email_pref_by_hash($hash)!="emailaddict")
+             {
+               /* email startplayer */
+               $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
+                 "Use this link to play a card: ".$HOST.$INDEX."?action=game&amp;me=".$hash."\n\n" ;
+               mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
+             }
+         }
+       else
+         echo " Please, <a href=\"$INDEX?action=game&amp;me=$me\">start</a> the game.<br />\n";
       }
 
     /* the following is part A) of what needs to be done */
@@ -719,10 +744,10 @@ switch($mystatus)
                    foreach($cards as $card)
                      if($card<27) $nrtrump++;
                    echo "Player $name has $nrtrump trump. Do you want to take them?".
-                     "<a href=\"index.php?action=game&me=$me&amp;trump=$user\">yes</a> <br />\n";
+                     "<a href=\"index.php?action=game&amp;me=$me&amp;trump=$user\">Yes</a> <br />\n";
                  }
              }
-           echo "<a href=\"index.php?action=game&me=$me&amp;trump=no\">No,way I take those trump...</a> <br />\n";
+           echo "<a href=\"index.php?action=game&amp;me=$me&amp;trump=no\">No way</a> <br />\n";
            echo "</div><div>\n";
 
            echo "<div class=\"mycards\">Your cards are: <br />\n";
@@ -791,7 +816,7 @@ switch($mystatus)
                DB_set_hand_status_by_hash($userhash,'poverty');
 
                $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
-                 " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
+                 " ".$HOST.$INDEX."?action=game&amp;me=".$userhash."\n\n" ;
                mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message);
              }
          }
@@ -807,6 +832,7 @@ switch($mystatus)
            /* copy trump from player A to B */
            $result = DB_query("UPDATE Hand_Card SET hand_id='$myhand' WHERE hand_id='$userhand' AND card_id<'27'" );
 
+           /* reload cards */
            $mycards = DB_get_hand($me);
 
            /* set re/contra */
@@ -817,18 +843,19 @@ switch($mystatus)
                  {
                    $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
                    if($hash==$userhash||$hash==$me)
-                     DB_set_party_by_hash($hash,"re");
+                     {
+                       DB_set_party_by_hash($hash,"re");
+                     }
                    else
-                     DB_set_party_by_hash($hash,"contra");
+                     {
+                       DB_set_party_by_hash($hash,"contra");
+                       DB_set_hand_status_by_hash($hash,'play'); /* the contra party is ready to play */
+                     }
                  }
-               /* check if we are done, if so, send everyone into the 'play' phase */
+               /* check if we are done (in case of no trump handed over), if so, go to 'play' phase right away*/
                if(count($mycards)==12)
                  {
-                   foreach($userids as $user)
-                     {
-                       $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
-                       DB_set_hand_status_by_hash($hash,'play');
-                     }
+                   DB_set_hand_status_by_hash($me,'play');
                  }
              }
            else /*dpoverty*/
@@ -875,13 +902,13 @@ switch($mystatus)
                    DB_set_hand_status_by_hash($userhash,'poverty');
 
                    $message = "Two people have poverty, it's your turn to decide, if you want to take the trump. Please visit:".
-                     " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
+                     " ".$HOST.$INDEX."?action=game&amp;me=".$userhash."\n\n" ;
                    mymail($To,$EmailName." double poverty (game ".DB_format_gameid($gameid).")",$message);
 
 
                  }
              }
-           echo "<div class=\"message\"> Please, <a href=\"$INDEX?action=game&me=$me\">continue</a> here.</div>\n";
+           echo "<div class=\"message\"> Please, <a href=\"$INDEX?action=game&amp;me=$me\">continue</a> here.</div>\n";
          }
       }
     echo "</div>";
@@ -928,7 +955,7 @@ switch($mystatus)
              {
                /* email startplayer) */
                $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
-                 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
+                 "Use this link to play a card: ".$HOST.$INDEX."?action=game&amp;me=".$hash."\n\n" ;
                mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
              }
          }
@@ -1392,7 +1419,7 @@ switch($mystatus)
 
                $message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
                  "It's your turn  now.\n".
-                 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$next_hash."\n\n" ;
+                 "Use this link to play a card: ".$HOST.$INDEX."?action=game&amp;me=".$next_hash."\n\n" ;
                if( DB_get_email_pref_by_uid($who)!="emailaddict" )
                  mymail($email,$EmailName."a card has been played in game ".DB_format_gameid($gameid),$message);
              }
@@ -1665,7 +1692,7 @@ switch($mystatus)
                      $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
 
                      $link = "Use this link to have a look at game ".DB_format_gameid($gameid).": ".
-                       $HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
+                       $HOST.$INDEX."?action=game&amp;me=".$hash."\n\n" ;
                      if( DB_get_email_pref_by_uid($user) != "emailaddict" )
                        mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link);
                    }
@@ -1681,7 +1708,7 @@ switch($mystatus)
          echo "please wait until it's your turn! <br />\n";
        }
 
-      if($seq!=4 && $trickNR>1)
+      if($seq!=4 && $trickNR>=1)
        echo "    </div>\n  </li>\n";  /* end div trick, end li trick */
 
       /* display points in case game is over */
@@ -1708,13 +1735,13 @@ switch($mystatus)
          echo "    </div>\n  </li>\n";  /* end div trick, end li trick */
        }
 
-
-      echo "</ul>\n"; /* end ul tricks*/
+      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</ul>\n"; /* end ul tricks*/
 
       echo "<div class=\"notes\"> Personal notes: <br />\n";
       $notes = DB_get_notes_by_userid_and_gameid($myid,$gameid);
       foreach($notes as $note)
-       echo "$note <hr \>\n";
+       echo "$note <hr />\n";
       echo "Insert note:<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
       echo "</div> \n";