You are here

function node_breadcrumb_admin_settings_submit in Node breadcrumb 6

File

./node_breadcrumb.module, line 262

Code

function node_breadcrumb_admin_settings_submit($form, &$form_state) {
  if (isset($form_state['values']['mid'])) {
    $mid = $form_state['values']['mid'];
    $mid_colon = strpos($mid, ":");
    $mid = $mid_colon === FALSE ? NULL : substr($mid, $mid_colon + 1);
  }
  if ($form_state['values']['op'] == t('Delete rule')) {
    foreach ($form_state['values']['delete'] as $value) {
      if ($value) {
        $rids[] = $value + 0;
      }
    }
    if ($rids) {
      db_query("DELETE FROM {node_breadcrumb_rule} WHERE rid IN (%s)", join(",", $rids));
      drupal_set_message(t('Rule(s) deleted.'));
    }
  }
  elseif ($form_state['values']['op'] == t('Save')) {
    foreach ($form_state['values'] as $key => $weight) {
      if (substr($key, 0, 7) == 'weight_') {
        $rid = substr($key, 7);
        db_query("update {node_breadcrumb_rule} set weight=%d where rid=%d", $weight, $rid);
      }
    }
    drupal_set_message(t("Weights applied."));
  }
  elseif ($form_state['values']['op'] == t('Add rule')) {
    $tid = array();
    foreach ($form_state['values'] as $key => $value) {
      if (substr($key, 0, 4) == 'vid_' && $value != 0) {
        $tid[] = $value;
      }
    }
    $a = $GLOBALS['db_type'] == 'pgsql' ? "" : "`";
    db_query("INSERT INTO {node_breadcrumb_rule} (node_type, tid1, tid2, mid, weight, %scondition%s) VALUES ('%s', %d, %d, %d, %d, '%s')", $a, $a, $form_state['values']['node_type'], $tid[0], $tid[1], $mid, $form_state['values']['weight'], $form_state['values']['condition']);
    drupal_set_message(t('Rule added.'));
  }
  elseif ($form_state['values']['op'] == t('Save rule')) {
    $tid = array();
    foreach ($form_state['values'] as $key => $value) {
      if (substr($key, 0, 4) == 'vid_' && $value != 0) {
        $tid[] = $value;
      }
    }
    $a = $GLOBALS['db_type'] == 'pgsql' ? "" : "`";
    db_query("UPDATE {node_breadcrumb_rule} SET node_type='%s', tid1=%d, tid2=%d, mid=%d, weight=%d, %scondition%s='%s' WHERE rid=%d", $form_state['values']['node_type'], $tid[0], $tid[1], $mid, $form_state['values']['weight'], $a, $a, $form_state['values']['condition'], $form_state['values']['rid']);
    drupal_set_message(t('Rule saved.'));
    $form_state['redirect'] = "admin/settings/node_breadcrumb";
  }
  elseif ($form_state['values']['op'] == t('Cancel')) {
    $form_state['redirect'] = "admin/settings/node_breadcrumb";
  }
}