You are here

function uc_recurring_subscription_overview in UC Recurring Payments and Subscriptions 6.2

Same name and namespace in other branches
  1. 7.2 modules/uc_recurring_subscription/uc_recurring_subscription.admin.inc \uc_recurring_subscription_overview()

Create the subscription overiew page.

1 string reference to 'uc_recurring_subscription_overview'
uc_recurring_subscription_menu in modules/uc_recurring_subscription/uc_recurring_subscription.module
Implementation of hook_menu().

File

modules/uc_recurring_subscription/uc_recurring_subscription.admin.inc, line 11
Uc recurring subscription UI.

Code

function uc_recurring_subscription_overview() {

  // Warn user if the ubercart API patch not applied.
  if (!function_exists('uc_attribute_load_multiple')) {
    drupal_set_message(t('This module requires a patch to ubercart, read the <a href="@readme">README.txt</a>', array(
      '@readme' => url(drupal_get_path('module', 'uc_recurring_subscription') . '/README.txt'),
    )), 'error');
    return '';
  }
  drupal_add_css(drupal_get_path('module', 'uc_recurring_subscription') . '/uc_recurring_subscription.css');
  $product_class = variable_get('uc_recurring_subscription_product_class', 'uc_recurring_subscription');
  $result = db_query("SELECT n.nid, n.title\n                      FROM {node} n\n                        LEFT JOIN {uc_recurring_subscription} rs ON rs.nid=n.nid\n                      WHERE n.type = '%s'\n                      ORDER BY rs.weight", $product_class);
  $roles = user_roles(TRUE);
  $form['products']['#tree'] = TRUE;
  $form['products']['#theme'] = 'uc_recurring_subscription_products';
  while ($node = db_fetch_object($result)) {
    $product = node_load($node->nid);
    $attribute = uc_attribute_load(variable_get('uc_recurring_subscription_attribute', ''));

    // roles
    $product_roles = array();
    if (!empty($product->subscription->access['subscribe_grant'])) {
      $product_roles = array_intersect_key($roles, $product->subscription->access['subscribe_grant']);
    }

    // payment options
    $products = _uc_recurring_subscription_get_product_features($node->nid);
    $intervals = array();
    foreach ($products as $id => $feature) {
      $interval = uc_price($feature->fee_amount, array()) . ' - ' . _uc_recurring_subscription_create_attribute_option($feature->regular_interval_value, $feature->regular_interval_unit);
      if ($product->attributes[$attribute->aid]->default_option == $feature->option->oid) {
        $interval = '<span class="default-option">' . $interval . '</span>';
      }
      if (module_exists('uc_cart_links')) {
        $interval .= ' ' . t('(<a href="@link">cart link</a>)', array(
          '@link' => url('cart/add/e-p' . $node->nid . '_q1_a' . $attribute->aid . 'o' . $feature->option->oid . '-isub', array(
            'query' => 'destination=cart/checkout',
            'absolute' => TRUE,
          )),
        ));
      }
      if ($feature->regular_interval_value != $feature->initial_charge_value && $feature->regular_interval_unit != $feature->initial_charge_unit) {
        $trial = uc_price($product->sell_price, array()) . ' - ' . $feature->initial_charge_value . ' ' . $feature->initial_charge_unit;
      }
      $intervals[] = $interval;
    }
    $form['products'][$node->nid]['title'] = array(
      '#value' => l($product->title, 'node/' . $product->nid),
    );
    $form['products'][$node->nid]['role'] = array(
      '#value' => implode(', ', $product_roles),
    );
    $form['products'][$node->nid]['trial'] = array(
      '#value' => empty($trial) ? t('None') : $trial,
    );
    $form['products'][$node->nid]['interval'] = array(
      '#value' => implode('<br/>', $intervals),
    );
    $form['products'][$node->nid]['operations'] = array(
      '#value' => l('edit', 'admin/store/subscriptions/' . $node->nid . '/edit') . ' | ' . l('delete', 'node/' . $node->nid . '/delete', array(
        'query' => 'destination=admin/store/subscriptions',
      )),
    );
    $form['products'][$node->nid]['weight'] = array(
      '#type' => 'weight',
      '#delta' => 10,
      '#default_value' => $product->subscription->weight,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save order'),
  );
  return $form;
}