NEW FEATURE: detailed few of the score of one game
[e-DoKo.git] / index.php
index aec7c7d1ef7f27808183fab71876b442a927bf79..312dc9239e96516dc143ce064ca0c37e89c4ceb1 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,45 +1,50 @@
 <?php
 error_reporting(E_ALL);
 
 <?php
 error_reporting(E_ALL);
 
-include_once("config.php");      
+include_once("config.php");
 include_once("output.php");      /* html output only */
 include_once("db.php");          /* database only */
 include_once("functions.php");   /* the rest */
 
 include_once("output.php");      /* html output only */
 include_once("db.php");          /* database only */
 include_once("functions.php");   /* the rest */
 
-/* check if some variables are set in the config file, else set defaults */
-if(!isset($EmailName))
-     $EmailName="[DoKo] ";
-
-/* in case work has to be done on the database or other section we can
- * shut down the server and tell people to come back later 
- */
-if(0) 
-  {
-    output_header();
-    echo "Working on the database...please check back in a few mintues"; 
-    output_footer(); 
-    exit(); 
-  }
+config_check();
 
 if(DB_open()<0)
   {
     output_header();
 
 if(DB_open()<0)
   {
     output_header();
-    echo "Database error, can't connect...";
-    output_footer(); 
-    exit(); 
+    echo "Database error, can't connect... Please wait a while and try again. ".
+      "If the problem doesn't go away feel free to contact $ADMIN_NAME at $ADMIN_EMAIL.";
+    output_footer();
+    exit();
   }
 
   }
 
+/* start a session, if it is not already running */
+session_start();
+
 /* done major error checking, output header of HTML page */
 output_header();
 
 /* check if we want to start a new game */
 /* done major error checking, output header of HTML page */
 output_header();
 
 /* check if we want to start a new game */
-if(myisset("new"))
+if(myisset("logout"))
   {
   {
-    $names = DB_get_all_names();
-    output_form_for_new_game($names);
+    session_unset();
+    session_destroy();
+    $_SESSION = array();
+    echo "you are now logged out!";
+  }
+else if(myisset("new"))
+  {
+    if( isset($_SESSION["name"]) )
+      {
+       $names = DB_get_all_names();
+       output_form_for_new_game($names);
+      }
+    else
+      {
+       echo "Please log in.";
+      }
   }
 /*check if everything is ready to set up a new game */
   }
 /*check if everything is ready to set up a new game */
- else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" ))
+ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","call" ))
   {
     $PlayerA = $_REQUEST["PlayerA"];
     $PlayerB = $_REQUEST["PlayerB"];
   {
     $PlayerA = $_REQUEST["PlayerA"];
     $PlayerB = $_REQUEST["PlayerB"];
@@ -48,12 +53,13 @@ if(myisset("new"))
 
     $dullen      = $_REQUEST["dullen"];
     $schweinchen = $_REQUEST["schweinchen"];
 
     $dullen      = $_REQUEST["dullen"];
     $schweinchen = $_REQUEST["schweinchen"];
-    
+    $call        = $_REQUEST["call"];
+
     $EmailA  = DB_get_email_by_name($PlayerA);
     $EmailB  = DB_get_email_by_name($PlayerB);
     $EmailC  = DB_get_email_by_name($PlayerC);
     $EmailD  = DB_get_email_by_name($PlayerD);
     $EmailA  = DB_get_email_by_name($PlayerA);
     $EmailB  = DB_get_email_by_name($PlayerB);
     $EmailC  = DB_get_email_by_name($PlayerC);
     $EmailD  = DB_get_email_by_name($PlayerD);
-    
+
     if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
       {
        echo "couldn't find one of the names, please start a new game";
     if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
       {
        echo "couldn't find one of the names, please start a new game";
@@ -61,36 +67,43 @@ if(myisset("new"))
        DB_close();
        exit();
       }
        DB_close();
        exit();
       }
-    
+
     $useridA  = DB_get_userid_by_name($PlayerA);
     $useridB  = DB_get_userid_by_name($PlayerB);
     $useridC  = DB_get_userid_by_name($PlayerC);
     $useridD  = DB_get_userid_by_name($PlayerD);
     $useridA  = DB_get_userid_by_name($PlayerA);
     $useridB  = DB_get_userid_by_name($PlayerB);
     $useridC  = DB_get_userid_by_name($PlayerC);
     $useridD  = DB_get_userid_by_name($PlayerD);
-    
+
     /* create random numbers */
     $randomNR       = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD);
     $randomNRstring = join(":",$randomNR);
     /* create random numbers */
     $randomNR       = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD);
     $randomNRstring = join(":",$randomNR);
