You are here

function notifications_content_form_submit in Notifications 6.2

Same name and namespace in other branches
  1. 5 notifications_content/notifications_content.module \notifications_content_form_submit()
  2. 6 notifications_content/notifications_content.pages.inc \notifications_content_form_submit()
  3. 6.3 notifications_content/notifications_content.pages.inc \notifications_content_form_submit()

Process generic form submission

1 string reference to 'notifications_content_form_submit'
notifications_tags_user_form in notifications_tags/notifications_tags.module
Returns the taxonomy subscription form

File

notifications_content/notifications_content.pages.inc, line 205
Subscriptions to content events

Code

function notifications_content_form_submit($form, &$form_state) {
  $form_values = $form_state['values'];
  $account = $form_values['account'];
  $current = $form_values['current'];
  $defaults = $form_values['defaults'];
  $defaults += array(
    'type' => 'node',
    '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);
    }
  }
  drupal_set_message(t('Your subscriptions have been updated.'));
}