<?php

/**
* Implements hook_install() using the name of the country as the base of
* the function name.
*/
function china_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' => 156,
      'country_name' => 'China',
      'country_iso_code_2' => 'CN',
      'country_iso_code_3' => 'CHN',
      'version' => 1,
    ))
    ->execute();

  // Make the entries in the zones table.  Use %d for the zone_id and the
  // function uc_get_zone_ids($num) as the second argument for db_query() where
  // $num is the number of zones in the INSERT query.
  // VALUES = %d for ID, Parent Country ID, Zone Abbreviation, Zone Name
  $zones = array(
    array(156, '京', '北京'),
    array(156, '沪', '上海'),
    array(156, '津', '天津'),
    array(156, '渝', '重庆'),
    array(156, '冀', '河北'),
    array(156, '豫', '河南'),
    array(156, '鄂', '湖北'),
    array(156, '湘', '湖南'),
    array(156, '苏', '江苏'),
    array(156, '赣', '江西'),
    array(156, '辽', '辽宁'),
    array(156, '吉', '吉林'),
    array(156, '黑', '黑龙江'),
    array(156, '陕', '陕西'),
    array(156, '鲁', '山东'),
    array(156, '晋', '山西'),
    array(156, '川', '四川'),
    array(156, '青', '青海'),
    array(156, '皖', '安徽'),
    array(156, '琼', '海南'),
    array(156, '粤', '广东'),
    array(156, '桂', '广西'),
    array(156, '贵', '贵州'),
    array(156, '浙', '浙江'),
    array(156, '闽', '福建'),
    array(156, '甘', '甘肃'),
    array(156, '云', '云南'),
    array(156, '蒙', '内蒙古'),
    array(156, '宁', '宁夏'),
    array(156, '新', '新疆'),
    array(156, '藏', '西藏'),
    array(156, '港', '香港'),
    array(156, '澳', '澳门'),
    array(156, '台', '台湾'),
  );

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