]> git.wh0rd.org - tt-rss.git/blobdiff - functions.php
implement settings profiles (bump schema)
[tt-rss.git] / functions.php
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');
 
        }
+
 ?>