-    
-    /* get ruleset information or create new one */
-    $ruleset = DB_get_ruleset($dullen,$schweinchen);
-    if($ruleset <0) 
-      {
-       echo "Error defining ruleset: $ruleset";
-       output_footer();
-       DB_close();
-       exit();
-      };
-    
+
     /* create game */
     $followup = NULL;
     if(myisset("followup") )
       {
        $followup= $_REQUEST["followup"];
        $session = DB_get_session_by_gameid($followup);
     /* create game */
     $followup = NULL;
     if(myisset("followup") )
       {
        $followup= $_REQUEST["followup"];
        $session = DB_get_session_by_gameid($followup);
-       $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game, 
+       $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game,
                                                         this way no manipulation is possible */
                                                         this way no manipulation is possible */
+
+       /* check if there is a game in pre or play mode, in that case do nothing */
+       if( DB_is_session_active($session) > 0 )
+         {
+           echo "<p class=\"message\"> There is already a game going on in session $session, you can't start a new one</p>";
+           output_footer();
+           DB_close();
+           exit();
+         }
+       else if ( DB_is_session_active($session) < 0 )
+         {
+           echo "<p class=\"message\"> ERROR: status of session $session couldn't be determined.</p>";
+           output_footer();
+           DB_close();
+           exit();
+         }
+
        if($session)
        if($session)
-         mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1','1','pre',".
+         mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
                      "'$ruleset','$session' ,NULL)");
        else
          {
                      "'$ruleset','$session' ,NULL)");
        else
          {
@@ -98,36 +111,51 @@ if(myisset("new"))
            $max = DB_get_max_session();
            $max++;
            mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
            $max = DB_get_max_session();
            $max++;
            mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
-           mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1','1','pre',".
+           mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
                        "'$ruleset','$max' ,NULL)");
          }
       }
     else
                        "'$ruleset','$max' ,NULL)");
          }
       }
     else
-      mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1','1','pre', ".
-                 "'$ruleset',NULL ,NULL)");
+      {
+       /* get ruleset information or create new one */
+       $ruleset = DB_get_ruleset($dullen,$schweinchen,$call);
+       if($ruleset <0)
+         {
+           myerror("Error defining ruleset: $ruleset");
+           output_footer();
+           DB_close();
+           exit();
+         };
+       /* get max session */
+       $max = DB_get_max_session();
+       $max++;
+
+       mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre', ".
+                 "'$ruleset','$max' ,NULL)");
+      }
     $game_id = mysql_insert_id();
     $game_id = mysql_insert_id();
-    
+
     /* create hash */
     $TIME  = (string) time(); /* to avoid collisions */
     $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA.$TIME);
     $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB.$TIME);
     $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC.$TIME);
     $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD.$TIME);
     /* create hash */
     $TIME  = (string) time(); /* to avoid collisions */
     $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA.$TIME);
     $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB.$TIME);
     $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC.$TIME);
     $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD.$TIME);
-    
+
     /* create hands */
     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
                ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,NULL)");
     /* create hands */
     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
                ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,NULL)");
-    $hand_idA = mysql_insert_id();                                                            
+    $hand_idA = mysql_insert_id();
     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
                ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,NULL)");
     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
                ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,NULL)");
-    $hand_idB = mysql_insert_id();                                                            
+    $hand_idB = mysql_insert_id();
     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
                ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,NULL)");
     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
                ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,NULL)");
-    $hand_idC = mysql_insert_id();                                                            
+    $hand_idC = mysql_insert_id();
     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
                ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,NULL)");
     $hand_idD = mysql_insert_id();
     mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
                ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,NULL)");
     $hand_idD = mysql_insert_id();
