summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2005-11-18 06:17:17 +0100
committerAndrew Dolgov <[email protected]>2005-11-18 06:17:17 +0100
commitff485f1d509abd45638dac0e8d644f3496a5b072 (patch)
tree7482625c953633f0975e1c69476d8abd67d8225f
parent46a1969d75faabb9b941287b3de3e6a6de782feb (diff)
per-user preferences
-rw-r--r--backend.php16
-rw-r--r--db-prefs.php8
-rw-r--r--error.php6
-rw-r--r--functions.php32
-rw-r--r--prefs.php5
-rw-r--r--schema/ttrss_schema_pgsql.sql35
-rw-r--r--tt-rss.php5
7 files changed, 78 insertions, 29 deletions
diff --git a/backend.php b/backend.php
index 54bd1e069..bc75ead8a 100644
--- a/backend.php
+++ b/backend.php
@@ -1555,8 +1555,8 @@
// 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"]);
}
@@ -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 "<form action=\"backend.php\" method=\"POST\">";
diff --git a/db-prefs.php b/db-prefs.php
index 7ff64a89c..a2a25d3e5 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 8582f257c..5e915483d 100644
--- 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);
diff --git a/functions.php b/functions.php
index 8b6bc6620..d07ce024f 100644
--- a/functions.php
+++ b/functions.php
@@ -484,4 +484,36 @@
}
}
+ 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");
+
+ }
+
?>
diff --git a/prefs.php b/prefs.php
index ab76f38ff..690de6abc 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
+
?>
<html>
<head>
diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql
index 407b3647c..97efd1b6d 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 ed7e6dc13..769940c70 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
+
?>
<html>
<head>