--- modules/nat/nat.module.orig	2007-06-30 21:58:45.000000000 +0800
+++ modules/nat/nat.module	2008-07-25 15:39:28.000000000 +0800
@@ -95,7 +95,7 @@ function nat_nodeapi(&$node, $op, $tease
       $terms = _nat_add_terms($nat_config['types'][$node->type], $node->title, $body, $node->taxonomy, $node->nat['related'], $node->nat['synonyms']);
 
       // Save node-term association in the NAT table.
-      _nat_save_association($node->nid, $terms);
+      _nat_save_association($node->nid, $terms, $node->type);
       break;
     case 'update':
       $body = $node->body;
@@ -238,6 +238,12 @@ function nat_settings_form() {
       '#default_value' => isset($nat_config['node_links'][$type]) ? $nat_config['node_links'][$type] : 0,
       '#parents' => array('node_links', $type)
     );
+    $form['nat_'. $type]['node_term_'. $type] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Associate an automatically created NAT term with %type parent node?', array('%type' => $type)),
+      '#default_value' => isset($nat_config['node_term'][$type]) ? $nat_config['node_term'][$type] : 0,
+      '#parents' => array('node_term', $type)
+    );
   }
   $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
 
@@ -254,6 +260,7 @@ function nat_settings_form_submit($form_
   $form_values['delete'] = array_filter($form_values['delete']);
   $form_values['node_links'] = array_filter($form_values['node_links']);
   $form_values['related'] = array_filter($form_values['related']);
+  $form_values['node_term'] = array_filter($form_values['node_term']);
 
   variable_set('nat_config', $form_values);
 
@@ -587,19 +594,55 @@ function _nat_delete_terms($nid) {
 }
 
 /**
- * Save node-term associations in the NAT table.
- *
- * @param $nid
- *   Node ID of the node.
- * @param $terms
- *   NAT-terms of the above node.
- */
-function _nat_save_association($nid, $terms) {
+* Save node-term associations in the NAT table.  Optionally, associate the terms with a given node in the
+* node_term table if the option is set for a given type in NAT's settings.
+*
+* @param $nid
+*   Node ID of the node.
+* @param $terms
+*   NAT-terms of the above node.
+* @param $node_type
+*   The type of the node.
+*/
+function _nat_save_association($nid, $terms, $node_type) {
+  $nat_config = variable_get('nat_config', array());
   foreach ($terms as $term) {
     db_query("INSERT INTO {nat} (nid, tid, vid) VALUES (%d, %d, %d)", $nid, $term['tid'], $term['vid']);
   }
+  if (isset($nat_config['node_term']["$node_type"])) {
+    $node_terms=taxonomy_node_get_terms($nid);
+    foreach ($terms as $term) {
+      $vocabulary=taxonomy_get_vocabulary($term['vid']);
+      if($vocabulary->multiple==0) {
+        $_terms=taxonomy_node_get_terms_by_vocabulary($nid,$vocabulary->vid);
+        foreach ($_terms as $_term) {
+          unset($node_terms[$_term->tid]);
+        }
+      }
+      $node_terms[$term['tid']]= new stdClass();
+      $node_terms[$term['tid']]->tid=$term['tid'];
+    }
+    taxonomy_node_save($nid,$node_terms);
+  }
 }
 
+/*
+function _nat_term_node_association($nid, $terms, $node_type) {
+
+  $nat_config = variable_get('nat_config', array());
+  
+  if (isset($nat_config['node_term']["$node_type"])) {
+    foreach ($terms as $term) {
+      db_query("INSERT INTO {term_node} (nid, tid) VALUES  (%d, %d)", $nid, $term['tid']);
+	}
+  }
+}
+
+  if (isset($nat_config['node_term']["$node_type"])) {
+    db_query("INSERT INTO {term_node} (nid, tid) VALUES  (%d, %d)", $nid, $term['tid']);
+  }
+*/
+
 /**
  * Delete node-term associations from the NAT table.
  *
@@ -633,7 +676,7 @@ function _nat_sync_associations($associa
       $terms = _nat_add_terms(array($association[1]), $node['title'], $body);
 
       // Save node-term association in the NAT table.
-      _nat_save_association($node['nid'], $terms);
+      _nat_save_association($node['nid'], $terms, $node['type']);
 
       $counter++;
     }
