function tac_fields_admin_form_submit in Taxonomy Access Control 6
Submit handler for permission administration form.
@todo This is cloned from TAC; finish.
File
- tac_fields/
tac_fields.admin.inc, line 513 - Administrative interface for TAC Fields.
Code
function tac_fields_admin_form_submit($form, &$form_state) {
$values = $form_state['values'];
$field = $values['field'];
$rid = $values['rid'];
switch ($values['op']) {
case t('Delete selected'):
if (is_array($values['selected_terms'])) {
foreach ($values['selected_terms'] as $tid => $enabled) {
if ($enabled) {
db_query("DELETE FROM {term_field_access} \n WHERE field = '%s' AND rid = %d AND tid = %d", $field, $rid, $tid);
}
}
}
if (is_array($values['selected_defaults'])) {
foreach ($values['selected_defaults'] as $vid => $enabled) {
if ($enabled) {
db_query("DELETE FROM {term_field_access_defaults} \n WHERE field = '%s' AND rid = %d AND vid = %d", $field, $rid, $vid);
}
}
}
break;
case t('Add'):
$new = $values['new'];
list($type, $id) = explode(' ', $new['item']);
if ($type == 'term') {
if ($new['recursive'] == 1) {
tac_fields_recursive_update($id, $field, $rid, $new['grants']);
}
else {
tac_fields_update_grants($id, $field, $rid, $new['grants']);
}
}
elseif ($type == 'default') {
tac_fields_update_defaults($id, $field, $rid, $new['grants']);
}
break;
case t('Save all'):
foreach ($values['grants'] as $vid => $rows) {
foreach ($rows as $tid => $grants) {
// Check the default values for this row.
$defaults = array();
foreach ($grants as $grant_name => $value) {
$defaults[$grant_name] = $form['grants'][$vid][$tid][$grant_name]['#default_value'];
}
// Proceed if the user changed the row (values differ from defaults).
if ($defaults != $grants) {
if ($tid == 0) {
tac_fields_update_defaults($vid, $field, $rid, $grants);
}
else {
tac_fields_update_grants($tid, $field, $rid, $grants);
}
}
}
}
drupal_goto('admin/user/tac_fields');
break;
}
}