You are here

function uc_order_usearch in Ubercart 5

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

Display a search form to browse all received orders.

1 string reference to 'uc_order_usearch'
uc_order_menu in uc_order/uc_order.module
Implementation of hook_menu().

File

uc_order/uc_order.module, line 1297

Code

function uc_order_usearch() {
  $output = drupal_get_form('uc_order_search_form');
  if (arg(4) == 'results') {
    $output .= '<p>' . t('Search returned the following results:') . '</p>';
    $billing_first_name = strtolower(str_replace('*', '%', check_plain(arg(5))));
    $billing_last_name = strtolower(str_replace('*', '%', check_plain(arg(6))));
    $billing_company = strtolower(str_replace('*', '%', check_plain(arg(7))));
    $shipping_first_name = strtolower(str_replace('*', '%', check_plain(arg(8))));
    $shipping_last_name = strtolower(str_replace('*', '%', check_plain(arg(9))));
    $shipping_company = strtolower(str_replace('*', '%', check_plain(arg(10))));
    $start_date = check_plain(arg(11));
    $end_date = check_plain(arg(12));
    $args = array();
    if ($billing_first_name !== '0' && $billing_first_name !== '%') {
      $where .= " AND LOWER(o.billing_first_name) LIKE '%s'";
      $args[] = $billing_first_name;
    }
    if ($billing_last_name !== '0' && $billing_last_name !== '%') {
      $where .= " AND LOWER(o.billing_last_name) LIKE '%s'";
      $args[] = $billing_last_name;
    }
    if ($billing_company !== '0' && $billing_company !== '%') {
      $where .= " AND LOWER(o.billing_company) LIKE '%s'";
      $args[] = $billing_company;
    }
    if ($shipping_first_name !== '0' && $shipping_first_name !== '%') {
      $where .= " AND LOWER(o.delivery_first_name) LIKE '%s'";
      $args[] = $shipping_first_name;
    }
    if ($shipping_last_name !== '0' && $shipping_last_name !== '%') {
      $where .= " AND LOWER(o.delivery_last_name) LIKE '%s'";
      $args[] = $shipping_last_name;
    }
    if ($shipping_company !== '0' && $shipping_company !== '%') {
      $where .= " AND LOWER(o.delivery_company) LIKE '%s'";
      $args[] = $shipping_company;
    }
    if ($start_date !== '0') {
      $where .= " AND o.created >= %d";
      $args[] = $start_date;
    }
    if ($end_date !== '0') {
      $where .= " AND o.created <= %d";
      $args[] = $end_date;
    }
    $sql = 'SELECT o.order_id, 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 o.order_status NOT IN ' . uc_order_status_list('specific', TRUE) . $where . ' ORDER BY o.created DESC';
    $output .= uc_order_admin($sql, $args, TRUE);
  }
  return $output;
}