You are here

function notifications_manage_subscriptions_form in Notifications 6.4

Same name and namespace in other branches
  1. 6 notifications.manage.inc \notifications_manage_subscriptions_form()
  2. 6.2 notifications.manage.inc \notifications_manage_subscriptions_form()
  3. 6.3 notifications.manage.inc \notifications_manage_subscriptions_form()
  4. 7 notifications.manage.inc \notifications_manage_subscriptions_form()

Administer user subscriptions

Parameters

$account: User account or destination

2 calls to notifications_manage_subscriptions_form()
notifications_admin_manage_subscriptions in ./notifications.admin.inc
Menu callback: subscriptions administration.
notifications_manage_user_subscriptions in ./notifications.manage.inc
Menu callback: user subscriptions management

File

./notifications.manage.inc, line 52
Common functions for bulk management of subscriptions

Code

function notifications_manage_subscriptions_form($account = NULL, $full = TRUE) {
  $filter = notifications_subscriptions_build_filter_query($account);
  if ($account) {
    $result = pager_query('SELECT n.*, d.address FROM {notifications} n INNER JOIN {messaging_destination} d ON n.mdid = d.mdid ' . $filter['join'] . $filter['where'] . ' ORDER BY n.sid DESC', 50, 0, NULL, $filter['args']);
  }
  else {
    $result = pager_query('SELECT n.*, d.address, u.name AS user_name FROM {notifications} n INNER JOIN {messaging_destination} d ON n.mdid = d.mdid ' . $filter['join'] . ' INNER JOIN {users} u ON n.uid = u.uid ' . $filter['where'] . ' ORDER BY n.sid DESC', 50, 0, NULL, $filter['args']);
  }
  $form = notifications_manage_subscriptions_form_options($account);
  $form_destination = drupal_get_destination();
  $subscriptions = array();
  $status = Notifications_Subscription::status_list();
  $send_methods = messaging_method_info(NULL, 'name');
  $send_intervals = notifications_send_intervals();
  while ($object = db_fetch_object($result)) {
    $sub = notifications_load_subscription($object);
    $subscriptions[$sub->sid] = '';

    // Naming for this specific subscription, formatted strings
    $form['type'][$sub->sid] = array(
      '#value' => $sub
        ->get_type('title'),
    );

    // If full loading, load full subscription and add description
    if ($full) {
      $form['description'][$sub->sid] = array(
        '#value' => $sub
          ->get_name(),
      );
    }

    // If not account, this is an admin form for multiple users, print full account and address
    if (!$account) {
      if ($sub->uid) {
        $username = $sub
          ->get_user_name();
      }
      else {

        // Anonymous subscription, print destination instead
        $dest = $sub
          ->get_destination();
        $username = $dest
          ->address_name() . ' ' . l($dest
          ->format_address(FALSE), 'notifications/destination/' . $sub->mdid . '/manage');
      }
      $form['username'][$sub->sid] = array(
        '#value' => $username,
      );
    }
    $form['send_method'][$sub->sid] = array(
      '#value' => !empty($send_methods[$sub->send_method]) ? $send_methods[$sub->send_method] : $sub->send_method,
    );
    $form['send_interval'][$sub->sid] = array(
      '#value' => !empty($send_intervals[$sub->send_interval]) ? $send_intervals[$sub->send_interval] : $sub->send_interval,
    );
    $form['status'][$sub->sid] = array(
      '#value' => $status[$sub->status],
    );

    // These links will be different depending on whether we are under admin or user account
    if ($account) {
      $operations = array(
        l(t('edit'), 'user/' . $account->uid . '/notifications/subscriptions/edit/' . $sub->sid, array(
          'query' => $form_destination,
        )),
        l(t('drop'), 'user/' . $account->uid . '/notifications/subscriptions/delete/' . $sub->sid, array(
          'query' => $form_destination,
        )),
      );
    }
    else {
      $operations = array(
        l(t('edit'), 'notifications/subscription/' . $sub->sid, array(
          'query' => $form_destination,
        )),
        l(t('drop'), 'notifications/unsubscribe/sid/' . $sub->sid, array(
          'query' => $form_destination,
        )),
      );
    }
    $form['operations'][$sub->sid] = array(
      '#value' => implode(', ', $operations),
    );
  }
  $form['subscriptions'] = array(
    '#type' => 'checkboxes',
    '#options' => $subscriptions,
  );
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  $form['#theme'] = 'notifications_manage_subscriptions';
  return $form;
}