You are here

function uc_order_admin in Ubercart 5

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

Display the main order admin screen, an overview of all received orders.

1 call to uc_order_admin()
uc_order_usearch in uc_order/uc_order.module
Display a search form to browse all received orders.
1 string reference to 'uc_order_admin'
uc_order_menu in uc_order/uc_order.module
Implementation of hook_menu().

File

uc_order/uc_order.module, line 1064

Code

function uc_order_admin($sql = NULL, $args = NULL, $search = FALSE) {
  $header = array(
    array(
      'data' => t('Actions'),
    ),
    array(
      'data' => t('Order ID'),
      'field' => 'o.order_id',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Customer'),
    ),
    array(
      'data' => t('Total'),
      'align' => 'center',
      'field' => 'o.order_total',
    ),
    array(
      'data' => t('Purchase date'),
      'align' => 'center',
      'field' => 'o.created',
    ),
    array(
      'data' => t('Status'),
      'field' => 'os.title',
    ),
  );
  if (is_null($sql)) {
    $args = array();
    $show_status = 1;
    if (arg(3) == 'sort' && !is_null(arg(4))) {
      $_SESSION['sort_status'] = arg(4);
      $where = "WHERE o.order_status = '%s'";
      $args[] = arg(4);
    }
    else {
      if (isset($_SESSION['sort_status']) && !is_null($_SESSION['sort_status'])) {
        $where = "WHERE o.order_status = '%s'";
        $args[] = $_SESSION['sort_status'];
      }
      else {
        $where = 'WHERE o.order_status IN ' . uc_order_status_list('general', TRUE);
      }
    }
    if ($_SESSION['sort_status'] == 'all') {
      $where = '';
    }
    $sql = 'SELECT o.order_id, o.uid, o.billing_first_name, o.billing_last_name, o.order_total, ' . 'o.order_status, o.created, os.title FROM {uc_orders} o LEFT JOIN {uc_order_statuses} os ' . 'ON o.order_status = os.order_status_id ' . $where . tablesort_sql($header);
  }
  $address = variable_get('uc_customer_list_address', 'billing');
  if ($address == 'shipping') {
    $sql = str_replace('billing', 'delivery', $sql);
  }
  else {
    $address = 'billing';
  }
  $result = pager_query($sql, variable_get('uc_order_number_displayed', 30), 0, NULL, $args);
  while ($order = db_fetch_object($result)) {
    if ($address == 'shipping') {
      $order_name = $order->delivery_first_name . ' ' . $order->delivery_last_name;
    }
    else {
      $order_name = $order->billing_first_name . ' ' . $order->billing_last_name;
    }
    if (trim($order_name) == '') {
      if ($order->uid !== 0) {
        $account = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $order->uid));
      }
      if (empty($account)) {
        $order_name = t('User: none');
      }
      else {
        $order_name = t('User: !name', array(
          '!name' => $account,
        ));
      }
    }
    $rows[] = array(
      'data' => array(
        array(
          'data' => uc_order_actions($order, TRUE),
          'nowrap' => 'nowrap',
        ),
        array(
          'data' => $order->order_id,
        ),
        array(
          'data' => check_plain($order_name),
          'nowrap' => 'nowrap',
        ),
        array(
          'data' => uc_currency_format($order->order_total, TRUE),
          'align' => 'right',
          'nowrap' => 'true',
        ),
        array(
          'data' => format_date($order->created, 'custom', variable_get('uc_date_format_default', 'm/d/Y')),
          'align' => 'center',
        ),
        array(
          'data' => $order->title,
        ),
      ),
      'id' => 'order-' . $order->order_id,
    );
  }
  uc_add_js(drupal_get_path('module', 'uc_order') . '/uc_order.js');
  if ($search === FALSE) {
    $output = '<div class="order-overview-form">' . drupal_get_form('uc_order_select_form') . '</div>' . '<div class="order-overview-form">' . drupal_get_form('uc_order_admin_sort_form') . '</div>';
  }
  $output .= theme('table', $header, $rows, array(
    'class' => 'uc-orders-table',
  ));
  $output .= theme('pager', NULL, variable_get('uc_order_number_displayed', 30), 0);
  return $output;
}