You are here

function signup_node_settings_form_submit in Signup 7

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

Submit handler for the per-node signup settings form.

Parameters

string $form_id: The ID of the form being submitted.

array $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 166
Code related to the per-node signup settings form.

Code

function signup_node_settings_form_submit($form, &$form_state) {
  $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_query("SELECT forwarding_email, send_confirmation, confirmation_email, close_signup_limit, send_reminder, reminder_days_before, reminder_email FROM {signup} WHERE nid = :nid", array(
      ':nid' => 0,
    ))
      ->fetchAssoc();
  }
  else {

    // 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...
  $node = $form['#node'];

  // TODO Please review the conversion of this statement to the D7 database API syntax.

  /* 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) */
  db_update('signup')
    ->fields($values)
    ->condition('nid', $node->nid)
    ->execute();

  // 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_query("SELECT SUM(count_towards_limit) FROM {signup_log} WHERE nid = :nid", array(
      ':nid' => $node->nid,
    ))
      ->fetchField();
    _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.'));
  }
}