bugfix: the gamenumber wasn't shown in all email subjects
[e-DoKo.git] / index.php
index 10416f1610974a33588be7dcaeff8aed745c3bcb..8e4f17f1293c03ed309c597b52629b4f08de9a7c 100644 (file)
--- a/index.php
+++ b/index.php
@@ -62,6 +62,7 @@ if(myisset("new"))
       {
        echo "couldn't find one of the names, please start a new game";
        output_footer();
+       DB_close();
        exit();
       }
     
@@ -80,6 +81,7 @@ if(myisset("new"))
       {
        echo "Error defining ruleset: $ruleset";
        output_footer();
+       DB_close();
        exit();
       };
     
@@ -172,6 +174,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();
+       DB_close();
        exit();
       }
     
@@ -217,6 +220,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();
+       DB_close();
        exit();
       }
 
@@ -427,7 +431,7 @@ else if(myisset("me"))
                $message = "Everyone finish the questionary in game $gameid, ".
                           "please visit this link now to continue: \n".
                           " ".$host."?me=".$userhash."\n\n" ;
-               mymail($To,$EmailName." finished setup",$message);
+               mymail($To,$EmailName." finished setup in game $gameid",$message);
              }
          };
 
@@ -531,6 +535,7 @@ else if(myisset("me"))
              echo "The game has been canceled because ".DB_get_name_by_userid($nines).
                " has five or more nines and nobody is playing solo.\n";
              output_footer();
+             DB_close();
              exit();
            }
          else if($poverty==1)
@@ -696,7 +701,7 @@ else if(myisset("me"))
                      
                      $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
                        " ".$host."?me=".$userhash."\n\n" ;
-                     mymail($To,$EmailName." poverty",$message);
+                     mymail($To,$EmailName." poverty (game $gameid)",$message);
                    }
 
                  /* this user is done */
@@ -776,7 +781,7 @@ else if(myisset("me"))
                              $message = "Someone has poverty, it's your turn to decide, ".
                                         "if you want to take the trump. Please visit:".
                                         " ".$host."?me=".$userhash."\n\n" ;
-                             mymail($To,$EmailName." poverty",$message);
+                             mymail($To,$EmailName." poverty (game $gameid)",$message);
                            }
 
                        }
@@ -900,6 +905,7 @@ else if(myisset("me"))
          
          echo "<p style=\"background-color:red\";>Game $gameid has been cancled.<br /><br /></p>";
          output_footer();
+         DB_close();
          exit();
        }
 
@@ -924,7 +930,7 @@ else if(myisset("me"))
              /* email startplayer) */
              $message = "It's your turn now in game $gameid.\n".
                "Use this link to play a card: ".$host."?me=".$hash."\n\n" ;
-             mymail($email,$EmailName."ready, set, go... ",$message);
+             mymail($email,$EmailName."ready, set, go... (game $gameid) ",$message);
            }
          else
            echo " Please, <a href=\"$host?me=$me\">start</a> the game.<br />";  
@@ -1059,7 +1065,7 @@ else if(myisset("me"))
              else
                echo "(wedding)";
          
-         if(substr_compare($GT,"solo",0,4)==0 && $party=="re")
+         if(ereg("solo",$GT) && $party=="re")
             echo "($GT)";
 
          /* add point calls */
@@ -1413,7 +1419,7 @@ else if(myisset("me"))
                  $message = "A card has been played in game $gameid.\n\n".
                    "It's your turn  now.\n".
                    "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
-                 mymail($email,$EmailName."a card has been played",$message);            
+                 mymail($email,$EmailName."a card has been played in game $gameid",$message);            
                }
            }
          else
@@ -1539,6 +1545,7 @@ else if(myisset("me"))
       echo "error in testing the status";
     }
     output_footer();
+    DB_close();
     exit();
  } 
 /* user status page */ 
@@ -1667,15 +1674,15 @@ else if(myisset("me"))
               
               
               echo "<p>and these are your games that are already done:<br />Game: \n";
+              $output=array();
               $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
               while( $r = mysql_fetch_array($result,MYSQL_NUM))
-                echo "<a href=\"".$host."?me=".$r[0]."\">#".$r[1]." </a>, ";
-              echo "</p>\n";
+                $output[]= "<a href=\"".$host."?me=".$r[0]."\">#".$r[1]." </a>";
+              echo implode(", ",$output)."</p>\n";
               
               $names = DB_get_all_names();
               echo "<p>registered players:<br />\n";
-              foreach ($names as $name)
-                echo "$name, \n";
+              echo implode(", ",$names)."\n";
               echo "</p>\n";
               
               echo "<p>Want to start a new game? Visit <a href=\"".$host."?new\">this page.</a></p>";
@@ -1687,6 +1694,7 @@ else if(myisset("me"))
         }
      };
      output_footer();
+     DB_close();
      exit();
    }
 /* page for registration */
@@ -1731,7 +1739,14 @@ else if(myisset("me"))
        $game = mysql_fetch_array($r,MYSQL_NUM);     
        $done = mysql_fetch_array($r,MYSQL_NUM);     
      }
-     output_home_page($pre[0],$game[0],$done[0]);
+
+     $r=mysql_query("SELECT AVG(datediff(mod_date,create_date)) FROM Game where status='gameover' ");
+     if($r)
+       $avgage= mysql_fetch_array($r,MYSQL_NUM);     
+     else
+       $avgage[0]=0;
+
+     output_home_page($pre[0],$game[0],$done[0],$avgage[0]);
    }
 
 output_footer();