You are here

function subscriptions_page_form in Subscriptions 2.0.x

Same name and namespace in other branches
  1. 7 subscriptions.admin.inc \subscriptions_page_form()

Display subscribed content data on the user and site subscriptions pages. @ TODO clean up all of these parts

_state

Parameters

$form:

object|null $account:

string $stype:

Return value

array|null

1 string reference to 'subscriptions_page_form'
subscriptions_menu in ./subscriptions.module.old.php
Implements hook_menu().

File

./subscriptions.admin.old.php, line 255
Subscriptions module (load-on-demand admin functions).

Code

function subscriptions_page_form($form, &$form_state, $account, $stype) {
  $stypes = subscriptions_types();
  if (!isset($stypes[$stype])) {
    drupal_not_found();
    return NULL;
  }
  if (subscriptions_arg(0) == 'admin') {
    $form['header'] = array(
      '#type' => 'fieldset',
      '#title' => t('Admin Information'),
      '#attributes' => array(
        'class' => array(
          'error',
        ),
      ),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#weight' => -2,
    );
    if (empty($_SESSION['subscriptions']['bulk_op'])) {
      $form['header'][] = array(
        '#markup' => '<div>' . t('The selected subscriptions will be given to <b>newly created</b> users.') . '</div>',
      );
      $tr = 't';
      $rid = subscriptions_arg(SUBSCRIPTIONS_CONFIG_PATH_LEVEL + 2);
      $form['header']['role'] = array(
        '#type' => 'fieldset',
        '#title' => check_plain($tr('Roles')),
        '#collapsible' => TRUE,
        '#collapsed' => !is_numeric($rid),
      );
      $form['header']['role']['header'] = array(
        '#markup' => '<div>' . t('If a user has one or more roles assigned at creation time, then she will receive the additional subscriptions defined for these roles.') . '</div>',
        '#weight' => -5,
      );
      $rid = is_numeric($rid) ? $rid : DRUPAL_AUTHENTICATED_RID;
      $form['header']['role']['roles'] = array(
        '#type' => 'select',
        '#title' => t('Role(s)'),
        '#default_value' => array(
          $rid,
        ),
        '#options' => user_roles(TRUE),
        '#description' => t('Select the role to load or role(s) to save.'),
        '#multiple' => TRUE,
      );
      $form['header']['role']['load'] = array(
        '#type' => 'submit',
        '#value' => t('Load'),
      );
    }
    else {
      $bulk_op = $_SESSION['subscriptions']['bulk_op'];
      $variables = _subscriptions_page_user_bulk_variables();
      $output = $variables['info'] . '<br />';
      $output .= t('Select the subscriptions to !change and click [@Save] to perform the action for the selected users.', $variables);
      if ($bulk_op == 'unsub') {
        $output .= '<br /><strong>' . t('This action cannot be undone!') . '</strong>';
      }
      $form['header']['info'] = array(
        '#markup' => $output,
      );
    }
  }
  else {
    subscriptions_suspended(subscriptions_arg(1, 'uid'), TRUE);

    //if (variable_get('subscriptions_hide_overview_page', 0)) {

    //  $dummy_form_state = NULL;
    //  $form = subscriptions_user_suspend_form($dummy_form_state, $account);

    //}
    $form['header'][] = array(
      '#markup' => t('Current subscriptions:'),
      '#weight' => -2,
    );
  }
  $uid = empty($account) ? -DRUPAL_AUTHENTICATED_RID : (is_object($account) ? $account->uid : -$account);
  $bulk_uids = empty($_SESSION['subscriptions']['bulk_op']) ? NULL : $_SESSION['subscriptions']['uids'];
  $form['#tree'] = TRUE;
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => isset($bulk_uids) ? $bulk_uids : $uid,
  );
  $form['access_key'] = array(
    '#type' => 'value',
    '#value' => $stype,
  );
  $form['module'] = array(
    '#type' => 'value',
    '#value' => $stypes[$stype]['fields'][0],
  );
  $form['field'] = array(
    '#type' => 'value',
    '#value' => $stypes[$stype]['fields'][1],
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 10,
  );
  $form['#submit'][] = 'subscriptions_page_form_submit';
  $form['footer'] = array(
    '#type' => 'item',
    '#description' => t('The master checkboxes in the left-most column turn the given subscription on or off. To turn a range of subscriptions on or off, click and Shift-click.') . '<br />' . t('Depending on the setup of the site, you may have additional options for active subscriptions.'),
    '#weight' => 4,
  );
  $callback = $stypes[$stype]['page'];
  if (!empty($callback) && function_exists($callback)) {
    $form = $callback($form, isset($bulk_uids) ? 0 : $uid);
    if (is_string($form)) {
      $form = array(
        'message' => array(
          '#type' => 'item',
          '#markup' => '<br /><br />' . $form,
        ),
      );
    }
  }

  //$form = function_exists($callback) ? $callback($account, $form) : NULL;

  //drupal_add_link(array(

  //  'rel' => 'alternate',
  //  'type' => 'application/rss+xml',
  //  'title' => t('!name Subscriptions', array('!name' => $user->name)),
  //  'href' => url('subscriptions/feed'),

  //));
  drupal_set_title(empty($account->name) ? t('Subscriptions') : format_username($account));
  return $form;
}