Merge branch 'master' of http://nubati.net/git/e-DoKo
authorArun Persaud <arun@nubati.net>
Sat, 28 Jun 2008 11:23:28 +0000 (04:23 -0700)
committerArun Persaud <arun@nubati.net>
Sat, 28 Jun 2008 11:23:28 +0000 (04:23 -0700)
include/cancelgame.php
include/game.php
include/newgame.php
include/output.php
include/preferences.php
include/reminder.php
include/stats.php
include/user.php
index.php

index 5b855347bab0794f65e220de04579e9e214fef58..43d32740c93014bded9fed6ef61a3d1626d906e6 100644 (file)
@@ -10,9 +10,7 @@ output_status();
 if(!myisset("me"))
   {
     echo "Hmm, you really shouldn't mess with the urls.<br />\n";
-    output_footer();
-    DB_close();
-    exit();
+    return;
   }
 
 $me = $_REQUEST["me"];
@@ -23,9 +21,7 @@ if(!$myid)
   {
     echo "Can't find you in the database, please check the url.<br />\n";
     echo "perhaps the game has been canceled, check by login in <a href=\"$INDEX\">here</a>.";
-    output_footer();
-    DB_close();
-    exit();
+    return;
   }
 
 DB_update_user_timestamp($myid);
index 0350d9e4adf2287889960674f3cea520c78808c5..25e2b2ff8166d24097d722dd81273d49b5063d38 100644 (file)
@@ -9,9 +9,7 @@ if(!isset($HOST))
 if(!myisset("me"))
   {
     echo "Hmm, you really shouldn't mess with the urls.<br />\n";
-    output_footer();
-    DB_close();
-    exit();
+    return;
   }
 $me = $_REQUEST["me"];
 
@@ -21,17 +19,11 @@ if(!$myid)
   {
     echo "Can't find you in the database, please check the url.<br />\n";
     echo "perhaps the game has been canceled, check by login in <a href=\"$INDEX\">here</a>.";
-    output_footer();
-    DB_close();
-    exit();
+    return;
   }
 
 global $GAME,$RULES,$CARDS;
 
-/* user might get here by clicking on the link in an email, so session might not be set */
-if(isset($_SESSION["name"]))
-  output_status($_SESSION["name"]);
-
 /* the user has done something, update the timestamp */
 DB_update_user_timestamp($myid);
 
@@ -501,9 +493,7 @@ switch($mystatus)
 
            echo "The game has been canceled because ".DB_get_name('userid',$nines).
              " has five or more nines and nobody is playing solo.\n";
-           output_footer();
-           DB_close();
-           exit();
+           return;
          }
        else if($poverty==1) /* one person has poverty */
          {
@@ -832,9 +822,7 @@ switch($mystatus)
                DB_cancel_game($me);
 
                echo "<p style=\"background-color:red\";>Game ".DB_format_gameid($gameid)." has been canceled.<br /><br /></p>";
-               output_footer();
-               DB_close();
-               exit();
+               return;
              }
            else
              {
@@ -1894,8 +1882,4 @@ switch($mystatus)
              output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
          }
       }
-
-    output_footer();
-    DB_close();
-    exit();
 ?>
\ No newline at end of file
index feb5216119f7b92ff6e5bd53fb23354399369bbf..db6b62da3474444b96348638220cc875363293ad 100644 (file)
@@ -20,7 +20,6 @@ else
       return;
 
     DB_update_user_timestamp($myid);
-    output_status();
 
     if( !myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" ))
       {
@@ -45,9 +44,7 @@ else
        if(!in_array($name,array($PlayerA,$PlayerB,$PlayerC,$PlayerD)))
          {
            echo "<div class=\"message\">You need to be one of the players to start a <a href=\"$INDEX?action=new\">new game</a>.</div>";
-           output_footer();
-           DB_close();
-           exit();
+           return;
          }
 
        /* what rules were selected */
@@ -65,9 +62,7 @@ else
        if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
          {
            echo "couldn't find one of the names, please start a new game";
-           output_footer();
-           DB_close();
-           exit();
+           return;
          }
 
        /* get user ids */
@@ -94,16 +89,12 @@ else
            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();
+               return;
              }
            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();
+               return;
              }
 
            if($session)
@@ -126,9 +117,7 @@ else
            if($ruleset <0)
              {
                myerror("Error defining ruleset: $ruleset");
-               output_footer();
-               DB_close();
-               exit();
+               return;
              };
            /* get max session */
            $max = DB_get_max_session();
