From dc0c8985bd301912022e1f1e4171cb975b993e3d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 29 Dec 2005 15:21:34 +0100 Subject: [PATCH] fixes for db-prefs cache --- db-prefs.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/db-prefs.php b/db-prefs.php index 5f61f15a..293af7be 100644 --- a/db-prefs.php +++ b/db-prefs.php @@ -19,7 +19,8 @@ } if ($_SESSION["prefs_cache"] && $_SESSION["prefs_cache"][$pref_name]) { - return $_SESSION["prefs_cache"][$pref_name]; + $tuple = $_SESSION["prefs_cache"][$pref_name]; + return convert_pref_type($tuple["value"], $tuple["type"]); } $result = db_query($link, "SELECT @@ -36,22 +37,24 @@ $value = db_fetch_result($result, 0, "value"); $type_name = db_fetch_result($result, 0, "type_name"); - if ($type_name == "bool") { - $retv = $value == "true"; - } else if ($type_name == "integer") { - $retv = sprintf("%d", $value); - } else { - $retv = $value; - } - if ($user_id = $_SESSION["uid"]) { - $_SESSION["prefs_cache"][$pref_name] = $value; + $_SESSION["prefs_cache"][$pref_name]["type"] = $type_name; + $_SESSION["prefs_cache"][$pref_name]["value"] = $value; } - return $value; + return convert_pref_type($value, $type_name); } else { die("Fatal error, unknown preferences key: $pref_name"); } } + function convert_pref_type($value, $type_name) { + if ($type_name == "bool") { + return $value == "true"; + } else if ($type_name == "integer") { + return sprintf("%d", $value); + } else { + return $value; + } + } ?> -- 2.39.5