<?php

function chad_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' => 148,
      'country_name' => 'Chad',
      'country_iso_code_2' => 'TD',
      'country_iso_code_3' => 'TCD',
      'version' => 1,
    ))
    ->execute();

  // Make the entries in the zones table.
  $zones = array(
    array(148, 'KA', 'Barh el Ghazel'),
    array(148, 'BA', 'Batha'),
    array(148, 'BET', 'Borkou'),
    array(148, 'CB', 'Chari-Baguirmi'),
    array(148, 'BET', 'Ennedi'),
    array(148, 'GR', 'Guera'),
    array(148, 'HL', 'Hadjer-Lamis'),
    array(148, 'KA', 'Kanem'),
    array(148, 'LC', 'Lac'),
    array(148, 'LO', 'Logone Occidental'),
    array(148, 'LR', 'Logone Oriental'),
    array(148, 'MA', 'Mandoul'),
    array(148, 'ME', 'Mayo-Kebbi Est'),
    array(148, 'MO', 'Mayo-Kebbi Ouest'),
    array(148, 'MC', 'Moyen-Chari'),
    array(148, 'OD', 'Ouaddai'),
    array(148, 'SA', 'Salamat'),
    array(148, 'OD', 'Sila'),
    array(148, 'TA', 'Tandjile'),
    array(148, 'BET', 'Tibesti'),
    array(148, 'ND', "Ville de N'Djamena"),
    array(148, 'WF', 'Wadi Fira'),
  );

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