<?php

/**
 * First implement hook_install() using the name of the country as the base of
 * the function name.
 */
function greenland_install() {
  // Make the entry in the country table.
  // VALUES = Country ID, Country Name, 2-digit Code, 3-digit Code, File Version
  db_query("INSERT INTO {uc_countries} (country_id, country_name, country_iso_code_2, country_iso_code_3, version) VALUES (304, 'Greenland', 'GL', 'GRL', 1)");

  // Make the entries in the zones table.  Use %d for the zone_id and the
  // function uc_get_zone_ids($num) as the second argument for db_query() where
  // $num is the number of zones in the INSERT query.
  // VALUES = %d for ID, Parent Country ID, Zone Abbreviation, Zone Name
  $zones = array(
    array(304, 'NK', 'Nuuk'),
    array(304, 'NQ', 'Nuussuaq'),
    array(304, 'KQ', 'Kangerlussuaq'),
    array(304, 'ST', 'Sisimiut'),
    array(304, 'MQ', 'Maniitsoq'),
    array(304, 'TQ', 'Tasiilaq'),
    array(304, 'KK', 'Kulusuk'),
    array(304, 'AP', 'Alluitsup Paa'),
    array(304, 'QQ', 'Qaqortoq'),
    array(304, 'NA', 'Narsaq'),
    array(304, 'NK', 'Nanortalik'),
    array(304, 'NR', 'Narsarsuaq'),
    array(304, 'IQ', 'Ikerasassuaq'),
    array(304, 'KT', 'Kangilinnguit'),
    array(304, 'AK', 'Arsuk'),
    array(304, 'PT', 'Paamiut'),
    array(304, 'AT', 'Aasiaat'),
    array(304, 'QT', 'Qasigiannguit'),
    array(304, 'IL', 'Ilulissat'),
    array(304, 'QE', 'Qeqertarsuaq'),
    array(304, 'KA', 'Kangaatsiaq'),
    array(304, 'UM', 'Uummannaq'),
    array(304, 'UP', 'Upernavik'),
    array(304, 'QA', 'Qaarsut'),
    array(304, 'PT', 'Pituffik'),
    array(304, 'QN', 'Qaanaaq'),
    array(304, 'SN', 'Station Nord'),
    array(304, 'IT', 'Ittoqqortoormiit'),
    array(304, 'MV', 'Mestersvig'),
    array(304, 'DH', 'Danmarkshavn'),
    array(304, 'CP', 'Constable Pynt'),
    array(304, 'SS', 'Slædepatruljen Sirius'),
  );

  foreach ($zones as $zone) {
    db_query("INSERT INTO {uc_zones} (zone_country_id, zone_code, zone_name) VALUES (%d, '%s', '%s')", $zone);
  }

  // Use uc_set_address_format() with the country ID as the first argument and
  // an address format string as the second.  Documentation on address formats
  // is available at:
  // http://www.ubercart.org/ubercart_users_guide/country_settings#address_format_docs
  uc_set_address_format(304,
    "!company\r\n!first_name !last_name\r\n!street1\r\n!street2\r\n!postal_code !city\r\n!country_name_if");
}
