<?php

function jamaica_install() {
  db_query("INSERT INTO {uc_countries} (country_id, country_name, country_iso_code_2, country_iso_code_3, version) VALUES ('388', 'Jamaica', 'JM', 'JAM', 2)");

  // Make the entries in the zones table.
  $zones = array(
    array(388, 'JM-13', 'Clarendon'),
    array(388, 'JM-09', 'Hanover'),
    array(388, 'JM-01', 'Kingston'),
    array(388, 'JM-12', 'Manchester'),
    array(388, 'JM-04', 'Portland'),
    array(388, 'JM-02', 'Saint Andrew'),
    array(388, 'JM-06', 'Saint Ann'),
    array(388, 'JM-14', 'Saint Catherine'),
    array(388, 'JM-11', 'Saint Elizabeth'),
    array(388, 'JM-08', 'Saint James'),
    array(388, 'JM-05', 'Saint Mary'),
    array(388, 'JM-03', 'Saint Thomas'),
    array(388, 'JM-07', 'Trelawny'),
    array(388, 'JM-10', 'Westmoreland'),
  );

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

/**
 * If necessary, implement 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 jamaica_update($version) {
  switch ($version) {
    case 2:
      $zones = array(
        array(388, 'JM-13', 'Clarendon'),
        array(388, 'JM-09', 'Hanover'),
        array(388, 'JM-01', 'Kingston'),
        array(388, 'JM-12', 'Manchester'),
        array(388, 'JM-04', 'Portland'),
        array(388, 'JM-02', 'Saint Andrew'),
        array(388, 'JM-06', 'Saint Ann'),
        array(388, 'JM-14', 'Saint Catherine'),
        array(388, 'JM-11', 'Saint Elizabeth'),
        array(388, 'JM-08', 'Saint James'),
        array(388, 'JM-05', 'Saint Mary'),
        array(388, 'JM-03', 'Saint Thomas'),
        array(388, 'JM-07', 'Trelawny'),
        array(388, 'JM-10', 'Westmoreland'),
      );

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