You are here

function weather_display_settings_form_submit in Weather 7

Implement hook_form_submit().

File

./weather.forms.inc, line 283
Provide forms for configuration of weather displays.

Code

function weather_display_settings_form_submit($form, &$form_state) {
  if ($form_state['values']['number'] == NULL) {

    // The number does not exist, so insert a new entry.
    $used_numbers = weather_get_displays_in_use($form_state['values']['type']);
    $free_number = 1;
    foreach ($used_numbers as $number) {
      if ($number > $free_number) {
        break;
      }
      else {
        $free_number++;
      }
    }
    db_insert('weather_display')
      ->fields(array(
      'type' => $form_state['values']['type'],
      'number' => $free_number,
      'units' => serialize($form_state['values']['units']),
      'settings' => serialize($form_state['values']['settings']),
    ))
      ->execute();
  }
  else {

    // The number already exists, so overwrite the entry.
    db_merge('weather_display')
      ->key(array(
      'type' => $form_state['values']['type'],
      'number' => $form_state['values']['number'],
    ))
      ->fields(array(
      'units' => serialize($form_state['values']['units']),
      'settings' => serialize($form_state['values']['settings']),
    ))
      ->execute();
  }
  if ($form_state['values']['type'] == 'user') {
    $path = 'user/' . $form_state['values']['number'] . '/weather';
  }
  else {
    $path = 'admin/config/user-interface/weather';
  }
  $form_state['redirect'] = $path;
}