<?php

/**
 * Implements hook_install().
 */
function singapore_install() {
  db_query("INSERT INTO {uc_countries} (country_id, country_name, country_iso_code_2, country_iso_code_3, version) VALUES (702, 'Singapore', 'SG', 'SGP', 2)");

  // Make the entries in the zones table.
  $zones = array(
    array(702, 'SG-01', 'Central Singapore'),
    array(702, 'SG-02', 'North East'),
    array(702, 'SG-03', 'North West'),
    array(702, 'SG-04', 'South East'),
    array(702, 'SG-05', 'South West'),
  );

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

/**
 * 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 singapore_update($version) {
  switch ($version) {
    case 2:
      $zones = array(
        array(702, 'SG-01', 'Central Singapore'),
        array(702, 'SG-02', 'North East'),
        array(702, 'SG-03', 'North West'),
        array(702, 'SG-04', 'South East'),
        array(702, 'SG-05', 'South West'),
      );

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