You are here

function domain_theme_settings_submit in Domain Access 6.2

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

Process domain_theme_settings form submissions.

1 string reference to 'domain_theme_settings_submit'
domain_theme_form_alter in domain_theme/domain_theme.admin.inc
Implement hook_form_alter().

File

domain_theme/domain_theme.admin.inc, line 287
Include file to handle theme configration screen

Code

function domain_theme_settings_submit($form, &$form_state) {
  $values = $form_state['values'];
  $filepath = NULL;
  $reset = FALSE;
  $form_state['redirect'] = 'admin/build/domain/theme/' . $values['domain_id'];
  $domain = domain_lookup($values['domain_id']);
  if ($values['op'] == $values['reset']) {
    db_query("DELETE FROM {domain_theme} WHERE domain_id = %d AND theme = '%s'", $values['domain_id'], $values['theme']);
    drupal_set_message(t('The %theme settings for %domain have been reset.', array(
      '%theme' => $values['theme'],
      '%domain' => $domain['sitename'],
    )));
    $reset = TRUE;
  }
  $vars = array(
    'palette',
    'stylesheets',
    'logo',
    'files',
    'screenshot',
  );
  foreach ($vars as $variable) {
    $preset = variable_get('color_' . $values['theme'] . '_' . $variable, '');
    if (!empty($preset)) {
      $values['color_' . $values['theme'] . '_' . $variable] = $preset;
    }
  }

  // If our domain uses different schemes, we have to ensure that the {variable} table stays accurate
  // for the primary domain.
  if (isset($values['domain_color_defaults'])) {
    foreach ($values['domain_color_defaults'] as $key => $value) {
      if (!empty($value)) {
        variable_set($key, domain_unserialize($value));
      }
      else {
        variable_del($key);
      }
    }
  }

  // Set the filepath for color module.
  if (!empty($values['color_' . $values['theme'] . '_stylesheets'][0])) {
    $filepath = domain_theme_get_color_path($values['color_' . $values['theme'] . '_stylesheets'][0]);
  }

  // If a reset, stop here.
  if ($reset) {
    return;
  }
  $key = $values['var'];
  $domain_id = $values['domain_id'];
  $theme = $values['theme'];

  // If no record exists, we behave differently.
  $check = db_result(db_query("SELECT 1 FROM {domain_theme} WHERE domain_id = %d AND theme = '%s'", $domain_id, $theme));
  if ($values['op'] == $values['reset'] && $check) {
    db_query("UPDATE {domain_theme} SET settings = NULL, filepath = NULL WHERE domain_id = %d AND theme = '%s'", $domain_id, $theme);
    drupal_set_message(t('The configuration options have been reset to their default values.'));
  }
  else {

    // Exclude unnecessary elements before saving.
    unset($values['var'], $values['submit'], $values['reset'], $values['form_id'], $values['op'], $values['form_build_id'], $values['form_token'], $values['domain_id'], $values['domain_color'], $values['domain_color_defaults']);
    $settings = serialize($values);
    if ($check > 0) {
      db_query("UPDATE {domain_theme} SET settings = %b, filepath = '%s' WHERE domain_id = %d AND theme = '%s'", $settings, $filepath, $domain_id, $theme);
    }
    else {
      db_query("INSERT INTO {domain_theme} (domain_id, theme, settings, status, filepath) VALUES (%d, '%s', %b, 0, '%s')", $domain_id, $theme, $settings, $filepath);
    }
    drupal_set_message(t('The configuration options have been saved.'));
  }

  // If nothing is active, then we make this one active.
  $active = db_result(db_query("SELECT 1 FROM {domain_theme} WHERE domain_id = %d AND status = 1", $domain_id));
  if (empty($active)) {
    db_query("UPDATE {domain_theme} SET status = 1 WHERE domain_id = %d AND theme = '%s'", $domain_id, $theme);
    drupal_set_message(t('%theme has been set as the default theme for %domain', array(
      '%theme' => $theme,
      '%domain' => $domain['sitename'],
    )));
  }

  // Clear the cache.
  cache_clear_all();
}