You are here

function domain_alias_form_submit in Domain Access 6.2

Same name and namespace in other branches
  1. 7.3 domain_alias/domain_alias.admin.inc \domain_alias_form_submit()
  2. 7.2 domain_alias/domain_alias.admin.inc \domain_alias_form_submit()

Forms_API for domain_alias_form().

File

domain_alias/domain_alias.admin.inc, line 238
Administration functions for the domain_alias module.

Code

function domain_alias_form_submit($form, &$form_state) {

  // The new alias fields are always present.
  foreach ($form_state['values']['domain_alias_new'] as $id => $alias) {
    if (!empty($alias['pattern'])) {
      $alias['pattern'] = _domain_alias_placeholders_to_sql($alias['pattern']);
      db_query("INSERT INTO {domain_alias} (domain_id, pattern, redirect) VALUES ('%d', '%s', '%d')", $form_state['values']['domain_id'], $alias['pattern'], intval($alias['redirect']));
    }
  }
  if (isset($form_state['values']['domain_alias'])) {
    foreach ($form_state['values']['domain_alias'] as $id => $alias) {
      $alias['pattern'] = _domain_alias_placeholders_to_sql($alias['pattern']);
      if ($alias['delete']) {
        db_query("DELETE FROM {domain_alias} WHERE alias_id = %d", $id);
      }
      else {
        db_query("UPDATE {domain_alias} SET pattern = '%s', redirect = '%d' WHERE alias_id = %d", $alias['pattern'], intval($alias['redirect']), $id);
      }
    }
  }
  drupal_set_message(t('Domain aliases updated successfully.'));

  // Clear the cache.
  cache_clear_all();
}