<?php

/**
 * Implements hook_install() using the name of the country as the base of
 * the function name.
 */
function sri_lanka_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' => 144,
      'country_name' => 'Sri Lanka',
      'country_iso_code_2' => 'LK',
      'country_iso_code_3' => 'LKA',
      'version' => 1,
    ))
    ->execute();

  // Make the entries in the zones table.
  $zones = array(
    array(144, '1', 'Basnahira Palata'),
    array(144, '2', 'Central Province'),
    array(144, '3', 'Dakunu Palata'),
    array(144, '5', 'Eastern Province'),
    array(144, '2', 'Madhyama Palata'),
    array(144, '5', 'Negenahira Palata'),
    array(144, '7', 'North Central Province'),
    array(144, '6', 'North Western Province'),
    array(144, '4', 'Northern Province'),
    array(144, '9', 'Sabaragamuwa Palata'),
    array(144, '3', 'Southern Province'),
    array(144, '4', 'Uturu Palata'),
    array(144, '7', 'Uturumeda Palata'),
    array(144, '8', 'Uva Palata'),
    array(144, '6', 'Wayamba Palata'),
    array(144, '1', 'Western Province'),
    array(144, '11', 'Colombo'),
    array(144, '12', 'Gampaha'),
    array(144, '13', 'Kalutara'),
    array(144, '21', 'Kandy'),
    array(144, '22', 'Matale'),
    array(144, '23', 'Nuwara Eliya'),
    array(144, '31', 'Galle'),
    array(144, '33', 'Hambantota'),
    array(144, '32', 'Matara'),
    array(144, '41', 'Jaffna'),
    array(144, '42', 'Kilinochchi'),
    array(144, '43', 'Mannar'),
    array(144, '45', 'Mullaittivu'),
    array(144, '44', 'Vavuniya'),
    array(144, '52', 'Ampara'),
    array(144, '51', 'Batticaloa'),
    array(144, '53', 'Trincomalee'),
    array(144, '61', 'Kurunegala'),
    array(144, '62', 'Puttalam'),
    array(144, '71', 'Anuradhapura'),
    array(144, '72', 'Polonnaruwa'),
    array(144, '81', 'Badulla'),
    array(144, '82', 'Monaragala'),
    array(144, '92', 'Kegalla'),
    array(144, '91', 'Ratnapura'),
  );

  $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(
    144,
    "!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"
  );
}
