3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class generates form components for Address Section
39 class CRM_Admin_Form_Preferences_Address
extends CRM_Admin_Form_Preferences
{
40 function preProcess() {
42 CRM_Utils_System
::setTitle(ts('Settings - Addresses'));
45 $this->_varNames
= array(
46 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=>
48 'address_options' => array(
49 'html_type' => 'checkboxes',
50 'title' => ts('Address Fields'),
53 'address_format' => array(
54 'html_type' => 'textarea',
55 'title' => ts('Display Format'),
56 'description' => NULL,
59 'mailing_format' => array(
60 'html_type' => 'textarea',
61 'title' => ts('Mailing Label Format'),
62 'description' => NULL,
66 CRM_Core_BAO_Setting
::ADDRESS_STANDARDIZATION_PREFERENCES_NAME
=>
68 'address_standardization_provider' => array(
69 'html_type' => 'select',
72 'address_standardization_userid' => array(
73 'html_type' => 'text',
74 'title' => ts('User ID'),
75 'description' => NULL,
78 'address_standardization_url' => array(
79 'html_type' => 'text',
80 'title' => ts('Web Service URL'),
81 'description' => NULL,
90 function setDefaultValues() {
92 $defaults['address_standardization_provider'] = $this->_config
->address_standardization_provider
;
93 $defaults['address_standardization_userid'] = $this->_config
->address_standardization_userid
;
94 $defaults['address_standardization_url'] = $this->_config
->address_standardization_url
;
97 $this->addressSequence
= isset($newSequence) ?
$newSequence : "";
99 if (empty($this->_config
->address_format
)) {
100 $defaults['address_format'] = "
101 {contact.street_address}
102 {contact.supplemental_address_1}
103 {contact.supplemental_address_2}
104 {contact.city}{, }{contact.state_province}{ }{contact.postal_code}
109 $defaults['address_format'] = $this->_config
->address_format
;
112 if (empty($this->_config
->mailing_format
)) {
113 $defaults['mailing_format'] = "
115 {contact.street_address}
116 {contact.supplemental_address_1}
117 {contact.supplemental_address_2}
118 {contact.city}{, }{contact.state_province}{ }{contact.postal_code}
123 $defaults['mailing_format'] = $this->_config
->mailing_format
;
127 parent
::cbsDefaultValues($defaults);
133 * Function to build the form
138 public function buildQuickForm() {
139 $this->applyFilter('__ALL__', 'trim');
141 // Address Standardization
142 $addrProviders = CRM_Core_SelectValues
::addressProvider();
143 $this->addElement('select',
144 'address_standardization_provider',
145 ts('Address Provider'),
147 '' => '- select -') +
$addrProviders
150 $this->addFormRule(array('CRM_Admin_Form_Preferences_Address', 'formRule'));
152 //get the tokens for Mailing Label field
153 $tokens = CRM_Core_SelectValues
::contactTokens();
154 $this->assign('tokens', CRM_Utils_Token
::formatTokensForDisplay($tokens));
156 parent
::buildQuickForm();
159 static function formRule($fields) {
160 $p = $fields['address_standardization_provider'];
161 $u = $fields['address_standardization_userid'];
162 $w = $fields['address_standardization_url'];
164 // make sure that there is a value for all of them
165 // if any of them are set
166 if ($p ||
$u ||
$w) {
167 if (!CRM_Utils_System
::checkPHPVersion(5, FALSE)) {
168 $errors['_qf_default'] = ts('Address Standardization features require PHP version 5 or greater.');
172 if (!($p && $u && $w)) {
173 $errors['_qf_default'] = ts('You must provide values for all three Address Standarization fields.');
182 * Function to process the form
188 public function postProcess() {
189 if ($this->_action
== CRM_Core_Action
::VIEW
) {
193 $this->_params
= $this->controller
->exportValues($this->_name
);
196 // check if county option has been set
197 $options = CRM_Core_OptionGroup
::values('address_options', FALSE, FALSE, TRUE);
198 foreach ($options as $key => $title) {
199 if ($title == ts('County')) {
200 // check if the $key is present in $this->_params
201 if (isset($this->_params
['address_options']) &&
202 !empty($this->_params
['address_options'][$key])
204 // print a status message to the user if county table seems small
209 $countyCount = CRM_Core_DAO
::singleValueQuery($sql);
210 if ($countyCount < 10) {
211 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 ') . CRM_Utils_System
::href(ts('CiviCRM Extensions Directory'), 'civicrm/admin/extensions', array('reset' => 1), TRUE, 'extensions-addnew'),
212 ts('Populate counties'),
220 $this->postProcessCommon();