]> git.wh0rd.org - tt-rss.git/commitdiff
per-user preferences
authorAndrew Dolgov <fox@madoka.spb.ru>
Fri, 18 Nov 2005 05:17:17 +0000 (06:17 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Fri, 18 Nov 2005 05:17:17 +0000 (06:17 +0100)
backend.php
db-prefs.php
error.php
functions.php
prefs.php
schema/ttrss_schema_pgsql.sql
tt-rss.php

index 54bd1e069e2f59d2844323a73db1eaad49d8dc80..bc75ead8a30a661360a7092f46cde74ba40ef488 100644 (file)
 
 //                                     print "$pref_name : $type_name : $value<br>";
 
-                                       db_query($link, "UPDATE ttrss_prefs SET value = '$value' 
-                                               WHERE pref_name = '$pref_name'");
+                                       db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' 
+                                               WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
 
                                }
 
 
                        if (WEB_DEMO_MODE) return;
 
-                       db_query($link, "UPDATE ttrss_prefs SET value = def_value");
+                       db_query($link,"UPDATE ttrss_user_prefs 
+                               SET value = ttrss_prefs.def_value 
+                               WHERE owner_uid = '".$_SESSION["uid"]."' AND
+                               ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
 
                        header("Location: prefs.php");
 
                } else {
 
                        $result = db_query($link, "SELECT 
-                               pref_name,short_desc,help_text,value,type_name,
+                               ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
                                section_name,def_value
-                               FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections 
+                               FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
                                WHERE type_id = ttrss_prefs_types.id AND 
-                                       section_id = ttrss_prefs_sections.id 
+                                       section_id = ttrss_prefs_sections.id AND
+                                       ttrss_user_prefs.pref_name = ttrss_prefs.pref_name
                                ORDER BY section_id,short_desc");
 
                        print "<form action=\"backend.php\" method=\"POST\">";
index 7ff64a89c9d9abfab0cc2509cd598e89a767590b..a2a25d3e50949727251ec342d3508128c47fb9e4 100644 (file)
 
                $result = db_query($link, "SELECT 
                        value,ttrss_prefs_types.type_name as type_name 
-                       FROM ttrss_prefs,ttrss_prefs_types
-                       WHERE pref_name = '$pref_name' AND ttrss_prefs_types.id = type_id");
+                       FROM 
+                               ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types
+                       WHERE 
+                               ttrss_user_prefs.pref_name = '$pref_name' AND 
+                               ttrss_prefs_types.id = type_id AND
+                               ttrss_user_prefs.pref_name = ttrss_prefs.pref_name");
 
                if (db_num_rows($result) > 0) {
                        $value = db_fetch_result($result, 0, "value");
index 8582f257ce131ee4001f7748cbfeb7bce79c50cb..5e915483d8bcccf446f2354f0e6028130613430b 100644 (file)
--- a/error.php
+++ b/error.php
@@ -1,7 +1,7 @@
 <?
-       require_once "version.php"
-       require_once "config.php"
-       require_once "db-prefs.php"
+       require_once "version.php";
+       require_once "config.php";
+       require_once "db-prefs.php";
 
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
 
index 8b6bc6620fe60e019727d4eb0b32dc96171317e7..d07ce024fa8033e55b14a4579d614c32501ef946 100644 (file)
                }
        }
 
+       function initialize_user_prefs($link, $uid) {
+
+               $uid = db_escape_string($uid);
+
+               db_query($link, "BEGIN");
+
+               $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs");
+               
+               $u_result = db_query($link, "SELECT pref_name 
+                       FROM ttrss_user_prefs WHERE owner_uid = '$uid'");
+
+               $active_prefs = array();
+
+               while ($line = db_fetch_assoc($u_result)) {
+                       array_push($active_prefs, $line["pref_name"]);                  
+               }
+
+               while ($line = db_fetch_assoc($result)) {
+                       if (array_search($line["pref_name"], $active_prefs) === FALSE) {
+//                             print "adding " . $line["pref_name"] . "<br>";
+
+                               db_query($link, "INSERT INTO ttrss_user_prefs
+                                       (owner_uid,pref_name,value) VALUES 
+                                       ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')");
+
+                       }
+               }
+
+               db_query($link, "COMMIT");
+
+       }
+
 ?>
index ab76f38ff829d47011eb2635597b38666f7d946e..690de6abc9f75c295d317433f31326a438cac82e 100644 (file)
--- a/prefs.php
+++ b/prefs.php
@@ -4,11 +4,16 @@
        require_once "version.php"; 
        require_once "config.php";
        require_once "db-prefs.php";
+       require_once "functions.php"; 
 
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
 
        $_SESSION["uid"] = PLACEHOLDER_UID; // FIXME: placeholder
        $_SESSION["name"] = PLACEHOLDER_NAME;
+
+       initialize_user_prefs($link, $_SESSION["uid"]); 
+       // FIXME this needs to be moved somewhere after user creation
+
 ?>
 <html>
 <head>
index 407b3647c56e9a87b043e40b3e6ac911e27a6d56..97efd1b6d0eff4e4d58436a374c015f320f1198b 100644 (file)
@@ -128,32 +128,31 @@ create table ttrss_prefs (pref_name varchar(250) primary key,
        section_id integer not null references ttrss_prefs_sections(id) default 1,
        short_desc text not null,
        help_text text not null default '',
-       def_value text not null,
-       value text not null);
-
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('ENABLE_FEED_ICONS', 1, 'true', 'true', 'Enable icons in feedlist',2);
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('ICONS_DIR', 2, 'icons', 'icons', 'Local directory for feed icons',1);
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('ICONS_URL', 2, 'icons', 'icons', 'Local URL for icons',1);
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('PURGE_OLD_DAYS', 3, '60', '60', 'Purge old posts after this number of days (0 - disables)',1);
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('UPDATE_POST_ON_CHECKSUM_CHANGE', 1, 'true', 'true', 'Update post on checksum change',1);
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('ENABLE_PREFS_CATCHUP_UNCATCHUP', 1, 'false', 'false', 'Enable catchup/uncatchup buttons in feed editor',2);
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id,help_text) values('ENABLE_LABELS', 1, 'false', 'false', 'Enable labels',3,
+       def_value text not null);
+
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ENABLE_FEED_ICONS', 1, 'true', 'Enable icons in feedlist',2);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ICONS_DIR', 2, 'icons', 'Local directory for feed icons',1);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ICONS_URL', 2, 'icons', 'Local URL for icons',1);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('PURGE_OLD_DAYS', 3, '60', 'Purge old posts after this number of days (0 - disables)',1);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('UPDATE_POST_ON_CHECKSUM_CHANGE', 1, 'true', 'Update post on checksum change',1);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ENABLE_PREFS_CATCHUP_UNCATCHUP', 1, 'false', 'Enable catchup/uncatchup buttons in feed editor',2);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ENABLE_LABELS', 1, 'false', 'Enable labels',3,
        'Experimental support for virtual feeds based on user crafted SQL queries. This feature is highly experimental and at this point not user friendly. Use with caution.');
        
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('DEFAULT_UPDATE_INTERVAL', 3, '30', '30', 'Default interval between feed updates (in minutes)',1);
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('DISPLAY_HEADER', 1, 'true', 'true', 'Display header',2);
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('DISPLAY_FOOTER', 1, 'true', 'true', 'Display footer',2);
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('USE_COMPACT_STYLESHEET', 1, 'false', 'false', 'Use compact stylesheet by default',2);
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id,help_text) values('DEFAULT_ARTICLE_LIMIT', 3, '0', '0', 'Default article limit',2,
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('DEFAULT_UPDATE_INTERVAL', 3, '30', 'Default interval between feed updates (in minutes)',1);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('DISPLAY_HEADER', 1, 'true', 'Display header',2);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('DISPLAY_FOOTER', 1, 'true', 'Display footer',2);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('USE_COMPACT_STYLESHEET', 1, 'false', 'Use compact stylesheet by default',2);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('DEFAULT_ARTICLE_LIMIT', 3, '0', 'Default article limit',2,
        'Default limit for articles to display, any custom number you like (0 - disables).');
        
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id,help_text) values('DAEMON_REFRESH_ONLY', 1, 'false', 'false', 'Daemon refresh only', 3,
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('DAEMON_REFRESH_ONLY', 1, 'false', 'Daemon refresh only', 3,
        'Updates to all feeds will only run when the backend script is invoked with a "daemon" option on the URI stem.');
 
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id,help_text) values('DISPLAY_FEEDLIST_ACTIONS', 1, 'false', 'false', 'Display feedlist actions',2,
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('DISPLAY_FEEDLIST_ACTIONS', 1, 'false', 'Display feedlist actions',2,
        'Display separate dropbox for feedlist actions, if disabled these actions are available in global actions menu.');
 
-insert into ttrss_prefs (pref_name,type_id,value,def_value,short_desc,section_id) values('ENABLE_SPLASH', 1, 'false', 'false', 'Enable loading splashscreen',2);
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ENABLE_SPLASH', 1, 'false', 'Enable loading splashscreen',2);
 
 create table ttrss_user_prefs (
        owner_uid integer not null references ttrss_users(id) on delete cascade,
index ed7e6dc136148ce2af17ec029482d63fd194f45f..769940c707dda6924290d784202f78450f05da38 100644 (file)
@@ -4,12 +4,17 @@
        require_once "version.php"; 
        require_once "config.php";
        require_once "db-prefs.php";
+       require_once "functions.php"; 
 
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
 
        $_SESSION["uid"] = PLACEHOLDER_UID; // FIXME: placeholder
        $_SESSION["name"] = PLACEHOLDER_NAME;
 
+
+       initialize_user_prefs($link, $_SESSION["uid"]); 
+       // FIXME this needs to be moved somewhere after user creation
+
 ?>
 <html>
 <head>