]> git.wh0rd.org Git - tt-rss.git/commitdiff
assorted labels bugfixes and UI work
authorAndrew Dolgov <fox@bah.spb.su>
Sun, 18 Jan 2009 09:09:52 +0000 (10:09 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Sun, 18 Jan 2009 09:09:52 +0000 (10:09 +0100)
functions.php
modules/backend-rpc.php
viewfeed.js

index 665825e41909ea8c96fc58542c9dff333c807927..6cc801a0bf88c04cf87221065a102dbdb554dbb3 100644 (file)
 
                                        $label_id = -$feed - 11;
 
-                                       $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
-                                               WHERE id = '$label_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_user_labels2 
+                                               SET unread = false WHERE label_id = '$label_id' 
+                                                       AND owner_uid = '".$_SESSION["uid"]."' AND ref_id = article_id");
 
-/*                                             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);
                        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");
                        $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)) {
                                        $label_id = $line["id"];
                                        $label_caption = $line["caption"];
 
-                                       print "<li onclick=\"javascript:selectionAssignLabel($label_id)\">
-                                               &nbsp;&nbsp;$label_caption</li>";
+                                       if ($feed_id < -10 && $feed_id == -11-$label_id) {
+                                               print "<li onclick=\"javascript:selectionRemoveLabel($label_id)\">
+                                                       &nbsp;&nbsp;$label_caption ".__('(remove)')."</li>";
+                                       } else {                                        
+                                               print "<li onclick=\"javascript:selectionAssignLabel($label_id)\">
+                                                       &nbsp;&nbsp;$label_caption</li>";
+                                       }
                        }
 
                                print   "</ul></li></ul>";
                }
        }
 
+       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);
index 691771f736ccb2665c3d0e90333ff6a5d1095745..4b67e1b38bef6e85dc62c1a0ea9ef5e7c6ed906f 100644 (file)
                        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 "<rpc-reply>OK</rpc-reply>";
+
+                       return;
+               }
+
                if ($subop == "assignToLabel") {
 
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
index b0cb068e1cc6c47cb01e017a1473481d9e2a3bc8..a1163893635d468feca04b5e451d87f31be147f2 100644 (file)
@@ -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 {