You are here

function uc_get_country_data in Ubercart 6.2

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

Returns country data based on the supplied criteria.

Parameters

$match: An associative array of fields to match.

$sort: The field to sort by.

16 calls to uc_get_country_data()
uc_2checkout_form in payment/uc_2checkout/uc_2checkout.module
Form to build the submission to 2Checkout.com.
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_cybersource_hop_form in payment/uc_cybersource/uc_cybersource.module
Define values to be posted to CyberSource.

... See full list

File

uc_store/uc_store.module, line 1153
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);
  while ($row = db_fetch_array($result)) {
    $countries[] = $row;
  }
  return empty($countries) ? FALSE : $countries;
}