--- taxonomy_access.module	Tue Jun 14 04:09:12 2005
+++ taxonomy_access.module	Thu Sep 08 18:04:12 2005
@@ -443,11 +443,24 @@ function taxonomy_access_nodeapi(&$node,
       else {      
 	      // Query the term_access table to get the permissions for the new node's assigned category/categories
 	      // then make appropriate changes to the node_access table.
-	      $result = db_query("SELECT * from {term_access} where tid in ('" . implode("','",array_values($tids)) . "')");
+//	      $result = db_query("SELECT * from {term_access} where tid in ('" . implode("','",array_values($tids)) . "')");
+	      $result = db_query("SELECT * from {term_access} where tid in ('%s')", implode(",",array_values($tids)));
+	      $permissions = array();
 	      while($row = db_fetch_object($result)) {
-	        db_query("DELETE FROM {node_access} WHERE nid=%d AND gid=%d AND realm='term_access'", $node->nid, $row->rid);
-	      	db_query('INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, \'term_access\', %d, %d, %d)', $node->nid, $row->rid, $row->grant_view, $row->grant_update, $row->grant_delete);
+	  	$permissions[$row->tid][$row->rid] = array('grant_view' => $row->grant_view, 'grant_update' => $row->grant_update, 'grant_delete' => $row->grant_delete, 'grant_create' => $row->grant_create);
 	      }
+		$access = array();
+		foreach ($tids as $tid){
+			foreach ($permissions[$tid] as $rid=>$perm){
+				$access[$rid]['grant_view'] = ($access[$rid]['grant_view'] || $perm['grant_view']) ? 1 : 0;
+				$access[$rid]['grant_update'] = ($access[$rid]['grant_update'] || $perm['grant_update']) ? 1 : 0;
+				$access[$rid]['grant_delete'] = ($access[$rid]['grant_delete'] || $perm['grant_delete']) ? 1 : 0;
+			}
+		}
+		foreach ($access as $rid=>$value){
+			db_query("DELETE FROM {node_access} WHERE nid=%d AND gid=%d AND realm='term_access'", $node->nid, $rid);
+			db_query('INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, \'term_access\', %d, %d, %d)', $node->nid, $rid, $value['grant_view'], $value['grant_update'], $value['grant_delete']);
+		}
 	    }	    
 	    break;
   }
@@ -788,16 +801,27 @@ 	// Load term_access table data into mem
 	// for nodes that are in a category.
 	$result = db_query("SELECT tn.nid, tn.tid FROM {term_node} as tn, {term_data} as td WHERE td.tid = tn.tid");
 	$category_nids = array();
+	$node_tids = array (); //array for storing term id-s to each node "$node_tids[$nid][]"
 	while($row = db_fetch_object($result)) {
- 		$nid = $row->nid;
- 		$tid = $row->tid;
  		$category_nids[] = $nid; // created now for use later on in code handling nodes without categories
- 		if(array_key_exists($tid, $permissions)) {
- 			foreach($permissions[$tid] as $key => $value) {
-			  db_query("DELETE FROM {node_access} WHERE nid=%d AND gid=%d AND realm='term_access'", $nid, $key);
-			  db_query('INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, \'term_access\', %d, %d, %d)', $nid, $key, $value['grant_view'], $value['grant_update'], $value['grant_delete']);
- 			}
+ 		if(array_key_exists($row->tid, $permissions)) {
+			$node_tids [$row->nid][] = $row->tid;
  		}
+	}
+	
+	foreach ($node_tids as $nid => $terms){
+		$access = array();
+		foreach ($terms as $tid){
+			foreach ($permissions[$tid] as $rid=>$perm){
+				$access[$rid]['grant_view'] = ($access[$rid]['grant_view'] || $perm['grant_view']) ? 1 : 0;
+				$access[$rid]['grant_update'] = ($access[$rid]['grant_update'] || $perm['grant_update']) ? 1 : 0;
+				$access[$rid]['grant_delete'] = ($access[$rid]['grant_delete'] || $perm['grant_delete']) ? 1 : 0;
+			}
+		}
+		foreach ($access as $rid=>$value){
+			db_query("DELETE FROM {node_access} WHERE nid=%d AND gid=%d AND realm='term_access'", $nid, $rid);
+			db_query('INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, \'term_access\', %d, %d, %d)', $nid, $rid, $value['grant_view'], $value['grant_update'], $value['grant_delete']);
+		}
 	}
 	
 	// Determine which nodes don't belong to a category
