SELECT DISTINCT catalog.* FROM catalog, category, roles_and_users WHERE catalog.uid=category.uid AND catalog.uid=roles_and_users.uid AND <dtml-var query> AND <dtml-sqltest parent_uid op=eq column=catalog.parent_uid type=int> ORDER BY <dtml-var sort_on>
<dtml-else>
SELECT * FROM catalog WHERE <dtml-sqltest parent_uid op=eq column=catalog.parent_uid type=int> ORDER BY <dtml-var sort_on>
</dtml-if>
<dtml-else>
<dtml-if query>
SELECT DISTINCT catalog.* FROM catalog, category, roles_and_users WHERE <dtml-sqltest parent_uid op=eq column=catalog.parent_uid type=int> AND catalog.uid=category.uid AND catalog.uid=roles_and_users.uid AND <dtml-var query>
<dtml-else>
SELECT * FROM catalog WHERE <dtml-sqltest parent_uid op=eq column=catalog.parent_uid type=int>