-    
+
     /* save cards */
     for($i=0;$i<12;$i++)
       mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
     /* save cards */
     for($i=0;$i<12;$i++)
       mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
@@ -137,7 +165,7 @@ if(myisset("new"))
       mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
     for($i=36;$i<48;$i++)
       mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
       mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
     for($i=36;$i<48;$i++)
       mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
-    
+
     /* send out email, TODO: check for error with email */
     $message = "\n".
       "you are invited to play a game of DoKo (that is to debug the program ;).\n".
     /* send out email, TODO: check for error with email */
     $message = "\n".
       "you are invited to play a game of DoKo (that is to debug the program ;).\n".
@@ -150,19 +178,19 @@ if(myisset("new"))
       "$PlayerD\n\n".
       "If you want to join this game, please follow this link:\n\n".
       "".$host."?me=";
       "$PlayerD\n\n".
       "If you want to join this game, please follow this link:\n\n".
       "".$host."?me=";
-    
+
     mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
     mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
     mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
     mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
     mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
     mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
     mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
     mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
-    
-    echo "You started a new game. The emails have been sent out!";    
+
+    echo "You started a new game. The emails have been sent out!";
   }    /* end set up a new game */
 /* cancle a game, if nothing has happend in the last N minutes */
 else if(myisset("cancle","me"))
   {
     $me = $_REQUEST["me"];
   }    /* end set up a new game */
 /* cancle a game, if nothing has happend in the last N minutes */
 else if(myisset("cancle","me"))
   {
     $me = $_REQUEST["me"];
-    
+
     /* test for valid ID */
     $myid = DB_get_userid_by_hash($me);
     if(!$myid)
     /* test for valid ID */
     $myid = DB_get_userid_by_hash($me);
     if(!$myid)
@@ -173,42 +201,97 @@ else if(myisset("cancle","me"))
        DB_close();
        exit();
       }
        DB_close();
        exit();
       }
-    
+
     DB_update_user_timestamp($myid);
     DB_update_user_timestamp($myid);
-    
+
     /* get some information from the DB */
     $gameid   = DB_get_gameid_by_hash($me);
     $myname   = DB_get_name_by_hash($me);
     /* get some information from the DB */
     $gameid   = DB_get_gameid_by_hash($me);
     $myname   = DB_get_name_by_hash($me);
-    
+
     /* check if game really is old enough */
     $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " );
     $r = mysql_fetch_array($result,MYSQL_NUM);
     if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */
       {
        $message = "Hello, \n\n".
     /* check if game really is old enough */
     $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " );
     $r = mysql_fetch_array($result,MYSQL_NUM);
     if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */
       {
        $message = "Hello, \n\n".
-         "Game $gameid has been cancled since nothing happend for a while and $myname requested it.\n";
-       
+         "Game ".DB_format_gameid($gameid).
+         " has been cancled since nothing happend for a while and $myname requested it.\n";
+
        $userids = DB_get_all_userid_by_gameid($gameid);
        foreach($userids as $user)
          {
            $To = DB_get_email_by_userid($user);
        $userids = DB_get_all_userid_by_gameid($gameid);
        foreach($userids as $user)
          {
            $To = DB_get_email_by_userid($user);
-           mymail($To,$EmailName."game $gameid cancled (timed out)",$message);
+           mymail($To,$EmailName."game ".DB_format_gameid($gameid)." cancled (timed out)",$message);
          }
          }
-       
+
        /* delete everything from the dB */
        DB_cancel_game($me);
        /* delete everything from the dB */
        DB_cancel_game($me);
-       
-       echo "<p style=\"background-color:red\";>Game $gameid has been cancled.<br /><br /></p>";
+
+       echo "<p style=\"background-color:red\";>Game ".DB_format_gameid($gameid).
+         " has been cancled.<br /><br /></p>";
       }
     else
       echo "<p>You need to wait longer before you can cancle a game...</p>\n";
   }
       }
     else
       echo "<p>You need to wait longer before you can cancle a game...</p>\n";
   }
