This module simply adds support for Belgian Provinces
* * @version $Id: cck_address_belgium.module,v 1.1 2007/08/16 01:33:16 rconstantine Exp $; * @package CCK * @category CCK * @author jpoesen@drupal.org * @filesource * @license http://www.gnu.org/licenses/gpl.txt GNU_GENERAL_PUBLIC_LICENSE * @link none yet */ /** * Implementation of hook_help * * Display help and module information * @param string section which section of the site we're displaying help * @return help text for section */ function cck_address_belgium_help($section='') { $output = ''; switch ($section) { case "admin/help#cck_address_belgium": $output = ''. t("Adds support for Belgian Provinces to cck_address."). '
'; break; } return $output; } // function cck_address_belgium_help() /** * Adds all Belgian Provinces to the states table. Adds Belgium to the countries table. Returns whether all queries succeeded. * * @return boolean $query_ok */ function cck_address_belgium_installstates($query_ok = TRUE) { if (db_table_exists('cck_address_states')) { $states = array(); $states[] = array("Antwerp", "AN", "BE"); $states[] = array("Limburg", "LI", "BE"); $states[] = array("Flemish Brabant", "VB", "BE"); $states[] = array("East Flanders", "OV", "BE"); $states[] = array("West Flanders", "WV", "BE"); $states[] = array("Hainaut", "AP", "HT"); $states[] = array("Walloon Brabant", "BW", "BE"); $states[] = array("Namur", "AP", "NA"); $states[] = array("Liège", "AP", "LG"); $states[] = array("Luxembourg", "LX", "BE"); $states[] = array("Brussels-Capital", "BR", "BE"); foreach($states as $state) { $query2 = db_query("INSERT INTO {cck_address_states} (state_name, state_abbrv, country_code) VALUES ('$state[0]', '$state[1]', '$state[2]')"); if (!$query2) {$query_ok = FALSE;} } } if (db_table_exists('cck_address_countries')) { $query2 = db_query("INSERT INTO {cck_address_countries} (country_name, country_code) VALUES ('Belgium', 'BE')"); if (!$query2) {$query_ok = FALSE;} } return $query_ok; } // function cck_address_belgium_installstates() /** * Implementation of hook_validate_address_fields * * This hook is used by cck_address and any supporting modules which add country-specific field validation. * The first argument is an array, passed in by reference in 'fieldname=>error string' pairs. The error string should remain empty * so long as there are no errors. If there is an error, the string should be replaced with an appropriate t-ified message. The * second argument is the country code of the address. The first thing an implementation of this hook should do is check to see if * the country code matches the country for which the module was made to support. If not, it should return immediately, without * modifying the $errors array. This will ensure that only the country which SHOULD validate, does the validation. The third argument * is the item containing the values of the form. */ function cck_address_belgium_validate_address_fields(&$errors, $country_code, $item, $field_name) { if ($country_code != 'BE' && $country_code != 'Belgium'){ return; } $val_locale = array('en_US' => 'en_US'); $locales = cck_address_get_all_locales(); $default_locale = setlocale(LC_ALL, 0); foreach ($val_locale as $key => $value) { $current_locale = cck_address_setLocaleCP($value); if (($item['street1'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9\/\s]+$/", $item['street1']))) { $errors['street1'] = t('(Belgium): Illegal value for %name\'s Street field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name)); } if (($item['street2'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9\/\s]+$/", $item['street2']))) { $errors['street2'] = t('(Belgium):Illegal value for %name\'s Street Continued field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name)); } if (($item['apt'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9\/]+$/", $item['apt']))) { $errors['apt'] = t('(Belgium):Illegal value for %name\'s Apt/Suite Number field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name)); } if (($item['city'] != '') && (!preg_match("/^[\.\'\-[:alpha:]\s]+$/", $item['city']))) { $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' => $field_name)); } if (($item['zip'] != '') && (!preg_match("/[0-9]{4}$/", $item['zip']))) { $errors['zip'] = t('(Belgium):Illegal value for %name\'s ZIP field.', array('%name' => $field_name)); } if (($item['other'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9\s]+$/", $item['other']))) { $errors['other'] = t('(Belgium):Illegal value for %name\'s Other field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' => $field_name)); } } setlocale(LC_ALL, $default_locale); return; }