Index: nat.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nat/nat.module,v
retrieving revision 1.14.2.15
diff -u -p -r1.14.2.15 nat.module
--- nat.module	30 Jun 2007 13:58:45 -0000	1.14.2.15
+++ nat.module	29 Oct 2008 07:35:14 -0000
@@ -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);
 
@@ -586,19 +593,55 @@ function _nat_delete_terms($nid) {
   }
 }
 
-/**
- * Save node-term associations in the NAT table.
+/*
+ * 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) {
+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.
@@ -624,7 +667,7 @@ function _nat_sync_associations($associa
   foreach ($associations as $association) {
     $association = explode('|', $association);
     // This query can possibly be improved.
-    $result = db_query("SELECT n.nid, n.title, nr.body, n1.vid FROM {node} n INNER JOIN {node_revisions} nr USING (vid) LEFT JOIN {nat} n1 ON (n.nid = n1.nid AND n1.vid = %d) LEFT JOIN {nat} n2 ON (n.nid = n2.nid AND n2.nid != n1.nid) WHERE n.type = '%s' AND ISNULL(n1.nid)", $association[1], $association[0]);
+    $result = db_query("SELECT n.nid, n.title, n.type, nr.body, n1.vid FROM {node} n INNER JOIN {node_revisions} nr USING (vid) LEFT JOIN {nat} n1 ON (n.nid = n1.nid AND n1.vid = %d) LEFT JOIN {nat} n2 ON (n.nid = n2.nid AND n2.nid != n1.nid) WHERE n.type = '%s' AND ISNULL(n1.nid)", $association[1], $association[0]);
     while ($node = db_fetch_array($result)) {
       // Copying over the node body is optional.
       $body = isset($nat_config['body'][$node['type']]) ? $node['body'] : '';
@@ -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++;
     }
