CLEANUP: started rewrite of pre-game phase, fixed 'start' section
[e-DoKo.git] / stats.php
index f5ce3c0d5a6ab46c65c9a4049613f5ab3f941095..44378d455b479c6486da35803cfde2e87000ca06 100644 (file)
--- a/stats.php
+++ b/stats.php
@@ -28,7 +28,8 @@ if(myisset("logout"))
     session_unset();
     session_destroy();
     $_SESSION = array();
-    echo "you are now logged out!";
+    echo "<div class=\"message\"><span class=\"bigger\">You are now logged out!</span><br />\n".
+      "(<a href=\"$INDEX\">This will take you back to the home-page</a>)</div>";
   }
 /* user status page */
 else if( isset($_SESSION["name"]) )
@@ -37,7 +38,6 @@ else if( isset($_SESSION["name"]) )
      $email     = DB_get_email_by_name($name);
      $password  = DB_get_passwd_by_name($name);
 
-
      /* verify password and email */
      if(strlen($password)!=32)
        $password = md5($password);
@@ -49,18 +49,9 @@ else if( isset($_SESSION["name"]) )
 
      if($ok)
        {
-        DB_get_PREF($myid);
-
-        $time     = DB_get_user_timestamp($myid);
-        $unixtime = strtotime($time);
+        output_status();
 
-        $offset   = DB_get_user_timezone($myid);
-        $zone     = return_timezone($offset);
-        date_default_timezone_set($zone);
-
-        output_status($name);
-
-        echo "<div class=\"lastlogin\">last login: ".date("r",$unixtime)."</div>";
+        DB_get_PREF($myid);
 
         DB_update_user_timestamp($myid);
 
@@ -86,7 +77,7 @@ else if( isset($_SESSION["name"]) )
                               " AND Game.status='gameover'");
         while( $r = mysql_fetch_array($result,MYSQL_NUM))
           echo $r[0];
-        echo " games</p>\n";
+        echo " games.</p>\n";
 
 
         /* number of solos */
@@ -122,7 +113,7 @@ else if( isset($_SESSION["name"]) )
  select id,type,solo,status from game where id in (select id from game where randomnumbers in (select randomnumbers from game where id=27));
 
         */
-        echo "<p>Most extra points (doko, fox, karlchen) in a game::<br />\n";
+        echo "<p>Most extra points (doko, fox, karlchen) in a single game:<br />\n";
         $result = mysql_query("SELECT COUNT(*) as c,fullname FROM Score".
                               " LEFT JOIN User ON User.id=winner_id" .
                               " WHERE score IN ('fox','doko','karlchen')".
@@ -133,22 +124,36 @@ else if( isset($_SESSION["name"]) )
         echo "</p>\n";
 
         /* longest and shortest game */
-        $r=mysql_query("SELECT MIN(datediff(mod_date,create_date)),session".
-                       " FROM Game WHERE status='gameover' GROUP BY status");
+        $r=mysql_query("SELECT timediff(mod_date,create_date) ,session,id".
+                       " FROM Game WHERE status='gameover'".
+                       " ORDER BY time_to_sec(timediff(mod_date,create_date)) ASC LIMIT 1");
+
         if($r)
           {
             $short= mysql_fetch_array($r,MYSQL_NUM);
-            echo "<p> The shortest game took only ".$short[0]." days.<br />\n";
+            $names = DB_get_all_names_by_gameid($short[2]);
+            echo "<p> The shortest game took only ".$short[0]." hours and was played by  ".join(", ",$names).".<br />\n";
           }
 
-        $r=mysql_query("SELECT MAX(datediff(mod_date,create_date)),session".
-                       " FROM Game where status='gameover' GROUP BY status");
+        $r=mysql_query("SELECT datediff(mod_date,create_date) ,session,id".
+                       " FROM Game WHERE status='gameover'".
+                       " ORDER BY time_to_sec(timediff(mod_date,create_date)) DESC LIMIT 1");
         if($r)
           {
             $long= mysql_fetch_array($r,MYSQL_NUM);
             echo "The longest game took ".$long[0]." days.</p>\n";
           }
 
+        $r=mysql_query("SELECT COUNT(*) as c, session, id FROM Game ".
+                       " GROUP BY session ORDER BY c DESC LIMIT 1");
+        if($r)
+          {
+            $long  = mysql_fetch_array($r,MYSQL_NUM);
+            $names = DB_get_all_names_by_gameid($long[2]);
+            echo "The longest session is session ".$long[1]." with ".$long[0].
+              " games played by ".join(", ",$names).".</p>\n";
+          }
+
         /* most reminders */
         echo "<p>These players got the most reminders:<br />\n";
         $result = mysql_query("SELECT COUNT(*) as c,fullname from Reminder".
@@ -222,7 +227,8 @@ else if( isset($_SESSION["name"]) )
  else
    {
      /* send them back to the login page */
-     echo "<p>Please log in</p>";
+    echo "<div class=\"message\"><span class=\"bigger\">You need to log in!</span><br />\n".
+      "(<a href=\"$INDEX\">This will take you back to the login-page</a>)</div>";
    }
 
 output_footer();