CLEANUP: moved register.php to the include directory
[e-DoKo.git] / stats.php
index 5bbca267f136609cbff7d288feca10926cbe2b4b..267b33284a5f2ca1fd87d6912ea67e2e326540fb 100644 (file)
--- a/stats.php
+++ b/stats.php
@@ -2,9 +2,9 @@
 error_reporting(E_ALL);
 
 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("./include/output.php");      /* html output only */
+include_once("./include/db.php");          /* database only */
+include_once("./include/functions.php");   /* the rest */
 
 config_check();
 
@@ -29,39 +29,29 @@ if(myisset("logout"))
     session_destroy();
     $_SESSION = array();
     echo "<div class=\"message\"><span class=\"bigger\">You are now logged out!</span><br />\n".
-      "(<a href=\"$host\">This will take you back to the home-page</a>)</div>";
+      "(<a href=\"$INDEX\">This will take you back to the home-page</a>)</div>";
   }
 /* user status page */
 else if( isset($_SESSION["name"]) )
    {
      $name = $_SESSION["name"];
-     $email     = DB_get_email_by_name($name);
+     $email     = DB_get_email('name',$name);
      $password  = DB_get_passwd_by_name($name);
 
-
      /* verify password and email */
      if(strlen($password)!=32)
        $password = md5($password);
 
      $ok  = 1;
-     $myid = DB_get_userid_by_email_and_password($email,$password);
+     $myid = DB_get_userid('email-password',$email,$password);
      if(!$myid)
        $ok = 0;
 
      if($ok)
        {
-        DB_get_PREF($myid);
-
-        $time     = DB_get_user_timestamp($myid);
-        $unixtime = strtotime($time);
-
-        $offset   = DB_get_user_timezone($myid);
-        $zone     = return_timezone($offset);
-        date_default_timezone_set($zone);
+        output_status();
 
-        output_status($name);
-
-        echo "<div class=\"lastlogin\">last login: ".date("r",$unixtime)."</div>";
+        DB_get_PREF($myid);
 
         DB_update_user_timestamp($myid);
 
@@ -134,8 +124,10 @@ else if( isset($_SESSION["name"]) )
         echo "</p>\n";
 
         /* longest and shortest game */
-        $r=mysql_query("SELECT MIN(timediff(mod_date,create_date)),session,id".
-                       " 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);
@@ -143,8 +135,9 @@ else if( isset($_SESSION["name"]) )
             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);
@@ -162,32 +155,57 @@ else if( isset($_SESSION["name"]) )
           }
 
         /* most reminders */
-        echo "<p>These players got the most reminders:<br />\n";
-        $result = mysql_query("SELECT COUNT(*) as c,fullname from Reminder".
+        echo "<p>These players got the most reminders per game:<br />\n";
+        $result = mysql_query("SELECT COUNT(*)  /" .
+                              "      (SELECT COUNT(*) FROM Hand".
+                              "       WHERE user_id=User.id) as c,".
+                              " fullname FROM Reminder".
                               " LEFT JOIN User ON User.id=user_id".
                               " GROUP BY user_id".
-                              " ORDER BY c DESC LIMIT 3" );
+                              " ORDER BY c DESC LIMIT 5" );
         while( $r = mysql_fetch_array($result,MYSQL_NUM))
           echo $r[1]." (".$r[0].") <br />\n";
         echo "</p>\n";
 
         /* fox */
-        echo "<p>These players caught the most foxes:<br />\n";
-        $result = mysql_query("SELECT COUNT(*) as c,fullname from Score".
+        echo "<p>These players caught the most foxes per game:<br />\n";
+        $result = mysql_query("SELECT COUNT(*) /" .
+                              "      (SELECT COUNT(*) FROM Hand".
+                              "       WHERE user_id=User.id) as c,".
+                              " fullname".
+                              " FROM Score".
                               " LEFT JOIN User ON User.id=winner_id".
                               " WHERE score='fox'".
                               " GROUP BY winner_id".
-                              " ORDER BY c DESC LIMIT 2" );
+                              " ORDER BY c DESC LIMIT 5" );
+        while( $r = mysql_fetch_array($result,MYSQL_NUM))
+          echo $r[1]." (".$r[0].") <br />\n";
+        echo "</p>\n";
+
+        echo "<p>These players lost their fox most often per game:<br />\n";
+        $result = mysql_query("SELECT COUNT(*) /" .
+                              "      (SELECT COUNT(*) FROM Hand".
+                              "       WHERE user_id=User.id) as c,".
+                              " fullname".
+                              " FROM Score".
+                              " LEFT JOIN User ON User.id=looser_id".
+                              " WHERE score='fox'".
+                              " GROUP BY looser_id".
+                              " ORDER BY c DESC LIMIT 5" );
         while( $r = mysql_fetch_array($result,MYSQL_NUM))
           echo $r[1]." (".$r[0].") <br />\n";
         echo "</p>\n";
 
-        echo "<p>These players lost their fox most often:<br />\n";
-        $result = mysql_query("SELECT COUNT(*) as c,fullname from Score".
+        echo "<p>These players lost their fox least often per game:<br />\n";
+        $result = mysql_query("SELECT COUNT(*) /" .
+                              "      (SELECT COUNT(*) FROM Hand".
+                              "       WHERE user_id=User.id) as c,".
+                              " fullname".
+                              " FROM Score".
                               " LEFT JOIN User ON User.id=looser_id".
                               " WHERE score='fox'".
                               " GROUP BY looser_id".
-                              " ORDER BY c DESC LIMIT 2" );
+                              " ORDER BY c ASC LIMIT 5" );
         while( $r = mysql_fetch_array($result,MYSQL_NUM))
           echo $r[1]." (".$r[0].") <br />\n";
         echo "</p>\n";
@@ -209,6 +227,31 @@ else if( isset($_SESSION["name"]) )
         echo " bottom ".$r[0]." <br />\n";
         echo "</p>\n";
 
+        /* most games */
+        echo "<p>Most games played on the server:<br />\n";
+        $result = mysql_query("SELECT COUNT(*) as c,  " .
+                              " fullname FROM Hand".
+                              " LEFT JOIN User ON User.id=user_id".
+                              " GROUP BY user_id".
+                              " ORDER BY c DESC LIMIT 7" );
+        while( $r = mysql_fetch_array($result,MYSQL_NUM))
+          echo $r[1]." (".$r[0].") <br />\n";
+        echo "</p>\n";
+
+        /* most active games */
+        echo "<p>These players are involved in this many active games:<br />\n";
+        $result = mysql_query("SELECT COUNT(*) as c,  " .
+                              " fullname FROM Hand".
+                              " LEFT JOIN User ON User.id=user_id".
+                              " LEFT JOIN Game ON Game.id=game_id".
+                              " WHERE Game.status<>'gameover'".
+                              " GROUP BY user_id".
+                              " ORDER BY c DESC LIMIT 7" );
+        while( $r = mysql_fetch_array($result,MYSQL_NUM))
+          echo $r[1]." (".$r[0].") <br />\n";
+        echo "</p>\n";
+        
+
         /*
          does the party win more often if they start
 
@@ -235,7 +278,7 @@ else if( isset($_SESSION["name"]) )
    {
      /* send them back to the login page */
     echo "<div class=\"message\"><span class=\"bigger\">You need to log in!</span><br />\n".
-      "(<a href=\"$host\">This will take you back to the login-page</a>)</div>";
+      "(<a href=\"$INDEX\">This will take you back to the login-page</a>)</div>";
    }
 
 output_footer();