show cards every time, in case you are playing, make them links only if it is your...
[e-DoKo.git] / index.php
index ff9af4622b2ee35b4d88e2b61e4f7da68a516122..2eb0cf75f6b0cea529b7adcda9f30e54806a4ec7 100644 (file)
--- a/index.php
+++ b/index.php
@@ -4,18 +4,19 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>
      <title>e-Doko</title>
-     <link rel="stylesheet" type="text/css" href="standard.css"/>      
+     <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
+     <link rel="stylesheet" type="text/css" href="standard.css" />     
   </head>
 <body>
 <h1> Welcome to E-Doko </h1>
-
+<p>
 <?php
 /*
  * config 
  */
 
 $host  = "http://doko.nubati.net/index.php";
-$debug = 1;
+$debug = 0;
 
 /*
  * end config
@@ -208,10 +209,10 @@ function card_to_name($card)
       return "ace of hearts";
       case 45:
       case 46:
-      return "ace of diamonds";
+      return "king of hearts";
       case 47:
       case 48:
-      return "nine of diamonds";
+      return "nine of hearts";
       default:
       return "something went wrong, please contact the admin";
     }
@@ -296,17 +297,18 @@ function card_value($card)
 function display_card($card)
 {
   if( $card/2 - (int)($card/2) == 0.5)
-    echo "<img src=\"cards/".$card.".png\" height=\"100\">";
+    echo "<img src=\"cards/".$card.".png\" height=\"100\" alt=\"".card_to_name($card)."\" />";
   else
-    echo "<img src=\"cards/".($card-1).".png\" height=\"100\">";
+    echo "<img src=\"cards/".($card-1).".png\" height=\"100\" alt=\"".card_to_name($card-1)."\" />";
   return;
 }
-   function display_link_card($card,$me)
+
+function display_link_card($card,$me)
 {
   if( $card/2 - (int)($card/2) == 0.5)
-    echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".$card.".png\" height=\"100\"></a>";
+    echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".$card.".png\" height=\"100\" alt=\"".card_to_name($card)."\" /></a>";
   else
-    echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".($card-1).".png\" height=\"100\"></a>";
+    echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".($card-1).".png\" height=\"100\" alt=\"".card_to_name($card-1)."\" /></a>";
   return;
 }
 
@@ -409,7 +411,9 @@ if( isset($_REQUEST["PlayerA"]) &&
     /* send out email, check for error with email */
 
     $message = "\n".
-      "you are invited to play a game of DoKo.\n".
+      "you are invited to play a game of DoKo (that is to debug the program ;).\n".
+      "Place comments and bug reports here:\n".
+      "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
       "The whole round would consist of the following players:\n".
       "$PlayerA\n".
       "$PlayerB\n".
@@ -472,16 +476,16 @@ if(sizeof($lines)<2)
     <p> no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct! </p>
  <form action="index.php" method="post">
    Name:  <input name="PlayerA" type="text" size="10" maxlength="20" /> 
-   Email: <input name="EmailA"  type="text" size="10" maxlength="20" /> <br />
+   Email: <input name="EmailA"  type="text" size="20" maxlength="30" /> <br />
 
    Name:  <input name="PlayerB" type="text" size="10" maxlength="20" /> 
-   Email: <input name="EmailB"  type="text" size="10" maxlength="20" /> <br />
+   Email: <input name="EmailB"  type="text" size="20" maxlength="30" /> <br />
 
    Name:  <input name="PlayerC" type="text" size="10" maxlength="20" /> 
-   Email: <input name="EmailC"  type="text" size="10" maxlength="20" /> <br />
+   Email: <input name="EmailC"  type="text" size="20" maxlength="30" /> <br />
 
    Name:  <input name="PlayerD" type="text" size="10" maxlength="20" /> 
-   Email: <input name="EmailD"  type="text" size="10" maxlength="20" /> <br />
+   Email: <input name="EmailD"  type="text" size="20" maxlength="30" /> <br />
 
    <input type="submit" value="start game" />
  </form>
@@ -553,8 +557,8 @@ if(sizeof($lines)<2)
                 for($i=0;$i<4;$i++)
                   {
                     $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
-                      "the game has been cancled due to the request of one of the players.\n";
-                    mymail($player[$hash[$i]]["email"],"[DoKo] the game has been cancled",$message); 
+                      "the game has been canceled due to the request of one of the players.\n";
+                    mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message); 
                   }
                   $output = fopen("status.txt","w");
                   if($output)
@@ -700,7 +704,7 @@ if(sizeof($lines)<2)
             
             $message = "you're in. once everyone has filled out the form,".
               "the game will start and you'll get an eamil on your turn\n";
