Autoassign default taxonomy terms based on content type and CCK fields

This works similarly to the Taxonomy Defaults module, but has no UI to set this up - this is for programmatic, backend stuff. It tests to see if somethings a particular content type and then checks for the value of a given CCK field to determine the appropriate term.

<?php
function custom_taxonomy_defaults_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if ($op == 'presave') {
    $taxonomy = $node->taxonomy;
    switch ($node->type) {
      case 'online_project_old':
        $vid = '15';
        $projtype = $node->field_external_resource_type[0]['value'];
        switch ($projtype) {
          case '1': # online exhibition
          case '2': # special project
            $taxonomy[$vid] = '902'; # special projects
            break;
          case '3': # index
            $taxonomy[$vid] = '901'; # research tools
            break;
          case '4': # ebooks/digital collection
            $taxonomy[$vid] = '895'; # collections
            break;
        }
        break;
    }
    if (isset($taxonomy)) {
      $node->taxonomy = $taxonomy;
    }
  }
}
?>