]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
display help_text in prefs editor
[tt-rss.git] / backend.php
index 954c4dacacf4a05a13ee14ac38aa67a177e60909..e413fbafb989741586f5715cd134b1695f8a58ca 100644 (file)
@@ -1,7 +1,7 @@
 <?
        define(SCHEMA_VERSION, 2);
 
-       $op = $_GET["op"];
+       $op = $_REQUEST["op"];
 
        if ($op == "rpc" || $op == "updateAllFeeds") {
                header("Content-Type: application/xml");
@@ -16,7 +16,6 @@
        $script_started = getmicrotime();
 
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
-       $dbprefs_link = $link;
 
        if (!$link) {
                if (DB_TYPE == "mysql") {
                        <title>Tiny Tiny RSS : Feedlist</title>
                        <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
 
-               if (USE_COMPACT_STYLESHEET) {
+               if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
                        print "<link rel=\"stylesheet\" type=\"text/css\" 
                                href=\"tt-rss_compact.css\"/>";
                } else {
                        if ($num_starred > 0) $class .= "Unread";
 
                        printFeedEntry(-1, $class, "Starred articles", $num_starred, 
-                               "images/mark_set.png");
+                               "images/mark_set.png", $link);
 
-                       if (ENABLE_LABELS) {
+                       if (get_pref($link, 'ENABLE_LABELS')) {
        
                                $result = db_query($link, "SELECT id,sql_exp,description FROM
                                        ttrss_labels ORDER by description");
                                        error_reporting (E_ERROR | E_WARNING | E_PARSE);
        
                                        printFeedEntry(-$line["id"]-11, 
-                                               $class, $line["description"], $count, "images/label.png");
+                                               $class, $line["description"], $count, "images/label.png", $link);
                
                                }
                        }
        
                                $total_unread += $unread;
        
-                               printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
+                               printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link);
        
                                ++$lnum;
                        }
                                        $class .= "Unread";
                                }
        
-                               printFeedEntry($tag, $class, $tag, $unread, "images/tag.png");
+                               printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
        
                        } 
 
                                <title>Tiny Tiny RSS : Feed $feed</title>
                                <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
 