-            mymail($player[$c]["email"],"[DoKo] the game will start soon",$message); 
+            mymail($player[$c]["email"],"[DoKo-debug] the game will start soon",$message); 
 
             $player[$c]["option"].="s";
             save_status();
@@ -711,10 +715,10 @@ if(sizeof($lines)<2)
             parse_status();
 
             if($game["init"]==4)
-3             {
+              {
                 $message = "The game can start now, it's your turn, please use this link to play a card:\n".
                   $host."?me=".$hash[$game["startplayer"]]."\n";
-                mymail($player[$hash[$game["startplayer"]]]["email"],"[DoKo] let's go",$message);
+                mymail($player[$hash[$game["startplayer"]]]["email"],"[DoKo-debug] let's go",$message);
               }
             
           }
@@ -722,13 +726,13 @@ if(sizeof($lines)<2)
      if($game["init"]==4)
        {
         /* check for sickness*/
-        /***** someone has 5 nines and no one is playing solo=> cancel game */
+        /***** someone has 5 nines and no one is playing solo=> cance5Al game */
         if($game["nines"]>=0 && $game["solo-who"]<0)
           {
             $message = $player[$hash[$game["poverty"]]]["nines"]." has more than 4 nines. Game aborted!\n";
             for($i=0;$i<4;$i++)
               {
-                mymail($player[$hash[$i]]["email"],"[DoKo] the game has been canceled",$message); 
+                mymail($player[$hash[$i]]["email"],"[DoKo-debug] the game has been canceled",$message); 
               }
             $output = fopen("status.txt","w");
             if($output)
@@ -739,21 +743,53 @@ if(sizeof($lines)<2)
 
         /* who is requesting this*/
         if(!isset($_REQUEST["me"]))
-          echo "a game is in progress, but you are not playing";
+          {    
+            if(!isset($_REQUEST["recovery"]))
+              {
+                echo "a game is in progress, but you are not playing.<br />";
+                echo "In case you are playing, but lost your email or can't access the game anymore, please input your email here:<br />";
+                ?>
+ <form action="index.php" method="post">
+   recorvery: <input name="recovery"  type="text" size="20" maxlength="30" /> <br />
+   <input type="submit" value="get me back into the game" />
+ </form>
+<?php
+               }
+            else
+              {
+                $recovery=$_REQUEST["recovery"];
+                $ok=-1;
+                for($i=0;$i<4;$i++)
+                  if(trim($recovery)==trim($player[$hash[$i]]["email"]))
+                    $ok=$i;
+                if($ok>=0)
+                  {
+                    $message = "Please try this link: ".$host."?me=".$hash[$ok]."\n".
+                      "\n if this doesn't work, contact the admin.\n";
+                    mymail($recovery,"[DoKo-Debug] recovery ",$message);
+                    echo "email has been sent.";
+                  }
+                else
+                  {
+                    echo "can't find this email address, sorry.";
+                  }; 
+              } /* end recovery */
+          }
         else
-          {
+          { /* $me is set */ 
             $me = $_REQUEST["me"];
-
+            
             echo "game in progress and you are in it<br />";
             if($game["solo-who"]>=0)
               echo $player[$hash[$game["solo-who"]]]["name"]." is playing a ".$game["solo-what"]." solo!<br />";
             else if($game["wedding"]>=0)
               echo $player[$hash[$game["wedding"]]]["name"]." is playing a wedding!<br />";
             
+            /* show history */
             foreach($history as $play) 
               {
                 echo "<br />";
-
+                
                 $trick = explode(":",$play);
                 
                 $last=-2;
@@ -771,6 +807,7 @@ if(sizeof($lines)<2)
                   }
               }
             
+            /* figure out who needs to play next */
             $next = $last + 1;
             if ($next>=4) 
               $next -= 4 ;
@@ -778,20 +815,24 @@ if(sizeof($lines)<2)
               {
                 $next=$history[sizeof($history)-1][0];
               }
-
-
+            
+            /* are we trying to play a card? */
             if(isset($_REQUEST["card"]))
               {
                 if($hash[$next]==$me)
                   {
-                    $card=$_REQUEST["card"];
+                    $card    = $_REQUEST["card"];
                     $mycards = explode(";",$player[$me]["cards"]);
+                    
+                    /* do we have that card */
                     if(in_array($card,$mycards))
                       {
-                        $tmp=array();
+                        /* delete card from array */
+                        $tmp = array();
                         foreach($mycards as $m)
-                          if($m!=$card)
+                          if($m != $card)
                             $tmp[]=$m;
+                        
                         $tmp2="";
                         for($i=0;$i<sizeof($tmp)-1;$i++)
                           {
@@ -800,6 +841,7 @@ if(sizeof($lines)<2)
                         $tmp2.=$tmp[$i];
                         $player[$me]["cards"]=$tmp2;
                         
+                        /* add card to history, special case if this is the first card */
                         if($last<0)
                           {
                             $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n";
@@ -811,9 +853,10 @@ if(sizeof($lines)<2)
                             $history[sizeof($history)-1]=join(":",$tmp);
                           }
                         save_status();
-
+                        
                         echo " you played ";
                         display_card($card);
+                        
                         /* send out email to players who want/need to get informed */
                         for($i=0;$i<4;$i++)
                           {
@@ -821,25 +864,30 @@ if(sizeof($lines)<2)
                             if((ereg("c",$player[$hash[$i]]["option"]) || $i==$mynext) && $hash[$i]!=$me)
                               {
                                 $message = " Hello ".$player[$hash[$i]]["name"].",\n\n";
-                                  
+                                
                                 if($i==$mynext)
-                                  $message .= "it's your turn  now.\n";
+                                  {
+                                    $message .= "it's your turn  now.\n".
+                                      "Use this link to play a card: ".$host."?me=".$hash[$i]."\n\n" ;
+                                  }
                                 $message .= $player[$me]["name"]. "has played the following card ".card_to_name($card)."\n";
                                 
-                                if($game["solo-who"]<=0)
+                                if($game["solo-who"]>=0)
                                   $message.= $player[$hash[$game["solo-who"]]]." is playing a ".$game["solo-what"]." solo!\n";
-
-                                mymail($player[$hash[$i]]["email"],"[DoKo] a card has been played",$message);
-                                echo "<a href=\"index.php?me=".$hash[$mynext]."\"> next player </a> <br />";
+                                
+                                mymail($player[$hash[$i]]["email"],"[DoKo-debug] a card has been played",$message);
+                                
+                                if($debug)
+                                  echo "<a href=\"index.php?me=".$hash[$mynext]."\"> next player </a> <br />";
                               }
                           }
                       }
                     else
                       echo "seems like you don't have that card<br>";
-                         
+                    
                   }
                 
-              }
+              } /* end if card is set */
             else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
               {
                 $win=$_REQUEST["win"];
@@ -856,13 +904,14 @@ if(sizeof($lines)<2)
                   }
                 $player[$hash[$win]]["points"]+=$points;
                 echo "<br> ".$player[$hash[$win]]["name"]." won: $points Points <br>";
-
+                
                 save_status();
-              }
+              }; /* end if win is set */
             echo "<br />";
 
             $tmp = explode(":",$history[sizeof($history)-1]);
 
+            /* check last history entry: end of a trick? ask who won it */
             if(sizeof($tmp)==5)
               {
                 ?>
@@ -877,16 +926,16 @@ who won?
 
 </form>
 <?php
-              }
+               }
             else if(sizeof($tmp)<5 && 1<sizeof($tmp) && !isset($_REQUEST["card"]))
