<?php

function new_zealand_install() {
  db_query("INSERT INTO {uc_countries} (country_id, country_name, country_iso_code_2, country_iso_code_3, version) VALUES (554, 'New Zealand', 'NZ', 'NZL', 3)");

  // Make the entries in the zones table.
  $zones = array(
    array(554, 'AUK', 'Auckland'),
    array(554, 'BOP', 'Bay of Plenty'),
    array(554, 'CAN', 'Canterbury'),
    array(554, 'COR', 'Coromandel'),
    array(554, 'GIS', 'Gisborne'),
    array(554, 'FIO', 'Fiordland'),
    array(554, 'HKB', "Hawke's Bay"),
    array(554, 'MBH', 'Marlborough'),
    array(554, 'MWT', 'Manawatu-Wanganui'),
    array(554, 'MCM', 'Mt Cook-Mackenzie'),
    array(554, 'NSN', 'Nelson'),
    array(554, 'NTL', 'Northland'),
    array(554, 'OTA', 'Otago'),
    array(554, 'STL', 'Southland'),
    array(554, 'TKI', 'Taranaki'),
    array(554, 'WGN', 'Wellington'),
    array(554, 'WKO', 'Waikato'),
    array(554, 'WAI', 'Wairarapa'),
    array(554, 'WTC', 'West Coast'),
  );

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

  uc_set_address_format(554, "!first_name !last_name\r\n!company\r\n!street1\r\n!street2"
                            ."\r\n!city !postal_code\r\n!country_name_if");
}

function new_zealand_update($version) {
  switch ($version) {
    case 2:
      $zones = array(
        array(554, 'AUK', 'Auckland'),
        array(554, 'BOP', 'Bay of Plenty'),
        array(554, 'CAN', 'Canterbury'),
        array(554, 'COR', 'Coromandel'),
        array(554, 'GIS', 'Gisborne'),
        array(554, 'FIO', 'Fiordland'),
        array(554, 'HKB', "Hawke's Bay"),
        array(554, 'MBH', 'Marlborough'),
        array(554, 'MWT', 'Manawatu-Wanganui'),
        array(554, 'MCM', 'Mt Cook-Mackenzie'),
        array(554, 'NSN', 'Nelson'),
        array(554, 'NTL', 'Northland'),
        array(554, 'OTA', 'Otago'),
        array(554, 'STL', 'Southland'),
        array(554, 'TKI', 'Taranaki'),
        array(554, 'WGN', 'Wellington'),
        array(554, 'WKO', 'Waikato'),
        array(554, 'WAI', 'Wairarapa'),
        array(554, 'WTC', 'West Coast'),
      );

      foreach ($zones as $zone) {
        db_query("INSERT INTO {uc_zones} (zone_country_id, zone_code, zone_name) VALUES (%d, '%s', '%s')", $zone);
      }
      break;
    case 3:
      db_query("UPDATE {uc_zones} SET zone_name = 'Wairarapa' WHERE zone_name = 'Wairprarapa'");
      break;
  }
}
