]> git.wh0rd.org Git - tt-rss.git/commitdiff
mobile: properly save preferences
authorAndrew Dolgov <fox@bah.org.ru>
Mon, 11 Jan 2010 11:06:19 +0000 (14:06 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Mon, 11 Jan 2010 11:06:19 +0000 (14:06 +0300)
db-prefs.php
mobile/functions.php
modules/pref-prefs.php
sanity_check.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql

index 659035e15e9f326e4bc1e472ed05792602285acd..c644ad70b1a3b327f4298c3094b70b838ad1c4b9 100644 (file)
        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();
+
+               }
        }
 ?>
index 39f492a25d1b0a7442c50f76e8e2098c6346f2ec..2a689fb77e6f1256ae96240ab5063a0c01641db5 100644 (file)
@@ -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) {
index 7450106a51576914bd155a4fe791eb443bd9253d..dd58fe7b5858ebe81854ee70e6fbf396cb23b8a1 100644 (file)
                                $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<br>";
-
-                                       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<br>";
-
-                                       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);
 
                        }
 
index 00c7925c4873d587de86d28a28cbdd83348f2668..950dff766169a6cbd9bcc4e82ac8b0a3859c0c5e 100644 (file)
@@ -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 "<b>Fatal Error</b>: You forgot to copy 
index 878f5a9005cdba6a1e7b1c852385a81edb64096e..e2f9729aab526743c23a325cbb9d758dbd4cda0b 100644 (file)
@@ -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),
index 93791ebb2c3f4ccf838cd20825be4b85e308da73..f242a6bba83aaa2c12d2d19260b6ca67f699de00 100644 (file)
@@ -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,