From f0bbdae184fed051df8ae0e93a41e88c9442a7db Mon Sep 17 00:00:00 2001 From: arun Date: Fri, 8 Dec 2006 14:00:56 +0000 Subject: [PATCH] added local time output --- db.php | 27 +++++++++++++++++++++++++++ functions.php | 14 ++++++++++++++ index.php | 18 ++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/db.php b/db.php index 10c5de2..9f00205 100644 --- a/db.php +++ b/db.php @@ -349,4 +349,31 @@ function DB_get_all_names() return $names; } + +function DB_update_user_timestamp($userid) +{ + mysql_query("UPDATE User SET last_login = CURRENT_TIMESTAMP WHERE id=".DB_quote_smart($userid)); + return; +} + +function DB_get_user_timestamp($userid) +{ + $result = mysql_query("SELECT last_login FROM User WHERE id=".DB_quote_smart($userid)); + $r = mysql_fetch_array($result,MYSQL_NUM); + + if($r) + return $r[0]; + else + return NULL; +} +function DB_get_user_timezone($userid) +{ + $result = mysql_query("SELECT timezone FROM User WHERE id=".DB_quote_smart($userid)); + $r = mysql_fetch_array($result,MYSQL_NUM); + + if($r) + return $r[0]; + else + return 0; +} ?> \ No newline at end of file diff --git a/functions.php b/functions.php index 49e0a1d..ce48513 100644 --- a/functions.php +++ b/functions.php @@ -431,4 +431,18 @@ function display_cards($me,$myturn) return; } +function return_timezone($offset) +{ + switch($offset) + { + case '1': + $zone = "Europe/Berlin"; + break; + default: + $zone = "Europe/London"; + } + + return $zone; +} + ?> \ No newline at end of file diff --git a/index.php b/index.php index 7db4399..8385576 100644 --- a/index.php +++ b/index.php @@ -171,6 +171,7 @@ else if(isset($_REQUEST["me"])) exit(); } + DB_update_user_timestamp($myid); $myname = DB_get_name_by_hash($me); $mystatus = DB_get_status_by_hash($me); @@ -541,7 +542,18 @@ else if(isset($_REQUEST["me"])) if($ok) { - echo "ok. your logged in, now what? :)
"; + $time = DB_get_user_timestamp($uid); + $unixtime =strtotime($time); + + $offset = DB_get_user_timezone($uid); + $zone = return_timezone($offset); + date_default_timezone_set($zone); + + echo "ok. your logged in, now what? :)
last login: "; + echo date("r",$unixtime)."
"; + + DB_update_user_timestamp($uid); + $names = DB_get_all_names(); echo "

registered players:
\n"; foreach ($names as $name) @@ -576,7 +588,9 @@ else if(isset($_REQUEST["register"]) ) - + + + -- 2.17.1