You are here

function notifications_user_form_submit in Notifications 5

Same name and namespace in other branches
  1. 6.4 notifications.module \notifications_user_form_submit()
  2. 6 notifications.module \notifications_user_form_submit()
  3. 6.2 notifications.module \notifications_user_form_submit()
  4. 6.3 notifications.module \notifications_user_form_submit()

Process generic form submission

File

./notifications.admin.inc, line 622

Code

function notifications_user_form_submit($form_id, $form_values) {
  $account = $form_values['account'];
  $current = $form_values['current'];
  $defaults = $form_values['defaults'];
  $defaults += array(
    'uid' => $account->uid,
  );
  $fields = $form_values['subscription_fields'];
  $values = $form_values['subscriptions'];
  $check = 'checkbox';
  foreach ($values[$check] as $index => $value) {
    $subscription = NULL;
    if ($value) {

      // Checked, save only if new or changed
      if (!isset($current[$index])) {
        $subscription = $defaults;
      }
      elseif ($current[$index]->send_interval != $values['send_interval'][$index] || $current[$index]->send_method != $values['send_method'][$index]) {
        $subscription = (array) $current[$index];
      }

      // Complete and save
      if ($subscription) {
        $subscription['send_interval'] = $values['send_interval'][$index];
        $subscription['send_method'] = $values['send_method'][$index];
        $subscription['fields'] = $fields[$index];
        notifications_save_subscription($subscription);
      }
    }
    elseif (isset($current[$index])) {
      notifications_delete_subscription($current[$index]->sid);
    }
  }
}