From 933ba4ee9c7c9f2cf5bcef5598272db8295a2157 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 18 Jan 2009 10:09:52 +0100 Subject: [PATCH] assorted labels bugfixes and UI work --- functions.php | 68 +++++++++++++++++------------------------ modules/backend-rpc.php | 19 ++++++++++++ viewfeed.js | 32 +++++++++++++++++++ 3 files changed, 79 insertions(+), 40 deletions(-) diff --git a/functions.php b/functions.php index 665825e41..6cc801a0b 100644 --- a/functions.php +++ b/functions.php @@ -2225,42 +2225,10 @@ $label_id = -$feed - 11; - $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels - WHERE id = '$label_id'"); + db_query($link, "UPDATE ttrss_user_entries, ttrss_user_labels2 + SET unread = false WHERE label_id = '$label_id' + AND owner_uid = '".$_SESSION["uid"]."' AND ref_id = article_id"); - if ($tmp_result) { - $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp"); - - db_query($link, "BEGIN"); - - $tmp2_result = db_query($link, - "SELECT - int_id - FROM - ttrss_user_entries,ttrss_entries,ttrss_feeds - WHERE - ref_id = ttrss_entries.id AND - ttrss_user_entries.feed_id = ttrss_feeds.id AND - $sql_exp AND - ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); - - while ($tmp_line = db_fetch_assoc($tmp2_result)) { - db_query($link, "UPDATE - ttrss_user_entries - SET - unread = false, last_read = NOW() - WHERE - int_id = " . $tmp_line["int_id"]); - } - - db_query($link, "COMMIT"); - -/* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries - SET unread = false,last_read = NOW() - WHERE $sql_exp - AND ref_id = id - AND owner_uid = ".$_SESSION["uid"]); */ - } } ccache_update($link, $feed, $_SESSION["uid"], $cat_view); @@ -2448,7 +2416,8 @@ SELECT SUM(unread) AS unread FROM ttrss_user_entries, ttrss_labels2, ttrss_user_labels2 WHERE label_id = id AND article_id = ref_id AND - ttrss_labels2.owner_uid = '$owner_uid' AND id = '$label_id'"); + ttrss_labels2.owner_uid = '$owner_uid' AND id = '$label_id' + AND ttrss_user_entries.owner_uid = '$owner_uid'"); if (db_num_rows($result) != 0) { return db_fetch_result($result, 0, "unread"); @@ -2686,8 +2655,9 @@ $result = db_query($link, "SELECT id, caption, SUM(unread) AS unread FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON (label_id = id) - LEFT JOIN ttrss_user_entries ON (ref_id = article_id) - WHERE ttrss_labels2.owner_uid = '$owner_uid' + LEFT JOIN ttrss_user_entries ON (ref_id = article_id AND + ttrss_user_entries.owner_uid = '$owner_uid') + WHERE ttrss_labels2.owner_uid = '$owner_uid' GROUP BY id"); while ($line = db_fetch_assoc($result)) { @@ -4056,8 +4026,13 @@ $label_id = $line["id"]; $label_caption = $line["caption"]; - print "
  • -   $label_caption
  • "; + if ($feed_id < -10 && $feed_id == -11-$label_id) { + print "
  • +   $label_caption ".__('(remove)')."
  • "; + } else { + print "
  • +   $label_caption
  • "; + } } print ""; @@ -6071,6 +6046,19 @@ } } + function label_remove_article($link, $id, $label, $owner_uid) { + + $label_id = label_find_id($link, $label, $owner_uid); + + if (!$label_id) return; + + $result = db_query($link, + "DELETE FROM ttrss_user_labels2 + WHERE + label_id = '$label_id' AND + article_id = '$id'"); + } + function label_add_article($link, $id, $label, $owner_uid) { $label_id = label_find_id($link, $label, $owner_uid); diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 691771f73..4b67e1b38 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -424,6 +424,25 @@ return; } + if ($subop == "removeFromLabel") { + + $ids = split(",", db_escape_string($_REQUEST["ids"])); + $label_id = db_escape_string($_REQUEST["lid"]); + + $label = label_find_caption($link, $label_id, $_SESSION["uid"]); + + if ($label) { + + foreach ($ids as $id) { + label_remove_article($link, $id, $label, $_SESSION["uid"]); + } + } + + print "OK"; + + return; + } + if ($subop == "assignToLabel") { $ids = split(",", db_escape_string($_REQUEST["ids"])); diff --git a/viewfeed.js b/viewfeed.js index b0cb068e1..a11638936 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -850,6 +850,38 @@ function toggleUnread(id, cmode, effect) { } } +function selectionRemoveLabel(id) { + try { + + var ids = getSelectedArticleIds2(); + + if (ids.length == 0) { + alert(__("No articles are selected.")); + return; + } + + var ok = confirm(__("Remove selected articles from label?")); + + if (ok) { + + var query = "backend.php?op=rpc&subop=removeFromLabel&ids=" + + param_escape(ids.toString()) + "&lid=" + param_escape(id); + +// notify_progress("Loading, please wait..."); + + new Ajax.Request(query, { + onComplete: function(transport) { + viewCurrentFeed(); + } }); + + } + + } catch (e) { + exception_error("selectionAssignLabel", e); + + } +} + function selectionAssignLabel(id) { try {