<?php

/**
 * Implements 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_insert('uc_countries')
    ->fields(array(
      'country_id' => 304,
      'country_name' => 'Greenland',
      'country_iso_code_2' => 'GL',
      'country_iso_code_3' => 'GRL',
      'version' => 1,
    ))
    ->execute();

  // 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'),
  );

  $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
  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"
  );
}