+/* send out a reminder */
+else if(myisset("remind","me"))
+  {
+    $me = $_REQUEST["me"];
+
+    /* test for valid ID */
+    $myid = DB_get_userid_by_hash($me);
+    if(!$myid)
+      {
+       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();
+       DB_close();
+       exit();
+      }
+
+    DB_update_user_timestamp($myid);
+
+    /* get some information from the DB */
+    $gameid   = DB_get_gameid_by_hash($me);
+    $myname   = DB_get_name_by_hash($me);
+
+    /* check if game really is old enough */
+    $result = mysql_query("SELECT mod_date,player,status from Game WHERE id='$gameid' " );
+    $r = mysql_fetch_array($result,MYSQL_NUM);
+    if( (time()-strtotime($r[0]) > 60*60*24*7)  && ($r[2]!='gameover') ) /* = 1 week */
+      {
+       $name = DB_get_name_by_userid($r[1]);
+       $To = DB_get_email_by_userid($r[1]);
+       $userhash = DB_get_hash_from_gameid_and_userid($gameid,$r[1]);
+
+       $message = "Hello $name, \n\n".
+         "It's your turn in game ".DB_format_gameid($gameid)." \n".
+         "Actually everyone else is waiting for you for more than a week now ;)\n\n".
+         "Please visit this link now to continue: \n".
+         " ".$host."?me=".$userhash."\n\n" ;
+
+       if(DB_get_reminder($r[1],$gameid)>0)
+         {
+           echo "<p>An email has already been sent out.</p>\n";
+         }
+       else
+         {
+           DB_set_reminder($r[1],$gameid);
+           mymail($To,$EmailName."Reminder: game ".DB_format_gameid($gameid)." it's your turn",$message);
+
+           echo "<p style=\"background-color:red\";>Game ".DB_format_gameid($gameid).
+             ": an email has been sent out.<br /><br /></p>";
+         }
+      }
+    else
+      echo "<p>You need to wait longer before you can send out a reminder...</p>\n";
+  }
 /* handle request from one specific player for one game,
  * (the hash is set on a per game base) */
 else if(myisset("me"))
   {
     $me = $_REQUEST["me"];
 /* handle request from one specific player for one game,
  * (the hash is set on a per game base) */
 else if(myisset("me"))
   {
     $me = $_REQUEST["me"];
-    
+
     /* test for valid ID */
     $myid = DB_get_userid_by_hash($me);
     if(!$myid)
     /* test for valid ID */
     $myid = DB_get_userid_by_hash($me);
     if(!$myid)
@@ -220,9 +303,12 @@ else if(myisset("me"))
        exit();
       }
 
        exit();
       }
 
+    if(isset($_SESSION["name"]))
+      output_status($_SESSION["name"]);
+
     /* the user had done something, update the timestamp */
     DB_update_user_timestamp($myid);
     /* the user had done something, update the timestamp */
     DB_update_user_timestamp($myid);
-    
+
     /* get some information from the DB */
     $gameid   = DB_get_gameid_by_hash($me);
     $myname   = DB_get_name_by_hash($me);
     /* get some information from the DB */
     $gameid   = DB_get_gameid_by_hash($me);
     $myname   = DB_get_name_by_hash($me);
@@ -234,8 +320,7 @@ else if(myisset("me"))
     /* get prefs and save them */
     DB_get_PREF($myid);
     /* end set pref */
     /* get prefs and save them */
     DB_get_PREF($myid);
     /* end set pref */
-      
-      
+
     /* get rule set for this game */
     $result = mysql_query("SELECT * FROM Rulesets".
                          " LEFT JOIN Game ON Game.ruleset=Rulesets.id ".
     /* get rule set for this game */
     $result = mysql_query("SELECT * FROM Rulesets".
                          " LEFT JOIN Game ON Game.ruleset=Rulesets.id ".
@@ -246,7 +331,6 @@ else if(myisset("me"))
     $RULES["schweinchen"] = $r[3];
     $RULES["call"]        = $r[4];
 
     $RULES["schweinchen"] = $r[3];
     $RULES["call"]        = $r[4];
 
-
     /* get some infos about the game */
     $gametype   = DB_get_gametype_by_gameid($gameid);
     $gamestatus = DB_get_game_status_by_gameid($gameid);
     /* get some infos about the game */
     $gametype   = DB_get_gametype_by_gameid($gameid);
     $gamestatus = DB_get_game_status_by_gameid($gameid);
@@ -257,17 +341,23 @@ else if(myisset("me"))
        $GT  = $gametype." ".$GT;
       }
 
        $GT  = $gametype." ".$GT;
       }
 
