Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
ce064e4f | 19 | * This class generates form components for Address Section. |
6a488035 TO |
20 | */ |
21 | class CRM_Admin_Form_Preferences_Address extends CRM_Admin_Form_Preferences { | |
6a488035 | 22 | |
c7cd4e2c | 23 | protected $_settings = [ |
24 | 'address_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
25 | 'address_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
26 | 'mailing_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
27 | 'hideCountryMailingLabels' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
28 | 'address_standardization_provider' => CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME, | |
29 | 'address_standardization_userid' => CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME, | |
30 | 'address_standardization_url' => CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME, | |
31 | ]; | |
6a488035 TO |
32 | |
33 | /** | |
eceb18cc | 34 | * Build the form object. |
6a488035 TO |
35 | */ |
36 | public function buildQuickForm() { | |
37 | $this->applyFilter('__ALL__', 'trim'); | |
38 | ||
be2fb01f | 39 | $this->addFormRule(['CRM_Admin_Form_Preferences_Address', 'formRule']); |
6a488035 TO |
40 | |
41 | //get the tokens for Mailing Label field | |
42 | $tokens = CRM_Core_SelectValues::contactTokens(); | |
ac0a3db5 | 43 | $this->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens)); |
6a488035 TO |
44 | |
45 | parent::buildQuickForm(); | |
46 | } | |
47 | ||
e0ef6999 EM |
48 | /** |
49 | * @param $fields | |
50 | * | |
51 | * @return bool | |
52 | */ | |
00be9182 | 53 | public static function formRule($fields) { |
6a488035 TO |
54 | $p = $fields['address_standardization_provider']; |
55 | $u = $fields['address_standardization_userid']; | |
56 | $w = $fields['address_standardization_url']; | |
57 | ||
58 | // make sure that there is a value for all of them | |
59 | // if any of them are set | |
60 | if ($p || $u || $w) { | |
6a488035 TO |
61 | |
62 | if (!($p && $u && $w)) { | |
c7cd4e2c | 63 | $errors['_qf_default'] = ts('You must provide values for all three Address Standardization fields.'); |
6a488035 TO |
64 | return $errors; |
65 | } | |
66 | } | |
67 | ||
68 | return TRUE; | |
69 | } | |
70 | ||
71 | /** | |
eceb18cc | 72 | * Process the form submission. |
6a488035 TO |
73 | */ |
74 | public function postProcess() { | |
75 | if ($this->_action == CRM_Core_Action::VIEW) { | |
76 | return; | |
77 | } | |
78 | ||
79 | $this->_params = $this->controller->exportValues($this->_name); | |
b96fee81 | 80 | $addressOptions = CRM_Core_OptionGroup::values('address_options', TRUE); |
6a488035 | 81 | |
6a488035 | 82 | // check if county option has been set |
f3acfdd9 | 83 | if (!empty($this->_params['address_options'][$addressOptions['County']])) { |
b96fee81 MM |
84 | $countyCount = CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_county"); |
85 | if ($countyCount < 10) { | |
be2fb01f | 86 | CRM_Core_Session::setStatus(ts('You have enabled the County option. Please ensure you populate the county table in your CiviCRM Database. You can find extensions to populate counties in the <a %1>CiviCRM Extensions Directory</a>.', [1 => 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', ['reset' => 1], TRUE, 'extensions-addnew') . '"']), |
b96fee81 MM |
87 | ts('Populate counties'), |
88 | "info" | |
89 | ); | |
6a488035 TO |
90 | } |
91 | } | |
92 | ||
b96fee81 | 93 | // check that locale supports address parsing |
2bc9bf1f | 94 | if ( |
b99f3e96 | 95 | !empty($this->_params['address_options'][$addressOptions['Street Address Parsing']]) && |
b96fee81 MM |
96 | !CRM_Core_BAO_Address::isSupportedParsingLocale() |
97 | ) { | |
98 | $config = CRM_Core_Config::singleton(); | |
99 | $locale = $config->lcMessages; | |
100 | CRM_Core_Session::setStatus(ts('Default locale (%1) does not support street parsing. en_US locale will be used instead.', [1 => $locale]), ts('Unsupported Locale'), 'alert'); | |
6a488035 TO |
101 | } |
102 | ||
103 | $this->postProcessCommon(); | |
104 | } | |
96025800 | 105 | |
6a488035 | 106 | } |