-                       if (USE_COMPACT_STYLESHEET) {
+                       if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
                                print "<link rel=\"stylesheet\" 
                                                type=\"text/css\" href=\"tt-rss_compact.css\"/>";
 
 
                                foreach ($ids as $id) {
                                        db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
+
+                                       $icons_dir = get_pref($link, 'ICONS_DIR');
                                        
-                                       if (file_exists(ICONS_DIR . "/$id.ico")) {
-                                               unlink(ICONS_DIR . "/$id.ico");
+                                       if (file_exists($icons_dir . "/$id.ico")) {
+                                               unlink($icons_dir . "/$id.ico");
                                        }
                                }
                        }
 
                        print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
 
-                       $icon_file = ICONS_DIR . "/$feed_id.ico";
+                       $icon_file = get_pref($link, 'ICONS_DIR') . "/$feed_id.ico";
 
                        if (file_exists($icon_file) && filesize($icon_file) > 0) {
                                        $feed_icon = "<img width=\"16\" height=\"16\"
-                                               src=\"" . ICONS_URL . "/$feed_id.ico\">";
+                                               src=\"" . get_pref($link, 'ICONS_URL') . "/$feed_id.ico\">";
                        } else {
                                $feed_icon = "&nbsp;";
                        }
                        <input type=\"submit\" class=\"button\" 
                                onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
                                
-                       if (ENABLE_PREFS_CATCHUP_UNCATCHUP) {
+                       if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
                                print "
                                <input type=\"submit\" class=\"button\" 
                                        onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
 
        }
 
+       if ($op == "pref-prefs") {
+
+               $subop = $_REQUEST["subop"];
+
+               if ($subop == "Save configuration") {
+
+                       foreach (array_keys($_POST) as $pref_name) {
+                       
+                               $pref_name = db_escape_string($pref_name);
+                               $value = db_escape_string($_POST[$pref_name]);
+
+                               $result = db_query($link, "SELECT type_name 
+                                       FROM ttrss_prefs,ttrss_prefs_types 
+                                       WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
+
+                               if (db_num_rows($result) > 0) {
+
+                                       $type_name = db_fetch_result($result, 0, "type_name");
+
+//                                     print "$pref_name : $type_name : $value<br>";
+
+                                       if ($type_name == "bool") {
+                                               if ($value == "1") {
+                                                       $value = "true";
+                                               } else {
+                                                       $value = "false";
+                                               }
+                                       } else if ($type_name == "integer") {
+                                               $value = sprintf("%d", $value);
+                                       }
+
+//                                     print "$pref_name : $type_name : $value<br>";
+
+                                       db_query($link, "UPDATE ttrss_prefs SET value = '$value' 
+                                               WHERE pref_name = '$pref_name'");
+
+                               }
+
+                               header("Location: prefs.php");
+
+                       }
+
+               } else if ($subop == "getHelp") {
+
+                       $pref_name = db_escape_string($_GET["pn"]);
+
+                       $result = db_query($link, "SELECT help_text FROM ttrss_prefs
+                               WHERE pref_name = '$pref_name'");
+
+                       if (db_num_rows($result) > 0) {
+                               $help_text = db_fetch_result($result, 0, "help_text");
+                               print $help_text;
+                       } else {
+                               print "Unknown option: $pref_name";
+                       }
+
+               } else if ($subop == "Reset to defaults") {
+
+                       db_query($link, "UPDATE ttrss_prefs SET value = def_value");
+
+                       header("Location: prefs.php");
+
+               } else {
+
+                       $result = db_query($link, "SELECT 
+                               pref_name,short_desc,help_text,value,type_name,
+                               section_name,def_value
+                               FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections 
+                               WHERE type_id = ttrss_prefs_types.id AND 
+                                       section_id = ttrss_prefs_sections.id 
+                               ORDER BY section_name,short_desc");
+
+                       print "<form action=\"backend.php\" method=\"POST\">";
+
+                       print "<table width=\"100%\" class=\"prefPrefsList\">";
+       
+                       $lnum = 0;
+
+                       $active_section = "";
+       
+                       while ($line = db_fetch_assoc($result)) {
+
+                               if ($active_section != $line["section_name"]) {
+
+                                       if ($active_section != "") {
+                                               print "</table><p><table width=\"100%\" class=\"prefPrefsList\">";
+                                       }
+                               
+                                       $active_section = $line["section_name"];                                
+                                       
+                                       print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
+//                                     print "<tr class=\"title\">
+//                                             <td width=\"25%\">Option</td><td>Value</td></tr>";
+                               }
+
+                               $class = ($lnum % 2) ? "even" : "odd";
+
+                               print "<tr class=\"$class\">";
+
+                               $type_name = $line["type_name"];
+                               $pref_name = $line["pref_name"];
+                               $value = $line["value"];
+                               $def_value = $line["def_value"];
+                               $help_text = $line["help_text"];
+
+                               print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
+
+                               if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
+                               
+                               print "</td>";
+
+                               print "<td>";
+
+                               if ($type_name == "bool") {
+//                                     print_select($pref_name, $value, array("true", "false"));
+
+                                       if ($value == "true") {
+                                               $value = "Yes";
+                                       } else {
+                                               $value = "No";
+                                       }
+
+                                       print_radio($pref_name, $value, array("Yes", "No"));
+                       
+                               } else {
+                                       print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
+                               }
+
+                               print "</td>";
+
+                               print "</tr>";
+
+                               $lnum++;
+                       }
+
+                       print "</table>";
+
+                       print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
+
+                       print "<p><input class=\"button\" type=\"submit\" 
+                               name=\"subop\" value=\"Save configuration\">";
+                               
+                       print "&nbsp;<input class=\"button\" type=\"submit\" 
+                               name=\"subop\" value=\"Reset to defaults\"></p>";
+
+                       print "</form>";
+
+               }
+
+       }
+
        db_close($link);
 ?>