You are here

function subscriptions_page_form_submit in Subscriptions 7

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

Subscriptions page submit handler.

_state

Parameters

array $form:

1 string reference to 'subscriptions_page_form_submit'
subscriptions_page_form in ./subscriptions.admin.inc
Display subscribed content data on the user and site subscriptions pages. @ TODO clean up all of these parts

File

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

Code

function subscriptions_page_form_submit(array $form, array &$form_state) {
  $form_values =& $form_state['values'];
  if (isset($form_values['header']['role']['roles'])) {
    $rid0 = current($form_values['header']['role']['roles']);
  }
  if ($form_values['op'] == $form['submit']['#value']) {

    // If we have rids, then they are >0, but we'll have to store them as
    // negative numbers below; if we have uids, we use the negative values
    // so they will end up positive in the database.
    if ($bulk_op = empty($_SESSION['subscriptions']['bulk_op']) ? '' : $_SESSION['subscriptions']['bulk_op']) {
      $rids = array();
      foreach (unserialize($form_values['uid']) as $uid) {
        $rids[] = -$uid;
      }
      $form_state['redirect'] = SUBSCRIPTIONS_CONFIG_PATH . '/userdefaults/bulk';
    }
    else {
      $rids = empty($rid0) ? array(
        -$form_values['uid'],
      ) : $form_values['header']['role']['roles'];
    }
    $module = $form_values['module'];
    $field = $form_values['field'];
    $access_key = isset($form_values['access_key']) ? $form_values['access_key'] : $module;
    foreach ($form_values as $element_values) {
      if (is_array($element_values) && 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' && (count($rids) > 1 || !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]))) {

              // Something has changed, or we have more than one rid,
              // which means we can't know whether something has changed.
              $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 ($rids as $rid) {
                subscriptions_write($access_key, $module, $field, $value, $author_uid, -$rid, $element_values['send_interval'][$value][$author_uid], $send_updates, $send_comments);
              }
              $changed = TRUE;
            }
            elseif ($bulk_op == 'unsub' && $set_to_enabled || empty($bulk_op) && !$set_to_enabled && (count($rids) > 1 || isset($defaults['checkboxes'][$value][$author_uid]))) {

              // It was bulk-unsubscribed, or it was enabled but now it is not. Delete.
              foreach ($rids as $rid) {
                subscriptions_delete(-$rid, $module, $field, $value, $bulk_op == 'unsub' ? NULL : $author_uid);
              }
              $changed = TRUE;
            }
          }
        }
      }
    }
    if (!empty($changed)) {
      drupal_set_message(t('Your subscriptions were updated.'));
    }
  }
  if (!empty($rid0)) {
    $subs_type = subscriptions_arg(SUBSCRIPTIONS_CONFIG_PATH_LEVEL + 1);
    $form_state['redirect'] = SUBSCRIPTIONS_CONFIG_PATH . '/userdefaults/' . $subs_type;
    if ($rid0 != DRUPAL_AUTHENTICATED_RID) {
      $form_state['redirect'] .= '/' . $rid0;
    }
  }
}