-    /* display rule set for this game */
-    echo "<div class=\"ruleset\">\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;
+         }
+      };
+
+    /* put everyting in a form */
+    echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
 
 
-    if($gamestatus != 'pre')
-      echo " Gametype: $GT <br />\n";
-    
-    echo "Rules: <br />\n";
-    echo "10ofhearts : ".$r[2]."<br />\n";
-    echo "schweinchen: ".$r[3]."<br />\n";
-    echo "call:        ".$r[4]."<br />\n";
-    echo "</div>\n";
+    /* output game */
 
     /* output extra division in case this game is part of a session */
     if($session)
 
     /* output extra division in case this game is part of a session */
     if($session)
@@ -279,27 +369,16 @@ else if(myisset("me"))
        foreach($hashes as $hash)
          {
            if($hash == $me)
        foreach($hashes as $hash)
          {
            if($hash == $me)
-             echo "$i ";
-           else 
-             echo "<a href=\"".$host."?me=".$hash."\">$i</a> ";
+             echo "$i \n";
+           else
+             echo "<a href=\"".$host."?me=".$hash."\">$i</a> \n";
            $i++;
          }
        echo "</div>\n";
       }
 
            $i++;
          }
        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;
-         }
-      };
+    /* display the table and the names */
+    display_table();
 
     /* mystatus gets the player through the different stages of a game.
      * start:    yes/no
 
     /* mystatus gets the player through the different stages of a game.
      * start:    yes/no
@@ -314,50 +393,55 @@ else if(myisset("me"))
     switch($mystatus)
       {
       case 'start':
     switch($mystatus)
       {
       case 'start':
-       check_want_to_play($me);
-       /* move on to the next stage*/
-       DB_set_hand_status_by_hash($me,'init');
-       break;
+       if( !myisset("in") )
+         {
+           output_check_want_to_play($me);
+           break;
+         }
+       else
+         {
+           /* move on to the next stage*/
+           DB_set_hand_status_by_hash($me,'init');
+         }
       case 'init':
        /* first check if everything went ok  in the last step
         * if not, send user back, if yes, check what he did
         */
        if( !myisset("in") )
          {
       case 'init':
        /* first check if everything went ok  in the last step
         * if not, send user back, if yes, check what he did
         */
        if( !myisset("in") )
          {
-           echo "<p> you need to answer the <a href=\"$host?me=$me\">question</a>.</p>";
+           echo "<p class=\"message\"> You need to answer the <a href=\"$host?me=$me\">question</a>.</p>";
            DB_set_hand_status_by_hash($me,'start');
          }
        else
          {
            if($_REQUEST["in"] == "no")
              {
            DB_set_hand_status_by_hash($me,'start');
          }
        else
          {
            if($_REQUEST["in"] == "no")
              {
-               /* cancle the game */
+               /* cancel the game */
                $message = "Hello, \n\n".
                  "the game has been canceled due to the request of one of the players.\n";
                $message = "Hello, \n\n".
                  "the game has been canceled due to the request of one of the players.\n";
-               
+
                $userids = DB_get_all_userid_by_gameid($gameid);
                foreach($userids as $user)
                  {
                    $To = DB_get_email_by_userid($user);
                $userids = DB_get_all_userid_by_gameid($gameid);
                foreach($userids as $user)
                  {
                    $To = DB_get_email_by_userid($user);
-                   mymail($To,$EmailName."game $gameid canceled",$message);
+                   mymail($To,$EmailName."game ".DB_format_gameid($gameid)." canceled",$message);
                  }
                  }
-               
+
               &nbs