--- ../org/modules/glossary/glossary.module	Fri Nov 19 17:47:38 2004
+++ modules/glossary.module	Thu Nov 25 18:32:37 2004
@@ -1,4 +1,4 @@
 <?php
-// $Id: glossary.module,v 1.82.2.1 2004/11/19 16:47:38 frodo Exp $
+// $Id: glossary.module,v 1.71 2004/11/07 17:32:41 frodo Exp $
 
 function glossary_help($section = "admin/help#glossary") {
@@ -234,5 +234,8 @@
   else {
     $vid = intval(arg(1));
-    if (!$vid) {
+    if ($vid) {
+      $found = array_search($vid, _glossary_get_filter_vids());
+    }
+    if (!$vid || $found === null || $found === false) {
       $breadcrumb = array(l(t("Home"), NULL));
       print theme("page", _glossary_list(), t("Glossaries"), $breadcrumb);
@@ -289,5 +292,7 @@
     }
   }
-  $output .= theme_links($links);
+  if (count($links)) {
+    $output .= theme_links($links);
+  }
   $output .= "</div>\n";
   return $output;
@@ -334,10 +339,15 @@
 function _glossary_list() {
   $output = "";
-  $taxonomies = taxonomy_get_vocabularies();
+  $vids = _glossary_get_filter_vids();
+  $vocs = array();
+  foreach ($vids as $vid) {
+    $voc = taxonomy_get_vocabulary($vid);
+    $vocs[$voc->name] = $voc;
+  }
+  uksort($vocs, _glossary_cmp_strcase);
 
   $header = array(t("Glossary"), t('Operations'));
   $rows = array();
-  foreach ($taxonomies as $taxonomy) {
-    $voc = taxonomy_get_vocabulary($taxonomy->vid);
+  foreach ($vocs as $voc) {
     $row = array();
     $row[0] = $voc->name;
@@ -423,4 +433,25 @@
     cache_clear_all('filter:', true);
   }
+}
+
+function _glossary_get_filter_vids() {
+  // We can't use filter_formats() here, because we need all input formats,
+  // not just those we are allowed to post in.
+
+  $vids = array();
+  $result = db_query('SELECT format FROM {filter_formats}');
+  while ($format = db_fetch_object($result)) {
+    $filters = filter_list_format($format->format);
+    foreach ($filters as $filter) {
+      if ($filter->module == "glossary") {
+        $vids = array_merge($vids, variable_get("glossary_vids_". $format->format, array()));
+      }
+    }
+  }
+  return array_unique($vids);
+}
+
+function _glossary_cmp_strcase($a, $b) {
+  return strcmp(strtolower($a), strtolower($b));
 }
 
