You are here

function uc_country_select in Ubercart 5

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

Create a country select box for a form. $display can be 'name', 'code2' for the 2-digit code, or 'code3' for the 3-digit 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
Get the billing information.
uc_checkout_pane_delivery in uc_cart/uc_cart_checkout_pane.inc
Get the delivery information.
uc_order_condition_billing_country_form in uc_order/uc_order_workflow.inc
uc_order_condition_delivery_country_form in uc_order/uc_order_workflow.inc

... See full list

File

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

Code

function uc_country_select($title, $default = NULL, $description = NULL, $display = 'name', $required = FALSE) {
  if ($display == 'name') {
    $order_by = 'country_name';
  }
  elseif ($display == 'code2') {
    $order_by = 'country_iso_code_2';
  }
  elseif ($display == 'code3') {
    $order_by = 'country_iso_code_3';
  }
  $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']] = $country[$order_by];
  }
  if (count($options) == 0) {
    $options[] = t('No countries found.');
  }
  $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,
  );
  uc_add_js(drupal_get_path('module', 'uc_store') . '/uc_country_select.js');
  return $select;
}