You are here

function taxonomy_access_admin_form_submit in Taxonomy Access Control 5.2

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

File

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

Code

function taxonomy_access_admin_form_submit($form_id, $form_values) {
  switch ($form_values['op']) {
    case t('Delete selected'):
      if (is_array($form_values['selected_terms'])) {
        foreach ($form_values['selected_terms'] as $tid => $enabled) {
          if ($enabled) {

            // issue #167977 - klance
            $affected_nodes = _taxonomy_access_get_nodes_for_term($tid);
            db_query('DELETE FROM {term_access} WHERE rid = %d AND tid = %d', $form_values['rid'], $tid);

            // issue #167977 - klance
            _taxonomy_access_node_access_update($affected_nodes);
          }
        }
      }
      if (is_array($form_values['selected_defaults'])) {
        foreach ($form_values['selected_defaults'] as $vid => $enabled) {
          if ($enabled) {

            // issue #167977 - klance
            $affected_nodes = _taxonomy_access_get_nodes_for_vocabulary($vid, $form_values['rid']);
            db_query('DELETE FROM {term_access_defaults} WHERE rid = %d AND vid = %d', $form_values['rid'], $vid);

            // issue #167977 - klance
            _taxonomy_access_node_access_update($affected_nodes);
          }
        }
      }

      // issue #167977 - klance

      //node_access_rebuild();
      break;
    case t('Add'):
      $new = $form_values['new'];
      list($type, $id) = explode(' ', $new['item']);
      if ($type == 'term') {
        taxonomy_access_grant_update($id, $form_values['rid'], $new['grants']);
      }
      elseif ($type == 'default') {
        taxonomy_access_defaults_update($id, $form_values['rid'], $new['grants']);
      }

      // issue #167977 - klance

      //node_access_rebuild();
      break;
    case t('Save all'):
      foreach ($form_values['grants'] as $vid => $rows) {
        foreach ($rows as $tid => $grants) {
          if ($tid == 0) {
            taxonomy_access_defaults_update($vid, $form_values['rid'], $grants);
          }
          else {
            taxonomy_access_grant_update($tid, $form_values['rid'], $grants);
          }
        }
      }

      // issue #167977 - klance

      //node_access_rebuild();
      drupal_goto('admin/user/taxonomy_access');
  }
}