You are here

function uc_country_formats_form in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_store/uc_store.module \uc_country_formats_form()
  2. 6.2 uc_store/uc_store.admin.inc \uc_country_formats_form()

Form builder to set country address formats.

See also

uc_country_formats_form_submit()

1 string reference to 'uc_country_formats_form'
uc_store_menu in uc_store/uc_store.module
Implements hook_menu().

File

uc_store/uc_store.countries.inc, line 117
Store administration forms for country and address handling.

Code

function uc_country_formats_form($form, &$form_state) {
  $form['instructions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Address format variables'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $header = array(
    t('Variable'),
    t('Description'),
  );
  $rows = array(
    array(
      '!first_name',
      t("Customer's first name"),
    ),
    array(
      '!last_name',
      t("Customer's last name"),
    ),
    array(
      '!company',
      t('Company name'),
    ),
    array(
      '!street1',
      t('First street address field'),
    ),
    array(
      '!street2',
      t('Second street address field'),
    ),
    array(
      '!city',
      t('City name'),
    ),
    array(
      '!zone_name',
      t('Full name of the zone'),
    ),
    array(
      '!zone_code',
      t('Abbreviation of the zone'),
    ),
    array(
      '!postal_code',
      t('Postal code'),
    ),
    array(
      '!country_name',
      t('Name of the country'),
    ),
    array(
      '!country_code2',
      t('2 digit country abbreviation'),
    ),
    array(
      '!country_code3',
      t('3 digit country abbreviation'),
    ),
  );
  $form['instructions']['text'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#prefix' => '<div><p>' . t('The following variables should be used in configuring addresses for the countries you ship to:') . '</p>',
    '#suffix' => '<p>' . t('Adding _if to any country variable will make it display only for addresses whose country is different than the default store country.') . '</p></div>',
  );
  $countries = array();
  $result = db_query("SELECT * FROM {uc_countries}");
  foreach ($result as $country) {
    $countries[t($country->country_name)] = $country;
  }
  uksort($countries, 'strnatcasecmp');
  if (is_array($countries)) {
    $form['countries'] = array(
      '#type' => 'vertical_tabs',
      '#tree' => TRUE,
    );
    foreach ($countries as $country) {
      $form['countries']['country'][$country->country_id] = array(
        '#type' => 'fieldset',
        '#title' => check_plain(t($country->country_name)),
        '#group' => 'country',
      );
      $form['countries']['country'][$country->country_id]['address_format'] = array(
        '#type' => 'textarea',
        '#title' => t('@country address format', array(
          '@country' => t($country->country_name),
        )),
        '#default_value' => variable_get('uc_address_format_' . $country->country_id, ''),
        '#description' => t('Use the variables mentioned in the instructions to format an address for this country.'),
        '#rows' => 7,
      );
    }
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit changes'),
  );
  return $form;
}