<?php

function united_states_install() {
  // Make the entry in the country table.
  // VALUES = Country ID, Country Name, 2-digit Code, 3-digit Code, File Version
  db_insert('uc_countries')
    ->fields(array(
      'country_id' => 840,
      'country_name' => 'United States',
      'country_iso_code_2' => 'US',
      'country_iso_code_3' => 'USA',
      'version' => 1,
    ))
    ->execute();

  // Make the entries in the zones table.
  $zones = array(
    array(840, 'AL', 'Alabama'),
    array(840, 'AK', 'Alaska'),
    array(840, 'AS', 'American Samoa'),
    array(840, 'AZ', 'Arizona'),
    array(840, 'AR', 'Arkansas'),
    array(840, 'AF', 'Armed Forces Africa'),
    array(840, 'AA', 'Armed Forces Americas'),
    array(840, 'AC', 'Armed Forces Canada'),
    array(840, 'AE', 'Armed Forces Europe'),
    array(840, 'AM', 'Armed Forces Middle East'),
    array(840, 'AP', 'Armed Forces Pacific'),
    array(840, 'CA', 'California'),
    array(840, 'CO', 'Colorado'),
    array(840, 'CT', 'Connecticut'),
    array(840, 'DE', 'Delaware'),
    array(840, 'DC', 'District of Columbia'),
    array(840, 'FM', 'Federated States Of Micronesia'),
    array(840, 'FL', 'Florida'),
    array(840, 'GA', 'Georgia'),
    array(840, 'GU', 'Guam'),
    array(840, 'HI', 'Hawaii'),
    array(840, 'ID', 'Idaho'),
    array(840, 'IL', 'Illinois'),
    array(840, 'IN', 'Indiana'),
    array(840, 'IA', 'Iowa'),
    array(840, 'KS', 'Kansas'),
    array(840, 'KY', 'Kentucky'),
    array(840, 'LA', 'Louisiana'),
    array(840, 'ME', 'Maine'),
    array(840, 'MH', 'Marshall Islands'),
    array(840, 'MD', 'Maryland'),
    array(840, 'MA', 'Massachusetts'),
    array(840, 'MI', 'Michigan'),
    array(840, 'MN', 'Minnesota'),
    array(840, 'MS', 'Mississippi'),
    array(840, 'MO', 'Missouri'),
    array(840, 'MT', 'Montana'),
    array(840, 'NE', 'Nebraska'),
    array(840, 'NV', 'Nevada'),
    array(840, 'NH', 'New Hampshire'),
    array(840, 'NJ', 'New Jersey'),
    array(840, 'NM', 'New Mexico'),
    array(840, 'NY', 'New York'),
    array(840, 'NC', 'North Carolina'),
    array(840, 'ND', 'North Dakota'),
    array(840, 'MP', 'Northern Mariana Islands'),
    array(840, 'OH', 'Ohio'),
    array(840, 'OK', 'Oklahoma'),
    array(840, 'OR', 'Oregon'),
    array(840, 'PW', 'Palau'),
    array(840, 'PA', 'Pennsylvania'),
    array(840, 'PR', 'Puerto Rico'),
    array(840, 'RI', 'Rhode Island'),
    array(840, 'SC', 'South Carolina'),
    array(840, 'SD', 'South Dakota'),
    array(840, 'TN', 'Tennessee'),
    array(840, 'TX', 'Texas'),
    array(840, 'UT', 'Utah'),
    array(840, 'VT', 'Vermont'),
    array(840, 'VI', 'Virgin Islands'),
    array(840, 'VA', 'Virginia'),
    array(840, 'WA', 'Washington'),
    array(840, 'WV', 'West Virginia'),
    array(840, 'WI', 'Wisconsin'),
    array(840, 'WY', 'Wyoming'),
  );

  $query = db_insert('uc_zones')->fields(array('zone_country_id', 'zone_code', 'zone_name'));
  foreach ($zones as $zone) {
    $query->values($zone);
  }
  $query->execute();

  // Set address format
  // Have to call variable_set() instead of uc_set_address_format()
  // because the Canada .cif file is loaded during the installation
  // of the uc_store module, before uc_set_address_format() is available
  // to use.
  variable_set(
    'uc_address_format_840',
    "!company\r\n".
    "!first_name !last_name\r\n".
    "!street1\r\n".
    "!street2\r\n".
    "!city, !zone_code !postal_code\r\n".
    "!country_name_if"
  );
}
