<?php

/**
 * Implements hook_install() using the name of the country as the base of
 * the function name.
 */
function denmark_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' => 208,
      'country_name' => 'Denmark',
      'country_iso_code_2' => 'DK',
      'country_iso_code_3' => 'DNK',
      'version' => 2,
    ))
    ->execute();

  // Make the entries in the zones table.
  $zones = array(
    array(208, 'DK-84', 'Hovedstaden'),
    array(208, 'DK-82', 'Midtjylland'),
    array(208, 'DK-81', 'Nordjylland'),
    array(208, 'DK-85', 'Sjælland'),
    array(208, 'DK-83', 'Syddanmark'),
  );

  $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(
    208,
    "!company\r\n".
    "!first_name !last_name\r\n".
    "!street1\r\n".
    "!street2\r\n".
    "!postal_code !city\r\n".
    "!country_name_if"
  );
}

/**
 * Implements hook_update() with $version being the only argument.
 * Add a new case for each version update, and be sure to always include the
 * latest changes in the install function.
 */
function denmark_update($version) {
  switch ($version) {
    case 2:
      $zones = array(
        array(208, 'DK-84', 'Hovedstaden'),
        array(208, 'DK-82', 'Midtjylland'),
        array(208, 'DK-81', 'Nordjylland'),
        array(208, 'DK-85', 'Sjælland'),
        array(208, 'DK-83', 'Syddanmark'),
      );

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