index 2f846be70badcabaf4b5eb930efc2c4e168f141e..81f01c5dc3fe95f72ad07dee1036c2c5cd60899a 100644 (file)
@@ -372,7 +372,13 @@ function output_status()
        date_default_timezone_set($zone);
 
        echo "<div class=\"lastlogin\">last login: ".date("r",$unixtime)."</div>\n";
-     };
+     }
+   else
+     {
+       echo "\n<div class=\"status\">\n";
+       echo "<a href=\"".$INDEX."\">login</a>\n";
+       echo "</div>\n";
+     }
   return;
 }
 
index 8a6050d0f70106831ca4502728d4e282c569a71d..03821932f282946f4c6f0aee2c03a4a04a645bc7 100644 (file)
@@ -18,7 +18,6 @@ $changed_cards           = 0;
 $changed_timezone  = 0;
 $changed_autosetup = 0;
 
-output_status();
 display_user_menu();
 
 /* get old infos */
@@ -206,8 +205,5 @@ echo "    </table>\n";
 echo "  </form>\n";
 echo "</div>\n";
 
-output_footer();
-DB_close();
-exit();
-
+return;
 ?>
\ No newline at end of file
index 8844e4801679ffa4f67b3627b6cf1e89058836d2..9c297cd4d7793ef58474618bce8e9e3ee0e85c89 100644 (file)
@@ -5,14 +5,10 @@
 if(!isset($HOST))
   exit;
 
-output_status();
-
 if(!myisset("me"))
   {
     echo "Hmm, you really shouldn't mess with the urls.<br />\n";
-    output_footer();
-    DB_close();
-    exit();
+    return;
   }
 
 $me = $_REQUEST["me"];
@@ -23,9 +19,7 @@ if(!$myid)
   {
     echo "Can't find you in the database, please check the url.<br />\n";
     echo "perhaps the game has been canceled, check by login in <a href=\"$INDEX\">here</a>.";
-    output_footer();
-    DB_close();
-    exit();
+    return;
   }
 
 DB_update_user_timestamp($myid);
index cff6a84fb3eb4b22ec020f7a52a5a40952d36c54..97e1979a86a27f6d837a636168fc099e006cb634 100644 (file)
@@ -12,8 +12,6 @@ $myid = DB_get_userid('email',$email);
 if(!$myid)
   return;
 
-output_status();
-
 $PREF = DB_get_PREF($myid);
 
 DB_update_user_timestamp($myid);
index 7b4880dec49a91b8a2585a73e7ab57b54bcccc6d..19eb27bc6745da85544254d34e7acd1c632d11a4 100644 (file)
@@ -6,17 +6,17 @@ if(!isset($HOST))
   exit;
 
 /* test id and password, should really be done in one step */
-if(!isset($_SESSION["name"]))
+if(!isset($_SESSION["name"])) 
   {
     $email     = $_REQUEST["email"];
     $password  = $_REQUEST["password"];
   }
- else
-   {
-     $name = $_SESSION["name"];
-     $email     = DB_get_email('name',$name);
-     $password  = DB_get_passwd_by_name($name);
-   };
+else
+  {
+    $name = $_SESSION["name"];
+    $email     = DB_get_email('name',$name);
+    $password  = DB_get_passwd_by_name($name);
+  };
 
 /* user has forgotten his password */
 if(myisset("forgot"))
@@ -81,111 +81,103 @@ if(myisset("forgot"))
            "or else try <a href=\"$INDEX\">again</a>.";
       }
   }
