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,
93 function setDefaultValues() {
95 $defaults['address_standardization_provider'] = $this->_config
->address_standardization_provider
;
96 $defaults['address_standardization_userid'] = $this->_config
->address_standardization_userid
;
97 $defaults['address_standardization_url'] = $this->_config
->address_standardization_url
;
100 $this->addressSequence
= isset($newSequence) ?
$newSequence : "";
102 if (empty($this->_config
->address_format
)) {
103 $defaults['address_format'] = "
104 {contact.street_address}
105 {contact.supplemental_address_1}
106 {contact.supplemental_address_2}
107 {contact.city}{, }{contact.state_province}{ }{contact.postal_code}
112 $defaults['address_format'] = $this->_config
->address_format
;
115 if (empty($this->_config
->mailing_format
)) {
116 $defaults['mailing_format'] = "
118 {contact.street_address}
119 {contact.supplemental_address_1}
120 {contact.supplemental_address_2}
121 {contact.city}{, }{contact.state_province}{ }{contact.postal_code}
126 $defaults['mailing_format'] = $this->_config
->mailing_format
;
130 parent
::cbsDefaultValues($defaults);
136 * Function to build the form
141 public function buildQuickForm() {
142 $this->applyFilter('__ALL__', 'trim');
144 // Address Standardization
145 $addrProviders = CRM_Core_SelectValues
::addressProvider();
146 $this->addElement('select',
147 'address_standardization_provider',
148 ts('Address Provider'),
150 '' => '- select -') +
$addrProviders
153 $this->addFormRule(array('CRM_Admin_Form_Preferences_Address', 'formRule'));
155 //get the tokens for Mailing Label field
156 $tokens = CRM_Core_SelectValues
::contactTokens();
157 $this->assign('tokens', CRM_Utils_Token
::formatTokensForDisplay($tokens));
159 parent
::buildQuickForm();
167 static function formRule($fields) {
168 $p = $fields['address_standardization_provider'];
169 $u = $fields['address_standardization_userid'];
170 $w = $fields['address_standardization_url'];
172 // make sure that there is a value for all of them
173 // if any of them are set
174 if ($p ||
$u ||
$w) {
175 if (!CRM_Utils_System
::checkPHPVersion(5, FALSE)) {
176 $errors['_qf_default'] = ts('Address Standardization features require PHP version 5 or greater.');
180 if (!($p && $u && $w)) {
181 $errors['_qf_default'] = ts('You must provide values for all three Address Standarization fields.');
190 * Function to process the form
196 public function postProcess() {
197 if ($this->_action
== CRM_Core_Action
::VIEW
) {
201 $this->_params
= $this->controller
->exportValues($this->_name
);
204 // check if county option has been set
205 $options = CRM_Core_OptionGroup
::values('address_options', FALSE, FALSE, TRUE);
206 foreach ($options as $key => $title) {
207 if ($title == ts('County')) {
208 // check if the $key is present in $this->_params
209 if (isset($this->_params
['address_options']) &&
210 !empty($this->_params
['address_options'][$key])
212 // print a status message to the user if county table seems small
217 $countyCount = CRM_Core_DAO
::singleValueQuery($sql);
218 if ($countyCount < 10) {
219 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'),
220 ts('Populate counties'),
228 $this->postProcessCommon();