Project

General

Profile

Download (9.87 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * This is the expertsdb_address_germany module for use with expertsdb_address.
4
 *
5
 * <p>This module simply adds support for German Provinces</p>
6
 *
7
 * @version $Id: expertsdb_address_germany.info,v 1.1 2008/05/02 14:24:56 suit4 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_germany_help($section='') {
24

    
25
	$output = '';
26

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

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

    
36
/**
37
 * Adds all German Provinces to the states table. Adds Germany to the countries table. Returns whether all queries succeeded.
38
 *
39
 * @return boolean $query_ok
40
 */
41
function expertsdb_address_germany_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 ('Baden-Württemberg', 'BW', 'DE')");
44
		if (!$query2) {$query_ok = FALSE;}
45
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Bayern', 'BY', 'DE')");
46
		if (!$query2) {$query_ok = FALSE;}
47
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Berlin', 'BE', 'DE')");
48
		if (!$query2) {$query_ok = FALSE;}
49
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Brandenburg', 'BR', 'DE')");
50
		if (!$query2) {$query_ok = FALSE;}
51
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Bremen', 'HB', 'DE')");
52
		if (!$query2) {$query_ok = FALSE;}
53
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Hamburg', 'HH', 'DE')");
54
		if (!$query2) {$query_ok = FALSE;}
55
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Hessen', 'HE', 'DE')");
56
		if (!$query2) {$query_ok = FALSE;}
57
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Mecklenburg-Vorpommern', 'MV', 'DE')");
58
		if (!$query2) {$query_ok = FALSE;}
59
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Niedersachsen', 'NI', 'DE')");
60
		if (!$query2) {$query_ok = FALSE;}
61
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Nordrhein-Westfalen', 'NW', 'DE')");
62
		if (!$query2) {$query_ok = FALSE;}
63
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Rheinland-Pfalz', 'RP', 'DE')");
64
		if (!$query2) {$query_ok = FALSE;}
65
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Saarland', 'SL', 'DE')");
66
		if (!$query2) {$query_ok = FALSE;}
67
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Sachsen', 'SN', 'DE')");
68
		if (!$query2) {$query_ok = FALSE;}
69
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Sachsen-Anhalt', 'ST', 'DE')");
70
		if (!$query2) {$query_ok = FALSE;}
71
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Schleswig-Holstein', 'SH', 'DE')");
72
		if (!$query2) {$query_ok = FALSE;}
73
		$query2 = db_query("INSERT INTO {expertsdb_address_states} (state_name, state_abbrv, country_code) VALUES ('Thüringen', 'TH', 'DE')");
74
		if (!$query2) {$query_ok = FALSE;}
75
	}
76
	if (db_table_exists('expertsdb_address_countries')) {
77
		$query2 = db_query("INSERT INTO {expertsdb_address_countries} (country_name, country_code) VALUES ('Germany', 'DE')");
78
		if (!$query2) {$query_ok = FALSE;}
79
	}
80
	return $query_ok;
81
} // function expertsdb_address_germany_installstates()
82

    
83
/**
84
 * Implementation of hook_validate_address_fields
85
 *
86
 * This hook is used by expertsdb_address and any supporting modules which add country-specific field validation.
87
 * The first argument is an array, passed in by reference in 'fieldname=>error string' pairs. The error string should remain empty
88
 * so long as there are no errors. If there is an error, the string should be replaced with an appropriate t-ified message. The
89
 * second argument is the country code of the address. The first thing an implementation of this hook should do is check to see if
90
 * the country code matches the country for which the module was made to support. If not, it should return immediately, without
91
 * modifying the $errors array. This will ensure that only the country which SHOULD validate, does the validation. The third argument
92
 * is the item containing the values of the form.
93
 */
