]> git.wh0rd.org - tt-rss.git/commitdiff
implement settings profiles (bump schema)
authorAndrew Dolgov <fox@bah.org.ru>
Wed, 13 Jan 2010 15:31:51 +0000 (18:31 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Wed, 13 Jan 2010 15:31:51 +0000 (18:31 +0300)
18 files changed:
backend.php
db-prefs.php
functions.js
functions.php
login_form.php
modules/backend-rpc.php
modules/popup-dialog.php
modules/pref-feeds.php
modules/pref-prefs.php
prefs.js
prefs.php
sanity_check.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/63.sql [new file with mode: 0644]
schema/versions/pgsql/63.sql [new file with mode: 0644]
themes/compact/theme.css
tt-rss.php

index f1b9cd34370e5873b8bc061a45310a48f0dc4bcb..7757931f3e38ccd75bc3ec58899fa24345fa548f 100644 (file)
@@ -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;
                        $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 "<select style='width: 100%' name='profile'>";
+
+                               print "<option value='0'>" . __("Default profile") . "</option>";
+
+                               while ($line = db_fetch_assoc($result)) {
+                                       $id = $line["id"];
+                                       $title = $line["title"];
+
+                                       print "<option value='$id'>$title</option>";
+                               }
+
+                               print "</select>";
+
+                               $_SESSION = array();
+
+               break;
+               }
+
        } // Select action according to $op value.
 
        // We close the connection to database.
index ecd38053552fa4a526143fd6b9364e1ab003c228..1c9bbd11659e94d057c98208ff2a3d173329ed39 100644 (file)
 
                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
                }
        }
 
-       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");
 
                        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();
index aa9bdcefe30897820cf73dc492d160ee60a4405f..1b676a9ef245580150c1f66ab30063634c33481a 100644 (file)
@@ -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');
index a0ec1c3fb4c1fbbde3bfcdaba0ff20a8390ea57b..672d9ef1d60b6c6348c69567ff78c469a20a12dc 100644 (file)
                }
        }
 
-       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();
 
 //                             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"]."')");
+                                       (owner_uid,pref_name,value, profile) VALUES 
+                                       ('$uid', '".$line["pref_name"]."','".$line["def_value"]."', $profile)");
 
                        }
                }
        
                                $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");
        
 
                        $user_theme = get_user_theme_path($link);
        
-                       $_SESSION["theme"] = $user_theme;
                        $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
        
                        initialize_user_prefs($link, $_SESSION["uid"]);
                                        $_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;
 
        }
 
        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 {
                        }
                }
 
-               print "<param key=\"theme\" value=\"".$_SESSION["theme"]."\"/>";
+               print "<param key=\"theme\" value=\"".get_user_theme_path($link)."\"/>";
                print "<param key=\"daemon_enabled\" value=\"" . ENABLE_UPDATE_DAEMON . "\"/>";
                print "<param key=\"feeds_frame_refresh\" value=\"" . FEEDS_FRAME_REFRESH . "\"/>";
                print "<param key=\"daemon_refresh_only\" value=\"true\"/>";
                }
 
                $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;
        }
 
                $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();
 
                return ($parts['scheme'] == 'http' || $parts['scheme'] == 'feed' || $parts['scheme'] == 'https');
 
        }
+
 ?>
index 884a13628919710a05d5a92240ad039caaa2fab1..af5e70e9b8e07dd5e5f9de59713537155b208f46 100644 (file)
@@ -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;
 </script>
 
-<form action="" method="POST" name="loginForm" onsubmit="return validateLoginForm(this)">
+<form action="" method="POST" id="loginForm" name="loginForm" onsubmit="return validateLoginForm(this)">
 <input type="hidden" name="login_action" value="do_login">
 
 <table width="100%" class="loginForm2">
@@ -104,9 +125,11 @@ window.onload = init;
                <table>
                        <tr><td align="right"><?php echo __("Login:") ?></td>
                        <td align="right"><input name="login" 
