You are here

function signup_node_settings_form_submit in Signup 6.2

Same name and namespace in other branches
  1. 6 includes/node_settings.inc \signup_node_settings_form_submit()
  2. 7 includes/node_settings.inc \signup_node_settings_form_submit()

Submit handler for the per-node signup settings form.

Parameters

$form_id: The ID of the form being submitted.

$form_values: The constructed form values array of the submitted form.

1 string reference to 'signup_node_settings_form_submit'
signup_node_settings_form in includes/node_settings.inc
Returns the form for the per-node signup settings.

File

includes/node_settings.inc, line 311
Code related to the per-node signup settings form.

Code

function signup_node_settings_form_submit($form, &$form_state) {
  $node = $form['#node'];
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  if ($op == t('Reset to defaults')) {

    // If we're resetting, we just want to grab the site-wide defaults.
    $values = db_fetch_array(db_query("SELECT forwarding_email, send_confirmation, confirmation_email, close_signup_limit, send_reminder, reminder_days_before, reminder_email FROM {signup} WHERE nid = 0"));

    // Clear all the panes for the node.
    db_query("DELETE FROM {signup_panes} WHERE nid = %d", $node->nid);
  }
  else {

    // Handle the pane settings.
    _signup_node_settings_panes_save($form_state['values']['signup_form_panes'], $node->nid);

    // Populate $values from $form_state.
    foreach (array(
      'forwarding_email',
      'send_confirmation',
      'confirmation_email',
      'close_signup_limit',
    ) as $setting) {
      $values[$setting] = $form_state['values']["signup_{$setting}"];
    }

    // If we're dealing with a node that doesn't have a start time, these
    // fields are missing from the signup settings form, so we can't assume
    // they're defined.
    $values['send_reminder'] = isset($form_state['values']['signup_send_reminder']) ? $form_state['values']['signup_send_reminder'] : 0;
    $values['reminder_days_before'] = isset($form_state['values']['signup_reminder_days_before']) ? $form_state['values']['signup_reminder_days_before'] : 0;
    $values['reminder_email'] = isset($form_state['values']['signup_reminder_email']) ? $form_state['values']['signup_reminder_email'] : '';
  }

  // Either way, we want to make sure we're updating the values for the
  // current node, not nid 0...
  $values[] = $node->nid;
  db_query("UPDATE {signup} SET forwarding_email = '%s', send_confirmation = %d, confirmation_email = '%s', close_signup_limit = %d, send_reminder = %d, reminder_days_before = %d, reminder_email = '%s' WHERE nid = %d", $values);

  // See if the limit changed, and if so, take any necessary action.
  if ($node->signup_close_signup_limit != $form_state['values']['signup_close_signup_limit']) {
    $node->signup_close_signup_limit = $form_state['values']['signup_close_signup_limit'];
    $node->signup_effective_total = db_result(db_query("SELECT SUM(count_towards_limit) FROM {signup_log} WHERE nid = %d", $node->nid));
    _signup_check_limit($node, 'limit');
  }
  if ($op == t('Reset to defaults')) {
    drupal_set_message(t('The configuration options have been reset to their default values.'));
  }
  else {
    drupal_set_message(t('The configuration options have been saved.'));
  }
}