Index: openacs-4/packages/categories/lib/list-categories.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/categories/lib/list-categories.tcl,v
diff -u -r1.4.2.1 -r1.4.2.2
--- openacs-4/packages/categories/lib/list-categories.tcl	10 Sep 2015 08:30:17 -0000	1.4.2.1
+++ openacs-4/packages/categories/lib/list-categories.tcl	3 Jul 2016 17:26:19 -0000	1.4.2.2
@@ -2,7 +2,7 @@
     set cat ""
 }
 
-if {(![info exists orderby] || $orderby eq "")} {
+if { ![info exists orderby] || $orderby eq "" } {
     set orderby "object_title"
 }
 set user_id [ad_conn user_id]
@@ -12,18 +12,7 @@
 set node_id [ad_conn node_id]
 set packages [subsite::util::packages -node_id $node_id]
 
-db_foreach category_count "
-    SELECT c.category_id as catid, count(*) as count
-    FROM category_object_map c, acs_objects o
-    where c.object_id = o.object_id
-    and o.package_id in ([join $packages ,])
-    and exists (select 1 
-                  from acs_object_party_privilege_map pm
-                 where pm.object_id = c.object_id
-                   and pm.party_id = :user_id
-                   and pm.privilege = 'read')
-    group by c.category_id
-" { 
+db_foreach category_count {} {
     lappend counts $catid $count
 }
 
Index: openacs-4/packages/categories/tcl/tagcloud-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/categories/tcl/Attic/tagcloud-procs-postgresql.xql,v
diff -u -r1.1.2.2 -r1.1.2.3
--- openacs-4/packages/categories/tcl/tagcloud-procs-postgresql.xql	3 Jul 2016 17:05:32 -0000	1.1.2.2
+++ openacs-4/packages/categories/tcl/tagcloud-procs-postgresql.xql	3 Jul 2016 17:26:19 -0000	1.1.2.3
@@ -10,7 +10,8 @@
 	   natural left join category_object_map com
 	   natural join category_trees
            natural join category_translations trans
-        where tree_id = :tree_id and trans.locale = :default_locale
+        where tree_id = :tree_id
+	  and trans.locale = :default_locale
           and acs_permission__permission_p(com.object_id, :user_id, 'read')
         group by category_id
   </querytext>
Index: openacs-4/packages/categories/www/categories-browse-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/categories/www/Attic/categories-browse-oracle.xql,v
diff -u -r1.2 -r1.2.20.1
--- openacs-4/packages/categories/www/categories-browse-oracle.xql	7 May 2003 13:35:06 -0000	1.2
+++ openacs-4/packages/categories/www/categories-browse-oracle.xql	3 Jul 2016 17:20:49 -0000	1.2.20.1
@@ -27,4 +27,33 @@
     </querytext>
   </fullquery>
 
+  <fullquery name="check_permissions_on_trees">
+    <querytext>
+      select t.tree_id
+      from category_trees t, category_temp tmp
+      where (t.site_wide_p = 't'
+      or exists (select 1
+                 from acs_object_party_privilege_map oppm
+                 where oppm.object_id = t.tree_id
+                 and oppm.party_id = :user_id
+                 and oppm.privilege = 'category_tree_read'))
+      and t.tree_id = tmp.category_id
+    </querytext>
+  </fullquery>
+
+  <fullquery name="get_categorized_object_count">
+    <querytext>
+      select n.object_id
+      from acs_named_objects n, ($subtree_sql) s
+      where n.object_id = s.object_id
+      and exists (select 1
+                  from acs_object_party_privilege_map oppm
+                  where oppm.object_id = n.object_id
+                  and oppm.party_id = :user_id
+                  and oppm.privilege = 'read')
+      $letter_sql
+      $package_sql
+    </querytext>
+  </fullquery>
+  
 </queryset>
Index: openacs-4/packages/categories/www/categories-browse-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/categories/www/Attic/categories-browse-postgresql.xql,v
diff -u -r1.3 -r1.3.20.1
--- openacs-4/packages/categories/www/categories-browse-postgresql.xql	19 May 2003 13:10:32 -0000	1.3
+++ openacs-4/packages/categories/www/categories-browse-postgresql.xql	3 Jul 2016 17:20:49 -0000	1.3.20.1
@@ -13,16 +13,36 @@
          and o.object_id = n.object_id
          and p.package_id = n.package_id
          and t.package_key = p.package_key
-         and exists (select 1
-                       from acs_object_party_privilege_map oppm
-                      where oppm.object_id = n.object_id
-                        and oppm.party_id = :user_id
-                        and oppm.privilege = 'read')
+         and acs_permission__permission_p(n.object_id, :user_id, 'read')
              $letter_sql
              $package_sql
              $order_by_clause
        limit $last_row offset $first_row
     </querytext>
   </fullquery>
 
+  <fullquery name="check_permissions_on_trees">
+    <querytext>
+      select t.tree_id
+      from category_trees t, category_temp tmp
+      where (
+         t.site_wide_p = 't'
+         or acs_permission__permission_p(t.tree_id, :user_id, 'category_tree_read')
+      )
+      and t.tree_id = tmp.category_id
+    </querytext>
+  </fullquery>
+
+  <fullquery name="get_categorized_object_count">
+    <querytext>
+      select n.object_id
+      from acs_named_objects n, ($subtree_sql) s
+      where n.object_id = s.object_id
+      and   acs_permission__permission_p(n.object_id, :user_id, 'read')
+      $letter_sql
+      $package_sql
+    </querytext>
+  </fullquery>
+  
+  
 </queryset>
Index: openacs-4/packages/categories/www/categories-browse.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/categories/www/categories-browse.xql,v
diff -u -r1.3 -r1.3.20.1
--- openacs-4/packages/categories/www/categories-browse.xql	19 May 2003 13:10:32 -0000	1.3
+++ openacs-4/packages/categories/www/categories-browse.xql	3 Jul 2016 17:20:49 -0000	1.3.20.1
@@ -15,20 +15,6 @@
     </querytext>
   </fullquery>
 
-  <fullquery name="check_permissions_on_trees">
-    <querytext>
-      select t.tree_id
-      from category_trees t, category_temp tmp
-      where (t.site_wide_p = 't'
-      or exists (select 1
-                 from acs_object_party_privilege_map oppm
-                 where oppm.object_id = t.tree_id
-                 and oppm.party_id = :user_id
-                 and oppm.privilege = 'category_tree_read'))
-      and t.tree_id = tmp.category_id
-    </querytext>
-  </fullquery>
-
   <partialquery name="other_letter">
     <querytext>
       and (upper(n.object_name) < 'A' or upper(n.object_name) > 'Z')
@@ -99,19 +85,4 @@
     </querytext>
   </fullquery>
 
-  <fullquery name="get_categorized_object_count">
-    <querytext>
-      select n.object_id
-      from acs_named_objects n, ($subtree_sql) s
-      where n.object_id = s.object_id
-      and exists (select 1
-                  from acs_object_party_privilege_map oppm
-                  where oppm.object_id = n.object_id
-                  and oppm.party_id = :user_id
-                  and oppm.privilege = 'read')
-      $letter_sql
-      $package_sql
-    </querytext>
-  </fullquery>
-
 </queryset>