94
function expertsdb_address_germany_validate_address_fields(&$errors, $country_code, $item, $field_name) {
95
	if ($country_code != 'DE' && $country_code != 'Germany'){
96
		return;
97
	}
98
	$val_locale = array('de_DE' => 'de_DE');
99
	$locales = expertsdb_address_get_all_locales();
100
	$default_locale = setlocale(LC_ALL, 0);
101

    
102
	foreach ($val_locale as $key => $value) {
103
		$current_locale = expertsdb_address_setLocaleCP($value);
104
		if (($item['street1'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9ßäöüÄÖÜ\/\s]+$/", $item['street1']))) {
105
			$errors['street1'] = t('(Germany): Illegal value for %name\'s Street field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' =>
106
			$field_name));
107
		}
108
		if (($item['street2'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9ßäöüÄÖÜ\/\s]+$/", $item['street2']))) {
109
			$errors['street2'] = t('(Germany):Illegal value for %name\'s Street Continued field. Only letters, numbers, \' and - are valid. No other special characters allowed.',
110
			array('%name' => $field_name));
111
		}
112
		if (($item['city'] != '') && (!preg_match("/^[\.\'\-[:alpha:]ßäöüÄÖÜ\/\s]+$/", $item['city']))) {
113
			$errors['city'] = t('(Germany):Illegal value for %name\'s City field. Only letters, \' and - are valid. No numbers or other special characters allowed.', array('%name' =>
114
			$field_name));
115
		}
116
		if (($item['zip'] != '') && (!preg_match("/[0-9]{5}$/", $item['zip']))) {
117
			$errors['zip'] = t('(Germany):Illegal value for %name\'s ZIP field.', array('%name' => $field_name));
118
		}
119
		if (($item['other'] != '') && (!preg_match("/^[\.\'\-[:alpha:]0-9ßäöüÄÖÜ\/\s]+$/", $item['other']))) {
120
			$errors['other'] = t('(Germany):Illegal value for %name\'s Other field. Only letters, numbers, \' and - are valid. No other special characters allowed.', array('%name' =>
121
			$field_name));
122
		}
123
	}
124
	setlocale(LC_ALL, $default_locale);
125
	return;
126
}
127

    
128

    
129
/**
130
 * Theme for address display as called from expertsdb_address_field_formatter().
131
 */
132
function theme_expertsdb_address_germany($expertsdb_address, $field) {
133
	//create the output
134
	if ($expertsdb_address['afd'] == 1) {
135
		$output = $expertsdb_address['street1']. ' ';
136
		$output .= $expertsdb_address['street2']. '<br />';
137
		$output .= $expertsdb_address['city']. ', ';
138
		$output .= $expertsdb_address['state']. ' ';
139
		$output .= $expertsdb_address['state_alternate']. ' ';
140
		$output .= $expertsdb_address['zip'];
141
		$output .= '<br />';
142
	}
143
	else {
144
		$output = '';
145
		asort($field['field_order']);
146
		foreach ($field['field_order'] as $field2 => $order) {
147
			switch ($field2) {//TODO create more elaborate output based on $order; not I'm only now using it for display of other, assuming it will either be first or last
148
				case 'street1':
149
					if ($field['fielddisplay']['field_display_street1'] === 'field_display_street1' && isset($expertsdb_address['street1']) && $expertsdb_address['street1'] != '') {
150
						$output .= $expertsdb_address['street1'] .' ';
151
					}
152
					break;
153
				case 'street2':
154
					if ($field['fielddisplay']['field_display_street2'] === 'field_display_street2' && isset($expertsdb_address['street2']) && $expertsdb_address['street2'] != '') {
155
						$output .= '<br />' . $expertsdb_address['street2'];
156
					}
157
					break;
158
				case 'apt':
159
					if ($field['fielddisplay']['field_display_apt'] === 'field_display_apt' && isset($expertsdb_address['apt']) && $expertsdb_address['apt'] != '') {
160
						$output .= '#'. $expertsdb_address['apt'];
161
					}
162
					break;
163
				case 'zip':
164
					if ($field['fielddisplay']['field_display_zip'] === 'field_display_zip' && isset($expertsdb_address['zip']) && $expertsdb_address['zip'] != '') {
165
						$output .= '<br />' . $expertsdb_address['zip'] . ' ';
166
					}
167
					break;
168
				case 'city':
169
					if ($field['fielddisplay']['field_display_city'] === 'field_display_city' && isset($expertsdb_address['city']) && $expertsdb_address['city'] != '') {
170
						$output .= $expertsdb_address['city'] . '<br />';
171
					}
172
					break;
173
				case 'state':
174
					if ($field['fielddisplay']['field_display_state'] === 'field_display_state' && isset($expertsdb_address['state']) && $expertsdb_address['state'] != '') {
175
						$output .= ', ' . $expertsdb_address['state'] .' ';
176
					}
177
					break;
178
				case 'country':
179
					if ($field['fielddisplay']['field_display_country'] === 'field_display_country' && isset($expertsdb_address['country']) && $expertsdb_address['country'] != '') {
180
						$output .= ' '. $expertsdb_address['country'];
181
					}
182
					break;
183
				case 'other':
184
					if ($field['fielddisplay']['field_display_other'] !== 0 && isset($expertsdb_address['other']) && $expertsdb_address['other'] != '') {
185
						if ($order > 1) {
186
							$output .= '<br />'. $expertsdb_address['other'] .'<br />';
187
						}
188
						else {
189
							$output .= $expertsdb_address['other'] .'<br />';
190
						}
191
					}
192
					break;
193
			}
194
		}
195
	}
196
	return $output;
197
} // function theme_expertsdb_address()
(14-14/23)