You are here

function subscriptions_page_form_submit in Subscriptions 6

Same name and namespace in other branches
  1. 5.2 subscriptions.admin.inc \subscriptions_page_form_submit()
  2. 7 subscriptions.admin.inc \subscriptions_page_form_submit()
  3. 2.0.x subscriptions.admin.old.php \subscriptions_page_form_submit()

Subscriptions page submit handler.

4 string references to 'subscriptions_page_form_submit'
subscriptions_blog_ui_blog_form in ./subscriptions_blog_ui.module
Returns the blog subscription form.
subscriptions_content_node_form in ./subscriptions_content.module
Build the Thread subscriptions form at user/UID/subscriptions/node.
subscriptions_content_type_form in ./subscriptions_content.module
Build the Content Types subscriptions form at user/UID/subscriptions/type.
subscriptions_taxonomy_taxa_form in ./subscriptions_taxonomy.module
Build the Categories subscription form at user/UID/subscriptions/taxa.

File

./subscriptions.admin.inc, line 160
Subscriptions module (load-on-demand admin functions).

Code

function subscriptions_page_form_submit($form, &$form_state) {
  global $user;
  if (isset($form_state['values']['header']['role']['roles'])) {
    $rid0 = current($form_state['values']['header']['role']['roles']);
  }
  if ($form_state['values']['op'] == $form_state['values']['submit']) {
    if (empty($rid0)) {
      $bulk_op = empty($_SESSION['subscriptions']['bulk_op']) ? '' : $_SESSION['subscriptions']['bulk_op'];
      if ($bulk_op) {
        foreach (unserialize($form_state['values']['uid']) as $uid) {
          $form_state['values']['header']['role']['roles'][] = -$uid;
        }
        $form_state['redirect'] = 'admin/settings/subscriptions/userdefaults/bulk';
      }
      else {
        $form_state['values']['header']['role']['roles'][] = -$form_state['values']['uid'];

        // will be negated again below
      }
    }
    $module = $form_state['values']['module'];
    $field = $form_state['values']['field'];
    $access_key = isset($form_state['values']['access_key']) ? $form_state['values']['access_key'] : $module;
    foreach ($form_state['values'] as $element_values) {
      if (isset($element_values[0])) {
        $element_values = $element_values[0];
      }
      if (isset($element_values['defaults']['send_interval'])) {
        $defaults = $element_values['defaults'];
        foreach ($element_values['checkboxes'] as $value => $bundle) {
          foreach ($bundle as $author_uid => $set_to_enabled) {
            if ($set_to_enabled && $bulk_op != 'unsub' && (!isset($defaults['checkboxes'][$value][$author_uid]) || $element_values['send_interval'][$value][$author_uid] != $defaults['send_interval'][$value][$author_uid] || empty($element_values['send_updates'][$value][$author_uid]) != empty($defaults['send_updates'][$value][$author_uid]) || empty($element_values['send_comments'][$value][$author_uid]) != empty($defaults['send_comments'][$value][$author_uid]))) {
              $send_updates = empty($element_values['send_updates'][$value][$author_uid]) ? 0 : 1;
              $send_comments = empty($element_values['send_comments'][$value][$author_uid]) ? 0 : 1;
              foreach ($form_state['values']['header']['role']['roles'] as $uid) {
                subscriptions_write($access_key, $module, $field, $value, $author_uid, -$uid, $element_values['send_interval'][$value][$author_uid], $send_updates, $send_comments);
              }
              $changed = TRUE;
            }
            elseif ($bulk_op == 'unsub' && $set_to_enabled || !$set_to_enabled && isset($defaults['checkboxes'][$value][$author_uid])) {

              // It was bulk-unsubscribed, or it was enabled but now it is not. Delete.
              foreach ($form_state['values']['header']['role']['roles'] as $uid) {
                db_query("DELETE FROM {subscriptions} WHERE module = '%s' AND field = '%s' AND value = '%s' AND author_uid = %d AND recipient_uid = %d", $module, $field, $value, $author_uid, -$uid);
              }
              $changed = TRUE;
            }
          }
        }
      }
    }
    if (!empty($changed)) {
      drupal_set_message(t('Your subscriptions were updated.'));
    }
  }
  if (!empty($rid0)) {
    $form_state['redirect'] = 'admin/settings/subscriptions/userdefaults/' . subscriptions_arg(4);
    if ($rid0 != DRUPAL_AUTHENTICATED_RID) {
      $form_state['redirect'] .= '/' . $rid0;
    }
  }
}