+                               onchange="fetchProfiles()"
                                value="<?php echo $_SERVER["REMOTE_USER"] ?>"></td></tr>
                        <tr><td align="right"><?php echo __("Password:") ?></td>
                        <td align="right"><input type="password" name="password"
+                               onchange="fetchProfiles()"
                                value="<?php echo $_SERVER["REMOTE_USER"] ?>"></td></tr>
                        <?php if (ENABLE_TRANSLATIONS) { ?>
                        <tr><td align="right"><?php echo __("Language:") ?></td>
@@ -118,6 +141,13 @@ window.onload = init;
                        ?>
                        </td></tr>
                        <?php } ?>
+
+                       <tr><td align="right"><?php echo __("Profile:") ?></td>
+                       <td align="right" id="profile_box">
+                       <select style='width : 100%' disabled='1'>
+                               <option><?php echo __("Default profile") ?></option></select>
+                       </td></tr>
+
                        <!-- <tr><td colspan="2">
                                <input type="checkbox" name="remember_me" id="remember_me">
                                <label for="remember_me">Remember me on this computer</label>
index 1e0732ef82a612ecb48fae91459a6cf40e9328c9..adefbd5a5f21e8ae673c6dc9220c2567b113483c 100644 (file)
@@ -3,6 +3,87 @@
 
                $subop = $_REQUEST["subop"];
 
