<?php

// Note: Ireland does not currently have postal codes but it has been announced
// that they will be implemented - so I left the postal code in the address
// definition.
// http://www.dcmnr.gov.ie/Press+Releases/Dempsey+announces+programme+to+introduce+postcodes+in+Ireland+by+1st+January+2008.htm
//

function ireland_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' => 372,
      'country_name' => 'Ireland',
      'country_iso_code_2' => 'IE',
      'country_iso_code_3' => 'IRL',
      'version' => 2,
    ))
    ->execute();

  // Make the entries in the zones table.
  $zones = array(
    array(372, 'CARLOW', 'Co. Carlow'),
    array(372, 'CAVAN', 'Co. Cavan'),
    array(372, 'CLARE', 'Co. Clare'),
    array(372, 'CORK', 'Co. Cork'),
    array(372, 'DONEGAL', 'Co. Donegal'),
    array(372, 'DUBLIN', 'Co. Dublin'),
    array(372, 'GALWAY', 'Co. Galway'),
    array(372, 'KERRY', 'Co. Kerry'),
    array(372, 'KILDARE', 'Co. Kildare'),
    array(372, 'KILKENNY', 'Co. Kilkenny'),
    array(372, 'LAOIS', 'Co. Laois'),
    array(372, 'LEITRIM', 'Co. Leitrim'),
    array(372, 'LIMERICK', 'Co. Limerick'),
    array(372, 'LONGFORD', 'Co. Longford'),
    array(372, 'LOUTH', 'Co. Louth'),
    array(372, 'MAYO', 'Co. Mayo'),
    array(372, 'MEATH', 'Co. Meath'),
    array(372, 'MONAGHAN', 'Co. Monaghan'),
    array(372, 'OFFALY', 'Co. Offaly'),
    array(372, 'ROSCOMMON', 'Co. Roscommon'),
    array(372, 'SLIGO', 'Co. Sligo'),
    array(372, 'TIPPERARY', 'Co. Tipperary'),
    array(372, 'WATERFORD', 'Co. Waterford'),
    array(372, 'WESTMEATH', 'Co. Westmeath'),
    array(372, 'WEXFORD', 'Co. Wexford'),
    array(372, 'WICKLOW', 'Co. Wicklow'),
  );

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

function ireland_update($version) {
  switch ($version) {
    case 2:
      uc_set_address_format(
        372,
        "!company\r\n".
        "!first_name !last_name\r\n".
        "!street1\r\n".
        "!street2\r\n".
        "!city, !zone_name !postal_code\r\n".
        "!country_name_if"
      );
      break;
  }
}
