fixed & in html
[e-DoKo.git] / index.php
index eded836ac1c86f532853864c5cecc121c2269720..6d43ddb828f56e3485292d3089bfa4b2619a91fa 100644 (file)
--- a/index.php
+++ b/index.php
@@ -49,6 +49,7 @@ if(myisset("new"))
     if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
       {
        echo "couldn't find one of the names, please start a new game";
+       output_footer();
        exit();
       }
     
@@ -66,6 +67,7 @@ if(myisset("new"))
     if($ruleset <0) 
       {
        echo "Error defining ruleset: $ruleset";
+       output_footer();
        exit();
       };
     
@@ -157,6 +159,7 @@ else if(myisset("cancle","me"))
       {
        echo "Can't find you in the database, please check the url.<br />\n";
        echo "perhaps the game has been cancled, check by login in <a href=\"$host\">here</a>.";
+       output_footer();
        exit();
       }
     
@@ -203,6 +206,7 @@ else if(myisset("me"))
       {
        echo "Can't find you in the database, please check the url.<br />\n";
        echo "perhaps the game has been cancled, check by login in <a href=\"$host\">here</a>.";
+       output_footer();
        exit();
       }
     
@@ -229,6 +233,19 @@ else if(myisset("me"))
     echo "schweinchen: ".$r[3]."<br />";
     echo "</div>\n";
     
+    /* does anyone have both foxes */
+    $GAME["schweinchen"]=0; 
+    for($i=1;$i<5;$i++)
+      {
+       $hash  = DB_get_hash_from_game_and_pos($gameid,$i);
+       $cards = DB_get_all_hand($hash);
+       if( in_array("19",$cards) && in_array("20",$cards) )
+         {
+           $GAME["schweinchen"]=1;
+           $GAME["schweinchen-who"]=$hash;
+         }
+      };
+        
 
     /* mystatus gets the player through the different stages of a game.
      * start:    yes/no
@@ -400,6 +417,7 @@ else if(myisset("me"))
              
              /* delete everything from the dB */
              DB_cancel_game($me);
+             output_footer();
              exit();
            }
 
@@ -486,17 +504,16 @@ else if(myisset("me"))
                break;
              if($usersick == "solo" && $gametype =="solo")
                break;
-           };    
+                         
+           };
+
+         if( $gametype != "solo")
+           if($GAME["schweinchen"] && $RULES["schweinchen"]=="both" )
+             echo DB_get_name_by_hash($GAME["schweinchen-who"])." has Schweinchen. <br />";
+         
          echo "<br />\n";
          
-         /* check for Schweinchen (cards 21,22) */
-         if($RULES["schweinchen"]=="both")
-           {
-             set_gametype($gametype);
-             echo "TODO: check if one user has both foxes and output here ";
-           }    
-
-         /* finished the setup, go to next stage unless there is a case of poverty*/
+         /* finished the setup, set re/contra parties if possible, go to next stage unless there is a case of poverty*/
          switch($gametype)
            {
            case "solo":
@@ -509,7 +526,8 @@ else if(myisset("me"))
              DB_set_hand_status_by_hash($me,'play');
              break;
            case "wedding":
-             echo "Don't know who will be Re and Contra, you need to figure that out at the end of the game yourself <br />\n";
+             echo "Don't know who will be Re and Contra, you need to ".
+               "figure that out at the end of the game yourself <br />\n";
              DB_set_hand_status_by_hash($me,'play');
              break;
            case "normal":
@@ -522,8 +540,23 @@ else if(myisset("me"))
              DB_set_hand_status_by_hash($me,'play');
              break;
            case "poverty":
+             /* figure out who has poverty */
+             /* check who was asked already 
+              *   everyone or trump was taken? 
+              *      trump was taken, start game 
+              *      trump was not taken, cancle game
+              *
+              *   not everyone, figure out who is next in the list
+              *   is the next person this one?
+              *      no, display wait message, e.g. player X is asked at the moment
+              *      yes, display trump, ask if he wants to take it
+              *        no, set player asked to true, email next player
+              *        yes, display all cards, ask for N return cards
+              *          set re/contra 
+              *        
+              */
            case "dpoverty":
-             echo "TODO: handle poverty here";
+             echo "TODO: handle double poverty here";
              DB_set_hand_status_by_hash($me,'play');
            };
        }
@@ -567,7 +600,7 @@ else if(myisset("me"))
       else
        $gametype="normal";
       
-      set_gametype($gametype);
+      set_gametype($gametype); /* this sets the $CARDS variable */
       
       /* get some infos about the game */
       $gamestatus = DB_get_game_status_by_gameid($gameid);
@@ -660,6 +693,10 @@ else if(myisset("me"))
          $trick   = $r[3];
          $comment = $r[4];
          
+         /* check if first schweinchen has been played */
+         if($r[0] == 19 || $r[0] == 20 )
+           $GAME["schweinchen"]++;
+         
          /* save card to be able to find the winner of the trick later */
          $play[$seq] = array("card"=>$r[0],"pos"=>$pos); 
          
@@ -744,10 +781,24 @@ else if(myisset("me"))
          
          if($handcardid)
            {
+             $comment = "";
+
              /* mark card as played */
              mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
                          DB_quote_smart($card));
              
+             /* check for schweinchen */
+             echo "schweinchen = ".$GAME["schweinchen"]." --$card-<br />";
+             if($card == 19 || $card == 20 )
+               {
+                 $GAME["schweinchen"]++;
+                 if($GAME["schweinchen"]==3 && $RULES["schweinchen"]=="second" )
+                   $comment="Schweinchen! ";
+                 if($RULES["schweinchen"]=="both" )
+                   $comment="Schweinchen! ";
+                 echo "schweinchen = ".$GAME["schweinchen"]." ---<br />";
+               }
+
              /* get trick id or start new trick */
              $a = DB_get_current_trickid($gameid);
              $trickid  = $a[0];
@@ -758,9 +809,11 @@ else if(myisset("me"))
              /* check for coment */
              if(myisset("comment"))
                {
-                 DB_insert_comment($_REQUEST["comment"],$playid,$myid);
+                 $comment.=$_REQUEST["comment"];
                };  
-             
+             if($comment != "")
+               DB_insert_comment($comment,$playid,$myid);
+
              /* display played card */
              echo "<div class=\"card\">";
              echo " you played  <br />";
@@ -981,6 +1034,7 @@ else if(myisset("me"))
     default:
       echo "error in testing the status";
     }
+    output_footer();
   exit();
  } 
 /* user status page */ 
@@ -1020,7 +1074,7 @@ else if(myisset("me"))
             echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a>";
             if(time()-strtotime($r[2]) > 60*60*24*30)
               echo " The game has been running for over a month.".
-                " Do you want to cancel it? <a href=\"$host?cancle=1&me=".$r[0]."\">yes</a>".
+                " Do you want to cancel it? <a href=\"$host?cancle=1&amp;me=".$r[0]."\">yes</a>".
                 " (clicking here is final and can't be restored)";
             echo "<br />";
           }
@@ -1045,6 +1099,7 @@ else if(myisset("me"))
        {
         echo "sorry email and password don't match <br />";
        }
+     output_footer();
      exit();
    }
 /* page for registration */