added a uniform list name for emails
[e-DoKo.git] / index.php
index 4f60b89ca0f396b7433857e614a29d8daf63282a..d931e6edaedf561cd2682e57cccbc720ebf25ef1 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,11 +1,18 @@
 <?php
 error_reporting(E_ALL);
 
+global $REV;
+$REV  ="\$Rev$";
+
 include_once("config.php");      
 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] ";
+
 if(0)
 {
   output_header();
@@ -19,8 +26,10 @@ output_header();
 
 /* check if we want to start a new game */
 if(myisset("new"))
-  output_form_for_new_game();
-
+{
+  $names = DB_get_all_names();
+  output_form_for_new_game($names);
+}
 /*check if everything is ready to set up a new game */
 else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD" ))
   {
@@ -137,7 +146,14 @@ else if(myisset("me"))
     $myname   = DB_get_name_by_hash($me);
     $mystatus = DB_get_status_by_hash($me);
     $mypos    = DB_get_pos_by_hash($me);
+
+    echo "<p class=\"gamenumber\"> Game $gameid </p>\n";
     
+
+    
+    if(myisset("cancle"))
+      echo "<p style=\"background-color:red\";>canceling a game is not implemented at the moment, but will be soon...<br /><br /></p>";
+
     switch($mystatus)
       {
       case 'start':
@@ -161,7 +177,7 @@ else if(myisset("me"))
                foreach($userids as $user)
                  {
                    $To = DB_get_email_by_userid($user);
-                   mymail($To,"[DoKo] game cancled",$message);
+                   mymail($To,$EmailName."game cancled",$message);
                  }
                
                /* delete everything from the dB */
@@ -191,7 +207,7 @@ else if(myisset("me"))
        echo "checking if you selected solo or nines...<br />".
          " if you have a wedding, please send an email to the other players. <br />".
          " if you have poverty you need to play a normal game,sorry...<br />".
-         " At the moment you need to reload this page to finish the setup.<br />";
+         " Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";
        if(!myisset("solo","wedding","poverty","nines") )
          {
            /* all these variables have a pre-selected default,
@@ -251,7 +267,7 @@ else if(myisset("me"))
         * tell people about it.
         */
        echo "<br />checking if someone else selected solo or nines... wedding and poverty not handled at the moment<br />".
-          "reload this page to finish the setup <br />";
+         " Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";  
        
        /* only set this after all poverty, etc. are handeled*/
        DB_set_hand_status_by_hash($me,'play');
@@ -292,7 +308,7 @@ else if(myisset("me"))
                foreach($userids as $user)
                  {
                    $To = DB_get_email_by_userid($user);
-                   mymail($To,"[DoKo] game cancled",$message);
+                   mymail($To,$EmailName."game cancled",$message);
                  }
                
                /* delete everything from the dB */
@@ -434,7 +450,7 @@ else if(myisset("me"))
        
        $play = array(); /* needed to calculate winner later  */
        $seq  = 1;          
-       $pos  = 0;
+       $pos  = DB_get_startplayer_by_gameid($gameid)-1; 
        $firstcard = ""; /* first card in a trick */
        
        echo "\n<ul class=\"tricks\">\n";
@@ -602,7 +618,7 @@ else if(myisset("me"))
                    foreach($userids as $user)
                      {
                        $To = DB_get_email_by_userid($user);
-                       mymail($To,"[DoKo] game over",$message);
+                       mymail($To,$EmailName."game over",$message);
                      }
                  }
                
@@ -645,7 +661,7 @@ else if(myisset("me"))
 
                    $message = "It's your turn  now.\n".
                      "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
-                   mymail($email,"[DoKo-debug] a card has been played",$message);
+                   mymail($email,$EmailName."a card has been played",$message);
                    
                    if($debug)
                      echo "DEBUG:<a href=\"index.php?me=".DB_get_hash_from_game_and_pos($gameid,$next).
@@ -664,7 +680,7 @@ else if(myisset("me"))
          }
        
        $mycards = DB_get_hand($me);
-       sort($mycards);
+       $mycards = mysort($mycards,$gametype);
        echo "<div class=\"mycards\">\n";
        
        if($myturn && !myisset("card"))
@@ -759,11 +775,19 @@ else if(myisset("me"))
        DB_update_user_timestamp($uid);
 
        echo "<p>these are the games you are playing in:<br />\n";
-       $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status<>'gameover'" );
+       $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date from Hand".
+                             " LEFT JOIN Game On Hand.game_id=Game.id".
+                             " WHERE Hand.user_id='$uid' AND Game.status<>'gameover'" );
        while( $r = mysql_fetch_array($result,MYSQL_NUM))
-         echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a><br />";
+         {
+           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>";
+           echo "<br />";
+         }
        echo "</p>\n";
 
+
        echo "<p>and these are your games that are already done:<br />\n";
        $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
        while( $r = mysql_fetch_array($result,MYSQL_NUM))