<?php

function korea_democratic_peoples_republic_of_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 ('408', 'Korea, Democratic People\'s Republic of', 'KP', 'PRK', 2)");

  // Make the entries in the zones table.
  $zones = array(
    array(408, 'KP-01', 'P’yŏngyang'),
    array(408, 'KP-13', 'Nasŏn (Najin-Sŏnbong'),
    array(408, 'KP-02', 'P’yŏngan-namdo'),
    array(408, 'KP-03', 'P’yŏngan-bukto'),
    array(408, 'KP-04', 'Chagang-do'),
    array(408, 'KP-05', 'Hwanghae-namdo'),
    array(408, 'KP-06', 'Hwanghae-bukto'),
    array(408, 'KP-07', 'Kangwŏn-do'),
    array(408, 'KP-08', 'Hamgyŏng-namdo'),
    array(408, 'KP-09', 'Hamgyŏng-bukto'),
    array(408, 'KP-10', 'Yanggang-do'),
  );

  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(408,
    "!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");

}

function korea_democratic_peoples_republic_of_update($version) {
  switch ($version) {
    case 2:
      // Correct ISO-3166-1 country name
      db_query("UPDATE {uc_countries} SET country_name = 'Korea, Democratic People\'s Republic of' WHERE country_id = 408");
      break;
  }
}
