Project

General

Profile

Download (4.35 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * This is the expertsdb_address_mexico module for use with expertsdb_address.
4
 *
5
 * <p>This module simply adds support for Mexican States</p>
6
 *
7
 * @version $Id: expertsdb_address_mexico.module,v 1.3 2007/10/10 17:52:06 ricflomag Exp $;
8
 * @package CCK
9
 * @category CCK
10
 * @author ricflomag
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_mexico_help($section='') {
24

    
25
  $output = '';
26

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

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

    
36

    
37

    
38
/**
39
 * Implementation of hook_validate_address_fields
40
 *
41
 * This hook is used by expertsdb_address and any supporting modules which add country-specific field validation.
42
 * The first argument is an array, passed in by reference in 'fieldname=>error string' pairs. The error string should remain empty
43
 * so long as there are no errors. If there is an error, the string should be replaced with an appropriate t-ified message. The
44
 * second argument is the country code of the address. The first thing an implementation of this hook should do is check to see if
45
 * the country code matches the country for which the module was made to support. If not, it should return immediately, without
46
 * modifying the $errors array. This will ensure that only the country which SHOULD validate, does the validation. The third argument
47
 * is the item containing the values of the form.
48
 */
49
function expertsdb_address_mexico_validate_address_fields(&$errors, $country_code, $item, $field_name) {
50
  if ($country_code != 'MX' && $country_code != 'Mexico'){
51
    return;
52
  }
53
  $val_locale = array('es_MX' => 'es_MX');
54
  $default_locale = setlocale(LC_ALL, 0);
55

    
56
  foreach ($val_locale as $key => $value) {
57
    $current_locale = expertsdb_address_setLocaleCP($value);
58
    if (($item['street1'] != '') && (!preg_match("/^[,\.\'\-[:alpha:]0-9\/\s]+$/", _expertsdb_address_mexico_remove_accents($item['street1'])))) {
59
      $errors['street1'] = t('(Mexico): Illegal value for %name\'s Street field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name));
60
    }
61
    if (($item['street2'] != '') && (!preg_match("/^[,\.\'\-[:alpha:]0-9\/\s]+$/", _expertsdb_address_mexico_remove_accents($item['street2'])))) {
62
      $errors['street2'] = t('(Mexico):Illegal value for %name\'s Street Continued field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name));
63
    }
64
    if (($item['apt'] != '') && (!preg_match("/^[,\.\'\-[:alpha:]0-9\/\s]+$/", _expertsdb_address_mexico_remove_accents($item['apt'])))) {
65
      $errors['apt'] = t('(Mexico):Illegal value for %name\'s Apt/Suite Number field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name));
66
    }
67
    if (($item['city'] != '') && (!preg_match("/^[,\.\'\-[:alpha:]\s]+$/", _expertsdb_address_mexico_remove_accents($item['city'])))) {
68
      $errors['city'] = t('(Mexico):Illegal value for %name\'s City field. Only letters, \' and - are valid. No numbers or other special characters allowed.', array('%name' => $field_name));
69
    }
70
    if (($item['zip'] != '') && (!preg_match("/^\s*[0-9]{5}\s*$/", $item['zip']))) {
71
      $errors['zip'] = t('(Mexico):Illegal value for %name\'s ZIP field.', array('%name' => $field_name));
72
    }
73
    if (($item['other'] != '') && (!preg_match("/^[,\.\'\-[:alpha:]0-9\s]+$/", _expertsdb_address_mexico_remove_accents($item['other'])))) {
74
      $errors['other'] = t('(Mexico):Illegal value for %name\'s Other field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name));
75
    }
76
  }
77
  setlocale(LC_ALL, $default_locale);
78
  return;
79
}
80

    
81
//*****************************************************************************
82
// Remove all accents from a string
83
function _expertsdb_address_mexico_remove_accents($str){
84
  $str = utf8_decode($str);
85
  return preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/','$1',htmlentities($str,ENT_NOQUOTES));
86
}
(20-20/23)