+               if ($subop == "setprofile") {
+                       $id = db_escape_string($_REQUEST["id"]);
+
+                       $_SESSION["profile"] = $id;
+                       $_SESSION["prefs_cache"] = array();
+                       return;
+               }
+
+               if ($subop == "remprofiles") {
+                       $ids = split(",", db_escape_string(trim($_REQUEST["ids"])));
+
+                       foreach ($ids as $id) {
+                               if ($_SESSION["profile"] != $id) {
+                                       db_query($link, "DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND
+                                               owner_uid = " . $_SESSION["uid"]);
+                               }
+                       }
+                       return;
+               }
+
+               if ($subop == "addprofile") {
+                       $title = db_escape_string(trim($_REQUEST["title"]));
+                       if ($title) {
+                               db_query($link, "BEGIN");
+
+                               $result = db_query($link, "SELECT id FROM ttrss_settings_profiles
+                                       WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]);
+
+                               if (db_num_rows($result) == 0) {
+
+                                       db_query($link, "INSERT INTO ttrss_settings_profiles (title, owner_uid)
+                                               VALUES ('$title', ".$_SESSION["uid"] .")");
+       
+                                       $result = db_query($link, "SELECT id FROM ttrss_settings_profiles WHERE
+                                               title = '$title'");
+       
+                                       if (db_num_rows($result) != 0) {
+                                               $profile_id = db_fetch_result($result, 0, "id");
+       
+                                               if ($profile_id) {
+                                                       initialize_user_prefs($link, $_SESSION["uid"], $profile_id); 
+                                               }
+                                       }
+                               }
+
+                               db_query($link, "COMMIT");
+                       }
+                       return;
+               }
+
+               if ($subop == "saveprofile") {
+                       $id = db_escape_string($_REQUEST["id"]);
+                       $title = db_escape_string(trim($_REQUEST["value"]));
+
+                       if ($id == 0) {
+                               print __("Default profile");
+                               return;
+                       }
+
+                       if ($title) {
+                               db_query($link, "BEGIN");
+
+                               $result = db_query($link, "SELECT id FROM ttrss_settings_profiles
+                                       WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]);
+
+                               if (db_num_rows($result) == 0) {
+                                       db_query($link, "UPDATE ttrss_settings_profiles
+                                               SET title = '$title' WHERE id = '$id' AND
+                                               owner_uid = " . $_SESSION["uid"]);
+                                       print $title;
+                               } else {
+                                       $result = db_query($link, "SELECT title FROM ttrss_settings_profiles
+                                               WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]);
+                                       print db_fetch_result($result, 0, "title");
+                               }
+
+                               db_query($link, "COMMIT");
+                       }                       
+                       return;
+               }
+
                if ($subop == "remarchive") {
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
 
 
                        print "<rpc-reply>";
 
-                       set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
+                       set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key(), $_SESSION["uid"]);
 
                        $new_link = article_publish_url($link);         
 
index c3285fb0cebab561bdc3a2f4f77b1463d4a3a530..cca7b053c1275b6331bcebf3cfa24353f14a6570 100644 (file)
@@ -3,6 +3,97 @@
                $id = $_REQUEST["id"];
                $param = db_escape_string($_REQUEST["param"]);
 
+               if ($id == "editPrefProfiles") {
+
+                       print "<div id=\"infoBoxTitle\">".__('Settings Profiles')."</div>";
+                       print "<div class=\"infoBoxContents\">";
+
+                       print "<div><input id=\"fadd_profile\" 
+                                       onkeypress=\"return filterCR(event, addPrefProfile)\"
+                                       size=\"40\">
+                                       <button onclick=\"javascript:addPrefProfile()\">".
+                                       __('Create profile')."</button></div>";
+
+                       print "<p>";
+
+                       $result = db_query($link, "SELECT title,id FROM ttrss_settings_profiles
+                               WHERE owner_uid = ".$_SESSION["uid"]."ORDER BY title");
+
+                       print   __('Select:')." 
+                               <a href=\"javascript:selectPrefRows('fcat', true)\">".__('All')."</a>,
+                               <a href=\"javascript:selectPrefRows('fcat', false)\">".__('None')."</a>";
+
+                       print "<div class=\"prefFeedCatHolder\">";
+
+                       print "<form id=\"profile_edit_form\" onsubmit=\"return false\">";
+
+                       print "<table width=\"100%\" class=\"prefFeedCatList\" 
+                               cellspacing=\"0\" id=\"prefFeedCatList\">";
+
+                       print "<tr class=\"odd\" id=\"FCATR-0\">";
+
+                       print "<td width='5%' align='center'><input 
+                               onclick='toggleSelectPrefRow(this, \"fcat\");' 
+                               type=\"checkbox\" id=\"FCCHK-0\"></td>";
+
+                       print "<td><span id=\"FCATT-0\">" . 
+                               __("Default profile") . "</span></td>";         
+                               
+                       print "</tr>";
+
+                       $lnum = 1;
+                       
+                       while ($line = db_fetch_assoc($result)) {
+       
+                               $class = ($lnum % 2) ? "even" : "odd";
+       
+                               $cat_id = $line["id"];
+                               $this_row_id = "id=\"FCATR-$cat_id\"";
+       
+                               print "<tr class=\"$class\" $this_row_id>";
+       
+                               $edit_title = htmlspecialchars($line["title"]);
+       
+                               print "<td width='5%' align='center'><input 
+                                       onclick='toggleSelectPrefRow(this, \"fcat\");' 
+                                       type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
+
+                               if ($_SESSION["profile"] == $line["id"]) {
+                                       $is_active = __("(active)");
+                               } else {
+                                       $is_active = "";
+                               }
+
+                               print "<td><span id=\"FCATT-$cat_id\">" . 
+                                       $edit_title . "</span> $is_active</td>";
+                               
+                               print "</tr>";
+       
+                               ++$lnum;
+                       }
+
+                       print "</table>";
+                       print "</form>";
+                       print "</div>";
+
+                       print "<div class='dlgButtons'>
+                               <div style='float : left'>
+                               <button onclick=\"return removeSelectedPrefProfiles()\">".
+                               __('Remove')."</button>
+                               <input class=\"button\"
+                               type=\"submit\" onclick=\"return activatePrefProfile()\" 
+                               value=\"".__('Activate')."\">
+                               </div>";
+
+                       print "<input class=\"button\"
+                               type=\"submit\" onclick=\"return closeInfoBox()\" 
+                               value=\"".__('Close this window')."\">";
+
+                       print "</div></div>";
+
+                       return;
+               }
+
                if ($id == "pubUrl") {
 
                        print "<div id=\"infoBoxTitle\">".__('Published Articles')."</div>";
 
                        $owner_uid = $_SESSION["uid"];
 
+/*                     print   __('Select:')." 
+                               <a href=\"javascript:selectPrefRows('fbrowse', true)\">".__('All')."</a>,
+                                       <a href=\"javascript:selectPrefRows('fbrowse', false)\">".__('None')."</a>"; */
+
                        print "<ul class='browseFeedList' id='browseFeedList'>";
                        print_feed_browser($link, $search, 25);
                        print "</ul>";
 
                        print "<div align='center'>
                                <button onclick=\"feedBrowserSubscribe()\">".__('Subscribe')."</button>
-                               <button style='display : none' id='feed_archive_remove' onclick=\"feedArchiveRemove()\">".__('Remove from archive')."</button>
+                               <button style='display : none' id='feed_archive_remove' onclick=\"feedArchiveRemove()\">".__('Remove')."</button>
                                <button onclick=\"closeInfoBox()\" >".__('Cancel')."</button></div>";
 
                        print "</div>";
index 531396cf5b45af2d94691d55c6e886b72be5ef4a..05c796bb39a4c3cc92cca069c4e50fd2d3dd367b 100644 (file)
                                }
                        }
 
-                       print "<div class=\"prefGenericAddBox\">
+                       print "<div>
                                <input id=\"fadd_cat\" 
                                        onkeypress=\"return filterCR(event, addFeedCat)\"
                                        size=\"40\">
index 6fb5fb57650839262eea88ceeff117c7720294fb..b789720d4afa7a1dea25ac651e1ff42be0c58244 100644 (file)
                $prefs_blacklist = array("HIDE_FEEDLIST", "SYNC_COUNTERS", "ENABLE_LABELS",
                        "ENABLE_SEARCH_TOOLBAR", "HIDE_READ_FEEDS");
 
+               $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", 
+                       "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", 
+                       "BLACKLISTED_TAGS", "ENABLE_FEED_ICONS", "ENABLE_API_ACCESS",
+                       "UPDATE_POST_ON_CHECKSUM_CHANGE", "DEFAULT_UPDATE_INTERVAL",
+                       "MARK_UNREAD_ON_UPDATE");
+
                if (FORCE_ARTICLE_PURGE != 0) {
                        array_push($prefs_blacklist, "PURGE_OLD_DAYS");
                        array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
@@ -79,6 +85,8 @@
 
 //                     print_r($_POST);
 
+                       $orig_theme_id = get_pref($link, "_THEME_ID");
+
                        foreach (array_keys($_POST) as $pref_name) {
                        
                                $pref_name = db_escape_string($pref_name);
 
                        }
 
-                       #return prefs_js_redirect();
+                       if ($orig_theme_id != get_pref($link, "_THEME_ID")) {
+
+                               $result = db_query($link, "SELECT theme_path FROM ttrss_themes
+                                       WHERE id = '".get_pref($link, "_THEME_ID")."'");
+
+                               if (db_num_rows($result) == 1) {
+                                       $theme_path = db_fetch_result($result, 0, "theme_path");
+                               } else {
+                                       $theme_path = "";
+                               }
+
+                               $_SESSION["theme"] = $theme_path;
 
-                       print __("The configuration was saved.");
+                               print "PREFS_THEME_CHANGED";
+                       } else {
+                               print __("The configuration was saved.");
+                       }
 
                        return;
 
 
                        return;
 
-               } else if ($subop == "change-theme") {
-
-                       $theme = db_escape_string($_POST["theme"]);
-
-                       if ($theme == "Default") {
-                               $theme_qpart = 'NULL';
-                       } else {
-                               $theme_qpart = "'$theme'";
-                       }
-
-                       $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
-                               WHERE theme_name = '$theme'");
-
-                       if (db_num_rows($result) == 1) {
-                               $theme_id = db_fetch_result($result, 0, "id");
-                               $theme_path = db_fetch_result($result, 0, "theme_path");
-                       } else {
-                               $theme_id = "NULL";
-                               $theme_path = "";
-                       }
-
-                       db_query($link, "UPDATE ttrss_users SET
-                               theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
-
-                       $_SESSION["theme"] = $theme_path;
-
-                       return prefs_js_redirect();
-
                } else {
 
                        set_pref($link, "_PREFS_ACTIVE_TAB", "genConfig");
 
+                       if ($_SESSION["profile"]) {
+                               print_notice("Some preferences are only available in default profile.");
+                       }
+
                        if (!SINGLE_USER_MODE) {
 
                                $result = db_query($link, "SELECT id FROM ttrss_users
 
                        }
 
-                       $result = db_query($link, "SELECT
-                               theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
-
-                       $user_theme_id = db_fetch_result($result, 0, "theme_id");
-
-                       $result = db_query($link, "SELECT
-                               id,theme_name FROM ttrss_themes ORDER BY theme_name");
-
-                       if (db_num_rows($result) > 0) {
-
-                               print "<form action=\"backend.php\" method=\"POST\">";
-                               print "<table width=\"100%\" class=\"prefPrefsList\">";
-                               print "<tr><td colspan='3'><h3>".__("Themes")."</h3></tr></td>";
-                               print "<tr><td width=\"40%\">".__("Select theme")."</td>";
-                               print "<td><select name=\"theme\">";
-                               print "<option value='Default'>".__('Default')."</option>";
-                               print "<option disabled>--------</option>";                             
-                               
-                               while ($line = db_fetch_assoc($result)) {       
-                                       if ($line["id"] == $user_theme_id) {
-                                               $selected = "selected";
-                                       } else {
-                                               $selected = "";
-                                       }
-                                       print "<option $selected>" . $line["theme_name"] . "</option>";
-                               }
-                               print "</select></td></tr>";
-                               print "</table>";
-                               print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
-                               print "<input type=\"hidden\" name=\"subop\" value=\"change-theme\">";
-                               print "<p><button>".__('Change theme')."</button>";
-                               print "</form>";
+                       if ($_SESSION["profile"]) {
+                               initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
+                               $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
+                       } else {
+                               initialize_user_prefs($link, $_SESSION["uid"]);
+                               $profile_qpart = "profile IS NULL";
                        }
 
-                       initialize_user_prefs($link, $_SESSION["uid"]);
-
                        $result = db_query($link, "SELECT 
                                ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
-                               section_name,def_value
+                               section_name,def_value,section_id
                                FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
                                WHERE type_id = ttrss_prefs_types.id AND 
+                                       $profile_qpart AND
                                        section_id = ttrss_prefs_sections.id AND
                                        ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
                                        short_desc != '' AND
                                        continue;
                                }
 
+                               if ($_SESSION["profile"] && in_array($line["pref_name"], 
+                                               $profile_blacklist)) {
+                                       continue;
+                               }
+
                                if ($active_section != $line["section_name"]) {
 
                                        if ($active_section != "") {
                                        }
 
                                        print "<p><table width=\"100%\" class=\"prefPrefsList\">";
-                               
+
                                        $active_section = $line["section_name"];                                
                                        
                                        print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
+
+                                       if ($line["section_id"] == 2) {
+                                               print "<tr><td width=\"40%\">".__("Select theme")."</td>";
+                                               print "<td><select name=\"_THEME_ID\">";
+                                               print "<option value='0'>".__('Default')."</option>";
+                                               print "<option disabled>--------</option>";                             
+                       
+                                               $user_theme_id = get_pref($link, "_THEME_ID");
+                       
+                                               $tmp_result = db_query($link, "SELECT
+                                                       id,theme_name FROM ttrss_themes ORDER BY theme_name");
+                       
+                                               while ($tmp_line = db_fetch_assoc($tmp_result)) {       
+                                                       if ($tmp_line["id"] == $user_theme_id) {
+                                                               $selected = "selected";
+                                                       } else {
+                                                               $selected = "";
+                                                       }
+                                                       print "<option value=\"".$tmp_line["id"]."\" $selected>" . 
+                                                               $tmp_line["theme_name"] . "</option>";
+                                               }
+                                               print "</select></td></tr>";
+                                       }
+
 //                                     print "<tr class=\"title\">
 //                                             <td width=\"25%\">Option</td><td>Value</td></tr>";
 
 
                        print "<p><button onclick=\"return validatePrefsSave()\">".
                                __('Save configuration')."</button> ";
-                               
+
+                       print "<button onclick=\"return editProfiles()\">".
+                               __('Manage profiles')."</button> ";
+
                        print "<button onclick=\"return validatePrefsReset()\">".
                                __('Reset to defaults')."</button></p>";
 
index 59e455443dd3e3d8b263fe63722b965fb5e3e2d5..cc0a8e978faf8f2c907df03b03798fd138d86087 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -121,6 +121,26 @@ function notify_callback2(transport) {
        notify_info(transport.responseText);     
 }
 
+function init_profile_inline_editor() {
+       try {
+
+               if ($("prefFeedCatList")) {
+                       var elems = $("prefFeedCatList").getElementsByTagName("SPAN");
+
+                       for (var i = 0; i < elems.length; i++) {
+                               if (elems[i].id && elems[i].id.match("FCATT-")) {
+                                       var id = elems[i].id.replace("FCATT-", "");
+                                               new Ajax.InPlaceEditor(elems[i],
+                                               'backend.php?op=rpc&subop=saveprofile&id=' + id);
+                               }
+                       }
+               }
+
+       } catch (e) {
+               exception_error("init_profile_inline_editor", e);
+       }
+}
+
 function init_cat_inline_editor() {
        try {
 
@@ -267,6 +287,28 @@ function addFeed() {
 
 }
 
+function addPrefProfile() {
+
+       var profile = $("fadd_profile");
+
+       if (profile.value.length == 0) {
+               alert(__("Can't add profile: no name specified."));
+       } else {
+               notify_progress("Adding profile...");
+
+               var query = "?op=rpc&subop=addprofile&title=" + 
+                       param_escape(profile.value);
+
+               new Ajax.Request("backend.php", {
+                       parameters: query,
+                       onComplete: function(transport) {
+                                       editProfiles();
+                               } });
+
+       }
+}
+
+
 function addFeedCat() {
 
        var cat = $("fadd_cat");
@@ -616,6 +658,34 @@ function purgeSelectedFeeds() {
        return false;
 }
 
+function removeSelectedPrefProfiles() {
+
+       var sel_rows = getSelectedFeedCats();
+
+       if (sel_rows.length > 0) {
+
+               var ok = confirm(__("Remove selected profiles? Active and default profiles will not be removed."));
+
+               if (ok) {
+                       notify_progress("Removing selected profiles...");
+       
+                       var query = "?op=rpc&subop=remprofiles&ids="+
+                               param_escape(sel_rows.toString());
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       editProfiles();
+                               } });
+               }
+
+       } else {
+               alert(__("No profiles selected."));
+       }
+
+       return false;
+}
+
 function removeSelectedFeedCats() {
 
        var sel_rows = getSelectedFeedCats();
@@ -1207,7 +1277,7 @@ function validatePrefsReset() {
                }
 
        } catch (e) {
-               exception_error("validatePrefsSave", e);
+               exception_error("validatePrefsReset", e);
        }
 
        return false;
@@ -1282,6 +1352,11 @@ function selectPrefRows(kind, select) {
                        nrow = "UMRR-";
                        nchk = "UMCHK-";
                        lname = "prefUserList";
+               } else if (kind == "fbrowse") {
+                       opbarid = "browseOpToolbar";
+                       nrow = "FBROW-";
+                       nchk = "FBCHK-";
+                       lname = "browseFeedList";
                }
 
                if (opbarid) {
@@ -1685,7 +1760,12 @@ function validatePrefsSave() {
                        new Ajax.Request("backend.php", {
                                parameters: query,
                                onComplete: function(transport) { 
-                               notify_callback2(transport); 
+                                       var msg = transport.responseText;
+                                       if (msg.match("PREFS_THEME_CHANGED")) {
+                                               window.location.reload();
+                                       } else {
+                                               notify_info(msg);
+                                       }
                        } });
 
                }
@@ -2104,3 +2184,39 @@ function mouse_up_handler(e) {
 function inPreferences() {
        return true;
 }
+
+function editProfiles() {
+       displayDlg('editPrefProfiles', false, function() {
+               init_profile_inline_editor();                   
+                       });
+}
+
+function activatePrefProfile() {
+
+       var sel_rows = getSelectedFeedCats();
+
+       if (sel_rows.length == 1) {
+
+               var ok = confirm(__("Activate selected profile?"));
+
+               if (ok) {
+                       notify_progress("Loading, please wait...");
+       
+                       var query = "?op=rpc&subop=setprofile&id="+
+                               param_escape(sel_rows.toString());
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       window.location.reload();
+                               } });
+               }
+
+       } else {
+               alert(__("Please choose a profile to activate."));
+       }
+
+       return false;
+}
+
+
index cae69a54fa80a300c393d2b8de407dd86f0cf2c8..8a0b5237aac7b6cb5084dde0512094dc677c2b95 100644 (file)
--- a/prefs.php
+++ b/prefs.php
@@ -26,7 +26,7 @@
        <title>Tiny Tiny RSS : Preferences</title>
        <link rel="stylesheet" type="text/css" href="tt-rss.css?<?php echo $dt_add ?>"/>
 
-       <?php   $user_theme = $_SESSION["theme"];
+       <?php   $user_theme = get_user_theme_path($link);
                if ($user_theme) { ?>
                <link rel="stylesheet" type="text/css" href="themes/<?php echo $user_theme ?>/theme.css"/>
        <?php } ?>
index 950dff766169a6cbd9bcc4e82ac8b0a3859c0c5e..c50d391a11c271a7e17a043a75104f77155ba00f 100644 (file)
@@ -2,7 +2,7 @@
        require_once "functions.php";
 
        define('EXPECTED_CONFIG_VERSION', 18);
-       define('SCHEMA_VERSION', 62);
+       define('SCHEMA_VERSION', 63);
 
        if (!file_exists("config.php")) {
                print "<b>Fatal Error</b>: You forgot to copy 
index e2f9729aab526743c23a325cbb9d758dbd4cda0b..862ae3a428436eb5a93e75327480b2fb9e32e940 100644 (file)
@@ -15,6 +15,7 @@ drop table if exists ttrss_prefs_types;
 drop table if exists ttrss_prefs_sections; 
 drop table if exists ttrss_tags;
 drop table if exists ttrss_enclosures;
+drop table if exists ttrss_settings_profiles;
 drop table if exists ttrss_entry_comments;
 drop table if exists ttrss_user_entries;
 drop table if exists ttrss_entries;
@@ -238,9 +239,9 @@ 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 (62);
+insert into ttrss_version values (63);
 
-create table ttrss_enclosures (id serial not null primary key,
+create table ttrss_enclosures (id integer primary key auto_increment,
        content_url text not null,
        content_type varchar(250) not null,
        post_id integer not null,
@@ -249,6 +250,12 @@ create table ttrss_enclosures (id serial not null primary key,
        index (post_id),
        foreign key (post_id) references ttrss_entries(id) ON DELETE cascade) TYPE=InnoDB;
 
+create table ttrss_settings_profiles(id integer primary key auto_increment,
+       title varchar(250) not null,
+       owner_uid integer not null,
+       index (owner_uid),
+       foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) TYPE=InnoDB;
+
 create table ttrss_prefs_types (id integer not null primary key, 
        type_name varchar(100) not null) TYPE=InnoDB;
 
@@ -389,10 +396,15 @@ 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('_MOBILE_SORT_FEEDS_UNREAD', 1, 'false', '', 1);
 
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_THEME_ID', 3, '0', '', 1);
+
 create table ttrss_user_prefs (
    owner_uid integer not null,
    pref_name varchar(250),
    value text not null,
+       profile integer,
+       index (profile),
+       foreign key (profile) references ttrss_settings_profiles(id) ON DELETE CASCADE,
        index (owner_uid),
        foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE,
        index (pref_name),
index f242a6bba83aaa2c12d2d19260b6ca67f699de00..fb2ac18222fb7c10a8da73460dcd41f711741e37 100644 (file)
@@ -12,6 +12,7 @@ drop table ttrss_prefs_types;
 drop table ttrss_prefs_sections; 
 drop table ttrss_tags;
 drop table ttrss_enclosures;
+drop table ttrss_settings_profiles;
 drop table ttrss_entry_comments;
 drop table ttrss_user_entries;
 drop table ttrss_entries;
@@ -210,7 +211,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 (62);
+insert into ttrss_version values (63);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
@@ -219,6 +220,10 @@ create table ttrss_enclosures (id serial not null primary key,
        duration text not null,
        post_id integer references ttrss_entries(id) ON DELETE cascade NOT NULL);
 
+create table ttrss_settings_profiles(id serial not null primary key,
+       title varchar(250) not null,
+       owner_uid integer not null references ttrss_users(id) on delete cascade);
+
 create table ttrss_prefs_types (id integer not null primary key, 
        type_name varchar(100) not null);
 
@@ -355,9 +360,12 @@ 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('_MOBILE_SORT_FEEDS_UNREAD', 1, 'false', '', 1);
 
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_THEME_ID', 3, '0', '', 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,
+       profile integer references ttrss_settings_profiles(id) ON DELETE CASCADE,
        value text not null);
 
 create index ttrss_user_prefs_owner_uid_index on ttrss_user_prefs(owner_uid);
diff --git a/schema/versions/mysql/63.sql b/schema/versions/mysql/63.sql
new file mode 100644 (file)
index 0000000..e5b5399
--- /dev/null
@@ -0,0 +1,18 @@
+begin;
+
+create table ttrss_settings_profiles(id integer primary key auto_increment,
+       title varchar(250) not null,
+       owner_uid integer not null,
+       index (owner_uid),
+       foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) TYPE=InnoDB;
+
+alter table ttrss_user_prefs add column profile integer;
+update ttrss_user_prefs set profile = NULL;
+
+alter table ttrss_user_prefs add FOREIGN KEY (profile) REFERENCES ttrss_settings_profiles(id) ON DELETE CASCADE;
+
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_THEME_ID', 3, '0', '', 1);
+
+update ttrss_version set schema_version = 63;
+
+commit;
diff --git a/schema/versions/pgsql/63.sql b/schema/versions/pgsql/63.sql
new file mode 100644 (file)
index 0000000..90bde31
--- /dev/null
@@ -0,0 +1,16 @@
+begin;
+
+create table ttrss_settings_profiles(id serial not null primary key,
+       title varchar(250) not null,
+       owner_uid integer not null references ttrss_users(id) on delete cascade);
+
+alter table ttrss_user_prefs add column profile integer;
+update ttrss_user_prefs set profile = NULL;
+
+alter table ttrss_user_prefs add constraint "$3" FOREIGN KEY (profile) REFERENCES ttrss_settings_profiles(id) ON DELETE CASCADE;
+
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('_THEME_ID', 3, '0', '', 1);
+
+update ttrss_version set schema_version = 63;
+
+commit;
index f9ff384b7e6133b1f8e139b7b2b91f429c631923..a221497ced9866898c324f2fd808ed574f41cca9 100644 (file)
@@ -37,7 +37,7 @@ div.postReply div.postHeader {
        border-width : 0px 0px 1px 1px;
 }
 
-#prefContent {
+#prefContentOuter {
        bottom : 0px;
 }
 
index ed4171a9b0ca1c1ff8f2df02aa13fbb9abd01c97..bf5575b95c56bea0ba4e1d017c58c3d238ab1934 100644 (file)
@@ -27,7 +27,7 @@
 
        <link rel="stylesheet" type="text/css" href="tt-rss.css?<?php echo $dt_add ?>"/>
 
-       <?php   $user_theme = $_SESSION["theme"];
+       <?php   $user_theme = get_user_theme_path($link);
                if ($user_theme) { ?>
                        <link rel="stylesheet" type="text/css" href="themes/<?php echo $user_theme ?>/theme.css?<?php echo $dt_add ?>">
        <?php } ?>