--- taxonomy.module	Sun Mar 21 21:06:20 2004
+++ taxonomy.module	Sat Mar 27 09:34:56 2004
@@ -92,8 +92,13 @@ function taxonomy_save_vocabulary($edit)
     $edit["nodes"] = array();
   }
 
-  $data = array("name" => $edit["name"], "nodes" => implode(",", $edit["nodes"]), "description" => $edit["description"], "multiple" => $edit["multiple"], "required" => $edit["required"], "hierarchy" => $edit["hierarchy"], "relations" => $edit["relations"], "weight" => $edit["weight"]);
+  $data = array("name" => $edit["name"], "description" => $edit["description"], "multiple" => $edit["multiple"], "required" => $edit["required"], "hierarchy" => $edit["hierarchy"], "relations" => $edit["relations"], "weight" => $edit["weight"]);
   if ($edit["vid"] && $edit["name"]) {
+    db_query("DELETE FROM {vocabulary_type} WHERE vid = %d", $edit["vid"]);
+    foreach ($edit["nodes"] as $type) {
+      db_query("INSERT INTO {vocabulary_type} (vid, type) VALUES (%d, '%s')", $edit["vid"], $type);
+    }
+    
     db_query("UPDATE {vocabulary} SET ". _prepare_update($data) ." WHERE vid = %d", $edit["vid"]);
     module_invoke_all("taxonomy", "update", "vocabulary", $edit);
     $message = t("updated vocabulary '%name'.", array("%name" => $edit["name"]));
@@ -103,6 +108,9 @@ function taxonomy_save_vocabulary($edit)
   }
   else {
     $data["vid"] = $edit["vid"] = db_next_id("{vocabulary}_vid");
+    foreach ($edit["nodes"] as $type) {
+      db_query("INSERT INTO {vocabulary_type} (vid, type) VALUES (%d, '%s')", $edit["vid"], $type);
+    }
     db_query("INSERT INTO {vocabulary} ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
     module_invoke_all("taxonomy", "insert", "vocabulary", $edit);
     $message = t("created new vocabulary '%name'.", array("%name" => $edit["name"]));
@@ -118,6 +126,7 @@ function taxonomy_del_vocabulary($vid) {
   $vocabulary = taxonomy_get_vocabulary($vid);
 
   db_query("DELETE FROM {vocabulary} WHERE vid = %d", $vid);
+  db_query("DELETE FROM {vocabulary_type} WHERE vid = %d", $vid);
   $result = db_query("SELECT tid FROM {term_data} WHERE vid = %d", $vid);
   while ($term = db_fetch_object($result)) {
     taxonomy_del_term($term->tid);
@@ -281,7 +290,7 @@ function taxonomy_overview() {
   foreach ($vocabularies as $vocabulary) {
     $links = array();
     $types = array();
-    foreach(explode(",", $vocabulary->nodes) as $type) {
+    foreach(taxonomy_get_vocabulary_types($vocabulary->vid) as $type) {
       $types[] = node_invoke($type, "node_name");
     }
     $rows[] = array($vocabulary->name, array("data" => implode(", ", $types), "align" => "center"), l(t("edit vocabulary"), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t("add term"), "admin/taxonomy/add/term/$vocabulary->vid"), l(t("preview form"), "admin/taxonomy/preview/vocabulary/$vocabulary->vid"));
@@ -322,19 +331,36 @@ function taxonomy_form($vocabulary_id, $
 */
 
 // return array of vocabularies, as objects
-function taxonomy_get_vocabularies($type = '', $key = "vid") {
-  if ($type) {
-    $result = db_query("SELECT * FROM {vocabulary} WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type);
+function taxonomy_get_vocabularies($type = '', $refresh = 0) {
+  static $vocs = array();
+
+  if (isset($vocs[$type]) && $refresh == 0) {
+    return $vocs[$type];
   }
   else {
-    $result = db_query("SELECT * FROM {vocabulary} ORDER BY weight, name");
-  }
-  $vocabularies = array();
-  while ($voc = db_fetch_object($result)) {
-    $vocabularies[$voc->$key] = $voc;
+    if ($type) {
+      $result = db_query("SELECT v.*, t.type FROM {vocabulary} v INNER JOIN {vocabulary_type} t ON v.vid = t.vid WHERE t.type = '%s' ORDER BY v.weight, v.name", $type);
+    }
+    else {
+      $result = db_query("SELECT * FROM {vocabulary} ORDER BY weight, name");
+    }
+    $vocabularies = array();
+    while ($voc = db_fetch_object($result)) {
+      $vocabularies[$voc->vid] = $voc;
+    }
+    $vocs[$type] = $vocabularies;
+
+    return $vocabularies;
   }
+}
 
-  return $vocabularies;
+function taxonomy_get_vocabulary_types($vid) {
+  $result = db_query("SELECT type FROM {vocabulary_type} WHERE vid = %d", $vid);
+  $types = array();
+  while ($type = db_fetch_object($result)) {
+    $types[] = $type->type;
+  }
+  return $types;
 }
 
 // return form with current term
@@ -351,7 +377,7 @@ function taxonomy_node_form($type, $node
     $terms = $node->taxonomy;
   }
 
-  $c = db_query("SELECT * FROM {vocabulary} WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type);
+  $c = db_query("SELECT v.*, t.type FROM {vocabulary} v INNER JOIN {vocabulary_type} t WHERE v.vid = t.vid AND t.type = '%s' ORDER BY v.weight, v.name", $type);
   while ($vocabulary = db_fetch_object($c)) {
     $result[] .= taxonomy_form($vocabulary->vid, $terms, $error);
   }
