BUGFIX: time display used wrong timezones. also optimized things a bit
authorArun Persaud <arun@nubati.net>
Sun, 16 Dec 2007 13:54:06 +0000 (14:54 +0100)
committerArun Persaud <arun@nubati.net>
Sun, 16 Dec 2007 21:33:43 +0000 (22:33 +0100)
Got rid of a few db-queries for getting the right timezone. The timezone was also set after the timefunction was called and therefore the timezone didn't have any effect.

create_database.sql
functions.php
index.php
output.php
register.php
stats.php

index d7b7e2091d769e2807c9542de252e30b9ee6a040..ed6d3f67ff891ab31a3ea19c4b7766a66a8fb36a 100644 (file)
@@ -260,7 +260,7 @@ CREATE TABLE `User` (
   `fullname` varchar(64) default NULL,
   `email` varchar(64) default NULL,
   `password` varchar(32) default NULL,
-  `timezone` tinyint(2) default NULL,
+  `timezone` varchar(64) default 'Europe/London',
   `last_login` timestamp NOT NULL default '0000-00-00 00:00:00',
   UNIQUE KEY `id` (`id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
index 16ca508bb70d8dfca1d2452713f53db4df030294..c835f89897906c6f188690f70bacb022bcc5bf1f 100644 (file)
@@ -390,26 +390,6 @@ function display_cards($me,$myturn)
   return;
 }
 
-function return_timezone($offset)
-{
-  switch($offset)
-    {
-    case '1':
-      $zone = "Europe/Berlin";
-      break;
-    case '-8':
-      $zone = "America/Vancouver";
-      break;
-    case '13':
-      $zone = "Pacific/Auckland";
-      break;
-    default:
-      $zone = "Europe/London";
-    }
-
-  return $zone;
-}
-
 function have_suit($cards,$c)
 {
   global $CARDS;
@@ -669,7 +649,8 @@ function display_table ()
                        "        Hand.sickness as sickness, ".
                        "        Hand.point_call, ".
                        "        User.last_login, ".
-                       "        Hand.hash        ".
+                       "        Hand.hash,       ".
+                       "        User.timezone    ".
                        "FROM Hand ".
                        "LEFT JOIN User ON User.id=Hand.user_id ".
                        "WHERE Hand.game_id='".$gameid."' ".
@@ -685,12 +666,12 @@ function display_table ()
       $party = $r[3];
       $sickness  = $r[4];
       $call      = $r[5];
-      $lastlogin = strtotime($r[6]);
       $hash      = $r[7];
+      $timezone  = $r[8];
+      date_default_timezone_set($timezone);
+      $timenow   = strtotime(date("Y-m-d H:i:s"));
+      $lastlogin = strtotime($r[6]);
 
-      $offset = DB_get_user_timezone($user);
-      $zone   = return_timezone($offset);
-      date_default_timezone_set($zone);
 
       echo "  <div class=\"table".($pos-1)."\">\n";
       if(!$debug)
@@ -790,7 +771,7 @@ function display_table ()
        }
 
       echo "    <br />\n";
-      echo "    <span title=\"".date("Y-m-d H:i:s")."\">local time</span>\n";
+      echo "    <span title=\"".date("Y-m-d H:i:s",$timenow).  "\">local time</span>\n";
       echo "    <span title=\"".date("Y-m-d H:i:s",$lastlogin)."\">last login</span>\n";
       echo "   </div>\n";
 
index 8acb8715b28289a76a7daf1b048db88c7b85026e..6584f0e5b9b229199b18f03b1160a6880b7ea304 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1153,13 +1153,8 @@ else if(myisset("me"))
          $seq     = $r[2];
          $trick   = $r[3];
          $comment = $r[4];
-         $timeplayed = strtotime($r[5]);
          $user    = $r[6];
 
-         $offset = DB_get_user_timezone($user);
-         $zone   = return_timezone($offset);
-         date_default_timezone_set($zone);
-
          /* check if first schweinchen has been played */
          if( $GAME["schweinchen"] && ($r[0] == 19 || $r[0] == 20) )
            $GAME["schweinchen"]++;
@@ -2057,24 +2052,12 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
             }
           else /* output default user page */
             {
-              $time     = DB_get_user_timestamp($myid);
-              $unixtime = strtotime($time);
-
-              $offset   = DB_get_user_timezone($myid);
-              $zone     = return_timezone($offset);
-              date_default_timezone_set($zone);
-
               $myname = DB_get_name_by_email($email);
               $_SESSION["name"] = $myname;
 
-              if(isset($_SESSION["name"]))
-                output_status($_SESSION["name"]);
-
               /* display links to settings */
               output_user_settings();
 
-              echo "<div class=\"lastlogin\">last login: ".date("r",$unixtime)."</div>";
-
               DB_update_user_timestamp($myid);
 
               display_user_menu();
index 8dc0c2e4c473bacb02c8373e3aff077278cbc951..29fd8f3bb58283dde836eb87654ac572a10b0974 100644 (file)
@@ -267,7 +267,7 @@ function output_home_page($pre,$game,$done,$avgtime)
       echo "$done games have been completed on this server. Average time of a game: $avgtime days</p>";
 ?>
 
-    <p> Please <a href="register.php">register</a>, in case you haven't done that yet  <br />
+    <p> Please <a href="register.php">register</a>, in case you have not done that yet  <br />
         or login with you email-address or name and password here:
     </p>
         <form action="index.php" method="post">
@@ -333,8 +333,29 @@ function output_header()
 <div class="header">
 <h1> Welcome to E-Doko <sup style="color:#888;">(beta)</sup> </h1>
 </div>
-<div class="main">
 <?php
+   if(isset($_SESSION["name"]))
+     {
+       $name = $_SESSION["name"];
+
+       /* logout info */
+       echo "<div class=\"status\">\n";
+       echo $name;
+       echo " <a href=\"index.php?logout=1\">logout</a>\n";
+       echo "</div>";
+
+       /* last logon time */
+       $myid   = DB_get_userid_by_name($name);
+       $zone   = DB_get_user_timezone($myid);
+       date_default_timezone_set($zone);
+
+       $time     = DB_get_user_timestamp($myid);
+       $unixtime = strtotime($time);
+
+       echo "<div class=\"lastlogin\">last login: ".date("r",$unixtime)."</div>";
+     };
+
+  echo "<div class=\"main\">";
   return;
 }
 
@@ -365,10 +386,6 @@ function output_footer()
 
 function output_status($name)
 {
-  echo "<div class=\"status\">\n";
-  echo $name;
-  echo " <a href=\"index.php?logout=1\">logout</a>\n";
-  echo "</div>";
 
   return;
 }
index 827e77ea3c0b7524db2190f64b1e1288afe9a9f0..7c3a373989bdfcd9d91bca39dff5014d9482183e 100644 (file)
@@ -71,9 +71,10 @@ if(myisset("Rfullname","Remail","Rpassword","Rtimezone") )
               <td><label for="Rtimezone">Timezone:</label></td>
                <td>
                  <select id="Rtimezone" name="Rtimezone" size="1">
-                     <option value="1">Berlin</option>
-                     <option value="-8">Berkeley</option>
-                     <option value="13">Wellington</option>
+                     <option value="Europe/London">Berlin</option>
+                     <option value="Europe/Berlin">Berlin</option>
+                     <option value="America/Vancouver">Berkeley</option>
+                     <option value="Pacific/Auckland">Wellington</option>
                  </select>
                 (If your timezone is not listed, just select whatever you want and email the admin your correct time zone.)
               </td>
index ba32a9269077c0954b202b96e87becfe8592c65c..68a09afbb6953156f4b23cb9a68015e217d67b93 100644 (file)
--- a/stats.php
+++ b/stats.php
@@ -52,17 +52,6 @@ else if( isset($_SESSION["name"]) )
        {
         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($name);
-
-        echo "<div class=\"lastlogin\">last login: ".date("r",$unixtime)."</div>";
-
         DB_update_user_timestamp($myid);
 
         display_user_menu();