From fbf85cf6467a12fce776475db97cf6dac808edf1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 14 Aug 2012 23:18:40 +0400 Subject: [PATCH] print_feed_cat_select: display nested category structure fix empty sub-sub-categories never being shown --- classes/pref_feeds.php | 2 ++ include/functions.php | 71 +++++++++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/classes/pref_feeds.php b/classes/pref_feeds.php index d292319cb..381330da0 100644 --- a/classes/pref_feeds.php +++ b/classes/pref_feeds.php @@ -33,6 +33,8 @@ class Pref_Feeds extends Protected_Handler { } private function get_category_items($cat_id) { + $show_empty_cats = $_REQUEST['mode'] != 2 && + get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'); $items = array(); diff --git a/include/functions.php b/include/functions.php index cb24cb877..ac9c5372c 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1999,39 +1999,54 @@ print ""; } - function print_feed_cat_select($link, $id, $default_id = "", - $attributes = "", $include_all_cats = true) { + function print_feed_cat_select($link, $id, $default_id, + $attributes, $include_all_cats = true, $root_id = false, $nest_level = 0) { - print ""; } - if ($line["title"]) - printf("", - $line["id"], htmlspecialchars($line["title"])); + if ($root_id) + $parent_qpart = "parent_cat = '$root_id'"; + else + $parent_qpart = "parent_cat IS NULL"; + + $result = db_query($link, "SELECT id,title, + (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE + c2.parent_cat = ttrss_feed_categories.id) AS num_children + FROM ttrss_feed_categories + WHERE owner_uid = ".$_SESSION["uid"]." AND $parent_qpart ORDER BY title"); + + while ($line = db_fetch_assoc($result)) { + if ($line["id"] == $default_id) { + $is_selected = "selected=\"1\""; + } else { + $is_selected = ""; + } + + for ($i = 0; $i < $nest_level; $i++) + $line["title"] = " - " . $line["title"]; + + if ($line["title"]) + printf("", + $line["id"], htmlspecialchars($line["title"])); + + if ($line["num_children"] > 0) + print_feed_cat_select($link, $id, $default_id, $attributes, + $include_all_cats, $line["id"], $nest_level+1); + } + + if (!$root_id) { + if ($include_all_cats) { + if (db_num_rows($result) > 0) { + print ""; + } + print ""; + } + print ""; + } } -# print ""; - - print ""; - } - function checkbox_to_sql_bool($val) { return ($val == "on") ? "true" : "false"; }