You are here

function taxonomy_access_admin_form in Taxonomy Access Control 5.2

Same name and namespace in other branches
  1. 6 taxonomy_access.admin.inc \taxonomy_access_admin_form()

Form for managing grants by role.

2 string references to 'taxonomy_access_admin_form'
taxonomy_access_admin in ./taxonomy_access_admin.inc
Menu callback; presents the category permissions page of TAC (admin/user/taxonomy_access).
taxonomy_access_menu in ./taxonomy_access.module
Implementation of hook_menu

File

./taxonomy_access_admin.inc, line 119
Administrative interface for taxonomy access control.

Code

function taxonomy_access_admin_form($rid) {

  // Fetch all default grants
  $result = db_query('SELECT * FROM {term_access_defaults} WHERE rid = %d', $rid);
  while ($row = db_fetch_array($result)) {
    $default_grants[$row['vid']] = $row;
  }

  // Fetch all grants
  $result = db_query('SELECT * FROM {term_access} WHERE rid = %d', $rid);
  while ($row = db_fetch_array($result)) {
    $grants[$row['tid']] = $row;
  }
  $form['rid'] = array(
    '#type' => 'value',
    '#value' => $rid,
  );
  $form['grants'] = $form['selected_terms'] = $form['selected_defaults'] = array(
    '#tree' => TRUE,
  );

  //Global default
  $form['vocabs'][0]['#title'] = 'Global';
  $form['grants'][0][0] = taxonomy_access_admin_build_row($default_grants[0]);
  $form['selected_defaults'][0] = array(
    '#type' => 'checkbox',
    '#disabled' => TRUE,
    '#title' => '<em>default<em>',
    '#description' => 'can\'t be disabled without disabling TAC for this role',
  );
  foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
    $form['vocabs'][$vid]['#title'] = check_plain($vocabulary->name);
    if (isset($default_grants[$vid])) {
      $form['grants'][$vid][0] = taxonomy_access_admin_build_row($default_grants[$vid]);
      $form['selected_defaults'][$vid] = array(
        '#type' => 'checkbox',
        '#title' => '<em>default<em>',
      );
    }
    else {
      $add_items[$vocabulary->name]["default {$vid}"] = '*default*';
    }
    if ($tree = taxonomy_get_tree($vid)) {
      foreach ($tree as $term) {
        if (isset($grants[$term->tid])) {
          $form['grants'][$vid][$term->tid] = taxonomy_access_admin_build_row($grants[$term->tid]);
          $form['selected_terms'][$term->tid] = array(
            '#type' => 'checkbox',
            '#title' => str_repeat('&nbsp;&nbsp;', $term->depth) . check_plain($term->name),
          );
        }
        else {
          $add_items[$vocabulary->name]["term {$term->tid}"] = str_repeat('-', $term->depth) . check_plain($term->name);
        }
      }
    }
  }

  //New grant row
  if (isset($add_items)) {
    $form['new']['grants'] = taxonomy_access_admin_build_row();
    $form['new']['#tree'] = TRUE;
    $form['new']['item'] = array(
      '#type' => 'select',
      '#options' => $add_items,
    );
    $form['new']['add'] = array(
      '#type' => 'submit',
      '#value' => t('Add'),
    );
  }
  $form['delete'] = array(
    '#type' => 'submit',
    '#value' => t('Delete selected'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save all'),
  );
  return $form;
}