Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / 5.x / modules / expertsdb / expertsdb_cck / countries / expertsdb_address_belgium.module @ 36311992

History | View | Annotate | Download (6.06 KB)

1
<?php
2
/**
3
 * This is the expertsdb_address_belgium module for use with expertsdb_address.
4
 *
5
 * <p>This module simply adds support for Belgian Provinces</p>
6
 *
7
 * @version $Id: expertsdb_address_belgium.module,v 1.1 2007/08/16 01:33:16 rconstantine Exp $;
8
 * @package CCK
9
 * @category CCK
10
 * @author jpoesen@drupal.org
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_belgium_help($section='') {
24

    
25
  $output = '';
26

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

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

    
36
/**
37
 * Adds all Belgian Provinces to the states table. Adds Belgium to the countries table. Returns whether all queries succeeded.
38
 *
39
 * @return boolean $query_ok
40
 */
41
function expertsdb_address_belgium_installstates($query_ok = TRUE) {
42
  if (db_table_exists('expertsdb_address_states')) {
43
    $query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Antwerpen', 'AP', 'BE')");
44
    if (!$query2) {$query_ok = FALSE;}
45
    $query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Limburg', 'LI', 'BE')");
46
    if (!$query2) {$query_ok = FALSE;}
47
    $query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Vlaams-Brabant/Brussel', 'VB', 'BE')");
48
    if (!$query2) {$query_ok = FALSE;}
49
    $query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Waals-Brabant', 'WB', 'BE')");
50
    if (!$query2) {$query_ok = FALSE;}
51
    $query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Oost-Vlaanderen', 'OV', 'BE')");
52
    if (!$query2) {$query_ok = FALSE;}
53
    $query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('West-Vlaanderen', 'WV', 'BE')");
54
    if (!$query2) {$query_ok = FALSE;}
55
    $query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Luik', 'LK', 'BE')");
56
    if (!$query2) {$query_ok = FALSE;}
57
    $query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Luxemburg', 'LU', 'BE')");
58
    if (!$query2) {$query_ok = FALSE;}
59
    $query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Namen', 'NA', 'BE')");
60
    if (!$query2) {$query_ok = FALSE;}
61
  }
62
  if (db_table_exists('expertsdb_address_countries')) {
63
    $query2 = db_query("INSERT INTO {expertsdb_address_countries} (country_name, country_code) VALUES ('Belgium', 'BE')");
64
    if (!$query2) {$query_ok = FALSE;}
65
  }
66
  return $query_ok;
67
} // function expertsdb_address_belgium_installstates()
68

    
69
/**
70
 * Implementation of hook_validate_address_fields
71
 *
72
 * This hook is used by expertsdb_address and any supporting modules which add country-specific field validation.
73
 * The first argument is an array, passed in by reference in 'fieldname=>error string' pairs. The error string should remain empty
74
 * so long as there are no errors. If there is an error, the string should be replaced with an appropriate t-ified message. The
75
 * second argument is the country code of the address. The first thing an implementation of this hook should do is check to see if
76
 * the country code matches the country for which the module was made to support. If not, it should return immediately, without
77
 * modifying the $errors array. This will ensure that only the country which SHOULD validate, does the validation. The third argument
78
 * is the item containing the values of the form.
79
 */
80
function expertsdb_address_belgium_validate_address_fields(&$errors, $country_code, $item, $field_name) {
81
  if ($country_code != 'BE' && $country_code != 'Belgium'){
82
    return;
83
  }
84
  $val_locale = array('en_US' => 'en_US');
85
  $locales = expertsdb_address_get_all_locales();
86
  $default_locale = setlocale(LC_ALL, 0);
87

    
88
  foreach ($val_locale as $key => $value) {
89
    $current_locale = expertsdb_address_setLocaleCP($value);
90
    if (($item['street1'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9\/\s]+$/", $item['street1']))) {
91
      $errors['street1'] = t('(Belgium): Illegal value for %name\'s Street field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' =>
92
$field_name));
93
    }
94
    if (($item['street2'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9\/\s]+$/", $item['street2']))) {
95
      $errors['street2'] = t('(Belgium):Illegal value for %name\'s Street Continued field. Only letters, numbers, \' and - are valid. No other special characters allowed.',
96
array('%name' => $field_name));
97
    }
98
    if (($item['apt'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9\/]+$/", $item['apt']))) {
99
      $errors['apt'] = t('(Belgium):Illegal value for %name\'s Apt/Suite Number field. Only letters, numbers, \' and - are valid. No other special characters allowed.',
100
array('%name' => $field_name));
101
    }
102
    if (($item['city'] != '') && (!preg_match("/^[\.\'\-[:alpha:]\s]+$/", $item['city']))) {
103
      $errors['city'] = t('(Belgium):Illegal value for %name\'s City field. Only letters, \' and - are valid. No numbers or other special characters allowed.', array('%name' =>
104
$field_name));
105
    }
106
    if (($item['zip'] != '') && (!preg_match("/[0-9]{4}$/", $item['zip']))) {
107
      $errors['zip'] = t('(Belgium):Illegal value for %name\'s ZIP field.', array('%name' => $field_name));
108
    }
109
    if (($item['other'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9\s]+$/", $item['other']))) {
110
      $errors['other'] = t('(Belgium):Illegal value for %name\'s Other field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' =>
111
$field_name));
112
    }
113
  }
114
  setlocale(LC_ALL, $default_locale);
115
  return;
116
}
Add picture from clipboard (Maximum size: 40 MB)