You are here

function uc_get_country_data in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_store/uc_store.module \uc_get_country_data()
  2. 7.3 uc_store/uc_store.module \uc_get_country_data()

Returns the rows of countries whose data matches the fields specified in the $fields array.

18 calls to uc_get_country_data()
uc_2checkout_form in payment/uc_2checkout/uc_2checkout.module
uc_authorizenet_arb_create in payment/uc_authorizenet/uc_authorizenet.module
Sends an ARB Create request via the XML API.
uc_cybersource_calculate_tax in payment/uc_cybersource/uc_cybersource.module
Calculates taxes for an order using CyberSource's tax service.
uc_cybersource_charge in payment/uc_cybersource/uc_cybersource.module
uc_paypal_ec_checkout in payment/uc_paypal/uc_paypal.module

... See full list

File

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

Code

function uc_get_country_data($match = array(), $sort = 'country_name') {
  $valid_fields = array(
    'country_id',
    'country_name',
    'country_iso_code_2',
    'country_iso_code_3',
    'version',
  );
  if (!is_array($match)) {
    $match = array();
  }
  if (!in_array($sort, $valid_fields)) {
    $sort = 'country_name';
  }
  $query = 'SELECT * FROM {uc_countries}';
  if (count($match) > 0) {
    $where = '';
    foreach ($match as $key => $value) {
      if (!in_array($key, $valid_fields)) {
        continue;
      }
      if (strlen($where) == 0) {
        $where = ' WHERE ';
      }
      if (strlen($where) > 7) {
        $where .= ' AND ';
      }
      $where .= $key . " = '" . check_plain($value) . "'";
    }
  }
  $query .= $where . ' ORDER BY ' . check_plain($sort);
  $result = db_query($query);
  if (db_num_rows($result) == 0) {
    return FALSE;
  }
  while ($row = db_fetch_array($result)) {
    $countries[] = $row;
  }
  return $countries;
}