3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * This class generates form components for Address Section.
37 class CRM_Admin_Form_Preferences_Address
extends CRM_Admin_Form_Preferences
{
38 public function preProcess() {
40 CRM_Utils_System
::setTitle(ts('Settings - Addresses'));
42 // Address Standardization
43 $addrProviders = array(
45 ) + CRM_Core_SelectValues
::addressProvider();
47 $this->_varNames
= array(
48 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=> array(
49 'address_options' => array(
50 'html_type' => 'checkboxes',
51 'title' => ts('Address Fields'),
54 'address_format' => array(
55 'html_type' => 'textarea',
56 'title' => ts('Display Format'),
57 'description' => NULL,
60 'mailing_format' => array(
61 'html_type' => 'textarea',
62 'title' => ts('Mailing Label Format'),
63 'description' => NULL,
66 'hideCountryMailingLabels' => array(
67 'html_type' => 'YesNo',
68 'title' => ts('Hide Country in Mailing Labels when same as domain country'),
72 CRM_Core_BAO_Setting
::ADDRESS_STANDARDIZATION_PREFERENCES_NAME
=> array(
73 'address_standardization_provider' => array(
74 'html_type' => 'select',
75 'title' => ts('Provider'),
76 'option_values' => $addrProviders,
79 'address_standardization_userid' => array(
80 'html_type' => 'text',
81 'title' => ts('User ID'),
82 'description' => NULL,
85 'address_standardization_url' => array(
86 'html_type' => 'text',
87 'title' => ts('Web Service URL'),
88 'description' => NULL,
100 public function setDefaultValues() {
102 $defaults['address_standardization_provider'] = $this->_config
->address_standardization_provider
;
103 $defaults['address_standardization_userid'] = $this->_config
->address_standardization_userid
;
104 $defaults['address_standardization_url'] = $this->_config
->address_standardization_url
;
106 $this->addressSequence
= isset($newSequence) ?
$newSequence : "";
108 $defaults['address_format'] = $this->_config
->address_format
;
109 $defaults['mailing_format'] = $this->_config
->mailing_format
;
110 $defaults['hideCountryMailingLabels'] = $this->_config
->hideCountryMailingLabels
;
112 parent
::cbsDefaultValues($defaults);
118 * Build the form object.
120 public function buildQuickForm() {
121 $this->applyFilter('__ALL__', 'trim');
123 $this->addFormRule(array('CRM_Admin_Form_Preferences_Address', 'formRule'));
125 //get the tokens for Mailing Label field
126 $tokens = CRM_Core_SelectValues
::contactTokens();
127 $this->assign('tokens', CRM_Utils_Token
::formatTokensForDisplay($tokens));
129 parent
::buildQuickForm();
137 public static function formRule($fields) {
138 $p = $fields['address_standardization_provider'];
139 $u = $fields['address_standardization_userid'];
140 $w = $fields['address_standardization_url'];
142 // make sure that there is a value for all of them
143 // if any of them are set
144 if ($p ||
$u ||
$w) {
145 if (!CRM_Utils_System
::checkPHPVersion(5, FALSE)) {
146 $errors['_qf_default'] = ts('Address Standardization features require PHP version 5 or greater.');
150 if (!($p && $u && $w)) {
151 $errors['_qf_default'] = ts('You must provide values for all three Address Standarization fields.');
160 * Process the form submission.
162 public function postProcess() {
163 if ($this->_action
== CRM_Core_Action
::VIEW
) {
167 $this->_params
= $this->controller
->exportValues($this->_name
);
168 $addressOptions = CRM_Core_OptionGroup
::values('address_options', TRUE);
170 // check if county option has been set
171 if (CRM_Utils_Array
::value($addressOptions['County'], $this->_params
['address_options'])) {
172 $countyCount = CRM_Core_DAO
::singleValueQuery("SELECT count(*) FROM civicrm_county");
173 if ($countyCount < 10) {
174 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>.', array(1 => 'href="' . CRM_Utils_System
::url('civicrm/admin/extensions', array('reset' => 1), TRUE, 'extensions-addnew') . '"')),
175 ts('Populate counties'),
181 // check that locale supports address parsing
183 CRM_Utils_Array
::value($addressOptions['Street Address Parsing'], $this->_params
['address_options']) &&
184 !CRM_Core_BAO_Address
::isSupportedParsingLocale()
186 $config = CRM_Core_Config
::singleton();
187 $locale = $config->lcMessages
;
188 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');
191 $this->postProcessCommon();