Project

General

Profile

Download (7.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * This is the expertsdb_address_spain module for use with expertsdb_address.
4
 *
5
 * <p>This module simply adds support for Spanish Provinces</p>
6
 *
7
 * @version $Id: expertsdb_address_spain.module,v 1.1 2007/12/04 21:18:09 rconstantine Exp $;
8
 * @package CCK
9
 * @category CCK
10
 * @author jonhattan
11
 * @filesource
12
 * @license http://www.gnu.org/licenses/gpl.txt GNU_GENERAL_PUBLIC_LICENSE
13
 * @link none yet
14
 */
15

    
16
/**
17
 * Implementation of hook_help
18
 *
19
 * Display help and module information
20
 * @param string section which section of the site we're displaying help
21
 * @return help text for section
22
 */
23
function expertsdb_address_spain_help($section='') {
24

    
25
  $output = '';
26

    
27
  switch ($section) {
28
    case "admin/help#expertsdb_address_spain":
29
      $output = '<p>'.  t("Adds support for Spanish Provinces to expertsdb_address."). '</p>';
30
      break;
31
  }
32

    
33
  return $output;
34
} // function expertsdb_address_spain_help()
35

    
36
/**
37
 * Adds all Mexican States to the states table. Adds Spain to the countries table. Returns whether all queries succeeded.
38
 *
39
 * @return boolean $query_ok
40
 */
41
function expertsdb_address_spain_installstates($query_ok = TRUE) {
42
  if (db_table_exists('expertsdb_address_states')) {
43
    $states = array (
44
      array("Álava", "ALA"),
45
      array("Albacete", "ALB"),
46
      array("Alicante", "ALI"),
47
      array("Almería", "ALM"),
48
      array("Asturias", "AST"),
49
      array("Ávila", "AVI"),
50
      array("Badajoz", "BAD"),
51
      array("Barcelona", "BAR"),
52
      array("Burgos", "BUR"),
53
      array("Cáceres", "CAC"),
54
      array("Cádiz", "CAD"),
55
      array("Cantabria", "CAN"),
56
      array("Castellón", "CAS"),
57
      array("Ciudad Real", "CIU"),
58
      array("Córdoba", "COR"),
59
      array("La Coruña", "LAC"),
60
      array("Cuenca", "CUE"),
61
      array("Gerona", "GER"),
62
      array("Granada", "GRA"),
63
      array("Guadalajara", "GUA"),
64
      array("Guipúzcoa", "GUI"),
65
      array("Huelva", "HUE"),
66
      array("Huesca", "HUS"),
67
      array("Islas Baleares", "ISB"),
68
      array("Jaén", "JAE"),
69
      array("León", "LEO"),
70
      array("Lérida", "LER"),
71
      array("Lugo", "LUG"),
72
      array("Madrid", "MAD"),
73
      array("Málaga", "MAL"),
74
      array("Región de Murcia", "REM"),
75
      array("Navarra", "NAV"),
76
      array("Orense", "ORE"),
77
      array("Palencia", "PAL"),
78
      array("Las Palmas", "LPA"),
79
      array("Pontevedra", "PON"),
80
      array("La Rioja", "LAR"),
81
      array("Salamanca", "SAL"),
82
      array("Santa Cruz de Tenerife", "TFE"),
83
      array("Segovia", "SEG"),
84
      array("Sevilla", "SEV"),
85
      array("Soria", "SOR"),
86
      array("Tarragona", "TAR"),
87
      array("Teruel", "TER"),
88
      array("Toledo", "TOL"),
89
      array("Valencia", "VAL"),
90
      array("Valladolid", "VLD"),
91
      array("Vizcaya", "VZY"),
92
      array("Zamora", "ZMR"),
93
      array("Zaragoza", "ZGZ"),
94
      );
95

    
96
      foreach ($states as $state){
97
        $query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('{$state[0]}', '{$state[1]}', 'ES')");
98
        if (!$query2) {$query_ok = FALSE;}
99
      }
100
  }
101
  if (db_table_exists('expertsdb_address_countries')) {
102
    $query2 = db_query("INSERT INTO {expertsdb_address_countries} (country_name, country_code) VALUES ('Spain', 'ES')");
103
    if (!$query2) {$query_ok = FALSE;}
104
  }
105
  return $query_ok;
106
} // function expertsdb_address_spain_installstates()
107

    
108
/**
109
 * Implementation of hook_validate_address_fields
110
 *
111
 * This hook is used by expertsdb_address and any supporting modules which add country-specific field validation.
112
 * The first argument is an array, passed in by reference in 'fieldname=>error string' pairs. The error string should remain empty
113
 * so long as there are no errors. If there is an error, the string should be replaced with an appropriate t-ified message. The
114
 * second argument is the country code of the address. The first thing an implementation of this hook should do is check to see if
115
 * the country code matches the country for which the module was made to support. If not, it should return immediately, without
116
 * modifying the $errors array. This will ensure that only the country which SHOULD validate, does the validation. The third argument
117
 * is the item containing the values of the form.
118
 *
119
 * NOTE TO SPANISH USERS: The original contributor of this add-on module commented out the validation routines below except for the
120
 * postal code one. I'm not sure why. I left it unchanged, but hope you'll comment on this module's issue queue if there are problems
121
 * and hopefully you'll come up with solutions that I can plug in if so.
122
 */
123
function expertsdb_address_spain_validate_address_fields(&$errors, $country_code, $item, $field_name) {
124
  if ($country_code != 'ES' && $country_code != 'Spain'){
125
    return;
126
  }
127
  $val_locale = array('es_ES' => 'es_ES');
128
  $default_locale = setlocale(LC_ALL, 0);
129

    
130
  foreach ($val_locale as $key => $value) {
131
    $current_locale = expertsdb_address_setLocaleCP($value);
132
    /*
133
    if (($item['street1'] != '') && (!preg_match("/^[,\.\'\-[:alpha:]0-9\/\s]+$/", _expertsdb_address_spain_remove_accents($item['street1'])))) {
134
      $errors['street1'] = t('(Spain):Illegal value for %name\'s Street field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name));
135
    }
136
    if (($item['street2'] != '') && (!preg_match("/^[,\.\'\-[:alpha:]0-9\/\s]+$/", _expertsdb_address_spain_remove_accents($item['street2'])))) {
137
      $errors['street2'] = t('(Spain):Illegal value for %name\'s Street Continued field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name));
138
    }
139
    if (($item['apt'] != '') && (!preg_match("/^[,\.\'\-[:alpha:]0-9\/\s]+$/", _expertsdb_address_spain_remove_accents($item['apt'])))) {
140
      $errors['apt'] = t('(Spain):Illegal value for %name\'s Apt/Suite Number field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name));
141
    }
142
    if (($item['city'] != '') && (!preg_match("/^[,\.\'\-[:alpha:]\s]+$/", _expertsdb_address_spain_remove_accents($item['city'])))) {
143
      $errors['city'] = t('(Spain):Illegal value for %name\'s City field. Only letters, \' and - are valid. No numbers or other special characters allowed.', array('%name' => $field_name));
144
    }
145
    */
146
    if (($item['zip'] != '') && (!preg_match("/^\s*[0-9]{5}\s*$/", $item['zip']))) {
147
      $errors['zip'] = t('(Spain):Illegal value for %name\'s ZIP field.', array('%name' => $field_name));
148
    }
149
    /*
150
    if (($item['other'] != '') && (!preg_match("/^[,\.\'\-[:alpha:]0-9\s]+$/", _expertsdb_address_spain_remove_accents($item['other'])))) {
151
      $errors['other'] = t('(Spain):Illegal value for %name\'s Other field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name));
152
    }
153
    */
154
  }
155
  setlocale(LC_ALL, $default_locale);
156
  return;
157
}
158

    
159
//*****************************************************************************
160
// Remove all accents from a string
161
function _expertsdb_address_spain_remove_accents($str){
162
  $str = utf8_decode($str);
163
  return preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/','$1',htmlentities($str,ENT_NOQUOTES));
164
}
(23-23/23)