From d9084cf22059f709e935c6c0755d2b69c21b3a87 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 13 Jan 2010 18:31:51 +0300 Subject: [PATCH] implement settings profiles (bump schema) --- backend.php | 29 ++++++- db-prefs.php | 26 ++++++- functions.js | 2 +- functions.php | 48 ++++++++---- login_form.php | 32 +++++++- modules/backend-rpc.php | 83 +++++++++++++++++++- modules/popup-dialog.php | 97 +++++++++++++++++++++++- modules/pref-feeds.php | 2 +- modules/pref-prefs.php | 137 +++++++++++++++++----------------- prefs.js | 120 ++++++++++++++++++++++++++++- prefs.php | 2 +- sanity_check.php | 2 +- schema/ttrss_schema_mysql.sql | 16 +++- schema/ttrss_schema_pgsql.sql | 10 ++- schema/versions/mysql/63.sql | 18 +++++ schema/versions/pgsql/63.sql | 16 ++++ themes/compact/theme.css | 2 +- tt-rss.php | 2 +- 18 files changed, 548 insertions(+), 96 deletions(-) create mode 100644 schema/versions/mysql/63.sql create mode 100644 schema/versions/pgsql/63.sql diff --git a/backend.php b/backend.php index f1b9cd34..7757931f 100644 --- a/backend.php +++ b/backend.php @@ -49,6 +49,7 @@ init_connection($link); $op = $_REQUEST["op"]; + $subop = $_REQUEST["subop"]; $mode = $_REQUEST["mode"]; $print_exec_time = false; @@ -81,7 +82,7 @@ } if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" - && $op != "rss" && $op != "getUnread" && $op != "publish") { + && $op != "rss" && $op != "getUnread" && $op != "publish" && $op != "getProfiles") { if ($op == "rpc" || $op == "viewfeed" || $op == "view") { print_error_xml(6); die; @@ -506,6 +507,32 @@ $print_exec_time = false; break; // digestSend + case "getProfiles": + $login = db_escape_string($_REQUEST["login"]); + $password = db_escape_string($_REQUEST["password"]); + + if (authenticate_user($link, $login, $password)) { + $result = db_query($link, "SELECT * FROM ttrss_settings_profiles + WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title"); + + print ""; + + $_SESSION = array(); + + break; + } + } // Select action according to $op value. // We close the connection to database. diff --git a/db-prefs.php b/db-prefs.php index ecd38053..1c9bbd11 100644 --- a/db-prefs.php +++ b/db-prefs.php @@ -14,11 +14,19 @@ if (!$user_id) { $user_id = $_SESSION["uid"]; + $profile = $_SESSION["profile"]; } else { $user_id = sprintf("%d", $user_id); $prefs_cache = false; } + if ($profile) { + $profile_qpart = "profile = '$profile'"; + } else { + $profile_qpart = "profile IS NULL"; + } + + if ($prefs_cache && !defined('DISABLE_SESSIONS') && !SINGLE_USER_MODE) { if ($_SESSION["prefs_cache"] && $_SESSION["prefs_cache"][$pref_name]) { $tuple = $_SESSION["prefs_cache"][$pref_name]; @@ -31,6 +39,7 @@ FROM ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types WHERE + $profile_qpart AND ttrss_user_prefs.pref_name = '$pref_name' AND ttrss_prefs_types.id = type_id AND owner_uid = '$user_id' AND @@ -68,10 +77,24 @@ } } - function set_pref($link, $key, $value) { + function set_pref($link, $key, $value, $user_id) { $key = db_escape_string($key); $value = db_escape_string($value); + if (!$user_id) { + $user_id = $_SESSION["uid"]; + $profile = $_SESSION["profile"]; + } else { + $user_id = sprintf("%d", $user_id); + $prefs_cache = false; + } + + if ($profile) { + $profile_qpart = "profile = '$profile'"; + } else { + $profile_qpart = "profile IS NULL"; + } + $result = db_query($link, "SELECT type_name FROM ttrss_prefs,ttrss_prefs_types WHERE pref_name = '$key' AND type_id = ttrss_prefs_types.id"); @@ -96,6 +119,7 @@ db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' WHERE pref_name = '$key' + AND $profile_qpart AND owner_uid = " . $_SESSION["uid"]); $_SESSION["prefs_cache"] = array(); diff --git a/functions.js b/functions.js index aa9bdcef..1b676a9e 100644 --- a/functions.js +++ b/functions.js @@ -2224,7 +2224,7 @@ function feedArchiveRemove() { if (selected.length > 0) { - var pr = __("Remove selected feeds from archive?"); + var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed."); if (confirm(pr)) { Element.show('feed_browser_spinner'); diff --git a/functions.php b/functions.php index a0ec1c3f..672d9ef1 100644 --- a/functions.php +++ b/functions.php @@ -1679,16 +1679,23 @@ } } - function initialize_user_prefs($link, $uid) { + function initialize_user_prefs($link, $uid, $profile = false) { $uid = db_escape_string($uid); + if (!$profile) { + $profile = "NULL"; + $profile_qpart = "profile IS NULL"; + } else { + $profile_qpart = "profile = '$profile'"; + } + 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'"); + FROM ttrss_user_prefs WHERE owner_uid = '$uid' AND $profile_qpart"); $active_prefs = array(); @@ -1701,8 +1708,8 @@ // print "adding " . $line["pref_name"] . "
"; db_query($link, "INSERT INTO ttrss_user_prefs - (owner_uid,pref_name,value) VALUES - ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')"); + (owner_uid,pref_name,value, profile) VALUES + ('$uid', '".$line["pref_name"]."','".$line["def_value"]."', $profile)"); } } @@ -1783,7 +1790,6 @@ $user_theme = get_user_theme_path($link); - $_SESSION["theme"] = $user_theme; $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; $_SESSION["pwd_hash"] = db_fetch_result($result, 0, "pwd_hash"); @@ -1801,7 +1807,6 @@ $user_theme = get_user_theme_path($link); - $_SESSION["theme"] = $user_theme; $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; initialize_user_prefs($link, $_SESSION["uid"]); @@ -1926,6 +1931,19 @@ $_SESSION["language"] = $_POST["language"]; $_SESSION["bw_limit"] = !!$_POST["bw_limit"]; + if ($_POST["profile"]) { + + $profile = db_escape_string($_POST["profile"]); + + $result = db_query($link, "SELECT id FROM ttrss_settings_profiles + WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + $_SESSION["profile"] = $profile; + $_SESSION["prefs_cache"] = array(); + } + } + header("Location: " . $_SERVER["REQUEST_URI"]); exit; @@ -1968,10 +1986,10 @@ } function get_user_theme_path($link) { + $theme_id = get_pref($link, "_THEME_ID"); + $result = db_query($link, "SELECT theme_path - FROM - ttrss_themes,ttrss_users - WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]); + FROM ttrss_themes WHERE id = '$theme_id'"); if (db_num_rows($result) != 0) { return db_fetch_result($result, 0, "theme_path"); } else { @@ -3039,7 +3057,7 @@ } } - print ""; + print ""; print ""; print ""; print ""; @@ -5570,7 +5588,8 @@ } $url_path .= $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); - $url_path .= "/backend.php?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY"); + $url_path .= "/backend.php?op=publish&key=" . + get_pref($link, "_PREFS_PUBLISH_KEY", $_SESSION["uid"]); return $url_path; } @@ -6206,11 +6225,13 @@ $num_tags = 0; - if ($_SESSION["theme"] == "3pane") { +/* if (get_user_theme_path($link) == "3pane") { $tag_limit = 3; } else { $tag_limit = 6; - } + } */ + + $tag_limit = 6; $formatted_tags = array(); @@ -6415,4 +6436,5 @@ return ($parts['scheme'] == 'http' || $parts['scheme'] == 'feed' || $parts['scheme'] == 'https'); } + ?> diff --git a/login_form.php b/login_form.php index 884a1362..af5e70e9 100644 --- a/login_form.php +++ b/login_form.php @@ -28,6 +28,27 @@ function init() { login.focus(); } +function fetchProfiles() { + try { + var params = Form.serialize('loginForm'); + var query = "?op=getProfiles&" + params; + + if (query) { + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + if (transport.responseText.match("select")) { + $('profile_box').innerHTML = transport.responseText; + } + } }); + } + + } catch (e) { + exception_error("fetchProfiles", e); + } +} + + function languageChange(elem) { try { document.forms['loginForm']['click'].disabled = true; @@ -87,7 +108,7 @@ if (document.addEventListener) { window.onload = init; -
+ @@ -104,9 +125,11 @@ window.onload = init;
@@ -118,6 +141,13 @@ window.onload = init; ?> + + + +
">
">
+ +