-              {                 
+              {                 
                 if(sizeof($tmp)==2 && strlen($tmp[0])==1)
                   {
                     $next=$tmp[0];
-
+                    
                     if($debug)
                       echo "DEBUG: the next move is for <a href=\"index.php?me=".$hash[$next]."\">the next player</a><br>";
-                     
+                    
                     if(strlen(trim($player[$me]["cards"]))==0)
                       {
                         echo "<br> game over, count points <br>";
@@ -896,23 +945,36 @@ who won?
                           }
                       }
                   }
-                if($hash[$next]==$me && strlen(trim($player[$me]["cards"]))>0 )
+                echo "<br />";
+              } /* end check for winner */
+            
+            /* do we still have cards? display them */
+            if(strlen(trim($player[$me]["cards"]))>0 )
+              {
+                $allcards = trim($player[$me]["cards"]);
+                $mycards = explode(";",$allcards);
+                
+                sort($mycards);
+                
+                /* is it our turn? */
+                if($hash[$next]==$me) 
                   {
-                    
-                    echo "ITS YOUR TURN<br>";
-                    $allcards = trim($player[$me]["cards"]);
-                    $mycards = explode(";",$allcards);
-                    
-                    sort($mycards);
-                    echo "your cards are <br>";
+                    echo "ITS YOUR TURN   <br />";
+                    echo "your cards are: <br />";
                     foreach($mycards as $card) 
                       {
                         display_link_card($card,$me);
                       }
-                    echo "<br />\n";   
                   }
-                echo "<br />";
-                
+                else 
+                  { /* not our turn, just show the hand */
+                    echo "your cards are: <br />";
+                    foreach($mycards as $card) 
+                      {
+                        display_card($card);
+                      }
+                  }
+                echo "<br />\n";   
               }
           }
        }
@@ -920,6 +982,6 @@ who won?
  } 
 
 ?>
-
+</p>
 </body>
 </html>