From e9105eb50dfbfbf33c75a475f21fb7f7ddf76b48 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 11 Jan 2010 14:06:19 +0300 Subject: [PATCH] mobile: properly save preferences --- db-prefs.php | 33 ++++++++++++++++++++++++++++----- mobile/functions.php | 12 ++++++++---- modules/pref-prefs.php | 31 +------------------------------ sanity_check.php | 2 +- schema/ttrss_schema_mysql.sql | 10 +++++++++- schema/ttrss_schema_pgsql.sql | 10 +++++++++- 6 files changed, 56 insertions(+), 42 deletions(-) diff --git a/db-prefs.php b/db-prefs.php index 659035e1..c644ad70 100644 --- a/db-prefs.php +++ b/db-prefs.php @@ -73,12 +73,35 @@ function set_pref($link, $key, $value) { $key = db_escape_string($key); $value = db_escape_string($value); - - db_query($link, "UPDATE ttrss_user_prefs SET - value = '$value' WHERE pref_name = '$key' - AND owner_uid = " . $_SESSION["uid"]); - $_SESSION["prefs_cache"] = array(); + $result = db_query($link, "SELECT type_name + FROM ttrss_prefs,ttrss_prefs_types + WHERE pref_name = '$key' AND type_id = ttrss_prefs_types.id"); + + if (db_num_rows($result) > 0) { + + $type_name = db_fetch_result($result, 0, "type_name"); + + if ($type_name == "bool") { + if ($value == "1" || $value == "true") { + $value = "true"; + } else { + $value = "false"; + } + } else if ($type_name == "integer") { + $value = sprintf("%d", $value); + } + + if ($pref_name == 'DEFAULT_ARTICLE_LIMIT' && $value == 0) { + $value = 30; + } + + db_query($link, "UPDATE ttrss_user_prefs SET + value = '$value' WHERE pref_name = '$key' + AND owner_uid = " . $_SESSION["uid"]); + $_SESSION["prefs_cache"] = array(); + + } } ?> diff --git a/mobile/functions.php b/mobile/functions.php index 39f492a2..2a689fb7 100644 --- a/mobile/functions.php +++ b/mobile/functions.php @@ -4,16 +4,20 @@ /* TODO replace with interface to db-prefs */ function mobile_pref_toggled($link, $id) { - if ($_SESSION["mobile-prefs"][$id]) return "true"; - + if (get_pref($link, "_MOBILE_$id")) + return "true"; + else + return ""; } function mobile_get_pref($link, $id) { - return $_SESSION["mobile-prefs"][$id]; + //return $_SESSION["mobile-prefs"][$id]; + return get_pref($link, "_MOBILE_$id"); } function mobile_set_pref($link, $id, $value) { - $_SESSION["mobile-prefs"][$id] = $value; + //$_SESSION["mobile-prefs"][$id] = $value; + return set_pref($link, "_MOBILE_$id", $value); } function mobile_feed_has_icon($id) { diff --git a/modules/pref-prefs.php b/modules/pref-prefs.php index 7450106a..dd58fe7b 100644 --- a/modules/pref-prefs.php +++ b/modules/pref-prefs.php @@ -84,36 +84,7 @@ $pref_name = db_escape_string($pref_name); $value = db_escape_string($_POST[$pref_name]); - $result = db_query($link, "SELECT type_name - FROM ttrss_prefs,ttrss_prefs_types - WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); - - if (db_num_rows($result) > 0) { - - $type_name = db_fetch_result($result, 0, "type_name"); - -// print "$pref_name : $type_name : $value
"; - - if ($type_name == "bool") { - if ($value == "1") { - $value = "true"; - } else { - $value = "false"; - } - } else if ($type_name == "integer") { - $value = sprintf("%d", $value); - } - -// print "$pref_name : $type_name : $value
"; - - if ($pref_name == 'DEFAULT_ARTICLE_LIMIT' && $value == 0) { - $value = 30; - } - - db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' - WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]); - - } + set_pref($link, $pref_name, $value); } diff --git a/sanity_check.php b/sanity_check.php index 00c7925c..950dff76 100644 --- a/sanity_check.php +++ b/sanity_check.php @@ -2,7 +2,7 @@ require_once "functions.php"; define('EXPECTED_CONFIG_VERSION', 18); - define('SCHEMA_VERSION', 61); + define('SCHEMA_VERSION', 62); if (!file_exists("config.php")) { print "Fatal Error: You forgot to copy diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 878f5a90..e2f9729a 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -238,7 +238,7 @@ create table ttrss_tags (id integer primary key auto_increment, create table ttrss_version (schema_version int not null) TYPE=InnoDB; -insert into ttrss_version values (61); +insert into ttrss_version values (62); create table ttrss_enclosures (id serial not null primary key, content_url text not null, @@ -381,6 +381,14 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_COLLAPSED_FEEDLIST', 1, 'false', '', 1); +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_MOBILE_ENABLE_CATS', 1, 'false', '', 1); + +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_MOBILE_SHOW_IMAGES', 1, 'false', '', 1); + +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_MOBILE_HIDE_READ', 1, 'false', '', 1); + +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_MOBILE_SORT_FEEDS_UNREAD', 1, 'false', '', 1); + create table ttrss_user_prefs ( owner_uid integer not null, pref_name varchar(250), diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 93791ebb..f242a6bb 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -210,7 +210,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid); create table ttrss_version (schema_version int not null); -insert into ttrss_version values (61); +insert into ttrss_version values (62); create table ttrss_enclosures (id serial not null primary key, content_url text not null, @@ -347,6 +347,14 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_COLLAPSED_FEEDLIST', 1, 'false', '', 1); +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_MOBILE_ENABLE_CATS', 1, 'false', '', 1); + +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_MOBILE_SHOW_IMAGES', 1, 'false', '', 1); + +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_MOBILE_HIDE_READ', 1, 'false', '', 1); + +insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_MOBILE_SORT_FEEDS_UNREAD', 1, 'false', '', 1); + create table ttrss_user_prefs ( owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE, pref_name varchar(250) not null references ttrss_prefs(pref_name) ON DELETE CASCADE, -- 2.39.5