You are here

function oa_files_addterm_callback in Open Atrium Files 7.2

Ajax Callback for adding a new taxonomy term (folder)

Parameters

$node:

1 string reference to 'oa_files_addterm_callback'
oa_files_menu in ./oa_files.module
Implements hook_menu().

File

./oa_files.module, line 714

Code

function oa_files_addterm_callback($parent_tid = 0, $parent_vid = 0) {
  $new_term = $_POST['node'];
  $node_type = !empty($_POST['type']) ? str_replace('-', '_', $_POST['type']) : 'oa_wiki_page';
  $parent_term = null;
  $vid = $parent_vid;
  if ($parent_tid) {
    $parent_term = taxonomy_term_load($parent_term);
    if ($parent_term) {
      $vid = $parent_term->vid;
    }
  }
  if (!($vocab = taxonomy_vocabulary_load($vid))) {
    ajax_deliver(MENU_ACCESS_DENIED);
    return FALSE;
  }
  if (empty($_REQUEST['token']) || !drupal_valid_token($_REQUEST['token'], 'add-term-' . $vid)) {
    return MENU_ACCESS_DENIED;
  }
  $space_id = oa_core_get_space_context();
  $allownew = FALSE;
  if (module_exists('og_vocab')) {
    $vids = og_vocab_get_accessible_vocabs('node', $node_type, OG_VOCAB_FIELD);
    if (in_array($vid, $vids)) {

      // check OG access for editing vocab terms
      $allownew = og_user_access('node', $space_id, "edit terms");
    }
  }
  if (!$allownew) {

    // otherwise check global permission for vocab
    $allownew = user_access('edit terms in ' . $vid);
  }
  if (!$allownew) {
    ajax_deliver(MENU_ACCESS_DENIED);
    return FALSE;
  }
  $term = new stdClass();
  $term->name = $new_term['name'];
  $term->vid = $vid;
  if (!empty($new_term['parent'])) {
    $term->parent = $new_term['parent'][0];
  }
  taxonomy_term_save($term);
  $return = array(
    'id' => 'tid' . $term->tid,
    'tid' => $term->tid,
  );
  print drupal_json_output($return);
}