Project

General

Profile

Download (3.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
//$Id: expertsdb_address_mexico.install,v 1.5 2007/10/11 15:57:56 ricflomag Exp $;
3
/**
4
 * Implementation of hook_install().
5
 *
6
 * For country codes, use http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
7
 * If you are adding states or provinces for other countries, just duplicate the .inc, .install, and . module set for Mexico.
8
 * We should be able to grab what we need by Country Code. *
9
 */
10
function expertsdb_address_mexico_install() {
11
  if (expertsdb_address_mexico_installstates()) {
12
    drupal_set_message('The expertsdb_address_Mexico module was installed successfully. The database was updated.');
13
  }
14
  else {
15
    drupal_set_message('There was an error installing expertsdb_address_Mexico.', 'error');
16
  }
17
}
18

    
19
/**
20
 * Implementation of hook_uninstall().
21
 */
22
function expertsdb_address_mexico_uninstall() {
23
  if (db_table_exists('expertsdb_address_states'))
24
    $query1 = db_query("DELETE FROM {expertsdb_address_states} WHERE country_code = '%s'", 'MX');
25
  else $query1 = TRUE;
26
  if (db_table_exists('expertsdb_address_countries'))
27
    $query2 = db_query("DELETE FROM {expertsdb_address_countries} WHERE country_code = '%s'", 'MX');
28
  else $query2 = TRUE;
29

    
30
  if ($query1 && $query2) {
31
    drupal_set_message('The expertsdb_address_Mexico module was uninstalled successfully.');
32
  }
33
  else {
34
    drupal_set_message('There was an error removing the expertsdb_address_Mexico database rows.', 'error');
35
  }
36
}
37

    
38
/**
39
 * Adds all Mexican States to the states table. Adds Mexico to the countries table. Returns whether all queries succeeded.
40
 *
41
 * @return boolean $query_ok
42
 */
43
function expertsdb_address_mexico_installstates() {
44
  if (!db_table_exists('expertsdb_address_states') or !db_table_exists('expertsdb_address_countries')) return FALSE;
45
  $states = array (
46
    array("Aguascalientes","AGS"),
47
    array("Baja California Norte","BC"),
48
    array("Baja California Sur","BCS"),
49
    array("Campeche","CAMP"),
50
    array("Chiapas","CHIS"),
51
    array("Chihuahua","CHIH"),
52
    array("Coahuila","COAH"),
53
    array("Colima","COL"),
54
    array("Distrito Federal","DF"),
55
    array("Durango","DGO"),
56
    array("Edo. de México","MEX"),
57
    array("Guanajuato","GTO"),
58
    array("Guerrero","GRO"),
59
    array("Hidalgo","HGO"),
60
    array("Jalisco","JAL"),
61
    array("Michoacán","MICH"),
62
    array("Morelos","MOL"),
63
    array("Nayarit","NAY"),
64
    array("Nuevo León","NL"),
65
    array("Oaxaca","OAX"),
66
    array("Puebla","PUE"),
67
    array("Querétaro","QRO"),
68
    array("Quintana Roo","QROO"),
69
    array("San Luis Potosí","SLP"),
70
    array("Sinaloa","SIN"),
71
    array("Sonora","SON"),
72
    array("Tabasco","TAB"),
73
    array("Tamaulipas","TAMPS"),
74
    array("Tlaxcala","TLAX"),
75
    array("Veracruz","VER"),
76
    array("Yucatán","YUC"),
77
    array("Zacatecas","ZAC"),
78
    );
79

    
80
  foreach ($states as $state) {
81
    if(!db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('{$state[0]}', '{$state[1]}', 'MX')")) return FALSE;
82
  }
83

    
84
  return db_query("INSERT INTO {expertsdb_address_countries} (country_name, country_code) VALUES ('Mexico', 'MX')");
85
} // function expertsdb_address_mexico_installstates()
(19-19/23)