You are here

function uc_product_administration in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_product/uc_product.admin.inc \uc_product_administration()

List the subcategories of product administration.

1 string reference to 'uc_product_administration'
uc_product_menu in uc_product/uc_product.module
Implementation of hook_menu().

File

uc_product/uc_product.module, line 1705
The product module for Ubercart.

Code

function uc_product_administration() {
  uc_add_js(drupal_get_path('module', 'uc_product') . '/uc_product.js', 'module');

  // Parse the URL for nodes in the list.
  $nids = array();
  foreach (func_get_args() as $nid) {
    if (intval($nid) > 0) {
      $nids[] = intval($nid);
    }
  }

  // Load all the vocabularies assigned to any product node type.
  $options = array();
  $types = module_invoke_all('product_types');
  $result = db_query("SELECT v.vid, v.name FROM {vocabulary} AS v LEFT JOIN {vocabulary_node_types} AS vnt ON v.vid = vnt.vid WHERE vnt.type IN ('" . implode("','", $types) . "')");
  while ($vocab = db_fetch_array($result)) {
    $options[$vocab['vid']] = $vocab['name'];
  }

  // Set the default vid, defaulting to the catalog if it's enabled.
  $default_vid = variable_get('uc_catalog_vid', 0);

  // If at least one vocabularies were found, display a uBrowser selector.
  if (count($options) > 0) {
    if (!in_array($default_vid, array_keys($options))) {
      $default_vid = array_shift(array_keys($options));
    }
    $output = '<div>' . t('Use the uBrowser to select as many products as you like and move them to the product container. When you are finished adding products, click the List button to reload the page showing the selected products. This effect is not cumulative and will not add products onto an existing list.') . '</div>';

    // Set the product filter for the uBrowser.
    $product_filter = implode(',', $types);

    // If more than one vocabularies were found, display a select box.
    if (count($options) > 1) {
      $form['vocabs'] = array(
        '#type' => 'select',
        '#id' => 'ubrowser-vocab-select',
        '#title' => t('Display vocabulary'),
        '#default_value' => $default_vid,
        '#options' => $options,
        '#attributes' => array(
          'onchange' => 'switch_vocabulary(this.value);',
        ),
      );
      $form['product_filter'] = array(
        '#type' => 'hidden',
        '#value' => $product_filter,
      );
      drupal_prepare_form('vocab-switcher', $form);
      $output .= drupal_render($form);
    }
    $settings = array(
      'div' => '#products-selector',
      'class' => 'product-ubrowser',
      'vid' => $default_vid,
      'filter' => $product_filter,
      'search' => 'true',
      'nids' => 'true',
      'nodesg' => t('product'),
      'nodepl' => t('products'),
      'multi' => 'true',
      'select' => 'buffer_products("' . file_create_url('') . '")',
    );
    $output .= ubrowser($settings, 'products-selector') . drupal_get_form('uc_product_buffer_form', $nids);
  }

  // If no nodes have been selected, display products 50 per page.
  if (!count($nids)) {
    $header = tapir_get_header('uc_product_table', array());
    $order = substr(tablesort_sql($header), 10);
    if (empty($order)) {
      $order = 'p.ordering, n.title';
    }
    $nids = array();
    $result = pager_query("SELECT n.nid FROM {node} AS n INNER JOIN {uc_products} AS p ON n.vid = p.vid ORDER BY " . $order, 50, 0, NULL);
    while ($product = db_fetch_object($result)) {
      $nids[] = $product->nid;
    }
  }

  // Setup the arguments to pass to the table builder function.
  $args = array(
    'nids' => $nids,
    'attributes' => array(
      'class' => 'product-list',
    ),
  );

  // Display the product table and pager if necessary.
  $output .= tapir_get_table('uc_product_table', $args) . theme('pager');
  return $output;
}