From ff485f1d509abd45638dac0e8d644f3496a5b072 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 18 Nov 2005 06:17:17 +0100 Subject: [PATCH] per-user preferences --- backend.php | 16 ++++++++++------ db-prefs.php | 8 ++++++-- error.php | 6 +++--- functions.php | 32 ++++++++++++++++++++++++++++++++ prefs.php | 5 +++++ schema/ttrss_schema_pgsql.sql | 35 +++++++++++++++++------------------ tt-rss.php | 5 +++++ 7 files changed, 78 insertions(+), 29 deletions(-) diff --git a/backend.php b/backend.php index 54bd1e06..bc75ead8 100644 --- a/backend.php +++ b/backend.php @@ -1555,8 +1555,8 @@ // print "$pref_name : $type_name : $value
"; - 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"]); } @@ -1582,18 +1582,22 @@ 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 "
"; diff --git a/db-prefs.php b/db-prefs.php index 7ff64a89..a2a25d3e 100644 --- a/db-prefs.php +++ b/db-prefs.php @@ -10,8 +10,12 @@ $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"); diff --git a/error.php b/error.php index 8582f257..5e915483 100644 --- a/error.php +++ b/error.php @@ -1,7 +1,7 @@ "; + + 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"); + + } + ?> diff --git a/prefs.php b/prefs.php index ab76f38f..690de6ab 100644 --- 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 + ?> diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 407b3647..97efd1b6 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -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, diff --git a/tt-rss.php b/tt-rss.php index ed7e6dc1..769940c7 100644 --- a/tt-rss.php +++ b/tt-rss.php @@ -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 + ?> -- 2.39.5