You are here

function agreement_form_submit in Agreement 6.2

Same name and namespace in other branches
  1. 6 agreement.module \agreement_form_submit()
  2. 7.2 agreement.pages.inc \agreement_form_submit()

Submit handler for agreement_form()

See also

agreement_form()

agreement_form_validate()

File

./agreement.module, line 433
agreement.module - Agreement module code

Code

function agreement_form_submit($form, &$form_state) {
  $uid = $form_state['values']['uid'];
  $agree = $form_state['values']['agree'];
  db_query("DELETE FROM {agreement} WHERE uid='%d'", $uid);
  db_query("INSERT INTO {agreement} (uid, agreed, sid, agreed_date) VALUES (%d, %d, '%s', %d)", $uid, $agree, session_id(), time());
  drupal_set_message(check_plain(variable_get('agreement_message_success', AGREEMENT_MESSAGE_SUCCESS)));

  // Send email notifying of acceptance if admin has set an email address.
  if ($to = variable_get('agreement_email_recipient', '')) {
    $params['account'] = user_load($uid);
    drupal_mail('agreement', 'notice', $to, user_preferred_language($params['account']), $params);
  }
  $agreement_success_destination = check_plain(variable_get('agreement_success_destination', ''));
  $agreement_success_destination = str_replace('&lt;front&gt;', '<front>', $agreement_success_destination);
  if ($_SESSION['agreement_destination'] == 'change password') {

    // Always go to user/%/edit page if original destination was user/reset.
    $redirect = 'user/' . $uid . '/edit';
  }
  elseif ($agreement_success_destination == '') {
    if ($_SESSION['agreement_destination'] == '') {
      $redirect = '<front>';
    }
    else {
      $redirect = $_SESSION['agreement_destination'];
    }
  }
  else {
    $redirect = $agreement_success_destination;
  }
  unset($_SESSION['agreement_destination']);
  $form_state['redirect'] = $redirect;
  return;
}