You are here

function uc_store_customer_search in Ubercart 5

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

Display the customer search page.

1 string reference to 'uc_store_customer_search'
uc_store_menu in uc_store/uc_store.module
Implementation of hook_menu().

File

uc_store/uc_store.module, line 794
Contains global Ubercart functions and store administration functionality.

Code

function uc_store_customer_search() {
  $output = drupal_get_form('uc_store_customer_search_form');
  if (arg(4) == 'results') {
    $first_name = strtolower(str_replace('*', '%', check_plain(arg(5))));
    $last_name = strtolower(str_replace('*', '%', check_plain(arg(6))));
    $email = strtolower(str_replace('*', '%', check_plain(arg(7))));
    if ($first_name !== '0' && $first_name !== '%') {
      $where .= " AND LOWER(o.billing_first_name) LIKE '" . $first_name . "'";
    }
    if ($last_name !== '0' && $last_name !== '%') {
      $where .= " AND LOWER(o.billing_last_name) LIKE '" . $last_name . "'";
    }
    if ($email !== '0' && $email !== '%') {
      $where .= " AND LOWER(o.primary_email) LIKE '" . $email . "'";
    }
    $query = "SELECT DISTINCT o.uid, u.mail, o.billing_first_name," . "o.billing_last_name, o.billing_city, o.billing_zone, " . "o.billing_country FROM {uc_orders} AS o LEFT JOIN " . "{users} AS u ON o.uid = u.uid WHERE o.uid > 0 AND " . "o.order_status IN " . uc_order_status_list('general', TRUE) . $where;

    // ." ORDER BY o.billing_last_name ASC";
    $count_query = '';
    switch ($GLOBALS['db_type']) {
      case 'mysql':
      case 'mysqli':
        $count_query = "SELECT COUNT(DISTINCT o.uid, o.billing_first_name, " . "o.billing_last_name, u.mail) FROM {uc_orders} AS o " . "LEFT JOIN {users} AS u ON o.uid = u.uid WHERE o.uid > 0 AND " . "o.order_status IN " . uc_order_status_list('general', TRUE) . $where;

        // ." ORDER BY o.billing_last_name ASC";
        break;
      case 'pgsql':
        $count_query = "SELECT DISTINCT o.uid, o.billing_first_name, " . "o.billing_last_name, u.mail, COUNT(*) " . "FROM {uc_orders} AS o " . "LEFT JOIN {users} AS u ON o.uid = u.uid WHERE o.uid > 0 AND " . "o.order_status IN " . uc_order_status_list('general', TRUE) . $where . "GROUP BY o.uid, o.billing_first_name, o.billing_last_name, u.mail ";

        //."ORDER BY o.billing_last_name ASC";
        break;
    }
    $message = t('Search returned the following results:');
    $output .= uc_store_customers($message, $query, $count_query, 100);
  }
  return $output;
}