<?php

/**
 * Implements hook_install() using the name of the country as the base of
 * the function name.
 */
function singapore_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' => 702,
      'country_name' => 'Singapore',
      'country_iso_code_2' => 'SG',
      'country_iso_code_3' => 'SGP',
      'version' => 2,
    ))
    ->execute();

  // 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'),
  );

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

/**
 * Implements 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'),
      );

      $query = db_insert('uc_zones')->fields(array('zone_country_id', 'zone_code', 'zone_name'));
      foreach ($zones as $zone) {
        $query->values($zone);
      }
      $query->execute();
      break;
  }
}