- else 
-   { /* normal user page */
-
-     /* verify password and email */
-     if(strlen($password)!=32)
-       $password = md5($password);
-
-     $ok  = 1;
-     $myid = DB_get_userid('email-password',$email,$password);
-     if(!$myid)
-       $ok = 0;
-
-     if($ok)
-       {
-        /* user information is ok */
-        $myname = DB_get_name('email',$email);
-        $_SESSION["name"] = $myname;
-        output_status();
+else 
+  { /* normal user page */
     
-        $PREF = DB_get_PREF($myid);
+    /* verify password and email */
+    if(strlen($password)!=32)
+      $password = md5($password);
     
-        DB_update_user_timestamp($myid);
-        
-        display_user_menu();
-        
-        /* display all games the user has played */
-        echo "<div class=\"user\">";
-        echo "<h4>These are all your games:</h4>\n";
-        echo "<p>Session: <br />\n";
-        echo "<span class=\"gamestatuspre\"> p </span> =  pre-game phase ";
-        echo "<span class=\"gamestatusplay\">P </span> =  game in progess ";
-        echo "<span class=\"gamestatusover\">F </span> =  game finished <br />";
-        echo "</p>\n";
-        
-        $output = array();
-        $result = DB_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player,Game.status from Hand".
-                           " LEFT JOIN Game ON Game.id=Hand.game_id".
-                           " WHERE user_id='$myid'".
-                           " ORDER BY Game.session,Game.create_date" );
-        $gamenrold = -1;
-        echo "<table>\n <tr><td>\n";
-        while( $r = DB_fetch_array($result))
-          {
-            $game = DB_format_gameid($r[1]);
-            $gamenr = (int) $game;
-            if($gamenrold < $gamenr)
-              {
-                if($gamenrold!=-1)
-                  echo "</td></tr>\n <tr> <td>$gamenr:</td>\n";
-                else
-                  echo "$gamenr:</td>\n";
-                $gamenrold = $gamenr;
-                echo "<td class=\"usergames\">\n";
-              }
-            if($r[4]=='pre')
-              echo "\n   <span class=\"gamestatuspre\"><a href=\"".$INDEX."?action=game&amp;me=".$r[0]."\">p </a></span> ";
-            else if ($r[4]=='gameover')
-              echo "\n   <span class=\"gamestatusover\"><a href=\"".$INDEX."?action=game&amp;me=".$r[0]."\">F </a></span> ";
-            else
-              echo "\n   <span class=\"gamestatusplay\"><a href=\"".$INDEX."?action=game&amp;me=".$r[0]."\">P </a></span> ";
-            if($r[4] != 'gameover')
-              {
-                echo "</td>\n<td>\n    ";
-                if($r[3]==$myid || !$r[3])
-                  echo "(it's <strong>your</strong> turn)\n";
-                else
-                  {
-                    $name = DB_get_name('userid',$r[3]);
-                    $gameid = $r[1];
-                    if(DB_get_reminder($r[3],$gameid)==0)
-                      if(time()-strtotime($r[2]) > 60*60*24*7)
-                        echo "".
-                          "<a href=\"$INDEX?action=reminder&amp;me=".$r[0]."\">Send a reminder.</a>";
-                    echo "(it's $name's turn)\n";
-                  };
-                if(time()-strtotime($r[2]) > 60*60*24*30)
-                  echo "".
-                    "<a href=\"$INDEX?action=cancel&amp;me=".$r[0]."\">Cancel?</a>".
-                    " (clicking here is final and can't be restored)";
-                
-              }
-          }
-        echo "</td></tr>\n</table>\n";
-        
-        /* display last 5 users that have signed up to e-DoKo */
-        $names = DB_get_names_of_new_logins(5);
-        echo "<h4>New Players:</h4>\n<p>\n";
-        echo implode(", ",$names).",...\n";
-        echo "</p>\n";
-        
-        /* display last 5 users that logged on */
-        $names = DB_get_names_of_last_logins(5);
-        echo "<h4>Players last logged in:</h4>\n<p>\n";
-        echo implode(", ",$names).",...\n";
-        echo "</p>\n";
-        
-        echo "</div>\n";
-       }
-     else
-       {
-        echo "<div class=\"message\">Sorry email and password don't match. Please <a href=\"$INDEX\">try again</a>. </div>";
-       }
-   };
-output_footer();
-DB_close();
-exit();
-
+    $ok  = 1;
+    $myid = DB_get_userid('email-password',$email,$password);
+    if(!$myid)
+      $ok = 0;
+    
+    if($ok)
+      {
+       /* user information is ok */
+       $myname = DB_get_name('email',$email);
+       $_SESSION["name"] = $myname;
+       
+       $PREF = DB_get_PREF($myid);
+       
+       DB_update_user_timestamp($myid);
+       
+       display_user_menu();
+       
+       /* display all games the user has played */
+       echo "<div class=\"user\">";
+       echo "<h4>These are all your games:</h4>\n";
+       echo "<p>Session: <br />\n";
+       echo "<span class=\"gamestatuspre\"> p </span> =  pre-game phase ";
+       echo "<span class=\"gamestatusplay\">P </span> =  game in progess ";
+       echo "<span class=\"gamestatusover\">F </span> =  game finished <br />";
+       echo "</p>\n";
+       
+       $output = array();
+       $result = DB_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player,Game.status from Hand".
+                          " LEFT JOIN Game ON Game.id=Hand.game_id".
+                          " WHERE user_id='$myid'".
+                          " ORDER BY Game.session,Game.create_date" );
+       $gamenrold = -1;
+       echo "<table>\n <tr><td>\n";
+       while( $r = DB_fetch_array($result))
+         {
+           $game = DB_format_gameid($r[1]);
+           $gamenr = (int) $game;
+           if($gamenrold < $gamenr)
+             {
+               if($gamenrold!=-1)
+                 echo "</td></tr>\n <tr> <td>$gamenr:</td>\n";
+               else
+                 echo "$gamenr:</td>\n";
+               $gamenrold = $gamenr;
+               echo "<td class=\"usergames\">\n";
+             }
+           if($r[4]=='pre')
+             echo "   <span class=\"gamestatuspre\"><a href=\"".$INDEX."?action=game&amp;me=".$r[0]."\">p </a></span>\n";
+           else if ($r[4]=='gameover')
+             echo "   <span class=\"gamestatusover\"><a href=\"".$INDEX."?action=game&amp;me=".$r[0]."\">F </a></span>\n";
+           else
+             echo "   <span class=\"gamestatusplay\"><a href=\"".$INDEX."?action=game&amp;me=".$r[0]."\">P </a></span>\n";
+           if($r[4] != 'gameover')
+             {
+               echo "</td>\n<td>\n    ";
+               if($r[3]==$myid || !$r[3])
+                 echo "(it's <strong>your</strong> turn)\n";
+               else
+                 {
+                   $name = DB_get_name('userid',$r[3]);
+                   $gameid = $r[1];
+                   if(DB_get_reminder($r[3],$gameid)==0)
+                     if(time()-strtotime($r[2]) > 60*60*24*7)
+                       echo "<a href=\"$INDEX?action=reminder&amp;me=".$r[0]."\">Send a reminder.</a>";
+                   echo "(it's $name's turn)\n";
+                 };
+               if(time()-strtotime($r[2]) > 60*60*24*30)
+                 echo "<a href=\"$INDEX?action=cancel&amp;me=".$r[0]."\">Cancel?</a>".
+                   " (clicking here is final and can't be restored)";
+             }
+         }
+       echo "</td></tr>\n</table>\n";
+       
+       /* display last 5 users that have signed up to e-DoKo */
+       $names = DB_get_names_of_new_logins(5);
+       echo "<h4>New Players:</h4>\n<p>\n";
+       echo implode(", ",$names).",...\n";
+       echo "</p>\n";
+       
+       /* display last 5 users that logged on */
+       $names = DB_get_names_of_last_logins(5);
+       echo "<h4>Players last logged in:</h4>\n<p>\n";
+       echo implode(", ",$names).",...\n";
+       echo "</p>\n";
+       
+       echo "</div>\n";
+      }
+    else
+      {
+       echo "<div class=\"message\">Sorry email and password don't match. Please <a href=\"$INDEX\">try again</a>. </div>";
+      }
+  };
 ?>
\ No newline at end of file
index 76bbc29a55dc115ccc12f7e94f0666c46cea396b..97028006cca1882ba7769b82d2ba8b6f4c70909d 100644 (file)
--- a/index.php
+++ b/index.php
@@ -8,13 +8,11 @@ error_reporting(E_ALL);
  */
 session_start();
 
-
 include_once("config.php");                /* needs to be first in list, since other includes use this */
 include_once("./include/output.php");      /* html output only */
 include_once("./include/db.php");          /* database only */
 include_once("./include/functions.php");   /* the rest */
 
-
 /* make sure that user has set all variables in config.php */
 config_check();
 
@@ -28,7 +26,7 @@ if(DB_open()<0)
     exit();
   }
 
-/* done major error checking, output header of HTML page */
+/* done major error checking, output5B header of HTML page */
 output_header();
 
 /* The rest of the file consists of handling user input.
@@ -81,6 +79,11 @@ switch($action)
       require './include/welcome.php';
   }
 
+/* ask for login or display login info, needs to go at the end, so that we have the
+ * session-variable already set.
+ */
+output_status();
+
 output_footer();
 
 DB_close();