You are here

function uc_country_select in Ubercart 6.2

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

Creates a country select box for a form.

Parameters

$display: One of:

  • 'name': for the country name.
  • 'code2': for the 2-digit ISO code.
  • 'code3': for the 3-digit ISO code.
12 calls to uc_country_select()
uc_cart_pane_quotes in shipping/uc_quote/uc_quote.module
Cart pane callback.
uc_checkout_pane_billing in uc_cart/uc_cart_checkout_pane.inc
Gets the billing information.
uc_checkout_pane_delivery in uc_cart/uc_cart_checkout_pane.inc
Gets the delivery information.
uc_order_condition_billing_country_form in uc_order/uc_order.ca.inc
uc_order_condition_delivery_country_form in uc_order/uc_order.ca.inc

... See full list

File

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

Code

function uc_country_select($title, $default = NULL, $description = NULL, $display = 'name', $required = FALSE) {
  if ($display == 'code2') {
    $order_by = 'country_iso_code_2';
  }
  elseif ($display == 'code3') {
    $order_by = 'country_iso_code_3';
  }
  else {
    $order_by = 'country_name';
  }
  $result = db_query("SELECT * FROM {uc_countries} WHERE version > 0 ORDER BY %s", $order_by);
  $options = array();
  while ($country = db_fetch_array($result)) {
    $options[$country['country_id']] = $order_by == 'country_name' ? t($country[$order_by]) : $country[$order_by];
  }
  if (count($options) == 0) {
    $options[] = t('No countries found.');
  }
  natcasesort($options);
  $default = db_result(db_query("SELECT country_id FROM {uc_countries} WHERE country_id = %d AND version > 0", empty($default) ? 0 : intval($default)));
  $select = array(
    '#type' => 'select',
    '#title' => $title,
    '#description' => $description,
    '#options' => $options,
    '#default_value' => empty($default) ? uc_store_default_country() : $default,
    '#required' => $required,
  );
  drupal_add_js(drupal_get_path('module', 'uc_store') . '/uc_country_select.js');

  // Ensure the path setting only gets added once.
  static $added = FALSE;
  if (!$added) {
    drupal_add_js(array(
      'ucURL' => array(
        'zoneSelect' => url('uc_js_util/zone_select'),
      ),
    ), 'setting');
    $added = TRUE;
  }
  return $select;
}