<?php
// $Id: united_kingdom_826_2.cif,v 1.1.4.4 2010-11-02 06:42:17 tr Exp $

/**
 * First implement hook_install() using the name of the country as the base of
 * the function name.
 */
function united_kingdom_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} VALUES ('826', 'United Kingdom', 'GB', 'GBR', 2)");

  // Make the entries in the zones table.
  db_query("INSERT INTO {uc_zones} (zone_id, zone_country_id, zone_code, zone_name) VALUES "
          ."(%d, 826, 'ABN', 'Aberdeen'),"
          ."(%d, 826, 'ABNS', 'Aberdeenshire'),"
          ."(%d, 826, 'ANG', 'Anglesey'),"
          ."(%d, 826, 'AGS', 'Angus'),"
          ."(%d, 826, 'ARY', 'Argyll and Bute'),"
          ."(%d, 826, 'AVON', 'Avon'),"
          ."(%d, 826, 'BEDS', 'Bedfordshire'),"
          ."(%d, 826, 'BERKS', 'Berkshire'),"
          ."(%d, 826, 'BLA', 'Blaenau Gwent'),"
          ."(%d, 826, 'BRI', 'Bridgend'),"
          ."(%d, 826, 'BSTL', 'Bristol'),"
          ."(%d, 826, 'BUCKS', 'Buckinghamshire'),"
          ."(%d, 826, 'CAE', 'Caerphilly'),"
          ."(%d, 826, 'CAMBS', 'Cambridgeshire'),"
          ."(%d, 826, 'CDF', 'Cardiff'),"
          ."(%d, 826, 'CARM', 'Carmarthenshire'),"
          ."(%d, 826, 'CDGN', 'Ceredigion'),"
          ."(%d, 826, 'CHES', 'Cheshire'),"
          ."(%d, 826, 'CLACK', 'Clackmannanshire'),"
          ."(%d, 826, 'CLVD', 'Cleveland'),"
          ."(%d, 826, 'CON', 'Conwy'),"
          ."(%d, 826, 'CORN', 'Cornwall'),"
          ."(%d, 826, 'COAN', 'County Antrim'),"
          ."(%d, 826, 'COAR', 'County Armagh'),"
          ."(%d, 826, 'CODN', 'County Down'),"
          ."(%d, 826, 'COFE', 'County Fermanagh'),"
          ."(%d, 826, 'COLO', 'County Londonderry'),"
          ."(%d, 826, 'COTY', 'County Tyrone'),"
          ."(%d, 826, 'CMA', 'Cumbria'),"
          ."(%d, 826, 'DNBG', 'Denbighshire'),"
          ."(%d, 826, 'DERBY', 'Derbyshire'),"
          ."(%d, 826, 'DVN', 'Devon'),"
          ."(%d, 826, 'DOR', 'Dorset'),"
          ."(%d, 826, 'DGL', 'Dumfries and Galloway'),"
          ."(%d, 826, 'DUND', 'Dundee'),"
          ."(%d, 826, 'DHM', 'Durham'),"
          ."(%d, 826, 'ARYE', 'East Ayrshire'),"
          ."(%d, 826, 'DUNBE', 'East Dunbartonshire'),"
          ."(%d, 826, 'LOTE', 'East Lothian'),"
          ."(%d, 826, 'RENE', 'East Renfrewshire'),"
          ."(%d, 826, 'ERYS', 'East Riding of Yorkshire'),"
          ."(%d, 826, 'SXE', 'East Sussex'),"
          ."(%d, 826, 'EDIN', 'Edinburgh'),"
          ."(%d, 826, 'ESX', 'Essex'),"
          ."(%d, 826, 'FALK', 'Falkirk'),"
          ."(%d, 826, 'FFE', 'Fife'),"
          ."(%d, 826, 'FLINT', 'Flintshire'),"
          ."(%d, 826, 'GLAS', 'Glasgow'),"
          ."(%d, 826, 'GLOS', 'Gloucestershire'),"
          ."(%d, 826, 'MAN', 'Greater Manchester'),"
          ."(%d, 826, 'GDD', 'Gwynedd'),"
          ."(%d, 826, 'HANTS', 'Hampshire'),"
          ."(%d, 826, 'HWR', 'Herefordshire'),"
          ."(%d, 826, 'HERTS', 'Hertfordshire'),"
          ."(%d, 826, 'HLD', 'Highlands'),"
          ."(%d, 826, 'IVER', 'Inverclyde'),"
          ."(%d, 826, 'IOW', 'Isle of Wight'),"
          ."(%d, 826, 'IOS', 'Isles of Scilly'),"
          ."(%d, 826, 'KNT', 'Kent'),"
          ."(%d, 826, 'LANCS', 'Lancashire'),"
          ."(%d, 826, 'LEICS', 'Leicestershire'),"
          ."(%d, 826, 'LINCS', 'Lincolnshire'),"
          ."(%d, 826, 'LDN', 'London'),"
          ."(%d, 826, 'MSY', 'Merseyside'),"
          ."(%d, 826, 'MERT', 'Merthyr Tydfil'),"
          ."(%d, 826, 'MIDDX', 'Middlesex'),"
          ."(%d, 826, 'MLOT', 'Midlothian'),"
          ."(%d, 826, 'MMOUTH', 'Monmouthshire'),"
          ."(%d, 826, 'MORAY', 'Moray'),"
          ."(%d, 826, 'NPRTAL', 'Neath Port Talbot'),"
          ."(%d, 826, 'NEWPT', 'Newport'),"
          ."(%d, 826, 'NOR', 'Norfolk'),"
          ."(%d, 826, 'ARYN', 'North Ayrshire'),"
          ."(%d, 826, 'LANN', 'North Lanarkshire'),"
          ."(%d, 826, 'YSN', 'North Yorkshire'),"
          ."(%d, 826, 'NHM', 'Northamptonshire'),"
          ."(%d, 826, 'NLD', 'Northumberland'),"
          ."(%d, 826, 'NOT', 'Nottinghamshire'),"
          ."(%d, 826, 'ORK', 'Orkney Islands'),"
          ."(%d, 826, 'OFE', 'Oxfordshire'),"
          ."(%d, 826, 'PEM', 'Pembrokeshire'),"
          ."(%d, 826, 'PERTH', 'Perth and Kinross'),"
          ."(%d, 826, 'PWS', 'Powys'),"
          ."(%d, 826, 'REN', 'Renfrewshire'),"
          ."(%d, 826, 'RHON', 'Rhondda Cynon Taff'),"
          ."(%d, 826, 'RUT', 'Rutland'),"
          ."(%d, 826, 'BOR', 'Scottish Borders'),"
          ."(%d, 826, 'SHET', 'Shetland Islands'),"
          ."(%d, 826, 'SPE', 'Shropshire'),"
          ."(%d, 826, 'SOM', 'Somerset'),"
          ."(%d, 826, 'ARYS', 'South Ayrshire'),"
          ."(%d, 826, 'LANS', 'South Lanarkshire'),"
          ."(%d, 826, 'YSS', 'South Yorkshire'),"
          ."(%d, 826, 'SFD', 'Staffordshire'),"
          ."(%d, 826, 'STIR', 'Stirling'),"
          ."(%d, 826, 'SFK', 'Suffolk'),"
          ."(%d, 826, 'SRY', 'Surrey'),"
          ."(%d, 826, 'SWAN', 'Swansea'),"
          ."(%d, 826, 'TORF', 'Torfaen'),"
          ."(%d, 826, 'TWR', 'Tyne and Wear'),"
          ."(%d, 826, 'VGLAM', 'Vale of Glamorgan'),"
          ."(%d, 826, 'WARKS', 'Warwickshire'),"
          ."(%d, 826, 'WDUN', 'West Dunbartonshire'),"
          ."(%d, 826, 'WLOT', 'West Lothian'),"
          ."(%d, 826, 'WMD', 'West Midlands'),"
          ."(%d, 826, 'SXW', 'West Sussex'),"
          ."(%d, 826, 'YSW', 'West Yorkshire'),"
          ."(%d, 826, 'WIL', 'Western Isles'),"
          ."(%d, 826, 'WLT', 'Wiltshire'),"
          ."(%d, 826, 'WORCS', 'Worcestershire'),"
          ."(%d, 826, 'WRX', 'Wrexham')",
          uc_get_zone_ids(111)
        );

  // 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(826,
    "!first_name !last_name\r\n!company\r\n!street1\r\n!street2"
   ."\r\n!city\r\n!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 united_kingdom_update($version) {
  switch ($version) {
    case 2:
      db_query("INSERT INTO {uc_zones} (zone_id, zone_country_id, zone_code, zone_name) VALUES "
              ."(%d, 826, 'AVON', 'Avon'),"
              ."(%d, 826, 'COAN', 'County Antrim'),"
              ."(%d, 826, 'COAR', 'County Armagh'),"
              ."(%d, 826, 'CODN', 'County Down'),"
              ."(%d, 826, 'COFE', 'County Fermanagh'),"
              ."(%d, 826, 'COLO', 'County Londonderry'),"
              ."(%d, 826, 'COTY', 'County Tyrone'),"
              ."(%d, 826, 'CLVD', 'Cleveland'),"
              ."(%d, 826, 'IOS', 'Isles of Scilly'),"
              ."(%d, 826, 'MIDDX', 'Middlesex')", uc_get_zone_ids(10));

      db_query("UPDATE {uc_zones} SET zone_name = 'Greater Manchester' WHERE zone_country_id = 826 AND zone_name = 'Manchester'");

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